Home Help Center

proxy cast

mutschaedimutschaedi Member nimo anousOrganization: privateProject: ice evaluation
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]
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

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    If you would like ZeroC to help you, please provide your real name in your signature.
  • mutschaedimutschaedi Member nimo anousOrganization: privateProject: ice evaluation
    my realname is 'osama bin laden'

    i often have problems with that name in forums and the real world (people hang up on the phone)

    should fakename my realname that you think my realname is not a fake?

    peace
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    My apologies. Somebody from ZeroC will help you.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Hi,

    You should call find on the object adapter to get back the servant that you added in the first place. You can get the identity to use from the proxy by calling ice_getIdentity(). If you have further problems please let us know!
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    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,
    - Mark
  • mutschaedimutschaedi Member nimo anousOrganization: privateProject: ice evaluation
    resolved

    thanks guys

    you pointed me into the right direction

    i did add
    typedef 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

    peace
Sign In or Register to comment.