omniORBpy / IDL mapping question...

Duncan Grisby dgrisby at uk.research.att.com
Tue Sep 26 07:19:17 EDT 2000


In article <MM_z5.61$Uc.6635 at juliett.dax.net>, Dag Sunde <dag at orion.no> wrote:

>  interface MarketInterface
>  {
>    readonly attribute CosNaming::Name CorbaName;
>    readonly attribute string NamingDef;
>
>    attribute string MarketNameLong;
>    attribute string MarketNameShort;
>    ...
>  };
>
>This ends up as the following in the generated Python-stubs
>from the IDL-compiler:

You shouldn't really bother to look at the generated code -- it will
only confuse you :-)  Most of it is magic which only makes sense if
you look at the C++ code which does the majority of the work.

What you should actually look at is the Python language mapping spec
at

  http://cgi.omg.org/cgi-bin/doc?ptc/00-04-08

[...]

>My problem is: how do I implement the Attributes from the IDL-file,
>so they behave like attributes when I'm implementing the
>"MarketInterface" - interface?
>
>ie. Mymarket.CorbaName = "Test" or sName = MyMarket.CorbaName ???

The answer is that you don't. CORBA attributes are just a short-hand
way of specifying a pair of accessor functions (or a single one for
readonly attributes). CORBA attributes do not behave like Python
attributes -- they involve a remote call, and can raise CORBA system
exceptions. The server side need not treat them as attributes -- it
can do anything it wants inside the operations.

So, on both the client and server sides, you must use _get and _set
functions:

  class MarketInterface_i (_GlobalIDL__POA.MarketInterface):

      def _get_CorbaName(self):
          print "getting the CorbaName..."
          return self.CorbaName

      def _get_NamingDef(self):
          return self.NamingDef

      def _get_MarketNameLong(self):
          return self.MarketNameLong

      def _set_MarketNameLong(self, mnl):
          self.MarketNameLong = mnl

      def _get_MarketNameShort(self):
          return self.MarketNameShort

      def _set_MarketNameShort(self, mns):
          self.MarketNameShort = "Ha!  Not the string you thought!"


On the client side:

  Mymarket._set_MarketNameShort("Hello")
  print Mymarket._get_MarketNameShort()
  ...


HTH,

Duncan.

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



More information about the Python-list mailing list