Ejemplo n.º 1
0
def create_link_table(links):
    ctx = SVMCORBA_RECORD.orb.resolve_initial_references("NameService")
    table = {}

    ii = code.InteractiveInterpreter(locals())

    for lk in links.keys():
        path = os.path.join(SVMCORBA_RECORD.stub_path, links[lk][0])
        path = os.path.join(path, links[lk][1])
        path = os.path.join(path, SVM_MODULE)

        sys.path = [path] + sys.path
        ii.runsource('import %s' % links[lk][0])

        cpath = [
            CosNaming.NameComponent('SVM', ''),
            CosNaming.NameComponent(SVM_MODULE, ''),
            CosNaming.NameComponent(links[lk][0], ''),
            CosNaming.NameComponent(links[lk][1], '')
        ]
        links[lk].append(ctx.resolve(cpath))

        if table.has_key(lk):
            table[lk].append(eval('links[lk][4].%s' % links[lk][3]))
        else:
            table[lk] = [eval('links[lk][4].%s' % links[lk][3])]

    return table
Ejemplo n.º 2
0
def start_service():
    orb = SVMCORBA_RECORD.orb
    boa = BOA.BOA_init()
    ctx = orb.resolve_initial_references("NameService")

    path = [
        CosNaming.NameComponent('SVM', ''),
        CosNaming.NameComponent(SVM_MODULE, ''),
        CosNaming.NameComponent(SVMCORBA_RECORD.module_name, '')
    ]
    for i in range(len(path)):
        try:
            ctx.bind_new_context(path[:i + 1])
        except CosNaming.NamingContext.AlreadyBound:
            pass

    interface_name = SVMCORBA_RECORD.module_name + '_' + str(
        SVMCORBA_RECORD.module_num)
    stubpath = os.path.join(
        os.path.join(SVMCORBA_RECORD.work_path, 'serverif'), interface_name)
    sys.path = [stubpath] + sys.path

    impl = []
    impl.append('from %s import %s' %
                (SVM_MODULE, SVMCORBA_RECORD.module_name))
    impl.append('from %s_skel import %s_skel' %
                (SVM_MODULE, SVMCORBA_RECORD.module_name))
    impl.append('from Fnorb.cos.naming import CosNaming')
    impl.append('import SVMCORBA')

    classdef = 'class inf_%dImpl(%s_skel.inf_%d_skel):\n' % (
        SVMCORBA_RECORD.module_num, SVMCORBA_RECORD.module_name,
        SVMCORBA_RECORD.module_num)
    for p in SVMCORBA_RECORD.ports:
        pp = SVMCORBA_RECORD.ports[p]
        if pp[PORT_IN]:
            classdef = classdef + '\
  def %s(self, event, params):\n\
    SVMCORBA.receive_external_event(%s, event, params)\n' % (p, p)
    classdef = classdef + '\
  def svm_module_add_connection(self, pserver, pclient, components):\n\
    SVMCORBA.svm_module_add_connection(pserver, pclient, components)\n'

    impl.append(classdef)
    impl.append('ifimpl=inf_%dImpl()' % SVMCORBA_RECORD.module_num)
    impl.append('ref=boa.create("inf_%d", inf_%dImpl._FNORB_ID)' %
                (SVMCORBA_RECORD.module_num, SVMCORBA_RECORD.module_num))
    impl.append('ctx.rebind([CosNaming.NameComponent("SVM", ""), CosNaming.NameComponent("%s", ""), CosNaming.NameComponent("%s", ""), CosNaming.NameComponent("inf_%d", "")], ref)'\
         % (SVM_MODULE, SVMCORBA_RECORD.module_name, SVMCORBA_RECORD.module_num))
    impl.append('boa.obj_is_ready(ref, ifimpl)')
    impl.append('SVMCORBA.SVMCORBA_RECORD.impl=ifimpl')

    ii = code.InteractiveInterpreter(locals())
    for i in impl:
        ii.runsource(i)

    del sys.path[0]

    ThreadUtil.StartThread(boa._fnorb_mainloop, ())
