summaryrefslogtreecommitdiffstats
path: root/binding/bluetooth-map-api.h
blob: d5b20a1321651f0b0532404ce8c4c58ef9023b06 (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
/*
 * Copyright 2019 Konsulko Group
 * Author: Matt Ranostay <matt.ranostay@konsulko.com>
 * Author: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef BLUETOOTH_MAP_API_H
#define BLUETOOTH_MAP_API_H

#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <glib.h>
#include <json-c/json.h>

#define BLUEZ_OBEX_SERVICE                 	"org.bluez.obex"
#define BLUEZ_OBEX_CLIENT_INTERFACE		BLUEZ_OBEX_SERVICE ".Client1"
#define BLUEZ_OBEX_SESSION_INTERFACE		BLUEZ_OBEX_SERVICE ".Session1"
#define BLUEZ_OBEX_TRANSFER_INTERFACE		BLUEZ_OBEX_SERVICE ".Transfer1"
#define BLUEZ_OBEX_MESSAGE_INTERFACE		BLUEZ_OBEX_SERVICE ".Message1"
#define BLUEZ_OBEX_MESSAGEACCESS_INTERFACE	BLUEZ_OBEX_SERVICE ".MessageAccess1"

#define BLUEZ_OBJECT_PATH			"/"
#define BLUEZ_OBEX_PATH				"/org/bluez/obex"

#define BLUEZ_ERRMSG(error) \
     (error ? error->message : "unspecified")

#define FREEDESKTOP_INTROSPECT			"org.freedesktop.DBus.Introspectable"
#define FREEDESKTOP_PROPERTIES			"org.freedesktop.DBus.Properties"
#define FREEDESKTOP_OBJECTMANAGER		"org.freedesktop.DBus.ObjectManager"

#define DBUS_REPLY_TIMEOUT			(120 * 1000)
#define DBUS_REPLY_TIMEOUT_SHORT		(10 * 1000)

#define	BLUEZ_AT_OBJECT				"object"
#define BLUEZ_AT_CLIENT				"client"
#define BLUEZ_AT_SESSION			"session"
#define BLUEZ_AT_TRANSFER			"transfer"
#define BLUEZ_AT_MESSAGE			"message"
#define BLUEZ_AT_MESSAGEACCESS			"message-access"

struct map_state;

struct map_state *map_get_userdata(afb_req_t request);

struct call_work *call_work_create_unlocked(struct map_state *ns,
		const char *access_type, const char *type_arg,
		const char *method, const char *bluez_method,
		GError **error);

void call_work_destroy_unlocked(struct call_work *cw);

void call_work_lock(struct map_state *ns);

void call_work_unlock(struct map_state *ns);

struct call_work *call_work_lookup_unlocked(
		struct map_state *ns,
		const char *access_type, const char *type_arg,
		const char *method);

const struct property_info *bluez_get_property_info(
		const char *access_type, GError **error);

gboolean bluez_property_dbus2json(const char *access_type,
		json_object *jprop, const gchar *key, GVariant *var,
		gboolean *is_config,
		GError **error);

GVariant *bluez_call(struct map_state *ns,
		const char *access_type, const char *type_arg,
		const char *method, GVariant *params, GError **error);

json_object *bluez_get_properties(struct map_state *ns,
		const char *access_type, const char *path,
		GError **error);

json_object *bluez_get_property(struct map_state *ns,
		const char *access_type, const char *type_arg,
		gboolean is_json_name, const char *name, GError **error);

gboolean bluez_set_property(struct map_state *ns,
		const char *access_type, const char *type_arg,
		gboolean is_json_name, const char *name, json_object *jval,
		GError **error);

gboolean bluetooth_autoconnect(gpointer data);

/* convenience access methods */
static inline gboolean session_property_dbus2json(json_object *jprop,
		const gchar *key, GVariant *var, gboolean *is_config,
		GError **error)
{
	return bluez_property_dbus2json(BLUEZ_AT_SESSION,
			jprop, key, var, is_config, error);
}

static inline gboolean transfer_property_dbus2json(json_object *jprop,
		const gchar *key, GVariant *var, gboolean *is_config,
		GError **error)
{
	return bluez_property_dbus2json(BLUEZ_AT_TRANSFER,
			jprop, key, var, is_config, error);
}

static inline json_object *object_properties(struct map_state *ns,
		GError **error)
{
	return bluez_get_properties(ns,
			BLUEZ_AT_OBJECT, BLUEZ_OBJECT_PATH, error);
}

struct bluez_pending_work {
	struct map_state *ns;
	void *user_data;
	GCancellable *cancel;
	void (*callback)(void *user_data, GVariant *result, GError **error);
};

void bluez_cancel_call(struct map_state *ns,
		struct bluez_pending_work *cpw);

struct bluez_pending_work *
bluez_call_async(struct map_state *ns,
		const char *access_type, const char *type_arg,
		const char *method, GVariant *params, GError **error,
		void (*callback)(void *user_data, GVariant *result, GError **error),
		void *user_data);

void bluez_decode_call_error(struct map_state *ns,
		const char *access_type, const char *type_arg,
		const char *method,
		GError **error);

#endif /* BLUETOOTH_MAP_API_H */