Skip to content

Commit

Permalink
Merge pull request #49 from alibaba/release/1.2.0
Browse files Browse the repository at this point in the history
Release/1.2.0
  • Loading branch information
SoXeon authored Feb 9, 2017
2 parents 393c45a + c4e0be8 commit a70b491
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 109 deletions.
2 changes: 1 addition & 1 deletion BeeHive.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |s|

s.name = "BeeHive"
s.version = "1.1.2"
s.version = "1.2.0"
s.summary = "BeeHive is a kind of modular programming method"

s.description = <<-DESC
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions BeeHive/BHAnnotation.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//
// BHAnnotation.h
// Pods
//
// Created by 寻峰 on 2016/11/5.
//
//
/**
* Created by BeeHive.
* Copyright (c) 2016, Alibaba, Inc. All rights reserved.
*
* This source code is licensed under the GNU GENERAL PUBLIC LICENSE.
* For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
*/


#import <Foundation/Foundation.h>

Expand Down
15 changes: 8 additions & 7 deletions BeeHive/BHAnnotation.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//
// BHAnnotation.m
// Pods
//
// Created by 寻峰 on 2016/11/5.
//
//
/**
* Created by BeeHive.
* Copyright (c) 2016, Alibaba, Inc. All rights reserved.
*
* This source code is licensed under the GNU GENERAL PUBLIC LICENSE.
* For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
*/


#import "BHAnnotation.h"
#import "BHCommon.h"
Expand Down
9 changes: 2 additions & 7 deletions BeeHive/BHAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

@interface BHAppDelegate ()

@property (nonatomic, strong) BHTimeProfiler *timeProfiler;

@end

@implementation BHAppDelegate
Expand All @@ -26,9 +24,6 @@ @implementation BHAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef DEBUG
self.timeProfiler = [BHTimeProfiler sharedTimeProfiler];
#endif

[[BHModuleManager sharedManager] triggerEvent:BHMSetupEvent];
[[BHModuleManager sharedManager] triggerEvent:BHMInitEvent];
Expand All @@ -38,8 +33,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
});

#ifdef DEBUG
[self.timeProfiler printOutTimeProfileResult];
[self.timeProfiler saveTimeProfileDataIntoFile:@"BeeHiveTimeProfiler"];
[[BHTimeProfiler sharedTimeProfiler] printOutTimeProfileResult];
[[BHTimeProfiler sharedTimeProfiler] saveTimeProfileDataIntoFile:@"BeeHiveTimeProfiler"];
#endif

return YES;
Expand Down
9 changes: 4 additions & 5 deletions BeeHive/BHContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ typedef enum

@property(nonatomic, strong) NSString *serviceConfigName;

@property(nonatomic, strong) NSMutableDictionary *modulesByName;

@property(nonatomic, strong) NSMutableDictionary *servicesByName;

//3D-Touch model
#if __IPHONE_OS_VERSION_MAX_ALLOWED > 80400
@property (nonatomic, strong) BHShortcutItem *touchShortcutItem;
Expand All @@ -59,7 +55,10 @@ typedef enum
//user Activity Model
@property (nonatomic, strong) BHUserActivityItem *userActivityItem;

+(instancetype) shareInstance;
+ (instancetype)shareInstance;

- (void)addServiceWithImplInstance:(id)implInstance serviceName:(NSString *)serviceName;

- (id)getServiceInstanceFromServiceName:(NSString *)serviceName;

@end
46 changes: 28 additions & 18 deletions BeeHive/BHContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,42 @@

#import "BHContext.h"


@interface BHContext()

@property(nonatomic, strong) NSMutableDictionary *modulesByName;

@property(nonatomic, strong) NSMutableDictionary *servicesByName;

@end

@implementation BHContext

-(instancetype)init
+ (instancetype)shareInstance
{
static dispatch_once_t p;
static id BHInstance = nil;

dispatch_once(&p, ^{
BHInstance = [[[self class] alloc] init];
if ([BHInstance isKindOfClass:[BHContext class]]) {
((BHContext *) BHInstance).config = [BHConfig shareInstance];
}
});

return BHInstance;
}

- (void)addServiceWithImplInstance:(id)implInstance serviceName:(NSString *)serviceName
{
[[BHContext shareInstance].servicesByName setObject:implInstance forKey:serviceName];
}

- (id)getServiceInstanceFromServiceName:(NSString *)serviceName
{
return [[BHContext shareInstance].servicesByName objectForKey:serviceName];
}

- (instancetype)init
{
self = [super init];
if (self) {
Expand All @@ -38,20 +64,4 @@ -(instancetype)init
return self;
}

+(instancetype) shareInstance
{
static dispatch_once_t p;
static id BHInstance = nil;

dispatch_once(&p, ^{
BHInstance = [[[self class] alloc] init];
if ([BHInstance isKindOfClass:[BHContext class]]) {
((BHContext *) BHInstance).config = [BHConfig shareInstance];
}
});

return BHInstance;
}


@end
7 changes: 0 additions & 7 deletions BeeHive/BHModuleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#import <Foundation/Foundation.h>

@class BHContext;

typedef NS_ENUM(NSUInteger, BHModuleLevel)
{
BHModuleBasic = 0,
Expand Down Expand Up @@ -48,11 +46,6 @@ typedef NS_ENUM(NSInteger, BHModuleEventType)

@interface BHModuleManager : NSObject

@property (nonatomic, strong) NSString *modulesConfigFilename;

@property (nonatomic, strong) BHContext *wholeContext;


+ (instancetype)sharedManager;

// If you do not comply with set Level protocol, the default Normal
Expand Down
22 changes: 5 additions & 17 deletions BeeHive/BHModuleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ @interface BHModuleManager()

@property(nonatomic, strong) NSMutableArray *BHModules;


@end

@implementation BHModuleManager
Expand All @@ -59,15 +58,15 @@ + (instancetype)sharedManager
static id sharedManager = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
sharedManager = [[self alloc] init];
sharedManager = [[BHModuleManager alloc] init];
});
return sharedManager;
}

