Authored by 于良

重新组织代码

... ... @@ -9,8 +9,7 @@
#import <Foundation/Foundation.h>
#import "YH_BridgeModule.h"
@interface UserModule : NSObject <YH_BridgeModule>
@interface UserModule : NSObject
... ...
... ... @@ -7,82 +7,60 @@
//
#import "UserModule.h"
#import "YH_WatchDog.h"
#import "UberSignals.h"
#import <objc/runtime.h>
CreateSignalType(Logged, BOOL logged)
@interface UserModule ()
YH_DECLARE_SIGNAL_PROPERTY(login, Dictionary)
@property (assign, nonatomic) BOOL logged;
@interface UserModule () <YH_BridgeModule>
YH_DECLARE_SIGNAL_PROPERTY(login, Dictionary) // login服务回调signal
@end
@implementation UserModule
@synthesize serviceQueue = _serviceQueue;
@synthesize bridge = _bridge; // YH_WatchDog引用,自动设置
@synthesize serviceQueue = _serviceQueue; // User模块调用所处dispatch queue,自动设置
YH_EXPORT_MODULE()
- (instancetype)init
{
self = [super init];
if (self) {
_logged = YES;
YH_INIT_SIGNAL_PROPERTY(login, Dictionary)
YH_INIT_SIGNAL_PROPERTY(login, Dictionary) // 初始化服务回调signal
}
return self;
}
//- (dispatch_queue_t)serviceQueue
//{
// return dispatch_get_main_queue();
//}
YH_EXPORT_MODULE()
//static char loginServiceQueueKey;
//- (NSOperationQueue *)loginServiceQueue {
// return objc_getAssociatedObject(self, &loginServiceQueueKey);
//}
//
//- (void)setloginServiceQueue:(NSOperationQueue *)value {
// objc_setAssociatedObject(self, &loginServiceQueueKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
//}
//YH_EXPORT_SERVICE(login)
YH_EXPORT_SERVICE_WITH_QUEUE(login)
{
// NSLog(@"call login, param:%@", parameters);
// NSLog(@"------%@", [self loginServiceOperationQueue]);
// NSLog(@"$$$$$$$%@", [self serviceQueue]);
// NSLog(@"&&&&&&&%@", [NSThread currentThread]);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), self.serviceQueue, ^{
NSLog(@"call login, param:%@", parameters);
// 业务逻辑处理
// 回调结果
UBSignalObserver *observer = parameters[YH_CallServiceObserverKey];
if (observer) {
self.loginSignal.fireForSignalObserver(observer, parameters);
}
// self.loginSignal.fire(parameters);
});
}
YH_EXPORT_SERVICE(profile)
{
// NSLog(@"profile, param:%@", parameters);
NSLog(@"call login, param:%@", parameters);
// 调用login服务
NSString *moduleId = @"UserModule";
NSString *serviceId = @"login";
NSInteger uid = 20;
NSString *username = @"Jim";
NSDictionary *param = @{YH_CallServiceModuleIdKey: moduleId,
YH_CallServiceServiceIdKey: serviceId,
YH_CallServiceParametersKey: @{@"uid": @(uid), @"username": username}};
[_bridge callService:param observer:self dictionaryCallback:^(id self, NSDictionary *dictionary) {
// 业务逻辑处理
}];
// 业务逻辑处理
}
//YH_EXPORT_SERVICE(order)
YH_EXPORT_SERVICE_WITH_QUEUE(order)
{
// NSLog(@"order, param:%@", parameters);
}
@end
... ...