创建 NSDisantObject

发布于 2024-11-01 00:17:19 字数 527 浏览 3 评论 0原文

我有两个应用程序“A”和“B”,需要执行一些 ipc。如果进程“A”尚未运行,则进程“A”将启动进程“B”。在进程“A”中,我创建 NSConnectionregisterName:。在进程 'B' 中,我通过调用 rootProxyForConnectionWithRegisteredName: 获取远程对象。它将客户端对象指针设置为远程对象,以便进程“A”使用该对象来调用客户端对象方法。在进程“B”启动并建立连接之前,_clientObj 为零。我可能会收到旨在 _clientObj 的事件。


@interface Server : NSObject {
    @private
    id _clientObj;
}

问题:有没有办法让我将 _clientObj 制作为 NSDistantObject 并在构建 _clientObj 之前保存所有消息。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空心空情空意 2024-11-08 00:17:19

您请求的功能不能直接使用,但您可以创建 NSDistantObject 的子类,该子类捕获传入的方法调用并将它们放入队列中,直到连接变得有效。一旦连接变得有效,它就可以将所有存储的方法调用出队并转发。可以这么说,任何进一步的方法调用都将被“实时”转发。

看一下这段代码,作为一个可能的示例,了解如何创建 NSDistantObject 的子类来执行我上面描述的操作。

GTMTransientRootProxy.m,
GTMTransientRootProxy.h

当连接断开时,此代码会默默地吞下 NSDistantObject 上的方法调用,但您可以扩展它以在停机期间对方法调用进行排队。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文