Commit 442a692891e70ecdf44026dd168d2fae1fe7e10f

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

Working on IPC service.

src/core/linux/gobject.c
... ... @@ -143,6 +143,101 @@ static gboolean
143 143  
144 144 }
145 145  
  146 +void ipc3270_add_terminal_introspection(GString *introspection) {
  147 +
  148 + size_t ix;
  149 +
  150 + g_string_append(introspection,
  151 + " <method name='connect'>"
  152 + " <arg type='s' name='url' direction='in'/>"
  153 + " <arg type='i' name='result' direction='out' />" \
  154 + " </method>"
  155 + " <method name='pfkey'>" \
  156 + " <arg type='i' name='keycode' direction='in'/>" \
  157 + " <arg type='i' name='result' direction='out' />" \
  158 + " </method>"
  159 + " <method name='pakey'>" \
  160 + " <arg type='i' name='keycode' direction='in'/>" \
  161 + " <arg type='i' name='result' direction='out' />" \
  162 + " </method>"
  163 + " <method name='getString'>" \
  164 + " <arg type='s' name='text' direction='out' />" \
  165 + " </method>" \
  166 + " <method name='setString'>" \
  167 + " <arg type='s' name='text' direction='in' />" \
  168 + " <arg type='i' name='result' direction='out' />" \
  169 + " </method>" \
  170 + " <method name='setStringAt'>" \
  171 + " <arg type='i' name='row' direction='in' />" \
  172 + " <arg type='i' name='col' direction='in' />" \
  173 + " <arg type='s' name='text' direction='in' />" \
  174 + " <arg type='i' name='result' direction='out' />" \
  175 + " </method>" \
  176 + " <method name= 'getStringAt'>" \
  177 + " <arg type='i' name='row' direction='in' />" \
  178 + " <arg type='i' name='col' direction='in' />" \
  179 + " <arg type='i' name='len' direction='in' />" \
  180 + " <arg type='y' name='lf' direction='in' />" \
  181 + " <arg type='s' name='text' direction='out' />" \
  182 + " </method>" \
  183 + " <method name='setStringAtAddress'>" \
  184 + " <arg type='i' name='addr' direction='in' />" \
  185 + " <arg type='s' name='text' direction='in' />" \
  186 + " <arg type='i' name='result' direction='out' />" \
  187 + " </method>" \
  188 + " <method name= 'getStringAtAddress'>" \
  189 + " <arg type='i' name='addr' direction='in' />" \
  190 + " <arg type='i' name='len' direction='in' />" \
  191 + " <arg type='y' name='lf' direction='in' />" \
  192 + " <arg type='s' name='text' direction='out' />" \
  193 + " </method>"
  194 + );
  195 +
  196 + // Constrói métodos usando a tabela de controle
  197 + const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();
  198 + for(ix = 0; actions[ix].name; ix++)
  199 + {
  200 + g_string_append_printf(
  201 + introspection, \
  202 + " <method name='%s'>" \
  203 + " </method>", actions[ix].name
  204 + );
  205 + }
  206 +
  207 + // Toggle properties
  208 + for(ix = 0; ix < (int) LIB3270_TOGGLE_COUNT; ix++) {
  209 + g_string_append_printf(introspection, " <property type='i' name='%s' access='readwrite'/>", lib3270_get_toggle_name((LIB3270_TOGGLE) ix));
  210 + }
  211 +
  212 + // Boolean properties
  213 + const LIB3270_INT_PROPERTY * bol_props = lib3270_get_boolean_properties_list();
  214 + for(ix = 0; bol_props[ix].name; ix++) {
  215 + debug("Boolean(%s)",bol_props[ix].name);
  216 + g_string_append_printf(introspection, " <property type='b' name='%s' access='%s'/>",
  217 + bol_props[ix].name,
  218 + ((bol_props[ix].set == NULL) ? "read" : "readwrite")
  219 + );
  220 + }
  221 +
  222 + // Integer properties
  223 + const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list();
  224 + for(ix = 0; int_props[ix].name; ix++) {
  225 + g_string_append_printf(introspection, " <property type='i' name='%s' access='%s'/>",
  226 + int_props[ix].name,
  227 + ((int_props[ix].set == NULL) ? "read" : "readwrite")
  228 + );
  229 + }
  230 +
  231 + // String properties
  232 + const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list();
  233 + for(ix = 0; str_props[ix].name; ix++) {
  234 + g_string_append_printf(introspection, " <property type='s' name='%s' access='%s'/>",
  235 + str_props[ix].name,
  236 + ((str_props[ix].set == NULL) ? "read" : "readwrite")
  237 + );
  238 + }
  239 +
  240 +}
