merge wrt-plugins-tizen_0.2.0-3
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Call / Converter.cpp
index 331a053..2a7535c 100755 (executable)
 #include <CommonsJavaScript/ScopedJSStringRef.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
+#include <API/Call/CallDefine.h>
 #include "JSCallHistoryEntry.h"
 #include "JSRemoteParty.h"
 #include "JSCallService.h"
 #include "JSCellularCallService.h"
 
-#define CH_ENTRY_ID                            "entryId"
-#define CH_SERVICE_ID                  "serviceId"
-#define CH_CALL_TYPE                   "callType"
-#define CH_TAGS                                        "tags"
-#define CH_REMOTE_PARTIES              "remoteParties"
-#define CH_FORWARDEDFROM               "forwardedFrom"
-#define CH_START_TIME                  "startTime"
-#define CH_DURATION                    "duration"
-#define CH_END_REASON                  "endReason"
-#define CH_DIRECTION                   "direction"
-#define CH_RECORDING                   "recording"
-#define CH_COST                                        "cost"
-#define CH_CURRENCY                            "currency"
-
-#define CH_REMOTE_PARTY                "remoteParty"
-#define CH_DISPLAY_NAME                "displayName"
-#define CH_CONTACT_ID                  "contactId"
-
-#define CH_SERVICETYPE_ID              "serviceTypeId"
-#define CH_SERVICENAME                 "serviceName"
-#define CH_PROVIDER_ID                 "providerId"
-
 using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
@@ -143,9 +122,9 @@ RemotePartyPtr Converter::toRemoteParty(const JSValueRef &jsValue)
                ThrowMsg(Commons::InvalidArgumentException, "Wrong attribute of RemoteParty");
        }
 
-       const ScopedJSStringRef remotePartyStr(JSStringCreateWithUTF8CString(CH_REMOTE_PARTY));
-       const ScopedJSStringRef displayNameStr(JSStringCreateWithUTF8CString(CH_DISPLAY_NAME));
-       const ScopedJSStringRef contactIdStr(JSStringCreateWithUTF8CString(CH_CONTACT_ID));
+       const ScopedJSStringRef remotePartyStr(JSStringCreateWithUTF8CString(STR_REMOTE_PARTY));
+       const ScopedJSStringRef displayNameStr(JSStringCreateWithUTF8CString(STR_DISPLAY_NAME));
+       const ScopedJSStringRef contactIdStr(JSStringCreateWithUTF8CString(STR_CONTACT_ID));
 
        JSObjectRef jsObject = toJSObjectRef(jsValue);
 
@@ -185,23 +164,23 @@ CallServiceFilterPtr Converter::toCallServiceFilter(const JSValueRef &jsValue)
 {
        Validator validator(m_context);
        if (!validator.checkArrayKeys(m_allowedCallServiceFilter, jsValue)) {
-               ThrowMsg(Commons::InvalidArgumentException, "Wrong attribute of RemoteParty");
+               ThrowMsg(Commons::InvalidArgumentException, "Wrong attribute of call service filter");
        }
 
-       const ScopedJSStringRef serviceTypeIdStr(JSStringCreateWithUTF8CString(CH_SERVICETYPE_ID));
-       const ScopedJSStringRef tagsStr(JSStringCreateWithUTF8CString(CH_TAGS));
-       const ScopedJSStringRef serviceNameStr(JSStringCreateWithUTF8CString(CH_SERVICENAME));
-       const ScopedJSStringRef providerIdStr(JSStringCreateWithUTF8CString(CH_PROVIDER_ID));
+       const ScopedJSStringRef callTypeStr(JSStringCreateWithUTF8CString(STR_CALL_TYPE));
+       const ScopedJSStringRef tagsStr(JSStringCreateWithUTF8CString(STR_TAGS));
+       const ScopedJSStringRef serviceNameStr(JSStringCreateWithUTF8CString(STR_SERVICE_NAME));
+       const ScopedJSStringRef providerIdStr(JSStringCreateWithUTF8CString(STR_PROVIDER_ID));
 
        JSObjectRef jsObject = toJSObjectRef(jsValue);
 
-       JSValueRef jServiceTypeId = JSObjectGetProperty(m_context, jsObject, serviceTypeIdStr.get(), NULL);
+       JSValueRef jCallType = JSObjectGetProperty(m_context, jsObject, callTypeStr.get(), NULL);
        JSValueRef jTags = JSObjectGetProperty(m_context, jsObject, tagsStr.get(), NULL);
        JSValueRef jServiceName = JSObjectGetProperty(m_context, jsObject, serviceNameStr.get(), NULL);
        JSValueRef jProviderId = JSObjectGetProperty(m_context, jsObject, providerIdStr.get(), NULL);
 
-       std::string serviceTypeId;
-       StringArrayPtr tags;
+       std::string callType;
+       StringArrayPtr tags(new StringArray());
        std::string serviceName;
        std::string providerId;
 
@@ -211,19 +190,9 @@ CallServiceFilterPtr Converter::toCallServiceFilter(const JSValueRef &jsValue)
                Throw(Commons::ConversionException);
        }
 
