else if (ev.State == "initialized")
for (var index in callHandlers)
callHandlers[index].onInitialized(activeCall);
- }
+ } else if (ev.ModemAdded) {
+ tizen.account.addAccount(new tizen.Account(ev.ModemAdded, ev));
+ } else if (ev.ModemRemoved) {
+ tizen.account.deleteAccount(ev.ModemRemoved);
+ }
}
this.history = null;
}
}
+var __accountmanager = function() {
+ var listeners = new Array();
+ var accounts = new Array();
+
+ this.findServices = function(filter) {
+ /* brain dead matching, patches accepted */
+ var result = new Array();
+ if (accounts.length == 0)
+ return result;
+ try {
+ for (var i in accounts) {
+ var a = accounts[i];
+ for (var f in filter)
+ if (a[f] && a[f] == filter[f]) {
+ result.push(a);
+ continue;
+ }
+ }
+ } catch (err) {
+ console.log(err);
+ }
+
+ if (result.length == 0)
+ result.push(accounts[0]);
+
+ return result;
+ }
+ this.getAccountById = function(accountid) {
+ for (var i in accounts)
+ if (accounts[i].id == accountid)
+ return accounts[i];
+ return null;
+ }
+ this.deleteAccount = function(accountid) {
+ var l = new Array();
+ for (var i in accounts)
+ if (accountid != accounts[i].id)
+ l.push(accounts[i]);
+ accounts = l;
+
+ for (var i in listeners)
+ listeners[i].onAccountRemoved(accountid);
+ }
+ this.addAccount = function(account) {
+ accounts.push(account);
+ for (var i in listeners)
+ listeners[i].onAccountAdded(account);
+ }
+ this.addAccountListener = function(observer, errorCallback) {
+ listeners.push(observer);
+ return listeners.length;
+ }
+ this.removeAccountListener = function(handle) {
+ var l = new Array();
+ for (var i in listeners)
+ if (i != handle)
+ l.push(listeners[i]);
+ listeners = l;
+ }
+}
+
var __tizen = function() {
var application = null;
this.__defineGetter__("application", function() {
return call;
});
+ this.Account = function (accountId, accountProperties) {
+ var id = accountId;
+ var properties = accountProperties;
+ this.__defineGetter__("id", function() {
+ return id;
+ });
+ for (var p in properties) {
+ this.__defineGetter__(p, function() {
+ return properties[p];
+ });
+ }
+ }
+ var account = null;
+ this.__defineGetter__("account", function() {
+ if (account == null)
+ account = new __accountmanager();
+ return account;
+ });
}
var tizen = new __tizen();
}
break;
+ case LWS_CALLBACK_ESTABLISHED:
+ if (voicecallmanager_path) {
+ /* inform any connections about the addition of the modem */
+ json_t *o = json_object();
+ json_object_set(o, "ModemAdded", json_string(voicecallmanager_path));
+ char *dump = json_dumps(o, 0);
+
+ unsigned char *b = malloc(LWS_SEND_BUFFER_PRE_PADDING +
+ strlen(dump) +
+ LWS_SEND_BUFFER_POST_PADDING);
+ unsigned char *p = b + LWS_SEND_BUFFER_PRE_PADDING;
+ int n = sprintf((char *)p, "%s", dump);
+
+ libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
+ free(b);
+ free(dump);
+ }
+
case LWS_CALLBACK_RECEIVE:
/*
* The other end of the websocket is sending us text
free(dump);
}
+void modem_properties_changed_cb(void *data, DBusMessage *msg)
+{
+ DBusMessageIter iter, values, entry;
+ const char *property, *v;
+ char *dump;
+ int n;
+ json_t *object;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &property);
+
+ if (!strcasecmp(property, "Interfaces")) {
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &values);
+
+ while (dbus_message_iter_get_arg_type(&values) == DBUS_TYPE_ARRAY) {
+ DBusMessageIter variant;
+ dbus_message_iter_recurse(&iter, &entry);
+ dbus_message_iter_recurse(&entry, &variant);
+ if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_INVALID) {
+ dbus_message_iter_get_basic(&variant, &v);
+ if (!strcasecmp(v, "org.ofono.VoiceCallManager")) {
+ object = json_object();
+ json_object_set(object, "ModemAdded", json_string(dbus_message_get_path(msg)));
+ dump = json_dumps(object, 0);
+ libwebsockets_broadcast(&protocols[PROTOCOL_DIALER], dump, strlen(dump));
+ free(dump);
+ }
+ } else {
+ // If the modem has removed all interfaces then its no longer
+ // available for making calls
+ object = json_object();
+ json_object_set(object, "ModemRemoved", json_string(dbus_message_get_path(msg)));
+ dump = json_dumps(object, 0);
+ libwebsockets_broadcast(&protocols[PROTOCOL_DIALER], dump, strlen(dump));
+ free(dump);
+ }
+ dbus_message_iter_next(&values);
+ }
+ }
+}
+
void call_added_cb(void *data, DBusMessage *msg)
{
DBusMessageIter iter, properties;
free(dump);
}
+void modem_added_cb(void *data, DBusMessage *msg)
+{
+ DBusMessageIter iter;
+ const char *path;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &path);
+
+ json_t *object = json_object();
+ json_object_set(object, "ModemAdded", json_string(path));
+ char *dump = json_dumps(object, 0);
+ libwebsockets_broadcast(&protocols[PROTOCOL_DIALER], dump, strlen(dump));
+ free(dump);
+}
+
+void modem_removed_cb(void *data, DBusMessage *msg)
+{
+ DBusMessageIter iter;
+ const char *path;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &path);
+
+ json_t *object = json_object();
+ json_object_set(object, "ModemRemoved", json_string(path));
+ char *dump = json_dumps(object, 0);
+ libwebsockets_broadcast(&protocols[PROTOCOL_DIALER], dump, strlen(dump));
+ free(dump);
+}
+
void
get_modems_reply(void *data, DBusMessage *reply, DBusError *error)
{
dbus_message_iter_recurse(&entry, &item);
dbus_message_iter_get_basic(&item, &path);
+ printf("registering %s\n", path);
+ e_dbus_signal_handler_add(bus, "org.ofono",
+ path, "org.ofono.Modem", "PropertyChanged",
+ modem_properties_changed_cb, (void *)strdup(path));
+ e_dbus_signal_handler_add(bus, "org.ofono",
+ path, "org.ofono.VoiceCallManager", "CallAdded",
+ call_added_cb, NULL);
+ e_dbus_signal_handler_add(bus, "org.ofono",
+ path, "org.ofono.VoiceCallManager",
+ "CallRemoved",
+ call_removed_cb, NULL);
+
dbus_message_iter_next(&item);
dbus_message_iter_recurse(&item, &properties);
free(voicecallmanager_path);
voicecallmanager_path = strdup(path);
- e_dbus_signal_handler_add(bus, "org.ofono",
- path, iface, "CallAdded",
- call_added_cb, NULL);
- e_dbus_signal_handler_add(bus, "org.ofono",
- path, iface,
- "CallRemoved",
- call_removed_cb, NULL);
+ /* inform any connections about the addition of the modem */
+ json_t *o = json_object();
+ json_object_set(o, "ModemAdded", json_string(path));
+ char *dump = json_dumps(o, 0);
+ libwebsockets_broadcast(&protocols[PROTOCOL_DIALER], dump, strlen(dump));
+ free(dump);
}
dbus_message_iter_next(&interfaces);
);
e_dbus_message_send(bus, msg, get_modems_reply, -1, NULL);
+ e_dbus_signal_handler_add(bus, "org.ofono", "/", "org.ofono.Manager", "ModemAdded",
+ modem_added_cb, NULL);
+ e_dbus_signal_handler_add(bus, "org.ofono", "/", "org.ofono.Manager", "ModemRemoved",
+ modem_removed_cb, NULL);
+
/* Listen for updates on application desktop files*/
fd = inotify_init();
inotify_add_watch(fd, APPDIR, IN_CREATE | IN_DELETE | IN_MODIFY);