Skip to content
Snippets Groups Projects
Commit a4205158 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

[+] Added function call from libdap-python. More precisely, the description...

[+] Added function call from libdap-python. More precisely, the description has been added to the array of calls that are available from Python.
parent 846a8afa
No related branches found
No related tags found
1 merge request!1Features 2466
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
#include "Python.h" #include "Python.h"
#include "libdap-python.h"
#include "dap_common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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[] = { static PyMethodDef CellFramePythonMethods[] = {
{"init", python_cellframe_init, METH_VARARGS, "Initialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, {"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"}, //{"deinit", dap_server_core_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) server core library"},
//{"loop", dap_server_core_loop, METH_VARARGS, ""}, //{"loop", dap_server_core_loop, METH_VARARGS, ""},
//{"listen", dap_server_core_listen, METH_VARARGS, ""}, //{"listen", dap_server_core_listen, METH_VARARGS, ""},
......
#include "python-cellframe.h" #include "python-cellframe.h"
PyMODINIT_FUNC PyInit_libCellFrame(void){ PyMODINIT_FUNC PyInit_libCellFrame(void){
if (PyType_Ready(&DapObject_DapObjectType) < 0 )
return NULL;
PyObject *module = PyModule_Create(&CellFramePythonModule); 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; 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); return PyLong_FromLong(0);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment