Creating NSDistantObject
I have two applications 'A' and 'B' and need to do some ipc. Process 'A' launches process 'B' if it is not already running. In process 'A' I create NSConnection
and registerName:
. In process 'B' , I get the 开发者_运维问答remote object by calling rootProxyForConnectionWithRegisteredName:
. And it sets client object pointer to remote object so that Process 'A' uses that object to call client object methods. Until process 'B' launches and establishes connection the _clientObj
is nil. I might receive events that are intended to _clientObj
.
@interface Server : NSObject {
@private
id _clientObj;
}
Question: Is there a way so that i make _clientObj
as NSDistantObject
and it holds all the messages until _clientObj
is constructed.
The functionality you request is not available straight out of the box, but you could create a subclass of NSDistantObject that captures incoming method calls and puts them in a queue until the connection becomes valid. Once the connection becomes valid, it could then dequeue and forward all of the stored method calls. Any further method calls would then be forwarded "live", so to speak.
Have a look at this code as a possible example of how to create a subclass of NSDistantObject to do what I've described above.
GTMTransientRootProxy.m, GTMTransientRootProxy.h
This code silently swallows method calls on the NSDistantObject while the connection is down, but you could extend it to queue the method calls during downtime.
精彩评论