class _CommunicationDispatcher
: public Tizen::Io::_IIpcServerEventListener
, public _IAppEventListener
- , virtual public Tizen::Base::Runtime::IEventListener
+ , public Tizen::Base::Runtime::IEventListener
{
private:
_CommunicationDispatcher(void);
virtual void OnApplicationTerminated(const AppId& appId, int pid);
bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response);
- result SendData(const int pid, Tizen::Base::Collection::ArrayList& data);
+ result SendData(const int pid, Tizen::Base::Collection::ArrayList* data);
private:
Tizen::Io::_IpcServer* __pIpcServer;
*/
class _DeviceManagerService
: public Tizen::App::_ICommunicationRequestListener
- , public Tizen::System::_IDeviceManagerEventListener
{
private:
_DeviceManagerService(void);
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 OnBluetoothEventOccured(int code);
void SendEvent(Tizen::Base::String event);
void SetBluetoothStatus(bool status);
bool GetBluetoothStatus(void);
void
AccessoryMonitor::OnDataRouterDataReceivedN(const char* buffer, int length)
{
- //result r = E_SUCCESS;
SysLog(NID_SYS, "serial data is forwarded to AccessoryMonitor class");
SysTryReturnVoidResult(NID_SYS, buffer != null, E_INVALID_ARG, "[E_INVALID_ARG] buffer should not be null.");
+ SysTryReturnVoidResult(NID_SYS, sendFunction != null, E_SYSTEM, "IPC Server is not ready.");
bool primitiveCommand = false;
if(__pAccessoryConditionHandler != null)
SysLog(NID_SYS, "Requested data is not command. it will be forwarded to current application[%d]", __currentPid);
if(__currentPid > 0)
{
- ArrayList* pDataList = new (std::nothrow) ArrayList();
+ ArrayList* pDataList = new (std::nothrow) ArrayList(SingleObjectDeleter);
ByteBuffer* pByteBuffer = new (std::nothrow) ByteBuffer();
String* pCommand = new (std::nothrow) String(SERIAL_COMMAND_DATA);
String* pComponentId= new (std::nothrow) String(ACCESSORY_COMPONENT_ID);
char* pIterator = const_cast<char*>(buffer);
+ SysLog(NID_SYS, "Required buffer length is %d.", length);
pByteBuffer->Construct(length);
- for(int i = 0; i < length; i++)
+ for(int i=0;i<length;i++)
{
- pByteBuffer->SetByte((byte)(*pIterator));
- pIterator++;
+ SysLog(NID_SYS, "TEST: %c", buffer[i]);
}
- pDataList->Construct();
- pDataList->Add(*pComponentId);
- pDataList->Add(*pCommand);
- pDataList->Add(*pByteBuffer);
-
+ pByteBuffer->SetArray((byte*)pIterator, 0, length);
- if(sendFunction!=null)
- {
- SysLog(NID_SYS, "Data is forwarded to [%d]", __currentPid);
- sendFunction(__currentPid, pDataList);
- }
- else
- {
- SysLog(NID_SYS, "sendFunction is empty.");
- }
+ pDataList->Construct();
+ pDataList->Add(pComponentId);
+ pDataList->Add(pCommand);
+ pDataList->Add(pByteBuffer);
- pDataList->RemoveAll(true);
- delete(pDataList);
+ sendFunction(__currentPid, pDataList);
}
}
}
_AppLaunchCondition* pAppLaunchCondition = null;
_AlarmConditionHandler* pAlarmConditionHandler = _AlarmConditionHandler::GetInstance();
pAppLaunchCondition = pAlarmConditionHandler->GetAppLaunchCondition(alarmId);
- if(pAppLaunchCondition != null)
+ if(pAppLaunchCondition != null)
{
SysLog(NID_SYS, "Launch Request");
pAlarmConditionHandler->Launch(*pAppLaunchCondition);
#include <FIo_AppServiceIpcMessages.h>
#include "FApp_CommunicationDispatcher.h"
+using namespace Tizen::Base::Runtime;
using namespace Tizen::Io;
using namespace Tizen::App;
using namespace Tizen::Base;
return __pCommunicationDispatcher;
}
+class _IpcEventThreadForAsync
+ : public EventDrivenThread
+{
+public:
+ _IpcEventThreadForAsync(_IpcServer *pIpcServer)
+ : __pIpcServer(pIpcServer)
+ {
+ }
+
+ result Construct(long stackSize, ThreadPriority priority)
+ {
+ return EventDrivenThread::Construct(stackSize, priority);
+ }
+
+ bool OnStart(void)
+ {
+ return true;
+ }
+
+ void OnStop(void)
+ {
+ }
+
+ void OnUserEventReceivedN(RequestId requestId, IList *pArgs)
+ {
+ if(pArgs != null)
+ {
+ ArrayList* data = (ArrayList*)pArgs;
+ result r = __pIpcServer->SendResponse((int)requestId, new (std::nothrow) IoService_Data(*data));
+ delete pArgs;
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send IPC message to %d. [%s]", (int)requestId, GetErrorMessage(r));
+ }
+ }
+private:
+ _IpcServer* __pIpcServer;
+};
+
+_IpcEventThreadForAsync* pIpcEventThreadForAsync = null;
+
result
-_CommunicationDispatcher::SendData(const int pid, ArrayList& data)
+_CommunicationDispatcher::SendData(const int pid, ArrayList* data)
{
result r = E_SUCCESS;
- SysTryReturnResult(NID_SYS, __pIpcServer != null, E_SYSTEM, "IPC server is not ready.");
- r = __pIpcServer->SendResponse(pid, new (std::nothrow) IoService_Data(data));
+
+ SysTryCatch(NID_SYS, __pIpcServer != null, r = E_SYSTEM, E_SYSTEM, "IPC server is not ready.");
+ SysTryCatch(NID_SYS, data != null, r = E_SYSTEM, E_SYSTEM, "There is no data.");
+
+ if(pIpcEventThreadForAsync == null)
+ {
+ pIpcEventThreadForAsync = new (std::nothrow) _IpcEventThreadForAsync(__pIpcServer);
+ pIpcEventThreadForAsync->Construct(1048576, THREAD_PRIORITY_MID);
+ pIpcEventThreadForAsync->Start();
+ }
+ SysTryCatch(NID_SYS, pIpcEventThreadForAsync != null, r = E_SYSTEM, E_SYSTEM, "Event thread is not ready.");
+
+ r = pIpcEventThreadForAsync->SendUserEvent((RequestId)pid, (IList*)data);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Message is failed to add on event thread.");
+
+CATCH:
+ if(r != E_SUCCESS)
+ {
+ delete data;
+ }
return r;
}
result
_AccessoryManagerService::SendDataFunc(int pid, ArrayList* data)
{
- SysLog(NID_SYS, "Request to send data");
+ SysLog(NID_SYS, "Request to send data to %d.", pid);
SysTryReturnResult(NID_SYS, __pAccessoryManagerService != null, E_SYSTEM, "AccessoryManagerService is not ready");
return __pAccessoryManagerService->SendData(pid, data);
}
{
SysTryReturnResult(NID_SYS, __pCommunicationDispatcher != null, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
- return __pCommunicationDispatcher->SendData(pid, *data);
+ return __pCommunicationDispatcher->SendData(pid, data);
}
String
{
int count = 0;
Integer* pPid = null;
- ArrayList data;
- String serviceId(DEVICE_MANAGER_SERVICE_ID);
- String commandId(DEVICE_MANAGER_COMMAND_EVENT);
- String deviceId(DEVICE_MANAGER_BLUETOOTH);
- String eventId(event);
-
- data.Construct();
- data.Add(serviceId);
- data.Add(commandId);
- data.Add(deviceId);
- data.Add(eventId);
+ ArrayList* data = null;
for(count = 0 ; count < __interestedPidList.GetCount() ; count++)
{
if(pPid == null)
{
SysLogException(NID_SYS, E_SYSTEM, "It is failed to get appid from bluetooth headset app list");
- return;
}
-
- __pCommunicationDispatcher->SendData(pPid->value, data);
- SysLog(NID_SYS, "Bluetooth headset event is sended to %d.", pPid->value);
+ 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
{
}
void
-_DeviceManagerService::OnBluetoothEventOccured(int code)
-{
- int count = 0;
- Integer* pPid = null;
-
- String command = DEVICE_MANAGER_COMMAND_EVENT;
- String device = DEVICE_MANAGER_BLUETOOTH;
- String event = L"event test";
-
- result r = E_SUCCESS;
-
- if(__interestedPidList.GetCount() == 0)
- {
- SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application.");
- return;
- }
-
- ArrayList eventData;
- r = eventData.Construct();
- SysTryCatch(NID_SYS, r == E_SUCCESS, , E_SYSTEM, "It is failed to create eventData, [%s] Propagated.", GetErrorMessage(r));
-
- eventData.Add(command);
- eventData.Add(device);
- eventData.Add(event);
-
- for(count = 0 ; count < __interestedPidList.GetCount() ; count++)
- {
- pPid = (Integer*)__interestedPidList.GetAt(count);
- SysTryReturnVoidResult(NID_SYS, pPid != null, E_SYSTEM, "It is failed to get appid from bluetooth headset app list.");
-
- r = __pCommunicationDispatcher->SendData(pPid->value, eventData);
- if(r != E_SUCCESS)
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to send bluetooth event data.");
- }
- }
-
-CATCH:
- SetLastResult(r);
-}
-
-void
_DeviceManagerService::AddInterestedApp(int pid)
{
int count = 0;
Integer* pProcessId = (Integer*)pEnum->GetCurrent();
SysTryReturnResult(NID_SYS, pProcessId != null, E_SYSTEM, "There is no listener id.");
- String serviceId(_SETTING_SERVICE_ID);
- String eventId(_SETTING_SERVICE_TYPE_EVENT);
-
- ArrayList data;
- data.Construct();
- data.Add(serviceId);
- data.Add(eventId);
- data.Add(key);
- r = __pCommunicationDispatcher->SendData(pProcessId->value, data);
+ ArrayList* data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ data->Construct();
+ data->Add(new (std::nothrow) String(_SETTING_SERVICE_ID));
+ data->Add(new (std::nothrow) String(_SETTING_SERVICE_TYPE_EVENT));
+ data->Add(new (std::nothrow) String(key));
+ r = __pCommunicationDispatcher->SendData(pProcessId->value, data); // Ownership is transfered.
if(r != E_SUCCESS)
{
SysLog(NID_SYS, "Required Key[%ls] is failed to delivered to application[%d]. [%s]", key.GetPointer(), pProcessId->value, GetErrorMessage(r));
Integer* pProcessId = (Integer*)pEnum->GetCurrent();
SysTryReturnResult(NID_SYS, pProcessId != null, E_SYSTEM, "There is no listener id.");
- String serviceId(_SETTING_SERVICE_ID);
- String eventId(_SETTING_SERVICE_TYPE_EVENT);
+ ArrayList* data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ data->Construct();
+ data->Add(new (std::nothrow) String(_SETTING_SERVICE_ID));
+ data->Add(new (std::nothrow) String(_SETTING_SERVICE_TYPE_EVENT_INTERNAL));
+ data->Add(new (std::nothrow) String(key));
- ArrayList data;
- data.Construct();
- data.Add(serviceId);
- data.Add(eventId);
- data.Add(key);
- r = __pCommunicationDispatcher->SendData(pProcessId->value, data);
+ r = __pCommunicationDispatcher->SendData(pProcessId->value, data); // Ownership is transfered.
if(r != E_SUCCESS)
{
SysLog(NID_SYS, "Required Key[%ls] is failed to delivered to application[%d]. [%s]", key.GetPointer(), pProcessId->value, GetErrorMessage(r));
String serviceId(_SETTING_SERVICE_ID);
- ArrayList data;
- data.Construct();
- data.Add(serviceId);
- data.Add(responseId);
- data.Add(key);
- data.Add(value);
+ ArrayList* data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ data->Construct();
+ data->Add(new (std::nothrow) String(_SETTING_SERVICE_ID));
+ data->Add(new (std::nothrow) String(responseId));
+ data->Add(new (std::nothrow) String(key));
+ data->Add(new (std::nothrow) String(value));
return __pCommunicationDispatcher->SendData(pid, data);
}
}
else
{
- char* pImei = null;
- ret = system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &pImei);
- if(ret != SYSTEM_INFO_ERROR_NONE || pImei == null)
+ bool supported = false;
+ r = __systemInfo.GetValue(L"http://tizen.org/feature/telephony", supported);
+ if(r != E_SUCCESS || supported == false)
{
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to get IMEI.");
+ SysLogException(NID_SYS, E_SYSTEM, "Current device does not support telephony feature.");
resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
}
else
{
- resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
- returnValue = new (std::nothrow) String(pImei);
+ char* pImei = null;
+ ret = system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &pImei);
+ if(ret != SYSTEM_INFO_ERROR_NONE || pImei == null)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to get IMEI.");
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
+ }
+ else
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
+ returnValue = new (std::nothrow) String(pImei);
+ }
}
}
}
result r = E_SUCCESS;
pthread_mutex_lock(&send_msg_lock);
- ArrayList data;
- String serviceId(_RUNTIME_SERVICE_ID);
- String responseId(_RUNTIME_GET_SIZE);
- String messageId;
- String value;
- String resultCode;
+ ArrayList* data = null;
+ String* value = null;
- SysLog(NID_SYS, "Send Result");
+ 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.");
- messageId.Append(msg_id);
- value.Append(size);
+ data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ data->Construct();
+ data->Add(new (std::nothrow) String(_RUNTIME_SERVICE_ID));
+ data->Add(new (std::nothrow) String(_RUNTIME_GET_SIZE));
+ data->Add(new (std::nothrow) String(msg_id));
+ value = new String();
+ value->Append(size);
+ data->Add(*value);
+
+ data->Add(value);
if(rcode == E_SUCCESS)
{
- resultCode.Append(_RUNTIME_RESULT_SUCCESS);
+ data->Add(new (std::nothrow) String(_RUNTIME_RESULT_SUCCESS));
}
else
{
- resultCode.Append(_RUNTIME_RESULT_SYSTEM);
+ data->Add(new (std::nothrow) String(_RUNTIME_RESULT_SYSTEM));
}
- data.Construct();
- data.Add(serviceId);
- data.Add(responseId);
- data.Add(messageId);
- data.Add(value);
- data.Add(resultCode);
-
- r = pCommunicationDispatcher->SendData(pid, data);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to deliver directory size[%lld] result to [%d].", size, pid);
- SysLog(NID_SYS, "Result is delivered.");
+ pCommunicationDispatcher->SendData(pid, data);
CATCH:
pthread_mutex_unlock(&send_msg_lock);
}