stop.c
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
* (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
* aplicativos mainframe. Registro no INPI sob o nome G3270.
*
* Copyright (C) <2008> <Banco do Brasil S.A.>
*
* Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
* os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
* Free Software Foundation.
*
* Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
* GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
* A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
* obter mais detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
* programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
* St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Este programa está nomeado como - e possui - linhas de código.
*
* Referências:
*
* https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c
* https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c
*
* Contatos:
*
* perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
* erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
*
*/
#include "gobject.h"
#include <lib3270.h>
#include <ipc-glib.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
void ipc3270_release_object(ipc3270 *object) {
if(object->dbus.id) {
g_dbus_connection_unregister_object(object->dbus.connection,object->dbus.id);
}
if(object->dbus.name) {
debug("Releasing %s",object->dbus.name);
// https://dbus.freedesktop.org/doc/dbus-specification.html
GError *err = NULL;
GVariant * response =
g_dbus_connection_call_sync (
object->dbus.connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"ReleaseName",
g_variant_new ("(s)", object->dbus.name),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&err
);
if(err) {
g_message("Can't release \"%s\": %s",object->dbus.name,err->message);
g_error_free(err);
err = NULL;
} else if(response) {
guint32 reply = 0;
g_variant_get(response, "(u)", &reply);
g_variant_unref(response);
switch(reply)
{
case DBUS_RELEASE_NAME_REPLY_RELEASED:
// The caller has released his claim on the given name.
// Either the caller was the primary owner of the name, and the name is
// now unused or taken by somebody waiting in the queue for the name,
// or the caller was waiting in the queue for the name and has now been removed from the queue.
g_message("%s released",object->dbus.name);
break;
case DBUS_RELEASE_NAME_REPLY_NON_EXISTENT:
// The given name does not exist on this bus.
g_message("%s does not exist on this bus",object->dbus.name);
break;
case DBUS_RELEASE_NAME_REPLY_NOT_OWNER:
// The caller was not the primary owner of this name, and was also not waiting in the queue to own this name.
g_message("%s does not exist on this bus", object->dbus.name);
break;
default:
g_message("Unexpected response %u when removing %s",(unsigned int) reply, object->dbus.name);
}
}
g_free(object->dbus.name);
object->dbus.name = NULL;
}
}