00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "PreCompiled.h"
00027
00028 #ifndef _PreComp_
00029 # include <assert.h>
00030 # include <fcntl.h>
00031 # include <sys/types.h>
00032 # include <sys/stat.h>
00033 # ifdef FC_OS_WIN32
00034 # include <io.h>
00035 # include <xercesc/sax/SAXParseException.hpp>
00036 # endif
00037 # include <stdio.h>
00038 #endif
00039
00040
00041 #include <fcntl.h>
00042 #ifdef FC_OS_LINUX
00043 # include <unistd.h>
00044 #endif
00045
00046 #include "Parameter.h"
00047 #include "Exception.h"
00048 #include "Console.h"
00049 #include "PyObjectBase.h"
00050
00051 using namespace Base;
00052
00053
00054
00055
00056
00057
00058
00059
00062 class ParameterGrpPy :public Base::PyObjectBase
00063 {
00065 Py_Header;
00066
00067 protected:
00069 ~ParameterGrpPy();
00070
00071 public:
00072
00073
00074
00075
00076
00077
00079 ParameterGrpPy(const Base::Reference<ParameterGrp> &rcParamGrp, PyTypeObject *T = &Type);
00081 static PyObject *PyMake(PyObject *, PyObject *);
00082
00083
00084
00085
00086
00087 PyObject *_getattr(char *attr);
00088
00089 int _setattr(char *attr, PyObject *value);
00090
00091 PYFUNCDEF_D (ParameterGrpPy,PyGetGrp);
00092 PYFUNCDEF_D (ParameterGrpPy,PyRemGrp);
00093 PYFUNCDEF_D (ParameterGrpPy,PyHasGroup);
00094 PYFUNCDEF_D (ParameterGrpPy,PyIsEmpty);
00095 PYFUNCDEF_D (ParameterGrpPy,PyClear);
00096 PYFUNCDEF_D (ParameterGrpPy,PyNotify);
00097 PYFUNCDEF_D (ParameterGrpPy,PyNotifyAll);
00098
00099 PYFUNCDEF_D (ParameterGrpPy,PySetBool);
00100 PYFUNCDEF_D (ParameterGrpPy,PyGetBool);
00101 PYFUNCDEF_D (ParameterGrpPy,PyRemBool);
00102
00103 PYFUNCDEF_D (ParameterGrpPy,PySetInt);
00104 PYFUNCDEF_D (ParameterGrpPy,PyGetInt);
00105 PYFUNCDEF_D (ParameterGrpPy,PyRemInt);
00106
00107 PYFUNCDEF_D (ParameterGrpPy,PySetUnsigned);
00108 PYFUNCDEF_D (ParameterGrpPy,PyGetUnsigned);
00109 PYFUNCDEF_D (ParameterGrpPy,PyRemUnsigned);
00110
00111 PYFUNCDEF_D (ParameterGrpPy,PySetFloat);
00112 PYFUNCDEF_D (ParameterGrpPy,PyGetFloat);
00113 PYFUNCDEF_D (ParameterGrpPy,PyRemFloat);
00114
00115 PYFUNCDEF_D (ParameterGrpPy,PySetString);
00116 PYFUNCDEF_D (ParameterGrpPy,PyGetString);
00117 PYFUNCDEF_D (ParameterGrpPy,PyRemString);
00118
00119 PYFUNCDEF_D (ParameterGrpPy,importFrom);
00120 PYFUNCDEF_D (ParameterGrpPy,insert);
00121 PYFUNCDEF_D (ParameterGrpPy,exportTo);
00122
00123 protected:
00124 Base::Reference<ParameterGrp> _cParamGrp;
00125 };
00126
00127
00128
00129
00130
00131
00132 PyTypeObject ParameterGrpPy::Type = {
00133 PyObject_HEAD_INIT(&PyType_Type)
00134 0,
00135 "ParameterGrp",
00136 sizeof(ParameterGrpPy),
00137 0,
00138
00139 PyDestructor,
00140 0,
00141 __getattr,
00142 __setattr,
00143 0,
00144 __repr,
00145 0,
00146 0,
00147 0,
00148 0,
00149 0,
00150 0,
00151 0,
00152 0,
00153
00154 0,
00155
00156 0,
00157 "Python interface class to set parameters",
00158 0,
00159 0,
00160 0,
00161 0,
00162 0,
00163 0,
00164 0,
00165 0,
00166 0,
00167 0,
00168 0,
00169 0,
00170 0,
00171 0,
00172 0,
00173 0,
00174 0,
00175 0,
00176 0,
00177 0,
00178 0,
00179 0,
00180 0,
00181 0,
00182 0
00183 };
00184
00185
00186
00187
00188 PyMethodDef ParameterGrpPy::Methods[] = {
00189 {"GetGroup", (PyCFunction) sPyGetGrp, Py_NEWARGS, 0},
00190 {"RemGroup", (PyCFunction) sPyRemGrp, Py_NEWARGS, 0},
00191 {"HasGroup", (PyCFunction) sPyHasGroup, Py_NEWARGS, 0},
00192 {"IsEmpty", (PyCFunction) sPyIsEmpty, Py_NEWARGS, 0},
00193 {"Clear", (PyCFunction) sPyClear, Py_NEWARGS, 0},
00194 {"Notify", (PyCFunction) sPyNotify, Py_NEWARGS, 0},
00195 {"NotifyAll", (PyCFunction) sPyNotifyAll, Py_NEWARGS, 0},
00196
00197 {"SetBool", (PyCFunction) sPySetBool, Py_NEWARGS, 0},
00198 {"GetBool", (PyCFunction) sPyGetBool, Py_NEWARGS, 0},
00199 {"RemBool", (PyCFunction) sPyRemBool, Py_NEWARGS, 0},
00200
00201 {"SetInt", (PyCFunction) sPySetInt, Py_NEWARGS, 0},
00202 {"GetInt", (PyCFunction) sPyGetInt, Py_NEWARGS, 0},
00203 {"RemInt", (PyCFunction) sPyRemInt, Py_NEWARGS, 0},
00204
00205 {"SetUnsigned", (PyCFunction) sPySetUnsigned, Py_NEWARGS, 0},
00206 {"GetUnsigned", (PyCFunction) sPyGetUnsigned, Py_NEWARGS, 0},
00207 {"RemUnsigned", (PyCFunction) sPyRemUnsigned, Py_NEWARGS, 0},
00208
00209 {"SetFloat", (PyCFunction) sPySetFloat, Py_NEWARGS, 0},
00210 {"GetFloat", (PyCFunction) sPyGetFloat, Py_NEWARGS, 0},
00211 {"RemFloat", (PyCFunction) sPyRemFloat, Py_NEWARGS, 0},
00212
00213 {"SetString", (PyCFunction) sPySetString, Py_NEWARGS, 0},
00214 {"GetString", (PyCFunction) sPyGetString, Py_NEWARGS, 0},
00215 {"RemString", (PyCFunction) sPyRemString, Py_NEWARGS, 0},
00216
00217 {"Import", (PyCFunction) simportFrom, Py_NEWARGS, 0},
00218 {"Insert", (PyCFunction) sinsert, Py_NEWARGS, 0},
00219 {"Export", (PyCFunction) sexportTo, Py_NEWARGS, 0},
00220
00221 {NULL, NULL, 0, NULL}
00222 };
00223
00224
00225
00226
00227 PyParentObject ParameterGrpPy::Parents[] = {&PyObjectBase::Type,&ParameterGrpPy::Type, NULL};
00228
00229
00230
00231
00232 ParameterGrpPy::ParameterGrpPy(const Base::Reference<ParameterGrp> &rcParamGrp, PyTypeObject *T )
00233 : PyObjectBase(0, T),_cParamGrp(rcParamGrp)
00234 {
00235
00236 }
00237
00238 PyObject *ParameterGrpPy::PyMake(PyObject* , PyObject* )
00239 {
00240
00241 return 0;
00242 }
00243
00244
00245
00246
00247 ParameterGrpPy::~ParameterGrpPy()
00248 {
00249
00250 }
00251
00252
00253
00254
00255 PyObject *ParameterGrpPy::_getattr(char *attr)
00256 {
00257 _getattr_up(PyObjectBase);
00258 }
00259
00260 int ParameterGrpPy::_setattr(char *attr, PyObject *value)
00261 {
00262 return PyObjectBase::_setattr(attr, value);
00263 }
00264
00265
00266
00267
00268
00269
00270 PyObject *ParameterGrpPy::importFrom(PyObject *args)
00271 {
00272 char *pstr;
00273 if (!PyArg_ParseTuple(args, "s", &pstr))
00274 return NULL;
00275 PY_TRY {
00276 _cParamGrp->importFrom(pstr);
00277 }PY_CATCH;
00278 Py_Return;
00279 }
00280
00281 PyObject *ParameterGrpPy::insert(PyObject *args)
00282 {
00283 char *pstr;
00284 if (!PyArg_ParseTuple(args, "s", &pstr))
00285 return NULL;
00286 PY_TRY {
00287 _cParamGrp->insert(pstr);
00288 }PY_CATCH;
00289 Py_Return;
00290 }
00291
00292 PyObject *ParameterGrpPy::exportTo(PyObject *args)
00293 {
00294 char *pstr;
00295 if (!PyArg_ParseTuple(args, "s", &pstr))
00296 return NULL;
00297 PY_TRY {
00298 _cParamGrp->exportTo(pstr);
00299 }PY_CATCH;
00300 Py_Return;
00301 }
00302
00303 PyObject *ParameterGrpPy::PyGetGrp(PyObject *args)
00304 {
00305 char *pstr;
00306 if (!PyArg_ParseTuple(args, "s", &pstr))
00307 return NULL;
00308 PY_TRY {
00309
00310 Base::Reference<ParameterGrp> handle = _cParamGrp->GetGroup(pstr);
00311 if(handle.isValid()){
00312
00313 ParameterGrpPy *pcParamGrp = new ParameterGrpPy(handle);
00314
00315
00316 return pcParamGrp;
00317 }else{
00318 PyErr_SetString(PyExc_IOError, "GetGroup failed");
00319 return 0L;
00320 }
00321 }PY_CATCH;
00322 }
00323
00324 PyObject *ParameterGrpPy::PySetBool(PyObject *args)
00325 {
00326 char *pstr;
00327 int Bool;
00328 if (!PyArg_ParseTuple(args, "si", &pstr,&Bool))
00329 return NULL;
00330 PY_TRY {
00331 _cParamGrp->SetBool(pstr,Bool!=0);
00332 Py_Return;
00333 }PY_CATCH;
00334 }
00335
00336 PyObject *ParameterGrpPy::PyGetBool(PyObject *args)
00337 {
00338 char *pstr;
00339 int Bool=0;
00340 if (!PyArg_ParseTuple(args, "s|i", &pstr,&Bool))
00341 return NULL;
00342 PY_TRY {
00343 return Py_BuildValue("i",_cParamGrp->GetBool(pstr,Bool!=0));
00344 }PY_CATCH;
00345 }
00346
00347 PyObject *ParameterGrpPy::PySetInt(PyObject *args)
00348 {
00349 char *pstr;
00350 long Int;
00351 if (!PyArg_ParseTuple(args, "si", &pstr,&Int))
00352 return NULL;
00353 PY_TRY {
00354 _cParamGrp->SetInt(pstr,Int);
00355 Py_Return;
00356 }PY_CATCH;
00357 }
00358
00359 PyObject *ParameterGrpPy::PyGetInt(PyObject *args)
00360 {
00361 char *pstr;
00362 long Int=0;
00363 if (!PyArg_ParseTuple(args, "s|i", &pstr,&Int))
00364 return NULL;
00365 PY_TRY {
00366 return Py_BuildValue("i",_cParamGrp->GetInt(pstr,Int));
00367 }PY_CATCH;
00368 }
00369
00370 PyObject *ParameterGrpPy::PySetUnsigned(PyObject *args)
00371 {
00372 char *pstr;
00373 unsigned long UInt;
00374 if (!PyArg_ParseTuple(args, "sI", &pstr,&UInt))
00375 return NULL;
00376 PY_TRY {
00377 _cParamGrp->SetUnsigned(pstr,UInt);
00378 Py_Return;
00379 }PY_CATCH;
00380 }
00381
00382 PyObject *ParameterGrpPy::PyGetUnsigned(PyObject *args)
00383 {
00384 char *pstr;
00385 unsigned long UInt=0;
00386 if (!PyArg_ParseTuple(args, "s|I", &pstr,&UInt))
00387 return NULL;
00388 PY_TRY {
00389 return Py_BuildValue("I",_cParamGrp->GetUnsigned(pstr,UInt));
00390 }PY_CATCH;
00391 }
00392
00393 PyObject *ParameterGrpPy::PySetFloat(PyObject *args)
00394 {
00395 char *pstr;
00396 double Float;
00397 if (!PyArg_ParseTuple(args, "sd", &pstr,&Float))
00398 return NULL;
00399 PY_TRY {
00400 _cParamGrp->SetFloat(pstr,Float);
00401 Py_Return;
00402 }PY_CATCH;
00403 }
00404
00405 PyObject *ParameterGrpPy::PyGetFloat(PyObject *args)
00406 {
00407 char *pstr;
00408 double Float=0.0;
00409 if (!PyArg_ParseTuple(args, "s|d", &pstr,&Float))
00410 return NULL;
00411 PY_TRY {
00412 return Py_BuildValue("d",_cParamGrp->GetFloat(pstr,Float));
00413 }PY_CATCH;
00414 }
00415
00416 PyObject *ParameterGrpPy::PySetString(PyObject *args)
00417 {
00418 char *pstr;
00419 char * str;
00420 if (!PyArg_ParseTuple(args, "ss", &pstr,&str))
00421 return NULL;
00422 PY_TRY {
00423 _cParamGrp->SetASCII(pstr,str);
00424 Py_Return;
00425 }PY_CATCH;
00426 }
00427
00428 PyObject *ParameterGrpPy::PyGetString(PyObject *args)
00429 {
00430 char *pstr;
00431 char * str="";
00432 if (!PyArg_ParseTuple(args, "s|s", &pstr,&str))
00433 return NULL;
00434 PY_TRY {
00435 return Py_BuildValue("s",_cParamGrp->GetASCII(pstr,str).c_str());
00436 }PY_CATCH;
00437 }
00438
00439
00440
00441 PyObject *ParameterGrpPy::PyRemInt(PyObject *args)
00442 {
00443 char *pstr;
00444 if (!PyArg_ParseTuple(args, "s", &pstr))
00445 return NULL;
00446 PY_TRY {
00447 _cParamGrp->RemoveInt(pstr);
00448 Py_Return;
00449 }PY_CATCH;
00450 }
00451
00452 PyObject *ParameterGrpPy::PyRemUnsigned(PyObject *args)
00453 {
00454 char *pstr;
00455 if (!PyArg_ParseTuple(args, "s", &pstr))
00456 return NULL;
00457 PY_TRY {
00458 _cParamGrp->RemoveUnsigned(pstr);
00459 Py_Return;
00460 }PY_CATCH;
00461 }
00462
00463 PyObject *ParameterGrpPy::PyRemBool(PyObject *args)
00464 {
00465 char *pstr;
00466 if (!PyArg_ParseTuple(args, "s", &pstr))
00467 return NULL;
00468 PY_TRY {
00469 _cParamGrp->RemoveBool(pstr);
00470 Py_Return;
00471 }PY_CATCH;
00472 }
00473
00474 PyObject *ParameterGrpPy::PyRemGrp(PyObject *args)
00475 {
00476 char *pstr;
00477 if (!PyArg_ParseTuple(args, "s", &pstr))
00478 return NULL;
00479 PY_TRY {
00480 _cParamGrp->RemoveGrp(pstr);
00481 Py_Return;
00482 }PY_CATCH;
00483 }
00484
00485 PyObject *ParameterGrpPy::PyRemFloat(PyObject *args)
00486 {
00487 char *pstr;
00488 if (!PyArg_ParseTuple(args, "s", &pstr))
00489 return NULL;
00490 PY_TRY {
00491 _cParamGrp->RemoveFloat(pstr);
00492 Py_Return;
00493 }PY_CATCH;
00494 }
00495
00496 PyObject *ParameterGrpPy::PyRemString(PyObject *args)
00497 {
00498 char *pstr;
00499 if (!PyArg_ParseTuple(args, "s", &pstr))
00500 return NULL;
00501 PY_TRY {
00502 _cParamGrp->RemoveASCII(pstr);
00503 Py_Return;
00504 }PY_CATCH;
00505 }
00506
00507 PyObject *ParameterGrpPy::PyClear(PyObject *args)
00508 {
00509 if (!PyArg_ParseTuple(args, ""))
00510 return NULL;
00511 PY_TRY {
00512 _cParamGrp->Clear();
00513 Py_Return;
00514 }PY_CATCH;
00515 }
00516
00517 PyObject *ParameterGrpPy::PyIsEmpty(PyObject *args)
00518 {
00519 if (!PyArg_ParseTuple(args, ""))
00520 return NULL;
00521 PY_TRY {
00522 return Py_BuildValue("i",_cParamGrp->IsEmpty());
00523 }PY_CATCH;
00524 }
00525
00526 PyObject *ParameterGrpPy::PyHasGroup(PyObject *args)
00527 {
00528 char *pstr;
00529 if (!PyArg_ParseTuple(args, "s", &pstr))
00530 return NULL;
00531 PY_TRY {
00532 return Py_BuildValue("i",_cParamGrp->HasGroup(pstr));
00533 }PY_CATCH;
00534 }
00535
00536 PyObject *ParameterGrpPy::PyNotify(PyObject *args)
00537 {
00538 char *pstr;
00539 if (!PyArg_ParseTuple(args, "s", &pstr))
00540 return NULL;
00541 PY_TRY {
00542 _cParamGrp->Notify(pstr);
00543 Py_Return;
00544 }PY_CATCH;
00545 }
00546 PyObject *ParameterGrpPy::PyNotifyAll(PyObject *args)
00547 {
00548 if (!PyArg_ParseTuple(args, ""))
00549 return NULL;
00550
00551 PY_TRY {
00552 _cParamGrp->NotifyAll();
00553 Py_Return;
00554 }PY_CATCH;
00555 }
00556
00559 PyObject* GetPyObject( const Base::Reference<ParameterGrp> &hcParamGrp)
00560 {
00561 return new ParameterGrpPy(hcParamGrp);
00562 }