#include <limits.h>
#include <new>
#include <fcntl.h>
+#include <unique_ptr.h>
#include <appinfo.h>
extern "C"
{
void _OSP_EXPORT_
-InitAppInfo(const char* packageId, const char* svcId, int argc, char* pArgv[], int fd)
+AppInfo_Update(void)
{
- result r = Tizen::App::_AppInfo::GetAppInfo()->Construct(packageId, svcId, argc, pArgv);
+ result r = Tizen::App::_AppInfo::GetInstance()->Construct();
if (IsFailed(r))
{
- SysLogException(NID_APP, E_SYSTEM, "Application initialization failure for %s.", packageId);
- fprintf(stderr, "Application initialization failure for %s.\n", packageId);
+ SysLogException(NID_APP, E_SYSTEM, "Application initialization failure.");
+ fprintf(stderr, "Application initialization failure.\n");
_Process::Exit(-1);
}
}
void _OSP_EXPORT_
+InitAppInfo(const char* packageId, const char* svcId, int argc, char* pArgv[], int fd)
+{
+ AppInfo_Update();
+}
+
+void _OSP_EXPORT_
InitWebAppInfo(const char* appId, const char* rootPath)
{
- result r = Tizen::App::_AppInfo::GetAppInfo()->Construct(appId, rootPath, Tizen::App::_APP_TYPE_WEB_APP);
+ result r = Tizen::App::_AppInfo::GetInstance()->Construct(appId, rootPath, Tizen::App::_APP_TYPE_WEB_APP);
if (IsFailed(r))
{
SysLogException(NID_APP, E_SYSTEM, "Application initialization failure for %s.", appId);
const char COMPAT_FILE_PATH[] = "info/compat.info";
const char VIRTUAL_ROOT_FILE_PATH[] = "info/virtual.info";
const char TYPE_FILE_PATH[] = "info/type.info";
+const char SUBMODE_NAME[] = "_AppControl";
_AppInfo::_AppInfo(void)
}
_AppInfo*
-_AppInfo::GetAppInfo(void)
+_AppInfo::GetInstance(void)
{
static _AppInfo info;
FBase_Initialize();
- return E_SUCCESS;
-}
-
-
-result
-_AppInfo::Construct(const char* packageId, const char* exeName, int argc, char* argv[])
-{
- SysAssertf(packageId != null, "Valid appId required to launch application.");
- SysAssertf(appinfo_is_initialized() == 1, "appinfo is not initialized.");
-
- FBase_Initialize();
+ const char* pPackageId = appinfo_get_packageid();
+ const char* pExecName = appinfo_get_execname();
- __appExecutableName = exeName;
- __packageId = packageId;
- if (__appExecutableName == L"_AppControl")
+ if (strncmp(pExecName, SUBMODE_NAME, strlen(SUBMODE_NAME)) == 0)
{
SysLog(NID_APP, "Handling for submode.");
- const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(__packageId);
+ const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(String(pPackageId));
__isSubMode = true;
- __appExecutableName = name;
std::unique_ptr<char[]> pActualExec(_StringConverter::CopyToCharArrayN(name));
appinfo_update_submode_execname_and_appid(pActualExec.get());
SysLog(NID_APP, "Executable name is changed to %s.", pActualExec.get());
}
- __appId = __packageId + L'.' + __appExecutableName;
-
result r = E_SUCCESS;
FILE* pFile = NULL;
int len = strlen(PACKAGE_PATH_FORMAT);
strncpy(appInfoPath, PACKAGE_PATH_FORMAT, len);
appInfoPath[len] = '\0';
- strncpy(appInfoPath + strlen(PATH_ROOT), packageId, MAX_APPID);
+ strncpy(appInfoPath + strlen(PATH_ROOT), pPackageId, MAX_APPID);
// app root directory file descriptor
__appRootDirFd = open(appInfoPath, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
}
}
- SysLog(NID_APP, "New appinfo [%s][%s.%s].", appinfo_get_appid(), appinfo_get_packageid(), appinfo_get_execname());
- SysLog(NID_APP, "AppInfo initialization finished [%ls][%ls.%ls][%d].",
- __appId.GetPointer(), __packageId.GetPointer(), __appExecutableName.GetPointer(), appinfo_get_api_version());
+ SysLog(NID_APP, "AppInfo [%s][%s.%s][%d].", appinfo_get_appid(), appinfo_get_packageid(), appinfo_get_execname(), appinfo_get_api_version());
}
return E_SUCCESS;
CATCH:
- __appId.Clear();
- __appExecutableName.Clear();
-
- delete __pAppName;
- __pAppName = null;
-
- delete __pAppVersion;
- __pAppVersion = null;
-
if (pFile != NULL)
{
fclose(pFile);
FBase_Initialize();
- __appId = appId;
-
- int index = 0;
- if (__appId.LastIndexOf(L'.', __appId.GetLength() - 1, index) == E_SUCCESS)
+ if (appinfo_is_initialized() == 0)
{
- __appId.SubString(index + 1, __appExecutableName);
- __appId.SubString(0, index, __packageId);
- }
- else
- {
- __appExecutableName = __appId;
- __packageId = __appId;
+ appinfo_init(appId, 0);
}
__appRootDirFd = open(appRoot, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
__appRootPath.Append(L'/');
}
- SysLog(NID_APP, "AppInfo initialization finished [%ls][%ls.%ls][%ls][%d].", __appId.GetPointer(), __packageId.GetPointer(), __appExecutableName.GetPointer(), __appRootPath.GetPointer(), appinfo_get_api_version());
+ SysLog(NID_APP, "AppInfo [%s][%s.%s][%ls][%d].", appinfo_get_appid(), appinfo_get_packageid(), appinfo_get_execname()), __appRootPath.GetPointer(), appinfo_get_api_version();
return E_SUCCESS;
}
result
_AppInfo::UpdateAppInfoFromPackageInfo(const PackageId& packageId)
{
- _PackageManagerImpl* pPkg = null;
- pPkg = _PackageManagerImpl::GetInstance();
+ _PackageManagerImpl* pPkg = _PackageManagerImpl::GetInstance();
SysTryReturnResult(NID_APP, pPkg != null, E_INVALID_STATE, "Invalid PackageManager instance.");
result r = E_SUCCESS;
- PackageInfo* pInfo = null;
- pInfo = pPkg->GetPackageInfoN(packageId);
+ std::unique_ptr<PackageInfo> pInfo(pPkg->GetPackageInfoN(packageId));
SysTryReturn(NID_APP, pInfo != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
- const _PackageInfoImpl* pPkgInfo = _PackageInfoImpl::GetInstance(pInfo);
+ const _PackageInfoImpl* pPkgInfo = _PackageInfoImpl::GetInstance(pInfo.get());
SysTryReturnResult(NID_APP, pPkgInfo != null, E_INVALID_STATE, "Invalid PackageInfo instance.");
delete __pAppName;
__isPackageInfoInitialized = true;
- delete pInfo;
-
SysLog(NID_APP, "AppInfo updated [%ls][%ls].", __pAppName->GetPointer(), __pAppVersion->GetPointer());
return r;
CATCH:
- delete pInfo;
-
delete __pAppName;
__pAppName = null;
bool
_AppInfo::IsVirtualRoot(void)
{
- return GetAppInfo()->__isVirtualRoot;
+ return GetInstance()->__isVirtualRoot;
}
result
int
_AppInfo::GetAppRootDirFd(void)
{
- return GetAppInfo()->__appRootDirFd;
+ return GetInstance()->__appRootDirFd;
}
AppId
_AppInfo::GetApplicationId(void)
{
- const String& appId = GetAppInfo()->__appId;
-
- SysAssertf(!appId.IsEmpty(), "AppId is not initialized properly.");
-
- return appId;
+ return String(appinfo_get_appid());
}
PackageId
_AppInfo::GetPackageId(void)
{
- const String& packageId = GetAppInfo()->__packageId;
-
- SysAssertf(!packageId.IsEmpty(), "PackageId is not initialized properly.");
-
- return packageId;
+ return String(appinfo_get_packageid());
}
String
_AppInfo::GetAppExecutableName(void)
{
- return GetAppInfo()->__appExecutableName;
+ return String(appinfo_get_execname());
}
bool
_AppInfo::IsSubMode(void)
{
- return GetAppInfo()->__isSubMode;
+ return GetInstance()->__isSubMode;
}
String
_AppInfo::GetAppName(void)
{
- if (!GetAppInfo()->__isPackageInfoInitialized)
+ if (!GetInstance()->__isPackageInfoInitialized)
{
- const String& packageId = GetAppInfo()->__packageId;
+ const String& packageId = GetInstance()->GetPackageId();
SysAssertf(!packageId.IsEmpty(), "PackageId is not initialized properly.");
- result r = GetAppInfo()->UpdateAppInfoFromPackageInfo(packageId);
+ result r = GetInstance()->UpdateAppInfoFromPackageInfo(packageId);
SysAssertf(r == E_SUCCESS, "AppInfo update failure due to package problem.");
}
- return *(GetAppInfo()->__pAppName);
+ return *(GetInstance()->__pAppName);
}
String
_AppInfo::GetAppRootPath(void)
{
- return GetAppInfo()->__appRootPath;
+ return GetInstance()->__appRootPath;
}
String
_AppInfo::GetAppVersion(void)
{
- if (!GetAppInfo()->__isPackageInfoInitialized)
+ if (!GetInstance()->__isPackageInfoInitialized)
{
- const String& packageId = GetAppInfo()->__packageId;
+ const String& packageId = GetInstance()->GetPackageId();
SysAssertf(!packageId.IsEmpty(), "PackageId is not initialized properly.");
- result r = GetAppInfo()->UpdateAppInfoFromPackageInfo(packageId);
+ result r = GetInstance()->UpdateAppInfoFromPackageInfo(packageId);
SysAssertf(r == E_SUCCESS, "AppInfo update failure due to package problem.");
}
- return *(GetAppInfo()->__pAppVersion);
+ return *(GetInstance()->__pAppVersion);
}
AppState
_AppInfo::GetAppState(void)
{
- return GetAppInfo()->__appState;
+ return GetInstance()->__appState;
}
void
_AppInfo::SetAppState(AppState appState)
{
- GetAppInfo()->__appState = appState;
+ GetInstance()->__appState = appState;
}
int
_AppInfo::GetAppType(void)
{
- return GetAppInfo()->__appType;
+ return GetInstance()->__appType;
}
void
_AppInfo::SetAppType(_AppType appType)
{
- GetAppInfo()->__appType |= appType;
+ GetInstance()->__appType |= appType;
}
int
_AppInfo::GetAppHandlerType(void)
{
- return GetAppInfo()->__appHandlerType;
+ return GetInstance()->__appHandlerType;
}
void
_AppInfo::SetAppHandlerType(int appHandlerType)
{
- GetAppInfo()->__appHandlerType = appHandlerType;
+ GetInstance()->__appHandlerType = appHandlerType;
}
unsigned int
_AppInfo::GetParentWindowHandle(void)
{
- return GetAppInfo()->__parentWindowHandle;
+ return GetInstance()->__parentWindowHandle;
}
void
_AppInfo::SetParentWindowHandle(unsigned int handle)
{
- GetAppInfo()->__parentWindowHandle = handle;
+ GetInstance()->__parentWindowHandle = handle;
}
void
_AppInfo::UpdatePackageInfo(bool update)
{
- GetAppInfo()->__isPackageInfoInitialized = !update;
+ GetInstance()->__isPackageInfoInitialized = !update;
}
}} // Tizen::App