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"
48 #include "FAppPkg_PackageManagerImpl.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Base::Utility;
53 using namespace Tizen::App::Package;
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";
74 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
75 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
76 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
77 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
79 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_ID[] = "client_id";
80 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET[] = "client_secret";
81 static const char SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY[] = "service_category";
83 static const char SMS_KEY_SERVICE_CALLER[] = "service_caller";
84 static const char SMS_KEY_SERVICE_DATA[] = "service_data";
87 _AppArg::_AppArg(void)
93 _AppArg::~_AppArg(void)
97 bundle_free(__pBundle);
103 _AppArg::Construct(const String& argText)
105 __pBundle = bundle_create();
106 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
108 return CreateLaunchArg(__pBundle, argText);
113 _AppArg::Construct(const IList* pList)
115 __pBundle = bundle_create();
116 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
118 return CreateLaunchArg(__pBundle, pList);
123 _AppArg::Construct(const _AppControlImpl& ac, const IList* pList)
125 __pBundle = bundle_create();
126 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
128 return CreateAppControlArg(__pBundle, ac, pList);
133 _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String* pMime, const IMap* pList)
135 __pBundle = bundle_create();
136 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
138 return CreateAppControlArg(__pBundle, ac, pUri, pMime, pList);
143 _AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
145 __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
146 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
148 return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
153 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
155 __pBundle = bundle_create();
156 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
158 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
163 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
165 __pBundle = bundle_create();
166 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
168 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
173 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
175 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
176 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
178 return CreateResultArg(__pBundle, pList);
183 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
185 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
186 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
188 return CreateResultArg(__pBundle, pMap);
193 _AppArg::Construct(bundle* b)
195 __pBundle = bundle_dup(b);
196 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
203 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
205 __pBundle = bundle_create();
206 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
208 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
212 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
214 __pBundle = bundle_create();
215 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
217 CreateAppLaunchConditionArg(__pBundle, condition, pList);
219 return CreateResultArg(__pBundle, pMap);
223 _AppArg::GetArgListN(int num) const
225 bundle* pBundle = __pBundle;
226 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
228 ArrayList* pList = new (std::nothrow) ArrayList();
229 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
233 const char* p = NULL;
234 _AppHandler launch_type = GetHandler(pBundle);
238 case _APP_HANDLER_APPCONTROL:
240 // [FIXME] proper request Id required
241 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
244 p = appsvc_get_category(pBundle);
247 pList->Add(*new (std::nothrow) String(p));
251 pList->Add(*new (std::nothrow) String(L""));
255 p = appsvc_get_mime(pBundle);
258 pList->Add(*new (std::nothrow) String(p));
262 pList->Add(*new (std::nothrow) String(L""));
266 p = appsvc_get_uri(pBundle);
269 pList->Add(*new (std::nothrow) String(p));
273 pList->Add(*new (std::nothrow) String(L""));
278 case _APP_HANDLER_DATACONTROL:
280 AddListFromBundle(pList, pBundle, OSP_K_APPID);
282 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
284 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
286 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
289 case _APP_HANDLER_LAUNCH_COND:
290 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
291 AddListFromBundle(pList, pBundle, OSP_K_COND);
294 case _APP_HANDLER_LAUNCH_NORMAL:
295 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
296 pList->Add(*new (std::nothrow) String(L"osp.operation.MAIN"));
300 SysLog(NID_APP, "Invalid handler type");
304 SetArgList(__pBundle, pList);
311 _AppArg::GetArgListN(void) const
313 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
315 ArrayList* pList = new (std::nothrow) ArrayList();
316 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
320 SetArgList(__pBundle, pList);
325 // the returned map is allocated using SingleObjectDeleter
327 _AppArg::GetArgMapN(void) const
329 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
333 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
334 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
336 pHashMap->Construct();
338 SetArgMap(__pBundle, pHashMap);
340 if (pHashMap->GetCount() == 0)
350 IsInternalKey(const char* pKey)
352 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
357 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
362 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
371 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
373 HashMap* pMap = static_cast<HashMap*>(pData);
375 if (pKey && pVal && pMap)
377 if (IsInternalKey(pKey))
379 //SysLog(NID_APP, "(%s)", pKey);
387 case BUNDLE_TYPE_STR:
388 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
391 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
394 case BUNDLE_TYPE_STR_ARRAY:
397 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
398 if (pArr && size > 0)
400 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
405 for (size_t i = 0; i < size; i++)
407 // type unsafe ugly static casting required
408 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
411 const int count = pList->GetCount();
414 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
415 pMap->Add(new (std::nothrow) String(pKey), pList);
419 SysLog(NID_APP, "No object for %s", pKey);
426 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
430 case BUNDLE_TYPE_BYTE:
431 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
433 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
437 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
438 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
439 result r = pBuffer->Construct(size);
440 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
442 r = pBuffer->SetArray((const byte*)pStr, 0, size);
443 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
447 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
451 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
458 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
460 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
466 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
468 // actual argument below
470 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
473 for (int i = 0; i < len; i++)
477 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
478 pList->Add(*new (std::nothrow) String(pa[i]));
483 const char* p = appsvc_get_uri(pBundle);
486 pList->Add(*new (std::nothrow) String(p));
487 SysLog(NID_APP, "argument is %s", p);
491 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_CALLER);
494 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_CALLER, p);
495 pList->Add(*new (std::nothrow) String(tmp));
496 SysLog(NID_APP, "service_caller is %s", p);
499 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_DATA);
502 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_DATA, p);
503 pList->Add(*new (std::nothrow) String(tmp));
504 SysLog(NID_APP, "service_data is set");
507 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_ID);
510 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_ID, p);
511 pList->Add(*new (std::nothrow) String(tmp));
512 SysLog(NID_APP, "client_id is %s", p);
515 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET);
518 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET, p);
519 pList->Add(*new (std::nothrow) String(tmp));
520 SysLog(NID_APP, "client_secret is %s", p);
523 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY);
526 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY, p);
527 pList->Add(*new (std::nothrow) String(tmp));
528 SysLog(NID_APP, "service_category is %s", p);
536 _AppArg::GetValue(const char* key) const
538 const char* p = appsvc_get_data(__pBundle, key);
544 _AppArg::GetHandler(bundle* b)
546 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
548 const char* p = null;
550 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
554 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
556 return _APP_HANDLER_DATACONTROL;
559 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
561 SysLog(NID_APP, "Building AppControl arguments.");
563 return _APP_HANDLER_APPCONTROL;
567 // not appcontrol nor datacontrol => normal launch or condlaunch
568 p = appsvc_get_data(b, OSP_K_COND);
571 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
572 return _APP_HANDLER_LAUNCH_COND;
576 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
577 return _APP_HANDLER_LAUNCH_NORMAL;
583 return _APP_HANDLER_APPCONTROL;
588 _AppArg::GetCallerPid(bundle* pBundle)
590 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
591 if (pBundleValue == NULL)
593 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
596 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
598 return atoi(pBundleValue);
603 _AppArg::GetCallerAppId(void) const
605 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
607 return String(pBundleValue);
612 _AppArg::GetCalleeAppId(void) const
614 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
616 String retVal = pBundleValue;
619 // [INFO] ugly code for submode callee
620 retVal.SubString(11, temp);
621 if (temp == L"_AppControl")
624 retVal.SubString(0, 10, id);
625 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(id);
627 retVal = id + L'.' + name;
628 SysLog(NID_APP, "Converted caller Id is %ls", retVal.GetPointer());
636 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
638 bundle* pBundle = bk;
640 const char* p = appsvc_get_data(pBundle, key);
643 pList->Add(*new (std::nothrow) String(p));
647 pList->Add(*new (std::nothrow) String(L""));
653 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
655 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
657 return AddStrArray(b, pKey.get(), pList);
662 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
664 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
666 if (pList == null || pList->GetCount() == 0)
668 SysLog(NID_APP, "No element added for bundle.");
672 _AppMessageImpl::AddValueArray(pb, key, pList);
674 _AppMessageImpl::AddData(pb, pList);
681 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
684 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
686 if (pMap == null || pMap->GetCount() == 0)
688 SysLog(NID_APP, "No element added for bundle.");
692 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
693 while(pEnum->MoveNext() == E_SUCCESS)
695 const String* pKey = static_cast<const String*>(pEnum->GetKey());
696 const Object* pObj = pEnum->GetValue();
700 if (typeid(*pObj) == typeid(const String))
702 const String* pVal = static_cast<const String*>(pEnum->GetValue());
705 _AppMessageImpl::AddData(pb, *pKey, *pVal);
708 else if (typeid(*pObj) == typeid(const ArrayList))
710 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
713 SysLog(NID_APP, "ArrayList type");
715 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
718 else if (typeid(*pObj) == typeid(const ByteBuffer))
720 SysLog(NID_APP, "ByteBuffer type");
721 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
723 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
724 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
734 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
736 if (pMap == null || pList == null)
741 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
742 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
746 while (pEnum->MoveNext() == E_SUCCESS)
748 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
751 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
755 pStr->SubString(0, index, key);
761 pStr->SubString(index + 1, value);
763 pMap->Add(new String(key), new String(value));
765 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
773 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
777 case APP_CTRL_RESULT_SUCCEEDED:
778 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
780 case APP_CTRL_RESULT_CANCELED:
781 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
783 case APP_CTRL_RESULT_TERMINATED:
784 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
786 case APP_CTRL_RESULT_ABORTED:
787 list.Add(* new (std::nothrow) String("aborted"));
789 //case APP_CTRL_RESULT_FAILED:
791 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
800 bool isPathRegistered = false;
801 // handle APP_CTRL_RESULT_SUCCEEDED only
802 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
804 while(pMapEnum->MoveNext() == E_SUCCESS)
806 String* pKey = static_cast<String*>(pMapEnum->GetKey());
809 SysLog(NID_APP, "Invalid entry.");
813 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
815 if (!isPathRegistered)
817 isPathRegistered = true;
821 SysLog(NID_APP, "Selected path key is already registered.");
826 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
829 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
831 StringTokenizer strTok(*pVal, L';');
832 if (strTok.GetTokenCount() == 0)
834 list.Add(* new (std::nothrow) String(*pVal));
839 while(strTok.HasMoreTokens())
841 strTok.GetNextToken(token);
842 list.Add(* new (std::nothrow) String(token));
843 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
854 _AppArg::GetListN(bundle* b, const char* key)
862 const char** pValArray = null;
865 pValArray = appsvc_get_data_array(b, key, &len);
866 if (len == 0 || pValArray == null)
871 ArrayList* pList = new (std::nothrow) ArrayList;
872 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
876 for (int i = 0; i < len; i++)
878 pList->Add(*new (std::nothrow) String(pValArray[i]));
886 _AppArg::CreateLaunchArg(bundle* b, const String& arg)
888 SysAssertf(b != null, "Valid bundle should be supplied");
894 const char** pSa = new (std::nothrow) const char*[1];
895 SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Insufficient memory.");
896 pSa[0] = _StringConverter::CopyToCharArrayN(arg);
897 bundle_add_str_array(pb, OSP_K_ARG, pSa, 1);
899 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pSa[0]);
905 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
912 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
914 SysAssertf(b != null, "Valid bundle should be supplied");
918 AddStrArray(pb, OSP_K_ARG, pList);
920 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
927 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
929 SysAssertf(b != null, "Valid bundle should be supplied");
934 AddStrArray(pb, OSP_K_ARG, pList);
936 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
939 bundle_add(pb, OSP_K_COND, p.get());
942 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
949 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
951 SysAssertf(b != null, "Valid bundle should be supplied");
955 AddStrArray(pb, OSP_K_ARG, pList);
957 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
960 appsvc_set_operation(pb, pOperation.get());
963 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
970 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
972 return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
977 _AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
979 SysAssertf(b != null, "Valid bundle should be supplied");
983 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
984 if (pOperation.get())
986 appsvc_set_operation(pb, pOperation.get());
991 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
994 appsvc_set_uri(pb, pUri.get());
1000 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
1003 appsvc_set_mime(pb, pMime.get());
1007 AddStrMap(pb, pMap);
1009 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
1017 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
1020 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
1021 const IList* pArgList)
1023 SysAssertf(b != null, "Valid bundle should be supplied");
1025 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1027 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1028 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
1029 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1030 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
1031 bundle_add(b, AUL_K_NO_CANCEL, "1");
1033 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1036 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1039 AddStrArray(b, OSP_K_ARG, pArgList);
1046 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
1047 const IList* pArgList)
1049 SysAssertf(b != null, "Valid bundle should be supplied");
1051 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1053 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1054 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
1055 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1056 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
1057 bundle_add(b, AUL_K_NO_CANCEL, "1");
1059 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1062 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1065 AddStrArray(b, OSP_K_ARG, pArgList);
1072 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1074 SysAssertf(b != null, "Valid bundle should be supplied");
1078 AddStrArray(pb, OSP_K_ARG, pList);
1080 _AppMessageImpl::AddData(pb, pList);
1087 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1089 SysAssertf(b != null, "Valid bundle should be supplied");
1093 AddStrMap(pb, pMap);
1100 _AppArg::CreateBundleFromSvc(void* svc)
1102 bundle* pBundle = GetBundleFromSvc(svc);
1105 return bundle_dup(pBundle);
1113 _AppArg::GetBundleFromSvc(void* svc)
1122 DummyS* pDummy = static_cast<DummyS*>(svc);
1124 if (pDummy && pDummy->pData)
1126 return pDummy->pData;
1134 _AppArg::GetRequestId(int num)
1137 str.Format(10, L"req%05d", num);
1143 _AppArg::GetRequestId(const String& str)
1148 result r = str.SubString(3, sub);
1149 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1151 r = Integer::Parse(sub, i);
1152 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1159 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1161 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1163 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1164 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1166 int res = bundle_add(b, OSP_K_APPID, pId.get());
1167 if (res < 0 && errno == EPERM) // key exists
1169 bundle_del(b, OSP_K_APPID);
1170 bundle_add(b, OSP_K_APPID, pId.get());
1173 appsvc_set_appid(b, pId.get());
1178 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1180 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1184 //SysLog(NID_APP, "Requested ID is %d", reqId);
1188 char buffer[32] = {0, };
1189 snprintf(buffer, 32, "%d", reqId);
1190 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1191 if (res < 0 && errno == EPERM) // key exists
1193 bundle_del(pBundle, OSP_K_REQUEST_ID);
1194 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1199 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1201 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1203 char pBuffer[128] = {0, };
1204 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1205 int res = bundle_add(pBundle, pKey, pBuffer);
1206 if (res < 0 && errno == EPERM) // key exists
1208 bundle_del(pBundle, pKey);
1209 bundle_add(pBundle, pKey, pBuffer);
1214 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1216 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1223 return (i < 0) ? -1 : i;
1228 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1230 appsvc_allow_transient_app(pBundle, handle);
1232 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1239 _AppArg::PrintSvcHandle(void* svc)
1241 service_h service = static_cast<service_h>(svc);
1243 if (service == null)
1248 Print(GetBundleFromSvc(service));
1253 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1261 case BUNDLE_TYPE_STR:
1262 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1265 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1269 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1276 _AppArg::Print(bundle* b)
1283 const char* p = null;
1284 p = appsvc_get_data(b, AUL_K_CALLER_PID);
1287 SysLog(NID_APP, "CallerPId[%s]", p);
1290 p = appsvc_get_data(b, AUL_K_WAIT_RESULT);
1293 SysLog(NID_APP, "WaitResult[%s]", p);
1296 p = appsvc_get_data(b, OSP_K_COND);
1299 SysLog(NID_APP, "Condition[%s]", p);
1302 p = appsvc_get_operation(b);
1305 SysLog(NID_APP, "operation[%s]", p);
1308 p = appsvc_get_uri(b);
1311 SysLog(NID_APP, "uri[%s]", p);
1314 p = appsvc_get_mime(b);
1317 SysLog(NID_APP, "mime[%s]", p);
1320 p = appsvc_get_category(b);
1323 SysLog(NID_APP, "Category[%s]", p);
1326 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1329 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1332 for (int i = 0; i < len; i++)
1336 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);