Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python-cellframe
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
python-cellframe
Commits
b245c75c
Commit
b245c75c
authored
5 years ago
by
alexey.stratulat
Browse files
Options
Downloads
Patches
Plain Diff
[+] Added wrapping dap_chain_node_cli
parent
48f38aab
No related branches found
Branches containing commit
No related tags found
1 merge request
!26
Support 3689
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/wrapping_dap_chain_net_node_cli.h
+81
-0
81 additions, 0 deletions
include/wrapping_dap_chain_net_node_cli.h
src/wrapping_dap_chain_net_node_cli.c
+79
-0
79 additions, 0 deletions
src/wrapping_dap_chain_net_node_cli.c
with
160 additions
and
0 deletions
include/wrapping_dap_chain_net_node_cli.h
0 → 100644
+
81
−
0
View file @
b245c75c
#ifndef _WRAPPING_DAP_CHAIN_NET_NODE_CLI_
#define _WRAPPING_DAP_CHAIN_NET_NODE_CLI_
#include
<Python.h>
#include
"dap_config.h"
#include
"dap_chain_node_cli.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
PyDapChainNodeCli
{
PyObject_HEAD
cmdfunc_t
*
func
;
}
PyDapChainNodeCliObject
;
static
PyObject
*
binded_object_cmdfunc
=
NULL
;
int
dap_chain_node_cli_init_py
(
dap_config_t
*
g_config
);
void
dap_chain_node_cli_delete_py
(
void
);
PyObject
*
DapChainNodeCliObject_new
(
PyTypeObject
*
type_object
,
PyObject
*
args
,
PyObject
*
kwds
);
PyObject
*
dap_chain_node_cli_cmd_item_create_py
(
PyObject
*
self
,
PyObject
*
args
);
PyObject
*
dap_chain_node_cli_set_reply_text_py
(
PyObject
*
self
,
PyObject
*
args
);
static
PyMethodDef
DapChainNodeCliMethods
[]
=
{
{
"cmdItemCreate"
,
dap_chain_node_cli_cmd_item_create_py
,
METH_VARARGS
,
""
},
{
"setReplyText"
,
dap_chain_node_cli_set_reply_text_py
,
METH_VARARGS
,
""
},
{
NULL
,
NULL
,
0
,
NULL
}
};
static
PyTypeObject
DapChainNodeCliObject_DapChainNodeCliObjectType
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"CellFrame.Chain.Node.cli"
,
/* tp_name */
sizeof
(
PyDapChainNodeCliObject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_reserved */
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_call */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"Chain net node cli object"
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
DapChainNodeCliMethods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_alloc */
DapChainNodeCliObject_new
,
/* tp_new */
};
char
**
PyListToString
(
PyObject
*
list
);
PyObject
*
stringToPyList
(
char
**
list
);
#ifdef __cplusplus
}
#endif
#endif //_WRAPPING_DAP_CHAIN_NET_NODE_CLI_
This diff is collapsed.
Click to expand it.
src/wrapping_dap_chain_net_node_cli.c
0 → 100644
+
79
−
0
View file @
b245c75c
#include
"wrapping_dap_chain_net_node_cli.h"
int
dap_chain_node_cli_init_py
(
dap_config_t
*
g_config
){
dap_chain_node_cli_init
(
g_config
);
}
void
dap_chain_node_cli_delete_py
(
void
){
dap_chain_node_cli_delete
();
}
static
int
wrapping_cmdfunc
(
int
argc
,
char
**
argv
,
char
**
str_reply
){
PyObject
*
arglist
;
PyObject
*
result
;
PyObject
*
obj_argv
=
stringToPyList
(
argv
);
PyObject
*
obj_str_reply
=
stringToPyList
(
str_reply
);
arglist
=
Py_BuildValue
(
"i|O|O"
,
argc
,
obj_argv
,
obj_str_reply
);
result
=
PyObject_CallObject
(
binded_object_cmdfunc
,
arglist
);
Py_DECREF
(
arglist
);
Py_DECREF
(
obj_argv
);
Py_DECREF
(
obj_str_reply
);
int
r
=
-
1
;
if
(
PyLong_Check
(
result
)){
r
=
(
int
)
PyLong_AsLong
(
result
);
}
Py_DECREF
(
result
);
return
r
;
}
PyObject
*
DapChainNodeCliObject_new
(
PyTypeObject
*
type_object
,
PyObject
*
args
,
PyObject
*
kwds
){
PyDapChainNodeCliObject
*
obj
=
(
PyDapChainNodeCliObject
*
)
PyType_GenericNew
(
type_object
,
args
,
kwds
);
obj
->
func
=
wrapping_cmdfunc
;
return
(
PyObject
*
)
obj
;
}
PyObject
*
dap_chain_node_cli_cmd_item_create_py
(
PyObject
*
self
,
PyObject
*
args
){
const
char
*
name
,
*
doc
,
*
doc_ex
;
PyObject
*
obj_cmdfunc
;
if
(
!
PyArg_ParseTuple
(
args
,
"s|O:set_callback|s|s"
,
&
name
,
&
obj_cmdfunc
,
&
doc
,
&
doc_ex
)){
return
NULL
;
}
else
{
if
(
!
PyCallable_Check
(
obj_cmdfunc
)){
PyErr_SetString
(
PyExc_TypeError
,
"parameter must be callable"
);
return
NULL
;
}
}
Py_XINCREF
(
obj_cmdfunc
);
Py_XDECREF
(
binded_object_cmdfunc
);
binded_object_cmdfunc
=
obj_cmdfunc
;
dap_chain_node_cli_cmd_item_create
(
name
,
((
PyDapChainNodeCliObject
*
)
obj_cmdfunc
)
->
func
,
doc
,
doc_ex
);
return
PyLong_FromLong
(
0
);
}
PyObject
*
dap_chain_node_cli_set_reply_text_py
(
PyObject
*
self
,
PyObject
*
args
){
PyObject
*
obj_str_reply_list
;
const
char
*
str_list
;
if
(
!
PyArg_ParseTuple
(
args
,
"O|O"
,
&
obj_str_reply_list
))
return
NULL
;
char
**
str_reply_list
=
PyListToString
(
obj_str_reply_list
);
dap_chain_node_cli_set_reply_text
(
str_reply_list
,
str_list
);
return
PyLong_FromLong
(
0
);
}
char
**
PyListToString
(
PyObject
*
list
){
Py_ssize_t
size
=
PyList_Size
(
list
);
char
**
res
=
calloc
(
sizeof
(
char
**
),
(
size_t
)
size
);
for
(
Py_ssize_t
i
=
0
;
i
<
size
;
i
++
){
char
*
data
=
PyBytes_AsString
(
PyList_GetItem
(
list
,
i
));
res
[(
size_t
)
i
]
=
data
;
}
return
res
;
}
PyObject
*
stringToPyList
(
char
**
list
){
size_t
size
=
sizeof
(
list
)
/
sizeof
(
list
[
0
]);
PyObject
*
obj
=
PyList_New
((
Py_ssize_t
)
size
);
for
(
size_t
i
=
0
;
i
<
size
;
i
++
){
PyObject
*
data
=
PyBytes_FromString
(
list
[
i
]);
PyList_Append
(
obj
,
data
);
}
return
obj
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment