Commit eeddb160abb4c8c620c54b92f2a7ab8a2473e306

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

Adding properties on IPC module.

src/linux/getproperties.c
... ... @@ -89,6 +89,14 @@ ipc3270_get_property (GDBusConnection *connection,
89 89  
90 90 }
91 91  
  92 + // Check for pre-defineds
  93 + if(!g_ascii_strcasecmp("url", property_name)) {
  94 + return g_variant_new_string(lib3270_get_url(IPC3270(user_data)->hSession));
  95 + }
  96 +
  97 + if(!g_ascii_strcasecmp("luname", property_name)) {
  98 + return g_variant_new_string(lib3270_get_luname(IPC3270(user_data)->hSession));
  99 + }
92 100  
93 101 g_set_error (error,
94 102 G_IO_ERROR,
... ...
src/linux/gobject.c
... ... @@ -34,6 +34,7 @@
34 34  
35 35 #include "gobject.h"
36 36 #include <lib3270.h>
  37 +#include <lib3270/actions.h>
37 38 #include <lib3270/properties.h>
38 39  
39 40 #include <dbus/dbus-glib.h>
... ... @@ -67,6 +68,7 @@ static void ipc3270_class_init(ipc3270Class *klass) {
67 68 static void ipc3270_init(ipc3270 *object) {
68 69  
69 70 debug("%s",__FUNCTION__);
  71 + object->error_domain = g_quark_from_static_string(PACKAGE_NAME);
70 72  
71 73 }
72 74  
... ... @@ -76,28 +78,6 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) {
76 78  
77 79 void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) {
78 80  
79   - #define DECLARE_LIB3270_ACTION( name ) \
80   - g_string_append_printf(introspection, \
81   - " <method name='%s'>" \
82   - " </method>", #name);
83   -
84   - #define DECLARE_LIB3270_KEY_ACTION( name ) \
85   - g_string_append_printf(introspection, \
86   - " <method name='%s'>" \
87   - " </method>", #name);
88   -
89   - #define DECLARE_LIB3270_CURSOR_ACTION( name ) \
90   - g_string_append_printf(introspection, \
91   - " <method name='%s'>" \
92   - " </method>", #name);
93   -
94   - #define DECLARE_LIB3270_FKEY_ACTION( name ) \
95   - g_string_append_printf(introspection, \
96   - " <method name='%s'>" \
97   - " <arg type='i' name='keycode' direction='in'/>" \
98   - " </method>", # name);
99   -
100   -
101 81 char id;
102 82 int ix;
103 83  
... ... @@ -167,10 +147,24 @@ void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GEr
167 147 " <method name='connect'>"
168 148 " <arg type='s' name='url' direction='in'/>"
169 149 " </method>"
  150 + " <method name='pfkey'>" \
  151 + " <arg type='i' name='keycode' direction='in'/>" \
  152 + " </method>"
  153 + " <method name='pakey'>" \
  154 + " <arg type='i' name='keycode' direction='in'/>" \
  155 + " </method>"
170 156 );
171 157  
172   - // Constrói métodos usando as macros
173   - #include <lib3270/action_table.h>
  158 + // Constrói métodos usando a tabela de controle
  159 + const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();
  160 + for(ix = 0; actions[ix].name; ix++)
  161 + {
  162 + g_string_append_printf(
  163 + introspection, \
  164 + " <method name='%s'>" \
  165 + " </method>", actions[ix].name
  166 + );
  167 + }
174 168  
175 169 // Inclui toggles
176 170 for(ix = 0; ix < (int) LIB3270_TOGGLE_COUNT; ix++) {
... ... @@ -187,6 +181,8 @@ void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GEr
187 181 }
188 182  
189 183 g_string_append(introspection,
  184 + " <property type='s' name='url' access='readwrite'/>"
  185 + " <property type='s' name='luname' access='read'/>"
190 186 " </interface>"
191 187 "</node>"
192 188 );
... ...
src/linux/gobject.h
... ... @@ -59,6 +59,7 @@
59 59 GDBusConnection * connection;
60 60 guint id;
61 61 H3270 * hSession;
  62 + GQuark error_domain;
62 63 };
63 64  
64 65 struct _ipc3270Class {
... ...
src/linux/methods.c
... ... @@ -34,6 +34,7 @@
34 34  
35 35 #include "gobject.h"
36 36 #include <lib3270.h>
  37 +#include <lib3270/actions.h>
37 38  
38 39 #include <dbus/dbus-glib.h>
39 40 #include <dbus/dbus-glib-bindings.h>
... ... @@ -48,6 +49,31 @@ ipc3270_method_call (GDBusConnection *connection,
48 49 GDBusMethodInvocation *invocation,
49 50 gpointer user_data)
50 51 {
  52 + size_t ix;
  53 +
  54 + // Check action table.
  55 + const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();
  56 + for(ix = 0; actions[ix].name; ix++)
  57 + {
  58 + if(!g_ascii_strcasecmp(actions[ix].name,method_name)) {
  59 +
  60 + g_autoptr (GError) error = NULL;
  61 +
  62 + int rc = actions[ix].call(IPC3270(user_data)->hSession);
  63 + if(rc)
  64 + {
  65 + // Failed
  66 + g_set_error(error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));
  67 + g_dbus_method_invocation_return_gerror(invocation, error);
  68 + }
  69 + else
  70 + {
  71 + // Suceeded
  72 + g_dbus_method_invocation_return_value (invocation, g_variant_new_int16((gint16) 0));
  73 +
  74 + }
  75 + }
  76 + }
51 77  
52 78 g_dbus_method_invocation_return_error (
53 79 invocation,
... ...
src/linux/setproperties.c
... ... @@ -97,6 +97,12 @@ ipc3270_set_property (GDBusConnection *connection,
97 97 return TRUE;
98 98 }
99 99  
  100 + // Check for pre-defineds
  101 + if(!g_ascii_strcasecmp("url", property_name)) {
  102 + lib3270_set_url(IPC3270(user_data)->hSession,g_variant_get_string(value,NULL));
  103 + return TRUE;
  104 + }
  105 +
100 106 g_set_error (error,
101 107 G_IO_ERROR,
102 108 G_IO_ERROR_NOT_FOUND,
... ...