NLAIPYSERVER Namespace Reference


Data Structures

class  CPyExport
class  IPythonModule

Functions

void endPythonInterface (CPyExport *Int)
PyMethodDef * getLib ()
CPyExportinitPythonLib (NLAIC::IIO *P, char *pathWay)
PyObject * print (PyObject *Self, PyObject *Arg)
PyObject * printNbr (PyObject *Self, PyObject *Arg)
PyObject * read (PyObject *Self, PyObject *Arg)

Variables

PyObject * Dictionarry = NULL
NLAIC::IIOInterface
PyMethodDef M_Constructeur []


Function Documentation

void NLAIPYSERVER::endPythonInterface CPyExport *  Interface  ) 
 

Definition at line 251 of file pythonmethode.cpp.

References Dictionarry, Interface, and NLAIC::IPointerGestion::release().

00252         {
00253                 Py_DECREF(Dictionarry);
00254                 delete Int;
00255                 Interface->release();
00256 
00257         }

PyMethodDef* getLib  ) 
 

Definition at line 164 of file pythonmethode.cpp.

References M_Constructeur.

00165         {
00166                 return M_Constructeur;
00167         }

CPyExport * NLAIPYSERVER::initPythonLib NLAIC::IIO Interface,
char *  pathWay
 

Definition at line 171 of file pythonmethode.cpp.

References Dictionarry, Interface, M_Constructeur, NLAIC::Out(), and NLAIPYSERVER::CPyExport::runCode().

00172         {
00173                 //char S[MAX_PATH + 1];
00174                 //HKEY  hKey;
00175 
00176                 Interface = P;          
00177 
00178                 Py_Initialize();
00179 
00180 #ifdef NL_DEBUG
00181                 char *k = (char *)Py_GetPlatform();
00182                 k = (char *)Py_GetVersion();
00183                 k = (char *)Py_GetProgramFullPath();
00184                 k = (char *)Py_GetPath();
00185                 k = (char *)Py_GetProgramName();
00186                 k = (char *)Py_GetPrefix();
00187                 k = (char *)Py_GetExecPrefix();
00188 #endif  
00189 
00190                 std::string PathPython = Py_GetPath();
00191                 //PathPython = new char[ strlen(Py_GetPath() ) + strlen(pathWay) + 3];
00192                 //memset(PathPython,0,strlen(Py_GetPath() ) + strlen(pathWay) + 3);             
00193 
00194                 /*strcpy(S,PathPython);
00195                 strcat(S,"/PyLib");*/
00196 
00197                 //const char delem[2] = {DELIM,0};      
00198 
00199                 CPyExport *m_pPyLib = new CPyExport;
00200                                 
00201                 PathPython += CPyExport::getPathSeparator();
00202 /*#ifdef NL_OS_WINDOWS
00203                 //sprintf(PathPython,"%s;%s",Py_GetPath(),pathWay);
00204                 PathPython += ";";
00205 #else
00206                 //sprintf(PathPython,"%s:%s",Py_GetPath(),pathWay);
00207                 PathPython += ":";
00208 #endif*/
00209                 PathPython += pathWay;                                          
00210 
00211                 PySys_SetPath((char *)PathPython.c_str());
00212 
00213 #ifdef NL_DEBUG
00214                 NLAIC::Out("%s\n",(char *)Py_GetPath());
00215                 k = (char *)Py_GetPath();
00216 #endif 
00217                 
00218                 Dictionarry = Py_InitModule("RysonSytemeIO",M_Constructeur);
00219 
00220                 char CodeExec[] =       "import sys\n"
00221                                                         "from RysonSytemeIO import *\n"
00222                                                         "class PyWindowInOut:\n"
00223                                                         "\tdef write(self, s, tags=(), mark='insert'):\n"
00224                                                         "\t\tEcho(s)\n\n"
00225                                                         "\tdef writelines(self, l):\n"
00226                                                         "\t\tmap(self.write, l)\n\n"
00227                                                         "\tdef read(self, length = None):\n"
00228                                                         "\t\treturn Read()\n\n"
00229                                                         "\tdef readline(self, length = None):\n"
00230                                                         "\t\treturn Read()\n\n"
00231                                                         "\tdef readlines(self, length = None):\n"
00232                                                         "\t\treturn Read()\n\n\n"
00233                                                         "sys.stdout = PyWindowInOut()\n"
00234                                                         "sys.stderr = PyWindowInOut()\n"
00235                                                         "sys.stdin = PyWindowInOut()\n"
00236                                                         "sys.argv = ' '\n"
00237                                                         "sys.argc = 1\n";
00238                                                         
00239                 m_pPyLib->runCode(CodeExec);
00240 
00241                 char CodeExec2[] =      "import sys\n"
00242                                                         "print 'Hello this is a window trace for python input/output statement ............................................................................'\n";
00243 
00244                 
00245                 m_pPyLib->runCode(CodeExec2);
00246 
00247                 
00248                 return m_pPyLib;
00249         }

