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.
27 #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"
49 #include "FAppPkg_PackageManagerImpl.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Utility;
54 using namespace Tizen::App::Package;
57 extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
59 namespace Tizen { namespace App
62 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
63 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
64 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
65 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
66 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
67 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
68 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
69 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
70 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
71 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
72 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
73 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
74 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 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
80 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_ID[] = "client_id";
81 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET[] = "client_secret";
82 static const char SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY[] = "service_category";
84 static const char SMS_KEY_SERVICE_CALLER[] = "service_caller";
85 static const char SMS_KEY_SERVICE_DATA[] = "service_data";
88 _AppArg::_AppArg(void)
94 _AppArg::~_AppArg(void)
98 bundle_free(__pBundle);
104 _AppArg::Construct(const String& argText)
106 __pBundle = bundle_create();
107 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
109 return CreateLaunchArg(__pBundle, argText);
114 _AppArg::Construct(const IList* pList)
116 __pBundle = bundle_create();
117 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
119 return CreateLaunchArg(__pBundle, pList);
124 _AppArg::Construct(const _AppControlImpl& ac, const IList* pList)
126 __pBundle = bundle_create();
127 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
129 return CreateAppControlArg(__pBundle, ac, pList);
134 _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String* pMime, const IMap* pList)
136 __pBundle = bundle_create();
137 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
139 return CreateAppControlArg(__pBundle, ac, pUri, pMime, pList);
144 _AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
146 __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
147 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
149 return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
154 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
156 __pBundle = bundle_create();
157 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
159 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
164 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
166 __pBundle = bundle_create();
167 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
169 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
174 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
176 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
177 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
179 return CreateResultArg(__pBundle, pList);
184 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
186 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
187 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
189 return CreateResultArg(__pBundle, pMap);
194 _AppArg::Construct(bundle* b)
196 __pBundle = bundle_dup(b);
197 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
204 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
206 __pBundle = bundle_create();
207 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
209 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
213 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
215 __pBundle = bundle_create();
216 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
218 CreateAppLaunchConditionArg(__pBundle, condition, pList);
220 return CreateResultArg(__pBundle, pMap);
224 _AppArg::GetArgListN(int num) const
226 bundle* pBundle = __pBundle;
227 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
229 ArrayList* pList = new (std::nothrow) ArrayList();
230 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
234 const char* p = NULL;
235 _AppHandler launch_type = GetHandler(pBundle);
239 case _APP_HANDLER_APPCONTROL:
241 // [FIXME] proper request Id required
242 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
245 p = appsvc_get_category(pBundle);
248 pList->Add(*new (std::nothrow) String(p));
252 pList->Add(*new (std::nothrow) String(L""));
256 p = appsvc_get_mime(pBundle);
259 pList->Add(*new (std::nothrow) String(p));
263 pList->Add(*new (std::nothrow) String(L""));
267 p = appsvc_get_uri(pBundle);
270 pList->Add(*new (std::nothrow) String(p));
274 pList->Add(*new (std::nothrow) String(L""));
279 case _APP_HANDLER_DATACONTROL:
281 AddListFromBundle(pList, pBundle, OSP_K_APPID);
283 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
285 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
287 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
290 case _APP_HANDLER_LAUNCH_COND:
291 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
292 AddListFromBundle(pList, pBundle, OSP_K_COND);
295 case _APP_HANDLER_LAUNCH_NORMAL:
296 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
297 pList->Add(*new (std::nothrow) String(L"osp.operation.MAIN"));
301 SysLog(NID_APP, "Invalid handler type");
305 SetArgList(__pBundle, pList);
312 _AppArg::GetArgListN(void) const
314 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
316 ArrayList* pList = new (std::nothrow) ArrayList();
317 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
321 SetArgList(__pBundle, pList);
326 // the returned map is allocated using SingleObjectDeleter
328 _AppArg::GetArgMapN(void) const
330 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
334 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
335 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
337 pHashMap->Construct();
339 SetArgMap(__pBundle, pHashMap);
341 if (pHashMap->GetCount() == 0)
351 IsInternalKey(const char* pKey)
353 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
358 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
363 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
372 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
374 HashMap* pMap = static_cast<HashMap*>(pData);
376 if (pKey && pVal && pMap)
378 if (IsInternalKey(pKey))
380 //SysLog(NID_APP, "(%s)", pKey);
388 case BUNDLE_TYPE_STR:
389 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
392 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
395 case BUNDLE_TYPE_STR_ARRAY:
398 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
399 if (pArr && size > 0)
401 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
406 for (size_t i = 0; i < size; i++)
408 // type unsafe ugly static casting required
409 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
412 const int count = pList->GetCount();
415 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
416 pMap->Add(new (std::nothrow) String(pKey), pList);
420 SysLog(NID_APP, "No object for %s", pKey);
427 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
431 case BUNDLE_TYPE_BYTE:
432 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
434 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
438 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
439 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
440 result r = pBuffer->Construct(size);
441 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
443 r = pBuffer->SetArray((const byte*)pStr, 0, size);
444 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
448 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
452 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
459 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
461 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
467 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
469 // actual argument below
471 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
474 for (int i = 0; i < len; i++)
478 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
479 pList->Add(*new (std::nothrow) String(pa[i]));
484 const char* p = appsvc_get_uri(pBundle);
487 pList->Add(*new (std::nothrow) String(p));
488 SysLog(NID_APP, "argument is %s", p);
492 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_CALLER);
495 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_CALLER, p);
496 pList->Add(*new (std::nothrow) String(tmp));
497 SysLog(NID_APP, "service_caller is %s", p);
500 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_DATA);
503 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_DATA, p);
504 pList->Add(*new (std::nothrow) String(tmp));
505 SysLog(NID_APP, "service_data is set");
508 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_ID);
511 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_ID, p);
512 pList->Add(*new (std::nothrow) String(tmp));
513 SysLog(NID_APP, "client_id is %s", p);
516 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET);
519 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET, p);
520 pList->Add(*new (std::nothrow) String(tmp));
521 SysLog(NID_APP, "client_secret is %s", p);
524 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY);
527 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY, p);
528 pList->Add(*new (std::nothrow) String(tmp));
529 SysLog(NID_APP, "service_category is %s", p);
537 _AppArg::GetValue(const char* key) const
539 const char* p = appsvc_get_data(__pBundle, key);
545 _AppArg::GetHandler(bundle* b)
547 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
549 const char* p = null;
551 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
555 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
557 return _APP_HANDLER_DATACONTROL;
560 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
562 SysLog(NID_APP, "Building AppControl arguments.");
564 return _APP_HANDLER_APPCONTROL;
568 // not appcontrol nor datacontrol => normal launch or condlaunch
569 p = appsvc_get_data(b, OSP_K_COND);
572 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
573 return _APP_HANDLER_LAUNCH_COND;
577 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
578 return _APP_HANDLER_LAUNCH_NORMAL;
584 return _APP_HANDLER_APPCONTROL;
589 _AppArg::GetCallerPid(bundle* pBundle)
591 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
592 if (pBundleValue == NULL)
594 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
597 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
599 return atoi(pBundleValue);
604 _AppArg::GetCallerAppId(void) const
606 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
608 return String(pBundleValue);
613 _AppArg::GetCalleeAppId(void) const
615 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
617 const AppId retVal = pBundleValue;
619 return _Aul::GetRealAppId(retVal);
624 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
626 bundle* pBundle = bk;
628 const char* p = appsvc_get_data(pBundle, key);
631 pList->Add(*new (std::nothrow) String(p));
635 pList->Add(*new (std::nothrow) String(L""));
641 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
643 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
645 return AddStrArray(b, pKey.get(), pList);
650 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
652 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
654 if (pList == null || pList->GetCount() == 0)
656 SysLog(NID_APP, "No element added for bundle.");
660 _AppMessageImpl::AddValueArray(pb, key, pList);
662 _AppMessageImpl::AddData(pb, pList);
669 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
672 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
674 if (pMap == null || pMap->GetCount() == 0)
676 SysLog(NID_APP, "No element added for bundle.");
680 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
681 while(pEnum->MoveNext() == E_SUCCESS)
683 const String* pKey = static_cast<const String*>(pEnum->GetKey());
684 const Object* pObj = pEnum->GetValue();
688 if (typeid(*pObj) == typeid(const String))
690 const String* pVal = static_cast<const String*>(pEnum->GetValue());
693 _AppMessageImpl::AddData(pb, *pKey, *pVal);
696 else if (typeid(*pObj) == typeid(const ArrayList))
698 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
701 SysLog(NID_APP, "ArrayList type");
703 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
706 else if (typeid(*pObj) == typeid(const ByteBuffer))
708 SysLog(NID_APP, "ByteBuffer type");
709 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
711 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
712 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
722 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
724 if (pMap == null || pList == null)
729 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
730 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
734 while (pEnum->MoveNext() == E_SUCCESS)
736 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
739 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
743 pStr->SubString(0, index, key);
749 pStr->SubString(index + 1, value);
751 pMap->Add(new String(key), new String(value));
753 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
761 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
765 case APP_CTRL_RESULT_SUCCEEDED:
766 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
768 case APP_CTRL_RESULT_CANCELED:
769 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
771 case APP_CTRL_RESULT_TERMINATED:
772 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
774 case APP_CTRL_RESULT_ABORTED:
775 list.Add(* new (std::nothrow) String("aborted"));
777 //case APP_CTRL_RESULT_FAILED:
779 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
788 bool isPathRegistered = false;
789 // handle APP_CTRL_RESULT_SUCCEEDED only
790 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
792 while(pMapEnum->MoveNext() == E_SUCCESS)
794 String* pKey = static_cast<String*>(pMapEnum->GetKey());
797 SysLog(NID_APP, "Invalid entry.");
801 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
803 if (!isPathRegistered)
805 isPathRegistered = true;
809 SysLog(NID_APP, "Selected path key is already registered.");
814 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
817 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
819 StringTokenizer strTok(*pVal, L';');
820 if (strTok.GetTokenCount() == 0)
822 list.Add(* new (std::nothrow) String(*pVal));
827 while(strTok.HasMoreTokens())
829 strTok.GetNextToken(token);
830 list.Add(* new (std::nothrow) String(token));
831 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
842 _AppArg::GetListN(bundle* b, const char* key)
850 const char** pValArray = null;
853 pValArray = appsvc_get_data_array(b, key, &len);
854 if (len == 0 || pValArray == null)
859 ArrayList* pList = new (std::nothrow) ArrayList;
860 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
864 for (int i = 0; i < len; i++)
866 pList->Add(*new (std::nothrow) String(pValArray[i]));
874 _AppArg::CreateLaunchArg(bundle* b, const String& arg)
876 SysAssertf(b != null, "Valid bundle should be supplied");
882 const char** pSa = new (std::nothrow) const char*[1];
883 SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Insufficient memory.");
884 pSa[0] = _StringConverter::CopyToCharArrayN(arg);
885 bundle_add_str_array(pb, OSP_K_ARG, pSa, 1);
887 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pSa[0]);
893 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
900 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
902 SysAssertf(b != null, "Valid bundle should be supplied");
906 AddStrArray(pb, OSP_K_ARG, pList);
908 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
915 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
917 SysAssertf(b != null, "Valid bundle should be supplied");
922 AddStrArray(pb, OSP_K_ARG, pList);
924 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
927 bundle_add(pb, OSP_K_COND, p.get());
930 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
937 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
939 SysAssertf(b != null, "Valid bundle should be supplied");
943 AddStrArray(pb, OSP_K_ARG, pList);
945 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
948 appsvc_set_operation(pb, pOperation.get());
951 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
958 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
960 return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
965 _AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
967 SysAssertf(b != null, "Valid bundle should be supplied");
971 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
972 if (pOperation.get())
974 appsvc_set_operation(pb, pOperation.get());
979 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
982 appsvc_set_uri(pb, pUri.get());
988 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
991 appsvc_set_mime(pb, pMime.get());
997 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
1005 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
1008 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
1009 const IList* pArgList)
1011 SysAssertf(b != null, "Valid bundle should be supplied");
1013 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1015 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1016 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
1017 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1018 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
1019 bundle_add(b, AUL_K_NO_CANCEL, "1");
1021 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1024 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1027 AddStrArray(b, OSP_K_ARG, pArgList);
1034 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
1035 const IList* pArgList)
1037 SysAssertf(b != null, "Valid bundle should be supplied");
1039 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1041 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1042 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
1043 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1044 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
1045 bundle_add(b, AUL_K_NO_CANCEL, "1");
1047 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1050 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1053 AddStrArray(b, OSP_K_ARG, pArgList);
1060 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1062 SysAssertf(b != null, "Valid bundle should be supplied");
1066 AddStrArray(pb, OSP_K_ARG, pList);
1068 _AppMessageImpl::AddData(pb, pList);
1075 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1077 SysAssertf(b != null, "Valid bundle should be supplied");
1081 AddStrMap(pb, pMap);
1088 _AppArg::CreateBundleFromSvc(void* svc)
1090 bundle* pBundle = GetBundleFromSvc(svc);
1093 return bundle_dup(pBundle);
1101 _AppArg::GetBundleFromSvc(void* svc)
1110 DummyS* pDummy = static_cast<DummyS*>(svc);
1112 if (pDummy && pDummy->pData)
1114 return pDummy->pData;
1122 _AppArg::GetRequestId(int num)
1125 str.Format(10, L"req%05d", num);
1131 _AppArg::GetRequestId(const String& str)
1136 result r = str.SubString(3, sub);
1137 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1139 r = Integer::Parse(sub, i);
1140 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1147 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1149 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1151 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1152 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1154 int res = bundle_add(b, OSP_K_APPID, pId.get());
1155 if (res < 0 && errno == EPERM) // key exists
1157 bundle_del(b, OSP_K_APPID);
1158 bundle_add(b, OSP_K_APPID, pId.get());
1161 appsvc_set_appid(b, pId.get());
1166 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1168 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1172 //SysLog(NID_APP, "Requested ID is %d", reqId);
1176 char buffer[32] = {0, };
1177 snprintf(buffer, 32, "%d", reqId);
1178 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1179 if (res < 0 && errno == EPERM) // key exists
1181 bundle_del(pBundle, OSP_K_REQUEST_ID);
1182 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1187 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1189 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1191 char pBuffer[128] = {0, };
1192 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1193 int res = bundle_add(pBundle, pKey, pBuffer);
1194 if (res < 0 && errno == EPERM) // key exists
1196 bundle_del(pBundle, pKey);
1197 bundle_add(pBundle, pKey, pBuffer);
1202 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1204 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1211 return (i < 0) ? -1 : i;
1216 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1218 appsvc_allow_transient_app(pBundle, handle);
1220 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1227 _AppArg::PrintSvcHandle(void* svc)
1229 service_h service = static_cast<service_h>(svc);
1231 if (service == null)
1236 Print(GetBundleFromSvc(service));
1241 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1249 case BUNDLE_TYPE_STR:
1250 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1253 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1257 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1264 _AppArg::Print(bundle* b)
1271 const char* p = null;
1272 p = appsvc_get_data(b, AUL_K_CALLER_PID);
1275 SysLog(NID_APP, "CallerPId[%s]", p);
1278 p = appsvc_get_data(b, AUL_K_WAIT_RESULT);
1281 SysLog(NID_APP, "WaitResult[%s]", p);
1284 p = appsvc_get_data(b, OSP_K_COND);
1287 SysLog(NID_APP, "Condition[%s]", p);
1290 p = appsvc_get_operation(b);
1293 SysLog(NID_APP, "operation[%s]", p);
1296 p = appsvc_get_uri(b);
1299 SysLog(NID_APP, "uri[%s]", p);
1302 p = appsvc_get_mime(b);
1305 SysLog(NID_APP, "mime[%s]", p);
1308 p = appsvc_get_category(b);
1311 SysLog(NID_APP, "Category[%s]", p);
1314 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1317 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1320 for (int i = 0; i < len; i++)
1324 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);