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 <FBaseUtilStringTokenizer.h>
39 #include <FBaseSysLog.h>
40 #include <FBase_StringConverter.h>
42 #include "FApp_MapDataControlImpl.h"
43 #include "FApp_AppControlImpl.h"
44 #include "FApp_SqlDataControlImpl.h"
45 #include "FApp_AppControlEventArg.h"
46 #include "FApp_AppArg.h"
47 #include "FApp_AppMessageImpl.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Base::Utility;
55 extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
57 namespace Tizen { namespace App
60 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
61 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
62 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
63 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
64 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
65 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
66 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
67 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
68 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
69 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
70 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
71 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
72 static const char OSP_V_VERSION_2_1_0_3[] = "ver_2.1.0.3";
73 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
74 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
75 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
76 static const char BUNDLE_KEY_PREFIX_UG[] = "__UG_";
77 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
78 const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
81 _AppArg::_AppArg(void)
87 _AppArg::~_AppArg(void)
91 bundle_free(__pBundle);
97 _AppArg::Construct(const String& argText)
99 __pBundle = bundle_create();
100 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
102 return CreateNotificationArg(__pBundle, argText);
107 _AppArg::Construct(const IList* pList)
109 __pBundle = bundle_create();
110 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
112 return CreateLaunchArg(__pBundle, pList);
117 _AppArg::Construct(const _AppControlImpl& ac, const IList* pList)
119 __pBundle = bundle_create();
120 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
122 return CreateAppControlArg(__pBundle, ac, pList);
127 _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String* pMime, const IMap* pList)
129 __pBundle = bundle_create();
130 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
132 return CreateAppControlArg(__pBundle, ac, pUri, pMime, pList);
137 _AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
139 __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
140 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
142 return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
147 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
149 __pBundle = bundle_create();
150 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
152 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
157 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
159 __pBundle = bundle_create();
160 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
162 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
167 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
169 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
170 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
172 return CreateResultArg(__pBundle, pList);
177 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
179 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
180 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
182 return CreateResultArg(__pBundle, pMap);
187 _AppArg::Construct(bundle* b)
189 __pBundle = bundle_dup(b);
190 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
197 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
199 __pBundle = bundle_create();
200 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
202 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
206 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
208 __pBundle = bundle_create();
209 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
211 CreateAppLaunchConditionArg(__pBundle, condition, pList);
213 return CreateResultArg(__pBundle, pMap);
217 _AppArg::GetArgListN(int num) const
219 bundle* pBundle = __pBundle;
220 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
222 ArrayList* pList = new (std::nothrow) ArrayList();
223 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
227 const char* p = NULL;
228 _AppHandler launch_type = GetHandler(pBundle);
232 case _APP_HANDLER_APPCONTROL:
234 // [FIXME] proper request Id required
235 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
238 p = appsvc_get_category(pBundle);
241 pList->Add(*new (std::nothrow) String(p));
245 pList->Add(*new (std::nothrow) String(L""));
249 p = appsvc_get_mime(pBundle);
252 pList->Add(*new (std::nothrow) String(p));
256 pList->Add(*new (std::nothrow) String(L""));
260 p = appsvc_get_uri(pBundle);
263 pList->Add(*new (std::nothrow) String(p));
267 pList->Add(*new (std::nothrow) String(L""));
272 case _APP_HANDLER_DATACONTROL:
274 AddListFromBundle(pList, pBundle, OSP_K_APPID);
276 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
278 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
280 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
283 case _APP_HANDLER_LAUNCH_COND:
284 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
285 AddListFromBundle(pList, pBundle, OSP_K_COND);
288 case _APP_HANDLER_LAUNCH_NORMAL:
289 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
290 pList->Add(*new (std::nothrow) String(LEGACY_OPERATION_MAIN));
294 SysLog(NID_APP, "Invalid handler type");
298 SetArgList(__pBundle, pList);
305 _AppArg::GetArgListN(void) const
307 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
309 ArrayList* pList = new (std::nothrow) ArrayList();
310 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
314 SetArgList(__pBundle, pList);
319 // the returned map is allocated using SingleObjectDeleter
321 _AppArg::GetArgMapN(void) const
323 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
327 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
328 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
330 pHashMap->Construct();
332 SetArgMap(__pBundle, pHashMap);
334 if (pHashMap->GetCount() == 0)
344 IsInternalKey(const char* pKey)
346 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
351 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
356 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
361 if (strncmp(BUNDLE_KEY_PREFIX_UG, pKey, strlen(BUNDLE_KEY_PREFIX_UG)) == 0)
370 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
372 HashMap* pMap = static_cast<HashMap*>(pData);
374 if (pKey && pVal && pMap)
376 if (IsInternalKey(pKey))
378 //SysLog(NID_APP, "(%s)", pKey);
386 case BUNDLE_TYPE_STR:
387 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
390 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
393 case BUNDLE_TYPE_STR_ARRAY:
396 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
397 if (pArr && size > 0)
399 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
404 for (size_t i = 0; i < size; i++)
406 // type unsafe ugly static casting required
407 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
410 const int count = pList->GetCount();
413 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
414 pMap->Add(new (std::nothrow) String(pKey), pList);
418 SysLog(NID_APP, "No object for %s", pKey);
425 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
429 case BUNDLE_TYPE_BYTE:
430 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
432 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
436 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
437 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
438 result r = pBuffer->Construct(size);
439 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
441 r = pBuffer->SetArray((const byte*)pStr, 0, size);
442 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
446 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
450 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
457 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
459 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
465 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
467 // actual argument below
469 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
472 for (int i = 0; i < len; i++)
476 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
477 pList->Add(*new (std::nothrow) String(pa[i]));
482 const char* p = appsvc_get_uri(pBundle);
485 pList->Add(*new (std::nothrow) String(p));
486 SysLog(NID_APP, "argument is %s", p);
494 _AppArg::GetValue(const char* key) const
496 const char* p = appsvc_get_data(__pBundle, key);
502 _AppArg::GetHandler(bundle* b)
504 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
506 const char* p = null;
508 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
512 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
514 return _APP_HANDLER_DATACONTROL;
517 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
519 SysLog(NID_APP, "Building AppControl arguments.");
521 return _APP_HANDLER_APPCONTROL;
525 // not appcontrol nor datacontrol => normal launch or condlaunch
526 p = appsvc_get_data(b, OSP_K_COND);
529 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
530 return _APP_HANDLER_LAUNCH_COND;
534 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
535 return _APP_HANDLER_LAUNCH_NORMAL;
541 return _APP_HANDLER_APPCONTROL;
546 _AppArg::GetCallerPid(bundle* pBundle)
548 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
549 if (pBundleValue == NULL)
551 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
554 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
556 return atoi(pBundleValue);
561 _AppArg::GetCallerAppId(void) const
563 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
565 return String(pBundleValue);
570 _AppArg::GetCalleeAppId(void) const
572 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
574 const AppId retVal = pBundleValue;
576 return _Aul::GetRealAppId(retVal);
581 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
583 bundle* pBundle = bk;
585 const char* p = appsvc_get_data(pBundle, key);
588 pList->Add(*new (std::nothrow) String(p));
592 pList->Add(*new (std::nothrow) String(L""));
598 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
600 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
602 return AddStrArray(b, pKey.get(), pList);
607 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
609 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
611 if (pList == null || pList->GetCount() == 0)
613 SysLog(NID_APP, "No element added for bundle.");
617 _AppMessageImpl::AddValueArray(pb, key, pList);
619 _AppMessageImpl::AddData(pb, pList);
626 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
629 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
631 if (pMap == null || pMap->GetCount() == 0)
633 SysLog(NID_APP, "No element added for bundle.");
637 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
638 while(pEnum->MoveNext() == E_SUCCESS)
640 const String* pKey = static_cast<const String*>(pEnum->GetKey());
641 const Object* pObj = pEnum->GetValue();
645 if (typeid(*pObj) == typeid(const String))
647 const String* pVal = static_cast<const String*>(pEnum->GetValue());
650 _AppMessageImpl::AddData(pb, *pKey, *pVal);
653 else if (typeid(*pObj) == typeid(const ArrayList))
655 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
658 SysLog(NID_APP, "ArrayList type");
660 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
663 else if (typeid(*pObj) == typeid(const ByteBuffer))
665 SysLog(NID_APP, "ByteBuffer type");
666 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
668 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
669 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
679 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
681 if (pMap == null || pList == null)
686 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
687 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
691 while (pEnum->MoveNext() == E_SUCCESS)
693 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
696 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
700 pStr->SubString(0, index, key);
706 pStr->SubString(index + 1, value);
708 pMap->Add(new String(key), new String(value));
710 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
718 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
722 case APP_CTRL_RESULT_SUCCEEDED:
723 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
725 case APP_CTRL_RESULT_CANCELED:
726 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
728 case APP_CTRL_RESULT_TERMINATED:
729 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
731 case APP_CTRL_RESULT_ABORTED:
732 list.Add(* new (std::nothrow) String("aborted"));
734 //case APP_CTRL_RESULT_FAILED:
736 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
745 bool isPathRegistered = false;
746 // handle APP_CTRL_RESULT_SUCCEEDED only
747 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
749 while(pMapEnum->MoveNext() == E_SUCCESS)
751 String* pKey = static_cast<String*>(pMapEnum->GetKey());
754 SysLog(NID_APP, "Invalid entry.");
758 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
760 if (!isPathRegistered)
762 isPathRegistered = true;
766 SysLog(NID_APP, "Selected path key is already registered.");
771 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
774 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
776 StringTokenizer strTok(*pVal, L';');
777 if (strTok.GetTokenCount() == 0)
779 list.Add(* new (std::nothrow) String(*pVal));
784 while(strTok.HasMoreTokens())
786 strTok.GetNextToken(token);
787 list.Add(* new (std::nothrow) String(token));
788 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
799 _AppArg::GetListN(bundle* b, const char* key)
807 const char** pValArray = null;
810 pValArray = appsvc_get_data_array(b, key, &len);
811 if (len == 0 || pValArray == null)
816 ArrayList* pList = new (std::nothrow) ArrayList;
817 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
821 for (int i = 0; i < len; i++)
823 pList->Add(*new (std::nothrow) String(pValArray[i]));
831 _AppArg::CreateNotificationArg(bundle* b, const String& arg)
833 SysAssertf(b != null, "Valid bundle should be supplied");
839 std::unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(arg));
840 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pStr.get());
843 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
850 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
852 SysAssertf(b != null, "Valid bundle should be supplied");
856 AddStrArray(pb, OSP_K_ARG, pList);
858 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
865 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
867 SysAssertf(b != null, "Valid bundle should be supplied");
872 AddStrArray(pb, OSP_K_ARG, pList);
874 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
877 bundle_add(pb, OSP_K_COND, p.get());
880 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
887 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
889 SysAssertf(b != null, "Valid bundle should be supplied");
893 AddStrArray(pb, OSP_K_ARG, pList);
895 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
898 appsvc_set_operation(pb, pOperation.get());
901 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
908 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
910 return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
915 _AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
917 SysAssertf(b != null, "Valid bundle should be supplied");
921 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
922 if (pOperation.get())
924 appsvc_set_operation(pb, pOperation.get());
929 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
932 appsvc_set_uri(pb, pUri.get());
938 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
941 appsvc_set_mime(pb, pMime.get());
947 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
955 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
958 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
959 const IList* pArgList)
961 SysAssertf(b != null, "Valid bundle should be supplied");
963 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
965 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
966 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
967 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
968 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
969 bundle_add(b, AUL_K_NO_CANCEL, "1");
971 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
974 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
977 AddStrArray(b, OSP_K_ARG, pArgList);
984 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
985 const IList* pArgList)
987 SysAssertf(b != null, "Valid bundle should be supplied");
989 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
991 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
992 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
993 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
994 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
995 bundle_add(b, AUL_K_NO_CANCEL, "1");
997 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1000 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1003 AddStrArray(b, OSP_K_ARG, pArgList);
1010 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1012 SysAssertf(b != null, "Valid bundle should be supplied");
1016 AddStrArray(pb, OSP_K_ARG, pList);
1018 _AppMessageImpl::AddData(pb, pList);
1025 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1027 SysAssertf(b != null, "Valid bundle should be supplied");
1031 AddStrMap(pb, pMap);
1038 _AppArg::CreateBundleFromSvc(void* svc)
1040 bundle* pBundle = GetBundleFromSvc(svc);
1043 return bundle_dup(pBundle);
1051 _AppArg::GetBundleFromSvc(void* svc)
1060 DummyS* pDummy = static_cast<DummyS*>(svc);
1062 if (pDummy && pDummy->pData)
1064 return pDummy->pData;
1072 _AppArg::GetRequestId(int num)
1075 str.Format(10, L"req%05d", num);
1081 _AppArg::GetRequestId(const String& str)
1086 result r = str.SubString(3, sub);
1087 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1089 r = Integer::Parse(sub, i);
1090 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1097 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1099 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1101 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1102 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1104 int res = bundle_add(b, OSP_K_APPID, pId.get());
1105 if (res < 0 && errno == EPERM) // key exists
1107 bundle_del(b, OSP_K_APPID);
1108 bundle_add(b, OSP_K_APPID, pId.get());
1111 appsvc_set_appid(b, pId.get());
1116 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1118 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1122 //SysLog(NID_APP, "Requested ID is %d", reqId);
1126 char buffer[32] = {0, };
1127 snprintf(buffer, 32, "%d", reqId);
1128 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1129 if (res < 0 && errno == EPERM) // key exists
1131 bundle_del(pBundle, OSP_K_REQUEST_ID);
1132 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1137 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1139 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1141 char pBuffer[128] = {0, };
1142 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1143 int res = bundle_add(pBundle, pKey, pBuffer);
1144 if (res < 0 && errno == EPERM) // key exists
1146 bundle_del(pBundle, pKey);
1147 bundle_add(pBundle, pKey, pBuffer);
1153 _AppArg::UpdateSubMode(bundle* pBundle)
1155 appsvc_add_data(pBundle, OSP_K_SUBMODE_CALLEE, "1");
1160 _AppArg::IsSubMode(bundle* pBundle)
1162 const char* p = appsvc_get_data(pBundle, OSP_K_SUBMODE_CALLEE);
1163 if (p && (strncmp(p, "1", sizeof(char)) == 0))
1173 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1175 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1182 return (i < 0) ? -1 : i;
1187 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1189 appsvc_allow_transient_app(pBundle, handle);
1191 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1198 _AppArg::PrintSvcHandle(void* svc)
1200 service_h service = static_cast<service_h>(svc);
1202 if (service == null)
1207 Print(GetBundleFromSvc(service));
1212 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1220 case BUNDLE_TYPE_STR:
1221 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1224 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1228 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1235 _AppArg::Print(bundle* b)
1242 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1245 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1248 for (int i = 0; i < len; i++)
1252 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);