1 // -*- Mode: C++; -*-
2 //                            Package   : omniORBpy
3 // pyInterceptors.cc          Created on: 2003/05/27
4 //                            Author    : Duncan Grisby (dgrisby)
5 //
6 //    Copyright (C) 2003-2012 Apasphere Ltd.
7 //
8 //    This file is part of the omniORBpy library
9 //
10 //    The omniORBpy library is free software; you can redistribute it
11 //    and/or modify it under the terms of the GNU Lesser General
12 //    Public License as published by the Free Software Foundation;
13 //    either version 2.1 of the License, or (at your option) any later
14 //    version.
15 //
16 //    This library is distributed in the hope that it will be useful,
17 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 //    GNU Lesser General Public License for more details.
20 //
21 //    You should have received a copy of the GNU Lesser General Public
22 //    License along with this library. If not, see http://www.gnu.org/licenses/
23 //
24 // Description:
25 //    Python interceptors
26 
27 #include <omnipy.h>
28 #include <pyThreadCache.h>
29 #include <omniORB4/omniInterceptors.h>
30 #include <giopStream.h>
31 #include <giopStrand.h>
32 #include <giopRope.h>
33 #include <GIOP_S.h>
34 #include <GIOP_C.h>
35 
36 
37 OMNI_USING_NAMESPACE(omni)
38 
39 
40 // Python lists of interceptor functions
41 static PyObject* clientSendRequestFns         = 0;
42 static PyObject* clientReceiveReplyFns        = 0;
43 static PyObject* clientReceiveReplyCredsFns   = 0;
44 static PyObject* serverReceiveRequestFns      = 0;
45 static PyObject* serverReceiveRequestCredsFns = 0;
46 static PyObject* serverSendReplyFns           = 0;
47 static PyObject* serverSendExceptionFns       = 0;
48 static PyObject* assignUpcallThreadFns        = 0;
49 static PyObject* assignAMIThreadFns           = 0;
50 
51 
52 static
53 void
callInterceptorsAndSetContexts(PyObject * fnlist,const char * opname,const char * exrepoid,IOP::ServiceContextList & service_contexts,CORBA::CompletionStatus completion)54 callInterceptorsAndSetContexts(PyObject*                fnlist,
55 			       const char*              opname,
56 			       const char*              exrepoid,
57 			       IOP::ServiceContextList& service_contexts,
58 			       CORBA::CompletionStatus  completion)
59 {
60   omniPy::PyRefHolder argtuple(PyTuple_New(exrepoid ? 3 : 2));
61 
62   PyObject* ctxtlist = PyList_New(0);
63   PyTuple_SetItem(argtuple, 0, String_FromString(opname));
64   PyTuple_SetItem(argtuple, 1, ctxtlist);
65 
66   if (exrepoid)
67     PyTuple_SetItem(argtuple, 2, String_FromString(exrepoid));
68 
69   CORBA::ULong sclen = service_contexts.length();
70   CORBA::ULong sci   = sclen;
71 
72   try {
73     for (int i=0; i < PyList_GET_SIZE(fnlist); i++) {
74       PyObject* interceptor = PyList_GET_ITEM(fnlist, i);
75       PyObject* result      = PyObject_CallObject(interceptor, argtuple);
76 
77       if (!result) {
78 	omniPy::handlePythonException();
79       }
80       if (result != Py_None) {
81 	Py_DECREF(result);
82 	OMNIORB_THROW(BAD_PARAM, BAD_PARAM_WrongPythonType, completion);
83       }
84       Py_DECREF(result);
85 
86       if (PyList_GET_SIZE(ctxtlist) > 0) {
87 	sclen += PyList_GET_SIZE(ctxtlist);
88 	service_contexts.length(sclen);
89 
90 	for (int j=0; j < PyList_GET_SIZE(ctxtlist); j++, sci++) {
91 	  PyObject* sc = PyList_GET_ITEM(ctxtlist, j);
92 
93 	  if (!PyTuple_Check(sc) || PyTuple_GET_SIZE(sc) != 2) {
94 	    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_WrongPythonType, completion);
95 	  }
96 	  service_contexts[sci].context_id =
97 	    omniPy::getULongVal(PyTuple_GET_ITEM(sc, 0), completion);
98 
99 	  PyObject* data = PyTuple_GET_ITEM(sc, 1);
100 
101 	  if (!RawString_Check(data))
102 	    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_WrongPythonType, completion);
103 
104           CORBA::ULong size;
105           const char*  str = RawString_AS_STRING_AND_SIZE(data, size);
106 
107 	  service_contexts[sci].context_data.length(size);
108 
109 	  memcpy(service_contexts[sci].context_data.NP_data(), str, size);
110 	}
111 	PyList_SetSlice(ctxtlist, 0, PyList_GET_SIZE(ctxtlist), 0);
112       }
113     }
114   }
115   catch (Py_BAD_PARAM& bp) {
116     bp.logInfoAndThrow();
117   }
118 }
119 
120 static
121 void
getContextsAndCallInterceptors(PyObject * fnlist,const char * opname,int pass_peer_info,const char * peer_address,const char * peer_identity,IOP::ServiceContextList & service_contexts,CORBA::CompletionStatus completion)122 getContextsAndCallInterceptors(PyObject*                fnlist,
123                                const char*              opname,
124                                int                      pass_peer_info,
125                                const char*              peer_address,
126                                const char*              peer_identity,
127                                IOP::ServiceContextList& service_contexts,
128                                CORBA::CompletionStatus  completion)
129 {
130   int i;
131   int sclen = service_contexts.length();
132 
133   omniPy::PyRefHolder argtuple(PyTuple_New(pass_peer_info ? 3 : 2));
134 
135   PyObject* sctuple = PyTuple_New(sclen);
136   PyTuple_SET_ITEM(argtuple, 0, String_FromString(opname));
137   PyTuple_SET_ITEM(argtuple, 1, sctuple);
138 
139   if (pass_peer_info) {
140     PyObject* peer_info = PyDict_New();
141     PyObject* value;
142     if (peer_address) {
143       value = String_FromString(peer_address);
144     }
145     else {
146       Py_INCREF(Py_None);
147       value = Py_None;
148     }
149     PyDict_SetItemString(peer_info, "address", value);
150     Py_DECREF(value);
151 
152     if (peer_identity) {
153       value = String_FromString(peer_identity);
154     }
155     else {
156       Py_INCREF(Py_None);
157       value = Py_None;
158     }
159     PyDict_SetItemString(peer_info, "identity", value);
160     Py_DECREF(value);
161 
162     PyTuple_SET_ITEM(argtuple, 2, peer_info);
163   }
164 
165   for (i=0; i < sclen; i++) {
166     PyObject* sc = PyTuple_New(2);
167     PyTuple_SET_ITEM(sc, 0,
168 		     PyLong_FromUnsignedLong(service_contexts[i].context_id));
169 
170     const char* data = (const char*)service_contexts[i].context_data.NP_data();
171     int len = service_contexts[i].context_data.length();
172 
173     PyTuple_SET_ITEM(sc, 1, RawString_FromStringAndSize(data, len));
174     PyTuple_SET_ITEM(sctuple, i, sc);
175   }
176 
177   try {
178     for (i=0; i < PyList_GET_SIZE(fnlist); i++) {
179       PyObject* interceptor = PyList_GET_ITEM(fnlist, i);
180       PyObject* result      = PyObject_CallObject(interceptor, argtuple);
181 
182       if (!result) {
183 	omniPy::handlePythonException();
184       }
185       if (result != Py_None) {
186 	Py_DECREF(result);
187 	OMNIORB_THROW(BAD_PARAM, BAD_PARAM_WrongPythonType, completion);
188       }
189       Py_DECREF(result);
190     }
191   }
192   catch (Py_BAD_PARAM& bp) {
193     bp.logInfoAndThrow();
194   }
195 }
196 
197 
198 static
199 CORBA::Boolean
pyClientSendRequestFn(omniInterceptors::clientSendRequest_T::info_T & info)200 pyClientSendRequestFn(omniInterceptors::clientSendRequest_T::info_T& info)
201 {
202   OMNIORB_ASSERT(clientSendRequestFns);
203 
204   omnipyThreadCache::lock _t;
205 
206   callInterceptorsAndSetContexts(clientSendRequestFns,
207 				 info.giop_c.operation(),
208                                  0,
209 				 info.service_contexts,
210 				 CORBA::COMPLETED_NO);
211 
212   return 1;
213 }
214 
215 static
216 CORBA::Boolean
pyClientReceiveReplyFn(omniInterceptors::clientReceiveReply_T::info_T & info)217 pyClientReceiveReplyFn(omniInterceptors::clientReceiveReply_T::info_T& info)
218 {
219   OMNIORB_ASSERT(clientReceiveReplyFns);
220 
221   omnipyThreadCache::lock _t;
222 
223   if (PyList_Size(clientReceiveReplyFns)) {
224 
225     getContextsAndCallInterceptors(clientReceiveReplyFns,
226 				   info.giop_c.operation(),
227 				   0, 0, 0,
228 				   info.service_contexts,
229 				   (CORBA::CompletionStatus)
230 				   info.giop_c.completion());
231   }
232 
233   if (PyList_Size(clientReceiveReplyCredsFns)) {
234 
235     giopStrand&     strand     = info.giop_c.strand();
236     giopConnection* connection = strand.connection;
237     const char*     address    = connection->peeraddress();
238     const char*     identity   = connection->peeridentity();
239 
240     getContextsAndCallInterceptors(clientReceiveReplyCredsFns,
241 				   info.giop_c.operation(),
242 				   1, address, identity,
243 				   info.service_contexts,
244 				   (CORBA::CompletionStatus)
245 				   info.giop_c.completion());
246   }
247   return 1;
248 }
249 
250 static
251 CORBA::Boolean
pyServerReceiveRequestFn(omniInterceptors::serverReceiveRequest_T::info_T & info)252 pyServerReceiveRequestFn(omniInterceptors::
253 			 serverReceiveRequest_T::info_T& info)
254 {
255   OMNIORB_ASSERT(serverReceiveRequestFns);
256 
257   omnipyThreadCache::lock _t;
258 
259   if (PyList_Size(serverReceiveRequestFns)) {
260     getContextsAndCallInterceptors(serverReceiveRequestFns,
261 				   info.giop_s.operation(),
262 				   0, 0, 0,
263 				   info.giop_s.service_contexts(),
264 				   (CORBA::CompletionStatus)
265 				   info.giop_s.completion());
266   }
267 
268   if (PyList_Size(serverReceiveRequestCredsFns)) {
269 
270     giopStrand&     strand     = info.giop_s.strand();
271     giopConnection* connection = strand.connection;
272     const char*     address    = connection->peeraddress();
273     const char*     identity   = connection->peeridentity();
274 
275     getContextsAndCallInterceptors(serverReceiveRequestCredsFns,
276 				   info.giop_s.operation(),
277 				   1, address, identity,
278 				   info.giop_s.service_contexts(),
279 				   (CORBA::CompletionStatus)
280 				   info.giop_s.completion());
281   }
282   return 1;
283 }
284 
285 static
286 CORBA::Boolean
pyServerSendReplyFn(omniInterceptors::serverSendReply_T::info_T & info)287 pyServerSendReplyFn(omniInterceptors::serverSendReply_T::info_T& info)
288 {
289   OMNIORB_ASSERT(serverSendReplyFns);
290 
291   omnipyThreadCache::lock _t;
292 
293   callInterceptorsAndSetContexts(serverSendReplyFns,
294 				 info.giop_s.operation(), 0,
295 				 info.giop_s.service_contexts(),
296 				 (CORBA::CompletionStatus)
297 				 info.giop_s.completion());
298 
299   return 1;
300 }
301 
302 static
303 CORBA::Boolean
pyServerSendExceptionFn(omniInterceptors::serverSendException_T::info_T & info)304 pyServerSendExceptionFn(omniInterceptors::serverSendException_T::info_T& info)
305 {
306   OMNIORB_ASSERT(serverSendExceptionFns);
307 
308   omnipyThreadCache::lock _t;
309 
310   callInterceptorsAndSetContexts(serverSendExceptionFns,
311 				 info.giop_s.operation(),
312 				 info.exception->_rep_id(),
313 				 info.giop_s.service_contexts(),
314 				 (CORBA::CompletionStatus)
315 				 info.giop_s.completion());
316   return 1;
317 }
318 
319 
320 template<class infoT>
321 static
322 void
assignThreadFn(infoT & info,PyObject * fns)323 assignThreadFn(infoT& info, PyObject* fns)
324 {
325   OMNIORB_ASSERT(fns);
326 
327   omnipyThreadCache::lock _t;
328 
329   omniPy::PyRefHolder post_list(PyList_New(0));
330 
331   int i;
332   for (i=0; i < PyList_GET_SIZE(fns); ++i) {
333     PyObject* interceptor = PyList_GET_ITEM(fns, i);
334     PyObject* result      = PyObject_CallObject(interceptor, 0);
335 
336     if (!result)
337       omniPy::handlePythonException();
338 
339     if (result == Py_None) {
340       // Simple function
341       Py_DECREF(result);
342     }
343     else {
344       if (!PyIter_Check(result))
345         OMNIORB_THROW(BAD_PARAM, BAD_PARAM_WrongPythonType, CORBA::COMPLETED_NO);
346 
347       // A generator function. Call next() on it once
348       PyList_Append(post_list, result);
349 
350       result = PyIter_Next(result);
351 
352       if (!result) {
353         if (PyErr_Occurred())
354           omniPy::handlePythonException();
355 
356         // The iterator terminated too soon
357         OMNIORB_THROW(BAD_PARAM, BAD_PARAM_WrongPythonType, CORBA::COMPLETED_NO);
358       }
359       Py_DECREF(result);
360     }
361   }
362   {
363     omniPy::InterpreterUnlocker _u;
364     info.run();
365   }
366 
367   // Reverse-iterate over functions
368   for (i = PyList_GET_SIZE(post_list) - 1; i >= 0; --i) {
369 
370     PyObject* gen    = PyList_GET_ITEM(post_list, i);
371     PyObject* result = PyIter_Next(gen);
372 
373     if (result) {
374       // Not expecting this -- next() should have raised StopIteration
375       Py_DECREF(result);
376     }
377     else {
378       // If an error occurred, we just swallow it.
379       if (PyErr_Occurred())
380         PyErr_Clear();
381     }
382   }
383 }
384 
385 static
386 void
pyAssignUpcallThreadFn(omniInterceptors::assignUpcallThread_T::info_T & info)387 pyAssignUpcallThreadFn(omniInterceptors::assignUpcallThread_T::info_T& info)
388 {
389   assignThreadFn(info, assignUpcallThreadFns);
390 }
391 
392 static
393 void
pyAssignAMIThreadFn(omniInterceptors::assignAMIThread_T::info_T & info)394 pyAssignAMIThreadFn(omniInterceptors::assignAMIThread_T::info_T& info)
395 {
396   assignThreadFn(info, assignAMIThreadFns);
397 }
398 
399 
400 void
401 omniPy::
registerInterceptors()402 registerInterceptors()
403 {
404   omniInterceptors* interceptors = omniORB::getInterceptors();
405 
406   if (clientSendRequestFns)
407     interceptors->clientSendRequest.add(pyClientSendRequestFn);
408 
409   if (clientReceiveReplyFns || clientReceiveReplyCredsFns)
410     interceptors->clientReceiveReply.add(pyClientReceiveReplyFn);
411 
412   if (serverReceiveRequestFns || serverReceiveRequestCredsFns)
413     interceptors->serverReceiveRequest.add(pyServerReceiveRequestFn);
414 
415   if (serverSendReplyFns)
416     interceptors->serverSendReply.add(pyServerSendReplyFn);
417 
418   if (serverSendExceptionFns)
419     interceptors->serverSendException.add(pyServerSendExceptionFn);
420 
421   if (assignUpcallThreadFns)
422     interceptors->assignUpcallThread.add(pyAssignUpcallThreadFn);
423 
424   if (assignAMIThreadFns)
425     interceptors->assignAMIThread.add(pyAssignAMIThreadFn);
426 }
427 
428 
429 #define CHECK_ORB_NOT_INITIALISED() \
430   do { \
431     if (omniPy::orb) { \
432       CORBA::BAD_INV_ORDER _ex(BAD_INV_ORDER_InvalidPortableInterceptorCall, \
433                                CORBA::COMPLETED_NO); \
434       return omniPy::handleSystemException(_ex); \
435     } \
436   } while(0)
437 
438 
439 extern "C" {
440   static char addClientSendRequest_doc [] =
441   "addClientSendRequest(interceptor) -> None\n"
442   "\n"
443   "Install an interceptor for when clients send requests.\n";
444 
pyInterceptor_addClientSendRequest(PyObject * self,PyObject * args)445   static PyObject* pyInterceptor_addClientSendRequest(PyObject* self,
446 						      PyObject* args)
447   {
448     PyObject* interceptor;
449 
450     if (!PyArg_ParseTuple(args, (char*)"O", &interceptor))
451       return 0;
452 
453     RAISE_PY_BAD_PARAM_IF(!PyCallable_Check(interceptor),
454 			  BAD_PARAM_WrongPythonType);
455 
456     CHECK_ORB_NOT_INITIALISED();
457 
458     if (!clientSendRequestFns)
459       clientSendRequestFns = PyList_New(0);
460 
461     PyList_Append(clientSendRequestFns, interceptor);
462     Py_INCREF(Py_None);
463     return Py_None;
464   }
465 
466   static char addClientReceiveReply_doc [] =
467   "addClientReceiveReply(interceptor) -> None\n"
468   "\n"
469   "Install an interceptor for when clients receive replies.\n";
470 
pyInterceptor_addClientReceiveReply(PyObject * self,PyObject * args)471   static PyObject* pyInterceptor_addClientReceiveReply(PyObject* self,
472 						       PyObject* args)
473   {
474     PyObject* interceptor;
475 
476     int pass_creds = 0;
477     if (!PyArg_ParseTuple(args, (char*)"O|i", &interceptor, &pass_creds))
478       return 0;
479 
480     RAISE_PY_BAD_PARAM_IF(!PyCallable_Check(interceptor),
481 			  BAD_PARAM_WrongPythonType);
482 
483     CHECK_ORB_NOT_INITIALISED();
484 
485     if (!clientReceiveReplyFns) {
486       clientReceiveReplyFns      = PyList_New(0);
487       clientReceiveReplyCredsFns = PyList_New(0);
488     }
489 
490     if (pass_creds)
491       PyList_Append(clientReceiveReplyCredsFns, interceptor);
492     else
493       PyList_Append(clientReceiveReplyFns, interceptor);
494 
495     Py_INCREF(Py_None);
496     return Py_None;
497   }
498 
499   static char addServerReceiveRequest_doc [] =
500   "addServerReceiveRequest(interceptor) -> None\n"
501   "\n"
502   "Install an interceptor for when servers receive requests.\n";
503 
pyInterceptor_addServerReceiveRequest(PyObject * self,PyObject * args)504   static PyObject* pyInterceptor_addServerReceiveRequest(PyObject* self,
505 							 PyObject* args)
506   {
507     PyObject* interceptor;
508 
509     int pass_creds = 0;
510     if (!PyArg_ParseTuple(args, (char*)"O|i", &interceptor, &pass_creds))
511       return 0;
512 
513     RAISE_PY_BAD_PARAM_IF(!PyCallable_Check(interceptor),
514 			  BAD_PARAM_WrongPythonType);
515 
516     CHECK_ORB_NOT_INITIALISED();
517 
518     if (!serverReceiveRequestFns) {
519       serverReceiveRequestFns      = PyList_New(0);
520       serverReceiveRequestCredsFns = PyList_New(0);
521     }
522 
523     if (pass_creds)
524       PyList_Append(serverReceiveRequestCredsFns, interceptor);
525     else
526       PyList_Append(serverReceiveRequestFns, interceptor);
527 
528     Py_INCREF(Py_None);
529     return Py_None;
530   }
531 
532   static char addServerSendReply_doc [] =
533   "addServerSendReply(interceptor) -> None\n"
534   "\n"
535   "Install an interceptor for when servers send replies.\n";
536 
pyInterceptor_addServerSendReply(PyObject * self,PyObject * args)537   static PyObject* pyInterceptor_addServerSendReply(PyObject* self,
538 						    PyObject* args)
539   {
540     PyObject* interceptor;
541 
542     if (!PyArg_ParseTuple(args, (char*)"O", &interceptor))
543       return 0;
544 
545     RAISE_PY_BAD_PARAM_IF(!PyCallable_Check(interceptor),
546 			  BAD_PARAM_WrongPythonType);
547 
548     CHECK_ORB_NOT_INITIALISED();
549 
550     if (!serverSendReplyFns)
551       serverSendReplyFns = PyList_New(0);
552 
553     PyList_Append(serverSendReplyFns, interceptor);
554     Py_INCREF(Py_None);
555     return Py_None;
556   }
557 
558   static char addServerSendException_doc [] =
559   "addServerSendException(interceptor) -> None\n"
560   "\n"
561   "Install an interceptor for when servers send exceptions.\n";
562 
pyInterceptor_addServerSendException(PyObject * self,PyObject * args)563   static PyObject* pyInterceptor_addServerSendException(PyObject* self,
564 							PyObject* args)
565   {
566     PyObject* interceptor;
567 
568     if (!PyArg_ParseTuple(args, (char*)"O", &interceptor))
569       return 0;
570 
571     RAISE_PY_BAD_PARAM_IF(!PyCallable_Check(interceptor),
572 			  BAD_PARAM_WrongPythonType);
573 
574     CHECK_ORB_NOT_INITIALISED();
575 
576     if (!serverSendExceptionFns)
577       serverSendExceptionFns = PyList_New(0);
578 
579     PyList_Append(serverSendExceptionFns, interceptor);
580     Py_INCREF(Py_None);
581     return Py_None;
582   }
583 
584   static char addAssignUpcallThread_doc [] =
585   "addAssignUpcallThread(interceptor) -> None\n"
586   "\n"
587   "Install an interceptor for when a thread is assigned to perform upcalls.\n";
588 
pyInterceptor_addAssignUpcallThread(PyObject * self,PyObject * args)589   static PyObject* pyInterceptor_addAssignUpcallThread(PyObject* self,
590                                                        PyObject* args)
591   {
592     PyObject* interceptor;
593 
594     if (!PyArg_ParseTuple(args, (char*)"O", &interceptor))
595       return 0;
596 
597     RAISE_PY_BAD_PARAM_IF(!PyCallable_Check(interceptor),
598 			  BAD_PARAM_WrongPythonType);
599 
600     CHECK_ORB_NOT_INITIALISED();
601 
602     if (!assignUpcallThreadFns)
603       assignUpcallThreadFns = PyList_New(0);
604 
605     PyList_Append(assignUpcallThreadFns, interceptor);
606     Py_INCREF(Py_None);
607     return Py_None;
608   }
609 
610   static char addAssignAMIThread_doc [] =
611   "addAssignAMIThread(interceptor) -> None\n"
612   "\n"
613   "Install an interceptor for when a thread is assigned to perform AMI calls.\n";
614 
pyInterceptor_addAssignAMIThread(PyObject * self,PyObject * args)615   static PyObject* pyInterceptor_addAssignAMIThread(PyObject* self,
616                                                     PyObject* args)
617   {
618     PyObject* interceptor;
619 
620     if (!PyArg_ParseTuple(args, (char*)"O", &interceptor))
621       return 0;
622 
623     RAISE_PY_BAD_PARAM_IF(!PyCallable_Check(interceptor),
624 			  BAD_PARAM_WrongPythonType);
625 
626     CHECK_ORB_NOT_INITIALISED();
627 
628     if (!assignAMIThreadFns)
629       assignAMIThreadFns = PyList_New(0);
630 
631     PyList_Append(assignAMIThreadFns, interceptor);
632     Py_INCREF(Py_None);
633     return Py_None;
634   }
635 
636 
637   static PyMethodDef pyInterceptor_methods[] = {
638     {(char*)"addClientSendRequest",
639      pyInterceptor_addClientSendRequest,
640      METH_VARARGS,
641      addClientSendRequest_doc},
642 
643     {(char*)"addClientReceiveReply",
644      pyInterceptor_addClientReceiveReply,
645      METH_VARARGS,
646      addClientReceiveReply_doc},
647 
648     {(char*)"addServerReceiveRequest",
649      pyInterceptor_addServerReceiveRequest,
650      METH_VARARGS,
651      addServerReceiveRequest_doc},
652 
653     {(char*)"addServerSendReply",
654      pyInterceptor_addServerSendReply,
655      METH_VARARGS,
656      addServerSendReply_doc},
657 
658     {(char*)"addServerSendException",
659      pyInterceptor_addServerSendException,
660      METH_VARARGS,
661      addServerSendException_doc},
662 
663     {(char*)"addAssignUpcallThread",
664      pyInterceptor_addAssignUpcallThread,
665      METH_VARARGS,
666      addAssignUpcallThread_doc},
667 
668     {(char*)"addAssignAMIThread",
669      pyInterceptor_addAssignAMIThread,
670      METH_VARARGS,
671      addAssignAMIThread_doc},
672 
673     {NULL,NULL}
674   };
675 }
676 
677 #if (PY_VERSION_HEX < 0x03000000)
678 
679 void
initInterceptorFunc(PyObject * d)680 omniPy::initInterceptorFunc(PyObject* d)
681 {
682   PyObject* m = Py_InitModule((char*)"_omnipy.interceptor_func",
683 			      pyInterceptor_methods);
684   PyDict_SetItemString(d, (char*)"interceptor_func", m);
685 }
686 
687 #else
688 
689  static struct PyModuleDef interceptor_func_module = {
690    PyModuleDef_HEAD_INIT,
691    "_omnipy.interceptor_func",
692    "omniORB Interceptor API",
693    -1,
694    pyInterceptor_methods,
695    NULL,
696    NULL,
697    NULL,
698    NULL
699  };
700 
701 void
initInterceptorFunc(PyObject * d)702 omniPy::initInterceptorFunc(PyObject* d)
703 {
704   PyObject* m = PyModule_Create(&interceptor_func_module);
705   if (!m)
706     return;
707 
708   PyDict_SetItemString(d, (char*)"interceptor_func", m);
709 }
710 
711 #endif
712