Upgrade ofono to 1.2
[profile/ivi/ofono.git] / dundee / dundee.h
1 /*
2  *
3  *  oFono - Open Source Telephony
4  *
5  *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
6  *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License version 2 as
10  *  published by the Free Software Foundation.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  */
22
23 #include <glib.h>
24
25 #define OFONO_API_SUBJECT_TO_CHANGE
26
27 #include <ofono/types.h>
28
29 void __dundee_exit(void);
30
31 enum dundee_error_type {
32         DUNDEE_ERROR_TYPE_NO_ERROR = 0,
33         DUNDEE_ERROR_TYPE_FAILURE,
34 };
35
36 struct dundee_error {
37         enum dundee_error_type type;
38         int error;
39 };
40
41 struct cb_data {
42         void *cb;
43         void *data;
44         void *user;
45 };
46
47 static inline struct cb_data *cb_data_new(void *cb, void *data)
48 {
49         struct cb_data *ret;
50
51         ret = g_new0(struct cb_data, 1);
52         ret->cb = cb;
53         ret->data = data;
54
55         return ret;
56 }
57
58 #define CALLBACK_WITH_FAILURE(cb, args...)              \
59         do {                                            \
60                 struct dundee_error cb_e;               \
61                 cb_e.type = DUNDEE_ERROR_TYPE_FAILURE;  \
62                 cb_e.error = 0;                         \
63                                                         \
64                 cb(&cb_e, ##args);                      \
65         } while (0)                                     \
66
67 #define CALLBACK_WITH_SUCCESS(f, args...)               \
68         do {                                            \
69                 struct dundee_error e;                  \
70                 e.type = DUNDEE_ERROR_TYPE_NO_ERROR;    \
71                 e.error = 0;                            \
72                 f(&e, ##args);                          \
73         } while(0)                                      \
74
75 #include <ofono/log.h>
76
77 int __ofono_log_init(const char *program, const char *debug,
78                                         ofono_bool_t detach);
79 void __ofono_log_cleanup(void);
80 void __ofono_log_enable(struct ofono_debug_desc *start,
81                                         struct ofono_debug_desc *stop);
82
83 #include <ofono/dbus.h>
84
85 #define DUNDEE_SERVICE                  "org.ofono.dundee"
86 #define DUNDEE_MANAGER_INTERFACE        "org.ofono.dundee.Manager"
87 #define DUNDEE_DEVICE_INTERFACE         "org.ofono.dundee.Device"
88 #define DUNDEE_MANAGER_PATH             "/"
89
90 int __ofono_dbus_init(DBusConnection *conn);
91 void __ofono_dbus_cleanup(void);
92
93 void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply);
94
95 DBusMessage *__dundee_error_invalid_args(DBusMessage *msg);
96 DBusMessage *__dundee_error_failed(DBusMessage *msg);
97 DBusMessage *__dundee_error_timed_out(DBusMessage *msg);
98
99
100 int __dundee_manager_init(void);
101 void __dundee_manager_cleanup(void);
102
103
104 struct dundee_device;
105
106 int __dundee_device_init(void);
107 void __dundee_device_cleanup(void);
108 void __dundee_device_shutdown(void);
109
110 typedef void (*dundee_device_connect_cb_t)(const struct dundee_error *error,
111                                                 int fd, void *data);
112 typedef void (*dundee_device_disconnect_cb_t)(const struct dundee_error *error,
113                                                 void *data);
114
115 struct dundee_device_driver {
116         const char *name;
117
118         /* Connect and dial */
119         void (*connect)(struct dundee_device *device,
120                         dundee_device_connect_cb_t cb, void *data);
121
122         /* Hangup and disconnect */
123         void (*disconnect)(struct dundee_device *device,
124                         dundee_device_disconnect_cb_t cb, void *data);
125 };
126
127 struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
128 int dundee_device_register(struct dundee_device *device);
129 void dundee_device_unregister(struct dundee_device *device);
130
131 void dundee_device_set_data(struct dundee_device *device, void *data);
132 void *dundee_device_get_data(struct dundee_device *device);
133
134 int dundee_device_set_name(struct dundee_device *device, const char *name);
135
136 typedef void (*dundee_device_foreach_func)(struct dundee_device *device,
137                                                 void *data);
138 void __dundee_device_foreach(dundee_device_foreach_func cb, void *userdata);
139
140 const char *__dundee_device_get_path(struct dundee_device *device);
141 void __dundee_device_append_properties(struct dundee_device *device,
142                                         DBusMessageIter *dict);
143
144 int __dundee_bluetooth_init(void);
145 void  __dundee_bluetooth_cleanup(void);