From a420515829ba04089db8b95dab0f61ef17c37145 Mon Sep 17 00:00:00 2001 From: Alexey Stratulat <alexey.stratulat@demlabs.net> Date: Wed, 28 Aug 2019 13:35:57 +0700 Subject: [PATCH] [+] Added function call from libdap-python. More precisely, the description has been added to the array of calls that are available from Python. --- include/python-cellframe.h | 23 ++++++++++++- src/python-cellframe.c | 66 +++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/include/python-cellframe.h b/include/python-cellframe.h index d415f060..d338fe3d 100644 --- a/include/python-cellframe.h +++ b/include/python-cellframe.h @@ -1,14 +1,35 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "libdap-python.h" +#include "dap_common.h" #ifdef __cplusplus extern "C" { #endif -PyObject *python_cellframe_init(PyObject *self, PyObject *args); +static PyObject* CellFrame_error; + +static PyObject *python_cellframe_init(PyObject *self, PyObject *args); + +static PyObject *python_cellframe_deinit(PyObject *self, PyObject *args); static PyMethodDef CellFramePythonMethods[] = { {"init", python_cellframe_init, METH_VARARGS, "Initialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, + {"deinit", python_cellframe_deinit, METH_VARARGS, "Deinitialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, + {"setLogLevel", (PyCFunction)dap_set_log_level, METH_VARARGS, "Setting the logging level"}, + {"logIt", (PyCFunction)dap_log_it, METH_VARARGS, "The wrapper of the log_it function for the libdap library"}, + {"logItDebug", (PyCFunction)dap_log_it_debug, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DEBUG"}, + {"logItInfo", (PyCFunction)dap_log_it_info, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level INFO"}, + {"logItNotice", (PyCFunction)dap_log_it_notice, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level NOTICE"}, + {"logItMessage", (PyCFunction)dap_log_it_message, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level MESSAGE"}, + {"logItDap", (PyCFunction)dap_log_it_dap, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DAP"}, + {"logItWarning", (PyCFunction)dap_log_it_warning, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level WARNING"}, + {"logItAtt", (PyCFunction)dap_log_it_att, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ATT"}, + {"logItError", (PyCFunction)dap_log_it_error, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ERROR"}, + {"logItCritical", (PyCFunction)dap_log_it_critical, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level CRITICAL"}, + + {"configGetItem", (PyCFunction)py_m_dap_config_get_item, METH_VARARGS, ""}, + {"configGetItemDefault", (PyCFunction)py_m_dap_config_get_item_default, METH_VARARGS, ""}, //{"deinit", dap_server_core_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) server core library"}, //{"loop", dap_server_core_loop, METH_VARARGS, ""}, //{"listen", dap_server_core_listen, METH_VARARGS, ""}, diff --git a/src/python-cellframe.c b/src/python-cellframe.c index decc7229..dc45a50e 100644 --- a/src/python-cellframe.c +++ b/src/python-cellframe.c @@ -1,11 +1,75 @@ #include "python-cellframe.h" PyMODINIT_FUNC PyInit_libCellFrame(void){ + + if (PyType_Ready(&DapObject_DapObjectType) < 0 ) + return NULL; + PyObject *module = PyModule_Create(&CellFramePythonModule); + + CellFrame_error = PyErr_NewException("libCellFrame.error", NULL, NULL); + PyModule_AddObject(module, "error", CellFrame_error); + + //PyModule_AddObject(module, "Dap", (PyObject*)&DapObject_DapObjectType); return module; } -PyObject *python_cellframe_init(PyObject *self, PyObject *args){ +static PyObject *python_cellframe_init(PyObject *self, PyObject *args){ + const char *app_name; + const char *file_name_log; + const char *config_dir; + const char *log_level; + const char *JSON_str; + if (!PyArg_ParseTuple(args, "s", &JSON_str)){ + return NULL; + } + +// PyObject* JSONModuleString = PyUnicode_FromString("json"); + PyObject *JSON_Module = PyImport_ImportModule("json"); + if (JSON_Module == NULL) { + printf("ERROR importing module"); + return NULL; + } + PyObject* JSONLoadsFunction = PyObject_GetAttrString(JSON_Module, "loads"); + if (JSONLoadsFunction == NULL) + return NULL; + PyObject* argsInLoadsJSON = PyTuple_Pack(1,PyUnicode_FromString(JSON_str)); + PyObject* result = PyObject_CallObject(JSONLoadsFunction, argsInLoadsJSON); + if (result == NULL) + return NULL; + PyObject* getModules = PyDict_GetItemString(result, "modules"); + if (getModules == NULL) + return NULL; + PyObject* getDap = PyDict_GetItemString(result, "DAP"); + if (getDap == NULL) + return NULL; +// /*Parse DAP*/ + PyObject* config_dir_PyObject = PyDict_GetItemString(getDap, "config_dir"); + PyObject* application_name_PyObject = PyDict_GetItemString(getDap, "application_name"); + PyObject* file_name_log_PyObject = PyDict_GetItemString(getDap, "file_name_log"); + PyObject* logLevel_PyObject = PyDict_GetItemString(getDap, "log_level"); + if (config_dir_PyObject == NULL || application_name_PyObject == NULL || + logLevel_PyObject == NULL || file_name_log_PyObject == NULL) + return NULL; + app_name = PyUnicode_AsUTF8(application_name_PyObject); + file_name_log = PyUnicode_AsUTF8(file_name_log_PyObject); + config_dir = PyUnicode_AsUTF8(config_dir_PyObject); + log_level = PyUnicode_AsUTF8(logLevel_PyObject); + + if (dap_common_init(app_name, file_name_log) != 0){ + PyErr_SetString(CellFrame_error, "Can't init common functions module"); + return NULL; + } + dap_config_init(config_dir); + if ((g_config = dap_config_open(app_name) ) == NULL){ + PyErr_SetString(CellFrame_error, "Can't init general configurations"); + return NULL; + } + return PyLong_FromLong(0); +} + +static PyObject *python_cellframe_deinit(PyObject *self, PyObject *args){ + const char *in; return PyLong_FromLong(0); } -- GitLab