Commit 61e7ae84f543db90d8876576759e50cdb55344c3

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

Working on IPC component based on GIO for Linux.

.gitignore
... ... @@ -12,3 +12,4 @@ scripts
12 12 config.h
13 13 stamp-h1
14 14 Makefile
  15 +*.[0-9]
... ...
pw3270-plugin-ipc.cbp
... ... @@ -44,6 +44,10 @@
44 44 <Option compilerVar="CC" />
45 45 </Unit>
46 46 <Unit filename="src/linux/gobject.h" />
  47 + <Unit filename="src/plugin/private.h" />
  48 + <Unit filename="src/plugin/start.c">
  49 + <Option compilerVar="CC" />
  50 + </Unit>
47 51 <Unit filename="src/testprogram/testprogram.c">
48 52 <Option compilerVar="CC" />
49 53 </Unit>
... ...
src/linux/gobject.c
... ... @@ -23,6 +23,7 @@
23 23 * Referências:
24 24 *
25 25 * https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c
  26 + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c
26 27 *
27 28 * Contatos:
28 29 *
... ... @@ -32,24 +33,44 @@
32 33 */
33 34  
34 35 #include "gobject.h"
  36 +#include <v3270.h>
35 37  
36 38 #include <dbus/dbus-glib.h>
37 39 #include <dbus/dbus-glib-bindings.h>
38 40  
  41 +/* Introspection data for the service we are exporting */
  42 +static const gchar introspection_xml[] =
  43 + "<node>"
  44 + " <interface name='br.com.bb.tn3270'>"
  45 + " <method name='about'>"
  46 + " <arg type='s' name='revision' direction='out'/>"
  47 + " </method>"
  48 + " </interface>"
  49 + "</node>";
  50 +
