Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 12-19-2005
PeteH PeteH is offline
Registered User
 
Name: Peter Hug
Organization: Warehouse Optimization LLC
Project: APAL
 
Join Date: Oct 2004
Location: Napier, New Zealand
Posts: 26
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"; }
};
Numerous little problems creep in if I simply create matching interface definitions and inherit from the slice generated proxies for the interfaces.

I wonder what the best approach is to accomplish this and would greatly appreciate some clues.
__________________
Peter Hug
Warehouse Optimization LLC (http://www.warehouseoptimization.com)
Reply With Quote
  #2 (permalink)  
Old 12-19-2005
benoit's Avatar
benoit benoit is offline
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,540
Hi,

Creating matching interfaces is probably the most straightforward solution if you want to expose all the library functionality through an Ice server but this might be quite some work! Another option is to declare simpler interfaces to only expose a subset of the library features (the facade design pattern).

Perhaps you could detail a little more the problems you ran into? Why are you trying to inherit from the proxy generated classes for instance?

Benoit.
Reply With Quote
  #3 (permalink)  
Old 12-19-2005
PeteH PeteH is offline
Registered User
 
Name: Peter Hug
Organization: Warehouse Optimization LLC
Project: APAL
 
Join Date: Oct 2004
Location: Napier, New Zealand
Posts: 26
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.
__________________
Peter Hug
Warehouse Optimization LLC (http://www.warehouseoptimization.com)
Reply With Quote
  #4 (permalink)  
Old 12-19-2005
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
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.
Reply With Quote
  #5 (permalink)  
Old 12-22-2005
PeteH PeteH is offline
Registered User
 
Name: Peter Hug
Organization: Warehouse Optimization LLC
Project: APAL
 
Join Date: Oct 2004
Location: Napier, New Zealand
Posts: 26
Quote:
Originally Posted by marc
Ice does not call any destructor explicitly. This simply happens as a side effect when your servant gets destroyed.
Just to explain what I'm doing let's call my application class testApp (which is based on Ice::Application). Let's also assume that I have a simple slice interface called Person and the class that implements this interface is IPerson.

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.
__________________
Peter Hug
Warehouse Optimization LLC (http://www.warehouseoptimization.com)

Last edited by PeteH : 12-22-2005 at 08:30 PM.
Reply With Quote
  #6 (permalink)  
Old 12-23-2005
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
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.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -4. The time now is 09:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.