Pyramid.h
4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Pyramid.h
// Pyramid
//
// Modify by jilutao on 04/01/2018.
// Copyright © 2017 Baidu. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Pyramid/BBPContext.h>
#import <Pyramid/BBPAppSpeedMonitor.h>
#import <Pyramid/BBPApplicationDelegate.h>
#import <Pyramid/BBPModuleProtocol.h>
#import <Pyramid/BBPServiceProtocol.h>
#import <Pyramid/PyramidDefines.h>
#define PyramidInstance ([Pyramid shared])
#define PyramidContext ([Pyramid shared].context)
#define PyramidAppDelegate ([Pyramid shared].applicationDelegate)
#define PyramidCreateService(p) ([Pyramid createService:@protocol(p)])
#define AliasService(Protocol, Selector) \
@protocol Protocol; \
@protocol Pyramid_##Protocol \
+ (Class<Protocol>)Selector; \
@end \
@interface Pyramid(Protocol)<Pyramid_##Protocol> \
@end
/**
Pyramid框架主类,包含环境变量,注册,获取和触发组件,服务和事件等功能
*/
@interface Pyramid : NSObject
// app参数存放对象
@property (nonatomic, strong) BBPContext *context;
// app事件接收
@property (nonatomic, strong) BBPApplicationDelegate *applicationDelegate;
// 开启异常崩溃,建议debug下开启
@property (nonatomic, assign) BOOL enableException;
+ (instancetype)shared;
/**
给指定的组件注册自定义事件,触发此事件后只要注册的组件才会接收
@param event 事件
@param moduleInstance 组件对象
*/
+ (void)registerCustomEvent:(BDPPyramidEvent)event moduleInstance:(id<BBPModuleProtocol>)moduleInstance;
/**
注销指定组件的自定义事件
@param event 事件
@param moduleInstance 组件对象
*/
+ (void)unregisterCustomEvent:(BDPPyramidEvent)event moduleInstance:(id<BBPModuleProtocol>)moduleInstance;
/**
注销指定组件的所有自定义事件
@param moduleInstance 组件对象
*/
+ (void)unregisterCustomEvent:(id<BBPModuleProtocol>)moduleInstance;
/**
触发自定义事件
@param event 事件
*/
+ (void)triggerCustomEvent:(BDPPyramidEvent)event;
/**
触发自定义事件
@param event 事件
@param customParam 参数
*/
+ (void)triggerCustomEvent:(BDPPyramidEvent)event customParam:(id)customParam;
/**
App环境加载完成调用,如:首页加载完成
*/
+ (void)applicationEnvironmentDidSetup;
/**
Window加载完成调用
*/
+ (void)applicationMakeKeyWindowAndVisible;
@end
#import <Pyramid/Pyramid+Module.h>
#import <Pyramid/Pyramid+Service.h>
// 注册Service
#define registerService(Protocol, Implementation) \
do { \
[Pyramid registerService:@protocol(Protocol) implClass:[Implementation class]]; \
[Pyramid registerDispatcher:[Implementation class] forModuleInstance:self]; \
} while(0)
// 注册Service和别名
#define registerServiceWithAlias(Protocol, Implementation, Alias) \
do { \
[Pyramid registerService:@protocol(Protocol) implClass:[Implementation class]];\
[Pyramid registerAlias:@selector(Alias) forService:@protocol(Protocol)]; \
[Pyramid registerDispatcher:[Implementation class] forModuleInstance:self]; \
} while(0)
// 注册外部Service
#define registerServiceWithIdentifier(Protocol, Implementation, identifier) \
do { \
[Pyramid registerExternService:@protocol(Protocol) implClass:[Implementation class] identifier:identifier];\
} while(0)
// 定义组件
#define ModuleDefine(Module) \
__attribute__((constructor)) \
static void registerModuleFor##Module(void) { \
[Pyramid addReadyRegisterModule:[Module class]]; \
}
// 定义Service
#define ServiceDefine(Protocol, Implementation) \
__attribute__((constructor)) \
static void registerModuleFor##MODULE(void) { \
[Pyramid registerService:@protocol(Protocol) implClass:[Implementation class]]; \
}
// 定义Service别名
#define ServiceDefineWithAlias(Protocol, Implementation, Alias) \
__attribute__((constructor)) \
static void registerModuleFor##MODULE(void) { \
[Pyramid registerService:@protocol(Protocol) implClass:[Implementation class]]; \
[Pyramid registerAlias:@selector(Alias) forService:@protocol(Protocol)];\
}
// 自动Hook系统事件,此宏不调动不自动Hook,系统事件需手动派发
#define PyramidAutoDispatcherSystemEvents(void) \
__attribute__((constructor)) \
static void AutoDispatcherSystemEventsForPyramid() { \
BBPContext.autoDispatcherSystemEvents = YES; \
}