Add support for making a call and hanging up
authorRusty Lynch <rusty.lynch@intel.com>
Thu, 16 Aug 2012 02:00:54 +0000 (19:00 -0700)
committerRusty Lynch <rusty.lynch@intel.com>
Thu, 16 Aug 2012 02:00:54 +0000 (19:00 -0700)
Tizen.Device.js
homescreen.js
main.c

index 22018c1..4cf9b8c 100644 (file)
@@ -115,7 +115,13 @@ var __callservice = function (wsi) {
     });
     
     this.makeCall = function(remotePartyId, handler, extension, localVideoOn) {
-        socket.send(JSON.stringify({"cmd": "makeCall", "remotePartyId": remotePartyId, "extension": extension, "localVideoOn": localVideoOn}));
+        var c = {
+            "cmd": "makeCall", 
+            "remotePartyId": remotePartyId.toString(), 
+            "extension": extension, 
+            "localVideoOn": localVideoOn
+        };
+        socket.send(JSON.stringify(c));
     }
 }
 
index 305fb9b..cc83615 100644 (file)
@@ -16,6 +16,7 @@ function createAppEntry(index) {
     return entry;
 }
 
+var activeCall = null;
 document.body.onload = function() {
     var handler = {
         onCallList: function (callList) {
@@ -23,9 +24,11 @@ document.body.onload = function() {
         },
         onIncoming: function(call) {
             console.log("Incoming call from " + call.callData.LineIdentification);
+            activeCall = call;
         },
         onDialing: function(call) {
             console.log("onDialing: "); console.log(call);
+            activeCall = call;
         },
         onAlerting: function(call) {
             console.log("onAlerting: "); console.log(call);
@@ -38,6 +41,7 @@ document.body.onload = function() {
         },
         onDisconnected: function(call, disconnectReason) {
             console.log("onDisconnected: " + call + " " + disconnectReason);
+            activeCall = null;
         },
         onDisconnecting: function(call) {
             console.log("onDisconnecting: "); console.log(call);
diff --git a/main.c b/main.c
index 49ebf55..f378c2d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -38,6 +38,8 @@ char *apps_directory = NULL;
 
 json_t *event_queue = NULL;
 
+char *voicecallmanager_path = NULL;
+
 #define MAX_POLL_ELEMENTS 100
 struct pollfd pollfds[100];
 int count_pollfds = 0;
@@ -180,6 +182,16 @@ callback_http(struct libwebsocket_context *context,
     return 0;
 }
 
+void
+dial_reply(void *data, DBusMessage *reply, DBusError *error)
+{
+    if (dbus_error_is_set(error)) {
+        fprintf(stderr, "Error: %s - %s\n", error->name, error->message);
+        return;
+    }
+}
+
+
 /* libwebsocket callback for 'protocol-app-list' based websockets */
 static int
 callback_dialer(struct libwebsocket_context *context,
@@ -200,7 +212,6 @@ callback_dialer(struct libwebsocket_context *context,
          */
     case LWS_CALLBACK_ESTABLISHED:
         if (in) {
-            printf("About to broadcast:\n%s\n", (char *) in);
             unsigned char *b = malloc(LWS_SEND_BUFFER_PRE_PADDING + 
                                       strlen((char *)in) + 
                                       LWS_SEND_BUFFER_POST_PADDING);
@@ -282,6 +293,35 @@ void handle_command(json_t *o)
             return;
         
         ecore_exe_run(json_string_value(exec), NULL);
+    } else if (strncmp(cmd, "makeCall", 8) == 0 && 
+               (tmp = json_object_get(o, "remotePartyId"))) {
+        const char *remotePartyId = json_string_value(tmp);
+        const char *hideCallerId = "";
+
+        DBusMessage *msg;
+        msg = dbus_message_new_method_call(
+                                           "org.ofono",
+                                           voicecallmanager_path,
+                                           "org.ofono.VoiceCallManager",
+                                           "Dial"
+                                           );
+        dbus_message_append_args(msg, 
+                                 DBUS_TYPE_STRING, &remotePartyId, 
+                                 DBUS_TYPE_INVALID);
+        dbus_message_append_args(msg, 
+                                 DBUS_TYPE_STRING, &hideCallerId,
+                                 DBUS_TYPE_INVALID);
+        e_dbus_message_send(bus, msg, dial_reply, -1, NULL);
+    } else if (strncmp(cmd, "end", 3) == 0) {
+        DBusMessage *msg;
+        msg = dbus_message_new_method_call(
+                                           "org.ofono",
+                                           voicecallmanager_path,
+                                           "org.ofono.VoiceCallManager",
+                                           "HangupAll"
+                                           );
+        e_dbus_message_send(bus, msg, dial_reply, -1, NULL);
+
     }
 }
 
@@ -415,8 +455,6 @@ void call_properties_changed_cb(void *data, DBusMessage *msg)
 
     dbus_message_iter_get_basic(&value, &v);
 
-    printf("Call changed: %s=%s\n", property, v);
-
     object = json_object();
     json_object_set(object, property, json_string(v));
     dump = json_dumps(object, 0);
@@ -437,7 +475,6 @@ void call_added_cb(void *data, DBusMessage *msg)
     dbus_message_iter_next(&iter);
     dbus_message_iter_recurse(&iter, &properties);
 
-    printf("%s :", path);
     while (dbus_message_iter_get_arg_type(&properties) == DBUS_TYPE_DICT_ENTRY) {
         DBusMessageIter entry, value;
         const char *key, *v;
@@ -450,12 +487,10 @@ void call_added_cb(void *data, DBusMessage *msg)
         
         dbus_message_iter_get_basic(&value, &v);
 
-        printf(" %s=%s ", key, v);
         json_object_set(object, key, json_string(v));
 
         dbus_message_iter_next(&properties);
     }
-    printf("\n");
 
     e_dbus_signal_handler_add(bus, 
                               "org.ofono", 
@@ -484,7 +519,7 @@ get_modems_reply(void *data, DBusMessage *reply, DBusError *error)
 {
     DBusMessageIter iter, entry;
     if (dbus_error_is_set(error)) {
-        printf("Error: %s - %s\n", error->name, error->message);
+        fprintf(stderr, "Error: %s - %s\n", error->name, error->message);
         return;
     }
 
@@ -525,7 +560,10 @@ get_modems_reply(void *data, DBusMessage *reply, DBusError *error)
                     dbus_message_iter_get_basic(&interfaces, &iface);
                     
                     if (!strcasecmp(iface, "org.ofono.VoiceCallManager")) {
-                        printf("Listening for calls on %s\n", path);
+                        if (voicecallmanager_path)
+                            free(voicecallmanager_path);
+                        voicecallmanager_path = strdup(path);
+
                         e_dbus_signal_handler_add(bus, "org.ofono", 
                                                   path, iface, "CallAdded", 
                                                   call_added_cb, NULL);