2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FApp_AppArg.cpp
20 * @brief This is the implementation for the _AppArg.cpp class.
28 #include <unique_ptr.h>
32 #include <appsvc/appsvc.h>
35 #include <FBaseInteger.h>
36 #include <FBaseColArrayList.h>
37 #include <FBaseColHashMap.h>
38 #include <FBaseUtilStringTokenizer.h>
40 #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"
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 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 _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
145 __pBundle = bundle_create();
146 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
148 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
153 _AppArg::Construct(const _MapDataControlImpl& 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 CreateMapDataControlArg(__pBundle, dc, requestType, pList);
163 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
165 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
166 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
168 return CreateResultArg(__pBundle, pList);
173 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
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, pMap);
183 _AppArg::Construct(bundle* b)
185 __pBundle = bundle_dup(b);
186 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
193 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
195 __pBundle = bundle_create();
196 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
198 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
202 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
204 __pBundle = bundle_create();
205 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
207 CreateAppLaunchConditionArg(__pBundle, condition, pList);
209 return CreateResultArg(__pBundle, pMap);
213 _AppArg::GetArgListN(int num) const
215 bundle* pBundle = __pBundle;
216 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
218 ArrayList* pList = new (std::nothrow) ArrayList();
219 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
223 const char* p = NULL;
224 _AppHandler launch_type = GetHandler(pBundle);
228 case _APP_HANDLER_APPCONTROL:
230 // [FIXME] proper request Id required
231 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
234 p = appsvc_get_category(pBundle);
237 pList->Add(*new (std::nothrow) String(p));
241 pList->Add(*new (std::nothrow) String(L""));
245 p = appsvc_get_mime(pBundle);
248 pList->Add(*new (std::nothrow) String(p));
252 pList->Add(*new (std::nothrow) String(L""));
256 p = appsvc_get_uri(pBundle);
259 pList->Add(*new (std::nothrow) String(p));
263 pList->Add(*new (std::nothrow) String(L""));
268 case _APP_HANDLER_DATACONTROL:
270 AddListFromBundle(pList, pBundle, OSP_K_APPID);
272 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
274 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
276 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
279 case _APP_HANDLER_LAUNCH_COND:
280 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
281 AddListFromBundle(pList, pBundle, OSP_K_COND);
284 case _APP_HANDLER_LAUNCH_NORMAL:
285 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
286 pList->Add(*new (std::nothrow) String(L"osp.operation.MAIN"));
290 SysLog(NID_APP, "Invalid handler type");
294 SetArgList(__pBundle, pList);
301 _AppArg::GetArgListN(void) const
303 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
305 ArrayList* pList = new (std::nothrow) ArrayList();
306 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
310 SetArgList(__pBundle, pList);
315 // the returned map is allocated using SingleObjectDeleter
317 _AppArg::GetArgMapN(void) const
319 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
321 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
322 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
324 pHashMap->Construct();
326 SetArgMap(__pBundle, pHashMap);
328 if (pHashMap->GetCount() == 0)
334 ArrayList* pList = _AppMessageImpl::GetValueArray(__pBundle, OSP_K_ARG);
337 pHashMap->Add(new (std::nothrow) String(TIZEN_APPCONTROL_DATA_LEGACY), pList);
343 IsInternalKey(const char* pKey)
345 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
350 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
355 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
364 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
366 HashMap* pMap = static_cast<HashMap*>(pData);
368 if (pKey && pVal && pMap)
370 if (IsInternalKey(pKey))
372 //SysLog(NID_APP, "(%s)", pKey);
380 case BUNDLE_TYPE_STR:
381 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
384 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
387 case BUNDLE_TYPE_STR_ARRAY:
390 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
391 if (pArr && size > 0)
393 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
398 for (size_t i = 0; i < size; i++)
400 // type unsafe ugly static casting required
401 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
404 const int count = pList->GetCount();
407 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
408 pMap->Add(new (std::nothrow) String(pKey), pList);
412 SysLog(NID_APP, "No object for %s", pKey);
419 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
424 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
431 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
433 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
439 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
441 // actual argument below
443 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
446 for (int i = 0; i < len; i++)
450 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
451 pList->Add(*new (std::nothrow) String(pa[i]));
456 const char* p = appsvc_get_uri(pBundle);
459 pList->Add(*new (std::nothrow) String(p));
460 SysLog(NID_APP, "argument is %s", p);
464 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_CALLER);
467 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_CALLER, p);
468 pList->Add(*new (std::nothrow) String(tmp));
469 SysLog(NID_APP, "service_caller is %s", p);
472 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_DATA);
475 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_DATA, p);
476 pList->Add(*new (std::nothrow) String(tmp));
477 SysLog(NID_APP, "service_data is set");
480 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_ID);
483 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_ID, p);
484 pList->Add(*new (std::nothrow) String(tmp));
485 SysLog(NID_APP, "client_id is %s", p);
488 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET);
491 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET, p);
492 pList->Add(*new (std::nothrow) String(tmp));
493 SysLog(NID_APP, "client_secret is %s", p);
496 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY);
499 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY, p);
500 pList->Add(*new (std::nothrow) String(tmp));
501 SysLog(NID_APP, "service_category is %s", p);
509 _AppArg::GetValue(const char* key) const
511 const char* p = appsvc_get_data(__pBundle, key);
517 _AppArg::GetHandler(bundle* b)
519 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
521 const char* p = null;
523 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
527 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
529 return _APP_HANDLER_DATACONTROL;
532 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
534 SysLog(NID_APP, "Building AppControl arguments.");
536 return _APP_HANDLER_APPCONTROL;
540 // not appcontrol nor datacontrol => normal launch or condlaunch
541 p = appsvc_get_data(b, OSP_K_COND);
544 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
545 return _APP_HANDLER_LAUNCH_COND;
549 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
550 return _APP_HANDLER_LAUNCH_NORMAL;
556 return _APP_HANDLER_APPCONTROL;
561 _AppArg::GetCallerPid(bundle* pBundle)
563 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
564 if (pBundleValue == NULL)
566 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
569 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
571 return atoi(pBundleValue);
576 _AppArg::GetCallerAppId(void) const
578 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
580 return String(pBundleValue);
585 _AppArg::GetCalleeAppId(void) const
587 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
589 String retVal = pBundleValue;
592 // [INFO] ugly code for submode callee
593 retVal.SubString(11, temp);
594 if (temp == L"_AppControl")
597 retVal.SubString(0, 10, id);
598 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(id);
600 retVal = id + L'.' + name;
601 SysLog(NID_APP, "Converted caller Id is %ls", retVal.GetPointer());
609 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
611 bundle* pBundle = bk;
613 const char* p = appsvc_get_data(pBundle, key);
616 pList->Add(*new (std::nothrow) String(p));
620 pList->Add(*new (std::nothrow) String(L""));
626 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
628 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
630 return AddStrArray(b, pKey.get(), pList);
635 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
637 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
639 if (pList == null || pList->GetCount() == 0)
641 SysLog(NID_APP, "No element added for bundle.");
645 _AppMessageImpl::AddValueArray(pb, key, pList);
647 _AppMessageImpl::AddData(pb, pList);
654 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
657 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
659 if (pMap == null || pMap->GetCount() == 0)
661 SysLog(NID_APP, "No element added for bundle.");
665 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
666 while(pEnum->MoveNext() == E_SUCCESS)
668 const String* pKey = static_cast<const String*>(pEnum->GetKey());
669 const Object* pObj = pEnum->GetValue();
673 if (typeid(*pObj) == typeid(const String))
675 const String* pVal = static_cast<const String*>(pEnum->GetValue());
678 _AppMessageImpl::AddData(pb, *pKey, *pVal);
681 else if (typeid(*pObj) == typeid(const ArrayList))
683 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
686 SysLog(NID_APP, "ArrayList type");
688 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
691 else if (typeid(*pObj) == typeid(const ByteBuffer))
693 SysLog(NID_APP, "ByteBuffer type");
703 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
705 if (pMap == null || pList == null)
710 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
711 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
715 while (pEnum->MoveNext() == E_SUCCESS)
717 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
720 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
724 pStr->SubString(0, index, key);
730 pStr->SubString(index + 1, value);
732 pMap->Add(new String(key), new String(value));
734 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
742 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
746 case APP_CTRL_RESULT_SUCCEEDED:
747 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
749 case APP_CTRL_RESULT_CANCELED:
750 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
752 case APP_CTRL_RESULT_TERMINATED:
753 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
755 case APP_CTRL_RESULT_ABORTED:
756 list.Add(* new (std::nothrow) String("aborted"));
758 //case APP_CTRL_RESULT_FAILED:
760 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
769 bool isPathRegistered = false;
770 // handle APP_CTRL_RESULT_SUCCEEDED only
771 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
773 while(pMapEnum->MoveNext() == E_SUCCESS)
775 String* pKey = static_cast<String*>(pMapEnum->GetKey());
778 SysLog(NID_APP, "Invalid entry.");
782 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
784 if (!isPathRegistered)
786 isPathRegistered = true;
790 SysLog(NID_APP, "Selected path key is already registered.");
795 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
798 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
800 StringTokenizer strTok(*pVal, L';');
801 if (strTok.GetTokenCount() == 0)
803 list.Add(* new (std::nothrow) String(*pVal));
808 while(strTok.HasMoreTokens())
810 strTok.GetNextToken(token);
811 list.Add(* new (std::nothrow) String(token));
812 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
823 _AppArg::GetListN(bundle* b, const char* key)
831 const char** pValArray = null;
834 pValArray = appsvc_get_data_array(b, key, &len);
835 if (len == 0 || pValArray == null)
840 ArrayList* pList = new (std::nothrow) ArrayList;
841 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
845 for (int i = 0; i < len; i++)
847 pList->Add(*new (std::nothrow) String(pValArray[i]));
855 _AppArg::CreateLaunchArg(bundle* b, const String& arg)
857 SysAssertf(b != null, "Valid bundle should be supplied");
863 const char** pSa = new (std::nothrow) const char*[1];
864 SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Insufficient memory.");
865 pSa[0] = _StringConverter::CopyToCharArrayN(arg);
866 bundle_add_str_array(pb, OSP_K_ARG, pSa, 1);
868 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pSa[0]);
874 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
881 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
883 SysAssertf(b != null, "Valid bundle should be supplied");
887 AddStrArray(pb, OSP_K_ARG, pList);
889 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
896 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
898 SysAssertf(b != null, "Valid bundle should be supplied");
903 AddStrArray(pb, OSP_K_ARG, pList);
905 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
908 bundle_add(pb, OSP_K_COND, p.get());
911 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
918 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
920 SysAssertf(b != null, "Valid bundle should be supplied");
924 AddStrArray(pb, OSP_K_ARG, pList);
926 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
929 appsvc_set_operation(pb, pOperation.get());
932 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
939 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pList)
941 SysAssertf(b != null, "Valid bundle should be supplied");
945 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
946 if (pOperation.get())
948 appsvc_set_operation(pb, pOperation.get());
953 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
956 appsvc_set_uri(pb, pUri.get());
962 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
965 appsvc_set_mime(pb, pMime.get());
969 AddStrMap(pb, pList);
971 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
979 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
982 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
983 const IList* pArgList)
985 SysAssertf(b != null, "Valid bundle should be supplied");
987 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
989 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
990 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
991 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
993 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
996 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
999 AddStrArray(b, OSP_K_ARG, pArgList);
1006 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
1007 const IList* pArgList)
1009 SysAssertf(b != null, "Valid bundle should be supplied");
1011 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1013 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1014 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
1015 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1017 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1020 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1023 AddStrArray(b, OSP_K_ARG, pArgList);
1030 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1032 SysAssertf(b != null, "Valid bundle should be supplied");
1036 AddStrArray(pb, OSP_K_ARG, pList);
1038 _AppMessageImpl::AddData(pb, pList);
1045 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1047 SysAssertf(b != null, "Valid bundle should be supplied");
1051 AddStrMap(pb, pMap);
1058 _AppArg::CreateBundleFromSvc(void* svc)
1060 bundle* pBundle = GetBundleFromSvc(svc);
1063 return bundle_dup(pBundle);
1071 _AppArg::GetBundleFromSvc(void* svc)
1080 DummyS* pDummy = static_cast<DummyS*>(svc);
1082 if (pDummy && pDummy->pData)
1084 return pDummy->pData;
1092 _AppArg::GetRequestId(int num)
1095 str.Format(10, L"req%05d", num);
1101 _AppArg::GetRequestId(const String& str)
1106 result r = str.SubString(3, sub);
1107 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1109 r = Integer::Parse(sub, i);
1110 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1117 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1119 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1121 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1122 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1124 bundle_add(b, OSP_K_APPID, pId.get());
1126 appsvc_set_appid(b, pId.get());
1131 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1133 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1137 //SysLog(NID_APP, "Requested ID is %d", reqId);
1141 char buffer[32] = {0, };
1142 snprintf(buffer, 32, "%d", reqId);
1143 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1148 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1150 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1157 return (i < 0) ? -1 : i;
1162 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1164 appsvc_allow_transient_app(pBundle, handle);
1166 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1173 _AppArg::PrintSvcHandle(void* svc)
1175 service_h service = static_cast<service_h>(svc);
1177 if (service == null)
1182 Print(GetBundleFromSvc(service));
1187 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1195 case BUNDLE_TYPE_STR:
1196 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1199 SysLog(NID_APP, "(%s, %s)", pKey, pStr);
1203 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1210 _AppArg::Print(bundle* b)
1217 const char* p = null;
1218 p = appsvc_get_data(b, AUL_K_CALLER_PID);
1221 SysLog(NID_APP, "CallerPId[%s]", p);
1224 p = appsvc_get_data(b, AUL_K_WAIT_RESULT);
1227 SysLog(NID_APP, "WaitResult[%s]", p);
1230 p = appsvc_get_data(b, OSP_K_COND);
1233 SysLog(NID_APP, "Condition[%s]", p);
1236 p = appsvc_get_operation(b);
1239 SysLog(NID_APP, "operation[%s]", p);
1242 p = appsvc_get_uri(b);
1245 SysLog(NID_APP, "uri[%s]", p);
1248 p = appsvc_get_mime(b);
1251 SysLog(NID_APP, "mime[%s]", p);
1254 p = appsvc_get_category(b);
1257 SysLog(NID_APP, "Category[%s]", p);
1260 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1263 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1266 for (int i = 0; i < len; i++)
1270 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);