Ejemplo n.º 3
0
def main ( argv ):
  
  # init ORB and BOA
  try:
    argv.append( "--ORBthreading-model=Threaded" )
    orb = CORBA.ORB_init( argv, CORBA.ORB_ID )
    boa = BOA.BOA_init( sys.argv, BOA.BOA_ID )
  except: 
    print "..... can`t initialize ORB"
    sys.exit( 1 )

  # resolve NameService
  try :
    nsior = open( "ns.ior", "r" ).read()
  except :
    print "..... ns.ior file for NameService missing"
    sys.exit( 1 )
    
  try :
    ns = orb.string_to_object( nsior )._narrow( CosNaming.NamingContext )
  except :
    print "..... no NameService IOR in ns.ior file or service not running"
    sys.exit( 1 ) 
  
  # create naming contexts
  nspath = [CosNaming.NameComponent( 'DCI', '' )]
  try:
    for component in nspath :
      ns.bind_new_context( [component] )
  except CosNaming.NamingContext.AlreadyBound:
    pass
    
  # create ScriptProcessorRegistry object
  root = Tkinter.Tk()
  obj = boa.create( 'ScriptProcessorRegistry', ScriptProcessorRegistry._FNORB_ID )
  impl = ScriptProcessorRegistry( root, orb, boa )
  boa.obj_is_ready( obj, impl )
  open( "script.ref", "w" ).write( orb.object_to_string( obj ) )
      
  # bind name in name service
  name = nspath + [CosNaming.NameComponent( 'ScriptProcessorRegistry', '' )]
  ns.rebind( name, obj )

  # register ScriptProcessor for Python
  obj2 = boa.create( uuid.uuid(), ScriptProcessor._FNORB_ID )
  impl2 = ScriptProcessor( orb, boa )
  boa.obj_is_ready( obj2, impl2 )
  impl.register_processor( "Python", obj2 )
  
  # mainloop
  print "..... ScriptProcessorRegistry running with ior:\n"
  print orb.object_to_string( obj )
  #boa._fnorb_mainloop()
  thread.start_new_thread(boa._fnorb_mainloop,())
  root.mainloop()
Ejemplo n.º 4
0
def main(argv):
    # init ORB and BOA
    try:
        argv.append("--ORBthreading-model=Threaded")
        orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
        boa = BOA.BOA_init(sys.argv, BOA.BOA_ID)
    except:
        print "..... can`t initialize ORB"
        sys.exit(1)

    # get NameService
    try:
        nsior = open("ns.ior", "r").read()
    except:
        print "..... ns.ior file for NameService missing"
        sys.exit(1)

    try:
        ns = orb.string_to_object(nsior)._narrow(CosNaming.NamingContext)
    except:
        print "..... no NameService IOR in ns.ior or service not running"
        sys.exit(1)

    # create naming contexts
    nspath = [CosNaming.NameComponent('DCI', '')]
    try:
        for component in nspath:
            ns.bind_new_context([component])
    except CosNaming.NamingContext.AlreadyBound:
        pass

    # create object for RuleProcessor
    obj = boa.create('RuleProcessor', RuleProcessor._FNORB_ID)
    impl = RuleProcessor(orb, boa)
    boa.obj_is_ready(obj, impl)
    open("rule.ref", "w").write(orb.object_to_string(obj))

    # bind name in name service
    name = nspath + [CosNaming.NameComponent('RuleProcessor', '')]
    ns.rebind(name, obj)

    # mainloop
    print "..... RuleProcessor running with ior:\n"
    print orb.object_to_string(obj)
    boa._fnorb_mainloop()
Ejemplo n.º 5
0
def locate_components(links):
    ctx = SVMCORBA_RECORD.orb.resolve_initial_references("NameService")

    for lk in links.keys():
        path = os.path.join(SVMCORBA_RECORD.stub_path, links[lk][0])
        path = os.path.join(path, links[lk][1])
        path = os.path.join(path, SVM_MODULE)

        sys.path = [path] + sys.path

        cpath = [
            CosNaming.NameComponent('SVM', ''),
            CosNaming.NameComponent(SVM_MODULE, ''),
            CosNaming.NameComponent(links[lk][0], ''),
            CosNaming.NameComponent(links[lk][1], '')
        ]

        links[lk].append(ctx.resolve(cpath))
