aboutsummaryrefslogtreecommitdiff
path: root/src/lib/include/gnunet_dbus_lib_method.h
blob: 9b47fcf977bdbb0de5a2fa12666ea4c58a7981ae (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
#ifndef GNUNET_DBUS_LIB_METHOD_H
#define GNUNET_DBUS_LIB_METHOD_H

#include <stdbool.h>

/**
 * Represents a DBus method. Consists of a linked-list of args and return args
 * of type GNUNET_DBUS_Arg.
 */
struct GNUNET_DBUS_Method;

#include "gnunet_dbus_lib_object.h"
#include "gnunet_dbus_lib_method_context.h"

/**
 * An iterable, double-linked list of GNUNET_DBUS_Method.
 */
struct GNUNET_DBUS_MethodIterator
{
  /* linked list */
  struct GNUNET_DBUS_MethodIterator *next;
  struct GNUNET_DBUS_MethodIterator *prev;

  struct GNUNET_DBUS_Method *method;
};

/**
 * Create a new GNUNET_DBUS_Method with the given name. The underlying_method
 * function will be called whenever this method is called via DBus. After
 * creating a method you need to populate it the args and return args before
 * binding it to an interface with GNUNET_DBUS_interface_add_method.
 */
struct GNUNET_DBUS_Method *
GNUNET_DBUS_method_create (
    const char *name,
    void (*underlying_method)(struct GNUNET_DBUS_MethodContext *mc));

/**
 * Increase the reference count of this GNUNET_DBUS_Method by one.
 */
void
GNUNET_DBUS_method_ref (
    struct GNUNET_DBUS_Method *method);

/**
 * Decrease the reference count of this GNUNET_DBUS_Method by one. Will free
 * the method if the reference count reaches zero.
 */
void
GNUNET_DBUS_method_unref (
    struct GNUNET_DBUS_Method *method);

/**
 * Add an argument with the given name and type signature to this method.
 */
void
GNUNET_DBUS_method_add_arg (
    struct GNUNET_DBUS_Method *method,
    const char *name,
    const char *signature);

/**
 * Add a return argument with the given name and type signature to this method.
 */
void
GNUNET_DBUS_method_add_return_arg (
    struct GNUNET_DBUS_Method *method,
    const char *name,
    const char *signature);

/**
 * Get the name of this method.
 */
const char *
GNUNET_DBUS_method_get_name (
    const struct GNUNET_DBUS_Method *method);

/**
 * Iterate over the arguments of this GNUNET_DBUS_Method.
 */
const struct GNUNET_DBUS_ArgIterator *
GNUNET_DBUS_method_iterate_args (
    const struct GNUNET_DBUS_Method *method);
/*
 * Iterate over the return arguments of this GNUNET_DBUS_Method.
 */
const struct GNUNET_DBUS_ArgIterator *
GNUNET_DBUS_method_iterate_return_args (
    const struct GNUNET_DBUS_Method *method);

/**
 * Call this method with the supplied GNUNET_DBUS_MethodContext.
 */
void
GNUNET_DBUS_method_call (
    struct GNUNET_DBUS_Method *method,
    struct GNUNET_DBUS_MethodContext *mc);

/**
 * Find a GNUNET_DBUS_Method with the given name in the supplied iterator.
 * Returns the position in the iterator of the method or NULL if it could not
 * be found.
 */
const struct GNUNET_DBUS_MethodIterator *
GNUNET_DBUS_method_find (
    const struct GNUNET_DBUS_MethodIterator *meth_it,
    const char *name);

#endif