Archived
This forum has been archived. Please start a new discussion on GitHub.
proxy cast
mutschaedi
in Help Center
hi
i am working on a interfacelayer that should connect a odbms and ice - for now to use php and later to replace com.
i came a long way generating sources for the interface but now i am stuck with a simple cast problem.
i have to get the (cpp) instance i put in a proxy before - i dont get it
to illustrate what i mean please read the following simplifyed scenario
if you need the complete project i'll tar cjf and upload
code:
[slice]
[client code]
as i learned from various cout sessions the ice proxy object that GetIndex gets passed is GUID the same but i need the PropertyHandleI to pass it to the ::PropertyHandle functions
any ideas what i am doing wrong?
is there a different way to cast the proxy back into a instance?
thanks for your help
peace
i am working on a interfacelayer that should connect a odbms and ice - for now to use php and later to replace com.
i came a long way generating sources for the interface but now i am stuck with a simple cast problem.
i have to get the (cpp) instance i put in a proxy before - i dont get it
to illustrate what i mean please read the following simplifyed scenario
if you need the complete project i'll tar cjf and upload
code:
[slice]
class PropertyHandle {
PropertyHandle* GetPropertyHandle(string path);
int GetIndex(PropertyHandle* hdl);
};
[cpp]
PropertyHandlePrx
PropertyHandleI::GetPropertyHandle(const ::std::string& path,
const Ice::Current& current)
{
cout << "GPH(" << path << ")" << endl;
PropertyHandleI* p = new PropertyHandleI;
p->Open(this,(char*)path.c_str());
cout << (::PropertyHandle*) p << endl; //0x9e7288
return PropertyHandlePrx::uncheckedCast(current.adapter->addWithUUID(p));
}
::Ice::Int
PropertyHandleI::GetIndex(const PropertyHandlePrx& phprx,
const Ice::Current& current)
{
PropertyHandleI *i = (PropertyHandleI*)&(*phprx);
::PropertyHandle *ph = (::PropertyHandle*)i;
cout << ph << endl; //0xa0f368
cout << "GIndx(" << ph->GetCurrentIndex() << ")" << endl;
return ph->GetCurrentIndex();
}
[class]
class PropertyHandleI : virtual public MyModule::PropertyHandle, public ::PropertyHandle
[client code]
$ph = $ph0->GetPropertyHandle("classes.functions");
$ph0->GetIndex($ph);
as i learned from various cout sessions the ice proxy object that GetIndex gets passed is GUID the same but i need the PropertyHandleI to pass it to the ::PropertyHandle functions
any ideas what i am doing wrong?
is there a different way to cast the proxy back into a instance?
thanks for your help
peace
0
Comments
-
Hi,
There is a memory leak (really a reference leak) in your GetPropertyHandle function:
PropertyHandleI* p = new PropertyHandleI;
We normally recommend declaring a smart pointer for your implementation class:
class PropertyHandleI ... {
};
typedef IceUtil::Handle<PropertyHandleI> PropertyHandleIPtr;
...
PropertyHandleIPtr p = new PropertyHandleI;
Take care,
- Mark0 -
resolved
thanks guys
you pointed me into the right direction
i did addtypedef IceUtil::Handle<PropertyHandleI> PropertyHandleIPtr;
to the interface class definition and altered my two example functions:PropertyHandleI::GetPropertyHandle(const ::std::string& path, const Ice::Current& current) { cout << "GPH(" << path << ")" << endl; PropertyHandleIPtr p = new PropertyHandleI; p->Open(this,(char*)path.c_str()); PropertyHandlePrx prx = PropertyHandlePrx::uncheckedCast(current.adapter->addWithUUID(p)); return prx; } ::Ice::Int PropertyHandleI::GetIndex(const PropertyHandlePrx& phprx, const Ice::Current& current) { Ice::ObjectPtr phptr = current.adapter->find((*phprx).ice_getIdentity()); PropertyHandleIPtr phiptr = PropertyHandleIPtr::dynamicCast(phptr); return phiptr->GetCurrentIndex();; }
in result my php client code works as i expect$funct = $ph->GetPropertyHandle("functions"); $funct->Get(10); echo $ph->GetIndex($funct); -> 10
now i will generate that for the complete interface.
thanks for your quick help
peace0
