Getting Distant Object In C++
Getting Distant Object In C++
- Subject: Getting Distant Object In C++
- From: rajesh swarnkar <email@hidden>
- Date: Tue, 10 Mar 2009 17:14:19 +0530
Hi All,
I have two application in which I want to implement IPC using cocoa
distributed object . Then I have established NSConnection between two
process and I am able to get proxy for the object in the remote process
in the client application . Using this proxy I want to get access to various
other object that exist in the remote process . These object are instance of
both c++ class as well as objective c class.
In the client process I have a base class pointer which I want to
point to the implementing class in the remote process. At the same time in
the client process I have objective c protocol in which I want to
recieve implementing objective c class's object that implements our
protocol.
While the objective C version works peerfectly , the c++ version does
not.
Can you please guide me to a possible way by which I get the c++
implementation working . Please see my code below.
Thanks
//****************************************************************************************************************************************************
// remote application
//****************************************************************************************************************************************************
/****TestRemote
.h*********/
class CRemoteBase;
@protocol RemoteProtocol
- (CRemoteBase*) GetRemoteObject;
@end
@interface CRemote : NSObject <RemoteProtocol>
{
}
- (void) RegistreRemote;
@end
class CRemoteBase
{
public:
virtual void ShowMessage() = 0;
};
class CRemoteDerived : public CRemoteBase
{
public:
CRemoteDerived ();
~CRemoteDerived();
void ShowMessage();
};
/****
TestRemote.cpp*********/
@implementing CRemote
- init
{
return self;
}
- (void) RegisterRemote
{
[[NSConnection defaultConnection] setRootObject : self];
[[NSConnection defaultConnection] registerName :@"TestRemote"];
}
- (void) dealloc
{
[super dealloc];
}
- (CRemoteBase*) GetRemoteObject
{
return new CRemoteDerived();
}
@end //end
CRemoteDerived :: CRemoteDerived () {}
CRemoteDerived :: ~CRemoteDerived () {}
void CRemoteDerived :: ShowMessage()
{
printf("This is remote object testing");
}
//****************************************************************************************************************************************************
// reciever application
//****************************************************************************************************************************************************
/****TestReciever.h*********/
@interface CTestReciever : NSObject
{
id remoteProxy;
}
- (CRemoteBase*) GetDistantObject : (NSString*) registerName;
@end
/****TestReciever.cpp*********/
@implementing CTestReciever
- init
{
if (self = [super init])
{
CRemoteBase ptrRemote = NULL;
ptrRemote = (CRemoteBase*)[self GetDistantObject : @"TestRemote"];
ptrRemote->ShowMessage();
delete(ptrRemote);
}
return self;
}
- (void) dealloc
{
[super dealloc];
}
- (CRemoteBase*) GetDistantObject : (NSString*) registerName
{
remoteProxy = [[NSConnection rootProxyFor ConnectionWithRegisteredName
:registerName host : nil]retain];
[remoteProxy setProtocolForProxy : @protocol(RemoteProtocol)];
if(remoteProxy && [remoteProxy conformsToProtocol :
@protocol(RemoteProtocol)])
{
return [remoteProxy GetRemoteObject ];
}
else
return NULL;
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden