What does what?
There are three classes in play:
General problems and limitations
- Warning
- The QtCreator does not display possible function calls for armarx::RemoteHandle<ProxyType> correctly! You can still call the functions for the ProxyType
It ignores following rule:
"If a user-defined operator-> is provided, the operator-> is called again on the value that it returns, recursively, until an operator-> is reached that returns a plain pointer. After that, built-in semantics are applied to that pointer."
(http://en.cppreference.com/w/cpp/language/operator_member_access#Built-in_member_access_operators)
Leaking
A object may leak if a connection error stops the message send when a handle is deleted (this stops the usecount from reaching zero). The deleter will be called when the armarx::ArmarXManager shuts down. A server can force delete the object by calling armarx::RemoteHandleControlBlock::forceDeletion on the direct handle returned by RemoteHandleControlBlock::create
Premature deletion
A object may be deleted with handles still alive if:
- the object's deletion was forced by calling armarx::RemoteHandleControlBlock::forceDeletion
- a scenario equivalent to this:
- pc A has the object and sends a handle to B
- pc B has now the only handle
- pc B now sends the handle to pc C and delets the handle before C deserialized the object (this could be done via a broadcast)
- The handle is deserialized after the deletion timeout set via property (default 3 sec) has passed.
This scenario 2) is possible but should not happen on a stable LAN if ice objects are not keept in a serialized form for a longer period
The client side
You will probably know the type of proxy to expect. E.g.: A memoryx::CommonStorageInterfacePrx.
If you don't know the proxy type to expect:
if(rh->ice_isA(memoryx::WorkingMemoryInterface::ice_staticId()))
{
std::cout << "the mystery is a working memory";
}
if(csrh)
{
std::cout << "the mystery is a common storage";
}
The server side
Create a armarx::RemoteHandleControlBlock like this:
{
auto objectPtr = createObject();
getArmarXManager()->addObject(objectPtr, true, "somename");
auto objectProxy = objectPtr->getProxy(-1);
auto axManager = getArmarXManager();
ManagementData mdat = RemoteHandleControlBlock::create(
getArmarXManager()->getAdapter(),
objectProxy,
[axManager, objectPtr]
{
axManager->removeObjectNonBlocking(objectPtr);
}
);
sendToClient(mdat.clientSideRemoteHandleControlBlock);
}
Maybe you want to clean up (if you don't do this and your network is unstable you may leak the armarx::RemoteHandle until the armarx::ArmarXManager shuts down):
storedDirectHandle->forceDeletion();