From: Hokwon Song Date: Tue, 16 Jul 2013 06:29:29 +0000 (+0000) Subject: Merge "Revert "Fix prevent defect for locales"" into devel_3.0_main X-Git-Tag: accepted/tizen/20130912.081851^2~116 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e65b762375b981e5f4d5970b14c55aa8c01db37d;hp=56f5b8808e88b183f03b4507370960fd5216ddac;p=platform%2Fframework%2Fnative%2Fappfw.git Merge "Revert "Fix prevent defect for locales"" into devel_3.0_main --- diff --git a/inc/FAppAppManager.h b/inc/FAppAppManager.h old mode 100755 new mode 100644 index 35bbae4..4200725 --- a/inc/FAppAppManager.h +++ b/inc/FAppAppManager.h @@ -383,7 +383,7 @@ public: L"DueTime='mm/dd/yyyy hh:mm:ss' LaunchPeriod='mm'" The specific condition is the time period after due time. L"WeeklyTime='EEE HH:mm:ss'" - The specified condition is a day of a week with a specific time at which the application is launched on a weekly basis. For multiple descriptions, "," delimiter can be used as shown in the following example:
i"Mon 09:00:00, Tue 09:00:00, Wed 09:00:00, Thu 09:00:00, Fri 09:00:00"
To specify the day of the week, it must be in one of the following supported string format:
Mon: Monday
Tue: Tuesday
Wed: Wednesday
Thu: Thursday
Fri: Friday
Sat: Saturday
Sun: Sunday + The specified condition is a day of a week with a specific time at which the application is launched on a weekly basis. For multiple descriptions, "," delimiter can be used as shown in the following example:
i"'Mon 09:00:00', 'Tue 09:00:00', 'Wed 09:00:00', 'Thu 09:00:00', 'Fri 09:00:00'"
To specify the day of the week, it must be in one of the following supported string format:
Mon: Monday
Tue: Tuesday
Wed: Wednesday
Thu: Thursday
Fri: Friday
Sat: Saturday
Sun: Sunday L"Serial='command'"The specified condition is a serial communication input command. L"NFC='command'"The specified condition is a Near Field Communication (NFC) tag that has the NFC Data Exchange Format (NDEF) data. diff --git a/inc/FSecCertICertificatePath.h b/inc/FSecCertICertificatePath.h index 7cfed08..5df9bac 100644 --- a/inc/FSecCertICertificatePath.h +++ b/inc/FSecCertICertificatePath.h @@ -213,10 +213,10 @@ public: /** * Adds a certificate to the certificate chain. - * The order of certificaett addition should be - * 1. Add user certificate. - * 2. Add intermediate certificate. - * 3. Add root CA certificate. + * The order of certificates should be as follows: @n + * 1. User certificate. + * 2. Intermediate certificate. + * 3. Root CA certificate. * * @since 2.0 * diff --git a/inc/FSecCertX509CertificatePath.h b/inc/FSecCertX509CertificatePath.h index 4f6bc60..6b3cf8b 100644 --- a/inc/FSecCertX509CertificatePath.h +++ b/inc/FSecCertX509CertificatePath.h @@ -73,11 +73,11 @@ public: virtual Tizen::Base::String GetFormat(void) const; /** - * Adds a certificate to the certificate chain. - * The order of certificaett addition should be - * 1. Add user certificate. - * 2. Add intermediate certificate. - * 3. Add root CA certificate. + * Adds a certificate to the certificate chain. + * The order of certificates should be as follows: @n + * 1. User certificate. + * 2. Intermediate certificate. + * 3. Root CA certificate. * * @since 2.0 * diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt old mode 100755 new mode 100644 index 954d3fd..e392e2e --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -67,6 +67,7 @@ SET (${this_target}_SOURCE_FILES FApp_LongevityManager.cpp FApp_AppControlResponseEvent.cpp FApp_AppLifecycleEvent.cpp + FApp_ActiveWindowManager.cpp ) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SINGLETON_CLEANUP -fvisibility=hidden") diff --git a/src/app/FApp_ActiveWindowManager.cpp b/src/app/FApp_ActiveWindowManager.cpp new file mode 100644 index 0000000..f06c428 --- /dev/null +++ b/src/app/FApp_ActiveWindowManager.cpp @@ -0,0 +1,434 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FApp_ActiveWindowManager.cpp + * @brief This is the implementation for the _ActiveWindowManager.cpp class. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include "FApp_Aul.h" +#include "FApp_ActiveWindowManager.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +//using namespace Tizen::Base::Utility; +using namespace Tizen::Base::Runtime; + +namespace +{ + +const wchar_t OSP_ECORE_X_SONAME[] = L"libecore_x.so.1"; +const wchar_t OSP_ECORE_SONAME[] = L"libecore.so.1"; +const wchar_t OSP_X11_SONAME[] = L"libX11.so.6"; + +// ActiveWindow related function and variable from shared library. +// libecore_x.so.1 +static Ecore_X_Atom(* p_ecore_x_atom_get)(const char* name) = null; +static int(* p_ecore_x_window_prop_window_get)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len) = null; +static Eina_Bool(* p_ecore_x_netwm_pid_get)(Ecore_X_Window win, int* pid) = null; +static int(* p_ecore_x_netwm_name_get)(Ecore_X_Window win, char** name) = null; +static Ecore_X_Window* (* p_ecore_x_window_root_list)(int* num_ret) = null; +static int* p_ECORE_X_EVENT_WINDOW_PROPERTY = null; +// libecore.so.1 +static Ecore_Event_Handler* (* p_ecore_event_handler_add)(int type, Ecore_Event_Handler_Cb func, const void* data) = null; +static void* (* p_ecore_event_handler_del)(Ecore_Event_Handler* event_handler) = null; +// libX11.so +static int (* p_XSelectInput)(Display* display, Window w, long event_mask) = null; +static Display* (* p_XOpenDisplay)(_Xconst char* display_name) = null; +static int (* p_XCloseDisplay)(Display* display) = null; + +static Ecore_Event_Handler* pWindowPropertyChanged = null; + +struct _DisplayDeleter +{ + void operator()(Display* pDisplay) + { + if (p_XOpenDisplay) + { + p_XCloseDisplay(pDisplay); + } + } +}; + +} // anonymous name-space + + +namespace Tizen { namespace App +{ + +_ActiveWindowManager::_ActiveWindowManager(void) + : __pX11Library(null) + , __pEcoreXLibrary(null) + , __pEcoreLibrary(null) +{ +} + +_ActiveWindowManager::~_ActiveWindowManager(void) +{ + if (__activeAppEventListenerList.GetCount() > 0) + { + if (p_ecore_event_handler_del == null) + { + _LibraryImpl& lib = GetEcoreLibraryImpl(); + p_ecore_event_handler_del = reinterpret_cast(lib.GetProcAddress(L"ecore_event_handler_del")); + } + if (p_ecore_event_handler_del) + { + if (pWindowPropertyChanged) + { + p_ecore_event_handler_del(pWindowPropertyChanged); + pWindowPropertyChanged = null; + } + } + } + + delete __pX11Library; + delete __pEcoreXLibrary; + __pEcoreXLibrary = null; + delete __pEcoreLibrary; + __pEcoreLibrary = null; +} + +Eina_Bool +_ActiveWindowManager::OnPropertyChanged(void* pData, int type, void* pEvent) +{ + if (!pData) + { + SysLog(NID_UI, "The data is not valid."); + return EINA_FALSE; + } + + _ActiveWindowManager* pThis = static_cast<_ActiveWindowManager*>(pData); + + if (p_ecore_x_atom_get == null) + { + _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl(); + p_ecore_x_atom_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_atom_get")); + SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, EINA_FALSE, + "A system error has been occurred. Failed to get ecore_x_atom_get."); + } + if (p_ecore_x_window_prop_window_get == null) + { + _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl(); + p_ecore_x_window_prop_window_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_prop_window_get")); + SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE, + "A system error has been occurred. Failed to get ecore_x_window_prop_window_get."); + } + if (p_ecore_x_netwm_pid_get == null) + { + _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl(); + p_ecore_x_netwm_pid_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_netwm_pid_get")); + SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE, + "A system error has been occurred. Failed to get ecore_x_netwm_pid_get."); + } + if (p_ecore_x_netwm_name_get == null) + { + _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl(); + p_ecore_x_netwm_name_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_netwm_name_get")); + SysTryReturnResult(NID_APP, p_ecore_x_netwm_name_get != null, EINA_FALSE, + "A system error has been occurred. Failed to get ecore_x_netwm_name_get."); + } + + if (!pEvent) + { + SysLog(NID_UI, "The event is not valid."); + return EINA_FALSE; + } + + Ecore_X_Event_Window_Property* pE = (Ecore_X_Event_Window_Property*) pEvent; + Ecore_X_Atom atom = pE->atom; + Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW"); + + if (atom != activeAtom) + { + return ECORE_CALLBACK_PASS_ON; + } + + Ecore_X_Window win = pE->win; + Ecore_X_Window activeWin = 0; + p_ecore_x_window_prop_window_get(win, activeAtom, &activeWin, 1); + + int pid = 0; + p_ecore_x_netwm_pid_get(activeWin, &pid); + + char* pAppName = null; + p_ecore_x_netwm_name_get(activeWin, &pAppName); + + pThis->FireActiveAppEvent(activeWin, pid, pAppName); + + if (pAppName) + { + free(pAppName); + } + + return ECORE_CALLBACK_PASS_ON; +} + +result +_ActiveWindowManager::AddActiveAppEventListener(IActiveAppEventListener& listener) +{ + if (p_ecore_x_window_root_list == null) + { + _LibraryImpl& lib = GetEcoreXLibraryImpl(); + p_ecore_x_window_root_list = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_root_list")); + SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, E_SYSTEM, + "A system error has been occurred. Failed to get p_ecore_x_window_root_list."); + } + if (p_ECORE_X_EVENT_WINDOW_PROPERTY == null) + { + _LibraryImpl& lib = GetEcoreXLibraryImpl(); + p_ECORE_X_EVENT_WINDOW_PROPERTY = reinterpret_cast(lib.GetProcAddress(L"ECORE_X_EVENT_WINDOW_PROPERTY")); + SysTryReturnResult(NID_APP, p_ECORE_X_EVENT_WINDOW_PROPERTY != null, E_SYSTEM, + "A system error has been occurred. Failed to get p_ECORE_X_EVENT_WINDOW_PROPERTY."); + } + if (p_XOpenDisplay == null) + { + _LibraryImpl& lib = GetX11LibraryImpl(); + p_XOpenDisplay = reinterpret_cast(lib.GetProcAddress(L"XOpenDisplay")); + SysTryReturnResult(NID_APP, p_XOpenDisplay != null, E_SYSTEM, + "A system error has been occurred. Failed to get p_XOpenDisplay."); + } + if (p_XCloseDisplay == null) + { + _LibraryImpl& lib = GetX11LibraryImpl(); + p_XCloseDisplay = reinterpret_cast(lib.GetProcAddress(L"XCloseDisplay")); + SysTryReturnResult(NID_APP, p_XCloseDisplay != null, E_SYSTEM, + "A system error has been occurred. Failed to get p_XCloseDisplay."); + } + if (p_XSelectInput == null) + { + _LibraryImpl& lib = GetX11LibraryImpl(); + p_XSelectInput = reinterpret_cast(lib.GetProcAddress(L"XSelectInput")); + SysTryReturnResult(NID_APP, p_XSelectInput != null, E_SYSTEM, + "A system error has been occurred. Failed to get p_XSelectInput."); + } + + if (p_ecore_event_handler_add == null) + { + _LibraryImpl& lib = GetEcoreLibraryImpl(); + p_ecore_event_handler_add = reinterpret_cast(lib.GetProcAddress(L"ecore_event_handler_add")); + SysTryReturnResult(NID_APP, p_ecore_event_handler_add != null, E_SYSTEM, + "A system error has been occurred. Failed to get p_ecore_event_handler_add."); + } + + bool alreadyExist = __activeAppEventListenerList.Contains(&listener); + SysTryReturnResult(NID_APP, !alreadyExist, E_OBJ_ALREADY_EXIST, "The event listener already exist."); + result r = __activeAppEventListenerList.Add(&listener); + SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); + + if (!pWindowPropertyChanged) + { + std::unique_ptr pDisplay(p_XOpenDisplay(NULL)); + SysTryReturnResult(NID_APP, pDisplay != null, E_SYSTEM, "A system error has been occurred. Failed to XOpenDisplay."); + + int num = 0; + Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num); + SysTryReturnResult(NID_APP, pRoots != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + for (int i = 0; i < num; i++) + { + p_XSelectInput(pDisplay.get(), pRoots[i], PropertyChangeMask); + } + + pWindowPropertyChanged = p_ecore_event_handler_add(*p_ECORE_X_EVENT_WINDOW_PROPERTY, OnPropertyChanged, (void*) this); + free(pRoots); + SysTryReturnResult(NID_APP, pWindowPropertyChanged, E_SYSTEM, "A system error has been occurred."); + } + + return r; +} + +result +_ActiveWindowManager::RemoveActiveAppEventListener(IActiveAppEventListener& listener) +{ + if (p_ecore_event_handler_del == null) + { + _LibraryImpl& lib = GetEcoreLibraryImpl(); + p_ecore_event_handler_del = reinterpret_cast(lib.GetProcAddress(L"ecore_event_handler_del")); + SysTryReturnResult(NID_APP, p_ecore_event_handler_del != null, E_SYSTEM, + "A system error has been occurred. Failed to get p_ecore_event_handler_del."); + } + + result r = __activeAppEventListenerList.Remove(&listener); + SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); + + if (__activeAppEventListenerList.GetCount() == 0) + { + p_ecore_event_handler_del(pWindowPropertyChanged); + pWindowPropertyChanged = null; + } + + return r; +} + + +void +_ActiveWindowManager::FireActiveAppEvent(unsigned int xid, int pid, const char* pAppName) +{ + static int oldPid = 0; + if (oldPid != pid) + { + oldPid = pid; + char pkgname[255] = {0, }; + if ((AUL_R_OK != aul_app_get_pkgname_bypid(pid, pkgname, 255)) || pkgname[0] == 0) + { + SysSecureLog(NID_APP, "Failed to get the package name from pid=%x pAppName=%s", pid, pAppName ? pAppName : "null"); + return; + } + AppId appId(_Aul::GetRealAppId(String(pkgname))); + + std::unique_ptr > pEnum(__activeAppEventListenerList.GetEnumeratorN()); + if (pEnum.get()) + { + while (pEnum->MoveNext() == E_SUCCESS) + { + Tizen::App::IActiveAppEventListener* pListener = null; + pEnum->GetCurrent(pListener); + if (pListener) + { + pListener->OnActiveAppChanged(appId); + } + } + } + } +} + + +result +_ActiveWindowManager::GetActiveApp(AppId& appId) +{ + const unsigned int windowId = GetActiveWindow(); + const int processId = GetProcessId(windowId); + char pkgname[255] = {0, }; + aul_app_get_pkgname_bypid(processId, pkgname, 255); + + appId = _Aul::GetRealAppId(String(pkgname)); + + SysLog(NID_APP, "ActiveApp is %ls.", appId.GetPointer()); + return E_SUCCESS; +} + +_LibraryImpl& +_ActiveWindowManager::GetEcoreXLibraryImpl(void) +{ + if (__pEcoreXLibrary == null) + { + __pEcoreXLibrary = new (std::nothrow) _LibraryImpl; + SysAssertf(__pEcoreXLibrary != null, "_LibraryImpl allocation failure."); + + result r = __pEcoreXLibrary->Construct(OSP_ECORE_X_SONAME); + SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r)); + } + return *__pEcoreXLibrary; +} + +_LibraryImpl& +_ActiveWindowManager::GetEcoreLibraryImpl(void) +{ + if (__pEcoreLibrary == null) + { + __pEcoreLibrary = new (std::nothrow) _LibraryImpl; + SysAssertf(__pEcoreLibrary != null, "_LibraryImpl allocation failure."); + + result r = __pEcoreLibrary->Construct(OSP_ECORE_SONAME); + SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r)); + } + return *__pEcoreLibrary; +} + +_LibraryImpl& +_ActiveWindowManager::GetX11LibraryImpl(void) +{ + if (__pX11Library == null) + { + __pX11Library = new (std::nothrow) _LibraryImpl; + SysAssertf(__pX11Library != null, "_LibraryImpl allocation failure."); + + result r = __pX11Library->Construct(OSP_X11_SONAME); + SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r)); + } + return *__pX11Library; +} + +unsigned int +_ActiveWindowManager::GetActiveWindow(void) +{ + if (p_ecore_x_window_root_list == null) + { + _LibraryImpl& lib = GetEcoreXLibraryImpl(); + p_ecore_x_window_root_list = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_root_list")); + SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, 0, + "A system error has been occurred. Failed to get p_ecore_x_window_root_list."); + } + if (p_ecore_x_atom_get == null) + { + _LibraryImpl& lib = GetEcoreXLibraryImpl(); + p_ecore_x_atom_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_atom_get")); + SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, 0, + "A system error has been occurred. Failed to get ecore_x_atom_get."); + } + if (p_ecore_x_window_prop_window_get == null) + { + _LibraryImpl& lib = GetEcoreXLibraryImpl(); + p_ecore_x_window_prop_window_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_prop_window_get")); + SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE, + "A system error has been occurred. Failed to get ecore_x_window_prop_window_get."); + } + + int num = 0; + Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num); + + Ecore_X_Window activeWin = 0; + if (pRoots) + { + Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW"); + p_ecore_x_window_prop_window_get(pRoots[0], activeAtom, &activeWin, 1); + free(pRoots); + } + + return activeWin; +} + +int +_ActiveWindowManager::GetProcessId(unsigned int window) +{ + if (p_ecore_x_netwm_pid_get == null) + { + _LibraryImpl& lib = GetEcoreXLibraryImpl(); + p_ecore_x_netwm_pid_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_netwm_pid_get")); + SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE, + "A system error has been occurred. Failed to get ecore_x_netwm_pid_get."); + } + + int pid = 0; + p_ecore_x_netwm_pid_get(window, &pid); + + return pid; +} + +}} // Tizen::App diff --git a/src/app/FApp_ActiveWindowManager.h b/src/app/FApp_ActiveWindowManager.h new file mode 100644 index 0000000..2dcf696 --- /dev/null +++ b/src/app/FApp_ActiveWindowManager.h @@ -0,0 +1,100 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FApp_ActiveWindowManager.h + * @brief This is the header file of the %_ActiveWindowManager class. + * + * This header file contains the declarations of the %_ActiveWindowManager class. + */ + +#ifndef _FAPP_INTERNAL_ACTIVE_WINDOW_MANAGER_H_ +#define _FAPP_INTERNAL_ACTIVE_WINDOW_MANAGER_H_ + +#include +#include + +#include + + +namespace Tizen { namespace Base +{ + class String; + namespace Runtime + { + class _LibraryImpl; + } +}} + +namespace Tizen { namespace App +{ + +class _IActiveAppEventListener; + +/** + * @class _ActiveWindowManager + * @brief + */ +class _OSP_LOCAL_ _ActiveWindowManager +{ +public: + _ActiveWindowManager(void); + + ~_ActiveWindowManager(void); + + result AddActiveAppEventListener(IActiveAppEventListener& listener); + + result RemoveActiveAppEventListener(IActiveAppEventListener& listener); + + result GetActiveApp(AppId& appId); + +private: + Tizen::Base::Runtime::_LibraryImpl& GetEcoreXLibraryImpl(void); + + Tizen::Base::Runtime::_LibraryImpl& GetEcoreLibraryImpl(void); + + Tizen::Base::Runtime::_LibraryImpl& GetX11LibraryImpl(void); + + static Eina_Bool OnPropertyChanged(void* pData, int type, void* pEvent); + + void FireActiveAppEvent(unsigned int xid, int pid, const char* pAppName); + + unsigned int GetActiveWindow(void); + + int GetProcessId(unsigned int window); + + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + */ + _ActiveWindowManager(const _ActiveWindowManager& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. + */ + _ActiveWindowManager& operator=(const _ActiveWindowManager& rhs); + +private: + Tizen::Base::Runtime::_LibraryImpl* __pX11Library; + Tizen::Base::Runtime::_LibraryImpl* __pEcoreXLibrary; + Tizen::Base::Runtime::_LibraryImpl* __pEcoreLibrary; + + Tizen::Base::Collection::LinkedListT __activeAppEventListenerList; +}; + +}} // Tizen::App + +#endif //_FAPP_INTERNAL_ACTIVE_WINDOW_MANAGER_H_ + diff --git a/src/app/FApp_AppManagerImpl.cpp b/src/app/FApp_AppManagerImpl.cpp old mode 100755 new mode 100644 index fe907a7..7cc180f --- a/src/app/FApp_AppManagerImpl.cpp +++ b/src/app/FApp_AppManagerImpl.cpp @@ -27,9 +27,6 @@ #include #include #include -#include -#include -#include #include #include @@ -48,6 +45,7 @@ #include #include #include +#include #include "FApp_AppControlRegistry.h" #include "FApp_AppImpl.h" @@ -65,12 +63,13 @@ #include "FAppPkg_PackageManagerImpl.h" #include "FAppPkg_PackageInfoImpl.h" #include "FApp_AppControlManager.h" +#include "FApp_TemplateUtil.h" #include "FApp_Aul.h" -#include "FSys_SystemInfoImpl.h" - #include "FApp_AppLifecycleEvent.h" #include "FApp_AppLifecycleEventArg.h" #include "FApp_IAppLifecycleEventListener.h" +#include "FApp_ActiveWindowManager.h" + using namespace Tizen::App::Package; using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -85,35 +84,6 @@ namespace const long MAX_APPCONTROL_ARGUMENT = 1024; const long MAX_CONDITION_LENGTH = 400; -// ActiveWindow related function and variable from shared library. -// libecore_x.so.1 -static Ecore_X_Atom(* p_ecore_x_atom_get)(const char* name) = null; -static int(* p_ecore_x_window_prop_window_get)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len) = null; -static Eina_Bool(* p_ecore_x_netwm_pid_get)(Ecore_X_Window win, int* pid) = null; -static int(* p_ecore_x_netwm_name_get)(Ecore_X_Window win, char** name) = null; -static Ecore_X_Window* (* p_ecore_x_window_root_list)(int* num_ret) = null; -static int* p_ECORE_X_EVENT_WINDOW_PROPERTY = null; -// libecore.so.1 -static Ecore_Event_Handler* (* p_ecore_event_handler_add)(int type, Ecore_Event_Handler_Cb func, const void* data) = null; -static void* (* p_ecore_event_handler_del)(Ecore_Event_Handler* event_handler) = null; -// libX11.so -static int (* p_XSelectInput)(Display* display, Window w, long event_mask) = null; -static Display* (* p_XOpenDisplay)(_Xconst char* display_name) = null; -static int (* p_XCloseDisplay)(Display* display) = null; - -Ecore_Event_Handler* pWindowPropertyChanged = null; - -struct _DisplayDeleter -{ - void operator()(Display* pDisplay) - { - if (p_XOpenDisplay) - { - p_XCloseDisplay(pDisplay); - } - } -}; - int GetTotalSize(const Tizen::Base::Collection::ICollection& col) { @@ -136,81 +106,6 @@ GetTotalSize(const Tizen::Base::Collection::ICollection& col) return size; } -Eina_Bool -OnPropertyChanged(void* pData, int type, void* pEvent) -{ - using namespace Tizen::App; - - if (p_ecore_x_atom_get == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_atom_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_atom_get")); - SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, EINA_FALSE, - "A system error has been occurred. Failed to get ecore_x_atom_get."); - } - if (p_ecore_x_window_prop_window_get == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_window_prop_window_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_prop_window_get")); - SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE, - "A system error has been occurred. Failed to get ecore_x_window_prop_window_get."); - } - if (p_ecore_x_netwm_pid_get == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_netwm_pid_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_netwm_pid_get")); - SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE, - "A system error has been occurred. Failed to get ecore_x_netwm_pid_get."); - } - if (p_ecore_x_netwm_name_get == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_netwm_name_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_netwm_name_get")); - SysTryReturnResult(NID_APP, p_ecore_x_netwm_name_get != null, EINA_FALSE, - "A system error has been occurred. Failed to get ecore_x_netwm_name_get."); - } - - if (!pData) - { - SysLog(NID_UI, "The data is not valid."); - return EINA_FALSE; - } - if (!pEvent) - { - SysLog(NID_UI, "The event is not valid."); - return EINA_FALSE; - } - - Ecore_X_Event_Window_Property* pE = (Ecore_X_Event_Window_Property*) pEvent; - Ecore_X_Atom atom = pE->atom; - Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW"); - - if (atom != activeAtom) - { - return ECORE_CALLBACK_PASS_ON; - } - - Ecore_X_Window win = pE->win; - Ecore_X_Window activeWin = 0; - p_ecore_x_window_prop_window_get(win, activeAtom, &activeWin, 1); - - int pid = 0; - p_ecore_x_netwm_pid_get(activeWin, &pid); - - char* pAppName = null; - p_ecore_x_netwm_name_get(activeWin, &pAppName); - - Tizen::App::_AppManagerImpl* pAppManagerImpl = static_cast(pData); - pAppManagerImpl->FireActiveAppEvent(activeWin, pid, pAppName); - - if (pAppName) - { - free(pAppName); - } - - return ECORE_CALLBACK_PASS_ON; -} - } // anonymous name-space @@ -220,19 +115,13 @@ namespace Tizen { namespace App const wchar_t LEGACY_LAUNCH_REASON_NORMAL[] = L"LAUNCH_NORMAL"; const wchar_t LEGACY_LAUNCH_REASON_CONDITIONAL[] = L"LAUNCH_CONDITIONAL"; const wchar_t OSP_UI_SONAME[] = L"libosp-uifw.so.1"; -const wchar_t OSP_ECORE_X_SONAME[] = L"libecore_x.so.1"; -const wchar_t OSP_ECORE_SONAME[] = L"libecore.so.1"; -const wchar_t OSP_X11_SONAME[] = L"libX11.so.6"; const int _MAX_PACKAGE_ID_LENGTH = 10; -_LibraryImpl* _AppManagerImpl::__pEcoreLibrary = null; -_LibraryImpl* _AppManagerImpl::__pEcoreXLibrary = null; _AppManagerImpl::_AppManagerImpl(void) : __pConditionManager(null) - , __eventListenerCount(0) + , __pActiveWindowManager(new (std::nothrow) _ActiveWindowManager) , __pUiLibrary(null) - , __pX11Library(null) { SysLog(NID_APP, ""); } @@ -241,30 +130,8 @@ _AppManagerImpl::~_AppManagerImpl(void) { SysLog(NID_APP, ""); - if (__activeAppEventListenerList.GetCount() > 0) - { - if (p_ecore_event_handler_del == null) - { - _LibraryImpl& lib = GetEcoreLibraryImpl(); - p_ecore_event_handler_del = reinterpret_cast(lib.GetProcAddress(L"ecore_event_handler_del")); - } - if (p_ecore_event_handler_del) - { - if (pWindowPropertyChanged) - { - p_ecore_event_handler_del(pWindowPropertyChanged); - pWindowPropertyChanged = null; - } - } - } - delete __pConditionManager; delete __pUiLibrary; - delete __pX11Library; - delete __pEcoreXLibrary; - __pEcoreXLibrary = null; - delete __pEcoreLibrary; - __pEcoreLibrary = null; } @@ -273,8 +140,9 @@ _AppManagerImpl::Construct(void) { __appManagerEvent.Construct(); __appLifecycleEvent.Construct(); - __appListForAppLifecycle.Construct(0, 0, __strHashCodeProvider, __comparer); - __mutex.Create(); + __appListForAppLifecycle.Construct(); + result r = __mutex.Create(); + SysTryLog(NID_APP, r == E_SUCCESS, "Creating mutex failed."); _IAppManager* pMgr = _AppManagerProxy::GetService(); //todo : uncomment following _SysTryReturn or put assert. @@ -825,10 +693,10 @@ _AppManagerImpl::AddEventListener(_IAppManagerEventListener& listener) result r = __appManagerEvent.AddListener(listener); SysTryReturn(NID_APP, IsFailed(r) == false, r, r, "[%s]", GetErrorMessage(r)); - __eventListenerCount++; - SysLog(NID_APP, "registered event listener(s) # %d", __eventListenerCount); + const int count = __appManagerEvent.GetListenerCount(); + SysLog(NID_APP, "registered event listener(s) # %d", count); - if( __eventListenerCount > 1) + if (count > 1) { return E_SUCCESS; } @@ -845,10 +713,10 @@ _AppManagerImpl::RemoveEventListener(_IAppManagerEventListener& listener) result r = __appManagerEvent.RemoveListener(listener); SysTryReturn(NID_APP, IsFailed(r) == false, r, r, "[%s]", GetErrorMessage(r)); - __eventListenerCount--; - SysLog(NID_APP, "registered event listener(s) # %d", __eventListenerCount); + const int count = __appManagerEvent.GetListenerCount(); + SysLog(NID_APP, "registered event listener(s) # %d", count); - if (__eventListenerCount == 0) + if (count == 0) { return pMgr->RemoveEventListener(-1); } @@ -1019,245 +887,28 @@ _AppManagerImpl::GetUiLibraryImpl(void) return *__pUiLibrary; } -_LibraryImpl& -_AppManagerImpl::GetEcoreXLibraryImpl(void) -{ - if (__pEcoreXLibrary == null) - { - __pEcoreXLibrary = new (std::nothrow) _LibraryImpl; - SysAssertf(__pEcoreXLibrary != null, "_LibraryImpl allocation failure."); - - result r = __pEcoreXLibrary->Construct(OSP_ECORE_X_SONAME); - SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r)); - } - return *__pEcoreXLibrary; -} - -_LibraryImpl& -_AppManagerImpl::GetEcoreLibraryImpl(void) -{ - if (__pEcoreLibrary == null) - { - __pEcoreLibrary = new (std::nothrow) _LibraryImpl; - SysAssertf(__pEcoreLibrary != null, "_LibraryImpl allocation failure."); - - result r = __pEcoreLibrary->Construct(OSP_ECORE_SONAME); - SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r)); - } - return *__pEcoreLibrary; -} - -_LibraryImpl& -_AppManagerImpl::GetX11LibraryImpl(void) -{ - if (__pX11Library == null) - { - __pX11Library = new (std::nothrow) _LibraryImpl; - SysAssertf(__pX11Library != null, "_LibraryImpl allocation failure."); - - result r = __pX11Library->Construct(OSP_X11_SONAME); - SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r)); - } - return *__pX11Library; -} - -void -_AppManagerImpl::FireActiveAppEvent(unsigned int xid, int pid, char* pAppName) -{ - static int oldPid = 0; - if (oldPid != pid) - { - oldPid = pid; - char pkgname[255] = {0, }; - if ((AUL_R_OK != aul_app_get_pkgname_bypid(pid, pkgname, 255)) || pkgname[0] == 0) - { - SysSecureLog(NID_APP, "Failed to get the package name from pid=%x pAppName=%s", pid, pAppName ? pAppName : "null"); - return; - } - AppId appId(_Aul::GetRealAppId(String(pkgname))); - - std::unique_ptr > pEnum(__activeAppEventListenerList.GetEnumeratorN()); - if (pEnum.get()) - { - while (pEnum->MoveNext() == E_SUCCESS) - { - Tizen::App::IActiveAppEventListener* pListener = null; - pEnum->GetCurrent(pListener); - if (pListener) - { - pListener->OnActiveAppChanged(appId); - } - } - } - } -} - -unsigned int -_AppManagerImpl::GetActiveWindow(void) -{ - if (p_ecore_x_window_root_list == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_window_root_list = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_root_list")); - SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, 0, - "A system error has been occurred. Failed to get p_ecore_x_window_root_list."); - } - if (p_ecore_x_atom_get == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_atom_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_atom_get")); - SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, 0, - "A system error has been occurred. Failed to get ecore_x_atom_get."); - } - if (p_ecore_x_window_prop_window_get == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_window_prop_window_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_prop_window_get")); - SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE, - "A system error has been occurred. Failed to get ecore_x_window_prop_window_get."); - } - - int num = 0; - Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num); - - Ecore_X_Window activeWin = 0; - if (pRoots) - { - Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW"); - p_ecore_x_window_prop_window_get(pRoots[0], activeAtom, &activeWin, 1); - free(pRoots); - } - - return activeWin; -} - -int -_AppManagerImpl::GetProcessId(unsigned int window) -{ - if (p_ecore_x_netwm_pid_get == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_netwm_pid_get = reinterpret_cast(lib.GetProcAddress(L"ecore_x_netwm_pid_get")); - SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE, - "A system error has been occurred. Failed to get ecore_x_netwm_pid_get."); - } - - int pid = 0; - p_ecore_x_netwm_pid_get(window, &pid); - - return pid; -} result _AppManagerImpl::AddActiveAppEventListener(IActiveAppEventListener& listener) { - if (p_ecore_x_window_root_list == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ecore_x_window_root_list = reinterpret_cast(lib.GetProcAddress(L"ecore_x_window_root_list")); - SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, E_SYSTEM, - "A system error has been occurred. Failed to get p_ecore_x_window_root_list."); - } - if (p_ECORE_X_EVENT_WINDOW_PROPERTY == null) - { - _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl(); - p_ECORE_X_EVENT_WINDOW_PROPERTY = reinterpret_cast(lib.GetProcAddress(L"ECORE_X_EVENT_WINDOW_PROPERTY")); - SysTryReturnResult(NID_APP, p_ECORE_X_EVENT_WINDOW_PROPERTY != null, E_SYSTEM, - "A system error has been occurred. Failed to get p_ECORE_X_EVENT_WINDOW_PROPERTY."); - } - if (p_XOpenDisplay == null) - { - _LibraryImpl& lib = GetX11LibraryImpl(); - p_XOpenDisplay = reinterpret_cast(lib.GetProcAddress(L"XOpenDisplay")); - SysTryReturnResult(NID_APP, p_XOpenDisplay != null, E_SYSTEM, - "A system error has been occurred. Failed to get p_XOpenDisplay."); - } - if (p_XCloseDisplay == null) - { - _LibraryImpl& lib = GetX11LibraryImpl(); - p_XCloseDisplay = reinterpret_cast(lib.GetProcAddress(L"XCloseDisplay")); - SysTryReturnResult(NID_APP, p_XCloseDisplay != null, E_SYSTEM, - "A system error has been occurred. Failed to get p_XCloseDisplay."); - } - if (p_XSelectInput == null) - { - _LibraryImpl& lib = GetX11LibraryImpl(); - p_XSelectInput = reinterpret_cast(lib.GetProcAddress(L"XSelectInput")); - SysTryReturnResult(NID_APP, p_XSelectInput != null, E_SYSTEM, - "A system error has been occurred. Failed to get p_XSelectInput."); - } - if (p_ecore_event_handler_add == null) - { - _LibraryImpl& lib = GetEcoreLibraryImpl(); - p_ecore_event_handler_add = reinterpret_cast(lib.GetProcAddress(L"ecore_event_handler_add")); - SysTryReturnResult(NID_APP, p_ecore_event_handler_add != null, E_SYSTEM, - "A system error has been occurred. Failed to get p_ecore_event_handler_add."); - } - - bool alreadyExist = __activeAppEventListenerList.Contains(&listener); - SysTryReturnResult(NID_APP, !alreadyExist, E_OBJ_ALREADY_EXIST, "The event listener already exist."); - result r = __activeAppEventListenerList.Add(&listener); - SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); - - if (!pWindowPropertyChanged) - { - std::unique_ptr pDisplay(p_XOpenDisplay(NULL)); - SysTryReturnResult(NID_APP, pDisplay != null, E_SYSTEM, "A system error has been occurred. Failed to XOpenDisplay."); - - int num = 0; - Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num); - SysTryReturnResult(NID_APP, pRoots != null, E_OUT_OF_MEMORY, "Memory allocation failed."); - - for (int i = 0; i < num; i++) - { - p_XSelectInput(pDisplay.get(), pRoots[i], PropertyChangeMask); - } - - pWindowPropertyChanged = p_ecore_event_handler_add(*p_ECORE_X_EVENT_WINDOW_PROPERTY, OnPropertyChanged, (void*) this); - free(pRoots); - SysTryReturnResult(NID_APP, pWindowPropertyChanged, E_SYSTEM, "A system error has been occurred."); - } - - return r; + return __pActiveWindowManager->AddActiveAppEventListener(listener); } + result _AppManagerImpl::RemoveActiveAppEventListener(IActiveAppEventListener& listener) { - if (p_ecore_event_handler_del == null) - { - _LibraryImpl& lib = GetEcoreLibraryImpl(); - p_ecore_event_handler_del = reinterpret_cast(lib.GetProcAddress(L"ecore_event_handler_del")); - SysTryReturnResult(NID_APP, p_ecore_event_handler_del != null, E_SYSTEM, - "A system error has been occurred. Failed to get p_ecore_event_handler_del."); - } - - result r = __activeAppEventListenerList.Remove(&listener); - SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); - - if (__activeAppEventListenerList.GetCount() == 0) - { - p_ecore_event_handler_del(pWindowPropertyChanged); - pWindowPropertyChanged = null; - } - - return r; + return __pActiveWindowManager->RemoveActiveAppEventListener(listener); } + result _AppManagerImpl::GetActiveApp(AppId& appId) { - const unsigned int windowId = GetActiveWindow(); - const int processId = GetProcessId(windowId); - char pkgname[255] = {0, }; - aul_app_get_pkgname_bypid(processId, pkgname, 255); - - appId = _Aul::GetRealAppId(String(pkgname)); - - SysLog(NID_APP, "ActiveApp is %ls.", appId.GetPointer()); - return E_SUCCESS; + return __pActiveWindowManager->GetActiveApp(appId); } + bool _AppManagerImpl::IsUserPreferredAppForAppControlResolution(const AppId& appId) const { @@ -1294,6 +945,7 @@ _AppManagerImpl::RegisterAppForAppLifecycleEvent(const AppId& appId) SysLog(NID_APP, "Enter"); result r = __mutex.Acquire(); + SysTryLog(NID_APP, r == E_SUCCESS, "Acquiring mutex failed."); bool isContained = false; r = __appListForAppLifecycle.ContainsKey(appId, isContained); @@ -1315,6 +967,7 @@ _AppManagerImpl::RegisterAppForAppLifecycleEvent(const AppId& appId) SysLog(NID_APP, "The appId(%ls) is registered.", appId.GetPointer()); } r = __mutex.Release(); + SysTryLog(NID_APP, r == E_SUCCESS, "Releasing mutex failed."); SysLog(NID_APP, "Exit"); @@ -1327,6 +980,7 @@ _AppManagerImpl::UnregisterAppForAppLifecycleEvent(const AppId& appId) SysLog(NID_APP, "Enter"); result r = __mutex.Acquire(); + SysTryLog(NID_APP, r == E_SUCCESS, "Acquiring mutex failed."); bool isContained = false; r = __appListForAppLifecycle.ContainsKey(appId, isContained); @@ -1341,7 +995,7 @@ _AppManagerImpl::UnregisterAppForAppLifecycleEvent(const AppId& appId) if (currentRefCnt < 0) { r = __appListForAppLifecycle.Remove(appId); - + _IAppManager* pMgr = _AppManagerProxy::GetService(); SysTryReturnResult(NID_APP, pMgr, E_SYSTEM, "_AppManagerProxy::GetService() is failed."); @@ -1352,7 +1006,7 @@ _AppManagerImpl::UnregisterAppForAppLifecycleEvent(const AppId& appId) else { r = __appListForAppLifecycle.SetValue(appId, currentRefCnt); - } + } } else { @@ -1360,6 +1014,7 @@ _AppManagerImpl::UnregisterAppForAppLifecycleEvent(const AppId& appId) } r = __mutex.Release(); + SysTryLog(NID_APP, r == E_SUCCESS, "Releasing mutex failed."); SysLog(NID_APP, "Exit"); diff --git a/src/app/FApp_AppManagerProxy.cpp b/src/app/FApp_AppManagerProxy.cpp index 05f884b..48cab0c 100755 --- a/src/app/FApp_AppManagerProxy.cpp +++ b/src/app/FApp_AppManagerProxy.cpp @@ -312,7 +312,7 @@ _AppManagerProxy::OnAppLifecycleEventReceived(const AppId& appId, int appLifecyc { SysTryLog(NID_APP, __pServiceEventListener != null, "__pServiceEventListener instance must not be null."); - _AppLifecycleEventType eventType; + _AppLifecycleEventType eventType = _APP_LIFECYCLE_EVENT_LAUNCH; if (appLifecycleEventType == 0) { diff --git a/src/app/inc/FApp_AppManagerImpl.h b/src/app/inc/FApp_AppManagerImpl.h old mode 100755 new mode 100644 index fefdcda..2929f64 --- a/src/app/inc/FApp_AppManagerImpl.h +++ b/src/app/inc/FApp_AppManagerImpl.h @@ -22,20 +22,17 @@ #ifndef _FAPP_INTERNAL_APP_MANAGER_IMPL_H_ #define _FAPP_INTERNAL_APP_MANAGER_IMPL_H_ -#include +#include #include #include #include -#include #include #include #include #include #include #include -#include -#include #include "FApp_Types.h" #include "FApp_AppManagerEvent.h" @@ -65,6 +62,7 @@ class _IAppManagerEventListener; class _IAppEventListener; class _AppManagerEventArg; class _IAppLifecycleEventListener; +class _ActiveWindowManager; class _AppLifecycleManager @@ -366,24 +364,14 @@ public: virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType); - static void SetAppManagerService(_IAppManager* pAppManager ); - _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void); - static Tizen::Base::Runtime::_LibraryImpl& GetEcoreXLibraryImpl(void); - - static Tizen::Base::Runtime::_LibraryImpl& GetEcoreLibraryImpl(void); - - Tizen::Base::Runtime::_LibraryImpl& GetX11LibraryImpl(void); - result AddActiveAppEventListener(IActiveAppEventListener& listener); result RemoveActiveAppEventListener(IActiveAppEventListener& listener); result GetActiveApp(AppId& appId); - void FireActiveAppEvent(unsigned int xid, int pid, char* pAppName); - bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const; result ClearUserPreferenceForAppControlResolution(const AppId& appId); @@ -409,26 +397,14 @@ private: _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void); - unsigned int GetActiveWindow(void); - - int GetProcessId(unsigned int window); - - static void AppEventCallback(app_context_h app_context, app_context_event_e event, void* pData); - private: _ConditionManagerProxy* __pConditionManager; - int __eventListenerCount; + std::unique_ptr<_ActiveWindowManager> __pActiveWindowManager; Tizen::Base::Runtime::_LibraryImpl* __pUiLibrary; - Tizen::Base::Runtime::_LibraryImpl* __pX11Library; - static Tizen::Base::Runtime::_LibraryImpl* __pEcoreXLibrary; - static Tizen::Base::Runtime::_LibraryImpl* __pEcoreLibrary; _AppLifecycleManager __lifeManager; _AppManagerEvent __appManagerEvent; - Tizen::Base::Collection::LinkedListT __activeAppEventListenerList; Tizen::App::_AppLifecycleEvent __appLifecycleEvent; Tizen::Base::Collection::HashMapT __appListForAppLifecycle; - Tizen::Base::ComparerT __comparer; - Tizen::Base::StringHashCodeProvider __strHashCodeProvider; Tizen::Base::Runtime::Mutex __mutex; friend class AppManager; @@ -437,7 +413,6 @@ private: friend class _MapDataControlImpl; friend class _DataControlProviderManagerImpl; friend class _AppControlProviderManagerImpl; - friend class _ActiveWindowEventListener; friend class Tizen::Io::_DataControlResultSetImpl; }; // _AppManagerImpl diff --git a/src/base/utility/FBaseUtil_ScannerImpl.cpp b/src/base/utility/FBaseUtil_ScannerImpl.cpp index 4e6fe41..794d4dd 100644 --- a/src/base/utility/FBaseUtil_ScannerImpl.cpp +++ b/src/base/utility/FBaseUtil_ScannerImpl.cpp @@ -22,7 +22,8 @@ #include "FBase_NativeError.h" #define ANY_PATTERN L"\\s*[^\\s]*" -#define DEFAULT_DELIMITER_PATTERN L"\\s*" +#define DEFAULT_DELIMITER_PATTERN L"\\s+" +#define DEFAULT_DELIMITER_PATTERN_ZERO_OR_MORE L"\\s*" #define COMPLETE_LINE_PATTERN L".*(\r\n|[\u000A\n\r\u2028\u2029\u0085])|.+$" #define DEFAULT_LINE_SEPARATOR_PATTERN L"[\u000A\n\r\u2028\u2029\u0085]*" @@ -125,8 +126,13 @@ CATCH: bool _ScannerImpl::HasNextToken(void) { - String pattern(ANY_PATTERN); - return HasNextToken(pattern); + String token; + int length = 0; + + result r = GetNextTokenWithoutPattern(token, length); + SysTryLogReturn(NID_BASE_UTIL, r == E_SUCCESS, false, "Can not get the next token"); + + return true; } bool _ScannerImpl::HasNextToken(const RegularExpression& pattern) @@ -137,12 +143,24 @@ bool _ScannerImpl::HasNextToken(const RegularExpression& pattern) bool _ScannerImpl::HasNextToken(const String& pattern) { - result r = E_SUCCESS; - String token; + RegularExpression regex; + ArrayList matchedStrList; int length = 0; + String out; - r = GetNextToken(pattern, token, length); - SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_DATA_NOT_FOUND, "[%s] Can not get the next token", GetErrorMessage(E_DATA_NOT_FOUND)); + result r = GetNextTokenWithoutPattern(out, length); + SysTryLogReturn(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, false, "Input has no remaining tokens"); + + SysTryLogReturn(NID_BASE_UTIL, r == E_SUCCESS, false, "The next token does not match to the pattern"); + + r = regex.Construct(pattern, REGEX_UNICODE); + SysTryLogReturn(NID_BASE_UTIL, r == E_SUCCESS, false, "Regular expression construction failed"); + + r = matchedStrList.Construct(); + SysTryLogReturn(NID_BASE_UTIL, r == E_SUCCESS, false, "Arraylist construction failed"); + + bool res = regex.Match(out, true, &matchedStrList); + SysTryLogReturn(NID_BASE_UTIL, res, res, "Match Failed"); return true; } @@ -150,11 +168,9 @@ bool _ScannerImpl::HasNextToken(const String& pattern) result _ScannerImpl::GetNextToken(String& nextStr) { - result r = E_SUCCESS; - String pattern(ANY_PATTERN); int length = 0; - r = GetNextToken(pattern, nextStr, length); + result r = GetNextTokenWithoutPattern(nextStr, length); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_ENOUGH, "Can not get the next token"); __position = __position + length; @@ -170,38 +186,28 @@ result _ScannerImpl::GetNextToken(const RegularExpression& pattern, String& next result _ScannerImpl::GetNextToken(const String& pattern, String& nextStr) { - result r = E_SUCCESS; - int length1 = 0; - int length2 = 0; + RegularExpression regex; + ArrayList matchedStrList; + int length = 0; + String out; - String str1; - String str2; - String anyPattern(ANY_PATTERN); + result r = GetNextTokenWithoutPattern(out, length); + SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); - while (true) - { - r = GetNextToken(anyPattern, str1, length1); - SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); - SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "The next token does not match to the pattern"); + SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "The next token does not match to the pattern"); - r = GetNextToken(pattern, str2, length2); - SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); - SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "The next token does not match to the pattern"); + r = regex.Construct(pattern, REGEX_UNICODE); + SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "Regular expression construction failed"); - if(str1 == str2) - { - nextStr = str1; - __position = __position + length2; - break; - } - else - { - nextStr = L""; - __position = __position + length1; - } - } + r = matchedStrList.Construct(); + SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "Arraylist construction failed"); - return r; + bool res = regex.Match(out, true, &matchedStrList); + SysTryReturnResult(NID_BASE_UTIL, res, E_DATA_NOT_FOUND, "Match Failed"); + + nextStr = out; + __position = __position + length; + return E_SUCCESS; } result _ScannerImpl::GetNextSignedChar(signed char& nextSignedChar) @@ -211,13 +217,11 @@ result _ScannerImpl::GetNextSignedChar(signed char& nextSignedChar) result _ScannerImpl::GetNextSignedChar(signed char& nextSignedChar, int radix) { - result r = E_SUCCESS; String out; int length = 0; char ch = 0x00; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_NUM_FORMAT, "Can not parse the token to signed char"); @@ -237,13 +241,11 @@ bool _ScannerImpl::IsNextTokenConvertibleToSignedChar(void) bool _ScannerImpl::IsNextTokenConvertibleToSignedChar(int radix) { - result r = E_SUCCESS; String out; int length = 0; - String pattern(ANY_PATTERN); char ch = 0; - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_NUM_FORMAT, "[%s] Can not get the next token as signed char", GetErrorMessage(E_NUM_FORMAT)); r = Int8::Parse(out, radix, ch); @@ -259,12 +261,10 @@ result _ScannerImpl::GetNextInt(int& nextInt) result _ScannerImpl::GetNextInt(int& nextInt, int radix) { - result r = E_SUCCESS; String out; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_NUM_FORMAT, "Can not parse the token to integer"); @@ -284,13 +284,11 @@ bool _ScannerImpl::IsNextTokenConvertibleToInt(void) bool _ScannerImpl::IsNextTokenConvertibleToInt(int radix) { - result r = E_SUCCESS; String out; int val = 0; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_NUM_FORMAT, "[%s] Can not get the next token as integer", GetErrorMessage(E_NUM_FORMAT)); out.Replace(DEFAULT_GROUP_SEPARATOR, L""); @@ -307,12 +305,10 @@ result _ScannerImpl::GetNextShort(short& nextShort) result _ScannerImpl::GetNextShort(short& nextShort, int radix) { - result r = E_SUCCESS; String out; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_NUM_FORMAT, "Can not parse the token to short"); @@ -332,13 +328,11 @@ bool _ScannerImpl::IsNextTokenConvertibleToShort(void) bool _ScannerImpl::IsNextTokenConvertibleToShort(int radix) { - result r = E_SUCCESS; String out; short val = 0; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_NUM_FORMAT, "[%s] Can not get next token as short", GetErrorMessage(E_NUM_FORMAT)); out.Replace(DEFAULT_GROUP_SEPARATOR, L""); @@ -355,12 +349,10 @@ result _ScannerImpl::GetNextLongLong(long long& nextLongLong) result _ScannerImpl::GetNextLongLong(long long& nextLongLong, int radix) { - result r = E_SUCCESS; String out; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_NUM_FORMAT, "Can not parse the token to long long"); @@ -375,13 +367,11 @@ result _ScannerImpl::GetNextLongLong(long long& nextLongLong, int radix) bool _ScannerImpl::IsNextTokenConvertibleToLongLong(void) { - result r = E_SUCCESS; String out; long long val = 0; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_NUM_FORMAT, "[E_NUM_FORMAT] Can not get next token as long long"); r = LongLong::Parse(out, val); @@ -392,12 +382,10 @@ bool _ScannerImpl::IsNextTokenConvertibleToLongLong(void) result _ScannerImpl::GetNextFloat(float& nextFloat) { - result r = E_SUCCESS; String out; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_NUM_FORMAT, "Can not parse the token to float"); @@ -413,14 +401,12 @@ result _ScannerImpl::GetNextFloat(float& nextFloat) bool _ScannerImpl::IsNextTokenConvertibleToFloat(void) { - result r = E_SUCCESS; String out; RegularExpression re; float val = 0.0f; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_NUM_FORMAT, "[%s] Can not get next token as float", GetErrorMessage(E_NUM_FORMAT)); out.Replace(DEFAULT_GROUP_SEPARATOR, L""); @@ -432,12 +418,10 @@ bool _ScannerImpl::IsNextTokenConvertibleToFloat(void) result _ScannerImpl::GetNextDouble(double& nextDouble) { - result r = E_SUCCESS; String out; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_NUM_FORMAT, "Can not parse the token to double"); @@ -452,13 +436,11 @@ result _ScannerImpl::GetNextDouble(double& nextDouble) bool _ScannerImpl::IsNextTokenConvertibleToDouble(void) { - result r = E_SUCCESS; String out; double val = 0.0f; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_NUM_FORMAT, "[%s] Can not get next token as double", GetErrorMessage(E_NUM_FORMAT)); out.Replace(DEFAULT_GROUP_SEPARATOR, L""); @@ -470,12 +452,10 @@ bool _ScannerImpl::IsNextTokenConvertibleToDouble(void) result _ScannerImpl::GetNextBool(bool& nextBool) { - result r = E_SUCCESS; String out; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturnResult(NID_BASE_UTIL, r != E_DATA_NOT_ENOUGH, E_DATA_NOT_ENOUGH, "Input has no remaining tokens"); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_NUM_FORMAT, "Can not parse the token to bool"); @@ -503,44 +483,30 @@ result _ScannerImpl::GetNextBool(bool& nextBool) bool _ScannerImpl::IsNextTokenConvertibleToBool(void) { - result r = E_SUCCESS; String out; - bool ret = false; int length = 0; - String pattern(ANY_PATTERN); - r = GetNextToken(pattern, out, length); + result r = GetNextTokenWithoutPattern(out, length); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_NUM_FORMAT, "[%s] Can not get next token as bool", GetErrorMessage(E_NUM_FORMAT)); String temp; out.ToUpper(temp); - if((!temp.CompareTo(L"TRUE")) || (!temp.CompareTo(L"FALSE"))) - { - ret = true; - } - else - { - ret = false; - } - - return ret; + return ((!temp.CompareTo(L"TRUE")) || (!temp.CompareTo(L"FALSE"))); } bool _ScannerImpl::HasNextLine(void) { - result r = E_SUCCESS; String pattern(DEFAULT_LINE_SEPARATOR_PATTERN); RegularExpression regex; ArrayList matchedStrList; - bool res = false; - r = regex.Construct(pattern, REGEX_UNICODE); + result r = regex.Construct(pattern, REGEX_UNICODE); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_DATA_NOT_ENOUGH, "[%s] Regular expression construction failed", GetErrorMessage(E_DATA_NOT_ENOUGH)); r = matchedStrList.Construct(); SysTryReturn(NID_BASE_UTIL, r == E_SUCCESS, false, E_DATA_NOT_ENOUGH, "[%s] Arraylist construction failed", GetErrorMessage(E_DATA_NOT_ENOUGH)); - res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); + bool res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); SysTryReturn(NID_BASE_UTIL, res == true, false, E_DATA_NOT_ENOUGH, "[%s] Match Failed", GetErrorMessage(E_DATA_NOT_ENOUGH)); return res; @@ -549,67 +515,57 @@ bool _ScannerImpl::HasNextLine(void) result _ScannerImpl::GetNextLine(String& nextLine) { - result r = E_SUCCESS; String pattern(COMPLETE_LINE_PATTERN); RegularExpression regex; ArrayList matchedStrList; - bool res = false; - int matches = 0; - r = regex.Construct(pattern, REGEX_UNICODE); + result r = regex.Construct(pattern, REGEX_UNICODE); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_ENOUGH, "Regular expression construction failed"); r = matchedStrList.Construct(); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_ENOUGH, "Arraylist construction failed"); - res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); + bool res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); SysTryReturnResult(NID_BASE_UTIL, res == true, E_DATA_NOT_ENOUGH, "Match Failed"); - matches = matchedStrList.GetCount(); - if(matches > 0) - { - String temp = *(String *)matchedStrList.GetAt(0); - __position = __position + temp.GetLength(); - - RegularExpression re; - r = re.Construct(DEFAULT_LINE_SEPARATOR_PATTERN, REGEX_UNICODE); - re.Replace(temp, L"", true); - nextLine = temp; + int matches = matchedStrList.GetCount(); + SysTryReturnResult(NID_BASE_UTIL,matches > 0, E_DATA_NOT_FOUND, "Match Failed"); + + String temp = *(String *)matchedStrList.GetAt(0); + __position = __position + temp.GetLength(); - matchedStrList.RemoveAll(); - } - - return r; + RegularExpression re; + r = re.Construct(DEFAULT_LINE_SEPARATOR_PATTERN, REGEX_UNICODE); + re.Replace(temp, L"", true); + nextLine = temp; + matchedStrList.RemoveAll(); + return E_SUCCESS; } result _ScannerImpl::FindInLine(const String& str, String& MatchedStr) { - result r = E_SUCCESS; _RegularExpressionImpl regex; ArrayList matchedStrList; - bool res = false; - int matches = 0; - r = regex.Construct(str, REGEX_UNICODE); + result r = regex.Construct(str, REGEX_UNICODE); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "Regular expression construction failed"); r = matchedStrList.Construct(); SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "Arraylist construction failed"); - res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); + bool res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); SysTryReturnResult(NID_BASE_UTIL, res == true, E_DATA_NOT_FOUND, "Match Failed"); - matches = matchedStrList.GetCount(); - if(matches > 0) - { - MatchedStr = *(String *)matchedStrList.GetAt(0); - int matchEnd = regex.GetLastMatchEnd(); - __position = __position + matchEnd; - matchedStrList.RemoveAll(); - } - return r; + int matches = matchedStrList.GetCount(); + SysTryReturnResult(NID_BASE_UTIL,matches > 0, E_DATA_NOT_FOUND, "Match Failed"); + + MatchedStr = *(String *)matchedStrList.GetAt(0); + int matchEnd = regex.GetLastMatchEnd(); + __position = __position + matchEnd; + matchedStrList.RemoveAll(); + return E_SUCCESS; } result _ScannerImpl::FindInLine(const RegularExpression& pattern, String& MatchedStr) @@ -620,61 +576,63 @@ result _ScannerImpl::FindInLine(const RegularExpression& pattern, String& Matche void _ScannerImpl::Skip(const String& str) { - result r = E_SUCCESS; RegularExpression regex; ArrayList matchedStrList; - bool res = false; - int matches = 0; + String inputStr(__pParseStr + __position); - r = regex.Construct(str, REGEX_UNICODE); - SysTryCatch(NID_BASE_UTIL, r == E_SUCCESS, , r, "[%s] Regular expression construction failed", GetErrorMessage(r)); + result r = regex.Construct(str, REGEX_UNICODE); + SysTryReturnVoidResult(NID_BASE_UTIL, r == E_SUCCESS, r,"Regular expression construction failed"); r = matchedStrList.Construct(); - SysTryCatch(NID_BASE_UTIL, r == E_SUCCESS, , r, "[%s] ArrayList construction failed", GetErrorMessage(r)); + SysTryReturnVoidResult(NID_BASE_UTIL, r == E_SUCCESS, r, "ArrayList construction failed"); - res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); - SysTryCatch(NID_BASE_UTIL, res == true, , E_SYSTEM, "[%s] Regular expression match failed", GetErrorMessage(E_SYSTEM)); + bool res = regex.Match(inputStr, false, &matchedStrList); + SysTryReturnVoidResult(NID_BASE_UTIL, res == true, E_SYSTEM, "Regular expression match failed"); - matches = matchedStrList.GetCount(); - if(matches > 0) - { - String temp = *(String *)matchedStrList.GetAt(0); - int length = temp.GetLength(); - const wchar_t* wstr1 = temp.GetPointer(); - const wchar_t* wstr2 = __pParseStr + __position; - bool isSame = true; - - while(*wstr1 != 0x0000) - { - if(*wstr1++ != *wstr2++) - { - isSame = false; - break; - } - } - if(isSame == true) - { - __position = __position + length; - } - matchedStrList.RemoveAll(); + int matches = matchedStrList.GetCount(); + SysTryReturnVoidResult(NID_BASE_UTIL, matches > 0, E_SYSTEM,"Regular expression construction failed"); - //Skip if there is any delimiters before the next token - RegularExpression re; - r = re.Construct(DEFAULT_DELIMITER_PATTERN, REGEX_UNICODE); - res = re.Match(String(__pParseStr + __position), false, &matchedStrList); - matches = matchedStrList.GetCount(); - if(matches > 0) - { - String temp = *(String *)matchedStrList.GetAt(0); - int length = temp.GetLength(); - __position = __position + length; - matchedStrList.RemoveAll(); - } - - } + String skipToken = *(dynamic_cast< String* >(matchedStrList.GetAt(0))); + int length = skipToken.GetLength(); + const wchar_t* wstr1 = skipToken.GetPointer(); + const wchar_t* wstr2 = __pParseStr + __position; + bool isSame = true; + + while (*wstr1 != 0x0000) + { + if (*wstr1++ != *wstr2++) + { + isSame = false; + break; + } + } + if (isSame) + { + __position = __position + length; + } + matchedStrList.RemoveAll(); + + //Skip if there is any delimiters before the next token + RegularExpression re; + if (__delimiter == DEFAULT_DELIMITER_PATTERN) + { + r = re.Construct(DEFAULT_DELIMITER_PATTERN_ZERO_OR_MORE, REGEX_UNICODE); + } + else + { + r = re.Construct(__delimiter, REGEX_UNICODE); + } + + res = re.Match(String(__pParseStr + __position), false, &matchedStrList); + matches = matchedStrList.GetCount(); + if (matches > 0) + { + String temp = *(dynamic_cast< String* >(matchedStrList.GetAt(0))); + int length = temp.GetLength(); + __position = __position + length; + matchedStrList.RemoveAll(); + } -CATCH: - return; } void _ScannerImpl::Skip(const RegularExpression& pattern) @@ -712,39 +670,129 @@ void _ScannerImpl::SetRadix(int radix) } } -result _ScannerImpl::GetNextToken(const String& pattern, String& ret, int& length) + +result _ScannerImpl::GetNextTokenWithoutPattern(String& ret, int& length) { - result r = E_SUCCESS; - SysTryReturnResult(NID_BASE_UTIL, __pParseStr + __position != null, E_DATA_NOT_ENOUGH, "Input has no remaining tokens."); - SysTryReturnResult(NID_BASE_UTIL, *(__pParseStr + __position) != 0x0000, E_DATA_NOT_ENOUGH, "Input has no remaining tokens."); + SysTryReturnResult(NID_BASE_UTIL, ((__pParseStr + __position) != null) && ((*(__pParseStr + __position) != 0x0000)), + E_DATA_NOT_ENOUGH, "Input has no remaining tokens."); + + RegularExpression regDelim; + result r = regDelim.Construct(__delimiter, REGEX_UNICODE); + SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "Regular expression construction failed"); - RegularExpression regex; ArrayList matchedStrList; - bool res = false; - int matches = 0; - String regPattern(pattern); + r = matchedStrList.Construct(); + SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_DATA_NOT_FOUND, "Arraylist construction failed"); - regPattern.Append(__delimiter); + String inputStr(__pParseStr + __position); + bool res = regDelim.Match(inputStr, false, &matchedStrList); - r = regex.Construct(regPattern, REGEX_UNICODE); - SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_OPERATION_FAILED, "Regular expression construction failed"); + int matches = matchedStrList.GetCount(); + if (matches > 0) + { + String delimiter1 = *(dynamic_cast< String* >(matchedStrList.GetAt(0))); - r = matchedStrList.Construct(); - SysTryReturnResult(NID_BASE_UTIL, r == E_SUCCESS, E_OPERATION_FAILED, "Arraylist construction failed"); + if (!delimiter1.IsEmpty()) // 1st delimiter is not empty + { + int delimLength1 = delimiter1.GetLength(); + int index1 = 0; + inputStr.IndexOf(delimiter1, 0, index1); - res = regex.Match(String(__pParseStr + __position), false, &matchedStrList); - SysTryReturnResult(NID_BASE_UTIL, res == true, E_OPERATION_FAILED, "Match Failed"); + // When the delimiter exists in first position, find the 2nd delimiter + if ((index1 == 0) && (__position == 0)) + { + length += delimLength1; + String tmpStr(__pParseStr + length); - matches = matchedStrList.GetCount(); - if(matches > 0) + matchedStrList.RemoveAll(); + res = regDelim.Match(tmpStr, false, &matchedStrList); + matches = matchedStrList.GetCount(); + if (matches > 0) + { + String delimiter2 = *(dynamic_cast< String* >(matchedStrList.GetAt(0))); + + // If the 2nd delimiter is empty, the token will be one character followed by 1st delimiter. + if (delimiter2.IsEmpty()) + { + ret.Clear(); + ret.Append(*(__pParseStr + length)); + length += 1; + // Though 2nd delimiter is empty, if 3rd non-empty delimiter exists right after the token, length to be moved should be added by 3rd delimiter. + matchedStrList.RemoveAll(); + String tmpStr1(__pParseStr + length); + res = regDelim.Match(tmpStr1, false, &matchedStrList); + matches = matchedStrList.GetCount(); + SysTryReturnResult(NID_BASE_UTIL, matches > 0, E_SUCCESS, "It's a last token."); + + String delimiter3 = *(dynamic_cast< String* >(matchedStrList.GetAt(0))); + int index3 = 0; + tmpStr1.IndexOf(delimiter3, 0, index3); + if (!delimiter3.IsEmpty() && index3 == 0) + { + length += delimiter3.GetLength(); + } + } + else + { + int delimLength2 = delimiter2.GetLength(); + int index2 = 0; + tmpStr.IndexOf(delimiter2, 0, index2); + tmpStr.SubString(0, index2, ret); // Extract the string in between first and second delimiter + length += index2 + delimLength2; + } + } + } + else + { + inputStr.SubString(0, index1, ret); + length = index1 + delimLength1; + } + } + else // 1st delimiter is empty + { + // Find 2nd delimiter from "__pParseStr + __position + 1" + String tmpStr(__pParseStr + __position + 1); + if (tmpStr == null) // When InputStr is last token, extract the token. + { + ret.Clear(); + ret.Append(__pParseStr + __position); + length = ret.GetLength(); + } + else + { + matchedStrList.RemoveAll(); + res = regDelim.Match(tmpStr, false, &matchedStrList); + matches = matchedStrList.GetCount(); + if (matches > 0) + { + String delimiter2 = *(dynamic_cast< String* >(matchedStrList.GetAt(0))); + if (delimiter2.IsEmpty()) // If the 2nd delimiter is also empty, the token will be one character followed by 1st delimiter. + { + ret.Clear(); + ret.Append(*(__pParseStr + __position)); + length = 1; + } + else + { + int delimLength2 = delimiter2.GetLength(); + int index2 = 0; + inputStr.IndexOf(delimiter2, 0, index2); + inputStr.SubString(0, index2, ret); + length = index2 + delimLength2; + } + } + } + } + } + else //There are no delimiters { - String temp = *(String *)matchedStrList.GetAt(0); - length = temp.GetLength(); - RegularExpression re; - r = re.Construct(__delimiter, REGEX_UNICODE); - re.Replace(temp, L"", true); - ret = temp; - matchedStrList.RemoveAll(); + ret.Clear(); + ret.Append(__pParseStr + __position); + length = ret.GetLength(); + if (length <= 0) + { + return E_DATA_NOT_FOUND; + } } return r; diff --git a/src/base/utility/FBaseUtil_ScannerImpl.h b/src/base/utility/FBaseUtil_ScannerImpl.h index 4f26927..1820888 100644 --- a/src/base/utility/FBaseUtil_ScannerImpl.h +++ b/src/base/utility/FBaseUtil_ScannerImpl.h @@ -89,6 +89,9 @@ public: result GetNextToken(const String& pattern, String& ret, int& matTokenLen); result GetNextMatchingString(const String& pattern, String& ret, int& length); +private : + result GetNextTokenWithoutPattern(String& ret, int& length); + public: int __radix; String __delimiter; diff --git a/src/security/FSecPrivacyInfo.cpp b/src/security/FSecPrivacyInfo.cpp index 6fac720..9dc7b05 100755 --- a/src/security/FSecPrivacyInfo.cpp +++ b/src/security/FSecPrivacyInfo.cpp @@ -40,7 +40,7 @@ PrivacyInfo::PrivacyInfo(void) PrivacyInfo::~PrivacyInfo(void) { - + delete __pImpl; } result diff --git a/src/security/FSecPrivilegeInfo.cpp b/src/security/FSecPrivilegeInfo.cpp index f982070..1fe92d1 100755 --- a/src/security/FSecPrivilegeInfo.cpp +++ b/src/security/FSecPrivilegeInfo.cpp @@ -43,7 +43,7 @@ PrivilegeInfo::PrivilegeInfo(void) PrivilegeInfo::~PrivilegeInfo(void) { - + delete __pImpl; } result diff --git a/src/security/FSec_PrivacyInfoImpl.cpp b/src/security/FSec_PrivacyInfoImpl.cpp index 941ac9c..d436b14 100755 --- a/src/security/FSec_PrivacyInfoImpl.cpp +++ b/src/security/FSec_PrivacyInfoImpl.cpp @@ -90,8 +90,13 @@ _PrivacyInfoImpl::GetDisplayName(void) const privacyInfo.privacy_id = pPrivacyId.get(); ret = privacy_info_client_get_privacy_display_name(&privacyInfo, &pPrivacyDisplayName); SysTryReturn(NID_SEC, ret == PRIV_MGR_ERROR_SUCCESS, displayName, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); - displayName.Append(pPrivacyDisplayName); + + if (pPrivacyDisplayName != null) + { + free(pPrivacyDisplayName); + } + return displayName; } diff --git a/src/security/FSec_PrivilegeInfo.cpp b/src/security/FSec_PrivilegeInfo.cpp index 53e6fac..48b125b 100644 --- a/src/security/FSec_PrivilegeInfo.cpp +++ b/src/security/FSec_PrivilegeInfo.cpp @@ -98,6 +98,10 @@ _PrivilegeInfo::Construct(const AppId& appId, const byte* pBitwisePrivilege, con SysTryReturnResult(NID_SEC, ret == PRVMGR_ERR_NONE, E_SYSTEM, "An unexpected system error occurred."); __privilegeList.Add((new String(*pTempString)), (new String(pPrivilegeLevel))); + if (pPrivilegeLevel != null) + { + free(pPrivilegeLevel); + } } return r; @@ -165,6 +169,10 @@ _PrivilegeInfo::Construct(const AppId& appId, const String& encryptedPrivileges, SysTryReturnResult(NID_SEC, ret == PRVMGR_ERR_NONE, E_SYSTEM, "An unexpected system error occurred."); __privilegeList.Add((new String(*pTempString)), (new String(pPrivilegeLevel))); + if (pPrivilegeLevel != null) + { + free(pPrivilegeLevel); + } } return r; @@ -265,6 +273,10 @@ _PrivilegeInfo::Construct(const AppId& appId, const String& encryptedPrivileges, SysTryReturnResult(NID_SEC, ret == PRVMGR_ERR_NONE, E_SYSTEM, "An unexpected system error occurred."); __privilegeList.Add((new String(*pTempString)), (new String(pPrivilegeLevel))); + if (pPrivilegeLevel != null) + { + free(pPrivilegeLevel); + } } return r; @@ -593,7 +605,7 @@ _PrivilegeInfo::VerifyIntegrity(const AppId& appId, const byte* targetBitwisePri ByteBuffer input; std::unique_ptr pHash(null); std::unique_ptr pChecksumByteBuffer(null); - std::unique_ptr pAppId(null); + std::unique_ptr pAppId(null); SysTryReturnResult(NID_SEC, length <= MAX_BITWISE_PRIV_SIZE, E_INVALID_ARG, "The privilege information of %ls is invalid.", appId.GetPointer()); diff --git a/src/security/FSec_PrivilegeInfoImpl.cpp b/src/security/FSec_PrivilegeInfoImpl.cpp index 9c2e0fa..87d17ac 100755 --- a/src/security/FSec_PrivilegeInfoImpl.cpp +++ b/src/security/FSec_PrivilegeInfoImpl.cpp @@ -139,8 +139,8 @@ _PrivilegeInfoImpl::CheckExternalPrivilege(const Tizen::Base::String& privilegeI CATCH: - delete pDb; delete pStmt; + delete pDb; return flag; } diff --git a/src/security/FSec_PrivilegeManager.cpp b/src/security/FSec_PrivilegeManager.cpp index d6ce9ec..441e44c 100644 --- a/src/security/FSec_PrivilegeManager.cpp +++ b/src/security/FSec_PrivilegeManager.cpp @@ -191,7 +191,10 @@ _PrivilegeManager::RetrieveCipherPrivilegeN(const AppId& appId, Tizen::Base::Str pPrivilegeList = new ArrayList; r = pPrivilegeList->Construct(); - IEnumerator* pEnum = tempPrivilegeList.GetEnumeratorN(); + std::unique_ptr pEnum(null); + pEnum.reset(tempPrivilegeList.GetEnumeratorN()); + SysTryReturnResult(NID_SEC, pEnum != null, E_SYSTEM, "An unexpected system error occurred."); + while (pEnum->MoveNext() == E_SUCCESS) { String* tempString = static_cast< String* >(pEnum->GetCurrent()); @@ -245,7 +248,10 @@ _PrivilegeManager::RetrieveCipherPrivilegeExN(const AppId& appId, Tizen::Base::S pPrivilegeList = new ArrayList; r = pPrivilegeList->Construct(); - IEnumerator* pEnum = tempPrivilegeList.GetEnumeratorN(); + std::unique_ptr pEnum(null); + pEnum.reset(tempPrivilegeList.GetEnumeratorN()); + SysTryReturnResult(NID_SEC, pEnum != null, E_SYSTEM, "An unexpected system error occurred."); + while (pEnum->MoveNext() == E_SUCCESS) { String* tempString = static_cast< String* >(pEnum->GetCurrent()); diff --git a/src/security/pkcs/FSecPkcs_Pkcs08AttributeImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs08AttributeImpl.cpp index 5234ef7..e796141 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs08AttributeImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs08AttributeImpl.cpp @@ -50,6 +50,8 @@ _Pkcs08AttributeImpl::_Pkcs08AttributeImpl(void) _Pkcs08AttributeImpl::~_Pkcs08AttributeImpl(void) { + if (__attributeValues.GetCount() > 0) + __attributeValues.RemoveAll(); //do nothing } diff --git a/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp index 9a28344..c4c68fc 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp @@ -139,7 +139,10 @@ _Pkcs08EncryptedPrivateKeyInfoImpl::Construct(const AlgorithmIdentifier& algorit SysTryReturn(NID_SEC_CRYPTO, encryptedData.GetRemaining() > 0, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); - r = __encryptionAlgorithm.Construct(algorithmId.GetAlgorithmObjectId(), algorithmId.GetParametersN()); + std::unique_ptr< IAlgorithmParameters > pParam(algorithmId.GetParametersN()); + SysTryReturn(NID_SEC_CRYPTO, pParam != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + r = __encryptionAlgorithm.Construct(algorithmId.GetAlgorithmObjectId(), pParam.get()); SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct the algorithm identifier instance for encryption algorithm.", GetErrorMessage(r)); r = __encryptedData.Construct(encryptedData); diff --git a/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp index 8f2ae40..3fff4e1 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp @@ -54,6 +54,8 @@ _Pkcs08PrivateKeyInfoImpl::_Pkcs08PrivateKeyInfoImpl(void) //Default Destructor _Pkcs08PrivateKeyInfoImpl::~_Pkcs08PrivateKeyInfoImpl(void) { + if (__attributes.GetCount() > 0) + __attributes.RemoveAll(); //do nothing }