Commit 37b5492d17d507176a2bce6b44d0f2f994c75043
1 parent
48811875
Exists in
master
and in
1 other branch
Migrating HLLAPI compatible plugin to another repository.
Showing
9 changed files
with
791 additions
and
512 deletions
Show diff stats
.gitignore
Makefile.in
... | ... | @@ -31,6 +31,7 @@ PACKAGE_NAME=@PACKAGE_NAME@ |
31 | 31 | |
32 | 32 | PLUGIN_SOURCES= \ |
33 | 33 | $(wildcard src/plugin/*.c) \ |
34 | + $(wildcard src/plugin/@OSNAME@/*.c) \ | |
34 | 35 | $(wildcard src/plugin/@OSNAME@/*.rc) |
35 | 36 | |
36 | 37 | TEST_SOURCES= \ |
... | ... | @@ -78,9 +79,7 @@ BINRLS=$(BINDIR)/Release |
78 | 79 | #---[ Rules ]---------------------------------------------------------------------------- |
79 | 80 | |
80 | 81 | DEPENDS= \ |
81 | - Makefile \ | |
82 | - src/include/*.h \ | |
83 | - src/include/lib3270/*.h | |
82 | + Makefile | |
84 | 83 | |
85 | 84 | CFLAGS= \ |
86 | 85 | @CFLAGS@ \ |
... | ... | @@ -229,11 +228,17 @@ $(POTDIR)/$(MODULE_NAME).pot: \ |
229 | 228 | locale: \ |
230 | 229 | $(POTDIR)/$(MODULE_NAME).pot |
231 | 230 | |
231 | +run: \ | |
232 | + $(BINDBG)/$(MODULE_NAME)@DLLEXT@ \ | |
233 | + $(BINDBG)/$(MODULE_NAME)@EXEEXT@ | |
234 | + | |
235 | + $(BINDBG)/$(MODULE_NAME)@EXEEXT@ | |
232 | 236 | |
233 | 237 | #---[ Debug Targets ]-------------------------------------------------------------------- |
234 | 238 | |
235 | 239 | Debug: \ |
236 | - $(BINDBG)/$(MODULE_NAME)@DLLEXT@ | |
240 | + $(BINDBG)/$(MODULE_NAME)@DLLEXT@ \ | |
241 | + $(BINDBG)/$(MODULE_NAME)@EXEEXT@ | |
237 | 242 | |
238 | 243 | $(BINDBG)/lib$(MODULE_NAME).a: \ |
239 | 244 | $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) |
... | ... | @@ -260,25 +265,8 @@ $(BINDBG)/$(MODULE_NAME)@EXEEXT@: \ |
260 | 265 | $(GTK_LIBS) \ |
261 | 266 | $(GLIB_LIBS) |
262 | 267 | |
263 | -$(BINDBG)/$(PACKAGE_NAME)d@EXEEXT@: \ | |
264 | - $(foreach SRC, $(basename $(SERVICE_SOURCES)), $(OBJDBG)/$(SRC).o) \ | |
265 | - $(BINDBG)/lib$(MODULE_NAME).a | |
266 | - | |
267 | - @$(MKDIR) $(@D) | |
268 | - @echo $< ... | |
269 | - @$(LD) \ | |
270 | - -o $@ \ | |
271 | - $(foreach SRC, $(basename $(SERVICE_SOURCES)), $(OBJDBG)/$(SRC).o) \ | |
272 | - -L$(BINDBG) \ | |
273 | - -Wl,-rpath,$(BINDBG) \ | |
274 | - $(LDFLAGS) \ | |
275 | - $(LIBS) \ | |
276 | - -l$(MODULE_NAME) \ | |
277 | - $(GLIB_LIBS) | |
278 | - | |
279 | 268 | $(BINDBG)/$(MODULE_NAME)@DLLEXT@: \ |
280 | - $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ | |
281 | - $(BINDBG)/lib$(MODULE_NAME).a | |
269 | + $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) | |
282 | 270 | |
283 | 271 | @$(MKDIR) $(@D) |
284 | 272 | @echo $< ... |
... | ... | @@ -287,7 +275,7 @@ $(BINDBG)/$(MODULE_NAME)@DLLEXT@: \ |
287 | 275 | -o $@ \ |
288 | 276 | $(LDFLAGS) \ |
289 | 277 | $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ |
290 | - -L$(BINDBG) -l$(MODULE_NAME) \ | |
278 | + -L$(BINDBG) -lpw3270cpp \ | |
291 | 279 | $(V3270_LIBS) \ |
292 | 280 | $(LIBS) \ |
293 | 281 | $(GTK_LIBS) |
... | ... | @@ -308,8 +296,10 @@ cleanDebug: |
308 | 296 | @rm -fr $(BINDBG) |
309 | 297 | @rm -fr $(OBJDIR)/marshal |
310 | 298 | |
311 | -clean: \ | |
312 | - cleanDebug \ | |
313 | - cleanRelease | |
299 | +cleanRelease: | |
300 | + | |
301 | + @rm -fr $(OBJRLS) | |
302 | + @rm -fr $(BINRLS) | |
303 | + @rm -fr $(OBJDIR)/marshal | |
314 | 304 | |
315 | 305 | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | |
2 | +<CodeBlocks_project_file> | |
3 | + <FileVersion major="1" minor="6" /> | |
4 | + <Project> | |
5 | + <Option title="pw3270 HLLAPI v5.1 compatibility plugin" /> | |
6 | + <Option pch_mode="2" /> | |
7 | + <Option compiler="gcc" /> | |
8 | + <Build> | |
9 | + <Target title="Debug"> | |
10 | + <Option output=".bin/Debug/pw3270 HLLAPI v5" prefix_auto="1" extension_auto="1" /> | |
11 | + <Option object_output=".obj/Debug/" /> | |
12 | + <Option type="1" /> | |
13 | + <Option compiler="gcc" /> | |
14 | + <Compiler> | |
15 | + <Add option="-g" /> | |
16 | + </Compiler> | |
17 | + </Target> | |
18 | + <Target title="Release"> | |
19 | + <Option output=".bin/Release/pw3270 HLLAPI v5" prefix_auto="1" extension_auto="1" /> | |
20 | + <Option object_output=".obj/Release/" /> | |
21 | + <Option type="1" /> | |
22 | + <Option compiler="gcc" /> | |
23 | + <Compiler> | |
24 | + <Add option="-O2" /> | |
25 | + </Compiler> | |
26 | + <Linker> | |
27 | + <Add option="-s" /> | |
28 | + </Linker> | |
29 | + </Target> | |
30 | + </Build> | |
31 | + <Compiler> | |
32 | + <Add option="-Wall" /> | |
33 | + </Compiler> | |
34 | + <Extensions> | |
35 | + <code_completion /> | |
36 | + <envvars /> | |
37 | + <debugger /> | |
38 | + <lib_finder disable_auto="1" /> | |
39 | + </Extensions> | |
40 | + </Project> | |
41 | +</CodeBlocks_project_file> | ... | ... |
... | ... | @@ -0,0 +1,122 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como daemon.c e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * licinio@bb.com.br (Licínio Luis Branco) | |
28 | + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
29 | + * | |
30 | + * Referencias: | |
31 | + * | |
32 | + * https://live.gnome.org/DBusGlibBindings | |
33 | + * | |
34 | + */ | |
35 | + | |
36 | +#include <glib.h> | |
37 | +#include <dbus/dbus.h> | |
38 | +#include <dbus/dbus-glib-lowlevel.h> | |
39 | +#include <dbus/dbus-glib.h> | |
40 | + | |
41 | +#include "daemon.h" | |
42 | +#include "dbus-glue.h" | |
43 | + | |
44 | +#define PW3270_DBUS_SERVICE_PATH "/br/com/bb/pw3270" | |
45 | +#define PW3270_DBUS_SERVICE "br.com.bb.pw3270" | |
46 | + | |
47 | + | |
48 | +/*---[ Globals ]---------------------------------------------------------------------------------*/ | |
49 | + | |
50 | + static DBusGConnection * connection = NULL; | |
51 | + static DBusGProxy * proxy = NULL; | |
52 | + static H3270 * hSession = NULL; | |
53 | + | |
54 | + GMainLoop * main_loop = NULL; | |
55 | + | |
56 | + | |
57 | +/*---[ Implement ]-------------------------------------------------------------------------------*/ | |
58 | + | |
59 | +static int initialize(void) | |
60 | +{ | |
61 | + GError * error = NULL; | |
62 | + guint result; | |
63 | + | |
64 | + connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); | |
65 | + if(error) | |
66 | + { | |
67 | + g_message("Error \"%s\" getting session dbus",error->message); | |
68 | + g_error_free(error); | |
69 | + return -1; | |
70 | + } | |
71 | + | |
72 | + proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); | |
73 | + | |
74 | + org_freedesktop_DBus_request_name(proxy, PW3270_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); | |
75 | + | |
76 | + pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,PW3270_DBUS_SERVICE_PATH); | |
77 | + | |
78 | + return 0; | |
79 | +} | |
80 | + | |
81 | +static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) | |
82 | +{ | |
83 | + g_logv(module,rc ? G_LOG_LEVEL_WARNING : G_LOG_LEVEL_MESSAGE, fmt, args); | |
84 | +} | |
85 | + | |
86 | +int main(int numpar, char *param[]) | |
87 | +{ | |
88 | + g_type_init (); | |
89 | + | |
90 | + if (!g_thread_supported ()) | |
91 | + g_thread_init (NULL); | |
92 | + | |
93 | + dbus_g_thread_init (); | |
94 | + | |
95 | + lib3270_set_log_handler(loghandler); | |
96 | + pw3270_dbus_register_io_handlers(); | |
97 | + | |
98 | + hSession = lib3270_session_new(""); | |
99 | + | |
100 | + main_loop = g_main_loop_new (NULL, FALSE); | |
101 | + | |
102 | + if(initialize()) | |
103 | + return -1; | |
104 | + | |
105 | + g_main_loop_run(main_loop); | |
106 | + | |
107 | + lib3270_session_free(hSession); | |
108 | + | |
109 | + return 0; | |
110 | +} | |
111 | + | |
112 | +void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context) | |
113 | +{ | |
114 | + g_main_loop_quit(main_loop); | |
115 | + dbus_g_method_return(context,0); | |
116 | +} | |
117 | + | |
118 | +H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object) | |
119 | +{ | |
120 | + return hSession; | |
121 | +} | |
122 | + | ... | ... |
... | ... | @@ -0,0 +1,361 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como iocallback.c e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * licinio@bb.com.br (Licínio Luis Branco) | |
28 | + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
29 | + * | |
30 | + */ | |
31 | + | |
32 | +#if defined(_WIN32) /*[*/ | |
33 | + #include <windows.h> | |
34 | +#elif defined(__APPLE__) | |
35 | + #include <poll.h> | |
36 | + #include <string.h> | |
37 | +#else | |
38 | + #include <poll.h> | |
39 | + #include <string.h> | |
40 | +#endif /*]*/ | |
41 | + | |
42 | +#include <stdio.h> | |
43 | +#include <glib.h> | |
44 | +#include "daemon.h" | |
45 | + | |
46 | +static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); | |
47 | +static void static_RemoveSource(void *id); | |
48 | + | |
49 | +static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); | |
50 | +static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); | |
51 | + | |
52 | +static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); | |
53 | +static void static_RemoveTimeOut(void * timer); | |
54 | +static int static_Sleep(H3270 *hSession, int seconds); | |
55 | +static int static_RunPendingEvents(H3270 *hSession, int wait); | |
56 | + | |
57 | +static gboolean IO_prepare(GSource *source, gint *timeout); | |
58 | +static gboolean IO_check(GSource *source); | |
59 | +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); | |
60 | +static void IO_finalize(GSource *source); /* Can be NULL */ | |
61 | +static gboolean IO_closure(gpointer data); | |
62 | + | |
63 | +/*---[ Structs ]-------------------------------------------------------------------------------------------*/ | |
64 | + | |
65 | + typedef struct _IO_Source | |
66 | + { | |
67 | + GSource gsrc; | |
68 | + GPollFD poll; | |
69 | +#if defined(_WIN32) | |
70 | + HANDLE source; | |
71 | +#else | |
72 | + int source; | |
73 | +#endif // _WIN32 | |
74 | + void (*fn)(H3270 *session); | |
75 | + H3270 *session; | |
76 | + } IO_Source; | |
77 | + | |
78 | + typedef struct _timer | |
79 | + { | |
80 | + unsigned char remove; | |
81 | + void (*fn)(H3270 *session); | |
82 | + H3270 *session; | |
83 | + } TIMER; | |
84 | + | |
85 | + static GSourceFuncs IOSources = | |
86 | + { | |
87 | + IO_prepare, | |
88 | + IO_check, | |
89 | + IO_dispatch, | |
90 | + IO_finalize, | |
91 | + IO_closure, | |
92 | + NULL | |
93 | + }; | |
94 | + | |
95 | +/*---[ Implement ]-----------------------------------------------------------------------------------------*/ | |
96 | + | |
97 | +#ifdef _WIN32 | |
98 | +static void * AddSource(HANDLE source, H3270 *session, gushort events, void (*fn)(H3270 *session)) | |
99 | +#else | |
100 | +static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H3270 *session)) | |
101 | +#endif // _WIN32 | |
102 | +{ | |
103 | + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); | |
104 | + | |
105 | + src->source = source; | |
106 | + src->fn = fn; | |
107 | + src->poll.fd = (int) source; | |
108 | + src->poll.events = events; | |
109 | + src->session = session; | |
110 | + | |
111 | + g_source_attach((GSource *) src,NULL); | |
112 | + g_source_add_poll((GSource *) src,&src->poll); | |
113 | + | |
114 | + return src; | |
115 | +} | |
116 | + | |
117 | +#ifdef _WIN32 | |
118 | +static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) | |
119 | +#else | |
120 | +static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) | |
121 | +#endif // _WIN32 | |
122 | +{ | |
123 | + return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn); | |
124 | +} | |
125 | + | |
126 | +static void static_RemoveSource(void *id) | |
127 | +{ | |
128 | + if(id) | |
129 | + g_source_destroy((GSource *) id); | |
130 | +} | |
131 | + | |
132 | +#if defined(_WIN32) | |
133 | +static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) | |
134 | +{ | |
135 | + return 0; | |
136 | +} | |
137 | +#else | |
138 | +static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) | |
139 | +{ | |
140 | + return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn); | |
141 | +} | |
142 | +#endif // _WIN32 | |
143 | + | |
144 | +static gboolean do_timer(TIMER *t) | |
145 | +{ | |
146 | + if(!t->remove) | |
147 | + t->fn(t->session); | |
148 | + return FALSE; | |
149 | +} | |
150 | + | |
151 | +static void * static_AddTimeOut(unsigned long interval, H3270 *session, void (*proc)(H3270 *session)) | |
152 | +{ | |
153 | + TIMER *t = g_malloc0(sizeof(TIMER)); | |
154 | + | |
155 | + t->fn = proc; | |
156 | + t->session = session; | |
157 | + | |
158 | + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free); | |
159 | + | |
160 | + return t; | |
161 | +} | |
162 | + | |
163 | +static void static_RemoveTimeOut(void * timer) | |
164 | +{ | |
165 | + ((TIMER *) timer)->remove++; | |
166 | +} | |
167 | + | |
168 | +static gboolean IO_prepare(GSource *source, gint *timeout) | |
169 | +{ | |
170 | + /* | |
171 | + * Called before all the file descriptors are polled. | |
172 | + * If the source can determine that it is ready here | |
173 | + * (without waiting for the results of the poll() call) | |
174 | + * it should return TRUE. | |
175 | + * | |
176 | + * It can also return a timeout_ value which should be the maximum | |
177 | + * timeout (in milliseconds) which should be passed to the poll() call. | |
178 | + * The actual timeout used will be -1 if all sources returned -1, | |
179 | + * or it will be the minimum of all the timeout_ values | |
180 | + * returned which were >= 0. | |
181 | + * | |
182 | + */ | |
183 | + return 0; | |
184 | +} | |
185 | + | |
186 | +static gboolean IO_check(GSource *source) | |
187 | +{ | |
188 | + /* | |
189 | + * Called after all the file descriptors are polled. | |
190 | + * The source should return TRUE if it is ready to be dispatched. | |
191 | + * Note that some time may have passed since the previous prepare | |
192 | + * function was called, so the source should be checked again here. | |
193 | + * | |
194 | + */ | |
195 | +#if defined(_WIN32) /*[*/ | |
196 | + | |
197 | + if(WaitForSingleObject(((IO_Source *) source)->source,0) == WAIT_OBJECT_0) | |
198 | + return TRUE; | |
199 | + | |
200 | +#else /*][*/ | |
201 | + | |
202 | + struct pollfd fds; | |
203 | + | |
204 | + memset(&fds,0,sizeof(fds)); | |
205 | + | |
206 | + fds.fd = ((IO_Source *) source)->poll.fd; | |
207 | + fds.events = ((IO_Source *) source)->poll.events; | |
208 | + | |
209 | + if(poll(&fds,1,0) > 0) | |
210 | + return TRUE; | |
211 | + | |
212 | +#endif /*]*/ | |
213 | + | |
214 | + return FALSE; | |
215 | +} | |
216 | + | |
217 | +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) | |
218 | +{ | |
219 | + /* | |
220 | + * Called to dispatch the event source, | |
221 | + * after it has returned TRUE in either its prepare or its check function. | |
222 | + * The dispatch function is passed in a callback function and data. | |
223 | + * The callback function may be NULL if the source was never connected | |
224 | + * to a callback using g_source_set_callback(). The dispatch function | |
225 | + * should call the callback function with user_data and whatever additional | |
226 | + * parameters are needed for this type of event source. | |
227 | + */ | |
228 | + ((IO_Source *) source)->fn(((IO_Source *) source)->session); | |
229 | + return TRUE; | |
230 | +} | |
231 | + | |
232 | +static void IO_finalize(GSource *source) | |
233 | +{ | |
234 | + | |
235 | +} | |
236 | + | |
237 | +static gboolean IO_closure(gpointer data) | |
238 | +{ | |
239 | + return 0; | |
240 | +} | |
241 | + | |
242 | +struct bgParameter | |
243 | +{ | |
244 | + gboolean running; | |
245 | + gboolean timer; | |
246 | + H3270 *session; | |
247 | + int rc; | |
248 | + int(*callback)(H3270 *session, void *); | |
249 | + void *parm; | |
250 | + | |
251 | +}; | |
252 | + | |
253 | +gpointer BgCall(struct bgParameter *p) | |
254 | +{ | |
255 | +// trace("%s starts",__FUNCTION__); | |
256 | + p->rc = p->callback(p->session, p->parm); | |
257 | + p->running = FALSE; | |
258 | +// trace("%s ends",__FUNCTION__); | |
259 | + return 0; | |
260 | +} | |
261 | + | |
262 | +static gboolean wait_for_thread(struct bgParameter *p) | |
263 | +{ | |
264 | + if(!p->running) | |
265 | + { | |
266 | + p->timer = 0; | |
267 | + return FALSE; | |
268 | + } | |
269 | + return TRUE; | |
270 | +} | |
271 | + | |
272 | +static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm) | |
273 | +{ | |
274 | + struct bgParameter p = { TRUE, TRUE, session, -1, callback, parm }; | |
275 | + GThread * thread; | |
276 | + | |
277 | +// trace("Starting auxiliary thread for callback %p",callback); | |
278 | + | |
279 | + p.running = TRUE; | |
280 | + p.timer = TRUE; | |
281 | + | |
282 | + thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL); | |
283 | + | |
284 | + if(!thread) | |
285 | + { | |
286 | + g_error("Can't start background thread"); | |
287 | + return -1; | |
288 | + } | |
289 | + | |
290 | + g_timeout_add(50,(GSourceFunc) wait_for_thread,(gpointer) &p); | |
291 | + | |
292 | + while(p.timer) | |
293 | + g_main_context_iteration(g_main_loop_get_context(main_loop),TRUE); | |
294 | + | |
295 | + return p.rc; | |
296 | +} | |
297 | + | |
298 | +static int static_Sleep(H3270 *hSession, int seconds) | |
299 | +{ | |
300 | + time_t end = time(0) + seconds; | |
301 | + | |
302 | + while(time(0) < end) | |
303 | + g_main_iteration(TRUE); | |
304 | + | |
305 | + return 0; | |
306 | +} | |
307 | + | |
308 | +static int static_RunPendingEvents(H3270 *hSession, int wait) | |
309 | +{ | |
310 | + GMainContext *context = g_main_loop_get_context(main_loop); | |
311 | + int rc = 0; | |
312 | + while(g_main_context_pending(context)) | |
313 | + { | |
314 | + rc = 1; | |
315 | + g_main_context_iteration(context,FALSE); | |
316 | + } | |
317 | + | |
318 | + if(wait) | |
319 | + g_main_context_iteration(context,TRUE); | |
320 | + | |
321 | + return rc; | |
322 | +} | |
323 | + | |
324 | +static void beep(H3270 *session) | |
325 | +{ | |
326 | +} | |
327 | + | |
328 | +void pw3270_dbus_register_io_handlers(void) | |
329 | +{ | |
330 | + static const struct lib3270_callbacks hdl = | |
331 | + { | |
332 | + sizeof(struct lib3270_callbacks), | |
333 | + | |
334 | + static_AddTimeOut, | |
335 | + static_RemoveTimeOut, | |
336 | + | |
337 | + static_AddInput, | |
338 | + static_RemoveSource, | |
339 | + | |
340 | + static_AddExcept, | |
341 | + | |
342 | +#ifdef G_THREADS_ENABLED | |
343 | + static_CallAndWait, | |
344 | +#else | |
345 | + NULL, | |
346 | +#endif | |
347 | + | |
348 | + static_Sleep, | |
349 | + static_RunPendingEvents, | |
350 | + beep | |
351 | + | |
352 | + }; | |
353 | + | |
354 | + #error Need rewrite | |
355 | + | |
356 | + if(lib3270_register_handlers(&hdl)) | |
357 | + { | |
358 | + g_error("%s","Can't set lib3270 I/O handlers"); | |
359 | + } | |
360 | + | |
361 | +} | ... | ... |
src/plugin/linux/daemon.c
... | ... | @@ -1,122 +0,0 @@ |
1 | -/* | |
2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | - * | |
6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | - * | |
8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | - * Free Software Foundation. | |
11 | - * | |
12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | - * obter mais detalhes. | |
16 | - * | |
17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | - * | |
21 | - * Este programa está nomeado como daemon.c e possui - linhas de código. | |
22 | - * | |
23 | - * Contatos: | |
24 | - * | |
25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | - * licinio@bb.com.br (Licínio Luis Branco) | |
28 | - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
29 | - * | |
30 | - * Referencias: | |
31 | - * | |
32 | - * https://live.gnome.org/DBusGlibBindings | |
33 | - * | |
34 | - */ | |
35 | - | |
36 | -#include <glib.h> | |
37 | -#include <dbus/dbus.h> | |
38 | -#include <dbus/dbus-glib-lowlevel.h> | |
39 | -#include <dbus/dbus-glib.h> | |
40 | - | |
41 | -#include "daemon.h" | |
42 | -#include "dbus-glue.h" | |
43 | - | |
44 | -#define PW3270_DBUS_SERVICE_PATH "/br/com/bb/pw3270" | |
45 | -#define PW3270_DBUS_SERVICE "br.com.bb.pw3270" | |
46 | - | |
47 | - | |
48 | -/*---[ Globals ]---------------------------------------------------------------------------------*/ | |
49 | - | |
50 | - static DBusGConnection * connection = NULL; | |
51 | - static DBusGProxy * proxy = NULL; | |
52 | - static H3270 * hSession = NULL; | |
53 | - | |
54 | - GMainLoop * main_loop = NULL; | |
55 | - | |
56 | - | |
57 | -/*---[ Implement ]-------------------------------------------------------------------------------*/ | |
58 | - | |
59 | -static int initialize(void) | |
60 | -{ | |
61 | - GError * error = NULL; | |
62 | - guint result; | |
63 | - | |
64 | - connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); | |
65 | - if(error) | |
66 | - { | |
67 | - g_message("Error \"%s\" getting session dbus",error->message); | |
68 | - g_error_free(error); | |
69 | - return -1; | |
70 | - } | |
71 | - | |
72 | - proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); | |
73 | - | |
74 | - org_freedesktop_DBus_request_name(proxy, PW3270_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); | |
75 | - | |
76 | - pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,PW3270_DBUS_SERVICE_PATH); | |
77 | - | |
78 | - return 0; | |
79 | -} | |
80 | - | |
81 | -static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) | |
82 | -{ | |
83 | - g_logv(module,rc ? G_LOG_LEVEL_WARNING : G_LOG_LEVEL_MESSAGE, fmt, args); | |
84 | -} | |
85 | - | |
86 | -int main(int numpar, char *param[]) | |
87 | -{ | |
88 | - g_type_init (); | |
89 | - | |
90 | - if (!g_thread_supported ()) | |
91 | - g_thread_init (NULL); | |
92 | - | |
93 | - dbus_g_thread_init (); | |
94 | - | |
95 | - lib3270_set_log_handler(loghandler); | |
96 | - pw3270_dbus_register_io_handlers(); | |
97 | - | |
98 | - hSession = lib3270_session_new(""); | |
99 | - | |
100 | - main_loop = g_main_loop_new (NULL, FALSE); | |
101 | - | |
102 | - if(initialize()) | |
103 | - return -1; | |
104 | - | |
105 | - g_main_loop_run(main_loop); | |
106 | - | |
107 | - lib3270_session_free(hSession); | |
108 | - | |
109 | - return 0; | |
110 | -} | |
111 | - | |
112 | -void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context) | |
113 | -{ | |
114 | - g_main_loop_quit(main_loop); | |
115 | - dbus_g_method_return(context,0); | |
116 | -} | |
117 | - | |
118 | -H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object) | |
119 | -{ | |
120 | - return hSession; | |
121 | -} | |
122 | - |
src/plugin/linux/iocallback.c
... | ... | @@ -1,361 +0,0 @@ |
1 | -/* | |
2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | - * | |
6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | - * | |
8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | - * Free Software Foundation. | |
11 | - * | |
12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | - * obter mais detalhes. | |
16 | - * | |
17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | - * | |
21 | - * Este programa está nomeado como iocallback.c e possui - linhas de código. | |
22 | - * | |
23 | - * Contatos: | |
24 | - * | |
25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | - * licinio@bb.com.br (Licínio Luis Branco) | |
28 | - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
29 | - * | |
30 | - */ | |
31 | - | |
32 | -#if defined(_WIN32) /*[*/ | |
33 | - #include <windows.h> | |
34 | -#elif defined(__APPLE__) | |
35 | - #include <poll.h> | |
36 | - #include <string.h> | |
37 | -#else | |
38 | - #include <poll.h> | |
39 | - #include <string.h> | |
40 | -#endif /*]*/ | |
41 | - | |
42 | -#include <stdio.h> | |
43 | -#include <glib.h> | |
44 | -#include "daemon.h" | |
45 | - | |
46 | -static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); | |
47 | -static void static_RemoveSource(void *id); | |
48 | - | |
49 | -static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); | |
50 | -static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); | |
51 | - | |
52 | -static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); | |
53 | -static void static_RemoveTimeOut(void * timer); | |
54 | -static int static_Sleep(H3270 *hSession, int seconds); | |
55 | -static int static_RunPendingEvents(H3270 *hSession, int wait); | |
56 | - | |
57 | -static gboolean IO_prepare(GSource *source, gint *timeout); | |
58 | -static gboolean IO_check(GSource *source); | |
59 | -static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); | |
60 | -static void IO_finalize(GSource *source); /* Can be NULL */ | |
61 | -static gboolean IO_closure(gpointer data); | |
62 | - | |
63 | -/*---[ Structs ]-------------------------------------------------------------------------------------------*/ | |
64 | - | |
65 | - typedef struct _IO_Source | |
66 | - { | |
67 | - GSource gsrc; | |
68 | - GPollFD poll; | |
69 | -#if defined(_WIN32) | |
70 | - HANDLE source; | |
71 | -#else | |
72 | - int source; | |
73 | -#endif // _WIN32 | |
74 | - void (*fn)(H3270 *session); | |
75 | - H3270 *session; | |
76 | - } IO_Source; | |
77 | - | |
78 | - typedef struct _timer | |
79 | - { | |
80 | - unsigned char remove; | |
81 | - void (*fn)(H3270 *session); | |
82 | - H3270 *session; | |
83 | - } TIMER; | |
84 | - | |
85 | - static GSourceFuncs IOSources = | |
86 | - { | |
87 | - IO_prepare, | |
88 | - IO_check, | |
89 | - IO_dispatch, | |
90 | - IO_finalize, | |
91 | - IO_closure, | |
92 | - NULL | |
93 | - }; | |
94 | - | |
95 | -/*---[ Implement ]-----------------------------------------------------------------------------------------*/ | |
96 | - | |
97 | -#ifdef _WIN32 | |
98 | -static void * AddSource(HANDLE source, H3270 *session, gushort events, void (*fn)(H3270 *session)) | |
99 | -#else | |
100 | -static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H3270 *session)) | |
101 | -#endif // _WIN32 | |
102 | -{ | |
103 | - IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); | |
104 | - | |
105 | - src->source = source; | |
106 | - src->fn = fn; | |
107 | - src->poll.fd = (int) source; | |
108 | - src->poll.events = events; | |
109 | - src->session = session; | |
110 | - | |
111 | - g_source_attach((GSource *) src,NULL); | |
112 | - g_source_add_poll((GSource *) src,&src->poll); | |
113 | - | |
114 | - return src; | |
115 | -} | |
116 | - | |
117 | -#ifdef _WIN32 | |
118 | -static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) | |
119 | -#else | |
120 | -static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) | |
121 | -#endif // _WIN32 | |
122 | -{ | |
123 | - return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn); | |
124 | -} | |
125 | - | |
126 | -static void static_RemoveSource(void *id) | |
127 | -{ | |
128 | - if(id) | |
129 | - g_source_destroy((GSource *) id); | |
130 | -} | |
131 | - | |
132 | -#if defined(_WIN32) | |
133 | -static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) | |
134 | -{ | |
135 | - return 0; | |
136 | -} | |
137 | -#else | |
138 | -static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) | |
139 | -{ | |
140 | - return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn); | |
141 | -} | |
142 | -#endif // _WIN32 | |
143 | - | |
144 | -static gboolean do_timer(TIMER *t) | |
145 | -{ | |
146 | - if(!t->remove) | |
147 | - t->fn(t->session); | |
148 | - return FALSE; | |
149 | -} | |
150 | - | |
151 | -static void * static_AddTimeOut(unsigned long interval, H3270 *session, void (*proc)(H3270 *session)) | |
152 | -{ | |
153 | - TIMER *t = g_malloc0(sizeof(TIMER)); | |
154 | - | |
155 | - t->fn = proc; | |
156 | - t->session = session; | |
157 | - | |
158 | - g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free); | |
159 | - | |
160 | - return t; | |
161 | -} | |
162 | - | |
163 | -static void static_RemoveTimeOut(void * timer) | |
164 | -{ | |
165 | - ((TIMER *) timer)->remove++; | |
166 | -} | |
167 | - | |
168 | -static gboolean IO_prepare(GSource *source, gint *timeout) | |
169 | -{ | |
170 | - /* | |
171 | - * Called before all the file descriptors are polled. | |
172 | - * If the source can determine that it is ready here | |
173 | - * (without waiting for the results of the poll() call) | |
174 | - * it should return TRUE. | |
175 | - * | |
176 | - * It can also return a timeout_ value which should be the maximum | |
177 | - * timeout (in milliseconds) which should be passed to the poll() call. | |
178 | - * The actual timeout used will be -1 if all sources returned -1, | |
179 | - * or it will be the minimum of all the timeout_ values | |
180 | - * returned which were >= 0. | |
181 | - * | |
182 | - */ | |
183 | - return 0; | |
184 | -} | |
185 | - | |
186 | -static gboolean IO_check(GSource *source) | |
187 | -{ | |
188 | - /* | |
189 | - * Called after all the file descriptors are polled. | |
190 | - * The source should return TRUE if it is ready to be dispatched. | |
191 | - * Note that some time may have passed since the previous prepare | |
192 | - * function was called, so the source should be checked again here. | |
193 | - * | |
194 | - */ | |
195 | -#if defined(_WIN32) /*[*/ | |
196 | - | |
197 | - if(WaitForSingleObject(((IO_Source *) source)->source,0) == WAIT_OBJECT_0) | |
198 | - return TRUE; | |
199 | - | |
200 | -#else /*][*/ | |
201 | - | |
202 | - struct pollfd fds; | |
203 | - | |
204 | - memset(&fds,0,sizeof(fds)); | |
205 | - | |
206 | - fds.fd = ((IO_Source *) source)->poll.fd; | |
207 | - fds.events = ((IO_Source *) source)->poll.events; | |
208 | - | |
209 | - if(poll(&fds,1,0) > 0) | |
210 | - return TRUE; | |
211 | - | |
212 | -#endif /*]*/ | |
213 | - | |
214 | - return FALSE; | |
215 | -} | |
216 | - | |
217 | -static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) | |
218 | -{ | |
219 | - /* | |
220 | - * Called to dispatch the event source, | |
221 | - * after it has returned TRUE in either its prepare or its check function. | |
222 | - * The dispatch function is passed in a callback function and data. | |
223 | - * The callback function may be NULL if the source was never connected | |
224 | - * to a callback using g_source_set_callback(). The dispatch function | |
225 | - * should call the callback function with user_data and whatever additional | |
226 | - * parameters are needed for this type of event source. | |
227 | - */ | |
228 | - ((IO_Source *) source)->fn(((IO_Source *) source)->session); | |
229 | - return TRUE; | |
230 | -} | |
231 | - | |
232 | -static void IO_finalize(GSource *source) | |
233 | -{ | |
234 | - | |
235 | -} | |
236 | - | |
237 | -static gboolean IO_closure(gpointer data) | |
238 | -{ | |
239 | - return 0; | |
240 | -} | |
241 | - | |
242 | -struct bgParameter | |
243 | -{ | |
244 | - gboolean running; | |
245 | - gboolean timer; | |
246 | - H3270 *session; | |
247 | - int rc; | |
248 | - int(*callback)(H3270 *session, void *); | |
249 | - void *parm; | |
250 | - | |
251 | -}; | |
252 | - | |
253 | -gpointer BgCall(struct bgParameter *p) | |
254 | -{ | |
255 | -// trace("%s starts",__FUNCTION__); | |
256 | - p->rc = p->callback(p->session, p->parm); | |
257 | - p->running = FALSE; | |
258 | -// trace("%s ends",__FUNCTION__); | |
259 | - return 0; | |
260 | -} | |
261 | - | |
262 | -static gboolean wait_for_thread(struct bgParameter *p) | |
263 | -{ | |
264 | - if(!p->running) | |
265 | - { | |
266 | - p->timer = 0; | |
267 | - return FALSE; | |
268 | - } | |
269 | - return TRUE; | |
270 | -} | |
271 | - | |
272 | -static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm) | |
273 | -{ | |
274 | - struct bgParameter p = { TRUE, TRUE, session, -1, callback, parm }; | |
275 | - GThread * thread; | |
276 | - | |
277 | -// trace("Starting auxiliary thread for callback %p",callback); | |
278 | - | |
279 | - p.running = TRUE; | |
280 | - p.timer = TRUE; | |
281 | - | |
282 | - thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL); | |
283 | - | |
284 | - if(!thread) | |
285 | - { | |
286 | - g_error("Can't start background thread"); | |
287 | - return -1; | |
288 | - } | |
289 | - | |
290 | - g_timeout_add(50,(GSourceFunc) wait_for_thread,(gpointer) &p); | |
291 | - | |
292 | - while(p.timer) | |
293 | - g_main_context_iteration(g_main_loop_get_context(main_loop),TRUE); | |
294 | - | |
295 | - return p.rc; | |
296 | -} | |
297 | - | |
298 | -static int static_Sleep(H3270 *hSession, int seconds) | |
299 | -{ | |
300 | - time_t end = time(0) + seconds; | |
301 | - | |
302 | - while(time(0) < end) | |
303 | - g_main_iteration(TRUE); | |
304 | - | |
305 | - return 0; | |
306 | -} | |
307 | - | |
308 | -static int static_RunPendingEvents(H3270 *hSession, int wait) | |
309 | -{ | |
310 | - GMainContext *context = g_main_loop_get_context(main_loop); | |
311 | - int rc = 0; | |
312 | - while(g_main_context_pending(context)) | |
313 | - { | |
314 | - rc = 1; | |
315 | - g_main_context_iteration(context,FALSE); | |
316 | - } | |
317 | - | |
318 | - if(wait) | |
319 | - g_main_context_iteration(context,TRUE); | |
320 | - | |
321 | - return rc; | |
322 | -} | |
323 | - | |
324 | -static void beep(H3270 *session) | |
325 | -{ | |
326 | -} | |
327 | - | |
328 | -void pw3270_dbus_register_io_handlers(void) | |
329 | -{ | |
330 | - static const struct lib3270_callbacks hdl = | |
331 | - { | |
332 | - sizeof(struct lib3270_callbacks), | |
333 | - | |
334 | - static_AddTimeOut, | |
335 | - static_RemoveTimeOut, | |
336 | - | |
337 | - static_AddInput, | |
338 | - static_RemoveSource, | |
339 | - | |
340 | - static_AddExcept, | |
341 | - | |
342 | -#ifdef G_THREADS_ENABLED | |
343 | - static_CallAndWait, | |
344 | -#else | |
345 | - NULL, | |
346 | -#endif | |
347 | - | |
348 | - static_Sleep, | |
349 | - static_RunPendingEvents, | |
350 | - beep | |
351 | - | |
352 | - }; | |
353 | - | |
354 | - #error Need rewrite | |
355 | - | |
356 | - if(lib3270_register_handlers(&hdl)) | |
357 | - { | |
358 | - g_error("%s","Can't set lib3270 I/O handlers"); | |
359 | - } | |
360 | - | |
361 | -} |
src/plugin/linux/main.c
... | ... | @@ -40,7 +40,7 @@ |
40 | 40 | #include <pw3270/plugin.h> |
41 | 41 | |
42 | 42 | #include "service.h" |
43 | -#include "dbus-glue.h" | |
43 | +//#include "dbus-glue.h" | |
44 | 44 | |
45 | 45 | #include <gtk/gtk.h> |
46 | 46 | |
... | ... | @@ -55,7 +55,6 @@ |
55 | 55 | |
56 | 56 | LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) |
57 | 57 | { |
58 | - | |
59 | 58 | GError * error = NULL; |
60 | 59 | guint result; |
61 | 60 | char session_id = 0; | ... | ... |
... | ... | @@ -0,0 +1,247 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob | |
5 | + * o nome G3270. | |
6 | + * | |
7 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
8 | + * | |
9 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
10 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
11 | + * Free Software Foundation. | |
12 | + * | |
13 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
14 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
15 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
16 | + * obter mais detalhes. | |
17 | + * | |
18 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
19 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
20 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | + * | |
22 | + * Este programa está nomeado como testprogram.c e possui - linhas de código. | |
23 | + * | |
24 | + * Contatos: | |
25 | + * | |
26 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
27 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
28 | + * | |
29 | + */ | |
30 | + | |
31 | + | |
32 | + /** | |
33 | + * @brief Test program for pw3270 HLLAPI compatibility plugin. | |
34 | + * | |
35 | + */ | |
36 | + | |
37 | + #include <config.h> | |
38 | + #include <v3270.h> | |
39 | + #include <v3270/trace.h> | |
40 | + #include <pw3270/plugin.h> | |
41 | + #include <string.h> | |
42 | + #include <stdlib.h> | |
43 | + | |
44 | + /*---[ Globals ]------------------------------------------------------------------------------------*/ | |
45 | + | |
46 | + const gchar * plugin_path = ".bin/Debug"; | |
47 | + const gchar * session_name = "pw3270"; | |
48 | + const gchar * plugin_name = "ipc3270c." G_MODULE_SUFFIX; | |
49 | + | |
50 | + /*---[ Implement ]----------------------------------------------------------------------------------*/ | |
51 | + | |
52 | + static void close_module(GtkWidget *widget, GModule *module) | |
53 | + { | |
54 | + g_message("Closing module %p",module); | |
55 | + | |
56 | + static void (*stop)(GtkWidget *window, GtkWidget *terminal) = NULL; | |
57 | + if(!g_module_symbol(module,"pw3270_plugin_stop",(gpointer) &stop)) | |
58 | + { | |
59 | + g_message("Can't get stop method from plugin: %s",g_module_error()); | |
60 | + } | |
61 | + else | |
62 | + { | |
63 | + stop(gtk_widget_get_toplevel(widget),widget); | |
64 | + } | |
65 | + | |
66 | + g_module_close(module); | |
67 | + g_message("Module %p was closed",module); | |
68 | + } | |
69 | + | |
70 | + static void toggle_ds_trace(GtkToggleToolButton *button, GtkWidget *terminal) | |
71 | + { | |
72 | + v3270_set_toggle(terminal,LIB3270_TOGGLE_DS_TRACE,gtk_toggle_tool_button_get_active(button)); | |
73 | + } | |
74 | + | |
75 | + static void toggle_event_trace(GtkToggleToolButton *button, GtkWidget *terminal) | |
76 | + { | |
77 | + v3270_set_toggle(terminal,LIB3270_TOGGLE_EVENT_TRACE,gtk_toggle_tool_button_get_active(button)); | |
78 | + } | |
79 | + | |
80 | + static void toggle_ssl_trace(GtkToggleToolButton *button, GtkWidget *terminal) | |
81 | + { | |
82 | + v3270_set_toggle(terminal,LIB3270_TOGGLE_SSL_TRACE,gtk_toggle_tool_button_get_active(button)); | |
83 | + } | |
84 | + | |
85 | + static void toggle_screen_trace(GtkToggleToolButton *button, GtkWidget *terminal) | |
86 | + { | |
87 | + v3270_set_toggle(terminal,LIB3270_TOGGLE_SCREEN_TRACE,gtk_toggle_tool_button_get_active(button)); | |
88 | + } | |
89 | + | |
90 | + static void toggle_started_trace(GtkToggleToolButton *button, GModule *module) | |
91 | + { | |
92 | + if(!module) | |
93 | + return; | |
94 | + | |
95 | + GtkWidget * terminal = g_object_get_data(G_OBJECT(button),"terminal"); | |
96 | + | |
97 | + const gchar * method_name = (gtk_toggle_tool_button_get_active(button) ? "pw3270_plugin_start" : "pw3270_plugin_stop"); | |
98 | + | |
99 | + static void (*call)(GtkWidget *window, GtkWidget *terminal) = NULL; | |
100 | + if(!g_module_symbol(module,method_name,(gpointer) &call)) | |
101 | + { | |
102 | + g_message("Can't get method \"%s\": %s",method_name,g_module_error()); | |
103 | + return; | |
104 | + } | |
105 | + | |
106 | + g_message("Calling %s",method_name); | |
107 | + call(gtk_widget_get_toplevel(terminal), GTK_WIDGET(terminal)); | |
108 | + | |
109 | + } | |
110 | + | |
111 | + static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, const gchar *tooltip, GCallback callback) | |
112 | + { | |
113 | + GtkToolItem * item = gtk_toggle_tool_button_new(); | |
114 | + gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); | |
115 | + | |
116 | + g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); | |
117 | + | |
118 | + if(tooltip) | |
119 | + gtk_widget_set_tooltip_text(GTK_WIDGET(item),tooltip); | |
120 | + | |
121 | + return item; | |
122 | + } | |
123 | + | |
124 | + static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { | |
125 | + | |
126 | + GtkWidget * window = gtk_application_window_new(app); | |
127 | + GtkWidget * terminal = v3270_new(); | |
128 | + GtkWidget * notebook = gtk_notebook_new(); | |
129 | + GModule * module = NULL; | |
130 | + | |
131 | + gtk_widget_set_name(window,session_name); | |
132 | + | |
133 | + // Setup tabs | |
134 | + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new(v3270_get_session_name(terminal))); | |
135 | + | |
136 | + // Load plugin | |
137 | + { | |
138 | + g_autofree gchar * plugin = g_build_filename(plugin_path,plugin_name,NULL); | |
139 | + | |
140 | + g_message("Loading %s",plugin); | |
141 | + | |
142 | + module = g_module_open(plugin,G_MODULE_BIND_LOCAL); | |
143 | + | |
144 | + if(module) | |
145 | + { | |
146 | + g_signal_connect (terminal, "destroy", G_CALLBACK(close_module), module); | |
147 | + } | |
148 | + else | |
149 | + { | |
150 | + g_message("Can't open \"%s\": %s",plugin,g_module_error()); | |
151 | + gtk_main_quit(); | |
152 | + } | |
153 | + | |
154 | + } | |
155 | + // Create trace window | |
156 | + { | |
157 | + GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); | |
158 | + GtkWidget * trace = v3270_trace_new(terminal); | |
159 | + GtkWidget * toolbar = gtk_toolbar_new(); | |
160 | + GtkToolItem * start = gtk_toggle_tool_button_new(); | |
161 | + | |
162 | + gtk_widget_set_sensitive(GTK_WIDGET(start),module != NULL); | |
163 | + | |
164 | + g_object_set_data(G_OBJECT(start),"terminal",terminal); | |
165 | + | |
166 | + gtk_tool_button_set_label(GTK_TOOL_BUTTON(start),"Enable"); | |
167 | + g_signal_connect(GTK_WIDGET(start), "toggled", G_CALLBACK(toggle_started_trace), module); | |
168 | + gtk_widget_set_tooltip_text(GTK_WIDGET(start),"Start/Stop plugin module"); | |
169 | + | |
170 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), start, -1); | |
171 | + | |
172 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),gtk_separator_tool_item_new(),-1); | |
173 | + | |
174 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "DS Trace","Toggle DS Trace",G_CALLBACK(toggle_ds_trace)),-1); | |
175 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Event Trace","Toggle Event Trace",G_CALLBACK(toggle_event_trace)),-1); | |
176 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Screen Trace","Toggle Screen Trace",G_CALLBACK(toggle_screen_trace)),-1); | |
177 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "SSL Trace","Toggle SSL Trace",G_CALLBACK(toggle_ssl_trace)),-1); | |
178 | + | |
179 | + gtk_box_pack_start(GTK_BOX(box),toolbar,FALSE,FALSE,0); | |
180 | + gtk_box_pack_start(GTK_BOX(box),trace,TRUE,TRUE,0); | |
181 | + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),box,gtk_label_new("Trace")); | |
182 | + } | |
183 | + | |
184 | + // Setup and show main window | |
185 | + gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); | |
186 | + gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); | |
187 | + gtk_container_add(GTK_CONTAINER(window),notebook); | |
188 | + gtk_widget_show_all (window); | |
189 | + | |
190 | + // Setup title. | |
191 | + const gchar *url = lib3270_get_url(v3270_get_session(terminal)); | |
192 | + if(url) { | |
193 | + | |
194 | + v3270_set_url(terminal,url); | |
195 | + v3270_reconnect(terminal); | |
196 | + | |
197 | + gchar * title = g_strdup_printf("%s - %s", v3270_get_session_name(terminal), url); | |
198 | + gtk_window_set_title(GTK_WINDOW(window), title); | |
199 | + g_free(title); | |
200 | + | |
201 | + } else { | |
202 | + | |
203 | + gtk_window_set_title(GTK_WINDOW(window), v3270_get_session_name(terminal)); | |
204 | + | |
205 | + } | |
206 | + | |
207 | +} | |
208 | + | |
209 | +int main (int argc, char **argv) { | |
210 | + | |
211 | + /* | |
212 | + GVariantBuilder builder; | |
213 | + | |
214 | + g_variant_builder_init(&builder,G_VARIANT_TYPE("(isi)")); | |
215 | + | |
216 | + g_variant_builder_add(&builder, "i", 10); | |
217 | + g_variant_builder_add(&builder, "s", "teste"); | |
218 | + g_variant_builder_add(&builder, "i", 20); | |
219 | + | |
220 | + GVariant *value = g_variant_builder_end(&builder); | |
221 | + | |
222 | + size_t szPacket = 0; | |
223 | + g_autofree unsigned char * buffer = ipc3270_pack("teste", value, &szPacket); | |
224 | + g_variant_unref(value); | |
225 | + | |
226 | + debug("Package \"%s\" was created with %u bytes", buffer, (unsigned int) szPacket); | |
227 | + | |
228 | + value = ipc3270_unpack(buffer); | |
229 | + | |
230 | + g_variant_unref(value); | |
231 | + */ | |
232 | + | |
233 | + GtkApplication *app; | |
234 | + int status; | |
235 | + | |
236 | + app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); | |
237 | + | |
238 | + g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); | |
239 | + | |
240 | + status = g_application_run (G_APPLICATION (app), argc, argv); | |
241 | + g_object_unref (app); | |
242 | + | |
243 | + g_message("rc=%d",status); | |
244 | + return status; | |
245 | + | |
246 | +} | |
247 | + | ... | ... |