1 // -*- Mode: C++; -*- 2 // Package : omniORB 3 // pyConnectionMgmt.cc Created on: 2006/07/21 4 // Author : Duncan Grisby (dgrisby) 5 // 6 // Copyright (C) 2006 Apasphere Ltd. 7 // 8 // This file is part of the omniORB library 9 // 10 // The omniORB library is free software; you can redistribute it and/or 11 // modify it under the terms of the GNU Lesser General Public 12 // License as published by the Free Software Foundation; either 13 // version 2.1 of the License, or (at your option) any later version. 14 // 15 // This library is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 // Lesser General Public License for more details. 19 // 20 // You should have received a copy of the GNU Lesser General Public 21 // License along with this library. If not, see http://www.gnu.org/licenses/ 22 // 23 // Description: 24 // Proprietary omniORB connection management API 25 26 #ifdef __WIN32__ 27 #define DLL_EXPORT _declspec(dllexport) 28 #else 29 #define DLL_EXPORT 30 #endif 31 32 #if defined(__VMS) 33 #include <Python.h> 34 #else 35 #include PYTHON_INCLUDE 36 #endif 37 38 #include <omniORB4/CORBA.h> 39 #include <omniORB4/omniConnectionMgmt.h> 40 41 #include <omniORBpy.h> 42 #include "../omnipy.h" 43 44 45 static omniORBpyAPI* omnipyApi; 46 47 48 extern "C" { 49 50 static char init_doc[] = 51 "init()\n" 52 "\n" 53 "Initialise the omniConnectionMgmt module. Must be called before \n" 54 "CORBA.ORB_init().\n"; 55 pyomniConnectionMgmt_init(PyObject * self,PyObject * args)56 static PyObject* pyomniConnectionMgmt_init(PyObject* self, PyObject* args) 57 { 58 if (!PyArg_ParseTuple(args, (char*)"")) 59 return 0; 60 61 omniConnectionMgmt::init(); 62 63 Py_INCREF(Py_None); 64 return Py_None; 65 } 66 67 static char makeRestrictedReference_doc[] = 68 "makeRestrictedReference(obj, connection_id, max_connections, max_threads,\n" 69 " data_batch, permit_interleaved, server_hold_open)\n" 70 "\n" 71 "Given an object reference, construct a new reference that uses\n" 72 "connections unique to references with <connection_id>. The client\n" 73 "will open at most <max_connections> network connections to the\n" 74 "server; the server will use at most <max_threads> concurrent\n" 75 "threads to service each of those connections. If <data_batch> is\n" 76 "true, the client will enable data batching on the connection if\n" 77 "relevant (e.g. Nagle's algorithm). If <permit_interleaved> is\n" 78 "true, multiple concurrent calls can be interleaved on a single\n" 79 "connection. If <server_hold_open> is true, the server will keep\n" 80 "the connection open until the client closes it.\n"; 81 pyomniConnectionMgmt_makeRestrictedReference(PyObject * self,PyObject * args)82 static PyObject* pyomniConnectionMgmt_makeRestrictedReference(PyObject* self, 83 PyObject* args) 84 { 85 PyObject* pyobj; 86 int connection_id, max_connections, max_threads; 87 int data_batch, permit_interleaved, server_hold_open; 88 89 if (!PyArg_ParseTuple(args, (char*)"Oiiiiii", 90 &pyobj, &connection_id, &max_connections, 91 &max_threads, &data_batch, &permit_interleaved, 92 &server_hold_open)) 93 return 0; 94 95 try { 96 CORBA::Object_var orig_obj = omnipyApi->pyObjRefToCxxObjRef(pyobj, 1); 97 CORBA::Object_var new_obj; 98 99 { 100 omniPy::InterpreterUnlocker _u; 101 new_obj = omniConnectionMgmt:: 102 makeRestrictedReference(orig_obj, 103 (CORBA::ULong)connection_id, 104 (CORBA::ULong)max_connections, 105 (CORBA::ULong)max_threads, 106 (CORBA::Boolean)data_batch, 107 (CORBA::Boolean)permit_interleaved, 108 (CORBA::Boolean)server_hold_open); 109 } 110 return omnipyApi->cxxObjRefToPyObjRef(new_obj, 1); 111 } 112 #define api omnipyApi 113 OMNIORBPY_CATCH_AND_HANDLE_SYSTEM_EXCEPTIONS 114 #undef api 115 } 116 117 static PyMethodDef omniConnectionMgmt_methods[] = { 118 {(char*)"init", 119 pyomniConnectionMgmt_init, METH_VARARGS, 120 init_doc}, 121 122 {(char*)"makeRestrictedReference", 123 pyomniConnectionMgmt_makeRestrictedReference, METH_VARARGS, 124 makeRestrictedReference_doc}, 125 126 {0,0} 127 }; 128 129 #if (PY_VERSION_HEX < 0x03000000) 130 init_omniConnMgmt()131 void DLL_EXPORT init_omniConnMgmt() 132 { 133 PyObject* m = Py_InitModule((char*)"_omniConnMgmt", 134 omniConnectionMgmt_methods); 135 136 // Get hold of the omniORBpy C++ API. 137 PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy"); 138 PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API"); 139 omnipyApi = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi); 140 Py_DECREF(pyapi); 141 } 142 143 #else 144 145 static struct PyModuleDef omniConnectionMgmtmodule = { 146 PyModuleDef_HEAD_INIT, 147 "_omniConnMgmt", 148 "omniORBpy connection management", 149 -1, 150 omniConnectionMgmt_methods, 151 NULL, 152 NULL, 153 NULL, 154 NULL 155 }; 156 157 PyMODINIT_FUNC PyInit__omniConnMgmt(void)158 PyInit__omniConnMgmt(void) 159 { 160 PyObject* m = PyModule_Create(&omniConnectionMgmtmodule); 161 if (!m) 162 return 0; 163 164 // Get hold of the omniORBpy C++ API. 165 PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy"); 166 PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API"); 167 omnipyApi = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi, 168 "_omnipy.API"); 169 Py_DECREF(pyapi); 170 171 return m; 172 } 173 174 #endif 175 }; 176 177