#include <FIoDirectory.h>
#include <FIoRegistry.h>
-#include <FAppApp.h>
+#include <FIoDatabase.h>
+#include <FIoDbStatement.h>
+#include <FIoDbEnumerator.h>
+#include <FAppApp.h>
#include <FBaseSysLog.h>
+#include <FBaseColHashMap.h>
+
+#include <FBase_StringConverter.h>
#include <FIo_RegistryImpl.h>
+#include <FIo_DatabaseImpl.h>
#include "FApp_Types.h"
#include "FAppPkg_PackageManagerImpl.h"
const String REG_KEY_KEY = L"Key";
const String REG_KEY_FILENAME = L"Filename";
- const String REGISTRY_FILE_OPERATIONS = L"data/app-launch-conditions.ini";
- const String REG_KEY_APPID = L"AppId";
- const String REG_KEY_CONDTION = L"Condition";
- const String REG_KEY_LAUNCH_TYPE = L"LaunchType";
- const String REG_KEY_ARG_COUNT = L"ArgCount";
- const String REG_KEY_ARG = L"Arg";
+ const String DATABASE_COND_OPERATIONS = L"app-launch-conditions.db";
+ const int DB_TABLE_COND_SECTION_NAME = 0;
+ const int DB_TABLE_COND_APPID = 1;
+ const int DB_TABLE_COND_USERID = 2;
+ const int DB_TABLE_COND_CONDITION = 3;
+ const int DB_TABLE_COND_LAUNCHTYPE = 4;
+ const int DB_TABLE_COND_ARG_COUNT = 5;
+ const int DB_TABLE_COND_ARG_LENGTH = 6;
+ const int DB_TABLE_COND_ARG = 7;
const int MAX_LEN_ARG = 1024;
const int MAX_LEN_CONDITION = 400;
_ConditionManagerService::~_ConditionManagerService()
{
SysLog(NID_APP, "Enter");
- result r = E_SUCCESS;
- //_ConditionHandler* pHandler = null;
- for (int i =0; i < __handlers.GetCount(); i ++)
- {
- _ConditionHandler* pHandler = null;
- r = __handlers.GetAt(i, pHandler);
- delete pHandler;
- }
__handlers.RemoveAll();
+ __handlerLookupTable.RemoveAll();
SysLog(NID_APP, "Exit");
}
_ConditionManagerService::Construct(void)
{
SysLog(NID_APP,"Enter.");
-
result r = E_SUCCESS;
- r = __handlers.Construct();
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __handlers.Construct.(%s)", GetErrorMessage(r) );
+ r = __handlers.Construct(0, 0, __strHashMapProvider, __strComparer);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to __handlers.Construct.");
- r = __handlerLookupTable.Construct( 16, 0.75f, __strHashMapProvider, __strComparer);
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __handlerLookupTable.Construct.(%s)", GetErrorMessage(r) );
+ r = __handlerLookupTable.Construct(0, 0, __strHashMapProvider, __strComparer);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to __handlerLookupTable.Construct.");
- r = InitializePlugins();
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to InitializePlugins.(%s)", GetErrorMessage(r) );
+ r = InitializePluginData();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to InitializePluginData.");
r = InitializeConditionalOperations();
- SysTryLog(NID_APP, !IsFailed(r), "failed to InitializeLaunchConditions.(%s)", GetErrorMessage(r) );
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to InitializeLaunchConditions.");
SysLog(NID_APP,"Exit.");
return E_SUCCESS;
}
result
-_ConditionManagerService::InitializePlugins(void)
+_ConditionManagerService::InitializePluginData(void)
{
SysLog(NID_APP,"Enter.");
_RegistryImpl reg;
- const String& homePath = App::GetInstance()->GetAppRootPath();
+ IList *pSections = null;
- result r = reg.Construct(homePath + REGISTRY_FILE_PLUGIN, REG_OPEN_READ_ONLY , null);
- if (IsFailed(r))
- {
- SysLog(NID_APP, "failed to open registry '%ls' (%s)", (homePath + REGISTRY_FILE_PLUGIN).GetPointer(), GetErrorMessage(r) );
- return E_SUCCESS;
- }
+ const String& homePath = App::GetInstance()->GetAppRootPath();
+ result r = reg.Construct(homePath + REGISTRY_FILE_PLUGIN, REG_OPEN_READ_ONLY, null);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to open registry '%ls'", (homePath + REGISTRY_FILE_PLUGIN).GetPointer());
- IList *pSections = null;
r = reg.GetSectionListN(&pSections);
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to GetSectionListN. (%s)", GetErrorMessage(r) );
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to GetSectionListN.");
std::unique_ptr<IEnumerator> pEnum(pSections->GetEnumeratorN());
- String* pSecName = null;
-
- IMap* pMap = null;
+ SysTryCatch(NID_APP, pEnum != null, , E_FAILURE, "failed to GetEnumeratorN.");
while (pEnum->MoveNext() == E_SUCCESS)
{
+ String* pSecName = null;
+
pSecName = static_cast<String*>(pEnum->GetCurrent());
pSecName->Trim();
- pMap = reg.GetAllEntriesN(*pSecName);
- SysTryCatch(NID_APP, pMap != null, , E_SYSTEM, "");// try next
+ std::unique_ptr<IMap> pMap(reg.GetAllEntriesN(*pSecName));
+ SysTryCatch(NID_APP, pMap != null, , E_FAILURE, "failed to GetAllEntriesN.");
- r = InitializePluginEntry(*pMap);
- if ( r == E_OBJ_NOT_FOUND)
+ const String* pTypes = static_cast<const String*>(pMap->GetValue(REG_KEY_KEY));
+ const String* pFilename = static_cast<const String*>(pMap->GetValue(REG_KEY_FILENAME));
+
+ SysTryCatch(NID_APP, pTypes != null, , E_OBJ_NOT_FOUND, "registry value is invalid. pTypes is null");
+ SysTryCatch(NID_APP, pFilename != null, , E_OBJ_NOT_FOUND, "registry value is invalid. pFilename is null");
+
+ Utility::StringTokenizer strTok(*pTypes, L',');
+ String keyTypes;
+
+ if (strTok.GetTokenCount() == 0)
{
- // empty statement
+ __handlerLookupTable.Add(*pTypes, *pFilename);
}
else
{
- SysTryCatch(NID_APP, !IsFailed(r), , r, "");
+ while (strTok.GetNextToken(keyTypes) == E_SUCCESS)
+ {
+ keyTypes.Trim();
+ __handlerLookupTable.Add(keyTypes, *pFilename);
+ }
}
-
- pMap->RemoveAll(true);
- delete pMap;
}
-
pSections->RemoveAll(true);
delete pSections;
CATCH:
SysLog(NID_APP,"Catch.");
+
pSections->RemoveAll(true);
delete pSections;
-
return r;
}
result
-_ConditionManagerService::InitializePluginEntry(IMap& map)
+_ConditionManagerService::LoadConditionPlugin(const String& fileName)
{
- result r = E_SUCCESS;
+ _RegistryImpl reg;
+ _ConditionHandler* pHandler = null;
+ HashMap* pMap = null;
+
+ const String& homePath = App::GetInstance()->GetAppRootPath();
+ result r = reg.Construct(homePath + REGISTRY_FILE_PLUGIN, REG_OPEN_READ_ONLY, null);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to open registry '%ls'", (homePath + REGISTRY_FILE_PLUGIN).GetPointer());
- const String* pTypes = static_cast<const String*>(map.GetValue(REG_KEY_KEY));
- const String* pFilename = static_cast<const String*>(map.GetValue(REG_KEY_FILENAME));
- _ConditionHandler * pHandler = null;
+ r = reg.GetEntryListN(fileName, &pMap);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to GetEntryListN.");
- SysTryReturn(NID_APP, pTypes != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pTypes is null");
- SysTryReturn(NID_APP, pFilename != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pFilename is null");
+ const String* pTypes = static_cast<const String*>(pMap->GetValue(REG_KEY_KEY));
+ const String* pFilename = static_cast<const String*>(pMap->GetValue(REG_KEY_FILENAME));
- Utility::StringTokenizer strTok(*pTypes, L',');
- String type;
+ SysTryCatch(NID_APP, pTypes != null, , E_OBJ_NOT_FOUND, "registry value is invalid. pTypes is null");
+ SysTryCatch(NID_APP, pFilename != null, , E_OBJ_NOT_FOUND, "registry value is invalid. pFilename is null");
pHandler = new (std::nothrow) _ConditionHandler(*pFilename, *pTypes);
- SysTryReturn(NID_APP, pHandler != null, E_FAILURE, E_FAILURE, "failed to new _ConditionHandler(%ls, %ls).", pFilename->GetPointer(), pTypes->GetPointer() );
+ SysTryCatch(NID_APP, pHandler != null, , E_FAILURE, "failed to construct _ConditionHandler(%ls, %ls).",
+ pFilename->GetPointer(), pTypes->GetPointer());
r = pHandler->Construct();
- SysTryCatch(NID_APP, !IsFailed(r), , r, "failed to pHandler->Construct. (%s)", GetErrorMessage(r) );
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "failed to pHandler->Construct.");
- __handlers.Add(pHandler);
-
-
- if ( strTok.GetTokenCount() == 0)
- {
- __handlerLookupTable.Add(*pTypes, pHandler);
- }
- else
- {
- while ( strTok.GetNextToken(type) == E_SUCCESS)
- {
- type.Trim();
- __handlerLookupTable.Add(type, pHandler);
- }
- }
-
- SysLog(NID_APP, "%ls is loaded.", pFilename->GetPointer() );
+ __handlers.Add(*pFilename, pHandler);
+ SysLog(NID_APP, "%ls is loaded.", pFilename->GetPointer());
+ pMap->RemoveAll(true);
+ delete pMap;
return E_SUCCESS;
CATCH:
SysLog(NID_APP, "CATCH:");
+
+ pMap->RemoveAll(true);
+ delete pMap;
delete pHandler;
+
return r;
}
-// condinfo.ini
result
_ConditionManagerService::InitializeConditionalOperations(void)
{
SysLog(NID_APP,"Enter.");
- _RegistryImpl reg;
- String homePath = App::GetInstance()->GetAppRootPath();
+ _DatabaseImpl condDb;
+ result r = E_SUCCESS;
+ String sql;
- result r = reg.Construct(homePath + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_ONLY, null);
-// SysTryReturn(NID_APP, !IsFailed(r), r, r, "");
- if ( IsFailed(r))
+ const String& homePath = App::GetInstance()->GetAppDataPath();
+ if(!(condDb.Exists(homePath + DATABASE_COND_OPERATIONS)))
{
- SysLog(NID_APP, "failed to open registry '%ls'", (homePath + REGISTRY_FILE_OPERATIONS).GetPointer());
- return E_SUCCESS;
- }
+ r = condDb.Construct(homePath + DATABASE_COND_OPERATIONS, DB_OPEN_READ_WRITE | DB_OPEN_CREATE);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to create/open database '%ls'",
+ (homePath + DATABASE_COND_OPERATIONS).GetPointer());
- IList *pSections = null;
- reg.GetSectionListN(&pSections );
-
- IEnumerator* pEnum = pSections->GetEnumeratorN();
- String* pSecName = null;
+ sql.Append(L"CREATE TABLE IF NOT EXISTS CondTbl (SectionName TEXT PRIMARY KEY, AppId TEXT, UserId INTEGER,"
+ "Condition TEXT, LaunchType TEXT, ArgCount INTEGER, ArgLength INTEGER, Arguments BLOB)");
- IMap* pMap = null;
+ r = condDb.ExecuteSql(sql, true);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to execute sql statement.");
- while (pEnum->MoveNext() == E_SUCCESS)
+ SysLog(NID_APP,"Database created successfully.");
+ }
+ else
{
- pSecName = static_cast<String*>(pEnum->GetCurrent());
- pSecName->Trim();
+ SysLog(NID_APP,"Database available and trying to open to read conditions.");
+ String* pSecName = null;
- pMap = reg.GetAllEntriesN(*pSecName);
- SysTryCatch(NID_APP, pMap != null, r = E_INVALID_FORMAT, E_INVALID_FORMAT, "failed to GetAllEntryNamesN(%ls)", pSecName->GetPointer() );
+ std::unique_ptr<ArrayList> pSections(new (std::nothrow) ArrayList(SingleObjectDeleter));
+ SysTryReturnResult(NID_APP, pSections != null, E_OUT_OF_MEMORY, "failed to allocate memory for ArrayList.");
- r = InitializeConditionalOperationEntry(*pSecName, *pMap);
- SysTryLog(NID_APP, !IsFailed(r), "failed to InitializeConditionalOperationEntry(%ls), but ignored.", pSecName->GetPointer() );
+ r = pSections->Construct();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to Construct arraylist.");
- pMap->RemoveAll(true);
- delete pMap;
+ r = _ConditionDatabaseHelper::GetAllSectionsFromConditionDb(pSections.get());
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to GetAllSectionsFromConditionDb.");
- pMap = null;
- }
+ std::unique_ptr< IEnumerator > pEnum(pSections->GetEnumeratorN());
+ SysTryReturnResult(NID_APP, pEnum != null, r, "failed to GetEnumeratorN.");
- r = E_SUCCESS;
-
-CATCH:
- delete pEnum;
-
- pSections->RemoveAll(true);
- delete pSections;
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ pSecName = static_cast<String*>(pEnum->GetCurrent());
+ pSecName->Trim();
+ r = InitializeConditionalOperationEntry(*pSecName);
+ SysTryLog(NID_APP, !IsFailed(r), "failed to InitializeConditionalOperationEntry(%ls), but ignored.",
+ pSecName->GetPointer());
+ }
+ }
SysLog(NID_APP,"Exit.");
- return r;
+ return E_SUCCESS;
}
result
-_ConditionManagerService::InitializeConditionalOperationEntry(const String& sectionName, const IMap& map)
+_ConditionManagerService::InitializeConditionalOperationEntry(const String& sectionName)
{
String appId;
String condition;
+ int userId = 0;
ArrayList* pArgs = null;
- result r = _ConditionRegistryHelper::GetAllParamsN(map, appId, condition, pArgs);
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] app(%ls), condition(%ls) is failed to register.", GetErrorMessage(r), appId.GetPointer(), condition.GetPointer() );
+ result r = _ConditionDatabaseHelper::GetConditionEntryFromDbN(sectionName, appId, userId, condition, pArgs);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "Not able to fetch the condition data.");
r = RegisterAppLaunch( appId, condition, pArgs, AppManager::LAUNCH_OPTION_DEFAULT, §ionName);
SysTryLog(NID_APP, !IsFailed(r), "[%s] app(%ls), condition(%ls) is failed to register.", GetErrorMessage(r), appId.GetPointer(), condition.GetPointer() );
+ if(r == E_INVALID_CONDITION)
+ {
+ r = _ConditionDatabaseHelper::RemoveRecordFromConditionDb(sectionName);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "Removing the table entry for the invalid conditions.");
+ }
+
if (pArgs != null)
{
pArgs->RemoveAll(true);
delete pArgs;
}
return r;
-
-//CATCH:
-// // remove invalid conditions.
-// _ConditionRegistryHelper::RemoveFromRegistry(sectionName);
-// return r;
}
_ConditionHandler*
_ConditionManagerService::GetHandlerByCondition(const String& condition)
{
Tizen::Base::Utility::StringTokenizer strTok(condition, L"=");
- SysTryReturn(NID_APP, strTok.GetTokenCount() > 0, null, E_INVALID_ARG, "Condition string is invalid.(%ls)", condition.GetPointer() );
+ SysTryReturn(NID_APP, strTok.GetTokenCount() > 0, null, E_INVALID_ARG, "Condition string is invalid.(%ls)",
+ condition.GetPointer());
String key;
result r = strTok.GetNextToken(key);
- SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), condition.GetPointer() );
+ SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), condition.GetPointer());
+
+ String fileName;
+ r = __handlerLookupTable.GetValue(key, fileName);
+ SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), key.GetPointer());
+
+ bool isHandlerFound = false;
+ r = __handlers.ContainsKey(fileName, isHandlerFound);
+ if(!isHandlerFound)
+ {
+ r = LoadConditionPlugin(fileName);
+ SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "LoadConditionPlugin failed [%s](%ls)",
+ GetErrorMessage(r), fileName.GetPointer());
+ }
_ConditionHandler* pHandler = null;
- r = __handlerLookupTable.GetValue(key, pHandler);
- SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), key.GetPointer() );
+ r = __handlers.GetValue(fileName, pHandler);
+ SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), fileName.GetPointer());
return pHandler;
}
SysTryReturnResult(NID_APP, condition.IsEmpty()==false, E_INVALID_ARG, "The launch condition is empty or too long (Maximum %d bytes).", MAX_LEN_CONDITION);
SysTryReturnResult(NID_APP, condition.GetLength() < MAX_LEN_CONDITION, E_INVALID_ARG, "The launch condition is empty or too long (Maximum %d bytes).", MAX_LEN_CONDITION);
//SysTryReturnResult(NID_APP, _PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer()); // Moved to client side due to negative test.
- SysTryReturn(NID_APP, pArguments == null || (r = ValidateArguments(pArguments)) == E_SUCCESS, r, r, "[%s]", GetErrorMessage(r));
+ SysTryReturnResult(NID_APP, pArguments == null || (r = ValidateArguments(pArguments)) == E_SUCCESS, r, "The launch arguments are not valid.");
SysTryReturnResult(NID_APP,appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH);
else
{
_ConditionHandler* pHandler = GetHandlerByCondition(*pCondition);
- SysTryReturnResult(NID_APP, pHandler != null, E_OBJ_NOT_FOUND, "");
+ SysTryReturnResult(NID_APP, pHandler != null, E_OBJ_NOT_FOUND, "failed to GetHandlerByCondition");
String curAppName;
appId.SubString(10, curAppName);
_ConditionManagerService::UnregisterAppLaunch(const Tizen::App::AppId& appId)
{
result r = E_SUCCESS;
- _ConditionHandler* pHandler = null;
- for (int i =0; i < __handlers.GetCount(); i ++)
+
+ std::unique_ptr< IMapEnumeratorT<String, _ConditionHandler*> > pMapEnum(__handlers.GetMapEnumeratorN());
+ SysTryReturnResult(NID_APP, pMapEnum != null, r = GetLastResult(), "failed to GetMapEnumeratorN.");
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
{
- pHandler = null;
- r = __handlers.GetAt(i, pHandler);
- SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r) );
+ _ConditionHandler* pHandler = null;
+ r = pMapEnum->GetValue(pHandler);
+ SysTryReturnResult(NID_APP, pHandler != null, r, "failed to get handler.");
String appName;
appId.SubString(10, appName);
-
pHandler->RemoveCondition(_PackageManagerImpl::GetPackageIdByAppId(appId), appName, null);
}
_ConditionManagerService::UnregisterAppLaunchByPackageId(const Tizen::App::PackageId& packageId)
{
result r = E_SUCCESS;
- _ConditionHandler* pHandler = null;
- for (int i =0; i < __handlers.GetCount(); i ++)
+
+ std::unique_ptr< IMapEnumeratorT<String, _ConditionHandler*> > pMapEnum(__handlers.GetMapEnumeratorN());
+ SysTryReturnResult(NID_APP, pMapEnum != null, r = GetLastResult(), "failed to GetMapEnumeratorN.");
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
{
- pHandler = null;
- r = __handlers.GetAt(i, pHandler);
- SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r) );
+ _ConditionHandler* pHandler = null;
+ r = pMapEnum->GetValue(pHandler);
+ SysTryReturnResult(NID_APP, pHandler != null, r, "failed to get the handler.");
pHandler->RemoveCondition(packageId, L"", null);
}
if (pCondition == null)
{
result r = E_SUCCESS;
- _ConditionHandler* pHandler = null;
- for (int i =0; i < __handlers.GetCount(); i ++)
+
+ std::unique_ptr< IMapEnumeratorT<String, _ConditionHandler*> > pMapEnum(__handlers.GetMapEnumeratorN());
+ SysTryReturn(NID_APP, pMapEnum != null, r, r, "failed to GetMapEnumeratorN. (%s)", GetLastResult());
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
{
- pHandler = null;
- r = __handlers.GetAt(i, pHandler);
- SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r) );
- if ( pHandler->HasCondition(appId, null) == true)
+ _ConditionHandler* pHandler = null;
+ r = pMapEnum->GetValue(pHandler);
+ SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r));
+
+ if (pHandler->HasCondition(appId, null) == true)
{
return true;
}
return false;
}
-
-///////////////////////////////////////////
-// internal helper
-///////////////////////////////////////////
-//TODO: save arguments
result
-_ConditionRegistryHelper::AddToRegistry(const String& sectionName, const Tizen::App::AppId& appId, /*const String& executableName,*/ const String& condition, const IList *pArg)
+_ConditionDatabaseHelper::InsertRecordToConditionDb(const String& sectionName, const AppId& appId, const int& userId,
+ const String& condition, const IList* pArgs)
{
- _RegistryImpl reg;
+ _DatabaseImpl condDb;
+ void* pBundleBuf = null;
+ int length = 0;
+ String statement;
+
+ const String& homePath = App::GetInstance()->GetAppDataPath();
+ result r = condDb.Construct(homePath + DATABASE_COND_OPERATIONS, DB_OPEN_READ_WRITE);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to create/open database '%ls'",
+ (homePath + DATABASE_COND_OPERATIONS).GetPointer());
+
+ r = condDb.BeginTransaction();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to begin database transaction.");
- result r = reg.Construct(App::GetInstance()->GetAppRootPath() + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_WRITE | REG_OPEN_CREATE, null);
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+ statement.Append(L"INSERT INTO CondTbl (SectionName, AppId, UserId, Condition, LaunchType, ArgCount, ArgLength, Arguments) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- r = reg.AddSection(sectionName);
- SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] sectionName : %ls", GetErrorMessage(r), sectionName.GetPointer() );
+ std::unique_ptr<DbStatement> pStmt(condDb.CreateStatementN(statement));
+ SysTryReturnResult(NID_APP, pStmt != null, E_FAILURE, "failed to create sql statement.");
- r = reg.AddValue(sectionName, REG_KEY_APPID, appId);
- r = reg.AddValue(sectionName, REG_KEY_CONDTION, condition);
- r = reg.AddValue(sectionName, REG_KEY_LAUNCH_TYPE, L"");
+ r = pStmt->BindString(DB_TABLE_COND_SECTION_NAME, sectionName);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind sectionName to database.");
- if (pArg != null)
+ r = pStmt->BindString(DB_TABLE_COND_APPID, appId);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind appId to database.");
+
+ r = pStmt->BindInt(DB_TABLE_COND_USERID, userId);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind userId to database.");
+
+ r = pStmt->BindString(DB_TABLE_COND_CONDITION, condition);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind condition to database.");
+
+ r = pStmt->BindString(DB_TABLE_COND_LAUNCHTYPE, L"");
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind launchtype to database.");
+
+ //Add the Arg data to bundle and then store in db
+ if (pArgs == null)
{
- String value = Integer::ToString(pArg->GetCount());
- r = reg.AddValue(sectionName, REG_KEY_ARG_COUNT, value );
+ r = pStmt->BindInt(DB_TABLE_COND_ARG_COUNT, 0);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind argcount to database.");
+ }
+ else
+ {
+ r = ConvertArgToBundleN(sectionName, pArgs, pBundleBuf, length);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to ConvertArgToBundleN.");
- const String* pCurArg = null;
- String key;
- for( int i = 0; i< pArg->GetCount(); i ++)
- {
- pCurArg = dynamic_cast<const String*>(pArg->GetAt(i));
- if (pCurArg != null)
- {
- key = REG_KEY_ARG + Integer::ToString(i);
- r = reg.AddValue(sectionName, key, *pCurArg);
- }
- }
+ r = pStmt->BindInt(DB_TABLE_COND_ARG_COUNT, pArgs->GetCount());
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind argcount to database.");
+
+ r = pStmt->BindInt(DB_TABLE_COND_ARG_LENGTH, length);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind length to database.");
+
+ r = pStmt->BindBlob(DB_TABLE_COND_ARG, pBundleBuf, length);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind pBundleBuf to database.");
}
- r = reg.Flush();
- SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+ std::unique_ptr<DbEnumerator> pEnum(condDb.ExecuteStatementN(*pStmt));
+ SysTryReturnResult(NID_APP, pEnum == null, r, "pEnum should be null as INSERT operation took place.");
- SysLog(NID_APP, "ConditionInfo is added to registry. [%ls] app(%ls), condition=%ls, lunchType=none", sectionName.GetPointer(), appId.GetPointer(), condition.GetPointer() );
+ r = condDb.CommitTransaction();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to commit database transaction.");
+ bundle_free_encoded_rawdata((bundle_raw**)&pBundleBuf);
return E_SUCCESS;
-
-CATCH:
- return r;
}
result
-_ConditionRegistryHelper::RemoveFromRegistry(const String §ion)
+_ConditionDatabaseHelper::RemoveRecordFromConditionDb(const String& sectionName)
{
- _RegistryImpl reg;
- result r = reg.Construct(App::GetInstance()->GetAppRootPath() + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_WRITE, null);
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+ _DatabaseImpl condDb;
+ String statement;
+
+ const String& homePath = App::GetInstance()->GetAppDataPath();
+ result r = condDb.Construct(homePath + DATABASE_COND_OPERATIONS, DB_OPEN_READ_WRITE);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to create/open database '%ls'",
+ (homePath + DATABASE_COND_OPERATIONS).GetPointer());
+
+ r = condDb.BeginTransaction();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to begin database transaction.");
+
+ statement.Append(L"DELETE FROM CondTbl WHERE SectionName = ?");
+ std::unique_ptr<DbStatement> pStmt(condDb.CreateStatementN(statement));
+ SysTryReturnResult(NID_APP, pStmt != null, E_FAILURE, "failed to create sql statement.");
+
+ r = pStmt->BindString(DB_TABLE_COND_SECTION_NAME, sectionName);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind sectionName to database.");
- r = reg.RemoveSection(section);
- SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+ std::unique_ptr<DbEnumerator> pEnum(condDb.ExecuteStatementN(*pStmt));
+ SysTryReturnResult(NID_APP, pEnum == null, r, "pEnum should be null as DELETE operation took place.");
- r = reg.Flush();
- SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+ r = condDb.CommitTransaction();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to commit database transaction.");
- SysLog(NID_APP, "Removed. [%ls]", section.GetPointer() );
return E_SUCCESS;
+}
-CATCH:
- return r;
+result
+_ConditionDatabaseHelper::GetAllSectionsFromConditionDb(ArrayList* pSections)
+{
+ _DatabaseImpl condDb;
+ String sectionName;
+ String sql;
+
+ const String& homePath = App::GetInstance()->GetAppDataPath();
+ result r = condDb.Construct(homePath + DATABASE_COND_OPERATIONS, DB_OPEN_READ_ONLY);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to create/open database '%ls'",
+ (homePath + DATABASE_COND_OPERATIONS).GetPointer());
+
+ sql.Append(L"SELECT SectionName FROM CondTbl");
+ std::unique_ptr<DbEnumerator> pEnum(condDb.QueryN(sql));
+ SysTryReturnResult(NID_APP, pEnum != null, E_FAILURE, "failed to query sql statement.");
+
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ r = pEnum->GetStringAt(DB_TABLE_COND_SECTION_NAME, sectionName);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get sectionName from database.");
+
+ r = pSections->Add(*new String(sectionName));
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to add sectionName to Array.");
+ }
+
+ return E_SUCCESS;
}
result
-_ConditionRegistryHelper::GetAllParamsN(const IMap& map, AppId& appId, String& condition, ArrayList*& pArgs)
+_ConditionDatabaseHelper::GetConditionEntryFromDbN(const String& sectionName, AppId& appId, int& userId,
+ String& condition, ArrayList*& pArgs)
{
- const String* pAppId = static_cast<const String*>(map.GetValue(REG_KEY_APPID));
- const String* pCondition = static_cast<const String*>(map.GetValue(REG_KEY_CONDTION));
- // const String* pLaunchMode = static_cast<const String*>(map.GetValue(REG_KEY_LAUNCH_TYPE));
- SysTryReturn(NID_APP, pAppId != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pAppId is null");
- SysTryReturn(NID_APP, pCondition != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pCondition is null");
-
- const String* pArgCount = static_cast<const String*>(map.GetValue(REG_KEY_ARG_COUNT));
- if (pArgCount != null)
+ _DatabaseImpl condDb;
+ String launchType;
+ String statement;
+ int argCount = 0;
+
+ const String& homePath = App::GetInstance()->GetAppDataPath();
+ result r = condDb.Construct(homePath + DATABASE_COND_OPERATIONS, DB_OPEN_READ_ONLY);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to create/open database '%ls'",
+ (homePath + DATABASE_COND_OPERATIONS).GetPointer());
+
+ statement.Append(L"SELECT * FROM CondTbl WHERE SectionName = ?");
+ std::unique_ptr<DbStatement> pStmt(condDb.CreateStatementN(statement));
+ SysTryReturnResult(NID_APP, pStmt != null, E_FAILURE, "failed to create sql statement.");
+
+ r = pStmt->BindString(DB_TABLE_COND_SECTION_NAME, sectionName);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to bind sectionName to database.");
+
+ std::unique_ptr<DbEnumerator> pEnum(condDb.ExecuteStatementN(*pStmt));
+ SysTryReturnResult(NID_APP, pEnum != null, E_FAILURE, "failed to execute sql statement.");
+
+ while (pEnum->MoveNext() == E_SUCCESS)
{
- int argCount;
- Integer::Parse(*pArgCount, argCount);
+ r = pEnum->GetStringAt(DB_TABLE_COND_APPID, appId);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get appId from database.");
+
+ r = pEnum->GetIntAt(DB_TABLE_COND_USERID, userId);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get userId from database.");
+
+ r = pEnum->GetStringAt(DB_TABLE_COND_CONDITION, condition);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get condition from database.");
+
+ r = pEnum->GetStringAt(DB_TABLE_COND_LAUNCHTYPE, launchType);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get launchType from database.");
+
+ //Get the bundle data from db and convert to arg format
+ r = pEnum->GetIntAt(DB_TABLE_COND_ARG_COUNT, argCount);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get argCount from database.");
+
if (argCount > 0)
{
- String key;
- const String* pValue = null;
- pArgs = new ArrayList();
- pArgs->Construct();
- for (int i = 0; i< argCount; i++)
- {
- key = REG_KEY_ARG + Integer::ToString(i);
- pValue = dynamic_cast<const String*>(map.GetValue(key));
- SysTryCatch(NID_APP, pValue != null, , GetLastResult(), "failed to get '%ls'.", key.GetPointer() );
- pArgs->Add(*new String(*pValue));
- }
+ int length = 0;
+ r = pEnum->GetIntAt(DB_TABLE_COND_ARG_LENGTH, length);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get length from database.");
+
+ void* pBundleBuf = new (std::nothrow) bundle_raw[length];
+ SysTryReturnResult(NID_APP, pBundleBuf != null, E_OUT_OF_MEMORY, "Memory allocation failure for bundle data.");
+
+ r = pEnum->GetBlobAt(DB_TABLE_COND_ARG, pBundleBuf, length);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to get pBundleBuf from database.");
+
+ r = ConvertBundleToArgN(sectionName, pBundleBuf, argCount, length, pArgs);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to ConvertBundleToArgN.");
}
}
- appId = *pAppId;
- condition = *pCondition;
+ return E_SUCCESS;
+}
+
+result
+_ConditionDatabaseHelper::ConvertArgToBundleN(const String& key, const IList* pArgs, void*& pBundleBuf, int& length)
+{
+ SysTryReturnResult(NID_APP, pArgs != null, E_OBJ_NOT_FOUND, "Argument list not available.");
+
+ bundle_raw* pBundleRaw = null;
+ String keyStr;
+ int bunRet = 0;
+ int index = 0;
+
+ bundle* pBundle = bundle_create();
+ SysTryReturnResult(NID_APP, pBundle != null, E_FAILURE, "Creating bundle failed.");
+
+ std::unique_ptr<IEnumerator> pEnum(pArgs->GetEnumeratorN());
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ keyStr.Clear();
+ String* pStr = static_cast<String*>(pEnum->GetCurrent());
+ pStr->Trim();
+
+ keyStr.Format(MAX_LEN_ARG, L"%ls_%d", key.GetPointer(), index++);
+ char* pKey = _StringConverter::CopyToCharArrayN(keyStr);
+ char* pValue = _StringConverter::CopyToCharArrayN(*pStr);
+
+ bunRet = bundle_add(pBundle, pKey, pValue);
+ delete pKey;
+ delete pValue;
+ }
+
+ bunRet = bundle_encode_raw(pBundle, &pBundleRaw, &length);
+ pBundleBuf = static_cast<void*>(pBundleRaw);
+ bundle_free(pBundle);
return E_SUCCESS;
+}
-CATCH:
- if (pArgs != null)
+result
+_ConditionDatabaseHelper::ConvertBundleToArgN(const String& key, void*& pBundleBuf, const int& argCount,
+ const int& length, ArrayList*& pArgs)
+{
+ SysTryReturnResult(NID_APP, pBundleBuf != null, E_OBJ_NOT_FOUND, "Invalid bundle memory passed.");
+
+ String keyStr;
+ bundle_raw* pBundleRaw = static_cast<bundle_raw*>(pBundleBuf);
+ bundle* pBundle = bundle_decode_raw(pBundleRaw, length);
+ SysTryReturnResult(NID_APP, pBundle != null, E_FAILURE, "Getting bundle instance failed.");
+
+ pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ SysTryReturnResult(NID_APP, pArgs != null, E_OUT_OF_MEMORY, "Allocating array failed.");
+
+ pArgs->Construct();
+ for (int loopCount = 0; loopCount < argCount; loopCount++)
{
- pArgs->RemoveAll(true);
+ keyStr.Clear();
+ keyStr.Format(MAX_LEN_ARG, L"%ls_%d", key.GetPointer(), loopCount);
+
+ char* pKey = _StringConverter::CopyToCharArrayN(keyStr);
+ const char* pValue = bundle_get_val(pBundle, pKey);
+ if (pValue)
+ {
+ pArgs->Add(*(new (std::nothrow) String(pValue)));
+ }
+ delete pKey;
}
- delete pArgs;
- pArgs = null;
- return E_FAILURE;
+ free(pBundleBuf);
+ bundle_free(pBundle);
+ return E_SUCCESS;
}
void