2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FApp_AppArg.cpp
19 * @brief This is the implementation for the _AppArg.cpp class.
26 #include <unique_ptr.h>
31 #include <appsvc/appsvc.h>
34 #include <FBaseInteger.h>
35 #include <FBaseColArrayList.h>
36 #include <FBaseColHashMap.h>
37 #include <FBaseByteBuffer.h>
38 #include <FBaseUtilStringTokenizer.h>
39 #include <FBaseSysLog.h>
41 #include <FBase_StringConverter.h>
43 #include "FApp_MapDataControlImpl.h"
44 #include "FApp_AppControlImpl.h"
45 #include "FApp_SqlDataControlImpl.h"
46 #include "FApp_AppControlEventArg.h"
47 #include "FApp_AppArg.h"
48 #include "FApp_AppMessageImpl.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Utility;
56 extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
58 namespace Tizen { namespace App
61 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
62 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
63 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
64 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
65 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
66 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
67 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
68 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
69 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
70 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
71 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
72 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
73 static const char OSP_V_VERSION_2_1_0_3[] = "ver_2.1.0.3";
75 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
76 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
77 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
78 static const char BUNDLE_KEY_PREFIX_UG[] = "__UG_";
80 static const char OSP_K_SUBMODE_CALLEE[] = "__OSP_SUB_CALLEE__";
81 static const char OSP_K_SERVICE_CALLEE[] = "__OSP_SERVICE_CALLEE__";
84 _AppArg::_AppArg(void)
90 _AppArg::~_AppArg(void)
94 bundle_free(__pBundle);
100 _AppArg::Construct(const String& argText)
102 __pBundle = bundle_create();
103 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
105 return CreateNotificationArg(__pBundle, argText);
110 _AppArg::Construct(const IList* pList)
112 __pBundle = bundle_create();
113 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
115 return CreateLaunchArg(__pBundle, pList);
120 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
122 __pBundle = bundle_create();
123 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
125 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
130 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
132 __pBundle = bundle_create();
133 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
135 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
140 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
142 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
143 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
145 return CreateResultArg(__pBundle, pList);
150 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
152 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
153 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
155 return CreateResultArg(__pBundle, pMap);
160 _AppArg::Construct(const bundle* b)
162 __pBundle = bundle_dup(const_cast<bundle*>(b));
163 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
170 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
172 __pBundle = bundle_create();
173 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
175 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
179 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
181 __pBundle = bundle_create();
182 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
184 CreateAppLaunchConditionArg(__pBundle, condition, pList);
186 return CreateResultArg(__pBundle, pMap);
190 _AppArg::GetArgListN(int num) const
192 bundle* pBundle = __pBundle;
193 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
195 ArrayList* pList = new (std::nothrow) ArrayList();
196 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
200 const char* p = NULL;
201 _AppHandler launch_type = GetHandler(pBundle);
205 case _APP_HANDLER_APPCONTROL:
207 // [FIXME] proper request Id required
208 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
211 p = appsvc_get_category(pBundle);
214 pList->Add(*new (std::nothrow) String(p));
218 pList->Add(*new (std::nothrow) String(L""));
222 p = appsvc_get_mime(pBundle);
225 pList->Add(*new (std::nothrow) String(p));
229 pList->Add(*new (std::nothrow) String(L""));
233 p = appsvc_get_uri(pBundle);
236 pList->Add(*new (std::nothrow) String(p));
240 pList->Add(*new (std::nothrow) String(L""));
245 case _APP_HANDLER_DATACONTROL:
247 AddListFromBundle(pList, pBundle, OSP_K_APPID);
249 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
251 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
253 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
256 case _APP_HANDLER_LAUNCH_COND:
257 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
258 AddListFromBundle(pList, pBundle, OSP_K_COND);
261 case _APP_HANDLER_LAUNCH_NORMAL:
262 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
263 pList->Add(*new (std::nothrow) String(LEGACY_OPERATION_MAIN));
267 SysLog(NID_APP, "Invalid handler type");
271 SetArgList(__pBundle, pList);
278 _AppArg::GetArgListN(void) const
280 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
282 ArrayList* pList = new (std::nothrow) ArrayList();
283 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
287 SetArgList(__pBundle, pList);
292 // the returned map is allocated using SingleObjectDeleter
294 _AppArg::GetArgMapN(void) const
296 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
300 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
301 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
303 pHashMap->Construct();
305 SetArgMap(__pBundle, pHashMap);
307 if (pHashMap->GetCount() == 0)
317 IsInternalKey(const char* pKey)
319 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
324 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
329 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
334 if (strncmp(BUNDLE_KEY_PREFIX_UG, pKey, strlen(BUNDLE_KEY_PREFIX_UG)) == 0)
343 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
345 HashMap* pMap = static_cast<HashMap*>(pData);
347 if (pKey && pVal && pMap)
349 if (IsInternalKey(pKey))
351 //SysLog(NID_APP, "(%s)", pKey);
359 case BUNDLE_TYPE_STR:
360 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
363 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
366 case BUNDLE_TYPE_STR_ARRAY:
369 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
370 if (pArr && size > 0)
372 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
377 for (size_t i = 0; i < size; i++)
379 // type unsafe ugly static casting required
380 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
383 const int count = pList->GetCount();
386 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
387 pMap->Add(new (std::nothrow) String(pKey), pList);
391 SysLog(NID_APP, "No object for %s", pKey);
398 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
402 case BUNDLE_TYPE_BYTE:
403 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
405 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
409 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
410 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
411 result r = pBuffer->Construct(size);
412 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
414 r = pBuffer->SetArray((const byte*)pStr, 0, size);
415 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
419 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
423 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
430 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
432 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
438 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
440 // actual argument below
442 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
445 for (int i = 0; i < len; i++)
449 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
450 pList->Add(*new (std::nothrow) String(pa[i]));
455 const char* p = appsvc_get_uri(pBundle);
458 pList->Add(*new (std::nothrow) String(p));
459 SysLog(NID_APP, "argument is %s", p);
467 _AppArg::GetValue(const char* key) const
469 const char* p = appsvc_get_data(__pBundle, key);
475 _AppArg::GetHandler(bundle* b)
477 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
479 const char* p = null;
481 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
485 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
487 return _APP_HANDLER_DATACONTROL;
490 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
492 SysLog(NID_APP, "Building AppControl arguments.");
494 return _APP_HANDLER_APPCONTROL;
498 // not appcontrol nor datacontrol => normal launch or condlaunch
499 p = appsvc_get_data(b, OSP_K_COND);
502 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
503 return _APP_HANDLER_LAUNCH_COND;
507 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
508 return _APP_HANDLER_LAUNCH_NORMAL;
514 return _APP_HANDLER_APPCONTROL;
519 _AppArg::GetCallerPid(bundle* pBundle)
521 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
522 if (pBundleValue == NULL)
524 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
527 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
529 return atoi(pBundleValue);
534 _AppArg::GetCallerAppId(void) const
536 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
538 return String(pBundleValue);
543 _AppArg::GetCalleeAppId(bundle* pBundle)
545 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_CALLEE_APPID);
547 const AppId retVal = pBundleValue;
549 return _Aul::GetRealAppId(retVal);
554 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
556 bundle* pBundle = bk;
558 const char* p = appsvc_get_data(pBundle, key);
561 pList->Add(*new (std::nothrow) String(p));
565 pList->Add(*new (std::nothrow) String(L""));
571 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
573 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
575 return AddStrArray(b, pKey.get(), pList);
580 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
582 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
584 if (pList == null || pList->GetCount() == 0)
586 SysLog(NID_APP, "No element added for bundle.");
590 _AppMessageImpl::AddValueArray(pb, key, pList);
592 _AppMessageImpl::AddData(pb, pList);
599 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
602 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
604 if (pMap == null || pMap->GetCount() == 0)
606 SysLog(NID_APP, "No element added for bundle.");
610 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
611 while(pEnum->MoveNext() == E_SUCCESS)
613 const String* pKey = static_cast<const String*>(pEnum->GetKey());
614 const Object* pObj = pEnum->GetValue();
618 if (typeid(*pObj) == typeid(const String))
620 const String* pVal = static_cast<const String*>(pEnum->GetValue());
623 _AppMessageImpl::AddData(pb, *pKey, *pVal);
626 else if (typeid(*pObj) == typeid(const ArrayList))
628 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
631 SysLog(NID_APP, "ArrayList type");
633 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
636 else if (typeid(*pObj) == typeid(const ByteBuffer))
638 SysLog(NID_APP, "ByteBuffer type");
639 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
641 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
642 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
652 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
654 if (pMap == null || pList == null)
659 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
660 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
664 while (pEnum->MoveNext() == E_SUCCESS)
666 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
669 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
673 pStr->SubString(0, index, key);
679 pStr->SubString(index + 1, value);
681 pMap->Add(new String(key), new String(value));
683 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
691 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
695 case APP_CTRL_RESULT_SUCCEEDED:
696 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
698 case APP_CTRL_RESULT_CANCELED:
699 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
701 case APP_CTRL_RESULT_TERMINATED:
702 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
704 case APP_CTRL_RESULT_ABORTED:
705 list.Add(* new (std::nothrow) String("aborted"));
707 //case APP_CTRL_RESULT_FAILED:
709 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
718 bool isPathRegistered = false;
719 // handle APP_CTRL_RESULT_SUCCEEDED only
720 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
722 while(pMapEnum->MoveNext() == E_SUCCESS)
724 String* pKey = static_cast<String*>(pMapEnum->GetKey());
727 SysLog(NID_APP, "Invalid entry.");
731 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
733 if (!isPathRegistered)
735 isPathRegistered = true;
739 SysLog(NID_APP, "Selected path key is already registered.");
744 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
747 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
749 StringTokenizer strTok(*pVal, L';');
750 if (strTok.GetTokenCount() == 0)
752 list.Add(* new (std::nothrow) String(*pVal));
757 while(strTok.HasMoreTokens())
759 strTok.GetNextToken(token);
760 list.Add(* new (std::nothrow) String(token));
761 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
772 _AppArg::GetListN(bundle* b, const char* key)
780 const char** pValArray = null;
783 pValArray = appsvc_get_data_array(b, key, &len);
784 if (len == 0 || pValArray == null)
789 ArrayList* pList = new (std::nothrow) ArrayList;
790 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
794 for (int i = 0; i < len; i++)
796 pList->Add(*new (std::nothrow) String(pValArray[i]));
804 _AppArg::CreateNotificationArg(bundle* b, const String& arg)
806 SysAssertf(b != null, "Valid bundle should be supplied");
812 std::unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(arg));
813 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pStr.get());
816 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
823 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
825 SysAssertf(b != null, "Valid bundle should be supplied");
829 AddStrArray(pb, OSP_K_ARG, pList);
831 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
838 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
840 SysAssertf(b != null, "Valid bundle should be supplied");
845 AddStrArray(pb, OSP_K_ARG, pList);
847 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
850 bundle_add(pb, OSP_K_COND, p.get());
853 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
861 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
864 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
865 const IList* pArgList)
867 SysAssertf(b != null, "Valid bundle should be supplied");
869 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
871 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
872 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
873 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
874 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
875 bundle_add(b, AUL_K_NO_CANCEL, "1");
877 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
880 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
883 AddStrArray(b, OSP_K_ARG, pArgList);
890 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
891 const IList* pArgList)
893 SysAssertf(b != null, "Valid bundle should be supplied");
895 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
897 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
898 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
899 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
900 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
901 bundle_add(b, AUL_K_NO_CANCEL, "1");
903 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
906 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
909 AddStrArray(b, OSP_K_ARG, pArgList);
916 _AppArg::CreateResultArg(bundle* b, const IList* pList)
918 SysAssertf(b != null, "Valid bundle should be supplied");
922 AddStrArray(pb, OSP_K_ARG, pList);
924 _AppMessageImpl::AddData(pb, pList);
931 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
933 SysAssertf(b != null, "Valid bundle should be supplied");
944 _AppArg::CreateBundleFromSvc(void* svc)
946 bundle* pBundle = GetBundleFromSvc(svc);
949 return bundle_dup(pBundle);
957 _AppArg::GetBundleFromSvc(void* svc)
959 bundle* pBundle = NULL;
960 int ret = service_to_bundle(static_cast<service_h>(svc), &pBundle);
962 return (ret == SERVICE_ERROR_NONE) ? pBundle : NULL;
967 _AppArg::GetRequestId(int num)
970 str.Format(10, L"req%05d", num);
976 _AppArg::GetRequestId(const String& str)
981 result r = str.SubString(3, sub);
982 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
984 r = Integer::Parse(sub, i);
985 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
992 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
994 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
996 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
997 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
999 int res = bundle_add(b, OSP_K_APPID, pId.get());
1000 if (res < 0 && errno == EPERM) // key exists
1002 bundle_del(b, OSP_K_APPID);
1003 bundle_add(b, OSP_K_APPID, pId.get());
1006 appsvc_set_appid(b, pId.get());
1011 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1013 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1017 //SysLog(NID_APP, "Requested ID is %d", reqId);
1021 char buffer[32] = {0, };
1022 snprintf(buffer, 32, "%d", reqId);
1023 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1024 if (res < 0 && errno == EPERM) // key exists
1026 bundle_del(pBundle, OSP_K_REQUEST_ID);
1027 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1032 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1034 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1036 char pBuffer[128] = {0, };
1037 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1038 int res = bundle_add(pBundle, pKey, pBuffer);
1039 if (res < 0 && errno == EPERM) // key exists
1041 bundle_del(pBundle, pKey);
1042 bundle_add(pBundle, pKey, pBuffer);
1048 _AppArg::UpdateSubMode(bundle* pBundle)
1050 appsvc_add_data(pBundle, OSP_K_SUBMODE_CALLEE, "1");
1055 _AppArg::IsSubMode(bundle* pBundle)
1057 const char* p = appsvc_get_data(pBundle, OSP_K_SUBMODE_CALLEE);
1058 return (p && (strncmp(p, "1", sizeof(char)) == 0));
1063 _AppArg::UpdateServiceApp(bundle* pBundle)
1065 appsvc_add_data(pBundle, OSP_K_SERVICE_CALLEE, "1");
1070 _AppArg::IsServiceApp(bundle* pBundle)
1072 const char* p = appsvc_get_data(pBundle, OSP_K_SERVICE_CALLEE);
1073 return (p && (strncmp(p, "1", sizeof(char)) == 0));
1078 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1080 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1087 return (i < 0) ? -1 : i;
1092 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1094 appsvc_allow_transient_app(pBundle, handle);
1096 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1103 _AppArg::PrintSvcHandle(void* svc)
1105 service_h service = static_cast<service_h>(svc);
1107 if (service == null)
1112 Print(GetBundleFromSvc(service));
1117 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1125 case BUNDLE_TYPE_STR:
1126 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1129 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1133 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1140 _AppArg::Print(bundle* b)
1147 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1150 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1153 for (int i = 0; i < len; i++)
1157 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);