146 241  
147 242 void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) {
148 243  
... ... @@ -209,103 +304,9 @@ void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GEr
209 304 lib3270_set_session_id(ipc->hSession, id);
210 305  
211 306 // Introspection data for the service we are exporting
212   - GString * introspection = g_string_new(
213   - "<node>\n"
214   - " <interface name='br.com.bb.tn3270'>"
215   - " <method name='connect'>"
216   - " <arg type='s' name='url' direction='in'/>"
217   - " <arg type='i' name='result' direction='out' />" \
218   - " </method>"
219   - " <method name='pfkey'>" \
220   - " <arg type='i' name='keycode' direction='in'/>" \
221   - " <arg type='i' name='result' direction='out' />" \
222   - " </method>"
223   - " <method name='pakey'>" \
224   - " <arg type='i' name='keycode' direction='in'/>" \
225   - " <arg type='i' name='result' direction='out' />" \
226   - " </method>"
227   - " <method name='getString'>" \
228   - " <arg type='s' name='text' direction='out' />" \
229   - " </method>" \
230   - " <method name='setString'>" \
231   - " <arg type='s' name='text' direction='in' />" \
232   - " <arg type='i' name='result' direction='out' />" \
233   - " </method>" \
234   - " <method name='setStringAt'>" \
235   - " <arg type='i' name='row' direction='in' />" \
236   - " <arg type='i' name='col' direction='in' />" \
237   - " <arg type='s' name='text' direction='in' />" \
238   - " <arg type='i' name='result' direction='out' />" \
239   - " </method>" \
240   - " <method name= 'getStringAt'>" \
241   - " <arg type='i' name='row' direction='in' />" \
242   - " <arg type='i' name='col' direction='in' />" \
243   - " <arg type='i' name='len' direction='in' />" \
244   - " <arg type='y' name='lf' direction='in' />" \
245   - " <arg type='s' name='text' direction='out' />" \
246   - " </method>" \
247   - " <method name='setStringAtAddress'>" \
248   - " <arg type='i' name='addr' direction='in' />" \
249   - " <arg type='s' name='text' direction='in' />" \
250   - " <arg type='i' name='result' direction='out' />" \
251   - " </method>" \
252   - " <method name= 'getStringAtAddress'>" \
253   - " <arg type='i' name='addr' direction='in' />" \
254   - " <arg type='i' name='len' direction='in' />" \
255   - " <arg type='y' name='lf' direction='in' />" \
256   - " <arg type='s' name='text' direction='out' />" \
257   - " </method>"
258   -
259   - );
260   -
261   - // Constrói métodos usando a tabela de controle
262   - const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();
263   - for(ix = 0; actions[ix].name; ix++)
264   - {
265   - g_string_append_printf(
266   - introspection, \
267   - " <method name='%s'>" \
268   - " </method>", actions[ix].name
269   - );
270   - }
271   -
272   - // Toggle properties
273   - for(ix = 0; ix < (int) LIB3270_TOGGLE_COUNT; ix++) {
274   - g_string_append_printf(introspection, " <property type='i' name='%s' access='readwrite'/>", lib3270_get_toggle_name((LIB3270_TOGGLE) ix));
275   - }
276   -
277   - // Boolean properties
278   - const LIB3270_INT_PROPERTY * bol_props = lib3270_get_boolean_properties_list();
279   - for(ix = 0; bol_props[ix].name; ix++) {
280   - debug("Boolean(%s)",bol_props[ix].name);
281   - g_string_append_printf(introspection, " <property type='b' name='%s' access='%s'/>",
282   - bol_props[ix].name,
283   - ((bol_props[ix].set == NULL) ? "read" : "readwrite")
284   - );
285   - }
286   -
287   - // Integer properties
288   - const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list();
289   - for(ix = 0; int_props[ix].name; ix++) {
290   - g_string_append_printf(introspection, " <property type='i' name='%s' access='%s'/>",
291   - int_props[ix].name,
292   - ((int_props[ix].set == NULL) ? "read" : "readwrite")
293   - );
294   - }
295   -
296   - // String properties
297   - const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list();
298   - for(ix = 0; str_props[ix].name; ix++) {
299   - g_string_append_printf(introspection, " <property type='s' name='%s' access='%s'/>",
300   - str_props[ix].name,
301   - ((str_props[ix].set == NULL) ? "read" : "readwrite")
302   - );
303   - }
304   -
305   - g_string_append(introspection,
306   - " </interface>"
307   - "</node>"
308   - );
  307 + GString * introspection = g_string_new("<node><interface name='br.com.bb.tn3270.session'>");
  308 + ipc3270_add_terminal_introspection(introspection);
  309 + g_string_append(introspection,"</interface></node>");
309 310  
310 311 gchar * introspection_xml = g_string_free(introspection,FALSE);
311 312  
... ...
src/include/lib3270/ipc.h
... ... @@ -60,6 +60,8 @@
60 60 gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error);
61 61 GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error);
62 62  
  63 + void ipc3270_add_terminal_introspection(GString *string);
  64 +