39 51 G_DEFINE_TYPE(ipc3270, ipc3270, G_TYPE_OBJECT)
40 52  
41 53 static void ipc3270_finalize(GObject *object) {
42 54  
  55 + ipc3270 * ipc = IPC3270(object);
43 56  
  57 + debug("%s",__FUNCTION__);
  58 + if(ipc->id) {
  59 + g_dbus_connection_unregister_object(ipc->connection,ipc->id);
  60 + }
44 61  
45 62 G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object);
46 63 }
47 64  
48 65  
49 66 static void ipc3270_class_init(ipc3270Class *klass) {
  67 +
  68 + debug("%s",__FUNCTION__);
  69 +
50 70 GObjectClass *object_class;
51 71 object_class = G_OBJECT_CLASS (klass);
52 72 object_class->finalize = ipc3270_finalize;
  73 +
53 74 }
54 75  
55 76 static void ipc3270_init(ipc3270 *object) {
... ... @@ -58,9 +79,75 @@ static void ipc3270_init(ipc3270 *object) {
58 79  
59 80 }
60 81  
61   - GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) {
  82 +void
  83 +ipc3270_method_call (GDBusConnection *connection,
  84 + const gchar *sender,
  85 + const gchar *object_path,
  86 + const gchar *interface_name,
  87 + const gchar *method_name,
  88 + GVariant *parameters,
  89 + GDBusMethodInvocation *invocation,
  90 + gpointer user_data)
  91 +{
  92 +
  93 +
  94 + g_dbus_method_invocation_return_error (
  95 + invocation,
  96 + G_DBUS_ERROR,
  97 + G_DBUS_ERROR_UNKNOWN_METHOD,
  98 + "Invalid or unexpected method call");
  99 +
  100 +}
  101 +
  102 +GVariant *
  103 +ipc3270_get_property (GDBusConnection *connection,
  104 + const gchar *sender,
  105 + const gchar *object_path,
  106 + const gchar *interface_name,
  107 + const gchar *property_name,
  108 + GError **error,
  109 + gpointer user_data)
  110 +{
  111 + GVariant *ret = NULL;
  112 +
  113 + g_set_error (error,
  114 + G_IO_ERROR,
  115 + G_IO_ERROR_NOT_FOUND,
  116 + "There's no %s propriety", property_name
  117 + );
  118 +
  119 + return ret;
  120 +}
  121 +
  122 +gboolean
  123 +ipc3270_set_property (GDBusConnection *connection,
  124 + const gchar *sender,
  125 + const gchar *object_path,
  126 + const gchar *interface_name,
  127 + const gchar *property_name,
  128 + GVariant *value,
  129 + GError **error,
  130 + gpointer user_data)
  131 +{
  132 +
  133 +
  134 + g_set_error (error,
  135 + G_IO_ERROR,
  136 + G_IO_ERROR_NOT_FOUND,
  137 + "There's no %s propriety", property_name
  138 + );
  139 +
  140 + return *error == NULL;
  141 +}
  142 +
  143 +GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) {
  144 +
  145 + static const GDBusInterfaceVTable interface_vtable = {
  146 + ipc3270_method_call,
  147 + ipc3270_get_property,
  148 + ipc3270_set_property
  149 + };
62 150  
63   - debug("%s",__FUNCTION__);
64 151 ipc3270 * object = IPC3270(g_object_new(GLIB_TYPE_IPC3270, NULL));
65 152  
66 153 GError * error = NULL;
... ... @@ -88,7 +175,7 @@ static void ipc3270_init(ipc3270 *object) {
88 175  
89 176 g_dbus_connection_set_exit_on_close(object->connection,FALSE);
90 177  
91   - for(id='a'; id < 'z' && !error && !object->proxy; id++) {
  178 + for(id='a'; id < 'z' && !object->id && !error; id++) {
92 179  
93 180 gchar *name = g_strdup_printf("br.com.bb.%s.%c",gtk_widget_get_name(window),id);
94 181  
... ... @@ -124,22 +211,28 @@ static void ipc3270_init(ipc3270 *object) {
124 211  
125 212 if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
126 213  
127   - object->proxy = g_dbus_proxy_new_sync(
128   - object->connection,
129   - G_DBUS_PROXY_FLAGS_NONE,
130   - NULL, // GDBusInterfaceInfo
131   - name, // name
132   - "/br/com/bb/" PACKAGE_NAME "/terminal", // object path
133   - "br.com.bb." PACKAGE_NAME ".terminal", // interface
134   - NULL, // GCancellable
135   - &error );
136   -
137 214 gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id);
138 215 v3270_set_session_name(terminal, widget_name);
139 216 g_free(widget_name);
140 217  
141 218 g_message("Got %s - %s", name, v3270_get_session_name(terminal));
142 219  
  220 + GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
  221 +
  222 + // Register object-id
  223 + object->id = g_dbus_connection_register_object (
  224 + object->connection,
  225 + "/br/com/bb/tn3270",
  226 + introspection_data->interfaces[0],
  227 + &interface_vtable,
  228 + object,
  229 + NULL,
  230 + &error
  231 + );
  232 +
  233 + g_dbus_node_info_unref(introspection_data);
  234 +
  235 + break;
143 236 }
144 237  
145 238 }
... ... @@ -148,34 +241,25 @@ static void ipc3270_init(ipc3270 *object) {
148 241  
149 242 }
150 243  
151   - if(!object->proxy) {
  244 + if(error) {
152 245  
153 246 GtkWidget *dialog = gtk_message_dialog_new(
154 247 GTK_WINDOW(window),
155 248 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
156 249 GTK_MESSAGE_ERROR,
157 250 GTK_BUTTONS_OK,
158   - _( "Can't get DBUS object name" ));
  251 + _( "Can't register D-Bus Object" ));
  252 +
  253 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
  254 + g_error_free(error);
159 255  
160 256 gtk_dialog_run(GTK_DIALOG(dialog));
161 257 gtk_widget_destroy(dialog);
162 258  
163 259 return G_OBJECT(object);
164   - }
165   -
166   - // Got D-Bus name, register object.
167   -
168   -/*
169   -gpointer pw3270_dbus_register_object(DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path)
170   -{
171   - GObject *object = g_object_new (object_type, NULL);
172   - dbus_g_object_type_install_info (object_type, info);
173   - dbus_g_connection_register_g_object (connection, path, object);
174   - return object;
175   -}
176   -*/
177 260  
  261 + }
178 262  
179 263 return G_OBJECT(object);
180 264  
181   - }
  265 +}
... ...
src/linux/gobject.h
... ... @@ -56,13 +56,17 @@
56 56 struct _ipc3270 {
57 57 GObject parent;
58 58 GDBusConnection * connection;
59   - GDBusProxy * proxy;
  59 + guint id;
60 60 };
61 61  
62 62 struct _ipc3270Class {
63 63 GObjectClass parent;
64 64 };
65 65  
  66 + G_GNUC_INTERNAL void ipc3270_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data);
  67 + G_GNUC_INTERNAL gboolean ipc3270_set_property(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GVariant *value, GError **error, gpointer user_data);
  68 + G_GNUC_INTERNAL GVariant * ipc3270_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data);
  69 +
66 70 G_END_DECLS
67 71  
68 72 #endif // LINUX_PRIVATE_H_INCLUDED
... ...
src/plugin/start.c
... ... @@ -37,10 +37,8 @@
37 37 #include "private.h"
38 38  
39 39 int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) {
40   -
41 40 g_object_set_data_full(G_OBJECT(terminal), "ipc-object-info", ipc3270_new(window,terminal), g_object_unref);
42 41 return 0;
43   -
44 42 }
45 43  
46 44  
... ...