File: embed.py

package info (click to toggle)
python-omniorb 3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 3,128 kB
  • ctags: 3,321
  • sloc: cpp: 13,969; python: 8,883; sh: 2,576; xml: 107; makefile: 95; ansic: 35
file content (53 lines) | stat: -rwxr-xr-x 1,026 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python

# embed.py -- Python part of embedding example

import sys
import CORBA, PortableServer
import _GlobalIDL, _GlobalIDL__POA
import _embed

# Define an implementation of the Echo interface
class Echo_i (_GlobalIDL__POA.Echo):
    def echoString(self, mesg):
        print "Python upcall '" + mesg + "'"
        return mesg

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

# Find the root POA
poa = orb.resolve_initial_references("RootPOA")

# Activate the POA
poaManager = poa._get_the_POAManager()
poaManager.activate()


# Test 1: Python calls C++

obj = _embed.getObjRef(orb)
eo  = obj._narrow(_GlobalIDL.Echo)

if eo is None:
    print "Failed to narrow Echo object:", ior
    sys.exit(1)

print "\nPython calling C++..."
ret = eo.echoString("Hello from Python")
print "The object said '" + ret + "'"

print "\n"


# Test 2: C++ calls Python

ei  = Echo_i()
eo  = ei._this()
ior = orb.object_to_string(eo)

print "\nC++ calling Python..."

_embed.putObjRef(eo)

print "\nTest done"