Commit 0b41a8135f9d370b189bcac18be9736c57d89404
1 parent
79de4453
Exists in
master
and in
3 other branches
Working on IPC client module.
Showing
5 changed files
with
113 additions
and
6 deletions
Show diff stats
src/lib3270++/Makefile.in
src/lib3270++/ipc/session.cc
... | ... | @@ -0,0 +1,101 @@ |
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 - 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 | + * | |
28 | + */ | |
29 | + | |
30 | +/** | |
31 | + * @file src/lib3270++/linux/request.cc | |
32 | + * | |
33 | + * @brief Implements D-Bus message. | |
34 | + * | |
35 | + * @author perry.werneck@gmail.com | |
36 | + * | |
37 | + */ | |
38 | + | |
39 | + #include "../private.h" | |
40 | + | |
41 | + using std::string; | |
42 | + | |
43 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
44 | + | |
45 | + namespace TN3270 { | |
46 | + | |
47 | + IPC::Request::Request(Session &session, const char *method) { | |
48 | + | |
49 | + this->conn = session.conn; | |
50 | + this->msg.in = nullptr; | |
51 | + | |
52 | + this->msg.out = dbus_message_new_method_call( session.name.c_str(), // Destination | |
53 | + session.path.c_str(), // Path | |
54 | + session.interface.c_str(), // Interface | |
55 | + method // method | |
56 | + ); | |
57 | + | |
58 | + if(!msg.out) { | |
59 | + throw std::runtime_error("Can't create D-Bus Method Call"); | |
60 | + } | |
61 | + | |
62 | + } | |
63 | + | |
64 | + IPC::Request::~Request() { | |
65 | + if(msg.out) { | |
66 | + dbus_message_unref(msg.out); | |
67 | + } | |
68 | + if(msg.in) { | |
69 | + dbus_message_unref(msg.in); | |
70 | + } | |
71 | + } | |
72 | + | |
73 | + IPC::Request & IPC::Request::call() { | |
74 | + | |
75 | + if(msg.in) { | |
76 | + dbus_message_unref(msg.in); | |
77 | + msg.in = nullptr; | |
78 | + } | |
79 | + | |
80 | + DBusError error; | |
81 | + dbus_error_init(&error); | |
82 | + this->msg.in = dbus_connection_send_with_reply_and_block(this->conn,this->msg.out,10000,&error); | |
83 | + | |
84 | + if(!this->msg.in) { | |
85 | + string message = error.message; | |
86 | + dbus_error_free(&error); | |
87 | + throw std::runtime_error(message.c_str()); | |
88 | + } | |
89 | + | |
90 | + return *this; | |
91 | + | |
92 | + } | |
93 | + | |
94 | + IPC::Request & IPC::Request::push(const char *arg) { | |
95 | + dbus_message_append_args(this->msg.out,DBUS_TYPE_STRING,&arg,DBUS_TYPE_INVALID); | |
96 | + return *this; | |
97 | + } | |
98 | + | |
99 | + } | |
100 | + | |
101 | + | ... | ... |
src/lib3270++/private.h
... | ... | @@ -232,14 +232,17 @@ |
232 | 232 | /// @brief Compacta array de argumentos em um bloco de dados. |
233 | 233 | static DWORD pack(std::vector<DataBlock *> &args, uint8_t * outBuffer, size_t szBuffer); |
234 | 234 | #else |
235 | - | |
236 | - DBusMessage * msg; | |
235 | + struct { | |
236 | + DBusMessage * in; | |
237 | + DBusMessage * out; | |
238 | + } msg; | |
237 | 239 | DBusConnection * conn; |
238 | 240 | |
239 | 241 | #endif // _WIN32 |
240 | 242 | |
241 | 243 | public: |
242 | 244 | Request(Session &session, const char *method); |
245 | + ~Request(); | |
243 | 246 | |
244 | 247 | Request & call(); |
245 | 248 | Request & push(const char *arg); |
... | ... | @@ -257,8 +260,9 @@ |
257 | 260 | #else |
258 | 261 | |
259 | 262 | DBusConnection * conn; |
260 | - std::string name; ///< @brief D-Bus Object name. | |
261 | - std::string path; ///< @brief D-Bus Object path. | |
263 | + std::string name; ///< @brief D-Bus Object name. | |
264 | + std::string path; ///< @brief D-Bus Object path. | |
265 | + std::string interface; ///< @brief D-Bus interface. | |
262 | 266 | |
263 | 267 | #endif // _WIN32 |
264 | 268 | ... | ... |