Commit 3b3fb738d10b50a260c1ddb739910ff5103a7f70

Authored by Perry Werneck
1 parent 9b0f78c1
Exists in master and in 1 other branch develop

Implementing get/set from D-Bus.

src/linux/getproperties.c
... ... @@ -33,7 +33,8 @@
33 33 */
34 34  
35 35 #include "gobject.h"
36   -#include <v3270.h>
  36 +#include <lib3270.h>
  37 +#include <lib3270/properties.h>
37 38  
38 39 #include <dbus/dbus-glib.h>
39 40 #include <dbus/dbus-glib-bindings.h>
... ... @@ -47,13 +48,41 @@ ipc3270_get_property (GDBusConnection *connection,
47 48 GError **error,
48 49 gpointer user_data)
49 50 {
50   - LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name);
  51 + size_t ix;
  52 +
  53 + errno = 0; // Just in case.
  54 +
  55 + // Check for property
  56 + const LIB3270_INT_PROPERTY * proplist = lib3270_get_int_properties_list();
  57 + for(ix = 0; proplist[ix].name; ix++) {
  58 +
  59 + if(proplist[ix].get && !g_ascii_strcasecmp(proplist[ix].name, property_name)) {
  60 +
  61 + // Found it!
  62 + int value = 0; // proplist[ix].get(IPC3270(user_data)->hSession);
  63 + if(value > 0 || errno == 0) {
  64 + return g_variant_new_int16((gint16) value);
  65 + }
  66 +
  67 + // Erro!
  68 + g_set_error (error,
  69 + G_IO_ERROR,
  70 + G_IO_ERROR_FAILED,
  71 + g_strerror(errno)
  72 + );
51 73  
52   - debug("%s: toggle(%s)=%d", __FUNCTION__, property_name,(int) toggle);
  74 + return NULL;
  75 + }
  76 +
  77 + }
  78 +
  79 +
  80 + // Check for toggle
  81 + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name);
53 82 if(toggle != (LIB3270_TOGGLE) -1) {
54 83  
55 84 // Is a Tn3270 toggle, get it!
56   - return g_variant_new_int16((gint16) lib3270_get_toggle(IPC3270(user_data)->hSession,toggle));
  85 + return g_variant_new_int16((gint16) lib3270_get_toggle( (IPC3270(user_data)->hSession), toggle));
57 86  
58 87 }
59 88  
... ...
src/linux/gobject.c
... ... @@ -33,7 +33,8 @@
33 33 */
34 34  
35 35 #include "gobject.h"
36   -#include <v3270.h>
  36 +#include <lib3270.h>
  37 +#include <lib3270/properties.h>
37 38  
38 39 #include <dbus/dbus-glib.h>
39 40 #include <dbus/dbus-glib-bindings.h>
... ... @@ -154,14 +155,22 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) {
154 155 " <method name='connect'>"
155 156 " <arg type='s' name='url' direction='in'/>"
156 157 " </method>"
157   - " <property type='i' name='Revision' access='read'/>"
158   - " <property type='s' name='Version' access='read'/>"
159 158 );
160 159  
  160 + // Inclui toggles
161 161 for(ix = 0; ix < (int) LIB3270_TOGGLE_COUNT; ix++) {
162 162 g_string_append_printf(introspection, " <property type='i' name='%s' access='readwrite'/>", lib3270_get_toggle_name((LIB3270_TOGGLE) ix));
163 163 }
164 164  
  165 + // Inclui propriedades.
  166 + const LIB3270_INT_PROPERTY * proplist = lib3270_get_int_properties_list();
  167 + for(ix = 0; proplist[ix].name; ix++) {
  168 + g_string_append_printf(introspection, " <property type='i' name='%s' access='%s'/>",
  169 + proplist[ix].name,
  170 + ((proplist[ix].set == NULL) ? "read" : "readwrite")
  171 + );
  172 + }
  173 +
165 174 g_string_append(introspection,
166 175 " </interface>"
167 176 "</node>"
... ...
src/linux/gobject.h
... ... @@ -58,7 +58,7 @@
58 58 GObject parent;
59 59 GDBusConnection * connection;
60 60 guint id;
61   - GtkWidget * hSession;
  61 + H3270 * hSession;
62 62 };
63 63  
64 64 struct _ipc3270Class {
... ...
src/linux/setproperties.c
... ... @@ -33,7 +33,8 @@
33 33 */
34 34  
35 35 #include "gobject.h"
36   -#include <v3270.h>
  36 +#include <lib3270.h>
  37 +#include <lib3270/properties.h>
37 38  
38 39 #include <dbus/dbus-glib.h>
39 40 #include <dbus/dbus-glib-bindings.h>
... ... @@ -48,6 +49,53 @@ ipc3270_set_property (GDBusConnection *connection,
48 49 GError **error,
49 50 gpointer user_data)
50 51 {
  52 + // Check for property
  53 + size_t ix;
  54 +
  55 + const LIB3270_INT_PROPERTY * proplist = lib3270_get_int_properties_list();
  56 + for(ix = 0; proplist[ix].name; ix++) {
  57 +
  58 + if(proplist[ix].set && !g_ascii_strcasecmp(proplist[ix].name, property_name)) {
  59 +
  60 + // Found it!
  61 + if(proplist[ix].set(IPC3270(user_data)->hSession, (int) g_variant_get_int32(value))) {
  62 +
  63 + // Erro!
  64 + g_set_error (error,
  65 + G_IO_ERROR,
  66 + G_IO_ERROR_FAILED,
  67 + g_strerror(errno)
  68 + );
  69 +
  70 + return FALSE;
  71 + }
  72 +
  73 + return TRUE;
  74 +
  75 + }
  76 +
  77 + }
  78 +
  79 + // Check for toggle
  80 + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name);
  81 + if(toggle != (LIB3270_TOGGLE) -1) {
  82 +
  83 + // Is a Tn3270 toggle, get it!
  84 + if(lib3270_set_toggle(IPC3270(user_data)->hSession,toggle,(int) g_variant_get_int32(value))) {
  85 +
  86 + // Erro!
  87 + g_set_error (error,
  88 + G_IO_ERROR,
  89 + G_IO_ERROR_FAILED,
  90 + g_strerror(errno)
  91 + );
  92 +
  93 + return FALSE;
  94 +
  95 + }
  96 +
  97 + return TRUE;
  98 + }
51 99  
52 100 g_set_error (error,
53 101 G_IO_ERROR,
... ... @@ -55,5 +103,5 @@ ipc3270_set_property (GDBusConnection *connection,
55 103 "Can't find any property named %s", property_name
56 104 );
57 105  
58   - return *error == NULL;
  106 + return FALSE;
59 107 }
... ...