From 201902897f0884e5096c6406ccb5815882cc942a Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Mon, 12 Jul 2010 16:36:02 +0000 Subject: [PATCH] Forgotten, as usual. --- mauka/src/PyMauka.cpp | 106 +++++++++++++++++++++ mauka/src/PyMaukaEngine.cpp | 164 ++++++++++++++++++++++++++++++++ mauka/src/mauka/PyMaukaEngine.h | 71 ++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 mauka/src/PyMauka.cpp create mode 100644 mauka/src/PyMaukaEngine.cpp create mode 100644 mauka/src/mauka/PyMaukaEngine.h diff --git a/mauka/src/PyMauka.cpp b/mauka/src/PyMauka.cpp new file mode 100644 index 00000000..070f1f66 --- /dev/null +++ b/mauka/src/PyMauka.cpp @@ -0,0 +1,106 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2010-2010, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | C O R I O L I S | +// | M a u k a - P l a c e r | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./PyMauka.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#include "hurricane/isobar/PyHurricane.h" +#include "hurricane/isobar/PyCell.h" +#include "mauka/PyMaukaEngine.h" + + +namespace Mauka { + + using std::cerr; + using std::endl; + using Hurricane::tab; + using Hurricane::in_trace; + using Isobar::__cs; + + +#if !defined(__PYTHON_MODULE__) + +// x=================================================================x +// | "PyMauka" Shared Library Code Part | +// x=================================================================x + + +# else // End of PyHurricane Shared Library Code Part. + + +// x=================================================================x +// | "PyMauka" Python Module Code Part | +// x=================================================================x + + +extern "C" { + + + // x-------------------------------------------------------------x + // | "PyMauka" Module Methods | + // x-------------------------------------------------------------x + + + static PyMethodDef PyMauka_Methods[] = + { { "get" , (PyCFunction)PyMaukaEngine_get , METH_VARARGS + , "Gets MaukaEngine from a Cell." } + , { "create" , (PyCFunction)PyMaukaEngine_create, METH_VARARGS + , "Create MaukaEngine on a Cell." } + , {NULL, NULL, 0, NULL} /* sentinel */ + }; + + + + + // --------------------------------------------------------------- + // Module Initialization : "initMauka ()" + + DL_EXPORT(void) initMauka () { + trace << "initMauka()" << endl; + + PyMaukaEngine_LinkPyType (); + + PYTYPE_READY ( MaukaEngine ); + + // Identifier string can take up to 10 characters. + __cs.addType ( "mauka", &PyTypeMaukaEngine, "", false ); + + + PyObject* module = Py_InitModule ( "Mauka", PyMauka_Methods ); + if ( module == NULL ) { + cerr << "[ERROR]\n" + << " Failed to initialize Mauka module." << endl; + return; + } + + PyObject* dictionnary = PyModule_GetDict ( module ); + //DbULoadConstants ( dictionnary ); + } + + +} // End of extern "C". + + +#endif // End of Python Module Code Part. + + +} // End of Mauka namespace. diff --git a/mauka/src/PyMaukaEngine.cpp b/mauka/src/PyMaukaEngine.cpp new file mode 100644 index 00000000..efc9d0ea --- /dev/null +++ b/mauka/src/PyMaukaEngine.cpp @@ -0,0 +1,164 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2010-2010, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | C O R I O L I S | +// | M a u k a - P l a c e r | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./PyMaukaEngine.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#include "hurricane/isobar/PyCell.h" +#include "nimbus/NimbusEngine.h" +#include "mauka/PyMaukaEngine.h" + + +namespace Mauka { + + using std::cerr; + using std::endl; + using std::hex; + using std::ostringstream; + using Hurricane::tab; + using Hurricane::in_trace; + using Hurricane::Error; + using Hurricane::Warning; + using Isobar::ProxyProperty; + using Isobar::ProxyError; + using Isobar::ConstructorError; + using Isobar::HurricaneError; + using Isobar::HurricaneWarning; + using Isobar::ParseOneArg; + using Isobar::ParseTwoArg; + using Isobar::PyCell; + using Isobar::PyCell_Link; + using Nimbus::NimbusEngine; + + +extern "C" { + + +#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(MaukaEngine,mauka,function) + + +// x=================================================================x +// | "PyMaukaEngine" Python Module Code Part | +// x=================================================================x + +#if defined(__PYTHON_MODULE__) + + + // Standart Accessors (Attributes). + DirectVoidMethod(MaukaEngine,mauka,Run) + + // Standart Destroy (Attribute). + DBoDestroyAttribute(PyMaukaEngine_destroy,PyMaukaEngine) + + + PyMethodDef PyMaukaEngine_Methods[] = + { { "run" , (PyCFunction)PyMaukaEngine_Run , METH_NOARGS + , "Runs Mauka on it's Cell." } + , { "destroy" , (PyCFunction)PyMaukaEngine_destroy, METH_NOARGS + , "Destroy the associated hurricane object. The python object remains." } + , {NULL, NULL, 0, NULL} /* sentinel */ + }; + + + PythonOnlyDeleteMethod(MaukaEngine) + PyTypeObjectLinkPyType(MaukaEngine) + + +#else // End of Python Module Code Part. + + +// x=================================================================x +// | "PyMaukaEngine" Shared Library Code Part | +// x=================================================================x + + + extern PyObject* PyMaukaEngine_get ( PyObject *module, PyObject* args ) + { + trace << "PyMaukaEngine_get()" << endl; + + MaukaEngine* mauka = NULL; + PyMaukaEngine* pyMauka = NULL; + + HTRY + PyObject* arg0; + + if ( not ParseOneArg ( "Mauka.get", args, CELL_ARG, &arg0) ) return NULL; + mauka = MaukaEngine::get ( PYCELL_O(arg0) ); + + pyMauka = PyObject_NEW ( PyMaukaEngine, &PyTypeMaukaEngine ); + if ( pyMauka == NULL ) return NULL; + + pyMauka->_object = mauka; + HCATCH + + return (PyObject*)pyMauka; + } + + + extern PyObject* PyMaukaEngine_create ( PyObject *module, PyObject* args ) + { + trace << "PyMaukaEngine_create()" << endl; + + MaukaEngine* mauka = NULL; + PyMaukaEngine* pyMauka = NULL; + + HTRY + PyObject* arg0; + + if ( not ParseOneArg ( "Mauka.get", args, CELL_ARG, &arg0) ) return NULL; + + Cell* cell = PYCELL_O(arg0); + mauka = MaukaEngine::get ( cell ); + + if ( mauka == NULL ) { + NimbusEngine* nimbus = NimbusEngine::get ( cell ); + if ( nimbus == NULL ) + NimbusEngine::create ( cell ); + + mauka = MaukaEngine::create ( cell ); + if ( cmess1.enabled() ) + mauka->getConfiguration()->print( cell ); + } else + cerr << Warning("%s already has a Mauka engine.",getString(cell).c_str()) << endl; + + pyMauka = PyObject_NEW ( PyMaukaEngine, &PyTypeMaukaEngine ); + if ( pyMauka == NULL ) return NULL; + + pyMauka->_object = mauka; + HCATCH + + return (PyObject*)pyMauka; + } + + + // Link/Creation Method. + PyTypeObjectDefinitions(MaukaEngine) + + +#endif // End of Shared Library Code Part. + + +} // End of extern "C". + + +} // End of Mauka namespace. + diff --git a/mauka/src/mauka/PyMaukaEngine.h b/mauka/src/mauka/PyMaukaEngine.h new file mode 100644 index 00000000..d244aeb6 --- /dev/null +++ b/mauka/src/mauka/PyMaukaEngine.h @@ -0,0 +1,71 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2010-2010, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | C O R I O L I S | +// | M a u k a - P l a c e r | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Header : "./PyMaukaEngine.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#ifndef __PY_MAUKA_ENGINE__ +#define __PY_MAUKA_ENGINE__ + +#include "hurricane/isobar/PyHurricane.h" +#include "mauka/MaukaEngine.h" + + +namespace Mauka { + + +extern "C" { + + +// ------------------------------------------------------------------- +// Python Object : "PyMaukaEngine". + + typedef struct { + PyObject_HEAD + Mauka::MaukaEngine* _object; + } PyMaukaEngine; + + +// ------------------------------------------------------------------- +// Functions & Types exported to "PyMauka.ccp". + + extern PyTypeObject PyTypeMaukaEngine; + extern PyMethodDef PyMaukaEngine_Methods[]; + + extern PyObject* PyMaukaEngine_get ( PyObject* module, PyObject* args ); + extern PyObject* PyMaukaEngine_create ( PyObject* module, PyObject* args ); + extern PyObject* PyMaukaEngine_Link ( Mauka::MaukaEngine* ); + extern void PyMaukaEngine_LinkPyType (); + + +#define IsPyMaukaEngine(v) ( (v)->ob_type == &PyTypeMaukaEngine ) +#define PYMAUKAENGINE(v) ( (PyMaukaEngine*)(v) ) +#define PYMAUKAENGINE_O(v) ( PYALLIANCEFRAMEWORK(v)->_object ) + + +} // End of extern "C". + + +} // End of Mauka namespace. + + +#endif // __PY_MAUKA_ENGINE__