63 65 const gchar * ipc3270_get_display_charset(GObject *object);
64 66 H3270 * ipc3270_get_session(GObject *object);
65 67  
... ...
src/service/getproperties.c
... ... @@ -33,13 +33,21 @@
33 33 */
34 34  
35 35 #include <config.h>
  36 +#include "private.h"
36 37 #include <lib3270/ipc.h>
37 38 #include <lib3270.h>
38 39 #include <lib3270/properties.h>
39 40  
40   -GVariant * service_get_property(GObject *object, const gchar *property_name, GError **error) {
  41 +GVariant * service_get_property(const gchar *property_name, GError **error) {
  42 +
  43 + debug("%s(%s)",__FUNCTION__,property_name);
  44 +
  45 + if(!g_ascii_strcasecmp(property_name,"version")) {
  46 + return g_variant_new_string(PACKAGE_VERSION);
  47 + } else if(!g_ascii_strcasecmp(property_name,"release")) {
  48 + return g_variant_new_string(G_STRINGIFY(PACKAGE_RELEASE));
  49 + }
41 50  
42   - debug("%s",__FUNCTION__);
43 51  
44 52 g_set_error (error,
45 53 G_IO_ERROR,
... ...
src/service/linux/start.c
... ... @@ -31,32 +31,101 @@
31 31 *
32 32 */
33 33  
  34 +#include <config.h>
  35 +#include <lib3270/ipc.h>
34 36 #include "../private.h"
35 37  
36 38 #define PW3270_SERVICE_DBUS_SERVICE_PATH "/br/com/bb/tn3270/service"
37 39 #define PW3270_SERVICE_DBUS_SERVICE "br.com.bb.tn3270.service"
38 40 #define PW3270_SERVICE_DBUS_SERVICE_INTERFACE "br.com.bb.tn3270.service"
39 41  
40   -static const gchar introspection_xml[] =
41   - "<node>"
42   - " <interface name='" PW3270_SERVICE_DBUS_SERVICE_INTERFACE "'>"
43   - " <property type='s' name='version' access='read'/>"
44   - " </interface>"
45   - "</node>";
46   -
47 42 static GDBusNodeInfo *introspection_data = NULL;
48 43 static guint owner_id = 0;
  44 +static gchar * introspection_xml = NULL;
  45 +
  46 +static void
  47 + method_call (
  48 + G_GNUC_UNUSED GDBusConnection *connection,
  49 + G_GNUC_UNUSED const gchar *sender,
  50 + G_GNUC_UNUSED const gchar *object_path,
  51 + G_GNUC_UNUSED const gchar *interface_name,
  52 + const gchar *method_name,
  53 + GVariant *parameters,
  54 + GDBusMethodInvocation *invocation,
  55 + gpointer user_data) {
  56 +
  57 + g_autoptr (GError) error = NULL;
  58 +
  59 + debug("%s(%s)",__FUNCTION__,object_path);
  60 +
  61 + GVariant * rc = service_method_call(method_name, parameters, &error);
  62 +
  63 + if(error) {
  64 +
  65 + if(rc) {
  66 + g_variant_unref(rc);
  67 + }
  68 +
  69 + g_dbus_method_invocation_return_gerror(invocation, error);
  70 +
  71 + } else if(rc) {
  72 +
  73 + g_dbus_method_invocation_return_value(invocation, rc);
  74 +
  75 + } else {
  76 +
  77 + g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Invalid or unexpected method call");
  78 +
  79 + }
  80 +
  81 +
  82 +}
  83 +
  84 +static GVariant *
  85 + get_property (
  86 + G_GNUC_UNUSED GDBusConnection *connection,
  87 + G_GNUC_UNUSED const gchar *sender,
  88 + G_GNUC_UNUSED const gchar *object_path,
  89 + G_GNUC_UNUSED const gchar *interface_name,
  90 + const gchar *property_name,
  91 + GError **error,
  92 + gpointer user_data)
  93 +{
  94 +
  95 + debug("%s(%s)",__FUNCTION__,object_path);
  96 + return service_get_property(property_name, error);
  97 +
  98 +}
  99 +
  100 +static gboolean
  101 + set_property (
  102 + G_GNUC_UNUSED GDBusConnection *connection,
  103 + G_GNUC_UNUSED const gchar *sender,
  104 + G_GNUC_UNUSED const gchar *object_path,
  105 + G_GNUC_UNUSED const gchar *interface_name,
  106 + const gchar *property_name,
  107 + GVariant *value,
  108 + GError **error,
  109 + gpointer user_data)
  110 +{
  111 +
  112 + debug("%s(%s)",__FUNCTION__,object_path);
  113 + return service_set_property(property_name, value, error);
  114 +
  115 +}
  116 +
49 117  
50 118 static void on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data) {
51 119  
52 120 static const GDBusInterfaceVTable interface_vtable = {
53   - service_method_call,
54   - service_get_property,
55   - service_set_property
  121 + method_call,
  122 + get_property,
  123 + set_property
56 124 };
57 125  
58 126 guint registration_id;
59 127  
  128 + g_message("Registering object %s",PW3270_SERVICE_DBUS_SERVICE_PATH);
60 129  
61 130 registration_id = g_dbus_connection_register_object (connection,
62 131 PW3270_SERVICE_DBUS_SERVICE_PATH,
... ... @@ -82,6 +151,29 @@ static void on_name_lost (GDBusConnection *connection, const gchar *name, gpoint
82 151  
83 152 void service_start(void) {
84 153  
  154 + GString * introspection = g_string_new("<node>\n");
  155 +
  156 + g_string_append(introspection,
  157 + " <interface name='" PW3270_SERVICE_DBUS_SERVICE_INTERFACE "'>"
  158 + " <method name='createSession'>"
  159 + " <arg type='s' name='id' direction='out' />"
  160 + " </method>"
  161 + " <method name='destroySession'>"
  162 + " <arg type='s' name='id' direction='in' />"
  163 + " <arg type='i' name='rc' direction='out' />"
  164 + " </method>"
  165 + " <property type='s' name='version' access='read'/>"
  166 + " <property type='s' name='release' access='read'/>"
  167 + );
  168 +
  169 + ipc3270_add_terminal_introspection(introspection);
  170 +
  171 + g_string_append(introspection,"</interface></node>\n");
  172 +
  173 + introspection_xml = g_string_free(introspection,FALSE);
  174 +
  175 + debug("\n\n%s\n\n",introspection_xml);
  176 +
85 177 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
86 178  
87 179 owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
... ...
src/service/methods.c
... ... @@ -33,12 +33,15 @@
33 33 */
34 34  
35 35 #include <config.h>
  36 +#include "private.h"
36 37 #include <string.h>
37 38 #include <lib3270/ipc.h>
38 39 #include <lib3270.h>
39 40 #include <lib3270/actions.h>
40 41  
41   -GVariant * service_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error) {
  42 +GVariant * service_method_call(const gchar *method_name, GVariant *parameters, GError **error) {
  43 +
  44 + debug("%s(%s)",__FUNCTION__,method_name);
42 45  
43 46 g_set_error (error,
44 47 G_IO_ERROR,
... ...
src/service/private.h
... ... @@ -50,34 +50,10 @@
50 50 typedef struct _sessionClass sessionClass;
51 51  
52 52 G_GNUC_INTERNAL void service_start(void);
53   - G_GNUC_INTERNAL GVariant * service_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error);
54   - G_GNUC_INTERNAL GVariant * service_get_property(GObject *object, const gchar *property_name, GError **error);
55   - G_GNUC_INTERNAL gboolean service_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error);
  53 + G_GNUC_INTERNAL GVariant * service_method_call(const gchar *method_name, GVariant *parameters, GError **error);
  54 + G_GNUC_INTERNAL GVariant * service_get_property(const gchar *property_name, GError **error);
  55 + G_GNUC_INTERNAL gboolean service_set_property(const gchar *property_name, GVariant *value, GError **error);
56 56  
57 57 G_END_DECLS
58 58  
59   -
60   - /*
61   - struct session {
62   - unsigned int id; ///< @brief Identificador da sessão.
63   - time_t activity; ///< @brief Timestamp da última atividade dessa sessão.
64   - time_t timeout; ///< @brief Após quantos segundos eu encerro a sessao?
65   - time_t maxidle; ///< @brief Tempo máximo que a sessão pode ficar IDLE
66   - time_t autoclose; ///< @brief Destroi a sessão quantos segundos após a desconexão?
67   - H3270 * host; ///< @brief Sessão TN3270.
68   - };
69   - */
70   -
71   - G_GNUC_INTERNAL GMainLoop * main_loop;
72   -
73   - /*
74   - G_GNUC_INTERNAL void init_3270(void);
75   - G_GNUC_INTERNAL void register_3270_io_handlers(void);
76   -
77   - G_GNUC_INTERNAL struct session * session_new();
78   - G_GNUC_INTERNAL struct session * session_find(const gchar *key);
79   - G_GNUC_INTERNAL void session_destroy(struct session *ses);
80   - G_GNUC_INTERNAL void session_check_for_timeout(void);
81   - */
82   -
83 59 #endif // PRIVATE_H_INCLUDED
... ...
src/service/setproperties.c
... ... @@ -33,21 +33,20 @@
33 33 */
34 34  
35 35 #include <config.h>
  36 +#include "private.h"
36 37 #include <lib3270/ipc.h>
37 38 #include <lib3270.h>
38 39 #include <lib3270/properties.h>
39 40  
40   -gboolean service_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error) {
  41 +gboolean service_set_property(const gchar *property_name, GVariant *value, GError **error) {
41 42  
42   - debug("%s",__FUNCTION__);
  43 + debug("%s(%s)",__FUNCTION__,property_name);
43 44  
44   - /*
45 45 g_set_error (error,
46 46 G_IO_ERROR,
47 47 G_IO_ERROR_NOT_FOUND,
48 48 "Can't find any property named %s", property_name
49 49 );
50   - */
51 50  
52 51 return FALSE;
53 52 }
... ...