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);
119 SCARD_DEBUG_ERR("ERROR: Can't make dbus proxy");
124 SCARD_DEBUG_ERR("ERROR: Can't get on system bus [%s]", error->message);
132 bool ClientIPC::sendMessage(Message *msg)
140 #ifdef SECURITY_SERVER
141 stream = cookie + msg->serialize();
143 stream = msg->serialize();
145 length = stream.getLength();
147 SCARD_DEBUG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
148 ipcSocket, msg->message, stream.getLength());
150 return IPCHelper::sendMessage(ipcSocket, stream);
153 int ClientIPC::handleIOErrorCondition(void *channel, GIOCondition condition)
157 if (dispatcher != NULL)
159 DispatcherMsg dispMsg;
161 /* push or process disconnect message */
162 dispMsg.message = Message::MSG_OPERATION_RELEASE_CLIENT;
165 #ifdef CLIENT_IPC_THREAD
166 dispatcher->processMessage(&dispMsg);
168 dispatcher->pushMessage(&dispMsg);
177 int ClientIPC::handleInvalidSocketCondition(void *channel, GIOCondition condition)
181 /* finalize context */
182 destroyConnectSocket();
189 int ClientIPC::handleIncomingCondition(void *channel, GIOCondition condition)
195 #ifndef CLIENT_IPC_THREAD
196 if (channel == ioChannel)
201 SCARD_DEBUG("message from server to client socket");
204 msg = retrieveMessage();
207 DispatcherMsg dispMsg(msg);
209 /* set peer socket */
210 dispMsg.setPeerSocket(ipcSocket);
212 /* push to dispatcher */
213 if (dispatcher != NULL)
215 #ifdef CLIENT_IPC_THREAD
216 dispatcher->processMessage(&dispMsg);
218 dispatcher->pushMessage(&dispMsg);
226 /* clear client connection */
227 #ifdef CLIENT_IPC_THREAD
228 handleIOErrorCondition(channel, condition);
233 #ifndef CLIENT_IPC_THREAD
237 SCARD_DEBUG_ERR("Unknown channel event [%p]", channel);
246 } /* namespace open_mobile_api */