summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-07-29 16:32:10 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-07-29 16:44:17 -0500
commita2d310642f47e2d139538ec04d08945bbf2f887a (patch)
tree1573d6a286e4af9315b9537c0f885c354a75da69
parentea4886816f57e588009112127974b0c4552b12b0 (diff)
downloadofono-a2d310642f47e2d139538ec04d08945bbf2f887a.tar.bz2
Move ofono_modem functions to modem.c
-rw-r--r--src/manager.c101
-rw-r--r--src/modem.c80
-rw-r--r--src/ofono.h1
3 files changed, 85 insertions, 97 deletions
diff --git a/src/manager.c b/src/manager.c
index 92437a2c..9353eae6 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -32,102 +32,26 @@
#include "modem.h"
#include "driver.h"
-static GSList *g_modem_list = NULL;
-static int g_next_modem_id = 1;
-
-/* Clients only need to free *modems */
-static int modem_list(char ***modems)
-{
- GSList *l;
- int i;
- struct ofono_modem *modem;
-
- *modems = g_new0(char *, g_slist_length(g_modem_list) + 1);
-
- if (!*modems)
- return -1;
-
- for (l = g_modem_list, i = 0; l; l = l->next, i++) {
- modem = l->data;
-
- (*modems)[i] = modem->path;
- }
-
- return 0;
-}
-
GSList *ofono_manager_get_modems()
{
return g_modem_list;
}
-struct ofono_modem *ofono_modem_register(struct ofono_modem_attribute_ops *ops)
-{
- struct ofono_modem *modem;
- DBusConnection *conn = ofono_dbus_get_connection();
- char **modems;
-
- modem = modem_create(g_next_modem_id, ops);
-
- if (modem == NULL)
- return 0;
-
- ++g_next_modem_id;
-
- __ofono_history_probe_drivers(modem);
- g_modem_list = g_slist_prepend(g_modem_list, modem);
-
- if (modem_list(&modems) == 0) {
- ofono_dbus_signal_array_property_changed(conn,
- OFONO_MANAGER_PATH,
- OFONO_MANAGER_INTERFACE, "Modems",
- DBUS_TYPE_OBJECT_PATH, &modems);
-
- g_free(modems);
- }
-
- return modem;
-}
-
-int ofono_modem_unregister(struct ofono_modem *m)
-{
- struct ofono_modem *modem = m;
- DBusConnection *conn = ofono_dbus_get_connection();
- char **modems;
-
- if (modem == NULL)
- return -1;
-
- __ofono_history_remove_drivers(modem);
- modem_remove(modem);
-
- g_modem_list = g_slist_remove(g_modem_list, modem);
-
- if (modem_list(&modems) == 0) {
- ofono_dbus_signal_array_property_changed(conn,
- OFONO_MANAGER_PATH,
- OFONO_MANAGER_INTERFACE, "Modems",
- DBUS_TYPE_OBJECT_PATH, &modems);
-
- g_free(modems);
- }
-
- return 0;
-}
-
static DBusMessage *manager_get_properties(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessageIter iter;
DBusMessageIter dict;
DBusMessage *reply;
- char **modems;
+ const char **modems;
reply = dbus_message_new_method_return(msg);
if (!reply)
return NULL;
- if (modem_list(&modems) == -1)
+ modems = __ofono_modem_get_list();
+
+ if (!modems)
return NULL;
dbus_message_iter_init_append(reply, &iter);
@@ -174,25 +98,8 @@ int __ofono_manager_init()
void __ofono_manager_cleanup()
{
- GSList *l;
- struct ofono_modem *modem;
DBusConnection *conn = ofono_dbus_get_connection();
- /* Clean up in case plugins didn't unregister the modems */
- for (l = g_modem_list; l; l = l->next) {
- modem = l->data;
-
- if (!modem)
- continue;
-
- ofono_debug("plugin owning %s forgot to unregister, cleaning up",
- modem->path);
- modem_remove(modem);
- }
-
- g_slist_free(g_modem_list);
- g_modem_list = 0;
-
g_dbus_unregister_interface(conn, OFONO_MANAGER_PATH,
OFONO_MANAGER_INTERFACE);
}
diff --git a/src/modem.c b/src/modem.c
index b5a62bbe..e52a3987 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -41,6 +41,9 @@
#define ATTRIBUTE_QUERY_DELAY 0
+static GSList *g_modem_list = NULL;
+static int g_next_modem_id = 1;
+
struct ofono_modem_data {
char *manufacturer;
char *model;
@@ -444,3 +447,80 @@ void modem_remove(struct ofono_modem *modem)
g_free(path);
}
+
+/* Clients only need to free *modems */
+const char **__ofono_modem_get_list()
+{
+ GSList *l;
+ int i;
+ struct ofono_modem *modem;
+ const char **modems;
+
+ modems = g_new0(const char *, g_slist_length(g_modem_list) + 1);
+
+ for (l = g_modem_list, i = 0; l; l = l->next, i++) {
+ modem = l->data;
+
+ modems[i] = modem->path;
+ }
+
+ return modems;
+}
+
+struct ofono_modem *ofono_modem_register(struct ofono_modem_attribute_ops *ops)
+{
+ struct ofono_modem *modem;
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char **modems;
+
+ modem = modem_create(g_next_modem_id, ops);
+
+ if (modem == NULL)
+ return 0;
+
+ ++g_next_modem_id;
+
+ __ofono_history_probe_drivers(modem);
+ g_modem_list = g_slist_prepend(g_modem_list, modem);
+
+ modems = __ofono_modem_get_list();
+
+ if (modems) {
+ ofono_dbus_signal_array_property_changed(conn,
+ OFONO_MANAGER_PATH,
+ OFONO_MANAGER_INTERFACE, "Modems",
+ DBUS_TYPE_OBJECT_PATH, &modems);
+
+ g_free(modems);
+ }
+
+ return modem;
+}
+
+int ofono_modem_unregister(struct ofono_modem *m)
+{
+ struct ofono_modem *modem = m;
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char **modems;
+
+ if (modem == NULL)
+ return -1;
+
+ __ofono_history_remove_drivers(modem);
+ modem_remove(modem);
+
+ g_modem_list = g_slist_remove(g_modem_list, modem);
+
+ modems = __ofono_modem_get_list();
+
+ if (modems) {
+ ofono_dbus_signal_array_property_changed(conn,
+ OFONO_MANAGER_PATH,
+ OFONO_MANAGER_INTERFACE, "Modems",
+ DBUS_TYPE_OBJECT_PATH, &modems);
+
+ g_free(modems);
+ }
+
+ return 0;
+}
diff --git a/src/ofono.h b/src/ofono.h
index 905e808c..fa4b0d6d 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -27,6 +27,7 @@ int __ofono_manager_init();
void __ofono_manager_cleanup();
GSList *ofono_manager_get_modems();
+const char **__ofono_modem_get_list();
#include <ofono/log.h>