diff --git a/dists/examples/plugins/demoCustomCMD/demoCustomCMD.py b/dists/examples/plugins/demoCustomCMD/demoCustomCMD.py new file mode 100644 index 0000000000000000000000000000000000000000..cd1eb93184466957efc054605ca7c8613d44f7bc --- /dev/null +++ b/dists/examples/plugins/demoCustomCMD/demoCustomCMD.py @@ -0,0 +1,34 @@ +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 diff --git a/dists/examples/plugins/demoCustomCMD/manifest.json b/dists/examples/plugins/demoCustomCMD/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..bf34c36336b6dea0c6e717989145cc0afb042263 --- /dev/null +++ b/dists/examples/plugins/demoCustomCMD/manifest.json @@ -0,0 +1,8 @@ +{ + "name": "demoCustomCMD", + "version": "1.0", + "author": "DEMLABS (C) 2022", + "dependencys": [], + "description": "This is a plugin example for working custom command." +} + diff --git a/modules/cellframe-sdk/net/src/wrapping_dap_app_cli_server.c b/modules/cellframe-sdk/net/src/wrapping_dap_app_cli_server.c index b98191cd5750cd4af5263a810a79330dd4926376..0db7ecf35471c891dcd12e2f3d8e8fa161fe2c3f 100644 --- a/modules/cellframe-sdk/net/src/wrapping_dap_app_cli_server.c +++ b/modules/cellframe-sdk/net/src/wrapping_dap_app_cli_server.c @@ -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; }