merge with master
[platform/framework/native/channel-service.git] / src / FIo_MessagePortStub.cpp
index fa05a40..df95596 100644 (file)
  *
  */
 
+#include <message-port-messages.h>
+
+#include <bundle.h>
+
 #include <FBaseSysLog.h>
-#include <FIo_IpcServer.h>
-#include <FIo_MessagePortMessages.h>
 
 #include "FIo_MessagePortStub.h"
 #include "FIo_MessagePortService.h"
@@ -34,8 +36,12 @@ using namespace Tizen::Base::Runtime;
 using namespace Tizen::Io;
 using namespace Tizen::App;
 
-namespace Tizen { namespace Io
+static void 
+ConvertBundleToMap(const char *pKey, const int type, const bundle_keyval_t *pVal, void *pData)
 {
+       SysLog(NID_IO, "CB key = %s", pKey);
+
+}
 
 _MessagePortStub::_MessagePortStub(void)
        : __pIpcServer(null)
@@ -55,12 +61,10 @@ _MessagePortStub::Construct(void)
        SysAssertf(__pIpcServer == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
 
        result r = E_SUCCESS;
-       _IpcServer* pIpcServer = null;
-
-       pIpcServer = new (std::nothrow) _IpcServer;
+       IpcServer* pIpcServer = new (std::nothrow) IpcServer;
        SysTryReturnResult(NID_IO, pIpcServer != null, E_OUT_OF_MEMORY, "Not enough memory.");
 
-       r = pIpcServer->Construct("osp.io.ipcserver.messageportmanager", *this, false);
+       r = pIpcServer->Construct("message-port-server", *this, false);
        SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Failed to create IPC server(MessagePort)", GetErrorMessage(r));
 
        __pIpcServer = pIpcServer;
@@ -80,153 +84,87 @@ _MessagePortStub::SetMessagePortService(_MessagePortService& service)
 }
 
 bool
-_MessagePortStub::OnRegisterMessagePort(const String& appId, const String& port, bool isTrusted, int* pResult)
+_MessagePortStub::OnRegisterMessagePort(const BundleBuffer& buffer, int* pResult)
 {
        SysAssertf(__pService != null, "Message port service has not been initialized.\n");
 
        int clientId = __pIpcServer->GetClientId();
 
-       SysLog(NID_IO, "Register a message port: [%ls:%ls], client id = %d", appId.GetPointer(), port.GetPointer(), clientId);
+       *pResult = __pService->RegisterMessagePort(clientId, buffer);
 
-       *pResult = __pService->RegisterMessagePort(appId, port, clientId, isTrusted);
+       bundle_free(buffer.b);
 
        return true;
 }
 
 bool
-_MessagePortStub::OnRequestRemotePort(const AppId& remoteAppId, const String& remotePort, bool isTrusted, int* pResult)
+_MessagePortStub::OnCheckRemotePort(const BundleBuffer& buffer, int* pResult)
 {
        SysAssertf(__pService != null, "Message port service has not been initialized.\n");
 
-       int clientId = __pIpcServer->GetClientId();
+       *pResult = __pService->CheckRemotePort(buffer);
 
-       SysLog(NID_IO, "Request a remote message port: [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
-
-       *pResult = __pService->RequestRemotePort(remoteAppId, remotePort, isTrusted);
+       bundle_free(buffer.b);
 
        return true;
 }
 
 bool
-_MessagePortStub::OnSendMessage(const String& dest, const String& destPort,
-                                                               bool isTrusted, const HashMap& map,
-                                                               int* pResult)
+_MessagePortStub::OnSendMessage(const BundleBuffer& buffer, int* pResult)
 {
        SysAssertf(__pService != null, "MessagePort service has not been initialized.\n");
 
-       SysLog(NID_IO, "Message is sent to [%ls:%ls]", dest.GetPointer(), destPort.GetPointer());
-
-       if (!isTrusted)
-       {
-               *pResult = __pService->SendMessage(dest, destPort, false, &map);
-       }
-       else
-       {
-               *pResult = __pService->SendMessage(dest, destPort, true, &map);
-       }
+       *pResult = __pService->SendMessage(buffer);
 
-       const_cast<HashMap*>(&map)->RemoveAll(true);
+       bundle_free(buffer.b);
 
        return true;
 }
 
-bool
-_MessagePortStub::OnSendBidirMessage(const String& src, const String& srcPort, bool isTrusted,
-                                                               const String& dest, const String& destPort,
-                                                               const HashMap& map, int* pResult)
-{
-       SysAssertf(__pService != null, "MessagePort service has not been initialized.\n");
-
-       SysLog(NID_IO, "[%ls:%ls] sends a message to [%ls:%ls]", src.GetPointer(), srcPort.GetPointer(), dest.GetPointer(), destPort.GetPointer());
-
-       *pResult = __pService->SendMessage(src, srcPort, isTrusted, dest, destPort, false, &map);
-
-       const_cast<HashMap*>(&map)->RemoveAll(true);
-
-       return true;
-}
-
-bool
-_MessagePortStub::OnSendTrustedBidirMessage(const String& src, const String& srcPort, bool isTrusted,
-                                                               const String& dest, const String& destPort,
-                                                               const HashMap& map, int* pResult)
-{
-       SysAssertf(__pService != null, "MessagePort service has not been initialized.\n");
-
-       SysLog(NID_IO, "[%ls:%ls] sends a message to [%ls:%ls]", src.GetPointer(), srcPort.GetPointer(), dest.GetPointer(), destPort.GetPointer());
-
-       *pResult = __pService->SendMessage(src, srcPort, isTrusted, dest, destPort, true, &map);
-
-       const_cast<HashMap*>(&map)->RemoveAll(true);
-
-       return true;
-}
-
-result
-_MessagePortStub::SendMessage(int clientId, const String& destPort, bool isTrusted, const HashMap* pMap)
-{
-       SysAssertf(__pService != null, "MessagePort service has not been initialized.\n");
-
-       SysLog(NID_IO, "Sends a message to port [%ls]", destPort.GetPointer());
-
-       if (pMap != null)
-       {
-               result r = __pIpcServer->SendResponse(clientId, new MessagePortService_sendMessageAsync(destPort, isTrusted, *pMap));
-               SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to send a response message.");
-       }
-
-       return E_SUCCESS;
-}
-
 result
-_MessagePortStub::SendMessage(int clientId, const String& destPort, bool isTrustedDest, const String& src, const String& srcPort, bool isTrustedSrc, const HashMap* pMap)
+_MessagePortStub::SendMessage(int clientId, const BundleBuffer& buffer)
 {
        SysAssertf(__pService != null, "MessagePort service has not been initialized.\n");
 
-       SysLog(NID_IO, "[%ls:%ls] sends a message to port [%ls]", src.GetPointer(), srcPort.GetPointer(), destPort.GetPointer());
+       result r = __pIpcServer->SendResponse(clientId, new MessagePort_sendMessageAsync(buffer));
 
-       if (pMap != null)
-       {
-               result r = __pIpcServer->SendResponse(clientId, new MessagePortService_sendBidirMessageAsync(destPort, isTrustedDest, src, srcPort, isTrustedSrc, *pMap));
-               SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to send a response message.");
-       }
+       SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to send a response message.");
 
        return E_SUCCESS;
-
 }
 
 void
-_MessagePortStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+_MessagePortStub::OnIpcRequestReceived(IpcServer& server, const IPC::Message& message)
 {
+       SysLog(NID_IO, "Message received, type %d", message.type());
+
        IPC_BEGIN_MESSAGE_MAP(_MessagePortStub, message)
-       IPC_MESSAGE_HANDLER_EX(MessagePortService_register, &server, OnRegisterMessagePort)
-       IPC_MESSAGE_HANDLER_EX(MessagePortService_requestRemotePort, &server, OnRequestRemotePort)
-       IPC_MESSAGE_HANDLER_EX(MessagePortService_sendMessage, &server, OnSendMessage)
-       IPC_MESSAGE_HANDLER_EX(MessagePortService_sendBidirMessage, &server, OnSendBidirMessage)
-       IPC_MESSAGE_HANDLER_EX(MessagePortService_sendTrustedBidirMessage, &server, OnSendTrustedBidirMessage)
+       IPC_MESSAGE_HANDLER_EX(MessagePort_registerPort, &server, OnRegisterMessagePort)
+       IPC_MESSAGE_HANDLER_EX(MessagePort_checkRemotePort, &server, OnCheckRemotePort)
+       IPC_MESSAGE_HANDLER_EX(MessagePort_sendMessage, &server, OnSendMessage)
        IPC_END_MESSAGE_MAP_EX()
 }
 
 void
-_MessagePortStub::OnIpcServerStarted(const _IpcServer& server)
+_MessagePortStub::OnIpcServerStarted(const IpcServer& server)
 {
 
 }
 
 void
-_MessagePortStub::OnIpcServerStopped(const _IpcServer& server)
+_MessagePortStub::OnIpcServerStopped(const IpcServer& server)
 {
 
 }
 
 void
-_MessagePortStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+_MessagePortStub::OnIpcClientConnected(const IpcServer& server, int clientId)
 {
-
+       SysLog(NID_IO, "Ipc connected");
 }
 
 void
-_MessagePortStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
+_MessagePortStub::OnIpcClientDisconnected(const IpcServer& server, int clientId)
 {
        SysAssertf(__pService != null, "Channel service has not been initialized.\n");
        SysLog(NID_IO, "Unregister - clientId =  %d", clientId);
@@ -234,5 +172,3 @@ _MessagePortStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId
        __pService->UnregisterMessagePort(clientId);
 }
 
-} } // Tizen::Io
-