Change-Id: I9ec20e72c512ba93f8b9a78f823f29dd9ac47207
Signed-off-by: Hariprasad Taduru <hariprasad.t@samsung.com>
Signed-off-by: Sunwook Bae <sunwook45.bae@samsung.com>
#include <FBaseString.h>
#include <FBaseSysLog.h>
#include <FBaseColAllElementsDeleter.h>
#include <FBaseString.h>
#include <FBaseSysLog.h>
#include <FBaseColAllElementsDeleter.h>
+#include <FBaseRtIEventArg.h>
#include <FIoFile.h>
#include <FIoIFileEventListener.h>
#include <FIoFileEventManager.h>
#include <FIoFile.h>
#include <FIoIFileEventListener.h>
#include <FIoFileEventManager.h>
using namespace std;
using namespace Tizen::Base;
using namespace std;
using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
using namespace Tizen::Base::Collection;
namespace Tizen { namespace Io
{
using namespace Tizen::Base::Collection;
namespace Tizen { namespace Io
{
+class _FileEventArg
+ : public IEventArg
+{
+public:
+ _FileEventArg(unsigned long event, String path, unsigned int eventId)
+ : __event(event)
+ , __path(path)
+ , __eventId(eventId)
+ {
+ }
+ unsigned long __event;
+ String __path;
+ unsigned int __eventId;
+};
+
+class _FileEvent
+ : public Event
+{
+protected:
+ virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
+ {
+ IFileEventListener* pListener = dynamic_cast<IFileEventListener*> (&listener);
+ if (pListener != null)
+ {
+ const _FileEventArg* pArg = dynamic_cast<const _FileEventArg*>(&arg);
+ if (pArg != null)
+ {
+ pListener->OnFileEventOccured(pArg->__event, pArg->__path, pArg->__eventId);
+ }
+ }
+ }
+};
+
_FileEventManagerImpl::_FileEventManagerImpl(void)
: __pMonitorFileList(null)
_FileEventManagerImpl::_FileEventManagerImpl(void)
: __pMonitorFileList(null)
- , __pFileEventListener(null)
, __inotifyFd(-1)
, __pGSource(null)
, __pGIOChannel(null)
, __inotifyFd(-1)
, __pGSource(null)
, __pGIOChannel(null)
__pMonitorFileList->RemoveAll(true);
delete __pMonitorFileList;
}
__pMonitorFileList->RemoveAll(true);
delete __pMonitorFileList;
}
path = GetRegisteredPath(pEvent->wd);
}
path = GetRegisteredPath(pEvent->wd);
}
- if (__pFileEventListener != null)
- {
- __pFileEventListener->OnFileEventOccured(event, path, eventId);
+ _FileEventArg* pEventArg= new (std::nothrow) _FileEventArg(event, path, eventId);
+ if(pEventArg != null)
+ {
+ SysLog(NID_IO, "_FileEventManagerImpl::SendEvent Event Fire");
+ __pEvent->Fire(*pEventArg);
iter += sizeof(struct inotify_event) + pEvent->len;
}
iter += sizeof(struct inotify_event) + pEvent->len;
}
{
GMainContext* pGContext = null;
result r = E_SUCCESS;
{
GMainContext* pGContext = null;
result r = E_SUCCESS;
+ _FileEvent* pEvent = null;
__inotifyFd = inotify_init();
if (__inotifyFd == -1 && errno == EMFILE)
__inotifyFd = inotify_init();
if (__inotifyFd == -1 && errno == EMFILE)
SysTryCatch(NID_IO, pGContext != null, r = E_IO, E_IO, "[E_IO] Failed to get glib context.");
}
SysTryCatch(NID_IO, pGContext != null, r = E_IO, E_IO, "[E_IO] Failed to get glib context.");
}
- SysLog(NID_IO, "GContext:%x", pGContext);
+ __pEvent = new (std::nothrow) _FileEvent();
+ SysTryReturnResult(NID_IO, __pEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- __pFileEventListener = &listener;
+ __pEvent->AddListener(listener);
__pGIOChannel = g_io_channel_unix_new(__inotifyFd); //fd wrapping
SysTryCatch(NID_IO, __pGIOChannel != null, r = E_IO, E_IO, "[E_IO] Failed to create glib channel.");
__pGIOChannel = g_io_channel_unix_new(__inotifyFd); //fd wrapping
SysTryCatch(NID_IO, __pGIOChannel != null, r = E_IO, E_IO, "[E_IO] Failed to create glib channel.");
- SysLog(NID_IO, "__pGIOChannel:%x", __pGIOChannel);
__pGSource = g_io_create_watch(__pGIOChannel, (GIOCondition)(G_IO_IN | G_IO_ERR | G_IO_NVAL | G_IO_HUP));
SysTryCatch(NID_IO, __pGSource != null, r = E_IO, E_IO, "[E_IO] Failed to create glib watch.");
__pGSource = g_io_create_watch(__pGIOChannel, (GIOCondition)(G_IO_IN | G_IO_ERR | G_IO_NVAL | G_IO_HUP));
SysTryCatch(NID_IO, __pGSource != null, r = E_IO, E_IO, "[E_IO] Failed to create glib watch.");
- SysLog(NID_IO, "__pGSource:%x", __pGSource);
g_source_set_callback(__pGSource, (GSourceFunc)OnFileEventOccured, this, NULL);
g_source_attach(__pGSource, pGContext);
g_source_set_callback(__pGSource, (GSourceFunc)OnFileEventOccured, this, NULL);
g_source_attach(__pGSource, pGContext);
- SysLog(NID_IO, "Attached fd on g_source");
__pMonitorFileList = pMonitorFileList.release();
__pMonitorFileList = pMonitorFileList.release();
#include <FBaseErrors.h>
#include <FBaseSysLog.h>
#include <FBaseErrors.h>
#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
#include <FIo_AppServiceIpcMessages.h>
#include <FIo_IpcClient.h>
#include <FIo_AppServiceIpcMessages.h>
#include <FIo_IpcClient.h>
using namespace std;
using namespace Tizen::App;
using namespace Tizen::Base;
using namespace std;
using namespace Tizen::App;
using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
using namespace Tizen::Base::Collection;
namespace Tizen { namespace Io
{
using namespace Tizen::Base::Collection;
namespace Tizen { namespace Io
{
-const String COMMUNICATION_DISPATCHER_IPC_ID = L"osp.app.ipcserver.communicationdispatcher";
-const String ACCESSORY_MANAGER_SERVICE_ID = L"osp.accessorymanager.service";
+const wchar_t COMMUNICATION_DISPATCHER_IPC_ID[] = L"osp.app.ipcserver.communicationdispatcher";
+const wchar_t ACCESSORY_MANAGER_SERVICE_ID[] = L"osp.accessorymanager.service";
+const wchar_t SERIAL_COMMAND_OPEN[] = L"Open";
+const wchar_t SERIAL_COMMAND_CLOSE[] = L"Close";
+const wchar_t SERIAL_COMMAND_WRITE[] = L"Write";
+const wchar_t SERIAL_COMMAND_DATA[] = L"Data";
+const wchar_t SERIAL_COMMAND_ERROR[] = L"Error";
-const String SERIAL_COMMAND_OPEN = L"Open";
-const String SERIAL_COMMAND_CLOSE = L"Close";
-const String SERIAL_COMMAND_WRITE = L"Write";
-const String SERIAL_COMMAND_DATA = L"Data";
-const String SERIAL_COMMAND_ERROR = L"Error";
-
-const int SERIAL_BUFFER_SIZE = 536870912; //512KB
+const int SERIAL_BUFFER_SIZE = 512 * 1024; //512KB
const int SERIAL_DATA_HEAD = 1;
const int SERIAL_DATA_BODY = 2;
const int SERIAL_DATA_HEAD = 1;
const int SERIAL_DATA_BODY = 2;
+class _SerialPortEventArg
+ : public IEventArg
+{
+public:
+ _SerialPortEventArg(ByteBuffer* pBuffer)
+ : __pBuffer(pBuffer)
+ {
+ }
+ ByteBuffer* __pBuffer;
+};
+
+class _SerialPortEvent
+ : public Event
+{
+protected:
+ virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
+ {
+ ISerialPortEventListener* pListener = dynamic_cast<ISerialPortEventListener*> (&listener);
+ if (pListener != null)
+ {
+ const _SerialPortEventArg* pArg = dynamic_cast<const _SerialPortEventArg*>(&arg);
+ if (pArg != null)
+ {
+ if (pArg->__pBuffer == null)
+ {
+ pListener->OnSerialPortErrorOccured(E_SYSTEM);
+ }
+ else
+ {
+ pListener->OnSerialPortDataReceivedN(*(pArg->__pBuffer));
+ }
+ }
+ }
+ }
+};
+
_SerialPortImpl::_SerialPortImpl(ISerialPortEventListener& listener)
: __pIpcClient(null)
_SerialPortImpl::_SerialPortImpl(ISerialPortEventListener& listener)
: __pIpcClient(null)
- , __pEventListener(null)
{
result r = E_SUCCESS;
ArrayList request;
{
result r = E_SUCCESS;
ArrayList request;
SysTryReturnVoidResult(NID_IO, __pIpcClient != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
r = __pIpcClient->Construct(COMMUNICATION_DISPATCHER_IPC_ID, this);
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturnVoidResult(NID_IO, __pIpcClient != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
r = __pIpcClient->Construct(COMMUNICATION_DISPATCHER_IPC_ID, this);
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
- __pEventListener = &listener;
+
+ __pEvent = new (std::nothrow) _SerialPortEvent();
+ SysTryReturnVoidResult(NID_IO, __pEvent != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+ __pEvent->AddListener(listener);
r = request.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = request.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
- r = request.Add(ACCESSORY_MANAGER_SERVICE_ID);
+ r = request.Add(String(ACCESSORY_MANAGER_SERVICE_ID));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
- r = request.Add(SERIAL_COMMAND_OPEN);
+ r = request.Add(String(SERIAL_COMMAND_OPEN));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = response.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = response.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = request.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = request.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
- r = request.Add(ACCESSORY_MANAGER_SERVICE_ID);
+ r = request.Add(String(ACCESSORY_MANAGER_SERVICE_ID));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
- r = request.Add(SERIAL_COMMAND_CLOSE);
+ r = request.Add(String(SERIAL_COMMAND_CLOSE));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = response.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = response.Construct();
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = __pIpcClient->SendRequest(pMsg.get());
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
r = __pIpcClient->SendRequest(pMsg.get());
SysTryReturnVoidResult(NID_IO, r == E_SUCCESS, r, "[%s] Propagated.", GetErrorMessage(r));
SetLastResult(E_SUCCESS);
}
SetLastResult(E_SUCCESS);
}
r = request.Construct();
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
r = request.Construct();
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
- r = request.Add(ACCESSORY_MANAGER_SERVICE_ID);
+ r = request.Add(String(ACCESSORY_MANAGER_SERVICE_ID));
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
- r = request.Add(SERIAL_COMMAND_WRITE);
+ r = request.Add(String(SERIAL_COMMAND_WRITE));
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
r = request.Add(*pByteBuffer);
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
r = request.Add(*pByteBuffer);
SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
if (pCommand->Equals(SERIAL_COMMAND_DATA, true))
{
if (pCommand->Equals(SERIAL_COMMAND_DATA, true))
{
- if (__pEventListener != null)
+ pBuffer = (ByteBuffer*)data.GetAt(SERIAL_DATA_BODY);
+ if (pBuffer != null)
- pBuffer = (ByteBuffer*)data.GetAt(SERIAL_DATA_BODY);
- __pEventListener->OnSerialPortDataReceivedN(*pBuffer);
+ _SerialPortEventArg* pEventArg= new (std::nothrow) _SerialPortEventArg(pBuffer);
+ if(pEventArg != null)
+ {
+ SysLog(NID_IO, "_SerialPortImpl::OnDataReceived Event Fire");
+ __pEvent->Fire(*pEventArg);
+ }
}
}
else if (pCommand->Equals(SERIAL_COMMAND_ERROR, true))
{
}
}
else if (pCommand->Equals(SERIAL_COMMAND_ERROR, true))
{
- if (__pEventListener != null)
- {
- __pEventListener->OnSerialPortErrorOccured(E_SYSTEM);
- }
+ _SerialPortEventArg* pEventArg= new (std::nothrow) _SerialPortEventArg(pBuffer);
+ if(pEventArg != null)
+ {
+ SysLog(NID_IO, "_SerialPortImpl::OnDataReceived Event Fire");
+ __pEvent->Fire(*pEventArg);
+ }
#ifndef _FIO_INTERNAL_SERIALPORT_IMPL_H_
#define _FIO_INTERNAL_SERIALPORT_IMPL_H_
#ifndef _FIO_INTERNAL_SERIALPORT_IMPL_H_
#define _FIO_INTERNAL_SERIALPORT_IMPL_H_
+#include <FBaseRtEvent.h>
#include <FIo.h>
#include <FIoISerialPortEventListener.h>
#include <FIo_IIpcClientEventListener.h>
#include <FIo.h>
#include <FIoISerialPortEventListener.h>
#include <FIo_IIpcClientEventListener.h>
private:
_IpcClient* __pIpcClient;
private:
_IpcClient* __pIpcClient;
- ISerialPortEventListener* __pEventListener;
+ Tizen::Base::Runtime::Event* __pEvent;
_SerialPortImpl(_SerialPortImpl& serialPortImpl);
_SerialPortImpl(_SerialPortImpl& serialPortImpl);
#include <FBaseObject.h>
#include <FBaseColHashMap.h>
#include <FOspConfig.h>
#include <FBaseObject.h>
#include <FBaseColHashMap.h>
#include <FOspConfig.h>
+#include <FBaseRtEvent.h>
namespace Tizen { namespace Base
{
namespace Tizen { namespace Base
{
static gboolean OnFileEventOccured(GIOChannel* source, GIOCondition condition, gpointer data);
Tizen::Base::Collection::HashMap* __pMonitorFileList;
static gboolean OnFileEventOccured(GIOChannel* source, GIOCondition condition, gpointer data);
Tizen::Base::Collection::HashMap* __pMonitorFileList;
- IFileEventListener* __pFileEventListener;
+ Tizen::Base::Runtime::Event* __pEvent;
int __inotifyFd;
GSource* __pGSource;
GIOChannel* __pGIOChannel;
int __inotifyFd;
GSource* __pGSource;
GIOChannel* __pGIOChannel;