PyObject* print PyObject *  Self,
PyObject *  Arg
[static]
 

Definition at line 72 of file pythonmethode.cpp.

References NLAIC::IIO::Echo(), and Interface.

00073         {
00074                 char *Text = NULL;
00075                 char T[2] = {'\n',0};
00076                 /*Py_UNICODE u[200];
00077                 PyObject *argi;
00078                 argi = PyTuple_GetItem (Arg, 0);                
00079                 PyUnicodeObject *self = (PyUnicodeObject *)PyUnicode_FromObject(argi);
00080 
00081                 if (self != NULL)
00082                 {
00083                         sint32 i = 0;
00084                         char str[200];
00085                         while(self->str[i])
00086                         {
00087                                 u[i] = self->str[i];
00088                                 str[i] = (char)self->str[i];
00089                                 i ++;
00090                         }
00091                         u[i] = 0;
00092                         str[i] = 0;
00093                 }
00094 
00095                 if(PyArg_ParseTuple(Arg,"u",&u))
00096                 {
00097                         //u = (short *)Text;
00098                 }               
00099                 else*/
00100                 if(!PyArg_ParseTuple(Arg,"s",&Text))
00101                 {
00102                         Text = T;
00103                 }
00104 
00105                 Interface->Echo("%s",Text);
00106                 PyObject *R = Py_BuildValue("i",true);
00107                 return R;
00108         }

PyObject* printNbr PyObject *  Self,
PyObject *  Arg
[static]
 

Definition at line 110 of file pythonmethode.cpp.

References NLAIC::Out(), and sint32.

00111         {
00112                 sint32 Text;
00113 
00114                 if(!PyArg_ParseTuple(Arg,"i",&Text)) return NULL;
00115                 NLAIC::Out("%0x",Text);
00116                 return Py_BuildValue("i",true);
00117         }

PyObject* read PyObject *  Self,
PyObject *  Arg
[static]
 

Definition at line 119 of file pythonmethode.cpp.

References NLAIC::IIO::InPut(), and Interface.

00120         {               
00121                 return Py_BuildValue("s",Interface->InPut().data());
00122         }


Variable Documentation

PyObject* NLAIPYSERVER::Dictionarry = NULL [static]
 

Definition at line 169 of file pythonmethode.cpp.

Referenced by endPythonInterface(), and initPythonLib().

NLAIC::IIO* NLAIPYSERVER::Interface [static]
 

Definition at line 71 of file pythonmethode.cpp.

Referenced by endPythonInterface(), initPythonLib(), print(), and read().

struct PyMethodDef NLAIPYSERVER::M_Constructeur[] [static]
 

Initial value:

        {
                {"Echo", print ,METH_VARARGS},
                {"Nbr", printNbr ,METH_VARARGS},
                {"Read", read ,METH_VARARGS},
                
                {NULL,NULL}
        }

Definition at line 153 of file pythonmethode.cpp.

Referenced by getLib(), and initPythonLib().


Generated on Tue Mar 16 11:11:01 2004 for NeL by doxygen 1.3.6