Add the check routine of certificate
[platform/framework/native/channel-service.git] / src / FIo_MessagePortStub.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FIo_MessagePortStub.cpp
20  * @brief       This is the implementation file for the  _MessagePortStub class.
21  *
22  */
23
24 #include <message-port-messages.h>
25
26 #include <bundle.h>
27
28 #include <FBaseSysLog.h>
29
30 #include "FIo_MessagePortStub.h"
31 #include "FIo_MessagePortService.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Io;
37 using namespace Tizen::App;
38
39 static void 
40 ConvertBundleToMap(const char *pKey, const int type, const bundle_keyval_t *pVal, void *pData)
41 {
42         SysLog(NID_IO, "CB key = %s", pKey);
43
44 }
45
46 _MessagePortStub::_MessagePortStub(void)
47         : __pIpcServer(null)
48         , __pService(null)
49 {
50
51 }
52
53 _MessagePortStub::~_MessagePortStub(void)
54 {
55         delete __pIpcServer;
56 }
57
58 result
59 _MessagePortStub::Construct(void)
60 {
61         SysAssertf(__pIpcServer == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
62
63         result r = E_SUCCESS;
64         IpcServer* pIpcServer = new (std::nothrow) IpcServer;
65         SysTryReturnResult(NID_IO, pIpcServer != null, E_OUT_OF_MEMORY, "Not enough memory.");
66
67         r = pIpcServer->Construct("message-port-server", *this, false);
68         SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Failed to create IPC server(MessagePort)", GetErrorMessage(r));
69
70         __pIpcServer = pIpcServer;
71
72         return E_SUCCESS;
73
74 CATCH:
75         delete pIpcServer;
76
77         return r;
78 }
79
80 void
81 _MessagePortStub::SetMessagePortService(_MessagePortService& service)
82 {
83         __pService = &service;
84 }
85
86 bool
87 _MessagePortStub::OnRegisterMessagePort(const BundleBuffer& buffer, int* pResult)
88 {
89         SysAssertf(__pService != null, "Message port service has not been initialized.\n");
90
91         int clientId = __pIpcServer->GetClientId();
92
93         *pResult = __pService->RegisterMessagePort(clientId, buffer);
94
95         bundle_free(buffer.b);
96
97         return true;
98 }
99
100 bool
101 _MessagePortStub::OnCheckRemotePort(const BundleBuffer& buffer, int* pResult)
102 {
103         SysAssertf(__pService != null, "Message port service has not been initialized.\n");
104
105         *pResult = __pService->CheckRemotePort(buffer);
106
107         bundle_free(buffer.b);
108
109         return true;
110 }
111
112 bool
113 _MessagePortStub::OnSendMessage(const BundleBuffer& buffer, int* pResult)
114 {
115         SysAssertf(__pService != null, "MessagePort service has not been initialized.\n");
116
117         *pResult = __pService->SendMessage(buffer);
118
119         bundle_free(buffer.b);
120
121         return true;
122 }
123
124 result
125 _MessagePortStub::SendMessage(int clientId, const BundleBuffer& buffer)
126 {
127         SysAssertf(__pService != null, "MessagePort service has not been initialized.\n");
128
129         result r = __pIpcServer->SendResponse(clientId, new MessagePort_sendMessageAsync(buffer));
130
131         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to send a response message.");
132
133         return E_SUCCESS;
134 }
135
136 void
137 _MessagePortStub::OnIpcRequestReceived(IpcServer& server, const IPC::Message& message)
138 {
139         IPC_BEGIN_MESSAGE_MAP(_MessagePortStub, message)
140         IPC_MESSAGE_HANDLER_EX(MessagePort_registerPort, &server, OnRegisterMessagePort)
141         IPC_MESSAGE_HANDLER_EX(MessagePort_checkRemotePort, &server, OnCheckRemotePort)
142         IPC_MESSAGE_HANDLER_EX(MessagePort_sendMessage, &server, OnSendMessage)
143         IPC_END_MESSAGE_MAP_EX()
144 }
145
146 void
147 _MessagePortStub::OnIpcServerStarted(const IpcServer& server)
148 {
149
150 }
151
152 void
153 _MessagePortStub::OnIpcServerStopped(const IpcServer& server)
154 {
155
156 }
157
158 void
159 _MessagePortStub::OnIpcClientConnected(const IpcServer& server, int clientId)
160 {
161         SysLog(NID_IO, "Ipc connected");
162 }
163
164 void
165 _MessagePortStub::OnIpcClientDisconnected(const IpcServer& server, int clientId)
166 {
167         SysAssertf(__pService != null, "Channel service has not been initialized.\n");
168         SysLog(NID_IO, "Unregister - clientId =  %d", clientId);
169
170         __pService->UnregisterMessagePort(clientId);
171 }
172