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>
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;
55 namespace Tizen { namespace App
58 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
59 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
60 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
61 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
62 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
63 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
64 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
65 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
66 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
67 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
68 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
69 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
70 static const char BUNDLE_KEY_WINDOW[] = "__APP_SVC_K_WIN_ID__";
71 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
72 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
73 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
74 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
76 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_ID[] = "client_id";
77 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET[] = "client_secret";
78 static const char SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY[] = "service_category";
80 static const char SMS_KEY_SERVICE_CALLER[] = "service_caller";
81 static const char SMS_KEY_SERVICE_DATA[] = "service_data";
84 _AppArg::_AppArg(void)
90 _AppArg::~_AppArg(void)
94 bundle_free(__pBundle);
100 _AppArg::Construct(const String& argText)
102 __pBundle = bundle_create();
103 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
105 return CreateLaunchArg(__pBundle, argText);
110 _AppArg::Construct(const IList* pList)
112 __pBundle = bundle_create();
113 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
115 return CreateLaunchArg(__pBundle, pList);
120 _AppArg::Construct(const _AppControlImpl& ac, const IList* pList)
122 __pBundle = bundle_create();
123 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
125 return CreateAppControlArg(__pBundle, ac, pList);
130 _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String* pMime, const IMap* pList)
132 __pBundle = bundle_create();
133 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
135 return CreateAppControlArg(__pBundle, ac, pUri, pMime, pList);
140 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
142 __pBundle = bundle_create();
143 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
145 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
150 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
152 __pBundle = bundle_create();
153 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
155 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
160 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
162 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
163 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
165 return CreateResultArg(__pBundle, pList);
170 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
172 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
173 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
175 return CreateResultArg(__pBundle, pMap);
180 _AppArg::Construct(bundle* b)
182 __pBundle = bundle_dup(b);
183 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
190 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
192 __pBundle = bundle_create();
193 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
195 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
199 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
201 __pBundle = bundle_create();
202 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
204 CreateAppLaunchConditionArg(__pBundle, condition, pList);
206 return CreateResultArg(__pBundle, pMap);
210 _AppArg::GetArgListN(int num) const
212 bundle* pBundle = __pBundle;
213 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
215 ArrayList* pList = new (std::nothrow) ArrayList();
216 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
220 const char* p = NULL;
221 _AppHandler launch_type = GetHandler(pBundle);
225 case _APP_HANDLER_APPCONTROL:
227 // [FIXME] proper request Id required
228 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
231 p = appsvc_get_category(pBundle);
234 pList->Add(*new (std::nothrow) String(p));
238 pList->Add(*new (std::nothrow) String(L""));
242 p = appsvc_get_mime(pBundle);
245 pList->Add(*new (std::nothrow) String(p));
249 pList->Add(*new (std::nothrow) String(L""));
253 p = appsvc_get_uri(pBundle);
256 pList->Add(*new (std::nothrow) String(p));
260 pList->Add(*new (std::nothrow) String(L""));
265 case _APP_HANDLER_DATACONTROL:
267 AddListFromBundle(pList, pBundle, OSP_K_APPID);
269 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
271 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
273 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
276 case _APP_HANDLER_LAUNCH_COND:
277 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
278 AddListFromBundle(pList, pBundle, OSP_K_COND);
281 case _APP_HANDLER_LAUNCH_NORMAL:
282 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
283 pList->Add(*new (std::nothrow) String(L"osp.operation.MAIN"));
287 SysLog(NID_APP, "Invalid handler type");
291 SetArgList(__pBundle, pList);
298 _AppArg::GetArgListN(void) const
300 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
302 ArrayList* pList = new (std::nothrow) ArrayList();
303 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
307 SetArgList(__pBundle, pList);
312 // the returned map is allocated using SingleObjectDeleter
314 _AppArg::GetArgMapN(void) const
316 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
318 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
319 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
321 pHashMap->Construct();
323 SetArgMap(__pBundle, pHashMap);
325 if (pHashMap->GetCount() == 0)
331 ArrayList* pList = _AppMessageImpl::GetValueArray(__pBundle, OSP_K_ARG);
334 pHashMap->Add(new (std::nothrow) String(TIZEN_APPCONTROL_DATA_LEGACY), pList);
340 IsInternalKey(const char* pKey)
342 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
347 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
352 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
361 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
363 HashMap* pMap = static_cast<HashMap*>(pData);
365 if (pKey && pVal && pMap)
367 if (IsInternalKey(pKey))
369 //SysLog(NID_APP, "(%s)", pKey);
377 case BUNDLE_TYPE_STR:
378 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
381 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
384 case BUNDLE_TYPE_STR_ARRAY:
387 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
388 if (pArr && size > 0)
390 String str = static_cast<char*>(*pArr);
391 for (size_t i = 1; i < size; i++)
394 str += static_cast<char*>(*(pArr + i));
397 SysLog(NID_APP, "(%s, %ls)", pKey, str.GetPointer());
398 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(str));
402 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
407 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
414 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
416 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
422 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
424 // actual argument below
426 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
429 for (int i = 0; i < len; i++)
433 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
434 pList->Add(*new (std::nothrow) String(pa[i]));
439 const char* p = appsvc_get_uri(pBundle);
442 pList->Add(*new (std::nothrow) String(p));
443 SysLog(NID_APP, "argument is %s", p);
447 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_CALLER);
450 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_CALLER, p);
451 pList->Add(*new (std::nothrow) String(tmp));
452 SysLog(NID_APP, "service_caller is %s", p);
455 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_DATA);
458 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_DATA, p);
459 pList->Add(*new (std::nothrow) String(tmp));
460 SysLog(NID_APP, "service_data is set");
463 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_ID);
466 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_ID, p);
467 pList->Add(*new (std::nothrow) String(tmp));
468 SysLog(NID_APP, "client_id is %s", p);
471 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET);
474 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET, p);
475 pList->Add(*new (std::nothrow) String(tmp));
476 SysLog(NID_APP, "client_secret is %s", p);
479 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY);
482 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY, p);
483 pList->Add(*new (std::nothrow) String(tmp));
484 SysLog(NID_APP, "service_category is %s", p);
492 _AppArg::GetValue(const char* key) const
494 const char* p = appsvc_get_data(__pBundle, key);
500 _AppArg::GetHandler(bundle* b)
502 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
504 const char* p = null;
506 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
510 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
512 return _APP_HANDLER_DATACONTROL;
515 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
517 SysLog(NID_APP, "Building AppControl arguments.");
519 return _APP_HANDLER_APPCONTROL;
523 // not appcontrol nor datacontrol => normal launch or condlaunch
524 p = appsvc_get_data(b, OSP_K_COND);
527 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
528 return _APP_HANDLER_LAUNCH_COND;
532 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
533 return _APP_HANDLER_LAUNCH_NORMAL;
539 return _APP_HANDLER_APPCONTROL;
544 _AppArg::GetCallerPid(bundle* pBundle)
546 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
547 if (pBundleValue == NULL)
549 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
552 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
554 return atoi(pBundleValue);
559 _AppArg::GetCallerAppId(void) const
561 pid_t callerPid = GetCallerPid();
562 SysTryReturn(NID_APP, callerPid > 0, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Wrong process id: %d.", callerPid);
564 char appId[PATH_MAX] = {0, };
565 SysTryReturn(NID_APP, aul_app_get_appid_bypid(callerPid, appId, sizeof(appId)) == AUL_R_OK, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found for %d.", callerPid);
567 return String(appId);
572 _AppArg::GetCalleeAppId(void) const
574 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_PID);
576 SysTryReturn(NID_APP, pBundleValue != null, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
578 pid_t calleePid = atoi(pBundleValue);
579 SysTryReturn(NID_APP, calleePid > 0, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Wrong process id: %d.", calleePid);
581 char appId[PATH_MAX] = {0, };
582 SysTryReturn(NID_APP, aul_app_get_appid_bypid(calleePid, appId, sizeof(appId)) == AUL_R_OK, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found for %d.", calleePid);
585 String retVal = appId;
586 // [INFO] ugly code for submode callee
587 retVal.SubString(11, temp);
588 if (temp == L"_AppControl")
591 retVal.SubString(0, 10, id);
592 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(id);
594 retVal = id + L'.' + name;
595 SysLog(NID_APP, "Converted caller Id is %ls", retVal.GetPointer());
603 _AppArg::SaveCalleeAppId(void)
605 const AppId& appId = GetCalleeAppId();
607 std::unique_ptr<char[]> pVal(_StringConverter::CopyToCharArrayN(appId));
609 appsvc_add_data(__pBundle, OSP_K_CALLEE_APPID, pVal.get());
614 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
616 bundle* pBundle = bk;
618 const char* p = appsvc_get_data(pBundle, key);
621 pList->Add(*new (std::nothrow) String(p));
625 pList->Add(*new (std::nothrow) String(L""));
631 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
633 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
635 return AddStrArray(b, pKey.get(), pList);
640 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
642 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
644 if (pList == null || pList->GetCount() == 0)
646 SysLog(NID_APP, "No element added for bundle.");
650 _AppMessageImpl::AddValueArray(pb, key, pList);
652 _AppMessageImpl::AddData(pb, pList);
659 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
662 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
664 if (pMap == null || pMap->GetCount() == 0)
666 SysLog(NID_APP, "No element added for bundle.");
670 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
671 while(pEnum->MoveNext() == E_SUCCESS)
673 const String* pKey = static_cast<const String*>(pEnum->GetKey());
674 const Object* pObj = pEnum->GetValue();
678 if (typeid(*pObj) == typeid(const String))
680 const String* pVal = static_cast<const String*>(pEnum->GetValue());
683 _AppMessageImpl::AddData(pb, *pKey, *pVal);
686 else if (typeid(*pObj) == typeid(const ArrayList))
688 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
691 SysLog(NID_APP, "ArrayList type");
693 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
696 else if (typeid(*pObj) == typeid(const ByteBuffer))
698 SysLog(NID_APP, "ByteBuffer type");
708 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
710 if (pMap == null || pList == null)
715 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
716 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
720 while (pEnum->MoveNext() == E_SUCCESS)
722 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
725 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
729 pStr->SubString(0, index, key);
735 pStr->SubString(index + 1, value);
737 pMap->Add(new String(key), new String(value));
739 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
747 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
751 case APP_CTRL_RESULT_SUCCEEDED:
752 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
754 case APP_CTRL_RESULT_CANCELED:
755 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
757 case APP_CTRL_RESULT_TERMINATED:
758 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
760 case APP_CTRL_RESULT_ABORTED:
761 list.Add(* new (std::nothrow) String("aborted"));
763 //case APP_CTRL_RESULT_FAILED:
765 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
774 bool isPathRegistered = false;
775 // handle APP_CTRL_RESULT_SUCCEEDED only
776 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
778 while(pMapEnum->MoveNext() == E_SUCCESS)
780 String* pKey = static_cast<String*>(pMapEnum->GetKey());
783 SysLog(NID_APP, "Invalid entry.");
787 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
789 if (!isPathRegistered)
791 isPathRegistered = true;
795 SysLog(NID_APP, "Selected path key is already registered.");
800 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
803 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
805 StringTokenizer strTok(*pVal, L';');
806 if (strTok.GetTokenCount() == 0)
808 list.Add(* new (std::nothrow) String(*pVal));
813 while(strTok.HasMoreTokens())
815 strTok.GetNextToken(token);
816 list.Add(* new (std::nothrow) String(token));
817 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
828 _AppArg::GetListN(bundle* b, const char* key)
836 const char** pValArray = null;
839 pValArray = appsvc_get_data_array(b, key, &len);
840 if (len == 0 || pValArray == null)
845 ArrayList* pList = new (std::nothrow) ArrayList;
846 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
850 for (int i = 0; i < len; i++)
852 pList->Add(*new (std::nothrow) String(pValArray[i]));
860 _AppArg::CreateLaunchArg(bundle* b, const String& arg)
862 SysAssertf(b != null, "Valid bundle should be supplied");
868 const char** pSa = new (std::nothrow) const char*[1];
869 SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Insufficient memory.");
870 pSa[0] = _StringConverter::CopyToCharArrayN(arg);
871 bundle_add_str_array(pb, OSP_K_ARG, pSa, 1);
873 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pSa[0]);
879 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
886 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
888 SysAssertf(b != null, "Valid bundle should be supplied");
892 AddStrArray(pb, OSP_K_ARG, pList);
894 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
901 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
903 SysAssertf(b != null, "Valid bundle should be supplied");
908 AddStrArray(pb, OSP_K_ARG, pList);
910 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
913 bundle_add(pb, OSP_K_COND, p.get());
916 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
923 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
925 SysAssertf(b != null, "Valid bundle should be supplied");
929 AddStrArray(pb, OSP_K_ARG, pList);
931 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
934 appsvc_set_operation(pb, pOperation.get());
937 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
944 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pList)
946 SysAssertf(b != null, "Valid bundle should be supplied");
950 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
951 if (pOperation.get())
953 appsvc_set_operation(pb, pOperation.get());
958 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
961 appsvc_set_uri(pb, pUri.get());
967 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
970 appsvc_set_mime(pb, pMime.get());
974 AddStrMap(pb, pList);
976 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
984 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
987 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
988 const IList* pArgList)
990 SysAssertf(b != null, "Valid bundle should be supplied");
992 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
994 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
995 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
996 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
998 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1001 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1004 AddStrArray(b, OSP_K_ARG, pArgList);
1011 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
1012 const IList* pArgList)
1014 SysAssertf(b != null, "Valid bundle should be supplied");
1016 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1018 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1019 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
1020 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1022 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1025 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1028 AddStrArray(b, OSP_K_ARG, pArgList);
1035 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1037 SysAssertf(b != null, "Valid bundle should be supplied");
1041 AddStrArray(pb, OSP_K_ARG, pList);
1043 _AppMessageImpl::AddData(pb, pList);
1050 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1052 SysAssertf(b != null, "Valid bundle should be supplied");
1056 AddStrMap(pb, pMap);
1063 _AppArg::CreateBundleFromSvc(void* svc)
1065 bundle* pBundle = GetBundleFromSvc(svc);
1068 return bundle_dup(pBundle);
1076 _AppArg::GetBundleFromSvc(void* svc)
1085 DummyS* pDummy = static_cast<DummyS*>(svc);
1087 if (pDummy && pDummy->pData)
1089 return pDummy->pData;
1097 _AppArg::GetRequestId(int num)
1100 str.Format(10, L"req%05d", num);
1106 _AppArg::GetRequestId(const String& str)
1111 result r = str.SubString(3, sub);
1112 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1114 r = Integer::Parse(sub, i);
1115 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1122 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1124 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1126 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1127 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1129 bundle_add(b, OSP_K_APPID, pId.get());
1131 appsvc_set_appid(b, pId.get());
1136 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1138 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1142 //SysLog(NID_APP, "Requested ID is %d", reqId);
1146 char buffer[32] = {0, };
1147 snprintf(buffer, 32, "%d", reqId);
1148 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1153 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1155 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1162 return (i < 0) ? -1 : i;
1167 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1171 SysLog(NID_APP, "Invalid window handle.");
1175 char handleName[32] = {0, };
1176 snprintf(handleName, 32, "%ld", handle);
1178 bundle_add(pBundle, BUNDLE_KEY_WINDOW, handleName);
1179 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1186 _AppArg::PrintSvcHandle(void* svc)
1188 service_h service = static_cast<service_h>(svc);
1190 if (service == null)
1195 Print(GetBundleFromSvc(service));
1200 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1208 case BUNDLE_TYPE_STR:
1209 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1212 SysLog(NID_APP, "(%s, %s)", pKey, pStr);
1216 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1223 _AppArg::Print(bundle* b)
1230 const char* p = null;
1231 p = appsvc_get_data(b, AUL_K_CALLER_PID);
1234 SysLog(NID_APP, "CallerPId[%s]", p);
1237 p = appsvc_get_data(b, AUL_K_WAIT_RESULT);
1240 SysLog(NID_APP, "WaitResult[%s]", p);
1243 p = appsvc_get_data(b, OSP_K_COND);
1246 SysLog(NID_APP, "Condition[%s]", p);
1249 p = appsvc_get_operation(b);
1252 SysLog(NID_APP, "operation[%s]", p);
1255 p = appsvc_get_uri(b);
1258 SysLog(NID_APP, "uri[%s]", p);
1261 p = appsvc_get_mime(b);
1264 SysLog(NID_APP, "mime[%s]", p);
1267 p = appsvc_get_category(b);
1270 SysLog(NID_APP, "Category[%s]", p);
1273 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1276 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1279 for (int i = 0; i < len; i++)
1283 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);