-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathIPC.h
122 lines (92 loc) · 4.95 KB
/
IPC.h
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
//
// libobjcipc
// IPC.h
//
// Created by Alan Yip on 6 Feb 2014
// Copyright 2014 Alan Yip. All rights reserved.
//
#import "header.h"
@interface OBJCIPC : NSObject {
BOOL _activated;
// SpringBoard server port
NSUInteger _serverPort;
// process assertions
NSMutableDictionary *_processAssertions;
// store active connections (each contains its own streams)
NSMutableSet *_pendingConnections;
NSMutableDictionary *_activeConnections;
// message handlers and queues
NSMutableDictionary *_globalIncomingMessageHandlers;
NSMutableDictionary *_incomingMessageHandlers;
NSMutableDictionary *_outgoingMessageQueue;
}
@property(nonatomic) BOOL activated;
@property(nonatomic) NSUInteger serverPort;
@property(nonatomic, retain) NSMutableDictionary *processAssertions;
@property(nonatomic, retain) NSMutableSet *pendingConnections;
@property(nonatomic, retain) NSMutableDictionary *activeConnections;
@property(nonatomic, retain) NSMutableDictionary *globalIncomingMessageHandlers;
@property(nonatomic, retain) NSMutableDictionary *incomingMessageHandlers;
@property(nonatomic, retain) NSMutableDictionary *outgoingMessageQueue;
// process checking methods
+ (BOOL)isSpringBoard;
+ (BOOL)isBackBoard;
+ (BOOL)isApp;
// retrieve the shared instance
+ (instancetype)sharedInstance;
// these two methods will be called automatically when needed
+ (void)activate;
+ (void)deactivate;
// or manually close the connection between an app and SpringBoard
+ (void)deactivateAppWithIdentifier:(NSString *)identifier;
// launch app in background (called in SpringBoard)
+ (BOOL)launchAppWithIdentifier:(NSString *)identifier stayInBackground:(BOOL)stayInBackground;
+ (BOOL)setAppWithIdentifier:(NSString *)identifier inBackground:(BOOL)inBackground;
/*** Asynchronous message delivery ***/
// SpringBoard* -----> App
+ (BOOL)sendMessageToAppWithIdentifier:(NSString *)identifier messageName:(NSString *)messageName dictionary:(NSDictionary *)dictionary replyHandler:(OBJCIPCReplyHandler)handler;
// App* -----> SpringBoard
+ (BOOL)sendMessageToSpringBoardWithMessageName:(NSString *)messageName dictionary:(NSDictionary *)dictionary replyHandler:(OBJCIPCReplyHandler)handler;
/*** Synchronous message delivery ***/
// SpringBoard* -----> App
+ (NSDictionary *)sendMessageToAppWithIdentifier:(NSString *)identifier messageName:(NSString *)messageName dictionary:(NSDictionary *)dictionary;
// App* -----> SpringBoard
+ (NSDictionary *)sendMessageToSpringBoardWithMessageName:(NSString *)messageName dictionary:(NSDictionary *)dictionary;
/*** Register incoming message handler ***/
// App -----> SpringBoard*
+ (void)registerIncomingMessageFromAppHandlerForMessageName:(NSString *)messageName handler:(OBJCIPCIncomingMessageHandler)handler;
+ (void)unregisterIncomingMessageFromAppHandlerForMessageName:(NSString *)messageName;
+ (void)unregisterIncomingMessageHandlerForAppWithIdentifier:(NSString *)identifier andMessageName:(NSString *)messageName;
+ (void)registerIncomingMessageHandlerForAppWithIdentifier:(NSString *)identifier andMessageName:(NSString *)messageName handler:(OBJCIPCIncomingMessageHandler)handler;
+ (void)unregisterIncomingMessageHandlerForAppWithIdentifier:(NSString *)identifier andMessageName:(NSString *)messageName;
// SpringBoard -----> App*
+ (void)registerIncomingMessageFromSpringBoardHandlerForMessageName:(NSString *)messageName handler:(OBJCIPCIncomingMessageHandler)handler;
+ (void)unregisterIncomingMessageFromSpringBoardHandlerForMessageName:(NSString *)messageName;
/*** For testing purpose ***/
+ (void)registerTestIncomingMessageHandlerForAppWithIdentifier:(NSString *)identifier;
+ (void)registerTestIncomingMessageHandlerForSpringBoard;
+ (void)sendAsynchronousTestMessageToAppWithIdentifier:(NSString *)identifier;
+ (void)sendAsynchronousTestMessageToSpringBoard;
+ (NSDictionary *)sendSynchronousTestMessageToAppWithIdentifier:(NSString *)identifier;
+ (NSDictionary *)sendSynchronousTestMessageToSpringBoard;
// manage connections
- (OBJCIPCConnection *)activeConnectionWithAppWithIdentifier:(NSString *)identifier;
- (void)addPendingConnection:(OBJCIPCConnection *)connection;
- (void)notifyConnectionBecomesActive:(OBJCIPCConnection *)connection;
- (void)notifyConnectionIsClosed:(OBJCIPCConnection *)connection;
- (void)removeConnection:(OBJCIPCConnection *)connection;
// queue up the outgoing message
- (void)queueOutgoingMessage:(OBJCIPCMessage *)message forAppWithIdentifier:(NSString *)identifier;
// private methods to setup socket server and connection
- (NSUInteger)_createSocketServer;
- (void)_createPairWithAppSocket:(CFSocketNativeHandle)handle;
- (void)_connectToSpringBoard;
// private methods to handle app activation and deactivation
+ (void)_setupAppActivationListener;
+ (void)_setupAppDeactivationListener;
+ (void)_sendActivationNotificationToAppWithIdentifier:(NSString *)identifier;
+ (void)_sendDeactivationNotificationToAppWithIdentifier:(NSString *)identifier;
+ (void)_appActivationHandler;
+ (void)_appDeactivationHandler;
- (void)_deactivateApp;
@end