summaryrefslogtreecommitdiffstats
path: root/dundee/dundee.h
blob: 1af56ca2a2a84e70646541767a979da0fab6b240 (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 *
 *  oFono - Open Source Telephony
 *
 *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
 *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
 *
 *  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 St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include <glib.h>

#define OFONO_API_SUBJECT_TO_CHANGE

#include <ofono/types.h>

#define DUN_VERSION_1_2 0x0102

void __dundee_exit(void);

enum dundee_error_type {
	DUNDEE_ERROR_TYPE_NO_ERROR = 0,
	DUNDEE_ERROR_TYPE_FAILURE,
};

struct dundee_error {
	enum dundee_error_type type;
	int error;
};

struct cb_data {
	void *cb;
	void *data;
	void *user;
};

static inline struct cb_data *cb_data_new(void *cb, void *data)
{
	struct cb_data *ret;

	ret = g_new0(struct cb_data, 1);
	ret->cb = cb;
	ret->data = data;

	return ret;
}

#define CALLBACK_WITH_FAILURE(cb, args...)		\
	do {						\
		struct dundee_error cb_e;		\
		cb_e.type = DUNDEE_ERROR_TYPE_FAILURE;	\
		cb_e.error = 0;				\
							\
		cb(&cb_e, ##args);			\
	} while (0)					\

#define CALLBACK_WITH_SUCCESS(f, args...)		\
	do {						\
		struct dundee_error e;			\
		e.type = DUNDEE_ERROR_TYPE_NO_ERROR;	\
		e.error = 0;				\
		f(&e, ##args);				\
	} while(0)					\

#include <ofono/log.h>

int __ofono_log_init(const char *program, const char *debug,
					ofono_bool_t detach);
void __ofono_log_cleanup(void);
void __ofono_log_enable(struct ofono_debug_desc *start,
					struct ofono_debug_desc *stop);

#include <ofono/dbus.h>

#define DUNDEE_SERVICE			"org.ofono.dundee"
#define DUNDEE_MANAGER_INTERFACE	"org.ofono.dundee.Manager"
#define DUNDEE_DEVICE_INTERFACE		"org.ofono.dundee.Device"
#define DUNDEE_MANAGER_PATH		"/"

int __ofono_dbus_init(DBusConnection *conn);
void __ofono_dbus_cleanup(void);

void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply);

DBusMessage *__dundee_error_invalid_args(DBusMessage *msg);
DBusMessage *__dundee_error_failed(DBusMessage *msg);
DBusMessage *__dundee_error_in_progress(DBusMessage *msg);
DBusMessage *__dundee_error_timed_out(DBusMessage *msg);


int __dundee_manager_init(void);
void __dundee_manager_cleanup(void);


struct dundee_device;

int __dundee_device_init(void);
void __dundee_device_cleanup(void);
void __dundee_device_shutdown(void);

typedef void (*dundee_device_connect_cb_t)(const struct dundee_error *error,
						int fd, void *data);
typedef void (*dundee_device_disconnect_cb_t)(const struct dundee_error *error,
						void *data);

struct dundee_device_driver {
	const char *name;

	/* Connect and dial */
	void (*connect)(struct dundee_device *device,
			dundee_device_connect_cb_t cb, void *data);

	/* Hangup and disconnect */
	void (*disconnect)(struct dundee_device *device,
			dundee_device_disconnect_cb_t cb, void *data);
};

struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
int dundee_device_register(struct dundee_device *device);
void dundee_device_unregister(struct dundee_device *device);

void dundee_device_disconnect(const struct dundee_error *error,
						struct dundee_device *device);

void dundee_device_set_data(struct dundee_device *device, void *data);
void *dundee_device_get_data(struct dundee_device *device);

int dundee_device_set_name(struct dundee_device *device, const char *name);

typedef void (*dundee_device_foreach_func)(struct dundee_device *device,
						void *data);
void __dundee_device_foreach(dundee_device_foreach_func cb, void *userdata);

const char *__dundee_device_get_path(struct dundee_device *device);
void __dundee_device_append_properties(struct dundee_device *device,
					DBusMessageIter *dict);

int __dundee_bluetooth_init(void);
void  __dundee_bluetooth_cleanup(void);