Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
CPDistributedMessagingCenter: Difference between revisions - iPhone Development Wiki

CPDistributedMessagingCenter: Difference between revisions

From iPhone Development Wiki
mNo edit summary
m (→‎Header: Section rename)
Line 46: Line 46:
This subsystem has only 2 routines: 79000 (CPDMMessage) and 79001 (CPDMTwoWayMessage).  
This subsystem has only 2 routines: 79000 (CPDMMessage) and 79001 (CPDMTwoWayMessage).  


== Header ==
== External links ==
* http://github.com/kennytm/iphone-private-frameworks/blob/master/AppSupport/CPDistributedMessagingCenter.h
 
{{IPFHeader|AppSupport|||CPDistributedMessagingCenter}}


{{occlass|library=AppSupport.framework|navbox=1}}
{{occlass|library=AppSupport.framework|navbox=1}}

Revision as of 16:02, 26 October 2014

CPDistributedMessagingCenter is a wrapper over the existing messaging facilities in the operating system. It provides server-client communication between different processes using simple messages and dictionaries. All dictionaries transferred must be serializable as a property list.

Usage

Server

-(id)init... {
...

  CPDistributedMessagingCenter *messagingCenter;
  // Center name must be unique, recommend using application identifier.
  messagingCenter = [CPDistributedMessagingCenter centerNamed:@"unique.name.for.messaging.center"];
  [messagingCenter runServerOnCurrentThread];

  // Register Messages
  [messagingCenter registerForMessageName:@"messageThatHasInfo" target:self selector:@selector(handleMessageNamed:withUserInfo:)];
  [messagingCenter registerForMessageName:@"message" target:self selector:@selector(handleSimpleMessageNamed:)];

...
}

- (NSDictionary *)handleMessageNamed:(NSString *)name withUserInfo:(NSDictionary *)userinfo {
    // Process userinfo (simple dictionary) and return a dictionary (or nil)
}

- (void)handleSimpleMessageNamed:(NSString *)name {
    // ...
}

Client

CPDistributedMessagingCenter *messagingCenter;
messagingCenter = [CPDistributedMessagingCenter centerNamed:@"unique.name.for.messaging.center"];

// One-way (message only)
[messagingCenter sendMessageName:@"message" userInfo:nil/* optional dictionary. in this example it will be ignored. */];

// Two-way (wait for reply)
NSDictionary *reply;
reply = [messagingCenter sendMessageAndReceiveReplyName:@"messageThatHasInfo" userInfo:nil/* optional dictionary */];

CPDistributedMessagingCenter as a MIG subsystem

The CPDistributedMessagingCenter is a complex wrapper on top of the MIG-generated RPC subsystem (_CPDMCPDistributedMessaging_subsystem). The center name will in fact be registered as the service name in the bootstrap name. Therefore, existing services like com.apple.springboard.services cannot be used as the center name.

This subsystem has only 2 routines: 79000 (CPDMMessage) and 79001 (CPDMTwoWayMessage).

External links