Commit 79e84de93bd456ae0874364b6ea7b87b822b5bdc
1 parent
35d8292f
Exists in
master
and in
5 other branches
Implementando mudança do objeto dbus para cada sessão do aplicativo
Showing
2 changed files
with
124 additions
and
43 deletions
Show diff stats
src/plugins/dbus3270/main.c
@@ -46,6 +46,7 @@ | @@ -46,6 +46,7 @@ | ||
46 | 46 | ||
47 | static DBusGConnection * connection = NULL; | 47 | static DBusGConnection * connection = NULL; |
48 | static DBusGProxy * proxy = NULL; | 48 | static DBusGProxy * proxy = NULL; |
49 | + static gchar * service_name = NULL; | ||
49 | 50 | ||
50 | 51 | ||
51 | /*---[ Implement ]-------------------------------------------------------------------------------*/ | 52 | /*---[ Implement ]-------------------------------------------------------------------------------*/ |
@@ -54,8 +55,9 @@ | @@ -54,8 +55,9 @@ | ||
54 | { | 55 | { |
55 | 56 | ||
56 | GError * error = NULL; | 57 | GError * error = NULL; |
57 | - gchar * service_path = NULL; | ||
58 | guint result; | 58 | guint result; |
59 | + char session_id = 0; | ||
60 | + char id = 'a'; | ||
59 | 61 | ||
60 | connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); | 62 | connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); |
61 | if(error) | 63 | if(error) |
@@ -81,18 +83,26 @@ | @@ -81,18 +83,26 @@ | ||
81 | 83 | ||
82 | proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); | 84 | proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); |
83 | 85 | ||
86 | + for(id='a'; id < 'z' && !error && !service_name; id++) | ||
84 | { | 87 | { |
85 | - gchar * service_name = g_strdup_printf("br.com.bb.%s",pw3270_get_session_name(window)); | ||
86 | - | ||
87 | - service_path = g_strdup_printf("/br/com/bb/%s",pw3270_get_session_name(window)); | ||
88 | - | ||
89 | - trace("DBUS service path is %s",service_path); | ||
90 | - trace("DBUS service name is %s",service_name); | ||
91 | - | ||
92 | - org_freedesktop_DBus_request_name(proxy, service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); | ||
93 | - | ||
94 | - g_free(service_name); | ||
95 | - | 88 | + gboolean has_owner = FALSE; |
89 | + | ||
90 | + service_name = g_strdup_printf("br.com.bb.%s.%c",pw3270_get_session_name(window),(int) id); | ||
91 | + | ||
92 | + org_freedesktop_DBus_name_has_owner(proxy, service_name, &has_owner, NULL); | ||
93 | + | ||
94 | + if(has_owner) | ||
95 | + { | ||
96 | + trace("Service \"%s\" has owner",service_name) | ||
97 | + g_free(service_name); | ||
98 | + service_name = NULL; | ||
99 | + } | ||
100 | + else | ||
101 | + { | ||
102 | + session_id = id; | ||
103 | + trace("DBUS service name is %s",service_name); | ||
104 | + org_freedesktop_DBus_request_name(proxy, service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); | ||
105 | + } | ||
96 | } | 106 | } |
97 | 107 | ||
98 | if(error) | 108 | if(error) |
@@ -116,15 +126,32 @@ | @@ -116,15 +126,32 @@ | ||
116 | return -1; | 126 | return -1; |
117 | } | 127 | } |
118 | 128 | ||
119 | - pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,service_path); | 129 | + if(session_id) |
130 | + { | ||
131 | + gchar * path = g_strdup_printf("/br/com/bb/%s",pw3270_get_session_name(window)); | ||
132 | + gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),g_ascii_toupper(session_id)); | ||
133 | + pw3270_set_session_name(window,session); | ||
134 | + g_free(session); | ||
135 | + | ||
136 | + trace("DBUS service path is %s",path); | ||
137 | + | ||
138 | + pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,path); | ||
120 | 139 | ||
121 | - g_free(service_path); | 140 | + g_free(path); |
141 | + } | ||
122 | 142 | ||
123 | return 0; | 143 | return 0; |
124 | } | 144 | } |
125 | 145 | ||
126 | LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window) | 146 | LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window) |
127 | { | 147 | { |
148 | + if(service_name) | ||
149 | + { | ||
150 | + // org_freedesktop_DBus_release_name | ||
151 | + | ||
152 | + g_free(service_name); | ||
153 | + service_name = NULL; | ||
154 | + } | ||
128 | return 0; | 155 | return 0; |
129 | } | 156 | } |
130 | 157 |
src/plugins/dbus3270/test.sh
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | -case $1 in | 3 | +SESSION=a |
4 | +DEST=br.com.bb.pw3270 | ||
5 | +BPATH=/br/com/bb/pw3270 | ||
4 | 6 | ||
5 | - revision) | ||
6 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.getRevision | ||
7 | - ;; | 7 | +run_command() |
8 | +{ | ||
8 | 9 | ||
9 | - message) | ||
10 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.getMessageID | ||
11 | - ;; | 10 | + case $1 in |
12 | 11 | ||
13 | - connect) | ||
14 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.connect string:$2 | ||
15 | - ;; | 12 | + revision) |
13 | + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getRevision | ||
14 | + ;; | ||
16 | 15 | ||
17 | - disconnect) | ||
18 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.disconnect | ||
19 | - ;; | 16 | + message) |
17 | + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getMessageID | ||
18 | + ;; | ||
20 | 19 | ||
21 | - quit) | ||
22 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.quit | ||
23 | - ;; | 20 | + connect) |
21 | + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.connect string:$2 | ||
22 | + ;; | ||
24 | 23 | ||
25 | - get) | ||
26 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.getScreenContents | ||
27 | - ;; | 24 | + disconnect) |
25 | + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.disconnect | ||
26 | + ;; | ||
28 | 27 | ||
29 | - set) | ||
30 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.setTextAt int32:$2 int32:$3 string:$4 | ||
31 | - ;; | 28 | + quit) |
29 | + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.quit | ||
30 | + ;; | ||
32 | 31 | ||
33 | - enter) | ||
34 | - dbus-send --session --print-reply --dest=br.com.bb.pw3270 /br/com/bb/pw3270 br.com.bb.pw3270.enter | ||
35 | - ;; | 32 | + get) |
33 | + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getScreenContents | ||
34 | + ;; | ||
36 | 35 | ||
37 | - *) | ||
38 | - echo "Comando $1 desconhecido" | ||
39 | - ;; | 36 | + set) |
37 | + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.setTextAt int32:$2 int32:$3 string:$4 | ||
38 | + ;; | ||
40 | 39 | ||
41 | -esac | 40 | + enter) |
41 | + dbus-send --session --print-reply --dest=$DEST $BPATH $DEST.enter | ||
42 | + ;; | ||
43 | + | ||
44 | + *) | ||
45 | + echo "Comando $1 desconhecido" | ||
46 | + ;; | ||
47 | + | ||
48 | + esac | ||
49 | +} | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | +until [ -z "$1" ] | ||
54 | +do | ||
55 | + if [ ${1:0:2} = '--' ]; then | ||
56 | + tmp=${1:2} | ||
57 | + parameter=${tmp%%=*} | ||
58 | + parameter=$(echo $parameter | tr "[:lower:]" "[:upper:]") | ||
59 | + value=${tmp##*=} | ||
60 | + | ||
61 | + case "$parameter" in | ||
62 | + SESSION) | ||
63 | + SESSION=$value | ||
64 | + ;; | ||
65 | + HELP) | ||
66 | + echo "$0 options" | ||
67 | + echo "" | ||
68 | + echo "Options:" | ||
69 | + echo "" | ||
70 | + echo " --session pw3270's session manager" | ||
71 | + echo "" | ||
72 | + exit 0 | ||
73 | + ;; | ||
74 | + | ||
75 | + *) | ||
76 | + eval $parameter=$value | ||
77 | + ;; | ||
78 | + | ||
79 | + esac | ||
80 | + | ||
81 | + elif [ -d $1 ]; then | ||
82 | + | ||
83 | + IMGNAME=$1 | ||
84 | + | ||
85 | + if [ -e $IMGNAME/matriz.conf ]; then | ||
86 | + . $IMGNAME/matriz.conf | ||
87 | + fi | ||
88 | + | ||
89 | + else | ||
90 | + run_command $@ | ||
91 | + exit 0 | ||
92 | + fi | ||
93 | + | ||
94 | + shift | ||
95 | +done | ||
42 | 96 |