Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: alibaba/BeeHive
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.2.0
Choose a base ref
...
head repository: alibaba/BeeHive
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -34,6 +34,8 @@ xcuserdata/
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/
Example/Pods/
Example/Podfile.lock

# Carthage
#
4 changes: 2 additions & 2 deletions BeeHive.podspec
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
Pod::Spec.new do |s|

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

s.description = <<-DESC
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|

s.license = "GPL"

s.platform = :ios, '7.0'
s.platform = :ios, '8.0'

s.author = { "soxeon" => "dpsopower@gmail.com" }

12 changes: 8 additions & 4 deletions BeeHive.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
D85037D31B9C6D8400864DF0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D85037D21B9C6D8400864DF0 /* Foundation.framework */; };
4DB2BE951F1CBDE1006DB06E /* BHRouter.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DB2BE931F1CBDE1006DB06E /* BHRouter.h */; };
4DB2BE961F1CBDE1006DB06E /* BHRouter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DB2BE941F1CBDE1006DB06E /* BHRouter.m */; };
D85037D81B9C6D8400864DF0 /* BeeHive-Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = D85037D71B9C6D8400864DF0 /* BeeHive-Prefix.pch */; };
D85037DA1B9C6D8400864DF0 /* BeeHive-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D85037D91B9C6D8400864DF0 /* BeeHive-Info.plist */; };
D85038001B9C70BE00864DF0 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D85037FF1B9C70BE00864DF0 /* UIKit.framework */; };
D8B050571B9ED5EF004F67D6 /* BeeHive.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B050551B9ED5EF004F67D6 /* BeeHive.h */; settings = {ATTRIBUTES = (Public, ); }; };
D8B050581B9ED5EF004F67D6 /* BeeHive.m in Sources */ = {isa = PBXBuildFile; fileRef = D8B050561B9ED5EF004F67D6 /* BeeHive.m */; };
E20133881E489237000B37DC /* BeeHiveTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E20133871E489237000B37DC /* BeeHiveTests.m */; };
@@ -39,6 +39,8 @@

