<tr><td>L"DueTime='mm/dd/yyyy hh:mm:ss' LaunchPeriod='mm'"</td>
<td>The specific condition is the time period after due time.</td></tr>
<tr><td>L"WeeklyTime='EEE HH:mm:ss'"</td>
- <td>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: <br>i"Mon 09:00:00, Tue 09:00:00, Wed 09:00:00, Thu 09:00:00, Fri 09:00:00"<br> To specify the day of the week, it must be in one of the following supported string format: <br>Mon: Monday<br>Tue: Tuesday<br>Wed: Wednesday<br>Thu: Thursday<br>Fri: Friday<br>Sat: Saturday<br>Sun: Sunday</td></tr>
+ <td>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: <br>i"'Mon 09:00:00', 'Tue 09:00:00', 'Wed 09:00:00', 'Thu 09:00:00', 'Fri 09:00:00'"<br> To specify the day of the week, it must be in one of the following supported string format: <br>Mon: Monday<br>Tue: Tuesday<br>Wed: Wednesday<br>Thu: Thursday<br>Fri: Friday<br>Sat: Saturday<br>Sun: Sunday</td></tr>
<tr><td>L"Serial='command'"</td><td>The specified condition is a serial
communication input command.</td></tr>
<tr><td>L"NFC='command'"</td><td>The specified condition is a Near Field Communication (NFC) tag that has the NFC Data Exchange Format (NDEF) data.
/**
* 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
*
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
*
FApp_LongevityManager.cpp
FApp_AppControlResponseEvent.cpp
FApp_AppLifecycleEvent.cpp
+ FApp_ActiveWindowManager.cpp
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SINGLETON_CLEANUP -fvisibility=hidden")
--- /dev/null
+//
+// 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 <unique_ptr.h>
+
+#include <aul/aul.h>
+#include <Ecore.h>
+#include <Ecore_X.h>
+#include <X11/Xlib.h>
+
+#include <FBaseSysLog.h>
+#include <FAppIActiveAppEventListener.h>
+
+#include <FBaseRt_LibraryImpl.h>
+
+#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<void*(*)(Ecore_Event_Handler* event_handler)>(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<Ecore_X_Atom(*)(const char* name)>(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<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(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<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(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<int(*)(Ecore_X_Window win, char** name)>(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<Ecore_X_Window*(*)(int* num_ret)>(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<int*>(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<Display*(*)(_Xconst char* display_name)>(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<int(*)(Display* display)>(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<int(*)(Display* display, Window w, long event_mask)>(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<Ecore_Event_Handler*(*)(int type, Ecore_Event_Handler_Cb func, const void* data)>(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<Display, _DisplayDeleter> 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<void*(*)(Ecore_Event_Handler* event_handler)>(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<IEnumeratorT<Tizen::App::IActiveAppEventListener* > > 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<Ecore_X_Window*(*)(int* num_ret)>(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<Ecore_X_Atom(*)(const char* name)>(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<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(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<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(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
--- /dev/null
+//
+// 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 <FOspConfig.h>
+#include <FBaseColLinkedListT.h>
+
+#include <Ecore.h>
+
+
+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<IActiveAppEventListener*> __activeAppEventListenerList;
+};
+
+}} // Tizen::App
+
+#endif //_FAPP_INTERNAL_ACTIVE_WINDOW_MANAGER_H_
+
#include <aul/aul.h>
#include <bundle.h>
#include <app_manager.h>
-#include <Ecore.h>
-#include <Ecore_X.h>
-#include <X11/Xlib.h>
#include <FBaseInteger.h>
#include <FBaseObject.h>
#include <FBase_StringConverter.h>
#include <FBaseRt_LibraryImpl.h>
#include <FIo_DataControlResultSetImpl.h>
+#include <FSys_SystemInfoImpl.h>
#include "FApp_AppControlRegistry.h"
#include "FApp_AppImpl.h"
#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;
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)
{
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<Ecore_X_Atom(*)(const char* name)>(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<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(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<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(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<int(*)(Ecore_X_Window win, char** name)>(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<Tizen::App::_AppManagerImpl*>(pData);
- pAppManagerImpl->FireActiveAppEvent(activeWin, pid, pAppName);
-
- if (pAppName)
- {
- free(pAppName);
- }
-
- return ECORE_CALLBACK_PASS_ON;
-}
-
} // anonymous name-space
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, "");
}
{
SysLog(NID_APP, "");
- if (__activeAppEventListenerList.GetCount() > 0)
- {
- if (p_ecore_event_handler_del == null)
- {
- _LibraryImpl& lib = GetEcoreLibraryImpl();
- p_ecore_event_handler_del = reinterpret_cast<void*(*)(Ecore_Event_Handler* event_handler)>(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;
}
{
__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.
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;
}
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);
}
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<IEnumeratorT<Tizen::App::IActiveAppEventListener* > > 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<Ecore_X_Window*(*)(int* num_ret)>(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<Ecore_X_Atom(*)(const char* name)>(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<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(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<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(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<Ecore_X_Window*(*)(int* num_ret)>(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<int*>(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<Display*(*)(_Xconst char* display_name)>(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<int(*)(Display* display)>(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<int(*)(Display* display, Window w, long event_mask)>(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<Ecore_Event_Handler*(*)(int type, Ecore_Event_Handler_Cb func, const void* data)>(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<Display, _DisplayDeleter> 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<void*(*)(Ecore_Event_Handler* event_handler)>(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
{
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);
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");
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);
if (currentRefCnt < 0)
{
r = __appListForAppLifecycle.Remove(appId);
-
+
_IAppManager* pMgr = _AppManagerProxy::GetService();
SysTryReturnResult(NID_APP, pMgr, E_SYSTEM, "_AppManagerProxy::GetService() is failed.");
else
{
r = __appListForAppLifecycle.SetValue(appId, currentRefCnt);
- }
+ }
}
else
{
}
r = __mutex.Release();
+ SysTryLog(NID_APP, r == E_SUCCESS, "Releasing mutex failed.");
SysLog(NID_APP, "Exit");
{
SysTryLog(NID_APP, __pServiceEventListener != null, "__pServiceEventListener instance must not be null.");
- _AppLifecycleEventType eventType;
+ _AppLifecycleEventType eventType = _APP_LIFECYCLE_EVENT_LAUNCH;
if (appLifecycleEventType == 0)
{
#ifndef _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
#define _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
-#include <appfw/app_context.h>
+#include <unique_ptr.h>
#include <FOspConfig.h>
#include <FBaseObject.h>
#include <FBaseString.h>
-#include <FBaseColIListT.h>
#include <FBaseColIList.h>
#include <FBaseColLinkedListT.h>
#include <FBaseColHashMapT.h>
#include <FBaseRtIEventListener.h>
#include <FAppAppManager.h>
#include <FBaseSysLog.h>
-#include <FBaseStringHashCodeProvider.h>
-#include <FBaseComparerT.h>
#include "FApp_Types.h"
#include "FApp_AppManagerEvent.h"
class _IAppEventListener;
class _AppManagerEventArg;
class _IAppLifecycleEventListener;
+class _ActiveWindowManager;
class _AppLifecycleManager
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);
_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<IActiveAppEventListener*> __activeAppEventListenerList;
Tizen::App::_AppLifecycleEvent __appLifecycleEvent;
Tizen::Base::Collection::HashMapT<Tizen::Base::String, int> __appListForAppLifecycle;
- Tizen::Base::ComparerT<Tizen::Base::String> __comparer;
- Tizen::Base::StringHashCodeProvider __strHashCodeProvider;
Tizen::Base::Runtime::Mutex __mutex;
friend class AppManager;
friend class _MapDataControlImpl;
friend class _DataControlProviderManagerImpl;
friend class _AppControlProviderManagerImpl;
- friend class _ActiveWindowEventListener;
friend class Tizen::Io::_DataControlResultSetImpl;
}; // _AppManagerImpl
#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]*"
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)
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;
}
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;
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)
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");
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);
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");
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"");
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");
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"");
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");
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);
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");
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"");
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");
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"");
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");
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;
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)
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)
}
}
-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;
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;
PrivacyInfo::~PrivacyInfo(void)
{
-
+ delete __pImpl;
}
result
PrivilegeInfo::~PrivilegeInfo(void)
{
-
+ delete __pImpl;
}
result
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;
}
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;
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;
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;
ByteBuffer input;
std::unique_ptr<IHash> pHash(null);
std::unique_ptr<ByteBuffer> pChecksumByteBuffer(null);
- std::unique_ptr<char> pAppId(null);
+ std::unique_ptr<char[]> pAppId(null);
SysTryReturnResult(NID_SEC, length <= MAX_BITWISE_PRIV_SIZE, E_INVALID_ARG, "The privilege information of %ls is invalid.", appId.GetPointer());
CATCH:
- delete pDb;
delete pStmt;
+ delete pDb;
return flag;
}
pPrivilegeList = new ArrayList;
r = pPrivilegeList->Construct();
- IEnumerator* pEnum = tempPrivilegeList.GetEnumeratorN();
+ std::unique_ptr<IEnumerator> 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());
pPrivilegeList = new ArrayList;
r = pPrivilegeList->Construct();
- IEnumerator* pEnum = tempPrivilegeList.GetEnumeratorN();
+ std::unique_ptr<IEnumerator> 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());
_Pkcs08AttributeImpl::~_Pkcs08AttributeImpl(void)
{
+ if (__attributeValues.GetCount() > 0)
+ __attributeValues.RemoveAll();
//do nothing
}
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);
//Default Destructor
_Pkcs08PrivateKeyInfoImpl::~_Pkcs08PrivateKeyInfoImpl(void)
{
+ if (__attributes.GetCount() > 0)
+ __attributes.RemoveAll();
//do nothing
}