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.
17 /* standard library header */
18 #include <sys/socket.h>
21 /* SLP library header */
22 #ifdef SECURITY_SERVER
23 #include "security-server.h"
28 #include "ClientIPC.h"
29 #include "DispatcherMsg.h"
31 namespace smartcard_service_api
33 ClientIPC::ClientIPC():IPCHelper()
38 #ifdef SECURITY_SERVER
41 if ((length = security_server_get_cookie_size()) > 0)
43 uint8_t *buffer = NULL;
45 buffer = new uint8_t[length];
50 if ((error = security_server_request_cookie(buffer, length))
51 == SECURITY_SERVER_API_SUCCESS)
53 cookie.setBuffer(buffer, length);
55 SCARD_DEBUG("cookie : %s", cookie.toString());
59 SCARD_DEBUG_ERR("security_server_request_cookie failed [%d]", error);
67 SCARD_DEBUG_ERR("security_server_get_cookie_size failed");
72 ClientIPC::~ClientIPC()
76 ClientIPC &ClientIPC::getInstance()
78 static ClientIPC clientIPC;
84 void ClientIPC::_launch_daemon()
86 DBusGConnection *connection;
95 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
100 proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.smartcard_service",
101 "/org/tizen/smartcard_service", "org.tizen.smartcard_service");
106 if (dbus_g_proxy_call(proxy, "launch", &error, G_TYPE_INVALID,
107 G_TYPE_INT, &result, G_TYPE_INVALID) == false)
109 SCARD_DEBUG_ERR("org_tizen_smartcard_service_launch failed");
112 SCARD_DEBUG_ERR("message : [%s]", error->message);
117 g_object_unref(proxy);
121 SCARD_DEBUG_ERR("ERROR: Can't make dbus proxy");
126 SCARD_DEBUG_ERR("ERROR: Can't get on system bus [%s]", error->message);
134 bool ClientIPC::sendMessage(Message *msg)
142 #ifdef SECURITY_SERVER
143 stream = cookie + msg->serialize();
145 stream = msg->serialize();
147 length = stream.getLength();
149 SCARD_DEBUG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
150 ipcSocket, msg->message, stream.getLength());
152 return IPCHelper::sendMessage(ipcSocket, stream);
155 int ClientIPC::handleIOErrorCondition(void *channel, GIOCondition condition)
159 if (dispatcher != NULL)
161 DispatcherMsg dispMsg;
163 /* push or process disconnect message */
164 dispMsg.message = Message::MSG_OPERATION_RELEASE_CLIENT;
167 #ifdef CLIENT_IPC_THREAD
168 dispatcher->processMessage(&dispMsg);
170 dispatcher->pushMessage(&dispMsg);
179 int ClientIPC::handleInvalidSocketCondition(void *channel, GIOCondition condition)
183 /* finalize context */
184 destroyConnectSocket();
191 int ClientIPC::handleIncomingCondition(void *channel, GIOCondition condition)
197 #ifndef CLIENT_IPC_THREAD
198 if (channel == ioChannel)
203 SCARD_DEBUG("message from server to client socket");
206 msg = retrieveMessage();
209 DispatcherMsg dispMsg(msg);
211 /* set peer socket */
212 dispMsg.setPeerSocket(ipcSocket);
214 /* push to dispatcher */
215 if (dispatcher != NULL)
217 #ifdef CLIENT_IPC_THREAD
218 dispatcher->processMessage(&dispMsg);
220 dispatcher->pushMessage(&dispMsg);
228 /* clear client connection */
229 #ifdef CLIENT_IPC_THREAD
230 handleIOErrorCondition(channel, condition);
235 #ifndef CLIENT_IPC_THREAD
239 SCARD_DEBUG_ERR("Unknown channel event [%p]", channel);
248 } /* namespace open_mobile_api */