Ejemplo n.º 6
0
def main(argv):
    """ Do it! """

    print 'Initialising the ORB...'

    # Initialise the ORB.
    orb = CORBA.ORB_init(argv, CORBA.ORB_ID)

    # Get a reference to the initial naming service context.
    ctx = CORBA.ORB_init().resolve_initial_references("NameService")

    # The 'pathname' of the context that holds the thermometer references.
    path = [
        CosNaming.NameComponent('SVM', ''),
        CosNaming.NameComponent('SVMMODULE', ''),
        CosNaming.NameComponent('test', '')
    ]

    # Lookup the temperatures of the thermometers in rooms 101-105, and then
    # force a lookup on a non-existent name "106"!
    for room in ["inf_0"]:
        # Create a naming service 'name' for the thermometer.
        name = path + [CosNaming.NameComponent(room, '')]

        try:
            # Lookup the thermometer in the naming service.
            thermometer = ctx.resolve(name)

            # Make sure the object implements the expected interface!
            if not thermometer._is_a(CORBA.id(test.inf_0)):
                raise 'This is not a Thermometer!'

            # Call the server!
            thermometer.p('e', [CORBA.Any(CORBA.TC_string, 'hello')])

        except CosNaming.NamingContext.NotFound:
            print 'No thermometer in room', room

    return 0
Ejemplo n.º 7
0
 def quit ( self ):
   # get NameService
   try:
     nsior = open( "ns.ior", "r" ).read()
     ns = self.orb.string_to_object( nsior )._narrow( CosNaming.NamingContext )
   except :
     print "..... no NameService IOR in ns.ior or service not running"
 
   # unbind name in name service
   nspath = [CosNaming.NameComponent('DCI', '')]
   name = nspath + [CosNaming.NameComponent('ScriptProcessorRegistry', '')]
   try:
     ns.unbind( name )
   except:
     print "..... can not unbind in name service"
 
   # deactivate object
   try:
     self.boa.deactivate_obj( self )
   except:
     pass
     
   self.frame.quit()
