Skip to content
Snippets Groups Projects
Commit 15f09566 authored by Aleksandr Vodianov's avatar Aleksandr Vodianov
Browse files

Merge branch 'fix_handler_cli_command' into hotfix-remove_python_env

parents 793d8570 e298f4de
No related branches found
No related tags found
No related merge requests found
from API_CellFrame import logItNotice, AppCliServer
"""
This function takes two arguments
argv is an array of incoming arguments
indexStrReply is an internal index that correlates what is needed
to fill the desired buffer with the data that will be passed to the CLI.
"""
def cmdDemo(argv, indexStrReply):
reply = "Arguments :\n"
for i in range(len(argv)):
reply += "arg["+str(i)+"]: "+argv[i]+"\n"
AppCliServer.setReplyText(reply, indexStrReply)
def cmdDemo2(argv, indexStrReply):
AppCliServer.setReplyText("I simple demo command", indexStrReply)
def init():
logItNotice("Running plugin order")
"""
The cmdItemCreate function creates a CLI command.
This function takes four arguments.
Command name, command handler function, short description of
of the command, full description of the command.
"""
AppCliServer.cmdItemCreate("demo", cmdDemo, "Command demo",
"""
This command is intended to demonstrate the work of custom command in the CellFrame API for Python.
""")
AppCliServer.cmdItemCreate("demo2", cmdDemo2, "Second command demo",
"""
This is demo and testing
""")
return 0
{
"name": "demoCustomCMD",
"version": "1.0",
"author": "DEMLABS (C) 2022",
"dependencys": [],
"description": "This is a plugin example for working custom command."
}
......@@ -100,12 +100,13 @@ void element_py_func_del_all(){
}
static int wrapping_cmdfunc(int argc, char **argv, char **str_reply){
PyGILState_STATE state = PyGILState_Ensure();
size_t id_str_replay = elements_str_reply_add(str_reply);
PyObject *obj_argv = stringToPyList(argc, argv);
PyObject *obj_id_str_replay = PyLong_FromSize_t(id_str_replay);
PyObject *arglist = Py_BuildValue("OO", obj_argv, obj_id_str_replay);
Py_XINCREF(arglist);
PyObject *arglist = Py_BuildValue("On", obj_argv, id_str_replay);
Py_INCREF(arglist);
PyObject *binden_obj_cmdfunc = element_py_func_get(argv[0]);
Py_INCREF(binden_obj_cmdfunc);
PyObject *result = PyObject_CallObject(binden_obj_cmdfunc, arglist);
if (!result){
log_it(L_DEBUG, "Function can't called");
......@@ -113,6 +114,8 @@ static int wrapping_cmdfunc(int argc, char **argv, char **str_reply){
}
Py_XDECREF(arglist);
Py_XDECREF(obj_argv);
Py_XDECREF(binden_obj_cmdfunc);
PyGILState_Release(state);
elements_str_reply_delete(id_str_replay);
return 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