Merge "Change the way to conver Mbs to Wcs and vice versa" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / FApp_AppArg.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 806bdb5..6657a36
@@ -30,6 +30,7 @@
 #include <aul.h>
 #include <app.h>
 #include <appsvc/appsvc.h>
+#include <Ecore_X.h>
 
 #include <FBaseInteger.h>
 #include <FBaseColArrayList.h>
@@ -52,6 +53,9 @@ using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
 using namespace Tizen::App::Package;
 
+
+extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
+
 namespace Tizen { namespace App
 {
 
@@ -67,7 +71,6 @@ static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
-static const char BUNDLE_KEY_WINDOW[] = "__APP_SVC_K_WIN_ID__";
 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
@@ -137,6 +140,16 @@ _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String*
 
 
 result
+_AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
+{
+       __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
+       SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
+
+       return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
+}
+
+
+result
 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
 {
        __pBundle = bundle_create();
@@ -328,7 +341,7 @@ _AppArg::GetArgMapN(void) const
                return null;
        }
 
-       ArrayList* pList = _AppMessageImpl::GetValueArray(__pBundle, OSP_K_ARG);
+       ArrayList* pList = _AppMessageImpl::GetValueArrayN(__pBundle, OSP_K_ARG);
        if (pList)
        {
                pHashMap->Add(new (std::nothrow) String(TIZEN_APPCONTROL_DATA_LEGACY), pList);
@@ -572,31 +585,20 @@ _AppArg::GetCallerPid(bundle* pBundle)
 AppId
 _AppArg::GetCallerAppId(void) const
 {
-       pid_t callerPid = GetCallerPid();
-       SysTryReturn(NID_APP, callerPid > 0, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Wrong process id: %d.", callerPid);
+       const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
 
-       char appId[PATH_MAX] = {0, };
-       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);
-
-       return String(appId);
+       return String(pBundleValue);
 }
 
 
 AppId
 _AppArg::GetCalleeAppId(void) const
 {
-       const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_PID);
-
-       SysTryReturn(NID_APP, pBundleValue != null, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
+       const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
 
-       pid_t calleePid = atoi(pBundleValue);
-       SysTryReturn(NID_APP, calleePid > 0, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Wrong process id: %d.", calleePid);
-
-       char appId[PATH_MAX] = {0, };
-       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);
+       String retVal = pBundleValue;
 
        String temp;
-       String retVal = appId;
        // [INFO] ugly code for submode callee
        retVal.SubString(11, temp);
        if (temp == L"_AppControl")
@@ -614,17 +616,6 @@ _AppArg::GetCalleeAppId(void) const
 
 
 void
-_AppArg::SaveCalleeAppId(void)
-{
-       const AppId& appId = GetCalleeAppId();
-
-       std::unique_ptr<char[]> pVal(_StringConverter::CopyToCharArrayN(appId));
-
-       appsvc_add_data(__pBundle, OSP_K_CALLEE_APPID, pVal.get());
-}
-
-
-void
 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
 {
        bundle* pBundle = bk;
@@ -955,13 +946,20 @@ _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList*
 
 
 result
-_AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pList)
+_AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
+{
+       return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
+}
+
+
+result
+_AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
 {
        SysAssertf(b != null, "Valid bundle should be supplied");
 
        bundle* pb = b;
 
-       std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
+       std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
        if (pOperation.get())
        {
                appsvc_set_operation(pb, pOperation.get());
@@ -985,7 +983,7 @@ _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String*
                }
        }
 
-       AddStrMap(pb, pList);
+       AddStrMap(pb, pMap);
 
        bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
 
@@ -1140,7 +1138,12 @@ _AppArg::UpdateAppId(bundle* b, const AppId& appId)
        std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
        SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
 
-       bundle_add(b, OSP_K_APPID, pId.get());
+       int res = bundle_add(b, OSP_K_APPID, pId.get());
+       if (res < 0 && errno == EPERM) // key exists
+       {
+               bundle_del(b, OSP_K_APPID);
+               bundle_add(b, OSP_K_APPID, pId.get());
+       }
 
        appsvc_set_appid(b, pId.get());
 }
@@ -1159,9 +1162,28 @@ _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
 
        char buffer[32] = {0, };
        snprintf(buffer, 32, "%d", reqId);
-       bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
+       int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
+       if (res < 0 && errno == EPERM) // key exists
+       {
+               bundle_del(pBundle, OSP_K_REQUEST_ID);
+               bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
+       }
 }
 
+void
+_AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
+{
+       SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
+
+       char pBuffer[128] = {0, };
+       snprintf(pBuffer, 128, "%ls", value.GetPointer());
+       int res = bundle_add(pBundle, pKey, pBuffer);
+       if (res < 0 && errno == EPERM) // key exists
+       {
+               bundle_del(pBundle, pKey);
+               bundle_add(pBundle, pKey, pBuffer);
+       }
+}
 
 int
 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
@@ -1180,16 +1202,8 @@ _AppArg::GetRequestIdFromBundle(bundle* pBundle)
 result
 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
 {
-       if (handle == -1)
-       {
-               SysLog(NID_APP, "Invalid window handle.");
-               return E_SUCCESS;
-       }
-
-       char handleName[32] = {0, };
-       snprintf(handleName, 32, "%ld", handle);
+       appsvc_allow_transient_app(pBundle, handle);
 
-       bundle_add(pBundle, BUNDLE_KEY_WINDOW, handleName);
        SysLog(NID_APP, "Window Handle 0x%x added.", handle);
 
        return E_SUCCESS;