diff --git a/client/src/session/remote/actions.cc b/client/src/session/remote/actions.cc index 494fdd0..efe6fe4 100644 --- a/client/src/session/remote/actions.cc +++ b/client/src/session/remote/actions.cc @@ -47,6 +47,10 @@ namespace TN3270 { + TN3270::Action * IPC::Session::getAction(const LIB3270_ACTION *descriptor) { + return new IPC::Action(this, descriptor); + } + IPC::Action::Action(Session *session, const LIB3270_ACTION *descriptor) : TN3270::Action(descriptor) { this->session = session; } @@ -55,10 +59,12 @@ bool rc; + debug(__FUNCTION__); Request(*session,"activatable") .push(descriptor->name) .call() .pop(rc); + debug(__FUNCTION__); return rc; } diff --git a/client/src/session/remote/attribute.cc b/client/src/session/remote/attribute.cc index 3e4a0f3..4a0e4bb 100644 --- a/client/src/session/remote/attribute.cc +++ b/client/src/session/remote/attribute.cc @@ -196,6 +196,61 @@ }; + // Toggle attribute + class TN3270_PRIVATE ToggleAttribute : public TemplateAttribute { + public: + ToggleAttribute(const IPC::Session *session, const LIB3270_TOGGLE_ENTRY *worker) : TemplateAttribute(session, Attribute::Boolean, worker) { + + get.asString = [](const Attribute & attr, const void *worker) { + return attr.getBoolean() ? "true" : "false"; + }; + + get.asInt32 = [](const Attribute & attr, const void *worker) { + return (uint32_t) attr.getBoolean(); + }; + + get.asUint32 = [](const Attribute & attr, const void *worker) { + return (uint32_t) attr.getInt32(); + }; + + get.asBoolean = [](const Attribute & attr, const void *worker) { + + const struct Worker * w = (const struct Worker *) worker; + + bool value; + + IPC::Request(*w->session,false,w->methods->name) + .call() + .pop(value); + + return value; + }; + + set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { + + const struct Worker * w = (const struct Worker *) worker; + + IPC::Request(*w->session,true,w->methods->name) + .push(value) + .call(); + + }; + + set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { + + const struct Worker * w = (const struct Worker *) worker; + + IPC::Request(*w->session,true,w->methods->name) + .push(value) + .call(); + + }; + + } + + }; + + // Unsigned int attribute class TN3270_PRIVATE UnsignedIntAttribute : public TemplateAttribute { public: @@ -367,7 +422,6 @@ // Check for boolean properties { - /* const LIB3270_TOGGLE_ENTRY *toggles = lib3270_get_toggle_list(); for(size_t ix = 0; toggles[ix].name; ix++) { @@ -376,7 +430,6 @@ } } - */ const LIB3270_INT_PROPERTY * intprop = lib3270_get_boolean_properties_list(); for(size_t ix = 0; intprop[ix].name; ix++) { @@ -426,12 +479,10 @@ // Add boolean properties { - /* const LIB3270_TOGGLE_ENTRY *toggles = lib3270_get_toggle_list(); for(size_t ix = 0; toggles[ix].name; ix++) { attributes.push_back(ToggleAttribute(this,&toggles[ix])); } - */ const LIB3270_INT_PROPERTY * intprop = lib3270_get_boolean_properties_list(); for(size_t ix = 0; intprop[ix].name; ix++) { diff --git a/client/src/session/remote/private.h b/client/src/session/remote/private.h index 99672b8..5dc46e2 100644 --- a/client/src/session/remote/private.h +++ b/client/src/session/remote/private.h @@ -105,6 +105,9 @@ virtual ~Session(); // Actions + TN3270::Action * getAction(const LIB3270_ACTION *descriptor) override; + + // Actions void action(const char *action_name) override; void connect(const char *url, int seconds) override; void disconnect() override; diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index c8650fa..5acb9dd 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -214,7 +214,7 @@ TN3270::Action * action = host.getAction("reconnect"); - action->activatable(); + cout << "Reconnect is " << (action->activatable() ? "available" : "unavailable") << endl; delete action; } diff --git a/server/src/core/linux/response.c b/server/src/core/linux/response.c index 64ca262..f940ae1 100644 --- a/server/src/core/linux/response.c +++ b/server/src/core/linux/response.c @@ -124,6 +124,16 @@ void ipc3270_response_append_string(GObject *object, const gchar *text) { } +void ipc3270_response_append_boolean(GObject *object, gboolean value) { + + ipc3270Response * response = IPC3270_RESPONSE(object); + + if(response->value) + g_variant_unref(response->value); + + response->value = g_variant_new_boolean(value); +} + GVariant * ipc3270_response_steal_value(GObject *object) { ipc3270Response * response = IPC3270_RESPONSE(object); diff --git a/server/src/core/methods/action.c b/server/src/core/methods/action.c index d768ee4..f6d385b 100644 --- a/server/src/core/methods/action.c +++ b/server/src/core/methods/action.c @@ -46,21 +46,25 @@ int ipc3270_method_action(GObject *session, GVariant *request, GObject *response return 0; } -int ipc3270_method_activatable(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) { +int ipc3270_method_activatable(GObject *session, GVariant *request, GObject *response, GError **error) { if(g_variant_n_children(request) != 1) { g_message("activatable was called with %u arguments.",(unsigned int) g_variant_n_children(request)); - ipc3270_response_append_int32(response, EINVAL); + + if(!*error) + g_set_error_literal(error,g_quark_from_static_string(PACKAGE_NAME),EINVAL,"Unexpected argument number"); + + return 0; } GVariant *value = g_variant_get_child_value(request,0); - LIB3270_ACTION * action = lib3270_action_get_by_name(g_variant_get_string(value,NULL)); + const LIB3270_ACTION * action = lib3270_action_get_by_name(g_variant_get_string(value,NULL)); if(action) { - ipc3270_response_append_int32(response, lib3270_action_is_activatable(action, ipc3270_get_session(session))); + ipc3270_response_append_boolean(response, lib3270_action_is_activatable(action, ipc3270_get_session(session))); } else { - ipc3270_response_append_int32(response, ENOENT); + ipc3270_response_append_boolean(response, FALSE); } g_variant_unref(value); diff --git a/server/src/include/ipc-glib.h b/server/src/include/ipc-glib.h index c176123..0908276 100644 --- a/server/src/include/ipc-glib.h +++ b/server/src/include/ipc-glib.h @@ -109,6 +109,8 @@ void ipc3270_response_append_int32(GObject *object, gint32 value); void ipc3270_response_append_uint32(GObject *object, guint32 value); void ipc3270_response_append_string(GObject *object, const gchar *text); + void ipc3270_response_append_boolean(GObject *object, gboolean value); + gboolean ipc3270_response_has_values(GObject *object); GVariant * ipc3270_response_steal_value(GObject *object); -- libgit2 0.21.2