Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions android/src/main/java/com/polidea/blemulator/JsCallHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ public class JsCallHandler {
private int nextCallId = 0;
private Map<String, Callback> callbacks = new HashMap<>();

public String getNextCallbackId() {
return Integer.toString(nextCallId++);
}

public String addCallback(Callback callback) {
String callId = getNextCallbackId();
callbacks.put(callId, callback);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -40,7 +40,7 @@ public interface NativeArgumentName {
String DESCRIPTORS = "descriptors";
String CHARACTERISTIC_ID = "characteristicId";
String CHARACTERISTIC_UUID = "characteristicUuid";

//RequestMtu
String MTU = "mtu";
}
108 changes: 108 additions & 0 deletions ios/Blemulator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 = "<group>"; };
1033FA1A24642D06003B0C50 /* SimulatedAdapter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SimulatedAdapter.m; sourceTree = "<group>"; };
10C7A84A24D2F8F600BC92D6 /* CachedCharacteristic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CachedCharacteristic.h; sourceTree = "<group>"; };
10C7A84B24D2F90600BC92D6 /* CachedService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CachedService.h; sourceTree = "<group>"; };
10C7A84C24D2F91800BC92D6 /* DeviceContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceContainer.h; sourceTree = "<group>"; };
10C7A84D24D2F92800BC92D6 /* DeviceManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceManager.h; sourceTree = "<group>"; };
10C7A84E24D2F94B00BC92D6 /* CachedCharacteristic.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CachedCharacteristic.m; sourceTree = "<group>"; };
10C7A85024D2F95D00BC92D6 /* CachedService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CachedService.m; sourceTree = "<group>"; };
10C7A85224D2F96B00BC92D6 /* DeviceContainer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceContainer.m; sourceTree = "<group>"; };
10C7A85424D2F97900BC92D6 /* DeviceManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceManager.m; sourceTree = "<group>"; };
10C7A85724D2FA2700BC92D6 /* DeviceParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceParser.h; sourceTree = "<group>"; };
10C7A85824D2FA4100BC92D6 /* ErrorParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ErrorParser.h; sourceTree = "<group>"; };
10C7A85924D2FA5200BC92D6 /* GattParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GattParser.h; sourceTree = "<group>"; };
10C7A85A24D2FA6300BC92D6 /* DeviceParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceParser.m; sourceTree = "<group>"; };
10C7A85C24D2FA7700BC92D6 /* ErrorParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ErrorParser.m; sourceTree = "<group>"; };
10C7A85E24D2FA8800BC92D6 /* GattParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GattParser.m; sourceTree = "<group>"; };
10C7A86124D2FACC00BC92D6 /* JsArgumentName.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JsArgumentName.h; sourceTree = "<group>"; };
10C7A86224D2FAE200BC92D6 /* NativeArgumentName.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NativeArgumentName.h; sourceTree = "<group>"; };
10C7A86324D2FAF400BC92D6 /* MethodName.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MethodName.h; sourceTree = "<group>"; };
10C7A86424D2FB0500BC92D6 /* JsArgumentName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JsArgumentName.m; sourceTree = "<group>"; };
10C7A86624D2FB5E00BC92D6 /* NativeArgumentName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NativeArgumentName.m; sourceTree = "<group>"; };
10C7A86924D2FB7500BC92D6 /* MethodName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MethodName.m; sourceTree = "<group>"; };
10C7A86C24D2FBB200BC92D6 /* JsCallHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JsCallHandler.m; sourceTree = "<group>"; };
10C7A87024D2FBDB00BC92D6 /* PlatformToJsBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlatformToJsBridge.m; sourceTree = "<group>"; };
10C7A87224D2FC1900BC92D6 /* JsCallHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JsCallHandler.h; sourceTree = "<group>"; };
10C7A87424D2FC4200BC92D6 /* PlatformToJsBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformToJsBridge.h; sourceTree = "<group>"; };
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 = "<group>"; };
10D74E91246453F700C37BC0 /* BlemulatorCommonTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlemulatorCommonTypes.h; sourceTree = "<group>"; };
134814201AA4EA6300B7C361 /* libBlemulator.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBlemulator.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -41,13 +79,66 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
10C7A87624D43C9300BC92D6 /* Foundation.framework in Frameworks */,
320F8AB317FF97AAD1EA62E8 /* Pods_Blemulator.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* 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 = "<group>";
};
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 = "<group>";
};
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 = "<group>";
};
10C7A86B24D2FB9000BC92D6 /* Bridging */ = {
isa = PBXGroup;
children = (
10C7A86C24D2FBB200BC92D6 /* JsCallHandler.m */,
10C7A87024D2FBDB00BC92D6 /* PlatformToJsBridge.m */,
10C7A87224D2FC1900BC92D6 /* JsCallHandler.h */,
10C7A87424D2FC4200BC92D6 /* PlatformToJsBridge.h */,
);
path = Bridging;
sourceTree = "<group>";
};
10D74E90246453DC00C37BC0 /* Util */ = {
isa = PBXGroup;
children = (
Expand All @@ -67,6 +158,10 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
10C7A86B24D2FB9000BC92D6 /* Bridging */,
10C7A86024D2FAB600BC92D6 /* Names */,
10C7A85624D2FA0D00BC92D6 /* Parsers */,
10C7A84924D2F8C800BC92D6 /* Containers */,
10D74E90246453DC00C37BC0 /* Util */,
10D74E8F24644F7B00C37BC0 /* SimulatedAdapter.h */,
1033FA1A24642D06003B0C50 /* SimulatedAdapter.m */,
Expand All @@ -90,6 +185,7 @@
C0CA31E543A1A53F13864080 /* Frameworks */ = {
isa = PBXGroup;
children = (
10C7A87524D43C9300BC92D6 /* Foundation.framework */,
81432FA2EACC1C10AF962CAB /* Pods_Blemulator.framework */,
);
name = Frameworks;
Expand Down Expand Up @@ -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;
};
Expand Down
13 changes: 13 additions & 0 deletions ios/Bridging/JsCallCallback.h
Original file line number Diff line number Diff line change
@@ -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 */
9 changes: 9 additions & 0 deletions ios/Bridging/JsCallCallback.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// JsCallCallback.m
// Blemulator
//
// Created by Mikolaj Kojdecki on 30/07/2020.
// Copyright © 2020 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
14 changes: 14 additions & 0 deletions ios/Bridging/JsCallHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <Foundation/Foundation.h>

typedef void (^JsCallback)(id result);

@interface JsCallHandler : NSObject

- (instancetype)init;

- (NSString*)addCallback:(JsCallback)callback;

- (void)handleReturnCallWithId:(NSString *)callId
args:(NSDictionary*)args;

@end
40 changes: 40 additions & 0 deletions ios/Bridging/JsCallHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#import "JsCallHandler.h"

@interface JsCallHandler()

@property (nonatomic) int nextCallbackId;
@property (nonatomic) NSMutableDictionary<NSString*, JsCallback>* 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
15 changes: 15 additions & 0 deletions ios/Bridging/PlatformToJsBridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import <Foundation/Foundation.h>
#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
9 changes: 9 additions & 0 deletions ios/Bridging/PlatformToJsBridge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// PlatformToJsBridge.m
// Blemulator
//
// Created by Mikolaj Kojdecki on 30/07/2020.
// Copyright © 2020 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
13 changes: 13 additions & 0 deletions ios/Containers/CachedCharacteristic.h
Original file line number Diff line number Diff line change
@@ -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 */
9 changes: 9 additions & 0 deletions ios/Containers/CachedCharacteristic.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// CachedCharacteristic.m
// Blemulator
//
// Created by Mikolaj Kojdecki on 30/07/2020.
// Copyright © 2020 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
13 changes: 13 additions & 0 deletions ios/Containers/CachedService.h
Original file line number Diff line number Diff line change
@@ -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 */
9 changes: 9 additions & 0 deletions ios/Containers/CachedService.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// CachedService.m
// Blemulator
//
// Created by Mikolaj Kojdecki on 30/07/2020.
// Copyright © 2020 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
13 changes: 13 additions & 0 deletions ios/Containers/DeviceContainer.h
Original file line number Diff line number Diff line change
@@ -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 */
9 changes: 9 additions & 0 deletions ios/Containers/DeviceContainer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// DeviceContainer.m
// Blemulator
//
// Created by Mikolaj Kojdecki on 30/07/2020.
// Copyright © 2020 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
Loading