Ejemplo n.º 8
0
  def __init__( self, orb, boa, root ):
    self.orb = orb
    self.boa = boa
    
    self.condition = "1"
    self.action = "TEST.disconnect_consumer( \"foo\" )"
    self.frequency = 0
    self.rule = None
    self.id = None
    
    #
    # get reference to testobject
    #
    ior = open( "testobject.ref", "r" ).read()
    try:
      self.test = orb.string_to_object( ior )._narrow( Components.CCMObject )
    except:
      util.debug()
    
    #
    # create NamingContext and insert TEST
    #
    nc = self.boa.create( 'nc', NamingContext._FNORB_ID )
    context = NamingContext( boa )
    self.boa.obj_is_ready( nc, context )
    context.bind( [CosNaming.NameComponent( 'TEST', '' )], self.test )
    self.namespace = nc
    
    #
    # get reference to ScriptProcessor
    #
    try:
      ior = open( "script.ref", "r" ).read()
      self.spr = orb.string_to_object( ior )._narrow( DCI.ScriptProcessorRegistry )
      self.sp = self.spr.get_processor( "Python" )
    except:
      print "..... start script processor first"
      sys.exit( 1 )

    #
    # get reference to RuleProcessor
    #
    try:
      ior = open( "rule.ref", "r" ).read()
      self.rp = orb.string_to_object( ior )._narrow( DCI.RuleProcessor )
    except:
      print "..... start rule processor first"
      sys.exit( 1 )
    
    #
    # create Test-GUI
    #

    # root widget
    self.tk = root
    self.tk.title('TestClient')
    
    # menue
    menubar = Tkinter.Menu(self.tk)
    self.tk.config(menu=menubar)
    controlmenu = Tkinter.Menu(menubar)
    menubar.add_cascade(label="Control", menu=controlmenu)
    controlmenu.add_command(label="Quit", command=self.quit)
    helpmenu = Tkinter.Menu(menubar)
    menubar.add_cascade(label="Help", menu=helpmenu)
    
    # quit button and clear button
    quitframe = Tkinter.Frame(self.tk, relief=FLAT, borderwidth=2)
    quitbutton = Tkinter.Button ( quitframe, fg="red", text="quit", command=self.quit )
    quitbutton.pack(side=RIGHT, expand=1)
    clearbutton = Tkinter.Button ( quitframe, text="clear", command=self.clear )
    clearbutton.pack(side=RIGHT,expand=1)
    quitframe.pack(side=BOTTOM, anchor=S, expand=0, fill=X)
    
    # condition
    cframe = Tkinter.Frame(self.tk, relief=RIDGE, borderwidth=2)
    cframeleft = Tkinter.Frame(cframe)
    self.ctext = Tkinter.Text(cframeleft, width=40, height=5)
    self.ctext.insert(END, self.condition)
    self.ctext.pack(side=LEFT, expand=1, fill=BOTH)
    cframeright = Tkinter.Frame(cframe)
    clabel = Tkinter.Label(cframeright, anchor=NW, text="condition")
    cbutton = Tkinter.Button(cframeright, text="eval", command=self.eval )
    clabel.pack(side=LEFT, expand=0)
    cbutton.pack(side=LEFT)
    cframeright.pack(side=RIGHT)
    cframeleft.pack(side=LEFT, expand=1, fill=BOTH)
    cframe.pack(expand=1, fill=BOTH)

    # action
    aframe = Tkinter.Frame(self.tk, relief=RIDGE, borderwidth=2)
    aframeleft = Tkinter.Frame(aframe)
    self.atext = Tkinter.Text(aframeleft, width=40, height=5)
    self.atext.insert(END, self.action)
    self.atext.pack(side=LEFT,expand=1,fill=BOTH)
    aframeright = Tkinter.Frame(aframe)
    alabel = Tkinter.Label(aframeright, anchor=NW, text="action")
    abutton = Tkinter.Button(aframeright, text="exec", command=self._exec )
    alabel.pack(side=LEFT, expand=0)
    abutton.pack(side=LEFT, anchor=E)
    aframeright.pack(side=RIGHT)
    aframeleft.pack(side=LEFT, expand=1, fill=BOTH)
    aframe.pack(expand=1, fill=BOTH)
    
    # rule
    rframe = Tkinter.Frame(self.tk, relief=RIDGE, borderwidth=2)
    rframeleft = Tkinter.Frame(rframe)
    self.rtext = Tkinter.Text(rframeleft, width=10, height=1)
    self.rtext.insert( END, self.frequency )
    self.rtext.pack( side=LEFT, expand=1, fill=BOTH )
    rframeright = Tkinter.Frame(rframe)
    rlabel = Tkinter.Label(rframeright, text="rule frequency")
    cr_button = Tkinter.Button(rframeright, text="create", command=self.create_rule)
    ex_button = Tkinter.Button(rframeright, text="eval", command=self.eval_rule)
    start_button = Tkinter.Button(rframeright,text="start", command=self.start)
    stop_button = Tkinter.Button(rframeright,text="stop", command=self.stop)
    de_button = Tkinter.Button(rframeright, text="destroy", command=self.destroy_rule)
    rlabel.pack(side=LEFT, expand=0)
    cr_button.pack(side=LEFT, anchor=E)
    ex_button.pack(side=LEFT, anchor=E)
    start_button.pack(side=LEFT, anchor=E)
    stop_button.pack(side=LEFT, anchor=E)
    de_button.pack(side=LEFT, anchor=E)
    rframeright.pack(side=RIGHT)
    rframeleft.pack(side=LEFT, expand=1, fill=BOTH)
    rframe.pack(expand=0, fill=BOTH)

    # status report
    statframe = Tkinter.Frame(self.tk, relief=RIDGE, borderwidth=2)
    statlabel = Tkinter.Label(statframe, fg="blue", text="status report")
    self.stattext = Tkinter.Text(statframe, width=40, height=10)
    statscroll = Tkinter.Scrollbar(statframe,orient=VERTICAL)
    statscroll.config(command=self.stattext.yview)
    self.stattext.config(yscrollcommand=statscroll.set)
    statlabel.pack(side=RIGHT)
    statscroll.pack(side=RIGHT,fill=Y,anchor=E)
    self.stattext.pack(side=LEFT, expand=1, fill=BOTH)
    statframe.pack(expand=1, fill=BOTH)