#include "FAppPkg_PackageInfoImpl.h"
#include "FApp_AppMessageImpl.h"
#include "FApp_AppManagerImpl.h"
+#include "FApp_AppControlResponseEvent.h"
using namespace Tizen::App::Package;
using namespace Tizen::Base;
__appControlEvent.Construct();
__appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
__listenerList.Construct();
+ __pAppControlResponseEventContainer = new (std::nothrow)HashMapT<int, _AppControlResponseEvent*>;
+ __pAppControlResponseEventContainer->Construct();
+ __appControlResponseEventList.Construct();
}
_AppControlManager::~_AppControlManager(void)
{
SysLog(NID_APP, "");
__appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
+ IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
+
+ if (pEnum != null)
+ {
+ while(pEnum->MoveNext() == E_SUCCESS)
+ {
+ int reqId;
+ pEnum->GetCurrent(reqId);
+ if (__pAppControlResponseEventContainer != null)
+ {
+ _AppControlResponseEvent* pResponseEvent = null;
+ __pAppControlResponseEventContainer->GetValue(reqId, pResponseEvent);
+ delete pResponseEvent;
+
+ __pAppControlResponseEventContainer->Remove(reqId);
+ SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
+ }
+ }
+ }
+ delete __pAppControlResponseEventContainer;
+ delete pEnum;
}
_AppControlManager*
if (pInfo->pUserData && (!__listenerList.Contains(pInfo->pUserData)))
{
- (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property);
+ (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
}
}
else
r = E_OPERATION_CANCELED;
}
SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
- pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
+
+ _AppControlResponseEvent* pResponseEvent = null;
+ __pAppControlResponseEventContainer->GetValue(reqId, pResponseEvent);
+ SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
+ if (pResponseEvent != null)
+ {
+ String oId(operationId);
+ _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId);
+
+ if (pResponseEventArg != null)
+ {
+ pResponseEvent->Fire(*pResponseEventArg);
+ SysLog(NID_APP, "pResponseEvent is Fired");
+ }
+ }
+ else
+ {
+ pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
+ SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
+ }
}
else
{
if (pInfo->property & _APPCONTROL_PROPERTY_ALIAS)
{
- _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
+ const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(aId, oId);
if (pEntry)
{
IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
if (pListener && (!__listenerList.Contains(pInfo->pListener)))
{
- SysLog(NID_APP, "OSP_AC OnAppControlCompleteResponseReceived");
- pListener->OnAppControlCompleteResponseReceived(aId, oId, static_cast<AppCtrlResult>(res), pArgs);
+ _AppControlResponseEvent* pResponseEvent = null;
+ int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
+ __pAppControlResponseEventContainer->GetValue(responseEventRequestId, pResponseEvent);
+
+ if (pResponseEvent != null)
+ {
+ _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), pArgs, responseEventRequestId);
+ if (pResponseEventArg != null)
+ {
+ pResponseEvent->Fire(*pResponseEventArg);
+ SysLog(NID_APP, "pResponseEvent is Fired");
+ }
+ }
+ else
+ {
+ pListener->OnAppControlCompleteResponseReceived(aId, oId, static_cast<AppCtrlResult>(res), pArgs);
+ SysLog(NID_APP, "OnAppControlCompleteResponseReceived called directly");
+ }
}
else
{
return __appControlEvent.FireAsync(arg);
}
+Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
+_AppControlManager::GetAppControlResponseEventContainer(void)
+{
+ return __pAppControlResponseEventContainer;
+}
+
+
// generic launch callback
static void
LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
return r;
}
+
+
int
_AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
{
}
+int
+_AppControlManager::LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const String& opId, const String* pUri, const String* pMime, AppSvcResFn pCb, void* data)
+{
+ std::unique_ptr<char[]> pPackage(_StringConverter::CopyToCharArrayN(appId));
+ std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(opId));
+
+ const char* pUriData = null;
+ if (pUri)
+ {
+ pUriData = _StringConverter::CopyToCharArrayN(*pUri);
+ }
+
+ const char* pMimeData = null;
+ if (pMime)
+ {
+ pMimeData = _StringConverter::CopyToCharArrayN(*pMime);
+ }
+
+ int pid = Launch(msg, pPackage.get(), pOperation.get(), pMimeData, pUriData, pCb, data);
+
+ delete [] pUriData;
+ delete [] pMimeData;
+
+ return pid;
+}
+
+
result
_AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
{
return r;
}
+static bool
+_IsDefaultApplication(const AppId& packageId, const String& appId)
+{
+ const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
+
+ int index = -1;
+ result r = appId.IndexOf(L'.', 0, index);
+ if (r != E_SUCCESS)
+ {
+ return false;
+ }
+
+ String tmp;
+ appId.SubString(index + 1, tmp);
+ if (tmp == execName)
+ {
+ SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
+ return true;
+ }
+
+ return false;
+}
+
+
+int
+_AppControlManager::Launch(const _AppMessageImpl& msg, const AppId& aId, const String& oId, const String* pUriData, const String* pMimeType, AppSvcResFn pCb, void* pData)
+{
+ SysLog(NID_APP, "Enter");
+
+ _AppArg arg;
+ arg.Construct(msg, oId, pUriData, pMimeType);
+
+ int pid = Launch(aId, &arg, pCb, pData, -1);
+ SysTryReturn(NID_APP, pid >= 0, -1, GetLastResult(), "Launching(%ls) is failed", aId.GetPointer());
+
+ SysLog(NID_APP, "Exit");
+
+ return pid;
+}
+
+
int
_AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
{
+ return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
+}
+
+
+int
+_AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
+{
SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
SysLog(NID_APP, "AppId: %ls.", appId.GetPointer());
String actualAppId = appId;
if (appId.GetLength() == 10)
{
- const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
+ const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
- if (!name.IsEmpty())
+ if (!execName.IsEmpty())
{
actualAppId.Append(L'.');
- actualAppId.Append(name);
+ actualAppId.Append(execName);
}
}
int pid = -1;
bundle* kb = NULL;
String tempId;
+
actualAppId.SubString(0, 10, tempId);
- tempId += L'.';
- tempId += L"_AppControl";
- // [INFO] Ugly solution for submode support
- pArg->UpdateAppId(tempId);
- kb = pArg->GetBundle();
-
- pid = appsvc_run_service(kb, req, LaunchResultCb, this);
- if (pid > 0)
+ if (_IsDefaultApplication(tempId, appId))
{
- SysLog(NID_APP, "Submode launch successful");
- return pid;
+ tempId += L'.';
+ tempId += L"_AppControl";
+
+ // [INFO] Ugly solution for submode support
+ pArg->UpdateAppId(tempId);
+ kb = pArg->GetBundle();
+
+ pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
+ if (pid > 0)
+ {
+ SysLog(NID_APP, "Submode launch successful");
+ return pid;
+ }
}
pArg->UpdateAppId(actualAppId);
do
{
kb = pArg->GetBundle();
- pid = appsvc_run_service(kb, req, LaunchResultCb, this);
+ pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
if (pid > 0)
{
SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
}
void
-_AppControlManager::FinishAppControl(int reqId, int res, const IMap* pMap)
+_AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
{
+ SysLog(NID_APP, "Enter.");
_NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap);
SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
SendAppControlEvent(*pArg);
+ SysLog(NID_APP, "Exit.");
}
const _AppArg*
bool
-_AppControlManager::IsAllowedAppControl(const wchar_t aTable[][2][64], int count, const String& aId, const String& oId)
+_AppControlManager::IsAllowedAppControl(const char aTable[][2][96], int count, const String& aId, const String& oId)
{
for (int i = 0; i < count; i++)
{
if (aId == aTable[i][0] && oId == aTable[i][1])
{
- SysLog(NID_APP, "Found entry (%ls, %ls)", aTable[i][0], aTable[i][1]);
+ SysLog(NID_APP, "Found entry (%s, %s)", aTable[i][0], aTable[i][1]);
return true;
}
}
return false;
}
+void
+_AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
+{
+ const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
+
+ if (pEventArg != null)
+ {
+ IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
+
+ if(pResponseListener != null)
+ {
+ if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
+ {
+ pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
+ SysLog(NID_APP, "OnAppControlStartResponseReceived called");
+ }
+ else
+ {
+ pResponseListener->OnAppControlCompleteResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData());
+ SysLog(NID_APP, "OnAppControlCompleteResponseReceived called");
+
+ _AppControlResponseEvent* pResponseEvent = null;
+ _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
+ _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
+
+ delete pResponseEvent;
+ SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
+ }
+ }
+ else
+ {
+ SysLog(NID_APP, "Invalid ResponseListener");
+ }
+ }
+ else
+ {
+ SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);
+ }
+}
+
+AppId
+_AppControlManager::GetAliasAppId(const AppId& appId)
+{
+ return _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
+}
+
}} // Tizen::App