File: c-impl.c

package info (click to toggle)
pyorbit 2.24.0-7
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,024 kB
  • ctags: 572
  • sloc: sh: 9,202; ansic: 5,440; python: 965; makefile: 177
file content (127 lines) | stat: -rw-r--r-- 3,057 bytes parent folder | download | duplicates (6)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#define ORBIT2_STUBS_API

#include <Python.h>
#include <pyorbit.h>
#include "testcall.h"

typedef struct {
    POA_PyORBit_TestCall baseServant;
    PyORBit_TestCall this;
} PyORBit_TestCall_Servant;


static void
TestCall_op1(PortableServer_Servant servant,
	     PyORBit_TestCall other,
	     CORBA_Environment *ev)
{
    PyORBit_TestCall_Servant *self = (PyORBit_TestCall_Servant *)servant;
    printf("  C impl of TestCall.op1 invoked\n");
    PyORBit_TestCall_op2(other, self->this, ev);
}

static void
TestCall_op2(PortableServer_Servant servant,
	     PyORBit_TestCall other,
	     CORBA_Environment *ev)
{
    printf("  C impl of TestCall.op2 invoked\n");
    PyORBit_TestCall_op3(other, ev);
}

static void
TestCall_op3(PortableServer_Servant servant,
	     CORBA_Environment *ev)
{
    printf("  C impl of TestCall.op3 invoked\n");
}

static PortableServer_ServantBase__epv TestCall_base_epv = {
    NULL,
    NULL,
    NULL
};

static POA_PyORBit_TestCall__epv TestCall_epv = {
    NULL,
    TestCall_op1,
    TestCall_op2,
    TestCall_op3
};

static POA_PyORBit_TestCall__vepv TestCall_vepv = {
    &TestCall_base_epv,
    &TestCall_epv
};


static CORBA_Object
create_TestCall(CORBA_ORB orb, CORBA_Environment *ev)
{
    /* hold the actual servant/objref ... */
    static PyORBit_TestCall_Servant servant;

    PortableServer_ObjectId *objid;
    PortableServer_POA poa;

    if (servant.this) {
	return CORBA_Object_duplicate(servant.this, ev);
    }
    servant.baseServant._private = NULL;
    servant.baseServant.vepv = &TestCall_vepv;

    POA_PyORBit_TestCall__init((PortableServer_ServantBase *)&servant, ev);
    g_assert(ev->_major == CORBA_NO_EXCEPTION);

    poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, "RootPOA", ev);
    g_assert(ev->_major == CORBA_NO_EXCEPTION);

    objid = PortableServer_POA_activate_object(poa, (PortableServer_ServantBase *)&servant, ev);
    g_assert(ev->_major == CORBA_NO_EXCEPTION);

    servant.this = PortableServer_POA_servant_to_reference(poa, (PortableServer_ServantBase *)&servant, ev);
    g_assert(ev->_major == CORBA_NO_EXCEPTION);

    CORBA_free(objid);

    return CORBA_Object_duplicate(servant.this, ev);
}

static PyObject *
_wrap_create_TestCall(PyObject *self, PyObject *args)
{
    PyCORBA_ORB *orb;
    CORBA_Environment ev;
    CORBA_Object objref;
    PyObject *py_objref;

    if (!PyArg_ParseTuple(args, "O!", &PyCORBA_ORB_Type, &orb))
	return NULL;

    CORBA_exception_init(&ev);
    objref = create_TestCall(orb->orb, &ev);
    g_assert(ev._major == CORBA_NO_EXCEPTION);

    py_objref = pycorba_object_new(objref);
    CORBA_Object_release(objref, NULL);
    return py_objref;
}

static PyMethodDef cTestCall_functions[] = {
    { "create_TestCall", (PyCFunction)_wrap_create_TestCall, METH_VARARGS },
    { NULL, NULL, 0 }
};

void initcTestCall(void);

DL_EXPORT(void)
initcTestCall(void)
{
    PyObject *mod;

    init_pyorbit();

    //ORBit_small_flags &= ~ ORBIT_SMALL_FAST_LOCALS;

    mod = Py_InitModule("cTestCall", cTestCall_functions);
}