Commit 3787e42df1ef00b1c07a10e1344578c374aab121
1 parent
25699294
Exists in
master
and in
5 other branches
Implementando interface DBUS na extensao LibreOffice
Showing
3 changed files
with
242 additions
and
3 deletions
Show diff stats
src/oxt/Makefile.in
@@ -63,9 +63,13 @@ LIB3270_CFLAGS ?= `pkg-config --cflags lib3270` | @@ -63,9 +63,13 @@ LIB3270_CFLAGS ?= `pkg-config --cflags lib3270` | ||
63 | DLL_CFLAGS=@DLL_CFLAGS@ | 63 | DLL_CFLAGS=@DLL_CFLAGS@ |
64 | DLL_FLAGS=-shared | 64 | DLL_FLAGS=-shared |
65 | 65 | ||
66 | -CXXFLAGS=-Wno-strict-aliasing -I$(OBJDIR)/uno/include -I$(OO_SDK_HOME)/include -I$(OBJDIR)/uno/include/br/com/bb $(LIB3270_CFLAGS) | ||
67 | -LDFLAGS=-L${OO_SDK_HOME}/lib -L${OO_SDK_URE_HOME}/lib -Wl,-rpath-link=${OO_SDK_URE_HOME}/lib,-rpath=${OO_SDK_URE_HOME}/lib \ | ||
68 | - $(CPPULIB) $(CPPUHELPERLIB) $(SALLIB) | 66 | +CXXFLAGS=-Wno-strict-aliasing -I$(OBJDIR)/uno/include -I$(OO_SDK_HOME)/include \ |
67 | + -I$(OBJDIR)/uno/include/br/com/bb $(LIB3270_CFLAGS) \ | ||
68 | + @DBUS_CFLAGS@ | ||
69 | + | ||
70 | +LDFLAGS=-L${OO_SDK_HOME}/lib -L${OO_SDK_URE_HOME}/lib \ | ||
71 | + -Wl,-rpath-link=${OO_SDK_URE_HOME}/lib,-rpath=${OO_SDK_URE_HOME}/lib \ | ||
72 | + $(CPPULIB) $(CPPUHELPERLIB) $(SALLIB) @DBUS_LIBS@ | ||
69 | 73 | ||
70 | # CC_DEFINES=-DUNX -DGCC -DLINUX -DCPPU_ENV=$(CPPU_ENV) -DGXX_INCLUDE_PATH=$(SDK_GXX_INCLUDE_PATH) -DHAVE_GCC_VISIBILITY_FEATURE | 74 | # CC_DEFINES=-DUNX -DGCC -DLINUX -DCPPU_ENV=$(CPPU_ENV) -DGXX_INCLUDE_PATH=$(SDK_GXX_INCLUDE_PATH) -DHAVE_GCC_VISIBILITY_FEATURE |
71 | 75 |
src/oxt/globals.hpp
@@ -13,6 +13,11 @@ | @@ -13,6 +13,11 @@ | ||
13 | #include <stdio.h> | 13 | #include <stdio.h> |
14 | #include <lib3270.h> | 14 | #include <lib3270.h> |
15 | 15 | ||
16 | +#if defined(HAVE_DBUS) | ||
17 | + #include <stdio.h> | ||
18 | + #include <dbus/dbus.h> | ||
19 | +#endif // HAVE_DBUS | ||
20 | + | ||
16 | #include <rtl/uuid.h> | 21 | #include <rtl/uuid.h> |
17 | #include <osl/thread.hxx> | 22 | #include <osl/thread.hxx> |
18 | 23 | ||
@@ -150,6 +155,21 @@ | @@ -150,6 +155,21 @@ | ||
150 | virtual bool in_tn3270e(); | 155 | virtual bool in_tn3270e(); |
151 | virtual void mem_free(void *); | 156 | virtual void mem_free(void *); |
152 | 157 | ||
158 | + private: | ||
159 | + | ||
160 | +#if defined(HAVE_DBUS) | ||
161 | + | ||
162 | + DBusConnection * conn; | ||
163 | + char * dest; | ||
164 | + char * path; | ||
165 | + char * intf; | ||
166 | + DBusMessage * create_message(const char *method); | ||
167 | + DBusMessage * call(DBusMessage *msg); | ||
168 | + char * query_string(const char *method); | ||
169 | + int query_intval(const char *method); | ||
170 | + | ||
171 | +#endif // HAVE_DBUS | ||
172 | + | ||
153 | }; | 173 | }; |
154 | 174 | ||
155 | 175 |
src/oxt/remote.cxx
@@ -35,13 +35,224 @@ | @@ -35,13 +35,224 @@ | ||
35 | 35 | ||
36 | /*---[ Statics ]-------------------------------------------------------------------------------------------*/ | 36 | /*---[ Statics ]-------------------------------------------------------------------------------------------*/ |
37 | 37 | ||
38 | +#if defined(HAVE_DBUS) | ||
39 | + static const char * prefix_dest = "br.com.bb."; | ||
40 | + static const char * prefix_path = "/br/com/bb/"; | ||
41 | +#endif // HAVE_DBUS | ||
38 | 42 | ||
39 | /*---[ Implement ]-----------------------------------------------------------------------------------------*/ | 43 | /*---[ Implement ]-----------------------------------------------------------------------------------------*/ |
40 | 44 | ||
45 | +#if defined(HAVE_DBUS) | ||
46 | +DBusMessage * pw3270::ipc3270_session::create_message(const char *method) | ||
47 | +{ | ||
48 | + DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | ||
49 | + this->path, // Path | ||
50 | + this->intf, // Interface | ||
51 | + method); // method | ||
52 | + | ||
53 | + if (!msg) | ||
54 | + log("Error creating message for method %s",method); | ||
55 | + | ||
56 | + return msg; | ||
57 | +} | ||
58 | + | ||
59 | +DBusMessage * pw3270::ipc3270_session::call(DBusMessage *msg) | ||
60 | +{ | ||
61 | + DBusMessage * reply; | ||
62 | + DBusError error; | ||
63 | + | ||
64 | + dbus_error_init(&error); | ||
65 | + reply = dbus_connection_send_with_reply_and_block(conn,msg,10000,&error); | ||
66 | + dbus_message_unref(msg); | ||
67 | + | ||
68 | + if(!reply) | ||
69 | + { | ||
70 | + log("%s",error.message); | ||
71 | + dbus_error_free(&error); | ||
72 | + } | ||
73 | + | ||
74 | + return reply; | ||
75 | + | ||
76 | +} | ||
77 | + | ||
78 | +static char * get_string(DBusMessage * msg) | ||
79 | +{ | ||
80 | + char *rc = NULL; | ||
81 | + if(msg) | ||
82 | + { | ||
83 | + DBusMessageIter iter; | ||
84 | + | ||
85 | + if(dbus_message_iter_init(msg, &iter)) | ||
86 | + { | ||
87 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) | ||
88 | + { | ||
89 | + const char * str; | ||
90 | + dbus_message_iter_get_basic(&iter, &str); | ||
91 | + trace("Response: [%s]",str); | ||
92 | + rc = strdup(str); | ||
93 | + } | ||
94 | +#ifdef DEBUG | ||
95 | + else | ||
96 | + { | ||
97 | + trace("Return type is %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_STRING); | ||
98 | + } | ||
99 | +#endif | ||
100 | + } | ||
101 | + | ||
102 | + dbus_message_unref(msg); | ||
103 | + } | ||
104 | + return rc; | ||
105 | +} | ||
106 | + | ||
107 | +char * pw3270::ipc3270_session::query_string(const char *method) | ||
108 | +{ | ||
109 | + if(conn) | ||
110 | + return get_string(call(create_message(method))); | ||
111 | + return NULL; | ||
112 | +} | ||
113 | + | ||
114 | +static int get_intval(DBusMessage * msg) | ||
115 | +{ | ||
116 | + int rc = -1; | ||
117 | + | ||
118 | + if(msg) | ||
119 | + { | ||
120 | + DBusMessageIter iter; | ||
121 | + | ||
122 | + if(dbus_message_iter_init(msg, &iter)) | ||
123 | + { | ||
124 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) | ||
125 | + { | ||
126 | + dbus_int32_t iSigned; | ||
127 | + dbus_message_iter_get_basic(&iter, &iSigned); | ||
128 | + rc = (int) iSigned; | ||
129 | + } | ||
130 | +#ifdef DEBUG | ||
131 | + else | ||
132 | + { | ||
133 | + trace("Return type is %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | ||
134 | + } | ||
135 | +#endif | ||
136 | + } | ||
137 | + | ||
138 | + dbus_message_unref(msg); | ||
139 | + } | ||
140 | + | ||
141 | + return rc; | ||
142 | +} | ||
143 | + | ||
144 | +int pw3270::ipc3270_session::query_intval(const char *method) | ||
145 | +{ | ||
146 | + if(conn) | ||
147 | + return get_intval(call(create_message(method))); | ||
148 | + return -1; | ||
149 | +} | ||
150 | + | ||
151 | +#endif // HAVE_DBUS | ||
152 | + | ||
153 | + | ||
41 | pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() | 154 | pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() |
42 | { | 155 | { |
43 | #ifdef HAVE_DBUS | 156 | #ifdef HAVE_DBUS |
44 | 157 | ||
158 | + DBusError err; | ||
159 | + int rc; | ||
160 | + char * str = strdup(name); | ||
161 | + char * ptr; | ||
162 | + | ||
163 | + for(ptr=str;*ptr;ptr++) | ||
164 | + *ptr = tolower(*ptr); | ||
165 | + | ||
166 | + ptr = strchr(str,':'); | ||
167 | + | ||
168 | + if(ptr) | ||
169 | + { | ||
170 | + size_t sz; | ||
171 | + | ||
172 | + *(ptr++) = 0; | ||
173 | + | ||
174 | + // Build destination | ||
175 | + sz = strlen(ptr)+strlen(str)+strlen(prefix_dest)+2; | ||
176 | + dest = (char *) malloc(sz+1); | ||
177 | + strncpy(dest,prefix_dest,sz); | ||
178 | + strncat(dest,str,sz); | ||
179 | + strncat(dest,".",sz); | ||
180 | + strncat(dest,ptr,sz); | ||
181 | + | ||
182 | + // Build path | ||
183 | + sz = strlen(str)+strlen(prefix_path); | ||
184 | + path = (char *) malloc(sz+1); | ||
185 | + strncpy(path,prefix_path,sz); | ||
186 | + strncat(path,str,sz); | ||
187 | + | ||
188 | + // Build intf | ||
189 | + sz = strlen(str)+strlen(prefix_dest)+1; | ||
190 | + intf = (char *) malloc(sz+1); | ||
191 | + strncpy(intf,prefix_dest,sz); | ||
192 | + strncat(intf,str,sz); | ||
193 | + | ||
194 | + } | ||
195 | + else | ||
196 | + { | ||
197 | + size_t sz; | ||
198 | + | ||
199 | + // Build destination | ||
200 | + sz = strlen(str)+strlen(prefix_dest)+2; | ||
201 | + dest = (char *) malloc(sz+1); | ||
202 | + strncpy(dest,prefix_dest,sz); | ||
203 | + strncat(dest,str,sz); | ||
204 | + | ||
205 | + // Build path | ||
206 | + sz = strlen(str)+strlen(prefix_path); | ||
207 | + path = (char *) malloc(sz+1); | ||
208 | + strncpy(path,prefix_path,sz); | ||
209 | + strncat(path,str,sz); | ||
210 | + | ||
211 | + // Build intf | ||
212 | + sz = strlen(str)+strlen(prefix_dest)+1; | ||
213 | + intf = (char *) malloc(sz+1); | ||
214 | + strncpy(intf,prefix_dest,sz); | ||
215 | + strncat(intf,str,sz); | ||
216 | + | ||
217 | + } | ||
218 | + | ||
219 | + trace("DBUS:\nDestination:\t[%s]\nPath:\t\t[%s]\nInterface:\t[%s]",dest,path,intf); | ||
220 | + | ||
221 | + free(str); | ||
222 | + | ||
223 | + dbus_error_init(&err); | ||
224 | + | ||
225 | + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); | ||
226 | + | ||
227 | + if (dbus_error_is_set(&err)) | ||
228 | + { | ||
229 | + log("DBUS Connection Error (%s)", err.message); | ||
230 | + dbus_error_free(&err); | ||
231 | + } | ||
232 | + | ||
233 | + if(!conn) | ||
234 | + { | ||
235 | + log("%s", "DBUS Connection failed"); | ||
236 | + return; | ||
237 | + } | ||
238 | + | ||
239 | + rc = dbus_bus_request_name(conn, "br.com.bb." PACKAGE_NAME ".oo", DBUS_NAME_FLAG_REPLACE_EXISTING , &err); | ||
240 | + | ||
241 | + if (dbus_error_is_set(&err)) | ||
242 | + { | ||
243 | + log("Name Error (%s)", err.message); | ||
244 | + dbus_error_free(&err); | ||
245 | + conn = NULL; | ||
246 | + return; | ||
247 | + } | ||
248 | + | ||
249 | + if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | ||
250 | + { | ||
251 | + log("%s", "DBUS request name failed"); | ||
252 | + conn = NULL; | ||
253 | + return; | ||
254 | + } | ||
255 | + | ||
45 | #else | 256 | #else |
46 | 257 | ||
47 | #endif // HAVE_DBUS | 258 | #endif // HAVE_DBUS |
@@ -51,6 +262,10 @@ pw3270::ipc3270_session::~ipc3270_session() | @@ -51,6 +262,10 @@ pw3270::ipc3270_session::~ipc3270_session() | ||
51 | { | 262 | { |
52 | #ifdef HAVE_DBUS | 263 | #ifdef HAVE_DBUS |
53 | 264 | ||
265 | + free(dest); | ||
266 | + free(path); | ||
267 | + free(intf); | ||
268 | + | ||
54 | #endif // HAVE_DBUS | 269 | #endif // HAVE_DBUS |
55 | } | 270 | } |
56 | 271 |