#include <unistd.h>
#include <glib.h>
#include <gio/gio.h>
+#include <dirent.h>
#include <dbus/dbus.h>
+#include <gio/gunixfdlist.h>
#include "bluetooth.h"
#include "obex.h"
void *user_data;
};
+struct nap_connection_state_changed_cb_node {
+ bt_nap_connection_state_changed_cb cb;
+ void *user_data;
+};
+
static struct device_connect_cb_node *device_connect_node;
static struct device_disconnect_cb_node *device_disconnect_node;
static struct avrcp_repeat_mode_changed_node *avrcp_repeat_node;
static struct socket_connection_state_changed_cb_node
*socket_connection_state_node;
static struct hid_host_connection_state_changed_cb_node *hid_host_state_node;
+static struct nap_connection_state_changed_cb_node
+ *nap_connection_state_changed_node;
static gboolean generic_device_removed_set;
data->cb(shuffle_mode, data->user_data);
}
+static void bluez_nap_connection_changed(bool connected,
+ const char *remote_address,
+ const char *interface_name,
+ void *user_data)
+{
+ struct nap_connection_state_changed_cb_node *data =
+ user_data;
+
+ if (data->cb)
+ data->cb(connected, remote_address,
+ interface_name, data->user_data);
+}
+
static void bluez_set_data_received_changed(
unsigned int channel,
const char *data,
bluez_set_device_disconnect_changed_cb(
bluez_device_disconnect_changed,
device_disconnect_node);
+
+ if (nap_connection_state_changed_node)
+ bluez_set_nap_connection_state_cb(
+ bluez_nap_connection_changed,
+ nap_connection_state_changed_node);
}
static void setup_bluez_lib(void)
return BT_SUCCESS;
}
+int bt_nap_set_connection_state_changed_cb(
+ bt_nap_connection_state_changed_cb callback,
+ void *user_data)
+{
+ struct nap_connection_state_changed_cb_node *node_data;
+
+ DBG("");
+
+ if (callback == NULL)
+ return BT_ERROR_INVALID_PARAMETER;
+
+ if (nap_connection_state_changed_node) {
+ DBG("Powered state changed callback already set.");
+ return BT_ERROR_ALREADY_DONE;
+ }
+
+ node_data = g_new0(struct nap_connection_state_changed_cb_node, 1);
+ if (node_data == NULL) {
+ ERROR("no memory");
+ return BT_ERROR_OUT_OF_MEMORY;
+ }
+
+ node_data->cb = callback;
+ node_data->user_data = user_data;
+
+ nap_connection_state_changed_node = node_data;
+
+ _bt_update_bluetooth_callbacks();
+
+ return BT_SUCCESS;
+}
+
+int bt_nap_unset_connection_state_changed_cb(void)
+{
+ DBG("");
+
+ if (initialized == false)
+ return BT_ERROR_NOT_INITIALIZED;
+
+ if (default_adapter == NULL)
+ return BT_ERROR_ADAPTER_NOT_FOUND;
+
+ if (!adapter_name_node)
+ return BT_SUCCESS;
+
+ bluez_unset_nap_connection_state_cb();
+
+ g_free(nap_connection_state_changed_node);
+ nap_connection_state_changed_node = NULL;
+
+ return BT_SUCCESS;
+}
+
static gboolean spp_is_device_connected(const char *address)
{
struct spp_context *spp_ctx;
gpointer user_data);
void bluez_unset_avrcp_target_cb();
+typedef void (*bluez_nap_connection_state_cb_t)(bool connected,
+ const char *remote_address,
+ const char *interface_name,
+ gpointer user_data);
+void bluez_set_nap_connection_state_cb(
+ bluez_nap_connection_state_cb_t cb,
+ gpointer user_data);
+void bluez_unset_nap_connection_state_cb(void);
+
typedef void (*bluez_audio_state_cb_t)(int result,
gboolean connected,
const char *remote_address,
#define MEDIACONTROL_INTERFACE "org.bluez.MediaControl1"
#define DEVICE_INTERFACE "org.bluez.Device1"
#define NETWORK_INTERFACE "org.bluez.Network1"
+#define NETWORKSERVER_INTERFACES "org.bluez.NetworkServer1"
#define INPUT_INTERFACE "org.bluez.Input1"
#define AGENT_INTERFACE "org.bluez.AgentManager1"
#define PROFILE_INTERFACE "org.bluez.ProfileManager1"
char *object_path;
GDBusInterface *interface;
GDBusInterface *media_interface;
+ GDBusInterface *netserver_interface;
guint avrcp_registration_id;
GDBusProxy *proxy;
GDBusProxy *media_proxy;
+ GDBusProxy *netserver_proxy;
struct _bluez_object *parent;
struct _device_head *device_head;
bluez_adapter_powered_cb_t powered_cb;
static gpointer avrcp_target_cb_data;
static bluez_audio_state_cb_t audio_state_cb;
static gpointer audio_state_cb_data;
+static bluez_nap_connection_state_cb_t nap_connnection_state_cb;
+static gpointer nap_connnection_state_cb_data;
static device_connect_cb_t dev_connect_cb;
static gpointer dev_connect_data;
static device_disconnect_cb_t dev_disconnect_cb;
adapter->discoverable_timeout_cb_data);
}
+static void networkserver_on_signal(GDBusProxy *proxy,
+ gchar *sender_name,
+ gchar *signal_name,
+ GVariant *param,
+ gpointer user_data)
+{
+ gboolean connected;
+ gchar *device = NULL, *address = NULL;
+
+ DBG("sender_name = %s, signal_name = %s",
+ sender_name, signal_name);
+ if (strcasecmp(signal_name, "PeerConnected"))
+ connected = true;
+ else if (strcasecmp(signal_name, "PeerDisconnected"))
+ connected = false;
+ else
+ return;
+
+ g_variant_get(param, "(ss)", &device, &address);
+
+ if (nap_connnection_state_cb)
+ nap_connnection_state_cb(connected,
+ address, device,
+ nap_connnection_state_cb_data);
+
+ g_free(device);
+ g_free(address);
+}
+
static void adapter_properties_changed(GDBusProxy *proxy,
GVariant *changed_properties,
GStrv *invalidated_properties,
struct _bluez_adapter *adapter = user_data;
GDBusInterface *interface = data;
GDBusProxy *proxy = G_DBUS_PROXY(interface);
- const gchar *iface_name;
+ GDBusProxy *signal_proxy;
+ const gchar *iface_name, *adapter_path;
if (!adapter) {
WARN("no adapter");
DBG("adapter->media_proxy = proxy");
adapter->media_interface = interface;
adapter->media_proxy = proxy;
+ } else if (g_strcmp0(iface_name,
+ NETWORKSERVER_INTERFACES) == 0) {
+ adapter_path = g_dbus_proxy_get_object_path(proxy);
+
+ signal_proxy = g_dbus_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM, 0,
+ NULL,
+ BLUEZ_NAME,
+ adapter_path,
+ iface_name,
+ NULL, NULL);
+
+ DBG("adapter->netserver_proxy = proxy");
+
+ adapter->netserver_interface = interface;
+ adapter->netserver_proxy = signal_proxy;
+
+ g_signal_connect(signal_proxy, "g-signal",
+ G_CALLBACK(networkserver_on_signal),
+ NULL);
}
+
}
static GList *bluez_object_list;
avrcp_target_cb_data = NULL;
}
+void bluez_set_nap_connection_state_cb(
+ bluez_nap_connection_state_cb_t cb,
+ gpointer user_data)
+{
+ nap_connnection_state_cb = cb;
+ nap_connnection_state_cb_data = user_data;
+}
+
+void bluez_unset_nap_connection_state_cb(void)
+{
+ nap_connnection_state_cb = NULL;
+ nap_connnection_state_cb_data = NULL;
+}
+
void bluez_set_audio_state_cb(bluez_audio_state_cb_t cb,
gpointer user_data)
{
g_free(adapter->object_path);
g_object_unref(adapter->interface);
g_object_unref(adapter->media_proxy);
+ g_object_unref(adapter->media_interface);
+ g_object_unref(adapter->netserver_proxy);
+ g_object_unref(adapter->netserver_interface);
g_object_unref(adapter->proxy);
g_free(adapter);
return 0;
}
+void bt_nap_connection_state_changed_cb_test(bool connected,
+ const char *remote_address,
+ const char *interface_name,
+ void *user_data)
+{
+
+ DBG("");
+ DBG("connected = %d", connected);
+ DBG("remote_address = %s", remote_address);
+ DBG("interfaces_name = %s", interface_name);
+}
+
+static int nap_set_connection_state_changed_cb(const char *p1,
+ const char *p2)
+{
+ int ret;
+
+ ret = bt_nap_set_connection_state_changed_cb(
+ bt_nap_connection_state_changed_cb_test,
+ NULL);
+
+ DBG("ret = %d", ret);
+
+ return 0;
+}
+
+static int nap_unset_connection_state_changed_cb(const char *p1,
+ const char *p2)
+{
+ int ret;
+
+ ret = bt_nap_unset_connection_state_changed_cb();
+
+ DBG("ret = %d", ret);
+
+ return 0;
+}
+
void bt_hdp_connected_cb_test(int result, const char *remote_address,
const char *app_id, bt_hdp_channel_type_e type,
unsigned int channel, void *user_data)
{"nap_deactivate", nap_deactivate,
"Usage: nap_deactivate\n\tdeactivate NAP"},
+ {"nap_set_connection_state_changed_cb", nap_set_connection_state_changed_cb,
+ "Usage: nap_set_connection_state_changed_cb\n\tset nap conn cb"},
+
+ {"nap_unset_connection_state_changed_cb", nap_unset_connection_state_changed_cb,
+ "Usage: nap_unset_connection_state_changed_cb\n\tunset nap conn cb"},
+
{"hdo_set_connect_cb", hdp_set_connection_state_changed_cb,
"Usage: hdp_set_connect_cb\n\tset hdp conn cb"},