-
Notifications
You must be signed in to change notification settings - Fork 9
/
StockfishBridge.mm
83 lines (70 loc) · 1.98 KB
/
StockfishBridge.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <string>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/machine.h>
#import <Capacitor/CAPPlugin.h>
#import <CapacitorStockfish/CapacitorStockfish-Swift.h>
#import "StockfishBridge.h"
#import "Stockfish.hpp"
@implementation StockfishBridge
- (instancetype)initWithPlugin:(Stockfish *)plugin {
self = [super init];
if (self) {
_plugin = plugin;
}
return self;
}
- (void) start {
CapacitorStockfish::init((__bridge void*)self);
}
- (void) cmd: (NSString*)command {
CapacitorStockfish::cmd(std::string([command UTF8String]));
}
- (void) exit {
CapacitorStockfish::exit();
}
- (void) sendOutput: (NSString*)output {
[_plugin sendOutput:output];
}
+ (NSString*) getCPUType {
NSMutableString *cpu = [[NSMutableString alloc] init];
size_t size;
cpu_type_t type;
cpu_subtype_t subtype;
size = sizeof(type);
sysctlbyname("hw.cputype", &type, &size, NULL, 0);
size = sizeof(subtype);
sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0);
// values for cputype and cpusubtype defined in mach/machine.h
if (type == CPU_TYPE_X86_64) {
[cpu appendString:@"x86_64"];
} else if (type == CPU_TYPE_X86) {
[cpu appendString:@"x86"];
switch (subtype) {
case CPU_SUBTYPE_X86_ALL:
case CPU_SUBTYPE_X86_64_H:
[cpu appendString:@"_64"];
break;
}
} else if (type == CPU_TYPE_ARM) {
[cpu appendString:@"ARM"];
switch(subtype)
{
case CPU_SUBTYPE_ARM_V6:
[cpu appendString:@"V6"];
break;
case CPU_SUBTYPE_ARM_V7:
[cpu appendString:@"V7"];
break;
case CPU_SUBTYPE_ARM_V8:
[cpu appendString:@"V8"];
break;
}
}
return cpu;
}
void StockfishSendOutput (void *bridge, const char *output)
{
[(__bridge id) bridge sendOutput:[NSString stringWithUTF8String:output]];
}
@end