From 023d26029cd9d364652b7db406bf06aaa54c2419 Mon Sep 17 00:00:00 2001 From: Mikolaj Kojdecki Date: Fri, 31 Jul 2020 17:21:13 +0200 Subject: [PATCH] WIP --- .../com/polidea/blemulator/JsCallHandler.java | 10 +- .../com/polidea/blemulator/MethodName.java | 2 +- .../blemulator/NativeArgumentName.java | 4 +- ios/Blemulator.xcodeproj/project.pbxproj | 108 ++++++++++++++++++ ios/Bridging/JsCallCallback.h | 13 +++ ios/Bridging/JsCallCallback.m | 9 ++ ios/Bridging/JsCallHandler.h | 14 +++ ios/Bridging/JsCallHandler.m | 40 +++++++ ios/Bridging/PlatformToJsBridge.h | 15 +++ ios/Bridging/PlatformToJsBridge.m | 9 ++ ios/Containers/CachedCharacteristic.h | 13 +++ ios/Containers/CachedCharacteristic.m | 9 ++ ios/Containers/CachedService.h | 13 +++ ios/Containers/CachedService.m | 9 ++ ios/Containers/DeviceContainer.h | 13 +++ ios/Containers/DeviceContainer.m | 9 ++ ios/Containers/DeviceManager.h | 13 +++ ios/Containers/DeviceManager.m | 9 ++ ios/Names/JsArgumentName.h | 26 +++++ ios/Names/JsArgumentName.m | 26 +++++ ios/Names/MethodName.h | 45 ++++++++ ios/Names/MethodName.m | 45 ++++++++ ios/Names/NativeArgumentName.h | 42 +++++++ ios/Names/NativeArgumentName.m | 42 +++++++ ios/Parsers/DeviceParser.h | 13 +++ ios/Parsers/DeviceParser.m | 9 ++ ios/Parsers/ErrorParser.h | 13 +++ ios/Parsers/ErrorParser.m | 9 ++ ios/Parsers/GattParser.h | 13 +++ ios/Parsers/GattParser.m | 9 ++ 30 files changed, 596 insertions(+), 8 deletions(-) create mode 100644 ios/Bridging/JsCallCallback.h create mode 100644 ios/Bridging/JsCallCallback.m create mode 100644 ios/Bridging/JsCallHandler.h create mode 100644 ios/Bridging/JsCallHandler.m create mode 100644 ios/Bridging/PlatformToJsBridge.h create mode 100644 ios/Bridging/PlatformToJsBridge.m create mode 100644 ios/Containers/CachedCharacteristic.h create mode 100644 ios/Containers/CachedCharacteristic.m create mode 100644 ios/Containers/CachedService.h create mode 100644 ios/Containers/CachedService.m create mode 100644 ios/Containers/DeviceContainer.h create mode 100644 ios/Containers/DeviceContainer.m create mode 100644 ios/Containers/DeviceManager.h create mode 100644 ios/Containers/DeviceManager.m create mode 100644 ios/Names/JsArgumentName.h create mode 100644 ios/Names/JsArgumentName.m create mode 100644 ios/Names/MethodName.h create mode 100644 ios/Names/MethodName.m create mode 100644 ios/Names/NativeArgumentName.h create mode 100644 ios/Names/NativeArgumentName.m create mode 100644 ios/Parsers/DeviceParser.h create mode 100644 ios/Parsers/DeviceParser.m create mode 100644 ios/Parsers/ErrorParser.h create mode 100644 ios/Parsers/ErrorParser.m create mode 100644 ios/Parsers/GattParser.h create mode 100644 ios/Parsers/GattParser.m diff --git a/android/src/main/java/com/polidea/blemulator/JsCallHandler.java b/android/src/main/java/com/polidea/blemulator/JsCallHandler.java index 2cad724..87d3662 100644 --- a/android/src/main/java/com/polidea/blemulator/JsCallHandler.java +++ b/android/src/main/java/com/polidea/blemulator/JsCallHandler.java @@ -9,10 +9,6 @@ public class JsCallHandler { private int nextCallId = 0; private Map callbacks = new HashMap<>(); - public String getNextCallbackId() { - return Integer.toString(nextCallId++); - } - public String addCallback(Callback callback) { String callId = getNextCallbackId(); callbacks.put(callId, callback); @@ -32,7 +28,11 @@ public void handleReturnCall(String id, ReadableMap args) { callbacks.remove(id); } + private String getNextCallbackId() { + return Integer.toString(nextCallId++); + } + interface Callback { - void invoke(ReadableMap args); + void invoke(ReadableMap args); } } diff --git a/android/src/main/java/com/polidea/blemulator/MethodName.java b/android/src/main/java/com/polidea/blemulator/MethodName.java index 8040629..1957dff 100644 --- a/android/src/main/java/com/polidea/blemulator/MethodName.java +++ b/android/src/main/java/com/polidea/blemulator/MethodName.java @@ -14,7 +14,7 @@ public interface MethodName { String CANCEL_CONNECTION_OR_DISCONNECT = "disconnect"; String IS_DEVICE_CONNECTED = "isDeviceConnected"; - String READ_RSSI = "readRssi"; + String READ_RSSI = "readRssi"; String REQUEST_CONNECTION_PRIORITY = "requestConnectionPriority"; String REQUEST_MTU = "requestMtu"; diff --git a/android/src/main/java/com/polidea/blemulator/NativeArgumentName.java b/android/src/main/java/com/polidea/blemulator/NativeArgumentName.java index bddfb0a..bfe5871 100644 --- a/android/src/main/java/com/polidea/blemulator/NativeArgumentName.java +++ b/android/src/main/java/com/polidea/blemulator/NativeArgumentName.java @@ -16,7 +16,7 @@ public interface NativeArgumentName { //ScanResult String NAME = "name"; - String RSSI ="rssi"; + String RSSI = "rssi"; String TX_POWER_LEVEL = "txPowerLeveL"; String OVERFLOW_SERVICE_UUIDS = "overflowServiceUuids"; String SERVICE_DATA = "serviceData"; @@ -40,7 +40,7 @@ public interface NativeArgumentName { String DESCRIPTORS = "descriptors"; String CHARACTERISTIC_ID = "characteristicId"; String CHARACTERISTIC_UUID = "characteristicUuid"; - + //RequestMtu String MTU = "mtu"; } diff --git a/ios/Blemulator.xcodeproj/project.pbxproj b/ios/Blemulator.xcodeproj/project.pbxproj index bddb8ba..b1e0e3a 100644 --- a/ios/Blemulator.xcodeproj/project.pbxproj +++ b/ios/Blemulator.xcodeproj/project.pbxproj @@ -8,6 +8,19 @@ /* Begin PBXBuildFile section */ 1033FA1B24642D06003B0C50 /* SimulatedAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1033FA1A24642D06003B0C50 /* SimulatedAdapter.m */; }; + 10C7A84F24D2F94B00BC92D6 /* CachedCharacteristic.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A84E24D2F94B00BC92D6 /* CachedCharacteristic.m */; }; + 10C7A85124D2F95D00BC92D6 /* CachedService.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A85024D2F95D00BC92D6 /* CachedService.m */; }; + 10C7A85324D2F96B00BC92D6 /* DeviceContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A85224D2F96B00BC92D6 /* DeviceContainer.m */; }; + 10C7A85524D2F97900BC92D6 /* DeviceManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A85424D2F97900BC92D6 /* DeviceManager.m */; }; + 10C7A85B24D2FA6300BC92D6 /* DeviceParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A85A24D2FA6300BC92D6 /* DeviceParser.m */; }; + 10C7A85D24D2FA7700BC92D6 /* ErrorParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A85C24D2FA7700BC92D6 /* ErrorParser.m */; }; + 10C7A85F24D2FA8800BC92D6 /* GattParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A85E24D2FA8800BC92D6 /* GattParser.m */; }; + 10C7A86524D2FB0500BC92D6 /* JsArgumentName.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A86424D2FB0500BC92D6 /* JsArgumentName.m */; }; + 10C7A86724D2FB5E00BC92D6 /* NativeArgumentName.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A86624D2FB5E00BC92D6 /* NativeArgumentName.m */; }; + 10C7A86A24D2FB7500BC92D6 /* MethodName.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A86924D2FB7500BC92D6 /* MethodName.m */; }; + 10C7A86D24D2FBB200BC92D6 /* JsCallHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A86C24D2FBB200BC92D6 /* JsCallHandler.m */; }; + 10C7A87124D2FBDB00BC92D6 /* PlatformToJsBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 10C7A87024D2FBDB00BC92D6 /* PlatformToJsBridge.m */; }; + 10C7A87624D43C9300BC92D6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 10C7A87524D43C9300BC92D6 /* Foundation.framework */; }; 320F8AB317FF97AAD1EA62E8 /* Pods_Blemulator.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81432FA2EACC1C10AF962CAB /* Pods_Blemulator.framework */; }; B3E7B58A1CC2AC0600A0062D /* Blemulator.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* Blemulator.m */; }; /* End PBXBuildFile section */ @@ -27,6 +40,31 @@ /* Begin PBXFileReference section */ 09473796EC6DD87C2E56F92D /* Pods-Blemulator.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Blemulator.debug.xcconfig"; path = "Target Support Files/Pods-Blemulator/Pods-Blemulator.debug.xcconfig"; sourceTree = ""; }; 1033FA1A24642D06003B0C50 /* SimulatedAdapter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SimulatedAdapter.m; sourceTree = ""; }; + 10C7A84A24D2F8F600BC92D6 /* CachedCharacteristic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CachedCharacteristic.h; sourceTree = ""; }; + 10C7A84B24D2F90600BC92D6 /* CachedService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CachedService.h; sourceTree = ""; }; + 10C7A84C24D2F91800BC92D6 /* DeviceContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceContainer.h; sourceTree = ""; }; + 10C7A84D24D2F92800BC92D6 /* DeviceManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceManager.h; sourceTree = ""; }; + 10C7A84E24D2F94B00BC92D6 /* CachedCharacteristic.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CachedCharacteristic.m; sourceTree = ""; }; + 10C7A85024D2F95D00BC92D6 /* CachedService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CachedService.m; sourceTree = ""; }; + 10C7A85224D2F96B00BC92D6 /* DeviceContainer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceContainer.m; sourceTree = ""; }; + 10C7A85424D2F97900BC92D6 /* DeviceManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceManager.m; sourceTree = ""; }; + 10C7A85724D2FA2700BC92D6 /* DeviceParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceParser.h; sourceTree = ""; }; + 10C7A85824D2FA4100BC92D6 /* ErrorParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ErrorParser.h; sourceTree = ""; }; + 10C7A85924D2FA5200BC92D6 /* GattParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GattParser.h; sourceTree = ""; }; + 10C7A85A24D2FA6300BC92D6 /* DeviceParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceParser.m; sourceTree = ""; }; + 10C7A85C24D2FA7700BC92D6 /* ErrorParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ErrorParser.m; sourceTree = ""; }; + 10C7A85E24D2FA8800BC92D6 /* GattParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GattParser.m; sourceTree = ""; }; + 10C7A86124D2FACC00BC92D6 /* JsArgumentName.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JsArgumentName.h; sourceTree = ""; }; + 10C7A86224D2FAE200BC92D6 /* NativeArgumentName.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NativeArgumentName.h; sourceTree = ""; }; + 10C7A86324D2FAF400BC92D6 /* MethodName.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MethodName.h; sourceTree = ""; }; + 10C7A86424D2FB0500BC92D6 /* JsArgumentName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JsArgumentName.m; sourceTree = ""; }; + 10C7A86624D2FB5E00BC92D6 /* NativeArgumentName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NativeArgumentName.m; sourceTree = ""; }; + 10C7A86924D2FB7500BC92D6 /* MethodName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MethodName.m; sourceTree = ""; }; + 10C7A86C24D2FBB200BC92D6 /* JsCallHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JsCallHandler.m; sourceTree = ""; }; + 10C7A87024D2FBDB00BC92D6 /* PlatformToJsBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlatformToJsBridge.m; sourceTree = ""; }; + 10C7A87224D2FC1900BC92D6 /* JsCallHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JsCallHandler.h; sourceTree = ""; }; + 10C7A87424D2FC4200BC92D6 /* PlatformToJsBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformToJsBridge.h; sourceTree = ""; }; + 10C7A87524D43C9300BC92D6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 10D74E8F24644F7B00C37BC0 /* SimulatedAdapter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SimulatedAdapter.h; sourceTree = ""; }; 10D74E91246453F700C37BC0 /* BlemulatorCommonTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlemulatorCommonTypes.h; sourceTree = ""; }; 134814201AA4EA6300B7C361 /* libBlemulator.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBlemulator.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -41,6 +79,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 10C7A87624D43C9300BC92D6 /* Foundation.framework in Frameworks */, 320F8AB317FF97AAD1EA62E8 /* Pods_Blemulator.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -48,6 +87,58 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 10C7A84924D2F8C800BC92D6 /* Containers */ = { + isa = PBXGroup; + children = ( + 10C7A84A24D2F8F600BC92D6 /* CachedCharacteristic.h */, + 10C7A84B24D2F90600BC92D6 /* CachedService.h */, + 10C7A84C24D2F91800BC92D6 /* DeviceContainer.h */, + 10C7A84D24D2F92800BC92D6 /* DeviceManager.h */, + 10C7A84E24D2F94B00BC92D6 /* CachedCharacteristic.m */, + 10C7A85024D2F95D00BC92D6 /* CachedService.m */, + 10C7A85224D2F96B00BC92D6 /* DeviceContainer.m */, + 10C7A85424D2F97900BC92D6 /* DeviceManager.m */, + ); + path = Containers; + sourceTree = ""; + }; + 10C7A85624D2FA0D00BC92D6 /* Parsers */ = { + isa = PBXGroup; + children = ( + 10C7A85724D2FA2700BC92D6 /* DeviceParser.h */, + 10C7A85824D2FA4100BC92D6 /* ErrorParser.h */, + 10C7A85924D2FA5200BC92D6 /* GattParser.h */, + 10C7A85A24D2FA6300BC92D6 /* DeviceParser.m */, + 10C7A85C24D2FA7700BC92D6 /* ErrorParser.m */, + 10C7A85E24D2FA8800BC92D6 /* GattParser.m */, + ); + path = Parsers; + sourceTree = ""; + }; + 10C7A86024D2FAB600BC92D6 /* Names */ = { + isa = PBXGroup; + children = ( + 10C7A86124D2FACC00BC92D6 /* JsArgumentName.h */, + 10C7A86224D2FAE200BC92D6 /* NativeArgumentName.h */, + 10C7A86324D2FAF400BC92D6 /* MethodName.h */, + 10C7A86424D2FB0500BC92D6 /* JsArgumentName.m */, + 10C7A86624D2FB5E00BC92D6 /* NativeArgumentName.m */, + 10C7A86924D2FB7500BC92D6 /* MethodName.m */, + ); + path = Names; + sourceTree = ""; + }; + 10C7A86B24D2FB9000BC92D6 /* Bridging */ = { + isa = PBXGroup; + children = ( + 10C7A86C24D2FBB200BC92D6 /* JsCallHandler.m */, + 10C7A87024D2FBDB00BC92D6 /* PlatformToJsBridge.m */, + 10C7A87224D2FC1900BC92D6 /* JsCallHandler.h */, + 10C7A87424D2FC4200BC92D6 /* PlatformToJsBridge.h */, + ); + path = Bridging; + sourceTree = ""; + }; 10D74E90246453DC00C37BC0 /* Util */ = { isa = PBXGroup; children = ( @@ -67,6 +158,10 @@ 58B511D21A9E6C8500147676 = { isa = PBXGroup; children = ( + 10C7A86B24D2FB9000BC92D6 /* Bridging */, + 10C7A86024D2FAB600BC92D6 /* Names */, + 10C7A85624D2FA0D00BC92D6 /* Parsers */, + 10C7A84924D2F8C800BC92D6 /* Containers */, 10D74E90246453DC00C37BC0 /* Util */, 10D74E8F24644F7B00C37BC0 /* SimulatedAdapter.h */, 1033FA1A24642D06003B0C50 /* SimulatedAdapter.m */, @@ -90,6 +185,7 @@ C0CA31E543A1A53F13864080 /* Frameworks */ = { isa = PBXGroup; children = ( + 10C7A87524D43C9300BC92D6 /* Foundation.framework */, 81432FA2EACC1C10AF962CAB /* Pods_Blemulator.framework */, ); name = Frameworks; @@ -178,8 +274,20 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 10C7A84F24D2F94B00BC92D6 /* CachedCharacteristic.m in Sources */, + 10C7A86A24D2FB7500BC92D6 /* MethodName.m in Sources */, + 10C7A86724D2FB5E00BC92D6 /* NativeArgumentName.m in Sources */, + 10C7A87124D2FBDB00BC92D6 /* PlatformToJsBridge.m in Sources */, + 10C7A86D24D2FBB200BC92D6 /* JsCallHandler.m in Sources */, + 10C7A85524D2F97900BC92D6 /* DeviceManager.m in Sources */, + 10C7A85324D2F96B00BC92D6 /* DeviceContainer.m in Sources */, 1033FA1B24642D06003B0C50 /* SimulatedAdapter.m in Sources */, B3E7B58A1CC2AC0600A0062D /* Blemulator.m in Sources */, + 10C7A85F24D2FA8800BC92D6 /* GattParser.m in Sources */, + 10C7A85B24D2FA6300BC92D6 /* DeviceParser.m in Sources */, + 10C7A85124D2F95D00BC92D6 /* CachedService.m in Sources */, + 10C7A86524D2FB0500BC92D6 /* JsArgumentName.m in Sources */, + 10C7A85D24D2FA7700BC92D6 /* ErrorParser.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ios/Bridging/JsCallCallback.h b/ios/Bridging/JsCallCallback.h new file mode 100644 index 0000000..f762a12 --- /dev/null +++ b/ios/Bridging/JsCallCallback.h @@ -0,0 +1,13 @@ +// +// JsCallCallback.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef JsCallCallback_h +#define JsCallCallback_h + + +#endif /* JsCallCallback_h */ diff --git a/ios/Bridging/JsCallCallback.m b/ios/Bridging/JsCallCallback.m new file mode 100644 index 0000000..2f07183 --- /dev/null +++ b/ios/Bridging/JsCallCallback.m @@ -0,0 +1,9 @@ +// +// JsCallCallback.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Bridging/JsCallHandler.h b/ios/Bridging/JsCallHandler.h new file mode 100644 index 0000000..9aa0be2 --- /dev/null +++ b/ios/Bridging/JsCallHandler.h @@ -0,0 +1,14 @@ +#import + +typedef void (^JsCallback)(id result); + +@interface JsCallHandler : NSObject + +- (instancetype)init; + +- (NSString*)addCallback:(JsCallback)callback; + +- (void)handleReturnCallWithId:(NSString *)callId + args:(NSDictionary*)args; + +@end diff --git a/ios/Bridging/JsCallHandler.m b/ios/Bridging/JsCallHandler.m new file mode 100644 index 0000000..c0376b8 --- /dev/null +++ b/ios/Bridging/JsCallHandler.m @@ -0,0 +1,40 @@ +#import "JsCallHandler.h" + +@interface JsCallHandler() + +@property (nonatomic) int nextCallbackId; +@property (nonatomic) NSMutableDictionary* callbacks; + +@end + +@implementation JsCallHandler + +- (instancetype)init { + self = [super init]; + if (self) { + self.nextCallbackId = 0; + self.callbacks = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (NSString*)addCallback:(JsCallback)callback { + NSString* id = [NSString stringWithFormat:@"%d", self.nextCallbackId++]; + [self.callbacks setObject:callback forKey:id]; + return id; +} + +- (void)handleReturnCallWithId:(NSString *)callId + args:(NSDictionary*)args { + JsCallback callback = [self.callbacks objectForKey:callId]; + if (callback != nil) { + callback(args); + [self.callbacks removeObjectForKey:callId]; + } else { + NSException* exception = [NSException exceptionWithName:@"Illegal state" + reason:@"Non-existent callback requested" + userInfo:nil] ; + @throw exception; + } +} +@end diff --git a/ios/Bridging/PlatformToJsBridge.h b/ios/Bridging/PlatformToJsBridge.h new file mode 100644 index 0000000..7fd7a53 --- /dev/null +++ b/ios/Bridging/PlatformToJsBridge.h @@ -0,0 +1,15 @@ +#import +#import "JsCallHandler" + +typedef void (^JsCallback)(id result); + +@interface PlatformToJsBridge : NSObject + +- (instancetype)initWithJsCallHandler:(JsCallHandler*)jsCallHandler; + +- (NSString*)addCallback:(JsCallback)callback; + +- (void)handleReturnCallWithId:(NSString *)callId + args:(NSDictionary*)args; + +@end diff --git a/ios/Bridging/PlatformToJsBridge.m b/ios/Bridging/PlatformToJsBridge.m new file mode 100644 index 0000000..44aa396 --- /dev/null +++ b/ios/Bridging/PlatformToJsBridge.m @@ -0,0 +1,9 @@ +// +// PlatformToJsBridge.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Containers/CachedCharacteristic.h b/ios/Containers/CachedCharacteristic.h new file mode 100644 index 0000000..40a4a50 --- /dev/null +++ b/ios/Containers/CachedCharacteristic.h @@ -0,0 +1,13 @@ +// +// CachedCharacteristic.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef CachedCharacteristic_h +#define CachedCharacteristic_h + + +#endif /* CachedCharacteristic_h */ diff --git a/ios/Containers/CachedCharacteristic.m b/ios/Containers/CachedCharacteristic.m new file mode 100644 index 0000000..4c3d6cc --- /dev/null +++ b/ios/Containers/CachedCharacteristic.m @@ -0,0 +1,9 @@ +// +// CachedCharacteristic.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Containers/CachedService.h b/ios/Containers/CachedService.h new file mode 100644 index 0000000..116f7f8 --- /dev/null +++ b/ios/Containers/CachedService.h @@ -0,0 +1,13 @@ +// +// CachedService.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef CachedService_h +#define CachedService_h + + +#endif /* CachedService_h */ diff --git a/ios/Containers/CachedService.m b/ios/Containers/CachedService.m new file mode 100644 index 0000000..b972ae8 --- /dev/null +++ b/ios/Containers/CachedService.m @@ -0,0 +1,9 @@ +// +// CachedService.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Containers/DeviceContainer.h b/ios/Containers/DeviceContainer.h new file mode 100644 index 0000000..004612d --- /dev/null +++ b/ios/Containers/DeviceContainer.h @@ -0,0 +1,13 @@ +// +// DeviceContainer.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef DeviceContainer_h +#define DeviceContainer_h + + +#endif /* DeviceContainer_h */ diff --git a/ios/Containers/DeviceContainer.m b/ios/Containers/DeviceContainer.m new file mode 100644 index 0000000..34d28cf --- /dev/null +++ b/ios/Containers/DeviceContainer.m @@ -0,0 +1,9 @@ +// +// DeviceContainer.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Containers/DeviceManager.h b/ios/Containers/DeviceManager.h new file mode 100644 index 0000000..bb13fe5 --- /dev/null +++ b/ios/Containers/DeviceManager.h @@ -0,0 +1,13 @@ +// +// DeviceManager.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef DeviceManager_h +#define DeviceManager_h + + +#endif /* DeviceManager_h */ diff --git a/ios/Containers/DeviceManager.m b/ios/Containers/DeviceManager.m new file mode 100644 index 0000000..9fd618c --- /dev/null +++ b/ios/Containers/DeviceManager.m @@ -0,0 +1,9 @@ +// +// DeviceManager.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Names/JsArgumentName.h b/ios/Names/JsArgumentName.h new file mode 100644 index 0000000..171d54e --- /dev/null +++ b/ios/Names/JsArgumentName.h @@ -0,0 +1,26 @@ +extern NSString* const JS_ARG_TRANSACTION_ID; + +extern NSString* const JS_ARG_FILTERED_UUIDS; +extern NSString* const JS_ARG_SCAN_MODE; +extern NSString* const JS_ARG_CALLBACK_TYPE; + +extern NSString* const JS_ARG_IDENTIFIER; +extern NSString* const JS_ARG_IS_AUTO_CONNECT; +extern NSString* const JS_ARG_REQUEST_MTU; +extern NSString* const JS_ARG_REFRESH_GATT; +extern NSString* const JS_ARG_TIMEOUT; +extern NSString* const JS_ARG_MTU; +extern NSString* const JS_ARG_CONNECTION_PRIORITY; + +extern NSString* const JS_ARG_DEVICE_IDS; +extern NSString* const JS_ARG_SERVICE_UUIDS; + +extern NSString* const JS_ARG_SERVICE_ID; +extern NSString* const JS_ARG_SERVICE_UUID; +extern NSString* const JS_ARG_CHARACTERISTIC_ID; +extern NSString* const JS_ARG_CHARACTERISTIC_UUID; +extern NSString* const JS_ARG_DESCRIPTOR_ID; +extern NSString* const JS_ARG_DESCRIPTOR_UUID; + +extern NSString* const JS_ARG_VALUE; +extern NSString* const JS_ARG_WITH_RESPONSE; diff --git a/ios/Names/JsArgumentName.m b/ios/Names/JsArgumentName.m new file mode 100644 index 0000000..d85c991 --- /dev/null +++ b/ios/Names/JsArgumentName.m @@ -0,0 +1,26 @@ +NSString * const JS_ARG_TRANSACTION_ID = @"transactionId"; + +NSString * const JS_ARG_FILTERED_UUIDS = @"filteredUuids"; +NSString * const JS_ARG_SCAN_MODE = @"scanMode"; +NSString * const JS_ARG_CALLBACK_TYPE = @"callbackType"; + +NSString * const JS_ARG_IDENTIFIER = @"identifier"; +NSString * const JS_ARG_IS_AUTO_CONNECT = @"isAutoConnect"; +NSString * const JS_ARG_REQUEST_MTU = @"requestMtu"; +NSString * const JS_ARG_REFRESH_GATT = @"refreshGatt"; +NSString * const JS_ARG_TIMEOUT = @"timeout"; +NSString * const JS_ARG_MTU = @"mtu"; +NSString * const JS_ARG_CONNECTION_PRIORITY = @"connectionPriority"; + +NSString * const JS_ARG_DEVICE_IDS = @"deviceIds"; +NSString * const JS_ARG_SERVICE_UUIDS = @"serviceUuids"; + +NSString * const JS_ARG_SERVICE_ID = @"serviceId"; +NSString * const JS_ARG_SERVICE_UUID = @"serviceUuid"; +NSString * const JS_ARG_CHARACTERISTIC_ID = @"characteristicId"; +NSString * const JS_ARG_CHARACTERISTIC_UUID = @"characteristicUuid"; +NSString * const JS_ARG_DESCRIPTOR_ID = @"descriptorId"; +NSString * const JS_ARG_DESCRIPTOR_UUID = @"descriptorUuid"; + +NSString * const JS_ARG_VALUE = @"value"; +NSString * const JS_ARG_WITH_RESPONSE = @"withResponse"; diff --git a/ios/Names/MethodName.h b/ios/Names/MethodName.h new file mode 100644 index 0000000..04ea708 --- /dev/null +++ b/ios/Names/MethodName.h @@ -0,0 +1,45 @@ +extern NSString* const METHOD_NAME_CREATE_CLIENT; +extern NSString* const METHOD_NAME_DESTROY_CLIENT; + +extern NSString* const METHOD_NAME_ENABLE; +extern NSString* const METHOD_NAME_DISABLE; + +extern NSString* const METHOD_NAME_START_SCAN; +extern NSString* const METHOD_NAME_STOP_SCAN; + +extern NSString* const METHOD_NAME_CONNECT; +extern NSString* const METHOD_NAME_CANCEL_CONNECTION_OR_DISCONNECT; +extern NSString* const METHOD_NAME_IS_DEVICE_CONNECTED; + +extern NSString* const METHOD_NAME_READ_RSSI; +extern NSString* const METHOD_NAME_REQUEST_CONNECTION_PRIORITY; +extern NSString* const METHOD_NAME_REQUEST_MTU; + +extern NSString* const METHOD_NAME_GET_KNOWN_DEVICES; +extern NSString* const METHOD_NAME_GET_CONNECTED_DEVICED; + +extern NSString* const METHOD_NAME_DISCOVERY; + +extern NSString* const METHOD_NAME_READ_CHARACTERISTIC; +extern NSString* const METHOD_NAME_READ_CHARACTERISTIC_FOR_SERVICE; +extern NSString* const METHOD_NAME_READ_CHARACTERISTIC_FOR_DEVICE; + +extern NSString* const METHOD_NAME_WRITE_CHARACTERISTIC; +extern NSString* const METHOD_NAME_WRITE_CHARACTERISTIC_FOR_SERVICE; +extern NSString* const METHOD_NAME_WRITE_CHARACTERISTIC_FOR_DEVICE; + +extern NSString* const METHOD_NAME_MONITOR_CHARACTERISTIC; +extern NSString* const METHOD_NAME_MONITOR_CHARACTERISTIC_FOR_SERVICE; +extern NSString* const METHOD_NAME_MONITOR_CHARACTERISTIC_FOR_DEVICE; + +extern NSString* const METHOD_NAME_READ_DESCRIPTOR; +extern NSString* const METHOD_NAME_READ_DESCRIPTOR_FOR_CHARACTERISTIC; +extern NSString* const METHOD_NAME_READ_DESCRIPTOR_FOR_SERVICE; +extern NSString* const METHOD_NAME_READ_DESCRIPTOR_FOR_DEVICE; + +extern NSString* const METHOD_NAME_WRITE_DESCRIPTOR; +extern NSString* const METHOD_NAME_WRITE_DESCRIPTOR_FOR_CHARACTERISTIC; +extern NSString* const METHOD_NAME_WRITE_DESCRIPTOR_FOR_SERVICE; +extern NSString* const METHOD_NAME_WRITE_DESCRIPTOR_FOR_DEVICE; + +extern NSString* const METHOD_NAME_CANCEL_TRANSACTION; diff --git a/ios/Names/MethodName.m b/ios/Names/MethodName.m new file mode 100644 index 0000000..7c12704 --- /dev/null +++ b/ios/Names/MethodName.m @@ -0,0 +1,45 @@ +NSString* const METHOD_NAME_CREATE_CLIENT = @"createClient"; +NSString* const METHOD_NAME_DESTROY_CLIENT = @"destroyClient"; + +NSString* const METHOD_NAME_ENABLE = @"enable"; +NSString* const METHOD_NAME_DISABLE = @"disable"; + +NSString* const METHOD_NAME_START_SCAN = @"startScan"; +NSString* const METHOD_NAME_STOP_SCAN = @"stopScan"; + +NSString* const METHOD_NAME_CONNECT = @"connect"; +NSString* const METHOD_NAME_CANCEL_CONNECTION_OR_DISCONNECT = @"disconnect"; +NSString* const METHOD_NAME_IS_DEVICE_CONNECTED = @"isDeviceConnected"; + +NSString* const METHOD_NAME_READ_RSSI = @"readRssi"; +NSString* const METHOD_NAME_REQUEST_CONNECTION_PRIORITY = @"requestConnectionPriority"; +NSString* const METHOD_NAME_REQUEST_MTU = @"requestMtu"; + +NSString* const METHOD_NAME_GET_KNOWN_DEVICES = @"getKnownDevices"; +NSString* const METHOD_NAME_GET_CONNECTED_DEVICED = @"getConnectedDevices"; + +NSString* const METHOD_NAME_DISCOVERY = @"discovery"; + +NSString* const METHOD_NAME_READ_CHARACTERISTIC = @"readCharacteristic"; +NSString* const METHOD_NAME_READ_CHARACTERISTIC_FOR_SERVICE = @"readCharacteristicForService"; +NSString* const METHOD_NAME_READ_CHARACTERISTIC_FOR_DEVICE = @"readCharacteristicForDevice"; + +NSString* const METHOD_NAME_WRITE_CHARACTERISTIC = @"writeCharacteristic"; +NSString* const METHOD_NAME_WRITE_CHARACTERISTIC_FOR_SERVICE = @"writeCharacteristicForService"; +NSString* const METHOD_NAME_WRITE_CHARACTERISTIC_FOR_DEVICE = @"writeCharacteristicForDevice"; + +NSString* const METHOD_NAME_MONITOR_CHARACTERISTIC = @"monitorCharacteristic"; +NSString* const METHOD_NAME_MONITOR_CHARACTERISTIC_FOR_SERVICE = @"monitorCharacteristicForService"; +NSString* const METHOD_NAME_MONITOR_CHARACTERISTIC_FOR_DEVICE = @"monitorCharacteristicForDevice"; + +NSString* const METHOD_NAME_READ_DESCRIPTOR = @"readDescriptor"; +NSString* const METHOD_NAME_READ_DESCRIPTOR_FOR_CHARACTERISTIC = @"readDescriptorForCharacteristic"; +NSString* const METHOD_NAME_READ_DESCRIPTOR_FOR_SERVICE = @"readDescriptorForService"; +NSString* const METHOD_NAME_READ_DESCRIPTOR_FOR_DEVICE = @"readDescriptorForDevice"; + +NSString* const METHOD_NAME_WRITE_DESCRIPTOR = @"writeDescriptor"; +NSString* const METHOD_NAME_WRITE_DESCRIPTOR_FOR_CHARACTERISTIC = @"writeDescriptorForCharacteristic"; +NSString* const METHOD_NAME_WRITE_DESCRIPTOR_FOR_SERVICE = @"writeDescriptorForService"; +NSString* const METHOD_NAME_WRITE_DESCRIPTOR_FOR_DEVICE = @"writeDescriptorForDevice"; + +NSString* const METHOD_NAME_CANCEL_TRANSACTION = @"cancelTransaction"; diff --git a/ios/Names/NativeArgumentName.h b/ios/Names/NativeArgumentName.h new file mode 100644 index 0000000..8789a02 --- /dev/null +++ b/ios/Names/NativeArgumentName.h @@ -0,0 +1,42 @@ +//UNIVERSAL +extern NSString* const NAT_ARG_ERROR; +extern NSString* const NAT_ARG_ID; +extern NSString* const NAT_ARG_VALUE; + +//ERROR +extern NSString* const NAT_ARG_ERROR_CODE; +extern NSString* const NAT_ARG_ERROR_MESSAGE; +extern NSString* const NAT_ARG_ERROR_DEVICE_ID; +extern NSString* const NAT_ARG_ERROR_SERVICE_UUID; +extern NSString* const NAT_ARG_ERROR_CHARACTERISTIC_UUID; +extern NSString* const NAT_ARG_ERROR_DESCRIPTOR_UUID; + +//ScanResult +extern NSString* const NAT_ARG_NAME; +extern NSString* const NAT_ARG_RSSI; +extern NSString* const NAT_ARG_TX_POWER_LEVEL; +extern NSString* const NAT_ARG_OVERFLOW_SERVICE_UUIDS; +extern NSString* const NAT_ARG_SERVICE_DATA; +extern NSString* const NAT_ARG_SERVICE_UUIDS; +extern NSString* const NAT_ARG_SOLICITED_SERVICE_UUIDS; +extern NSString* const NAT_ARG_MANUFACTURER_DATA; +extern NSString* const NAT_ARG_LOCAL_NAME; + +//Discovery +extern NSString* const NAT_ARG_DEVICE_ID; +extern NSString* const NAT_ARG_UUID; +extern NSString* const NAT_ARG_CHARACTERISTICS; +extern NSString* const NAT_ARG_SERVICE_ID; +extern NSString* const NAT_ARG_SERVICE_UUID; +extern NSString* const NAT_ARG_IS_READABLE; +extern NSString* const NAT_ARG_IS_WRITABLE_WITHOUT_RESPONSE; +extern NSString* const NAT_ARG_IS_WRITABLE_WITH_RESPONSE; +extern NSString* const NAT_ARG_IS_NOTIFIABLE; +extern NSString* const NAT_ARG_IS_INDICATABLE; +extern NSString* const NAT_ARG_IS_NOTIFYING; +extern NSString* const NAT_ARG_DESCRIPTORS; +extern NSString* const NAT_ARG_CHARACTERISTIC_ID; +extern NSString* const NAT_ARG_CHARACTERISTIC_UUID; + +//RequestMtu +extern NSString* const NAT_ARG_MTU; diff --git a/ios/Names/NativeArgumentName.m b/ios/Names/NativeArgumentName.m new file mode 100644 index 0000000..ad5ec6c --- /dev/null +++ b/ios/Names/NativeArgumentName.m @@ -0,0 +1,42 @@ +//UNIVERSAL +NSString* const NAT_ARG_ERROR = @"error"; +NSString* const NAT_ARG_ID = @"id"; +NSString* const NAT_ARG_VALUE = @"value"; + +//ERROR +NSString* const NAT_ARG_ERROR_CODE = @"errorCode"; +NSString* const NAT_ARG_ERROR_MESSAGE = @"message"; +NSString* const NAT_ARG_ERROR_DEVICE_ID = @"deviceId"; +NSString* const NAT_ARG_ERROR_SERVICE_UUID = @"serviceUuid"; +NSString* const NAT_ARG_ERROR_CHARACTERISTIC_UUID = @"characteristicUuid"; +NSString* const NAT_ARG_ERROR_DESCRIPTOR_UUID = @"descriptorUuid"; + +//ScanResult +NSString* const NAT_ARG_NAME = @"name"; +NSString* const NAT_ARG_RSSI = @"rssi"; +NSString* const NAT_ARG_TX_POWER_LEVEL = @"txPowerLeveL"; +NSString* const NAT_ARG_OVERFLOW_SERVICE_UUIDS = @"overflowServiceUuids"; +NSString* const NAT_ARG_SERVICE_DATA = @"serviceData"; +NSString* const NAT_ARG_SERVICE_UUIDS = @"serviceUuids"; +NSString* const NAT_ARG_SOLICITED_SERVICE_UUIDS = @"solicitedServiceUuids"; +NSString* const NAT_ARG_MANUFACTURER_DATA = @"manufacturerData"; +NSString* const NAT_ARG_LOCAL_NAME = @"localName"; + +//Discovery +NSString* const NAT_ARG_DEVICE_ID = @"peripheralId"; +NSString* const NAT_ARG_UUID = @"uuid"; +NSString* const NAT_ARG_CHARACTERISTICS = @"characteristics"; +NSString* const NAT_ARG_SERVICE_ID = @"serviceId"; +NSString* const NAT_ARG_SERVICE_UUID = @"serviceUuid"; +NSString* const NAT_ARG_IS_READABLE = @"isReadable"; +NSString* const NAT_ARG_IS_WRITABLE_WITHOUT_RESPONSE = @"isWritableWithoutResponse"; +NSString* const NAT_ARG_IS_WRITABLE_WITH_RESPONSE = @"isWritableWithResponse"; +NSString* const NAT_ARG_IS_NOTIFIABLE = @"isNotifiable"; +NSString* const NAT_ARG_IS_INDICATABLE = @"isIndicatable"; +NSString* const NAT_ARG_IS_NOTIFYING = @"isNotifying"; +NSString* const NAT_ARG_DESCRIPTORS = @"descriptors"; +NSString* const NAT_ARG_CHARACTERISTIC_ID = @"characteristicId"; +NSString* const NAT_ARG_CHARACTERISTIC_UUID = @"characteristicUuid"; + +//RequestMtu +NSString* const NAT_ARG_MTU = @"mtu"; diff --git a/ios/Parsers/DeviceParser.h b/ios/Parsers/DeviceParser.h new file mode 100644 index 0000000..ae9897d --- /dev/null +++ b/ios/Parsers/DeviceParser.h @@ -0,0 +1,13 @@ +// +// DeviceParser.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef DeviceParser_h +#define DeviceParser_h + + +#endif /* DeviceParser_h */ diff --git a/ios/Parsers/DeviceParser.m b/ios/Parsers/DeviceParser.m new file mode 100644 index 0000000..30250ea --- /dev/null +++ b/ios/Parsers/DeviceParser.m @@ -0,0 +1,9 @@ +// +// DeviceParser.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Parsers/ErrorParser.h b/ios/Parsers/ErrorParser.h new file mode 100644 index 0000000..7f58078 --- /dev/null +++ b/ios/Parsers/ErrorParser.h @@ -0,0 +1,13 @@ +// +// ErrorParser.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef ErrorParser_h +#define ErrorParser_h + + +#endif /* ErrorParser_h */ diff --git a/ios/Parsers/ErrorParser.m b/ios/Parsers/ErrorParser.m new file mode 100644 index 0000000..8a83949 --- /dev/null +++ b/ios/Parsers/ErrorParser.m @@ -0,0 +1,9 @@ +// +// ErrorParser.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import diff --git a/ios/Parsers/GattParser.h b/ios/Parsers/GattParser.h new file mode 100644 index 0000000..08cadb0 --- /dev/null +++ b/ios/Parsers/GattParser.h @@ -0,0 +1,13 @@ +// +// GattParser.h +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#ifndef GattParser_h +#define GattParser_h + + +#endif /* GattParser_h */ diff --git a/ios/Parsers/GattParser.m b/ios/Parsers/GattParser.m new file mode 100644 index 0000000..bd65312 --- /dev/null +++ b/ios/Parsers/GattParser.m @@ -0,0 +1,9 @@ +// +// GattParser.m +// Blemulator +// +// Created by Mikolaj Kojdecki on 30/07/2020. +// Copyright © 2020 Facebook. All rights reserved. +// + +#import