/* Begin PBXFileReference section */
0E496C5F1E4B277D0012851F /* BHCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BHCommon.h; sourceTree = "<group>"; };
4DB2BE931F1CBDE1006DB06E /* BHRouter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BHRouter.h; sourceTree = "<group>"; };
4DB2BE941F1CBDE1006DB06E /* BHRouter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BHRouter.m; sourceTree = "<group>"; };
D85037CF1B9C6D8400864DF0 /* BeeHive.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework.static; includeInIndex = 0; path = BeeHive.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D85037D21B9C6D8400864DF0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
D85037D61B9C6D8400864DF0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -77,8 +79,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D85038001B9C70BE00864DF0 /* UIKit.framework in Frameworks */,
D85037D31B9C6D8400864DF0 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -143,6 +143,8 @@
E232FEA51CF311EE00CBFA52 /* BHTimeProfiler.m */,
E232FEA81CF311F800CBFA52 /* BHWatchDog.h */,
E232FEA91CF311F800CBFA52 /* BHWatchDog.m */,
4DB2BE931F1CBDE1006DB06E /* BHRouter.h */,
4DB2BE941F1CBDE1006DB06E /* BHRouter.m */,
E22E60111BEB923700C195E4 /* BHModuleProtocol.h */,
E22E60221BEB924200C195E4 /* BHServiceProtocol.h */,
0E496C5F1E4B277D0012851F /* BHCommon.h */,
@@ -197,6 +199,7 @@
E286CAAD1CB4B27A004E6640 /* BHServiceManager.h in Headers */,
F857731A1DCDC275005C8AF5 /* BHAnnotation.h in Headers */,
E22E601A1BEB923700C195E4 /* BHContext.h in Headers */,
4DB2BE951F1CBDE1006DB06E /* BHRouter.h in Headers */,
D8B050571B9ED5EF004F67D6 /* BeeHive.h in Headers */,
D85037D81B9C6D8400864DF0 /* BeeHive-Prefix.pch in Headers */,
);
@@ -342,6 +345,7 @@
F857731B1DCDC275005C8AF5 /* BHAnnotation.m in Sources */,
E22E60191BEB923700C195E4 /* BHConfig.m in Sources */,
E286CAAE1CB4B27A004E6640 /* BHServiceManager.m in Sources */,
4DB2BE961F1CBDE1006DB06E /* BHRouter.m in Sources */,
E232FEA71CF311EE00CBFA52 /* BHTimeProfiler.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
8 changes: 3 additions & 5 deletions BeeHive/BHAnnotation.h
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@


#import <Foundation/Foundation.h>
#import "BeeHive.h"

#ifndef BeehiveModSectName

@@ -27,14 +28,11 @@


#define BeeHiveMod(name) \
char * k##name##_mod BeeHiveDATA(BeehiveMods) = ""#name"";
class BeeHive; char * k##name##_mod BeeHiveDATA(BeehiveMods) = ""#name"";

#define BeeHiveService(servicename,impl) \
char * k##servicename##_service BeeHiveDATA(BeehiveServices) = "{ \""#servicename"\" : \""#impl"\"}";
class BeeHive; char * k##servicename##_service BeeHiveDATA(BeehiveServices) = "{ \""#servicename"\" : \""#impl"\"}";

@interface BHAnnotation : NSObject

+ (NSArray<NSString *> *)AnnotationModules;
+ (NSArray<NSString *> *)AnnotationServices;

@end
88 changes: 54 additions & 34 deletions BeeHive/BHAnnotation.m
Original file line number Diff line number Diff line change
@@ -15,27 +15,63 @@
#include <dlfcn.h>
#import <objc/runtime.h>
#import <objc/message.h>
static NSArray<NSString *>* BHReadConfiguration(char *section)
#include <mach-o/ldsyms.h>

NSArray<NSString *>* BHReadConfiguration(char *sectionName,const struct mach_header *mhp);
static void dyld_callback(const struct mach_header *mhp, intptr_t vmaddr_slide)
{
NSMutableArray *configs = [NSMutableArray array];
NSArray *mods = BHReadConfiguration(BeehiveModSectName, mhp);
for (NSString *modName in mods) {
Class cls;
if (modName) {
cls = NSClassFromString(modName);

if (cls) {
[[BHModuleManager sharedManager] registerDynamicModule:cls];
}
}
}

Dl_info info;
dladdr(BHReadConfiguration, &info);
//register services
NSArray<NSString *> *services = BHReadConfiguration(BeehiveServiceSectName,mhp);
for (NSString *map in services) {
NSData *jsonData = [map dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (!error) {
if ([json isKindOfClass:[NSDictionary class]] && [json allKeys].count) {

NSString *protocol = [json allKeys][0];
NSString *clsName = [json allValues][0];

if (protocol && clsName) {
[[BHServiceManager sharedManager] registerService:NSProtocolFromString(protocol) implClass:NSClassFromString(clsName)];
}

}
}
}

#ifndef __LP64__
// const struct mach_header *mhp = _dyld_get_image_header(0); // both works as below line
const struct mach_header *mhp = (struct mach_header*)info.dli_fbase;
unsigned long size = 0;
uint32_t *memory = (uint32_t*)getsectiondata(mhp, "__DATA", section, & size);
#else /* defined(__LP64__) */
const struct mach_header_64 *mhp = (struct mach_header_64*)info.dli_fbase;
}
__attribute__((constructor))
void initProphet() {
_dyld_register_func_for_add_image(dyld_callback);
}

