00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef RtcFactoryPy_h
00029 #define RtcFactoryPy_h
00030
00031 #include <list>
00032 #include "Python.h"
00033 #include "rtm/RtcFactory.h"
00034
00035 namespace RTM
00036 {
00056 class EXPORTS RtcFactoryPy
00057 : public RtcFactoryBase
00058 {
00059 public:
00060
00086 RtcFactoryPy(RtcModuleProfile profile, PyObject* callable)
00087 : RtcFactoryBase(profile), m_pyClass(callable)
00088 {
00089 if (!PyCallable_Check(m_pyClass))
00090 {
00091 cout << "callable is not callable Python object." << endl;
00092 }
00093 else
00094 {
00095 Py_INCREF(m_pyClass);
00096 }
00097
00098
00099
00100
00101
00102
00103 };
00104
00112 ~RtcFactoryPy()
00113 {
00114 Py_DECREF(m_pyClass);
00115 }
00116
00117
00137 RtcBase* create(RtcManager* mgr)
00138 {
00139 PyObject* pyMgr;
00140 PyObject* pyArg;
00141 PyObject* pyComponent;
00142
00143 if (!PyCallable_Check(m_pyClass))
00144 {
00145 cout << "callable is not callable Python object." << endl;
00146 }
00147
00148
00149 pyMgr = SWIG_NewPointerObj((void *) mgr,
00150 SWIGTYPE_p_RTM__RtcManager, 1);
00151 if (pyMgr == NULL) cerr << "pyMgr Object is NULL" << endl;
00152
00153
00154 pyArg = Py_BuildValue("(O)", pyMgr);
00155 if (pyArg == NULL) cerr << "pyArg Object is NULL" << endl;
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 pyComponent = PyEval_CallObject(m_pyClass, pyArg);
00167 if (pyComponent == NULL)
00168 {
00169 cerr << "m_pyComponent Object is NULL" << endl;
00170 return NULL;
00171 }
00172
00173
00174 ++m_Number;
00175
00176 RtcBase* comp;
00177 if ((SWIG_ConvertPtr(pyComponent, (void **)&comp,
00178 SWIGTYPE_p_RTM__RtcBase,
00179 SWIG_POINTER_EXCEPTION)) == -1)
00180 {
00181 cerr << "conversion error" << endl;
00182 return NULL;
00183 }
00184
00185
00186 m_pyComponents.push_back(pyComponent);
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 return comp;
00199 };
00200
00220 void destroy(RtcBase* comp)
00221 {
00222 --m_Number;
00223
00224 delete comp;
00225 };
00226
00227 protected:
00235 PyObject* m_pyClass;
00236
00244 std::list<PyObject*> m_pyComponents;
00252 PyInterpreterState *m_Interp;
00253 };
00254
00255 };
00256
00257
00258
00259 #endif // end of __RtcFactory_h__