src/FApp_ContextManager.cpp
src/FApp_CommunicationDispatcher.cpp
src/FApp_PackageManagerStub.cpp
- src/FSys_DeviceManagerService.cpp
src/FSys_SystemService.cpp
src/FSys_AccessoryManagerService.cpp
src/AppService.cpp
src/FIo_MmcStorageManagerService.cpp
src/FIo_MmcStorageManagerStub.cpp
src/system/FSys_DeviceId.cpp
- src/system/FSys_RuntimeInfo.cpp
- src/system/FSys_PowerManager.cpp
src/FShell_LockManagerService.cpp
src/FShell_LockManagerStub.cpp
)
{
class _AlarmService;
class _AccessoryManagerService;
-class _DeviceManagerService;
class _SystemService;
}}
Tizen::App::_AppManagerStub* __pAppManagerStub;
Tizen::App::_ConditionManagerStub* __pConditionManagerStub;
_TaskHandlerThread __handlerThread;
- Tizen::System::_DeviceManagerService* __pDeviceManagerService;
Tizen::System::_SystemService* __pSystemService;
Tizen::System::_AccessoryManagerService* __pAccessoryManagerService;
Tizen::App::_PackageManagerStub* __pPackageManagerStub;
+++ /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 FSys_DeviceManagerService.h
- * @brief This is the header file of the _DeviceManagerService class.
- *
- * This header file contains the declarations of the _DeviceManagerService class.
- */
-#include <FApp.h>
-#include <FBase.h>
-#include <FSys_IDeviceManagerEventListener.h>
-#include "FApp_ICommunicationRequestListener.h"
-
-#ifndef _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
-#define _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
-
-namespace Tizen { namespace System {
-
-/**
- * @class _DeviceManagerService
- * @brief This class contains implementaion of device control.
- * @since 2.1
- */
-class _DeviceManagerService
- : public Tizen::App::_ICommunicationRequestListener
-{
-private:
- _DeviceManagerService(void);
- virtual ~_DeviceManagerService(void);
-public:
- virtual Tizen::Base::String GetId(void);
- void OnRequestOccured(Tizen::App::AppId appId, int pid, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
- void OnApplicationTerminated(const Tizen::App::AppId& appId, int pid);
- void SendEvent(Tizen::Base::String event);
- void SetBluetoothStatus(bool status);
- bool GetBluetoothStatus(void);
- static _DeviceManagerService* GetInstance(void);
-
-private:
- static _DeviceManagerService* __pDeviceManagerService;
- Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
- bool isBluetoothHeadSetConnected;
- bool isInitBluetooth;
- Tizen::Base::Collection::ArrayList __interestedPidList;
-
-private:
- void AddInterestedApp(int pid);
- void RemoveInterestedApp(int pid);
-
-}; //_DeviceManagerService
-
-}} //Tizen::System
-#endif /* _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_ */
#include <FBase.h>
#include "FApp_ICommunicationRequestListener.h"
-#include "FSys_PowerManager.h"
-
-#include "FSys_RuntimeInfo.h"
#ifndef _FSYS_INTERNAL_SYSTEM_SERVICE_H_
#define _FSYS_INTERNAL_SYSTEM_SERVICE_H_
private:
Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
- Tizen::System::_PowerManager* __pPowerManager;
- Tizen::System::_RuntimeInfo __runtimeInfo;
static _SystemService* __pSystemService;
}; //_SystemService
#include "FApp_ContextManager.h"
#include "FApp_AppManagerStub.h"
#include "FApp_ConditionManagerStub.h"
-#include "FSys_DeviceManagerService.h"
#include "FSys_SystemService.h"
#include "FSys_AccessoryManagerService.h"
#include "FApp_PackageManagerStub.h"
, __pAppManagerStub(null)
, __pConditionManagerStub(null)
, __handlerThread(*this)
-, __pDeviceManagerService(null)
, __pSystemService(null)
, __pAccessoryManagerService(null)
, __pPackageManagerStub(null)
void
AppService::ReadySystemServices(void)
{
- __pDeviceManagerService = _DeviceManagerService::GetInstance();
- SysAssert( __pDeviceManagerService != null);
- SysTryReturnVoidResult(NID_APP, __pDeviceManagerService != null, E_OUT_OF_MEMORY, "It is failed to _DeviceManagerService creation.");
-
__pSystemService = _SystemService::GetInstance();
SysAssert( __pSystemService != null);
SysTryReturnVoidResult(NID_APP, __pSystemService != null, E_OUT_OF_MEMORY, "It is failed to _SystemService creation.");
+++ /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 FSys_DeviceManagerService.cpp
- * @brief This is the implementation file for _DeviceManagerService class.
- */
-
-#include <new>
-#include <system/media_key.h>
-#include <bluetooth.h>
-
-#include <FIo.h>
-#include <FBaseSysLog.h>
-#include <FSys_DeviceManagerEventProvider.h>
-
-#include "FApp_CommunicationDispatcher.h"
-#include "FSys_DeviceManagerService.h"
-
-using namespace Tizen::App;
-using namespace Tizen::Io;
-using namespace Tizen::System;
-using namespace Tizen::Base;
-using namespace Tizen::Base::Collection;
-
-namespace {
- const String DEVICE_MANAGER_SERVICE_ID = L"osp.devicemanager.service";
- const String DEVICE_MANAGER_COMMAND_OPEN = L"osp.devicemanager.command.open";
- const String DEVICE_MANAGER_COMMAND_CLOSE = L"osp.devicemanager.command.close";
- const String DEVICE_MANAGER_COMMAND_STATUS= L"osp.devicemanager.command.status";
- const String DEVICE_MANAGER_COMMAND_EVENT = L"osp.devicemanager.command.event";
- const String DEVICE_MANAGER_BLUETOOTH = L"osp.devicemanager.bluetooth";
-
- const String BLUETOOTH_A2DP_CONNECTED = L"Connected";
- const String BLUETOOTH_A2DP_DISCONNECTED = L"Disconnected";
- const String BLUETOOTH_A2DP_PLAY = L"Play";
- const String BLUETOOTH_A2DP_STOP = L"Stop";
- const String BLUETOOTH_A2DP_PAUSE = L"Pause";
- const String BLUETOOTH_A2DP_RESUME = L"Resume";
- const String BLUETOOTH_A2DP_FORWARD = L"Forward";
- const String BLUETOOTH_A2DP_FASTFORWARD = L"FastForward";
- const String BLUETOOTH_A2DP_BACKWARD = L"Backward";
- const String BLUETOOTH_A2DP_REWIND = L"Rewind";
-}
-
-Tizen::System::_DeviceManagerService* Tizen::System::_DeviceManagerService::__pDeviceManagerService = null;
-
-void bluetooth_connection_state_changed(int result, bool connected, const char* remote_address, bt_audio_profile_type_e type, void* user_data)
-{
- SysLog(NID_SYS, "Bluetooth headset[%s] connection[%d] event", remote_address, connected);
- String bt_event;
- _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
-
- if(pDeviceManagerService != null)
- {
- if(pDeviceManagerService->GetBluetoothStatus() != connected)
- {
- if(connected == true)
- {
- bt_event = BLUETOOTH_A2DP_CONNECTED;
- }
- else
- {
- bt_event = BLUETOOTH_A2DP_DISCONNECTED;
- }
- pDeviceManagerService->SendEvent(bt_event);
- }
- pDeviceManagerService->SetBluetoothStatus(connected);
- }
-}
-
-void app_media_key_handler(media_key_e key, media_key_event_e status, void* pUserData)
-{
- String event;
- SysLog(NID_SYS, "Bluetooth headset event is occured %d, %d", (int)key, (int)status);
- _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
- if(pDeviceManagerService != null)
- {
- if(status == MEDIA_KEY_STATUS_RELEASED)
- {
- switch(key)
- {
- case MEDIA_KEY_PLAY:
- event = BLUETOOTH_A2DP_PLAY;
- break;
- case MEDIA_KEY_STOP:
- event = BLUETOOTH_A2DP_STOP;
- break;
- case MEDIA_KEY_PAUSE:
- event = BLUETOOTH_A2DP_PAUSE;
- break;
- case MEDIA_KEY_PREVIOUS:
- event = BLUETOOTH_A2DP_BACKWARD;
- break;
- case MEDIA_KEY_NEXT:
- event = BLUETOOTH_A2DP_FORWARD;
- break;
- case MEDIA_KEY_FASTFORWARD:
- event = BLUETOOTH_A2DP_FASTFORWARD;
- break;
- case MEDIA_KEY_REWIND:
- event = BLUETOOTH_A2DP_REWIND;
- break;
- case MEDIA_KEY_UNKNOWN:
- default:
- SysLog(NID_SYS, "Unsupported key[%d] is occured.", key);
- return;
- }
- pDeviceManagerService->SendEvent(event);
- }
- }
-}
-
-_DeviceManagerService::_DeviceManagerService()
- : _ICommunicationRequestListener()
- , __pCommunicationDispatcher(null)
- , isBluetoothHeadSetConnected(false)
- , isInitBluetooth(false)
-{
- result r = E_SUCCESS;
-
- __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
- SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher initiate is failed.");
-
-/*
- if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_devicemanager") != true)
- {
- r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add event listener.");
- }
-*/
- r = __interestedPidList.Construct();
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to initiate bluetooth headset application list.");
-CATCH:
- SetLastResult(r);
-}
-
-_DeviceManagerService::~_DeviceManagerService()
-{
- result r = E_SUCCESS;
-
-
- if(isInitBluetooth == true)
- {
- int btResult = 0;
- SysLog(NID_SYS, "Bluetooth headset event is released.");
- media_key_release();
- btResult = bt_audio_unset_connection_state_changed_cb();
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to unregister bluetooth headset connection event");
-
- btResult = bt_audio_deinitialize();
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to close bluetooth");
-
- btResult = bt_deinitialize();
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to init bluetooth module");
- isInitBluetooth = false;
- }
-
- SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not ready");
-
- r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to remove event listener");
-
-CATCH:
- SetLastResult(r);
-}
-
-_DeviceManagerService*
-_DeviceManagerService::GetInstance(void)
-{
- if(__pDeviceManagerService == null)
- {
- __pDeviceManagerService = new (std::nothrow) _DeviceManagerService();
- }
- return __pDeviceManagerService;
-}
-
-String
-_DeviceManagerService::GetId(void)
-{
- return DEVICE_MANAGER_SERVICE_ID;
-}
-
-void
-_DeviceManagerService::SendEvent(String event)
-{
- if(__interestedPidList.GetCount() > 0)
- {
- int count = 0;
- Integer* pPid = null;
- ArrayList* data = null;
-
- for(count = 0 ; count < __interestedPidList.GetCount() ; count++)
- {
- pPid = (Integer*)__interestedPidList.GetAt(count);
- if(pPid == null)
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to get appid from bluetooth headset app list");
- }
- else
- {
- data = new (std::nothrow) ArrayList(SingleObjectDeleter);
- data->Construct();
- data->Add(new (std::nothrow) String(DEVICE_MANAGER_SERVICE_ID));
- data->Add(new (std::nothrow) String(DEVICE_MANAGER_COMMAND_EVENT));
- data->Add(new (std::nothrow) String(DEVICE_MANAGER_BLUETOOTH));
- data->Add(new (std::nothrow) String(event));
-
- __pCommunicationDispatcher->SendData(pPid->value, data);
- SysLog(NID_SYS, "Bluetooth headset event is sended to %d.", pPid->value);
- }
- }
- }
- else
- {
- SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application.");
- }
-}
-
-void
-_DeviceManagerService::AddInterestedApp(int pid)
-{
- int count = 0;
- for(count = 0; count < __interestedPidList.GetCount(); count++)
- {
- Integer* pPid = (Integer*)__interestedPidList.GetAt(count);
- if(pPid->value == pid)
- {
- return;
- }
- }
-
- if(isInitBluetooth == false)
- {
- SysLog(NID_SYS, "Bluetooth headset event is reserved.");
-
- int btResult = 0;
- btResult = bt_initialize();
-
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to init bluetooth module");
-
- btResult = bt_audio_initialize();
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to init bluetooth audio module");
-
- btResult = bt_audio_set_connection_state_changed_cb(bluetooth_connection_state_changed, null);
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to register bluetooth audio event");
-
- isInitBluetooth = true;
- }
-
- Integer* pPid = new (std::nothrow) Integer(pid);
- __interestedPidList.Add(*pPid);
-
- if(__interestedPidList.GetCount() > 0)
- {
- media_key_reserve(app_media_key_handler, null);
- }
-}
-
-void
-_DeviceManagerService::RemoveInterestedApp(int pid)
-{
- int count = 0;
- for(count = 0; count < __interestedPidList.GetCount(); count++)
- {
- Integer* pPid = (Integer*)__interestedPidList.GetAt(count);
- SysTryReturnVoidResult(NID_SYS, pPid != null, E_SYSTEM, "It is failed to get integerested PID.");
- if(pPid->value == pid)
- {
- __interestedPidList.RemoveAt(count, true);
- break;
- }
- }
-
- if(__interestedPidList.GetCount() == 0)
- {
- media_key_release();
- }
-}
-
-void
-_DeviceManagerService::OnRequestOccured(AppId appId, int pid, ArrayList* request, ArrayList* response)
-{
- StringComparer strComparer;
- int cmp = 0;
- result r = E_SUCCESS;
- String* command = null;
- String* device = null;
-
- SysLog(NID_APP, "Request is forwarded to _DeviceManagerService");
- SysTryCatch(NID_SYS, request != null && response != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters are null");
-
- command = (String*)request->GetAt(1);
- device = (String*)request->GetAt(2);
- SysTryCatch(NID_SYS, command!= null && device != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters has no command %x, %x", command, device);
-
- SysLog(NID_SYS, "command is %ls, device is %ls", command->GetPointer(), device->GetPointer());
-
- strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_OPEN, cmp);
- if(cmp == 0)
- {
- strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
- if(cmp == 0)
- {
- SysLog(NID_SYS, "Bluetooth headset event is required");
- AddInterestedApp(pid);
- }
- }
-
- strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_CLOSE, cmp);
- if(cmp == 0)
- {
- strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
- if(cmp == 0)
- {
- RemoveInterestedApp(pid);
- }
- }
-
- strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_STATUS, cmp);
- if(cmp == 0)
- {
- strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
- if(cmp == 0)
- {
-
- SysLog(NID_SYS, "Bluetooth headset status is %d", isBluetoothHeadSetConnected);
- if(response != null)
- {
- String* serviceId = new (std::nothrow) String(DEVICE_MANAGER_SERVICE_ID);
- String* commandId = new (std::nothrow) String(DEVICE_MANAGER_COMMAND_STATUS);
- String* deviceId = new (std::nothrow) String(DEVICE_MANAGER_BLUETOOTH);
- String* status = null;
- if(isBluetoothHeadSetConnected == true)
- {
- status = new (std::nothrow) String(BLUETOOTH_A2DP_CONNECTED);
- }
- else
- {
- status = new (std::nothrow) String(BLUETOOTH_A2DP_DISCONNECTED);
- }
- response->Add(*serviceId);
- response->Add(*commandId);
- response->Add(*deviceId);
- response->Add(*status);
- }
- }
- }
-
-CATCH:
- SetLastResult(r);
-}
-
-void
-_DeviceManagerService::OnApplicationTerminated(const AppId& appId, int pid)
-{
- RemoveInterestedApp(pid);
-}
-
-bool
-_DeviceManagerService::GetBluetoothStatus(void)
-{
- return isBluetoothHeadSetConnected;
-}
-void
-_DeviceManagerService::SetBluetoothStatus(bool status)
-{
- isBluetoothHeadSetConnected = status;
-}
-
#include "FApp_CommunicationDispatcher.h"
#include "FSys_SystemService.h"
-#include "FSys_RuntimeInfo.h"
using namespace std;
static const wchar_t* _SYSTEM_COMMAND_GET_IMEI_INTERNAL = L"osp.system.command.get.imei.internal";
static const wchar_t* _SYSTEM_COMMAND_GET_DUID_INTERNAL = L"osp.system.command.get.duid.internal";
- static const wchar_t* _SYSTEM_COMMAND_POWER = L"osp.system.command.power";
static const wchar_t* _SYSTEM_COMMAND_SYSTEM = L"osp.system.command.system";
- static const wchar_t* _SYSTEM_COMMAND_RUNTIME = L"osp.system.command.runtime";
static const wchar_t* _SYSTEM_RESULT_OK = L"osp.system.result.ok";
static const wchar_t* _SYSTEM_RESULT_ERROR = L"osp.system.result.error";
_SystemService::_SystemService()
: _ICommunicationRequestListener()
, __pCommunicationDispatcher(null)
- , __pPowerManager(null)
{
result r = E_SUCCESS;
_AppManagerImpl* pAppManagerImpl = null;
r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add event listener");
-/*
- if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_powermanager") != true)
- {
- __pPowerManager = _PowerManager::GetInstance();
- SysTryCatch(NID_SYS, __pPowerManager != null, r = E_SYSTEM, E_SYSTEM, "_pPowerManager initiate is failed");
- }
-*/
+
pAppManagerImpl = _AppManagerImpl::GetInstance();
SysTryCatch(NID_SYS, pAppManagerImpl != null, r = E_SYSTEM, E_SYSTEM, "It is failed to get _AppManagerImpl class.");
r = pAppManagerImpl->AddActiveAppEventListener(*this);
SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add active app event listener");
-
CATCH:
SetLastResult(r);
}
void
_SystemService::OnActiveAppChanged(const AppId& appId)
{
- AppId smallAppId;
-
- result r = E_SUCCESS;
- r = appId.SubString(0, 10, smallAppId);
-
- if(__pPowerManager != null && r == E_SUCCESS)
- {
- __pPowerManager->OnActiveAppChanged(smallAppId);
- }
}
void
returnValue = new (std::nothrow) String(duid);
}
}
- else if(command->Contains(_SYSTEM_COMMAND_POWER) == true)
- {
- if(__pPowerManager != null)
- {
- __pPowerManager->OnRequestOccured(appId, request, response);
- return;
- }
- }
else if(*command == _SYSTEM_COMMAND_CHANGE_TIME)
{
SysLog(NID_SYS, "Change system time");
}
}
}
- else if(command->Contains(_SYSTEM_COMMAND_RUNTIME) == true)
- {
- r = __runtimeInfo.OnRequestOccured(appId, pid, request, response);
- return;
- }
else
{
resultId = new (std::nothrow) String(_SYSTEM_RESULT_INVALID);
void
_SystemService::OnApplicationTerminated(const AppId& appId, int pid)
{
- SysLog(NID_SYS, "Application (%ls) is terminated.", appId.GetPointer());
- if(__pPowerManager != null)
- {
- __pPowerManager->OnApplicationTerminated(appId);
- }
}
+++ /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 FSys_PowerManager.cpp
- * @brief This is the implementation file for _PowerManager class.
- */
-#include <unique_ptr.h>
-#include <new>
-
-#include <device.h>
-#include <system_info.h>
-
-#include <FBaseSysLog.h>
-
-#include "FSys_PowerManager.h"
-
-using namespace std;
-
-using namespace Tizen::App;
-using namespace Tizen::Base;
-using namespace Tizen::Base::Collection;
-using namespace Tizen::Base::Utility;
-using namespace Tizen::Io;
-
-namespace {
- static const wchar_t* _POWER_BRIGHTNESS_CHANGE = L"osp.system.command.power.change.brightness";
- static const wchar_t* _POWER_BRIGHTNESS_RESTORE = L"osp.system.command.power.restore.brightness";
- static const int _POWER_COMMAND_ID = 1;
- static const wchar_t* _POWER_OK = L"osp.system.result.ok";
- static const wchar_t* _POWER_ERROR = L"osp.system.result.error";
-}
-
-namespace Tizen { namespace System
-{
-
-_PowerManager* _PowerManager::__pPowerManager = null;
-
-_PowerManager::_PowerManager()
-{
- __appBrightnessList.Construct();
-}
-
-_PowerManager::~_PowerManager()
-{
- __appBrightnessList.RemoveAll(true);
-}
-
-_PowerManager*
-_PowerManager::GetInstance()
-{
-
- if(__pPowerManager == null)
- {
- __pPowerManager = new (std::nothrow) _PowerManager();
- }
-
- return __pPowerManager;
-}
-
-result
-_PowerManager::ChangeBrightness(void)
-{
-
- int ret = DEVICE_ERROR_NONE;
- result r = E_OBJ_NOT_FOUND;
-
- SysLog(NID_SYS, "Current Active App is [%ls]", __activeAppId.GetPointer());
-
- if(__appBrightnessList.GetCount() > 0)
- {
- Integer* brightness = (Integer*)__appBrightnessList.GetValue(__activeAppId);
-
- if(brightness != null)
- {
- SysLog(NID_SYS, "Brightness is [%d]", brightness->ToInt());
- ret = device_set_brightness(0, brightness->ToInt());
- if(ret == DEVICE_ERROR_NONE)
- {
- r = E_SUCCESS;
- }
- else
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to change brightness.");
- r = E_SYSTEM;
- }
- }
- }
-
- if(r == E_OBJ_NOT_FOUND)
- {
- SysLog(NID_SYS, "Current Active App does not have brightness.");
- ret = device_set_brightness_from_settings(0);
- r = E_SUCCESS;
- }
-
- return r;
-}
-
-result
-_PowerManager::OnActiveAppChanged(const AppId& appId)
-{
- result r = E_SUCCESS;
-
- if(__activeAppId != appId)
- {
- __activeAppId = appId;
- r = ChangeBrightness();
- }
- else
- {
- SysLog(NID_SYS, "Current App[%ls] is already a");
- }
-
- return r;
-}
-
-result
-_PowerManager::OnApplicationTerminated(const AppId& appId)
-{
- result r = E_SUCCESS;
- String requiredAppId;
- appId.SubString(0, 10, requiredAppId);
-
- __appBrightnessList.Remove(requiredAppId, true);
- r = ChangeBrightness();
-
- return r;
-}
-
-result
-_PowerManager::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
-{
- result r = E_SUCCESS;
-
- String* command = (String*)request->GetAt(_POWER_COMMAND_ID);
-
- SysTryCatch(NID_SYS, command != null, r = E_SYSTEM, r, "command is empty.");
-
- if(*command == _POWER_BRIGHTNESS_CHANGE)
- {
- SysTryCatch(NID_SYS, __activeAppId == appId, r = E_SUCCESS, r, "It is not active application[%ls]. Current Active App is [%ls].", appId.GetPointer(), __activeAppId.GetPointer());
- int brightness = 0;
- String* brightnessBuffer = (String*)request->GetAt(_POWER_COMMAND_ID + 1);
- Integer::Parse(*brightnessBuffer, brightness);
-
- __appBrightnessList.Remove(appId, true);
-
- unique_ptr<Integer> pBrightness(new (std::nothrow) Integer(brightness));
- unique_ptr<String> pAppId(new (std::nothrow) String(appId));
-
- r = __appBrightnessList.Add(*pAppId, *pBrightness);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add requested App Id(%ls) and Brightness(%d) on the managed app list.", pAppId->GetPointer(), pBrightness->ToInt());
- pAppId.release();
- pBrightness.release();
- r = ChangeBrightness();
- }
- else if(*command == _POWER_BRIGHTNESS_RESTORE)
- {
- __appBrightnessList.Remove(appId, true);
- r = ChangeBrightness();
- }
- else
- {
- SysLogException(NID_SYS, E_SYSTEM, "Required command[%ls] is not proccess on _PowerManager.", command->GetPointer());
- r = E_SYSTEM;
- }
-
-CATCH:
- unique_ptr<String> resultId(new (std::nothrow) String());
-
- SysTryReturnResult(NID_SYS, resultId != null, E_SYSTEM, "It is failed to allocate memory for response message creating.");
-
- if(r == E_SUCCESS)
- {
- resultId->Append(_POWER_OK);
- }
- else
- {
- resultId->Append(_POWER_ERROR);
- }
-
- response->Add(*resultId.release());
-
- return r;
-}
-
-} } // Tizen::System
+++ /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 FSys_PowerManager.h
- * @brief This is the header file for the _PowerManager class.
- */
-
-#ifndef _FSYS_SERVICE_SYS_POWER_MANAGER_H_
-#define _FSYS_SERVICE_SYS_POWER_MANAGER_H_
-
-#include <FApp.h>
-#include <FBase.h>
-
-namespace Tizen { namespace System
-{
-
-class _PowerManager
-{
-public:
- result OnRequestOccured(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
- result OnActiveAppChanged(const Tizen::App::AppId& appId);
- result OnApplicationTerminated(const Tizen::App::AppId& appId);
-
-public:
- static _PowerManager* GetInstance(void);
-
-private:
- _PowerManager();
- ~_PowerManager();
- result ChangeBrightness(void);
-
-private:
- Tizen::App::AppId __activeAppId;
- Tizen::Base::Collection::HashMap __appBrightnessList;
-
- static _PowerManager* __pPowerManager;
-};
-
-} } // Tizen::System
-
-#endif // _FSYS_SERVICE_SYS_POWER_MANAGER_H_
+++ /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 FSys_RuntimeInfo.cpp
- * @brief This is the implementation file for _RuntimeInfo class.
- */
-
-#include <unique_ptr.h>
-#include <pthread.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <sys/stat.h>
-
-#include <FBase_StringConverter.h>
-#include <FBaseSysLog.h>
-
-#include "FApp_CommunicationDispatcher.h"
-#include "FSys_RuntimeInfo.h"
-
-using namespace std;
-using namespace Tizen::App;
-using namespace Tizen::Base;
-using namespace Tizen::Base::Collection;
-
-namespace Tizen { namespace System
-{
-
-//Communication
-static const int _RUNTIME_GET_PARAM_TYPE = 1;
-static const wchar_t* _RUNTIME_SERVICE_ID = L"osp.system.service";
-static const wchar_t* _RUNTIME_GET_SIZE = L"osp.system.command.runtime.get.size";
-static const wchar_t* _RUNTIME_RESULT_SUCCESS = L"osp.system.result.success";
-static const wchar_t* _RUNTIME_RESULT_SYSTEM = L"osp.system.result.system";
-
-static pthread_mutex_t send_msg_lock;
-class _DirectorySizeObject
-{
-public:
- _DirectorySizeObject()
- : path(null)
- , pid(0)
- , msg_id(0)
- {
- }
- ~_DirectorySizeObject()
- {
- if(path != null)
- {
- delete [] path;
- }
- }
-
- char* path;
- int pid;
- int msg_id;
-};
-
-_RuntimeInfo::_RuntimeInfo()
-{
- if(pthread_mutex_init(&send_msg_lock, null))
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to init mutex.");
- }
-}
-
-_RuntimeInfo::~_RuntimeInfo()
-{
- if(pthread_mutex_destroy(&send_msg_lock))
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to term mutex.");
- }
-}
-
-result
-_RuntimeInfo::OnRequestOccured(AppId appId, int pid, ArrayList* request, ArrayList* response)
-{
-
- SysLog(NID_SYS, "Request is forwarded to _RuntimeInfo");
- SysTryReturnResult(NID_SYS, request!=null && response!=null, E_SYSTEM, "There is no data.");
-
- String* command = (String*)request->GetAt(_RUNTIME_GET_PARAM_TYPE);
- String* resultCode = null;
-
- if(*command == _RUNTIME_GET_SIZE)
- {
- int mid = 0;
- String* path = (String*)request->GetAt(_RUNTIME_GET_PARAM_TYPE+1);
- String* messageId = (String*)request->GetAt(_RUNTIME_GET_PARAM_TYPE+2);
- SysTryReturnResult(NID_SYS, path != null, E_SYSTEM, "There is no path information.");
- unique_ptr<char> directoryPath(_StringConverter::CopyToCharArrayN(*path));
- Integer::Parse(*messageId, mid);
- _DirectorySizeObject* dso = new (std::nothrow) _DirectorySizeObject();
- dso->pid = pid;
- dso->path = directoryPath.release();
- dso->msg_id = mid;
-
- pthread_t p_thread;
- int thr_id = pthread_create(&p_thread, null, GetDirectorySizeAsync, dso);
- if(thr_id < 0)
- {
- resultCode = new (std::nothrow) String(_RUNTIME_RESULT_SYSTEM);
- }
- else
- {
- pthread_detach(p_thread);
- resultCode = new (std::nothrow) String(_RUNTIME_RESULT_SUCCESS);
- }
- }
- else
- {
- resultCode = new (std::nothrow) String(_RUNTIME_RESULT_SYSTEM);
- }
-
- response->Add(resultCode);
- return E_SUCCESS;
-}
-
-
-long long GetDirectorySize(const char* path)
-{
- struct dirent *de;
- struct stat buf;
- DIR* d = opendir(path);
- long long total_size = 0;
- if(d == null)
- {
- return 0;
- }
-
- for (de = readdir(d); de != null; de = readdir(d))
- {
- char filePath[1024] = {0,};
- sprintf(filePath, "%s%s", path, de->d_name);
-
- if (lstat(filePath, &buf) == 0)
- {
- if (S_ISLNK(buf.st_mode) == true)
- {
- total_size += buf.st_size;
- }
- else // reg file
- {
- if(stat(filePath, &buf) == 0)
- {
- if(S_ISDIR(buf.st_mode) == true)
- {
- char directoryName[1024] = {0,};
- sprintf(directoryName, "%s%s/", path, de->d_name);
- if(strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0)
- {
- total_size += GetDirectorySize(directoryName);
- }
- total_size += buf.st_size;
-
- }
- else
- {
- total_size += buf.st_size;
- }
- }
- }
- }
- }
- closedir(d);
- return total_size;
-}
-
-void*
-_RuntimeInfo::GetDirectorySizeAsync(void* data)
-{
- result r= E_SUCCESS;
- long long size = 0;
-
- _DirectorySizeObject* dso = (_DirectorySizeObject*) data;
- SysTryCatch(NID_SYS, dso != null, r = E_SYSTEM, r, "There is no _DirectorySizeObject.");
- size = GetDirectorySize(dso->path);
-
-CATCH:
- SysLog(NID_SYS, "pid: %d, id: %d, size: %lld, result: %s", dso->pid, dso->msg_id, size, GetErrorMessage(r));
- SendResponse(dso->pid, dso->msg_id, size, r);
- delete dso;
- return null;
-}
-
-void
-_RuntimeInfo::SendResponse(int pid, int msg_id, long long size, result rcode)
-{
- result r = E_SUCCESS;
- pthread_mutex_lock(&send_msg_lock);
-
- ArrayList* data = null;
- String* pValue = null;
- String* pMessageId = null;
-
- SysLog(NID_SYS, "It sends asynchronous result.");
-
- _CommunicationDispatcher* pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
- SysTryCatch(NID_SYS, pCommunicationDispatcher != null, r = E_SYSTEM, r, "Communication Dispatcher is not ready.");
-
- data = new (std::nothrow) ArrayList(SingleObjectDeleter);
- data->Construct();
-
- pMessageId = new (std::nothrow) String();
- pMessageId->Append(msg_id);
-
- data->Add(new (std::nothrow) String(_RUNTIME_SERVICE_ID));
- data->Add(new (std::nothrow) String(_RUNTIME_GET_SIZE));
- data->Add(pMessageId);
-
- pValue = new (std::nothrow) String();
- pValue->Append(size);
- data->Add(pValue);
-
- if(rcode == E_SUCCESS)
- {
- data->Add(new (std::nothrow) String(_RUNTIME_RESULT_SUCCESS));
- }
- else
- {
- data->Add(new (std::nothrow) String(_RUNTIME_RESULT_SYSTEM));
- }
-
- pCommunicationDispatcher->SendData(pid, data);
-CATCH:
- pthread_mutex_unlock(&send_msg_lock);
-}
-} } // Tizen::System
+++ /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 FSys_RuntimeInfo.h
- * @brief This is the header file for the _RuntimeInfo class.
- */
-
-#ifndef _FSYS_SERVICE_RUN_INFO_H_
-#define _FSYS_SERVICE_RUN_INFO_H_
-
-#include <FApp.h>
-#include <FBaseColArrayList.h>
-
-namespace Tizen { namespace System
-{
-
-class _RuntimeInfo
-{
-public:
- _RuntimeInfo();
- ~_RuntimeInfo();
-public:
- result OnRequestOccured(Tizen::App::AppId appId, int pid, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
-
- static void* GetDirectorySizeAsync(void* data);
-
- static void SendResponse(int pid, int msg_id, long long size, result rcode);
-};
-
-} } // Tizen::System
-
-#endif // _FSYS_SERVICE_RUN_INFO_H_