Skip to content

Commit

Permalink
Cleaning unused code, adding action factory by name.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerryWerneck committed Jun 2, 2023
1 parent 4a218c5 commit d31de92
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 255 deletions.
4 changes: 0 additions & 4 deletions py3270.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<Add option="`pkg-config --libs python dbus-1`" />
<Add library="pw3270cpp" />
</Linker>
<Unit filename="src/action/init.cc" />
<Unit filename="src/action/methods.cc" />
<Unit filename="src/action/new.cc" />
<Unit filename="src/action/tools.cc" />
<Unit filename="src/include/config.h" />
<Unit filename="src/include/config.h.in" />
<Unit filename="src/include/py3270.h" />
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
src_files = [
'src/module/init.c',
'src/module/types.c',
'src/action/methods.cc',
'src/action/new.cc',
'src/action/tools.cc',
'src/module/properties.cc',
'src/session/actions.cc',
'src/session/attributes.cc',
Expand Down
48 changes: 0 additions & 48 deletions src/action/init.cc

This file was deleted.

49 changes: 0 additions & 49 deletions src/action/methods.cc

This file was deleted.

86 changes: 0 additions & 86 deletions src/action/new.cc

This file was deleted.

63 changes: 0 additions & 63 deletions src/action/tools.cc

This file was deleted.

2 changes: 1 addition & 1 deletion src/include/pysession.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
DLL_PRIVATE int py3270_session_set_attribute(PyObject *self, PyObject *value, const LIB3270_PROPERTY *property);

DLL_PRIVATE PyObject * py3270_session_get_action(PyObject *self, const LIB3270_ACTION *action);
// DLL_PRIVATE int py3270_session_set_action(PyObject *self, PyObject *value, const LIB3270_ACTION *action);
DLL_PRIVATE PyObject * py3270_session_action_factory(PyObject *self, PyObject *args);

DLL_PRIVATE PyObject * py3270_session_get_timeout(PyObject *self, void *dunno);
DLL_PRIVATE int py3270_session_set_timeout(PyObject *self, PyObject *value, void *dunno);
Expand Down
8 changes: 8 additions & 0 deletions src/module/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
"connect(url,timeout): Connect to host on url wait 'timeout' seconds for session startup\n"
},

{
.ml_name = "action",
.ml_meth = (PyCFunction) py3270_session_action_factory,
.ml_flags = METH_VARARGS,
.ml_doc = "Get action by name\n\n"
"action('enter'): Return the 'enter' action\n"
},

{
.ml_name = "wait",
.ml_meth = (PyCFunction) py3270_session_wait,
Expand Down
35 changes: 34 additions & 1 deletion src/objects/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
py3270_session_type.tp_getset[index].doc = (char *) (action->summary ? action->summary : "");
py3270_session_type.tp_getset[index].closure = (void *) action;
py3270_session_type.tp_getset[index].get = (getter) py3270_session_get_action;
// py3270_session_type.tp_getset[index].set = (setter) py3270_session_set_action;

index++;
}
Expand Down Expand Up @@ -246,6 +245,40 @@

}

PyObject * py3270_session_action_factory(PyObject *self, PyObject *args) {

const char *name;

if(!PyArg_ParseTuple(args, "s", &name))
return (PyObject *) NULL;

return py3270_call(self,[name](TN3270::Session &session){

PyObject *object = NULL;

TN3270::for_each([&object,name,&session](const LIB3270_ACTION &action){

#ifdef _WIN32
if(!strcmp(action.name,name)) {
object = py3270_action_new(session.ActionFactory(&action));
return true;
}
#else
if(!strcasecmp(action.name,name)) {
object = py3270_action_new(session.ActionFactory(&action));
return true;
}
#endif // _WIN32

return false;
});

return object;

});

}

PyObject * py3270_session_get_action(PyObject *self, const LIB3270_ACTION *descriptor) {

return py3270_call(self,[descriptor](TN3270::Session &session){
Expand Down

0 comments on commit d31de92

Please sign in to comment.