[omniORB] Using omniNotify with omniOrbPy

Mark Zimmerman markzimm@frii.com
Thu, 14 Jun 2001 09:40:11 -0600


Thanks for the info. I have made some progress but I have reached
another point of confusion. My short term goal is to write a python
script that will push a structured event onto an existing notification
channel. I figured out that when porting C++ code to python, you have
to map "CosNA_" to "CosNotifyChannelAdmin.". That got me to the
attached script that almost works. I have commented the point of
failure and another point of uncertainty and I have forgone error
checking for now to keep it short.

If you could shed some light on this I would appreciate it.

Here is the error I get:

mulder$ python push.py 
Traceback (most recent call last):
  File "push.py", line 47, in ?
    jack = Pusher()
  File "push.py", line 27, in __init__
    self._pcons.connect_structured_push_supplier(self._this())
AttributeError: 'Pusher' instance has no attribute '_this'

and here is the code:

----------------------------------------------------------------------
#!/usr/bin/env python

import sys
from omniORB import CORBA
import CosNaming
import CosNotification
import CosNotifyComm
import CosNotifyChannelAdmin

class Pusher (CosNotifyComm.StructuredPushSupplier):

   def __init__ (self):
      orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
      ns = orb.resolve_initial_references("NameService")
      rootCon = ns._narrow(CosNaming.NamingContext)
      name = [CosNaming.NameComponent("EventChannel","EventChannel")]
      echannel_ref = rootCon.resolve(name)
      channel = echannel_ref._narrow(CosNotifyChannelAdmin.EventChannel)
      sadmin, suppid = channel.new_for_suppliers(CosNotifyChannelAdmin.AND_OP)     
      cons, prxID = sadmin.obtain_notification_push_consumer (
                CosNotifyChannelAdmin.STRUCTURED_EVENT)
      self._pcons = cons._narrow (
                       CosNotifyChannelAdmin.StructuredProxyPushConsumer)
#
#     This is where it fails:
#
      self._pcons.connect_structured_push_supplier(self._this())

   def Speak (self, whosez, whatsay):
      fixhead = CosNotification.FixedEventHeader ("SPW", "Log")
      header  = CosNotification.EventHeader (fixhead, None)
#
#     I am not sure of the proper data type for filterable_data.
#     This is a guess:
#
      filterable_data   = [{'name': "Severity",    'value': 0},
                           {'name': "HostName",    'value': "myhost"},
                           {'name': "UserName",    'value': "moi"},
                           {'name': "PID",         'value': 1234},
                           {'name': "PPID",        'value': 2345},
                           {'name': "ProgramName", 'value': whosez},
                           {'name': "Time",        'value': 202020202}]
      event   = CosNotification.StructuredEvent (
                     header, filterable_data, whatsay)
      self._pcons.push_structured_event (event)

jack = Pusher()
jack.Speak ("ProgramName", "Hello, sailor")

----------------------------------------------------------------------