-       if (!JSValueIsUndefined(m_context, jServiceTypeId)) {
-               serviceTypeId = toString(jServiceTypeId);
-               result->setServiceTypeId(serviceTypeId);
-       }
-
-       if (!JSValueIsUndefined(m_context, jTags)) {
-               tags = toStringArray(jProviderId);
-               result->setTags(tags);
-       }
-
-       if (!JSValueIsUndefined(m_context, jServiceName)) {
-               serviceName = toString(jServiceName);
-               result->setServiceName(serviceName);
+       if (!JSValueIsUndefined(m_context, jCallType)) {
+               callType = toString(jCallType);
+               result->setCallType(callType);
        }
 
        if (!JSValueIsUndefined(m_context, jProviderId)) {
@@ -241,19 +210,19 @@ CallHistoryEntryPropertiesPtr Converter::toCallHistoryEntryProperties(const JSVa
                ThrowMsg(Commons::InvalidArgumentException, "Wrong attribute of call history entry");
        }
 
-       const ScopedJSStringRef entryIdStr(JSStringCreateWithUTF8CString(CH_ENTRY_ID));
-       const ScopedJSStringRef serviceIdStr(JSStringCreateWithUTF8CString(CH_SERVICE_ID));
-       const ScopedJSStringRef callTypeStr(JSStringCreateWithUTF8CString(CH_CALL_TYPE));
-       const ScopedJSStringRef tagsStr(JSStringCreateWithUTF8CString(CH_TAGS));
-       const ScopedJSStringRef remotePartiesStr(JSStringCreateWithUTF8CString(CH_REMOTE_PARTIES));
-       const ScopedJSStringRef forwardedFromStr(JSStringCreateWithUTF8CString(CH_FORWARDEDFROM));
-       const ScopedJSStringRef startTimeStr(JSStringCreateWithUTF8CString(CH_START_TIME));
-       const ScopedJSStringRef durationStr(JSStringCreateWithUTF8CString(CH_DURATION));
-       const ScopedJSStringRef endReasonStr(JSStringCreateWithUTF8CString(CH_END_REASON));
-       const ScopedJSStringRef directionStr(JSStringCreateWithUTF8CString(CH_DIRECTION));
-       const ScopedJSStringRef recordingStr(JSStringCreateWithUTF8CString(CH_RECORDING));
-       const ScopedJSStringRef costStr(JSStringCreateWithUTF8CString(CH_COST));
-       const ScopedJSStringRef currencyStr(JSStringCreateWithUTF8CString(CH_CURRENCY));
+       const ScopedJSStringRef entryIdStr(JSStringCreateWithUTF8CString(STR_ENTRY_ID));
+       const ScopedJSStringRef serviceIdStr(JSStringCreateWithUTF8CString(STR_SERVICE_ID));
+       const ScopedJSStringRef callTypeStr(JSStringCreateWithUTF8CString(STR_CALL_TYPE));
+       const ScopedJSStringRef tagsStr(JSStringCreateWithUTF8CString(STR_TAGS));
+       const ScopedJSStringRef remotePartiesStr(JSStringCreateWithUTF8CString(STR_REMOTE_PARTIES));
+       const ScopedJSStringRef forwardedFromStr(JSStringCreateWithUTF8CString(STR_FORWARDEDFROM));
+       const ScopedJSStringRef startTimeStr(JSStringCreateWithUTF8CString(STR_START_TIME));
+       const ScopedJSStringRef durationStr(JSStringCreateWithUTF8CString(STR_DURATION));
+       const ScopedJSStringRef endReasonStr(JSStringCreateWithUTF8CString(STR_END_REASON));
+       const ScopedJSStringRef directionStr(JSStringCreateWithUTF8CString(STR_DIRECTION));
+       const ScopedJSStringRef recordingStr(JSStringCreateWithUTF8CString(STR_RECORDING));
+       const ScopedJSStringRef costStr(JSStringCreateWithUTF8CString(STR_COST));
+       const ScopedJSStringRef currencyStr(JSStringCreateWithUTF8CString(STR_CURRENCY));
 
        JSObjectRef jsObject = toJSObjectRef(jsValue);
 
@@ -456,15 +425,15 @@ JSValueRef Converter::toJSValueRef(const Api::Account::AccountServicesArrayPtr&
 {
        std::vector<JSValueRef> callServiceList;
 
-       Api::Account::AccountServices tmpAccountServices;
+       Api::Account::AccountServices tmpService;
 
        for (size_t i = 0; i < (*arg).size(); i++) {
-               tmpAccountServices = *((*arg)[i]);
+               tmpService = *((*arg)[i]);
 
-               if (tmpAccountServices.getServiceTypeId().compare("tizen.tel") == 0) {
-                       callServiceList.push_back(JSCellularCallService::createJSObject(context, tmpAccountServices));
+               if (tmpService.getServiceTypeId().compare(STR_TIZEN_TEL) == 0) {
+                       callServiceList.push_back(JSCellularCallService::createJSObject(context, tmpService));
                } else {
-                       callServiceList.push_back(JSCallService::createJSObject(context, tmpAccountServices));
+                       callServiceList.push_back(JSCallService::createJSObject(context, tmpService));
                }
        }
 
@@ -473,26 +442,26 @@ JSValueRef Converter::toJSValueRef(const Api::Account::AccountServicesArrayPtr&
 
 bool Converter::initializeAllowedProperties()
 {
-       m_allowedCallHistoryEntryProperties.push_back(CH_ENTRY_ID);
-       m_allowedCallHistoryEntryProperties.push_back(CH_SERVICE_ID);
-       m_allowedCallHistoryEntryProperties.push_back(CH_CALL_TYPE);
-       m_allowedCallHistoryEntryProperties.push_back(CH_TAGS);
-       m_allowedCallHistoryEntryProperties.push_back(CH_REMOTE_PARTIES);
-       m_allowedCallHistoryEntryProperties.push_back(CH_FORWARDEDFROM);
-       m_allowedCallHistoryEntryProperties.push_back(CH_START_TIME);
-       m_allowedCallHistoryEntryProperties.push_back(CH_DURATION);
-       m_allowedCallHistoryEntryProperties.push_back(CH_END_REASON);
-       m_allowedCallHistoryEntryProperties.push_back(CH_DIRECTION);
-       m_allowedCallHistoryEntryProperties.push_back(CH_RECORDING);
-       m_allowedCallHistoryEntryProperties.push_back(CH_COST);
-       m_allowedCallHistoryEntryProperties.push_back(CH_CURRENCY);
-       m_allowedRemoteParty.push_back(CH_REMOTE_PARTY);
-       m_allowedRemoteParty.push_back(CH_DISPLAY_NAME);
-       m_allowedRemoteParty.push_back(CH_CONTACT_ID);
-       m_allowedCallServiceFilter.push_back(CH_SERVICETYPE_ID);
-       m_allowedCallServiceFilter.push_back(CH_TAGS);
-       m_allowedCallServiceFilter.push_back(CH_SERVICENAME);
-       m_allowedCallServiceFilter.push_back(CH_PROVIDER_ID);
+       m_allowedCallHistoryEntryProperties.push_back(STR_ENTRY_ID);
+       m_allowedCallHistoryEntryProperties.push_back(STR_SERVICE_ID);
+       m_allowedCallHistoryEntryProperties.push_back(STR_CALL_TYPE);
+       m_allowedCallHistoryEntryProperties.push_back(STR_TAGS);
+       m_allowedCallHistoryEntryProperties.push_back(STR_REMOTE_PARTIES);
+       m_allowedCallHistoryEntryProperties.push_back(STR_FORWARDEDFROM);
+       m_allowedCallHistoryEntryProperties.push_back(STR_START_TIME);
+       m_allowedCallHistoryEntryProperties.push_back(STR_DURATION);
+       m_allowedCallHistoryEntryProperties.push_back(STR_END_REASON);
+       m_allowedCallHistoryEntryProperties.push_back(STR_DIRECTION);
+       m_allowedCallHistoryEntryProperties.push_back(STR_RECORDING);
+       m_allowedCallHistoryEntryProperties.push_back(STR_COST);
+       m_allowedCallHistoryEntryProperties.push_back(STR_CURRENCY);
+       m_allowedRemoteParty.push_back(STR_REMOTE_PARTY);
+       m_allowedRemoteParty.push_back(STR_DISPLAY_NAME);
+       m_allowedRemoteParty.push_back(STR_CONTACT_ID);
+       m_allowedCallServiceFilter.push_back(STR_CALL_TYPE);
+       m_allowedCallServiceFilter.push_back(STR_TAGS);
+       m_allowedCallServiceFilter.push_back(STR_SERVICE_NAME);
+       m_allowedCallServiceFilter.push_back(STR_PROVIDER_ID);
 
        return true;
 }