1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """A set of utility function to ease the use of OmniORBpy.
19
20
21
22
23 """
24 __docformat__ = "restructuredtext en"
25
26 from omniORB import CORBA, PortableServer
27 import CosNaming
28
29 orb = None
30
32 """
33 returns a reference to the ORB.
34 The first call to the method initialized the ORB
35 This method is mainly used internally in the module.
36 """
37
38 global orb
39 if orb is None:
40 import sys
41 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
42 return orb
43
45 """
46 returns a reference to the NameService object.
47 This method is mainly used internally in the module.
48 """
49
50 orb = get_orb()
51 nss = orb.resolve_initial_references("NameService")
52 rootContext = nss._narrow(CosNaming.NamingContext)
53 assert rootContext is not None,"Failed to narrow root naming context"
54 return rootContext
55
57 """
58 Registers a object in the NamingService.
59 The name path is a list of 2-uples (id,kind) giving the path.
60
61 For instance if the path of an object is [('foo',''),('bar','')],
62 it is possible to get a reference to the object using the URL
63 'corbaname::hostname#foo/bar'.
64 [('logilab','rootmodule'),('chatbot','application'),('chatter','server')]
65 is mapped to
66 'corbaname::hostname#logilab.rootmodule/chatbot.application/chatter.server'
67
68 The get_object_reference() function can be used to resolve such a URL.
69 """
70 context = get_root_context()
71 for id, kind in namepath[:-1]:
72 name = [CosNaming.NameComponent(id, kind)]
73 try:
74 context = context.bind_new_context(name)
75 except CosNaming.NamingContext.AlreadyBound, ex:
76 context = context.resolve(name)._narrow(CosNaming.NamingContext)
77 assert context is not None, \
78 'test context exists but is not a NamingContext'
79
80 id,kind = namepath[-1]
81 name = [CosNaming.NameComponent(id, kind)]
82 try:
83 context.bind(name, object._this())
84 except CosNaming.NamingContext.AlreadyBound, ex:
85 context.rebind(name, object._this())
86
88 """
89 This methods activates the Portable Object Adapter.
90 You need to call it to enable the reception of messages in your code,
91 on both the client and the server.
92 """
93 orb = get_orb()
94 poa = orb.resolve_initial_references('RootPOA')
95 poaManager = poa._get_the_POAManager()
96 poaManager.activate()
97
99 """
100 Enters the ORB mainloop on the server.
101 You should not call this method on the client.
102 """
103 get_orb().run()
104
106 """
107 Resolves a corbaname URL to an object proxy.
108 See register_object_name() for examples URLs
109 """
110 return get_orb().string_to_object(url)
111
113 """given an host name and a name path as described in register_object_name,
114 return a corba string identifier
115 """
116 strname = '/'.join(['.'.join(path_elt) for path_elt in namepath])
117 return 'corbaname::%s#%s' % (host, strname)
118