aboutsummaryrefslogtreecommitdiff
path: root/src/lib/include/gnunet_dbus_lib_method_context.h
blob: 27b57890d0ec6e763171d582fdc80ea339536589 (plain) (blame)
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
112
113
114
115
#ifndef GNUNET_DBUS_LIB_METHOD_CONTEXT_H
#define GNUNET_DBUS_LIB_METHOD_CONTEXT_H

#include <stdbool.h>

#include <dbus/dbus.h>

/**
 * An object of this type is passed to every function bound to a
 * GNUNET_DBUS_Method when it is called via DBus.
 */
struct GNUNET_DBUS_MethodContext
{
  /**
   * The client calling this method.
   */
  struct GNUNET_DBUS_Client *client;

  /**
   * The service that this method was called on. This is necessary as the
   * process might be running several DBus services all advertising the same
   * method.
   */
  struct GNUNET_DBUS_Service *service;
  
  /**
   * The object that this method was called on.
   */
  struct GNUNET_DBUS_Object *object;
  
  /**
   * The interface that this method was called on.
   */
  struct GNUNET_DBUS_Interface *interface;

  /**
   * The method that was called. Necessary because multiple DBus methods may be
   * bound to a single internal function.
   */
  struct GNUNET_DBUS_Method *method;

  /**
   * The method-call message sent by the client.
   */
  DBusMessage *message;

  /**
   * Whether the client expects a reply to this message. If the user of this
   * API tries to send a reply to the client via this
   * GNUNET_DBUS_MethodContext, the reply will not be sent if this flag is
   * unset.
   */
  bool expects_reply;

  /**
   * Whether we have already replied to this DBus method-call message.
   */
  bool replied;
  
  /**
   * The reference count of the GNUNET_DBUS_MethodContext.
   */
  unsigned ref_count;
};

/**
 * Create a GNUNET_DBUS_MethodContext from the supplied DBus method-call
 * message. The message must have been sent by the given client to the given
 * service+object+interface+method. This will increase the reference count of
 * the DBusMessage but not the other supplied objects.
 */
struct GNUNET_DBUS_MethodContext *
GNUNET_DBUS_method_context_create (
    struct GNUNET_DBUS_Client *client,
    struct GNUNET_DBUS_Service *service,
    struct GNUNET_DBUS_Object *object,
    struct GNUNET_DBUS_Interface *interface,
    struct GNUNET_DBUS_Method *method,
    DBusMessage *message);

/**
 * Increase the reference count of this GNUNET_DBUS_MethodContext by one.
 */
void
GNUNET_DBUS_method_context_ref (
    struct GNUNET_DBUS_MethodContext *mc);

/**
 * Decrease the reference count of this GNUNET_DBUS_MethodContext by one. Will
 * free the method context if the reference count reaches zero.
 */
void
GNUNET_DBUS_method_context_unref (
    struct GNUNET_DBUS_MethodContext *mc);

/**
 * Send a DBusMessage in reply to the method call associated with this method
 * context. The DBusMessage should have been created using
 * GNUNET_DBUS_method_context_create_reply.
 */
void
GNUNET_DBUS_method_context_send_reply (
    struct GNUNET_DBUS_MethodContext *mc,
    DBusMessage *reply);

/**
 * Create a DBusMessage in reply to this method call. After populating the
 * message with data, send it using GNUNET_DBUS_method_context_send_reply.
 */
DBusMessage *
GNUNET_DBUS_method_context_create_reply (
    struct GNUNET_DBUS_MethodContext *mc);

#endif