[omniORB] simple question on general Corba

Duncan Grisby dgrisby@uk.research.att.com
Tue, 11 Sep 2001 10:48:53 +0100


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 --