Results 1 to 7 of 7

Thread: proxy cast

  1. #1
    mutschaedi is offline Registered User
    Name: nimo anous
    Organization: private
    Project: ice evaluation
    Join Date
    Jun 2006
    Location
    small flat with view on a trainsupply
    Posts
    9

    proxy cast

    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]
    Code:
    class PropertyHandle {
      PropertyHandle* GetPropertyHandle(string path);
      int GetIndex(PropertyHandle* hdl);
    };
    [cpp]
    Code:
    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]
    Code:
    class PropertyHandleI : virtual public MyModule::PropertyHandle, public ::PropertyHandle
    [client code]
    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
    full name [ osama bin laden ]
    company [ none ]
    project: com replacement for oodbms

  2. #2
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    If you would like ZeroC to help you, please provide your real name in your signature.

  3. #3
    mutschaedi is offline Registered User
    Name: nimo anous
    Organization: private
    Project: ice evaluation
    Join Date
    Jun 2006
    Location
    small flat with view on a trainsupply
    Posts
    9

    Unhappy

    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
    full name [ osama bin laden ]
    company [ none ]
    project: com replacement for oodbms

  4. #4
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    My apologies. Somebody from ZeroC will help you.

  5. #5
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    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!

  6. #6
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    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

  7. #7
    mutschaedi is offline Registered User
    Name: nimo anous
    Organization: private
    Project: ice evaluation
    Join Date
    Jun 2006
    Location
    small flat with view on a trainsupply
    Posts
    9

    Smile resolved

    thanks guys

    you pointed me into the right direction

    i did add
    Code:
     typedef IceUtil::Handle<PropertyHandleI> PropertyHandleIPtr;
    to the interface class definition and altered my two example functions:
    Code:
    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
    Code:
    $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
    full name [ osama bin laden ]
    company [ none ]
    project: com replacement for oodbms

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 10-06-2010, 01:49 AM
  2. BiDirectional connection - problem with cast
    By lukaszg84 in forum Help Center
    Replies: 3
    Last Post: 11-10-2009, 07:55 AM
  3. smart pointer down cast
    By peterlspot in forum Help Center
    Replies: 3
    Last Post: 05-24-2008, 09:37 AM
  4. why cast
    By rodolfo.bamberg in forum Help Center
    Replies: 2
    Last Post: 04-21-2008, 03:52 PM
  5. Question about the Ptr cast
    By minifat in forum Help Center
    Replies: 1
    Last Post: 08-09-2004, 09:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •