format OC code

This commit is contained in:
pengfei.zhou
2019-10-12 14:48:19 +08:00
parent 820f1e9f8c
commit f9b599e7cf
43 changed files with 493 additions and 472 deletions

View File

@@ -10,9 +10,9 @@
#import "DoricConstant.h"
#import "DoricWSClient.h"
@interface DoricDriver()
@property (nonatomic, strong) DoricJSEngine *jsExecutor;
@property (nonatomic, strong) DoricWSClient *wsclient;
@interface DoricDriver ()
@property(nonatomic, strong) DoricJSEngine *jsExecutor;
@property(nonatomic, strong) DoricWSClient *wsclient;
@end
@implementation DoricDriver
@@ -20,7 +20,7 @@ @implementation DoricDriver
@dynamic registry;
- (instancetype)init {
if(self = [super init]){
if (self = [super init]) {
_jsExecutor = [[DoricJSEngine alloc] init];
}
return self;
@@ -30,7 +30,7 @@ - (DoricRegistry *)registry {
return self.jsExecutor.registry;
}
+ (instancetype)instance{
+ (instancetype)instance {
static DoricDriver *_instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@@ -39,7 +39,7 @@ + (instancetype)instance{
return _instance;
}
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method, ... {
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method, ... {
va_list args;
va_start(args, method);
DoricAsyncResult *ret = [self invokeDoricMethod:method arguments:args];
@@ -47,15 +47,15 @@ + (instancetype)instance{
return ret;
}
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
NSMutableArray *array = [[NSMutableArray alloc] init];
id arg;
while((arg = va_arg(args, id)) != nil){
while ((arg = va_arg(args, id)) != nil) {
[array addObject:arg];
}
__weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){
dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self;
if (!self) return;
@try {
@@ -68,7 +68,7 @@ + (instancetype)instance{
return ret;
}
- (DoricAsyncResult<JSValue *> *)invokeContextEntity:(NSString *)contextId method:(NSString *)method,... {
- (DoricAsyncResult<JSValue *> *)invokeContextEntity:(NSString *)contextId method:(NSString *)method, ... {
va_list args;
va_start(args, method);
DoricAsyncResult *ret = [self invokeContextEntity:contextId method:method arguments:args];
@@ -82,12 +82,12 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
[array addObject:contextId];
[array addObject:method];
id arg = va_arg(args, id);
while(arg != nil){
while (arg != nil) {
[array addObject:arg];
arg = va_arg(args, JSValue *);
}
__weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){
dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self;
if (!self) return;
@try {
@@ -99,16 +99,17 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
});
return ret;
}
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:contextId];
[array addObject:method];
for (id arg in args){
[array addObject: arg];
for (id arg in args) {
[array addObject:arg];
}
__weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){
dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self;
if (!self) return;
@try {
@@ -124,10 +125,10 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
- (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
__weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){
dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self;
if(!self) return;
@try{
if (!self) return;
@try {
[self.jsExecutor prepareContext:contextId script:script source:source];
[ret setupResult:[NSNumber numberWithBool:YES]];
} @catch (NSException *exception) {
@@ -140,10 +141,10 @@ - (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)scr
- (DoricAsyncResult *)destroyContext:(NSString *)contextId {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
__weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){
dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self;
if(!self) return;
@try{
if (!self) return;
@try {
[self.jsExecutor destroyContext:contextId];
[ret setupResult:[NSNumber numberWithBool:YES]];
} @catch (NSException *exception) {
@@ -154,14 +155,14 @@ - (DoricAsyncResult *)destroyContext:(NSString *)contextId {
}
- (void)connectDevKit:(NSString *)url {
if(self.wsclient) {
if (self.wsclient) {
[self.wsclient close];
}
self.wsclient = [[DoricWSClient alloc] initWithUrl:url];
}
- (void)disconnectDevKit {
if(self.wsclient) {
if (self.wsclient) {
[self.wsclient close];
self.wsclient = nil;
}