NSArray<NSString *>* BHReadConfiguration(char *sectionName,const struct mach_header *mhp)
{
NSMutableArray *configs = [NSMutableArray array];
unsigned long size = 0;
uint64_t *memory = (uint64_t*)getsectiondata(mhp, "__DATA", section, & size);
#endif /* defined(__LP64__) */
#ifndef __LP64__
uintptr_t *memory = (uintptr_t*)getsectiondata(mhp, SEG_DATA, sectionName, &size);
#else
const struct mach_header_64 *mhp64 = (const struct mach_header_64 *)mhp;
uintptr_t *memory = (uintptr_t*)getsectiondata(mhp64, SEG_DATA, sectionName, &size);
#endif

for(int idx = 0; idx < size/sizeof(void*); ++idx){
unsigned long counter = size/sizeof(void*);
for(int idx = 0; idx < counter; ++idx){
char *string = (char*)memory[idx];

NSString *str = [NSString stringWithUTF8String:string];
if(!str)continue;

@@ -44,28 +80,12 @@
}

return configs;


}

@implementation BHAnnotation

+ (NSArray<NSString *> *)AnnotationModules
{
static NSArray<NSString *> *mods = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
mods = BHReadConfiguration(BeehiveModSectName);
});
return mods;
}
@end

+ (NSArray<NSString *> *)AnnotationServices
{
static NSArray<NSString *> *services = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
services = BHReadConfiguration(BeehiveServiceSectName);
});
return services;
}

@end
39 changes: 31 additions & 8 deletions BeeHive/BHAppDelegate.h
Original file line number Diff line number Diff line change
@@ -8,53 +8,76 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
#import <UserNotifications/UserNotifications.h>
#endif


@interface BHAppDelegate : UIResponder <UIApplicationDelegate>

@end

typedef void (^notificationResultHandler)(UIBackgroundFetchResult);
typedef void (^BHNotificationResultHandler)(UIBackgroundFetchResult);
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
typedef void (^BHNotificationPresentationOptionsHandler)(UNNotificationPresentationOptions options);
typedef void (^BHNotificationCompletionHandler)();
#endif

@interface BHNotificationsItem : NSObject

@property (nonatomic, strong) NSError *notificationsError;
@property (nonatomic, strong) NSData *deviceToken;
@property (nonatomic, strong) NSDictionary *userInfo;
@property (nonatomic, assign) notificationResultHandler notificationResultHander;
@property (nonatomic, copy) BHNotificationResultHandler notificationResultHander;
@property (nonatomic, strong) UILocalNotification *localNotification;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
@property (nonatomic, strong) UNNotification *notification;
@property (nonatomic, strong) UNNotificationResponse *notificationResponse;
@property (nonatomic, copy) BHNotificationPresentationOptionsHandler notificationPresentationOptionsHandler;
@property (nonatomic, copy) BHNotificationCompletionHandler notificationCompletionHandler;
@property (nonatomic, strong) UNUserNotificationCenter *center;
#endif

@end

@interface BHOpenURLItem : NSObject

@property (nonatomic, strong) NSURL *openURL;
@property (nonatomic, strong) NSString *sourceApplication;
@property (nonatomic, copy) NSString *sourceApplication;
@property (nonatomic, strong) id annotation;
@property (nonatomic, strong) NSDictionary *options;

@end

typedef void (^shortcutItemCompletionHandler)(BOOL);
typedef void (^BHShortcutCompletionHandler)(BOOL);

@interface BHShortcutItem : NSObject

#if __IPHONE_OS_VERSION_MAX_ALLOWED > 80400
@property(nonatomic, strong) UIApplicationShortcutItem *shortcutItem;
@property(nonatomic, copy) shortcutItemCompletionHandler scompletionHandler;
@property(nonatomic, copy) BHShortcutCompletionHandler scompletionHandler;
#endif

@end


typedef void (^restorationHandler)(NSArray *);
typedef void (^BHUserActivityRestorationHandler)(NSArray *);

@interface BHUserActivityItem : NSObject

@property (nonatomic, strong) NSString *userActivityType;
@property (nonatomic, copy) NSString *userActivityType;
@property (nonatomic, strong) NSUserActivity *userActivity;
@property (nonatomic, strong) NSError *userActivityError;
@property (nonatomic, strong) restorationHandler restorationHandler;
@property (nonatomic, copy) BHUserActivityRestorationHandler restorationHandler;

@end

typedef void (^BHWatchReplyHandler)(NSDictionary *replyInfo);

@interface BHWatchItem : NSObject

@property (nonatomic, strong) NSDictionary *userInfo;
@property (nonatomic, copy) BHWatchReplyHandler replyHandler;

@end

Loading