File: dbus_pending_data.c

package info (click to toggle)
libnih 1.0.3-11
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,824 kB
  • sloc: ansic: 188,730; sh: 11,217; makefile: 1,117; yacc: 291; xml: 239; sed: 16
file content (103 lines) | stat: -rw-r--r-- 3,031 bytes parent folder | download | duplicates (6)
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
/* libnih
 *
 * dbus_pending_data.c - D-Bus pending call attached data
 *
 * Copyright © 2009 Scott James Remnant <scott@netsplit.com>.
 * Copyright © 2009 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */


#include <dbus/dbus.h>

#include <nih/macros.h>
#include <nih/alloc.h>
#include <nih/logging.h>

#include "dbus_pending_data.h"


/* Prototypes for static functions */
static int nih_dbus_pending_data_destroy (NihDBusPendingData *pending_data);


/**
 * nih_dbus_pending_data_new:
 * @parent: parent object for new structure,
 * @connection: D-Bus connection to associate with,
 * @message: D-Bus message to encapulsate.
 *
 * Creates a new D-Bus pending call data object allocated using
 * nih_alloc().  You would then use this as the data pointer of a
 * DBusPendingCall to be passed to the notify function.  The structure
 * contains a reference to the underlying D-Bus connection and details
 * about the handler functions and user data pointer.
 *
 * If @parent is not NULL, it should be a pointer to another object which
 * will be used as a parent for the returned object.  When all parents
 * of the returned object are freed, the returned object will also be
 * freed.
 *
 * Returns: new NihDBusPendingData structure, or NULL if insufficient memory.
 **/
NihDBusPendingData *
nih_dbus_pending_data_new (const void *        parent,
			   DBusConnection *    connection,
			   NihDBusReplyHandler handler,
			   NihDBusErrorHandler error_handler,
			   void *              data)
{
	NihDBusPendingData *pending_data;

	nih_assert (connection != NULL);
	nih_assert (error_handler != NULL);

	pending_data = nih_new (parent, NihDBusPendingData);
	if (! pending_data)
		return NULL;

	pending_data->connection = connection;
	dbus_connection_ref (pending_data->connection);

	pending_data->handler = handler;
	pending_data->error_handler = error_handler;
	pending_data->data = data;

	nih_alloc_set_destructor (pending_data, nih_dbus_pending_data_destroy);

	return pending_data;
}

/**
 * nih_dbus_pending_data_destroy:
 * @pending_data: pending data to be destroyed.
 *
 * Unreferences the attached D-Bus connection.
 *
 * Returns: zero
 **/
static int
nih_dbus_pending_data_destroy (NihDBusPendingData *pending_data)
{
	nih_assert (pending_data != NULL);

	dbus_connection_unref (pending_data->connection);

	return 0;
}