From: Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
Subject: [PATCH 06/32] Add delete instance petition
Date: Fri, 4 Jun 2010 10:29:59 +0200 [thread overview]
Message-ID: <1275640225-4186-7-git-send-email-santoscadenas@gmail.com> (raw)
In-Reply-To: <1275640225-4186-6-git-send-email-santoscadenas@gmail.com>
---
health/hdp.c | 64 +++++++++++++++++++++++++++++++++++++++++++----------
health/hdp_util.c | 35 +++++++++++++++++++++++++++-
2 files changed, 85 insertions(+), 14 deletions(-)
diff --git a/health/hdp.c b/health/hdp.c
index 5b09ab3..8d90588 100644
--- a/health/hdp.c
+++ b/health/hdp.c
@@ -34,7 +34,6 @@
#include "../src/dbus-common.h"
#define HEALTH_MANAGER_INTERFACE "org.bluez.HealthAdapter"
-#define HEALTH_INSTANCE_INTERFACE "org.bluez.HealthInstance"
#define HEALTH_DEVICE "org.bluez.HealthDevice"
static GSList *adapters = NULL;
@@ -147,6 +146,16 @@ static struct hdp_device *create_health_device(DBusConnection *conn,
return dev;
}
+static int hdp_instance_idcmp(gconstpointer instance, gconstpointer p)
+{
+ const struct hdp_instance *hdpi = instance;
+ const uint32_t *id = p;
+
+ if (hdpi->id == *id)
+ return 0;
+ return -1;
+}
+
static void hdp_set_instance_id(struct hdp_instance *hdpi)
{
struct hdp_adapter *adapter = hdpi->adapter;
@@ -187,24 +196,20 @@ static DBusMessage *hdp_create_instance(DBusConnection *conn,
hdpi->aname = g_strdup(name);
hdpi->apath = g_strdup(path);
hdpi->config = config;
- if (!config->svc_dsc)
- config->svc_dsc = g_strdup(HDP_SERVICE_DSC);
- if (!config->svc_name)
- config->svc_name = g_strdup(HDP_SERVICE_NAME);
- if (!config->svc_prov)
- config->svc_prov = g_strdup(HDP_SERVICE_PROVIDER);
hdp_set_instance_id(hdpi);
/* TODO: Create mcap instance */
if (!hdp_register_sdp_record(hdpi)) {
+ hdp_instance_free(hdpi);
return g_dbus_create_error(msg, ERROR_INTERFACE ".HealthError",
"Session can't be registered");
}
- return g_dbus_create_error(msg,
- ERROR_INTERFACE ".HealthError",
- "Incomplete call yet");
+ adapter->instances = g_slist_prepend(adapter->instances, hdpi);
+ info("HDP instance created with path %d", hdpi->id);
+ return g_dbus_create_reply(msg, DBUS_TYPE_UINT32, &hdpi->id,
+ DBUS_TYPE_INVALID);
error:
if (err) {
reply = g_dbus_create_error(msg,
@@ -218,16 +223,51 @@ error:
return reply;
}
+static DBusMessage *hdp_delete_instance(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ struct hdp_adapter *adapter = user_data;
+ struct hdp_instance *hdpi;
+ GSList *l;
+ const char *name;
+ uint32_t id;
+
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &id,
+ DBUS_TYPE_INVALID))
+ return g_dbus_create_error(msg,
+ ERROR_INTERFACE ".InvalidArguments",
+ "Invalid arguments in method call");
+
+ l = g_slist_find_custom(adapter->instances, &id, hdp_instance_idcmp);
+ if (!l)
+ return g_dbus_create_error(msg,
+ ERROR_INTERFACE ".NotFound",
+ "The session was not found");
+
+ name = dbus_message_get_sender(msg);
+ hdpi = l->data;
+ if (g_strcmp0(hdpi->aname, name) != 0)
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".HealthError",
+ "This session was created by an other process");
+ adapter->instances = g_slist_remove(adapter->instances, hdpi);
+ hdp_instance_free(hdpi);
+
+ DBG("Stop HDP Session %d deleted", id);
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
static GDBusMethodTable hdp_methods[] = {
{ "CreateInstance", "oa{sv}", "u", hdp_create_instance },
+ { "DeleteInstance", "u", "", hdp_delete_instance },
{ NULL }
};
void hdp_delete_instance_iter(gpointer data, gpointer user_data)
{
- /* struct hdp_instance *hdpi = data; */
+ struct hdp_instance *hdpi = data;
- /* TODO: Create a free function */
+ hdp_instance_free(hdpi);
}
static void hdp_path_unregister(void *data)
diff --git a/health/hdp_util.c b/health/hdp_util.c
index 96fa737..31a0248 100644
--- a/health/hdp_util.c
+++ b/health/hdp_util.c
@@ -109,6 +109,28 @@ static void free_config(struct hdp_config *config)
g_free(config);
}
+void hdp_instance_free(struct hdp_instance *hdpi)
+{
+ DBG("HDP instance %d is deleted", hdpi->id);
+ /* TODO: Complete this part */
+ /*
+ g_slist_foreach(hdpi->devices, hdp_device_unregister, NULL);
+ g_slist_free(hdpi->devices);
+ hdpi->devices = NULL;
+ */
+
+ if (hdpi->sdp_handler)
+ remove_record_from_server(hdpi->sdp_handler);
+ /* TODO: stop mcap instance */
+ if (hdpi->apath)
+ g_free(hdpi->apath);
+ if (hdpi->aname)
+ g_free(hdpi->aname);
+ if (hdpi->config)
+ free_config(hdpi->config);
+ g_free(hdpi);
+}
+
static gboolean parse_dict_entry(struct dict_entry_func dict_context[],
DBusMessageIter *iter,
GError **err,
@@ -441,8 +463,17 @@ struct hdp_config *hdp_get_config(DBusMessageIter *iter, GError **err)
"\"data_spec\" and \"end_point\" should be set or not");
goto error;
}
- if (!config->ds_present)
- goto error;
+ if (!config->ds_present) {
+ g_free(config);
+ return NULL;
+ }
+ if (!config->svc_dsc)
+ config->svc_dsc = g_strdup(HDP_SERVICE_DSC);
+ if (!config->svc_name)
+ config->svc_name = g_strdup(HDP_SERVICE_NAME);
+ if (!config->svc_prov)
+ config->svc_prov = g_strdup(HDP_SERVICE_PROVIDER);
+
DBG("config->data_spec %d", config->data_spec);
g_slist_foreach(config->supp_fts, print_features, NULL);
return config;
--
1.6.3.3
next prev parent reply other threads:[~2010-06-04 8:29 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-04 8:29 [PATCH 00/32] Health Device Prifile (HDP) -- updated Jose Antonio Santos Cadenas
2010-06-04 8:29 ` [PATCH 01/32] Add Health api description Jose Antonio Santos Cadenas
2010-06-04 8:29 ` [PATCH 02/32] Initial support for HDP Jose Antonio Santos Cadenas
2010-06-04 8:29 ` [PATCH 03/32] Add functions to resiger health instances in SDP Jose Antonio Santos Cadenas
2010-06-04 8:29 ` [PATCH 04/32] Initial support for hdp_device_drivers Jose Antonio Santos Cadenas
2010-06-04 8:29 ` [PATCH 05/32] Register healt_driver interfaces in d-bus Jose Antonio Santos Cadenas
2010-06-04 8:29 ` Jose Antonio Santos Cadenas [this message]
2010-06-04 8:30 ` [PATCH 07/32] Add watcher to control client disconections to delete hdp instance Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 08/32] Work in getting remote SDP records Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 09/32] Adds functions to get remote suported features from its SDP record Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 10/32] Insert end_point in array returned by get_health_instances Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 11/32] Initial support for connecting instances Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 12/32] Complete the response dictionary in GetHealthInstances response Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 13/32] Implement connection of health instances Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 14/32] Manage mcap instances Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 15/32] Implement connect MCL callback in health instances connection Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 16/32] Register Health link int the bus when MCL is connected Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 17/32] Analize remote record looking for psm Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 18/32] Unify the creation of health links Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 19/32] Remove hdp_device pointer from health link struct Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 20/32] Release health link resources Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 21/32] Manage mcap disconnections and reconnections Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 22/32] Initial work for disconnecting health links Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 23/32] Avoid multiple links with the same device Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 24/32] Disconnect health link petition Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 25/32] Create new structure to manage data channels in HDP Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 26/32] Implement connect data channel callback Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 27/32] Change function name when retreiving remote SDP records Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 28/32] Changed HEALTH_MANAGER_INTERFACE to HEALTH_MANAGER Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 29/32] Call the agent when a new Health Link is created Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 30/32] Add a test that creates a simple health agent Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 31/32] Send MCL disconnect callback to agents Jose Antonio Santos Cadenas
2010-06-04 8:30 ` [PATCH 32/32] Add support for mcl reconnections Jose Antonio Santos Cadenas
-- strict thread matches above, loose matches on Subject: below --
2010-06-02 13:18 [PATCH 00/32] Health device profile (HDP) Jose Antonio Santos Cadenas
2010-06-02 13:18 ` [PATCH 01/32] Add Health api description Jose Antonio Santos Cadenas
2010-06-02 13:18 ` [PATCH 02/32] Initial support for HDP Jose Antonio Santos Cadenas
2010-06-02 13:18 ` [PATCH 03/32] Add functions to resiger health instances in SDP Jose Antonio Santos Cadenas
2010-06-02 13:19 ` [PATCH 04/32] Initial support for hdp_device_drivers Jose Antonio Santos Cadenas
2010-06-02 13:19 ` [PATCH 05/32] Register healt_driver interfaces in d-bus Jose Antonio Santos Cadenas
2010-06-02 13:19 ` [PATCH 06/32] Add delete instance petition Jose Antonio Santos Cadenas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1275640225-4186-7-git-send-email-santoscadenas@gmail.com \
--to=santoscadenas@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).