|
|
|
|||||
|
Implementing ICE interface for existing class library
I'm currently investigating how I best implement an ICE interface for an existing class library.
In an ideal world the entire public interface of all classes would be accessible through ICE and the oo features (polymorphism, inheritance, etc.) in the library would also exist in the ICE interface. Here is a simple example: Code:
class WorldCitizen
{
public:
virtual std::string SayHello() = 0;
};
class French : public WorldCitizen
{
public:
virtual std::string SayHello() { return "Bonjour"; }
};
I wonder what the best approach is to accomplish this and would greatly appreciate some clues. |
|
|||||
|
Well I was wrong with my statement that I "... inherit from the slice generated proxy classes". I got a bit lost in the forest of classes and namespaces that slice created for me.
At this stage, the main problem I'm having is the object life cycle. If a class inherits directly or indirectly from ::Ice::Object I find that Ice calls the destructor of my class which in my case is an undesirable side effect. In my case this is critical because an object with an Ice interface is created during static initialisation. |
|
||||||
|
Ice does not call any destructor explicitly. This simply happens as a side effect when your servant gets destroyed.
Note that all servants must inherit from Ice::Object, and therefore all of them must be allocated with new because of reference counting. You cannot allocate a servant on the stack. Please see the Ice manual for details, in particular the section about reference counting. |
|
|||||
|
Quote:
So what I do is create an ObjectAdapter in my testApp::Run method, create an instance of my IPerson class and register it with the object adapter. The run method then waits with communicator()->waitForShutdown(). Ultimately, this call returns and in due course the testApp instance gets destroyed. It is at this point that the IPerson instance is also deleted by code inside ICE. How can I ensure that the object continues to live beyond this point? BTW: I also tried to call ObjectAdapter::remove to remove the IPerson instance from the object adapter but this too resulted in the destruction of my IPerson instance. Last edited by PeteH : 12-22-2005 at 08:30 PM. |
|
||||||
|
You must keep a smart pointer to the servant to avoid that it gets destroyed prematurely. For details, please see the chapter about C++ reference counting (6.14.6) in the Ice manual.
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Ice-3.1.0 - slice2cpp - interface seq in class | StuartA | Bug Reports | 2 | 07-15-2006 09:15 PM |
| How do I write a c++ server for the slice containing interface and class? | bharath123 | Help Center | 4 | 03-21-2006 08:45 PM |
| difference between proxies from class and from interface | kovacm | Help Center | 3 | 05-29-2005 05:57 PM |
| Please give me a simple sample for interface and class. | kane | Help Center | 4 | 12-09-2004 05:53 PM |
| Class/Interface Confusion with IcePack | amrufon | Help Center | 2 | 07-14-2004 06:12 AM |