2 * Copyright (c) 2013 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.
17 #ifndef _SOCKETSERVICE_H_
18 #define _SOCKETSERVICE_H_
26 #include "SocketConnection.h"
28 typedef void(*socketServiceCallback)(SocketConnection* pConnector);
32 struct ConnectionInfo{
33 ConnectionInfo(int fd, void* pData) : connFd(fd), pData(pData) {}
40 ServiceCallback(socketServiceCallback callback)
41 : serviceCallback(callback)
43 socketServiceCallback serviceCallback;
47 static const int MAX_LISTEN;
48 static const int TIMEOUT_SEC;
49 static const int TIMEOUT_NSEC;
52 pthread_t m_mainThread;
54 typedef std::shared_ptr<ServiceCallback> ServiceCallbackPtr;
55 //Map for callback methods, key is a method name and value is a callback to method
56 typedef std::map<std::string, ServiceCallbackPtr> ServiceMethodCallbackMap;
57 //Map for interface methods, key is an interface name and value is a map of available methods with callbacks
58 std::map <std::string, ServiceMethodCallbackMap > m_callbackMap;
60 std::list < int > m_clientSocketList;
61 std::mutex m_clientSocketListMutex;
64 static void* serverThread(void* );
65 static void* connectionThread(void* pData);
66 int connectionService(int fd);
68 void closeConnections(void);
70 void addClientSocket(int clientSocket);
71 void removeClientSocket(int clientSocket);
72 bool popClientSocket(int* pClientSocket);
78 int registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod);
84 #endif //_SOCKETSERVICE_H_