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

Added initialization, deinitialization of the libdap library. Also added...

Added initialization, deinitialization of the libdap library. Also added functions with which this library is connected to the python
parent 37ddbcb4
No related branches found
No related tags found
1 merge request!26Support 3689
[submodule "libdap"] [submodule "libdap"]
path = libdap path = libdap
url = https://github.com/cellframe/libdap.git url = https://github.com/cellframe/libdap.git
[submodule "libdap-crypto"]
path = libdap-crypto
url = https://github.com/cellframe/libdap-crypto.git
Subproject commit ff63d762657f9687173db825705b8bf4b958abee
#include "libdap-python.h" #include "libdap-python.h"
int main(void)
static PyObject *dap_init(PyObject *self, PyObject *args)
{ {
return -1; const char *data;
char *system_configs_dir;
char *dap_app_name;
char *dap_app_name_logs;
if (!PyArg_ParseTuple(args, "s", &data))
return NULL;
int lenSystemConfigDir=0;
int lenDapAppName=0;
int countSeparators=0;
int lenMassives = 0;
while (*(data+lenMassives) != '\0' ||*(data+lenMassives) != NULL)
{
if (*(data+lenMassives)=='\n')
{
countSeparators += 1;
}
else {
if (countSeparators == 0)
lenSystemConfigDir++;
if (countSeparators == 1)
lenDapAppName++;
}
lenMassives++;
}
system_configs_dir = calloc(lenSystemConfigDir, sizeof(char));
dap_app_name = calloc(lenDapAppName, sizeof(char));
dap_app_name_logs = calloc((lenDapAppName+9), sizeof(char));
memcpy(system_configs_dir,data,lenSystemConfigDir);
memcpy(dap_app_name, data+lenSystemConfigDir+1, lenDapAppName);
memcpy(dap_app_name_logs, dap_app_name, lenDapAppName);
const char* log = "_logs.txt";
memcpy(dap_app_name_logs+lenDapAppName, log,9);
dap_config_init(system_configs_dir);
dap_config_open(dap_app_name);
dap_common_init(dap_app_name_logs);
return PyLong_FromLong(0);
}
static PyObject *dap_deinit(PyObject *self)
{
dap_config_deinit();
dap_common_deinit();
return PyLong_FromLong(0);
}
PyMODINIT_FUNC PyInit_dap(void)
{
return PyModule_Create(&dapmodule);
}
int main(int argc, char **argv) {
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
/* Add a built-in module, before Py_Initialize */
PyImport_AppendInittab("dap", PyInit_dap);
/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(program);
/* Initialize the Python interpreter. Required. */
Py_Initialize();
/* Optionally import the module; alternatively,
import can be deferred until the embedded script
imports it. */
PyImport_ImportModule("dap");
PyMem_RawFree(program);
return 0;
} }
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
#include <Python.h> #include <python3.7/Python.h>
#include "dap_config.h"
#include "dap_common.h"
#ifdef __cplusplus
extern "C" {
#endif
static PyObject *dap_init(PyObject *self, PyObject *args);
static PyObject *dap_deinit(PyObject *self);
static PyMethodDef DapMethods[] = {
{"init", dap_init, METH_VARARGS, "Initialization of the DAP (Deus Applicaions Prototypes) library"},
{"deinit", dap_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) library"},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef dapmodule = {
PyModuleDef_HEAD_INIT,
"dap", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
DapMethods
};
PyMODINIT_FUNC PyInit_dap(void);
#ifdef __cplusplus
}
#endif
\ No newline at end of file
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