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.
17 * @file security_socket_service.h
18 * @author Zofia Abramowska (z.abramowska@samsung.com)
20 * @brief Header of socket server class
23 #ifndef SECURITY_SOCKET_SERVICE_H_
24 #define SECURITY_SOCKET_SERVICE_H_
31 #include <security_daemon.h>
32 #include <SocketConnection.h>
33 #include <callback_api.h>
35 class SecuritySocketService : public SecurityDaemon::DaemonService {
39 virtual void initialize();
42 virtual void deinitialize();
47 //Function for registering callback with given interface and method name and possibly security check callback
48 void registerServiceCallback(const std::string& interfaceName,
49 const std::string& methodName,
50 socketServerCallback serviceCallback,
51 securityCheck securityCallback = NULL);
52 //Thread function for server
53 static void * serverThread(void *);
54 //Main function for server
56 //Thread function for connection serving
57 static void * connectionThread(void *);
58 //Main function for connection serving
59 void connectionService(int fd);
60 //closing all connections
61 void closeConnections();
62 //logs an error and throws an exception with message containing errno message
63 void throwWithErrnoMessage(const std::string &specificInfo);
65 //concurrency safe methods for client socket list - add, remove and pop (with returned value)
66 void addClientSocket(int clientThread);
67 void removeClientSocket(int clientThread);
68 bool popClientSocket(int* clientThread);
70 //Address of socket server
71 std::string m_serverAddress;
72 //Signal used for informing threads to stop
74 //Socket for listening
76 //Number of main thread
77 pthread_t m_mainThread;
78 //Numbers of all created threads for connections
79 std::list<int> m_clientSocketList;
82 std::mutex m_clientSocketListMutex;
84 //Structure for callback maps
88 ServiceCallback(socketServerCallback ser, securityCheck sec) : serviceCallback(ser), securityCallback(sec){}
89 socketServerCallback serviceCallback;
90 securityCheck securityCallback;
93 typedef std::shared_ptr<ServiceCallback> ServiceCallbackPtr;
94 //Map for callback methods, key is a method name and value is a callback to method
95 typedef std::map<std::string, ServiceCallbackPtr> ServiceMethodCallbackMap;
96 //Map for interface methods, key is an interface name and value is a map of available methods with callbacks
97 std::map<std::string, ServiceMethodCallbackMap> m_callbackMap;
99 //Structure passed to connection thread
100 struct Connection_Info{
101 Connection_Info(int fd, void * data) : connfd(fd), data(data)
109 #endif /* SECURITY_SOCKET_SERVICE_H_ */