- (void)loadLocalModules
{

NSString *plistPath = [[NSBundle mainBundle] pathForResource:self.modulesConfigFilename ofType:@"plist"];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:[BHContext shareInstance].moduleConfigName ofType:@"plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
return;
}
Expand Down Expand Up @@ -285,17 +284,6 @@ - (void)addModuleFromObject:(id)object

#pragma mark - property setter or getter

- (void)setModulesConfigFilename:(NSString *)modulesConfigFilename
{
_modulesConfigFilename = modulesConfigFilename;
}

- (void)setWholeContext:(BHContext *)wholeContext
{
_wholeContext = wholeContext;
self.modulesConfigFilename = _wholeContext.moduleConfigName;
}

- (NSMutableArray *)BHModules
{
if (!_BHModules) {
Expand All @@ -316,7 +304,7 @@ - (void)handleModulesInitEvent
__strong typeof(&*self) sself = wself;
if (sself) {
if ([moduleInstance respondsToSelector:@selector(modInit:)]) {
[moduleInstance modInit:sself.wholeContext];
[moduleInstance modInit:[BHContext shareInstance]];
}
}
};
Expand Down Expand Up @@ -346,7 +334,7 @@ - (void)handleModulesTearDownEvent
for (int i = (int)self.BHModules.count - 1; i >= 0; i--) {
id<BHModuleProtocol> moduleInstance = [self.BHModules objectAtIndex:i];
if (moduleInstance && [moduleInstance respondsToSelector:@selector(modTearDown:)]) {
[moduleInstance modTearDown:self.wholeContext];
[moduleInstance modTearDown:[BHContext shareInstance]];
}
}
}
Expand All @@ -358,7 +346,7 @@ - (void)handleModuleEvent:(NSString *)selectorStr
if ([moduleInstance respondsToSelector:seletor]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[moduleInstance performSelector:seletor withObject:self.wholeContext];
[moduleInstance performSelector:seletor withObject:[BHContext shareInstance]];
#pragma clang diagnostic pop

[[BHTimeProfiler sharedTimeProfiler] recordEventTime:[NSString stringWithFormat:@"%@ --- %@", [moduleInstance class], NSStringFromSelector(seletor)]];
Expand Down
3 changes: 0 additions & 3 deletions BeeHive/BHServiceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

@interface BHServiceManager : NSObject

@property (nonatomic, strong) BHContext *wholeContext;

@property (nonatomic, assign) BOOL enableException;


+ (instancetype)sharedManager;

- (void)registerLocalServices;
Expand Down
20 changes: 6 additions & 14 deletions BeeHive/BHServiceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,11 @@ + (instancetype)sharedManager
return sharedManager;
}

- (instancetype)init
{
self = [super init];
if (self) {
}
return self;
}

- (void)registerLocalServices
{
NSString *serviceConfigName = self.wholeContext.serviceConfigName;
NSString *serviceConfigName = [BHContext shareInstance].serviceConfigName;

NSString *plistPath = [[NSBundle mainBundle] pathForResource:serviceConfigName ofType:@"plist"];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:serviceConfigName ofType:@"plist"];
if (!plistPath) {
return;
}
Expand Down Expand Up @@ -122,16 +114,16 @@ - (id)createService:(Protocol *)service
NSString *serviceStr = NSStringFromProtocol(service);

if ([implInstance singleton]) {
id protocol = [[BHContext shareInstance].servicesByName objectForKey:serviceStr];
id protocol = [[BHContext shareInstance] getServiceInstanceFromServiceName:serviceStr];

if (protocol) {
return protocol;
} else {
[[BHContext shareInstance].servicesByName setObject:implInstance forKey:serviceStr];
[[BHContext shareInstance] addServiceWithImplInstance:implInstance serviceName:serviceStr];
}

} else {
[[BHContext shareInstance].servicesByName setObject:implInstance forKey:serviceStr];
[[BHContext shareInstance] addServiceWithImplInstance:implInstance serviceName:serviceStr];
}

return implInstance;
Expand Down Expand Up @@ -181,7 +173,7 @@ - (NSRecursiveLock *)lock
- (NSArray *)servicesArray
{
[self.lock lock];
NSArray *array = [self.allServices mutableCopy];
NSArray *array = [self.allServices copy];
[self.lock unlock];
return array;
}
Expand Down
21 changes: 7 additions & 14 deletions BeeHive/BeeHive.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

#import "BeeHive.h"


//BootLoader

@interface BeeHive()

@end


@implementation BeeHive

#pragma mark - public
Expand Down Expand Up @@ -63,7 +55,6 @@ -(void)setContext:(BHContext *)context

- (void)loadStaticModules
{
[[BHModuleManager sharedManager] setWholeContext:self.context];

[[BHModuleManager sharedManager] loadLocalModules];

Expand All @@ -77,16 +68,18 @@ -(void)loadStaticServices
{
[BHServiceManager sharedManager].enableException = self.enableException;

[[BHServiceManager sharedManager] setWholeContext:self.context];

[[BHServiceManager sharedManager] registerLocalServices];

[[BHServiceManager sharedManager] registerAnnotationServices];

}
- (void)tiggerCustomEvent:(NSInteger)eventType{
if(eventType<1000)
return;

- (void)tiggerCustomEvent:(NSInteger)eventType
{
if(eventType < 1000) {
return;
}

[[BHModuleManager sharedManager] triggerEvent:eventType];
}

Expand Down
Loading

0 comments on commit a70b491

Please sign in to comment.