summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-05-18 19:19:49 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-05-18 19:19:49 +0000
commitaab0210d3c33296381cff7f988a30f75f058ae8c (patch)
treeabc7c0b3f67c8d030006c8e9a0861d55e28d6471
parent3568bdd8c1a21ba36e9baf0b1485a1960d1c566b (diff)
serial: remove the entry from the persistent storage when RemovePort is called
-rw-r--r--serial/manager.c12
-rw-r--r--serial/port.c14
-rw-r--r--serial/storage.c15
-rw-r--r--serial/storage.h1
4 files changed, 38 insertions, 4 deletions
diff --git a/serial/manager.c b/serial/manager.c
index b860659d..0cf46a3d 100644
--- a/serial/manager.c
+++ b/serial/manager.c
@@ -860,8 +860,10 @@ done:
static DBusHandlerResult remove_port(DBusConnection *conn,
DBusMessage *msg, void *data)
{
+ struct rfcomm_dev_info di;
DBusError derr;
const char *path;
+ int16_t id;
dbus_error_init(&derr);
if (!dbus_message_get_args(msg, &derr,
@@ -872,8 +874,16 @@ static DBusHandlerResult remove_port(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}
+ if (sscanf(path, SERIAL_MANAGER_PATH"/rfcomm%hd", &id) != 1)
+ return err_does_not_exist(conn, msg, "Invalid RFCOMM node");
+
+ di.id = id;
+ if (ioctl(rfcomm_ctl, RFCOMMGETDEVINFO, &di) < 0)
+ return err_does_not_exist(conn, msg, "Invalid RFCOMM node");
+ port_delete(&di.src, &di.dst, id);
+
if (port_unregister(path) < 0)
- return err_does_not_exist(conn, msg, "path doesn't exist");
+ return err_does_not_exist(conn, msg, "Invalid RFCOMM node");
return send_message_and_unref(conn,
dbus_message_new_method_return(msg));
diff --git a/serial/port.c b/serial/port.c
index 3c6980ce..fac0d5f7 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -196,9 +196,17 @@ static gboolean rfcomm_disconnect_cb(GIOChannel *io,
static void port_handler_unregister(DBusConnection *conn, void *data)
{
struct rfcomm_node *node = data;
+ char path[MAX_PATH_LENGTH];
+ const char *ppath = path;
debug("Unregistered serial port: %s", node->name);
+ snprintf(path, MAX_PATH_LENGTH, "%s/rfcomm%d", SERIAL_MANAGER_PATH, node->id);
+ dbus_connection_emit_signal(conn, SERIAL_MANAGER_PATH,
+ SERIAL_MANAGER_INTERFACE, "PortRemoved" ,
+ DBUS_TYPE_STRING, &ppath,
+ DBUS_TYPE_INVALID);
+
bound_nodes = g_slist_remove(bound_nodes, node);
rfcomm_node_free(node);
}
@@ -289,12 +297,12 @@ int port_unregister(const char *path)
{
struct rfcomm_node *node;
char name[16];
- int id;
+ int16_t id;
- if (sscanf(path, SERIAL_MANAGER_PATH"/rfcomm%d", &id) != 1)
+ if (sscanf(path, SERIAL_MANAGER_PATH"/rfcomm%hd", &id) != 1)
return -ENOENT;
- snprintf(name, sizeof(name), "/dev/rfcomm%d", id);
+ snprintf(name, sizeof(name), "/dev/rfcomm%hd", id);
node = find_node_by_name(bound_nodes, name);
if (!node)
return -ENOENT;
diff --git a/serial/storage.c b/serial/storage.c
index 89d156e5..e6d73827 100644
--- a/serial/storage.c
+++ b/serial/storage.c
@@ -38,6 +38,21 @@
#include "storage.h"
+int port_delete(bdaddr_t *src, bdaddr_t *dst, int id)
+{
+ char filename[PATH_MAX + 1];
+ char src_addr[18], dst_addr[18];
+ char key[32];
+
+ ba2str(src, src_addr);
+ ba2str(dst, dst_addr);
+
+ create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "serial");
+ snprintf(key, sizeof(key), "%s#%d", dst_addr, id);
+
+ return textfile_del(filename, key);
+}
+
int port_store(bdaddr_t *src, bdaddr_t *dst, int id,
uint8_t ch, const char *svcname)
{
diff --git a/serial/storage.h b/serial/storage.h
index 82512c90..2abdf0ce 100644
--- a/serial/storage.h
+++ b/serial/storage.h
@@ -21,5 +21,6 @@
*
*/
+int port_delete(bdaddr_t *src, bdaddr_t *dst, int id);
int port_store(bdaddr_t *src, bdaddr_t *dst, int id,
uint8_t ch, const char *svcname);