aboutsummaryrefslogtreecommitdiff
path: root/src/lib/common/gnunet_dbus_lib_method_context.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/common/gnunet_dbus_lib_method_context.c')
-rw-r--r--src/lib/common/gnunet_dbus_lib_method_context.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/lib/common/gnunet_dbus_lib_method_context.c b/src/lib/common/gnunet_dbus_lib_method_context.c
new file mode 100644
index 0000000..f7a4bac
--- /dev/null
+++ b/src/lib/common/gnunet_dbus_lib_method_context.c
@@ -0,0 +1,83 @@
1#include "config.h"
2
3#include <dbus/dbus.h>
4
5#include <gnunet/platform.h>
6#include <gnunet/gnunet_common.h>
7#include <gnunet/gnunet_container_lib.h>
8
9#include "gnunet_dbus_lib.h"
10
11#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-method-context", __VA_ARGS__)
12
13struct GNUNET_DBUS_MethodContext *
14GNUNET_DBUS_method_context_create (
15 struct GNUNET_DBUS_Client *client,
16 struct GNUNET_DBUS_Service *service,
17 struct GNUNET_DBUS_Object *object,
18 struct GNUNET_DBUS_Interface *interface,
19 struct GNUNET_DBUS_Method *method,
20 DBusMessage *message)
21{
22 struct GNUNET_DBUS_MethodContext *ret = GNUNET_new (struct GNUNET_DBUS_MethodContext);
23 ret->client = client;
24 ret->service = service;
25 ret->object = object;
26 ret->interface = interface;
27 ret->method = method;
28 ret->message = message;
29 ret->expects_reply = ! dbus_message_get_no_reply (message);
30
31 ret->replied = false;
32 ret->ref_count = 1;
33 dbus_message_ref (message);
34
35 return ret;
36};
37
38void
39GNUNET_DBUS_method_context_ref (
40 struct GNUNET_DBUS_MethodContext *mc)
41{
42 mc->ref_count++;
43};
44
45void
46GNUNET_DBUS_method_context_unref (
47 struct GNUNET_DBUS_MethodContext *mc)
48{
49 if (0 == mc->ref_count)
50 {
51 LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unreference method context with ref count 0\n");
52 GNUNET_abort_ ();
53 };
54 if (0 == --(mc->ref_count))
55 {
56 dbus_message_unref (mc->message);
57 GNUNET_free (mc);
58 }
59};
60
61void
62GNUNET_DBUS_method_context_send_reply (
63 struct GNUNET_DBUS_MethodContext *mc,
64 DBusMessage *reply)
65{
66 if (! mc->expects_reply)
67 return;
68
69 GNUNET_DBUS_service_send (mc->service, reply);
70 dbus_message_unref (reply);
71};
72
73DBusMessage *
74GNUNET_DBUS_method_context_create_reply (
75 struct GNUNET_DBUS_MethodContext *mc)
76{
77 DBusMessage *ret = dbus_message_new_method_return (mc->message);
78 //GNUNET_DBUS_message_set_pretty (ret, GNUNET_DBUS_client_get_prefers_pretty_encodings (mc->client));
79 GNUNET_DBUS_message_set_pretty (ret, GNUNET_DBUS_message_get_pretty (mc->message));
80 return ret;
81}
82
83