2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 /* standard library header */
19 #include <sys/socket.h>
22 /* SLP library header */
23 #ifdef SECURITY_SERVER
24 #include "security-server.h"
29 #include "ClientIPC.h"
30 #include "DispatcherMsg.h"
32 namespace smartcard_service_api
34 ClientIPC::ClientIPC() : IPCHelper()
39 #ifdef SECURITY_SERVER
42 if ((length = security_server_get_cookie_size()) > 0)
44 uint8_t *buffer = NULL;
46 buffer = new uint8_t[length];
51 if ((error = security_server_request_cookie(buffer, length))
52 == SECURITY_SERVER_API_SUCCESS)
54 cookie.assign(buffer, length);
56 _DBG("cookie : %s", cookie.toString().c_str());
60 _ERR("security_server_request_cookie failed [%d]", error);
68 _ERR("security_server_get_cookie_size failed");
73 ClientIPC::~ClientIPC()
77 ClientIPC &ClientIPC::getInstance()
79 static ClientIPC clientIPC;
85 void ClientIPC::_launch_daemon()
87 DBusGConnection *connection;
96 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
101 proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.smartcard_service",
102 "/org/tizen/smartcard_service", "org.tizen.smartcard_service");
107 if (dbus_g_proxy_call(proxy, "launch", &error, G_TYPE_INVALID,
108 G_TYPE_INT, &result, G_TYPE_INVALID) == false)
110 _ERR("org_tizen_smartcard_service_launch failed");
113 _ERR("message : [%s]", error->message);
120 _ERR("ERROR: Can't make dbus proxy");
125 _ERR("ERROR: Can't get on system bus [%s]", error->message);
133 bool ClientIPC::sendMessage(const Message &msg)
141 #ifdef SECURITY_SERVER
142 stream = cookie + msg.serialize();
144 stream = msg.serialize();
146 length = stream.size();
148 _DBG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
149 ipcSocket, msg.message, stream.size());
151 return IPCHelper::sendMessage(ipcSocket, stream);
154 int ClientIPC::handleIOErrorCondition(void *channel, GIOCondition condition)
158 if (dispatcher != NULL)
160 DispatcherMsg dispMsg;
162 /* push or process disconnect message */
163 dispMsg.message = Message::MSG_OPERATION_RELEASE_CLIENT;
166 #ifdef CLIENT_IPC_THREAD
167 dispatcher->processMessage(&dispMsg);
169 dispatcher->pushMessage(&dispMsg);
178 int ClientIPC::handleInvalidSocketCondition(void *channel, GIOCondition condition)
182 /* finalize context */
183 destroyConnectSocket();
190 int ClientIPC::handleIncomingCondition(void *channel, GIOCondition condition)
196 #ifndef CLIENT_IPC_THREAD
197 if (channel == ioChannel)
202 _DBG("message from server to client socket");
205 msg = retrieveMessage();
208 DispatcherMsg dispMsg(*msg);
210 /* set peer socket */
211 dispMsg.setPeerSocket(ipcSocket);
213 /* push to dispatcher */
214 if (dispatcher != NULL)
216 #ifdef CLIENT_IPC_THREAD
217 dispatcher->processMessage(&dispMsg);
219 dispatcher->pushMessage(&dispMsg);
227 /* clear client connection */
228 #ifdef CLIENT_IPC_THREAD
229 handleIOErrorCondition(channel, condition);
234 #ifndef CLIENT_IPC_THREAD
238 _ERR("Unknown channel event [%p]", channel);
246 } /* namespace open_mobile_api */
247 #endif /* USE_GDBUS */