[Messaging] sendMessage SMS
authorMaciek Blim <m.blim@samsung.com>
Mon, 12 Jan 2015 15:11:52 +0000 (16:11 +0100)
committerMaciek Blim <m.blim@samsung.com>
Tue, 13 Jan 2015 11:39:02 +0000 (12:39 +0100)
Change-Id: I8b4d1a843adc7e7bddc4d9c67de8ed3483b2cbba
Signed-off-by: Maciek Blim <m.blim@samsung.com>
src/messaging/message_service_short_msg.cc
src/messaging/short_message_manager.cc

index 463f27a..ba4663c 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "message_service_short_msg.h"
 #include "messaging_instance.h"
+#include "short_message_manager.h"
 #include "common/logger.h"
 #include "common/platform_exception.h"
 
@@ -15,7 +16,6 @@
 //#include <JSWebAPIErrorFactory.h>
 //#include <JSWebAPIError.h>
 //#include <JSUtil.h>
-//#include "ShortMsgManager.h"
 //#include "JSMessage.h"
 
 //using namespace DeviceAPI::Common;
@@ -47,7 +47,7 @@ static gboolean sendMessageThread(void* data)
     }
 
     // TODO
-    //ShortMsgManager::getInstance().sendMessage(callback);
+    ShortMsgManager::getInstance().sendMessage(callback);
     return FALSE;
 }
 
index 3cf62f6..04b4c5e 100644 (file)
@@ -45,26 +45,36 @@ static gboolean sendMessageCompleteCB(void* data)
 
     try {
         if (callback->isError()) {
-            // TODO call error callback
-            //JSObjectRef errobj = JSWebAPIErrorFactory::makeErrorObject(context,
-                    //callback->getErrorName(),
-                    //callback->getErrorMessage());
-
-            //LoggerD("Calling error callback with error:%s msg:%s",
-                    //callback->getErrorName().c_str(),
-                    //callback->getErrorMessage().c_str());
-
-            //callback->callErrorCallback(errobj);
-            //callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
+            MessagingInstance::getInstance().PostMessage(callback->getJson()->serialize().c_str());
+            callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
         }
         else {
             std::shared_ptr<Message> message = callback->getMessage();
 
             LoggerD("Calling success callback with: %d recipients", message->getTO().size());
-            // TODO call success callback
-            //callback->callSuccessCallback(
-                    //JSUtil::toJSValueRef(context, message->getTO()));
-            //callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
+
+            auto json = callback->getJson();
+            picojson::object& obj = json->get<picojson::object>();
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+
+            std::vector<picojson::value> recipients;
+            auto addToRecipients = [&recipients](std::string& e)->void {
+                recipients.push_back(picojson::value(e));
+            };
+
+            auto toVect = callback->getMessage()->getTO();
+            std::for_each(toVect.begin(), toVect.end(), addToRecipients);
+
+            auto ccVect = callback->getMessage()->getCC();
+            std::for_each(ccVect.begin(), ccVect.end(), addToRecipients);
+
+            auto bccVect = callback->getMessage()->getBCC();
+            std::for_each(bccVect.begin(), bccVect.end(), addToRecipients);
+
+            obj[JSON_DATA] = picojson::value(recipients);
+
+            MessagingInstance::getInstance().PostMessage(json->serialize().c_str());
+            callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
         }
     }
     catch (const common::PlatformException& err) {