[omniORB] simple question on general Corba

Sveta Shasharina sveta@txcorp.com
Tue, 11 Sep 2001 09:39:20 -0600


So, the signatures of the calls for accessors and modifiers
are overloaded as I expected. (I derived it from looking 
at the skeleton h-file.)  Although, one of the omni 
correspondents (Carl) suggested that I should
use get_name and set_name.  By the way, I was using orbacus
for this exersize, not omniorb.  Is there a difference?

I understood Duncan's points about benefits of using struct
versus intrerfaces with attributes.  The problem is that I
do want inheritance, so I could use classes polymorphically.
To illustrate what I need, I will give this in C++ mapping:

class Unit {
	string name;
	string unit;
	string operation;
}

class Param : public Unit {
	double value;
}

class Option: public Unit {
	int value;
}

So, what will be the corresponding .idl interface?

Maybe:

class Unit {
	string name;
	string unit;
	string operation;
	any value; // NEVER USED ANY BEFORE!
}

Then I can derive a template C++ class from the skeleton,
with the "value" casted to the template parameter...

Thank you all: Duncan, Anton and Carl!  I will try all
your suggestions!

Sveta

-----Original Message-----
From: dpg1@uk.research.att.com [mailto:dpg1@uk.research.att.com]On
Behalf Of Duncan Grisby
Sent: Tuesday, September 11, 2001 3:49 AM
To: sveta@txcorp.com
Cc: omni
Subject: Re: [omniORB] simple question on general Corba 


On Monday 10 September, "Sveta Shasharina" wrote:

> I never used attributes before and decided to use them 
> instead od structs because I want inheritance and 
> thus have to go with interfaces with attributes:

Note that there is a big difference between structs and interfaces
with attributes. With structs, the receiver gets all the data in one
go; with interfaces, each attribute access involves a remote call.
This can have a huge impact on performance and network use.

> interface Unit {
> 	attribute string name;
> }
> 
> interface Param : Unit {
> 	attribute double value;
> }
> 
> Now, how I implement this?
> Will does NOT work:
> 
> class UnitImpl : public virtual POA_Unit {
> 	char* name() {returm name;}
> 	void name(const char* n) {name = n;}
> }

You haven't declared a member to store the name. Try

  class UnitImpl : public virtual POA_Unit {
  public:
    char* name() { return CORBA::string_dup(name_); }
    void name(const char* n) { name_ = n; }

  private:
    CORBA::String_var name_;
  };

Note the memory management rules. When returning the name, it must be
duplicated since ownership passes to the caller. When assigning, the
String_var automatically duplicates the string since it is a const
char*.

> class ParamImpl: public virtual POA_Param, public UnitImpl {

You must use virtual inheritance for UnitImpl too:

 class ParamImpl: public virtual POA_Param, public virtual UnitImpl {

> 	CORBA double value() {return value;}
> 	void value(CORBA::double d) {value = d;}
> };

Again, you need to store a member for the value. This time there
aren't any memory management issues.

After that it should work fine.

Cheers,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --