2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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 */
26 #include "ClientIPC.h"
27 #include "DispatcherMsg.h"
29 namespace smartcard_service_api
31 ClientIPC::ClientIPC():IPCHelper()
35 ClientIPC::~ClientIPC()
39 ClientIPC &ClientIPC::getInstance()
41 static ClientIPC clientIPC;
46 int ClientIPC::handleIOErrorCondition(void *channel, GIOCondition condition)
50 /* finalize context */
53 g_source_remove(watchId);
57 if (ioChannel != NULL)
59 g_io_channel_unref(ioChannel);
65 shutdown(ipcSocket, SHUT_RDWR);
71 /* push disconnect message */
72 DispatcherMsg *dispMsg = new DispatcherMsg();
74 dispMsg->message = Message::MSG_OPERATION_RELEASE_CLIENT;
77 if (dispatcher != NULL)
78 dispatcher->pushMessage(dispMsg);
85 int ClientIPC::handleInvalidSocketCondition(void *channel, GIOCondition condition)
89 /* finalize context */
96 int ClientIPC::handleIncomingCondition(void *channel, GIOCondition condition)
102 if (channel == ioChannel)
106 SCARD_DEBUG("message from server to client socket");
109 msg = retrieveMessage();
112 DispatcherMsg *dispMsg = new DispatcherMsg(msg);
114 /* set peer socket */
115 dispMsg->setPeerSocket(ipcSocket);
117 /* push to dispatcher */
118 if (dispatcher != NULL)
119 dispatcher->pushMessage(dispMsg);
125 /* clear client connection */
132 SCARD_DEBUG_ERR("Unknown channel event [%p]", channel);
140 } /* namespace open_mobile_api */