[omniORB] simple question on general Corba

Carl Thompson cet@carlthompson.net
Mon, 10 Sep 2001 15:21:33 -0700


Sveta Shasharina wrote:
> Hi!
> 
> 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:
> 
> interface Unit {
> 	attribute string name;
> }
> 
> interface Param : Unit {
> 	attribute double value;
> }

Your IDL is exactly equivalent to this one:

interface Unit {
	string get_name();
	void set_name(in string n);
}

interface Param : Unit {
	double get_value();
	void set_value(in double d);
}

Therefore it should be implemented like this:

> class UnitImpl : public virtual POA_Unit {
> 	char* get_name() {return CORBA::string_dup(name);}
> 	void set_name(const char* n) {name = n;}
> }
> 
> class ParamImpl: public virtual POA_Param, public UnitImpl {
> 	CORBA::double get_value() {return value;}
> 	void set_value(CORBA::double d) {value = d;}
> };

Note that CORBA does not allow overloaded operations as you attempted.

Also note that some prominent people consider it bad form to use 
attributes; you should explicitly define you get_ and set_ operations in 
your IDL instead (as I showed, above).  Using attributes yields no 
benefits and has some drawbacks (impossible to specify exceptions).

I'm not sure whether it's necessary, but I would use CORBA::string_dup() 
  for the return of get_name().

> Thanks,
> Svetlana Shasharina -- sveta@txcorp.com

Carl Thompson