2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Rafal Krypa <r.krypa@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @file socket-manager.h
20 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 * @brief SocketManager implementation.
25 #ifndef _SECURITY_MANAGER_SOCKET_MANAGER_
26 #define _SECURITY_MANAGER_SOCKET_MANAGER_
34 #include <dpl/exception.h>
36 #include <generic-socket-manager.h>
38 namespace SecurityManager {
40 class SocketManager : public GenericSocketManager {
44 DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
45 DECLARE_EXCEPTION_TYPE(Base, InitFailed)
48 virtual ~SocketManager();
49 virtual void MainLoop();
50 virtual void MainLoopStop();
52 virtual void RegisterSocketService(GenericSocketService *service);
53 virtual void Close(ConnectionID connectionID);
54 virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer);
55 virtual void Write(ConnectionID connectionID, const SendMsgData &sendMsgData);
58 void CreateDomainSocket(
59 GenericSocketService *service,
60 const GenericSocketService::ServiceDescription &desc);
61 int CreateDomainSocketHelp(
62 const GenericSocketService::ServiceDescription &desc);
63 int GetSocketFromSystemD(
64 const GenericSocketService::ServiceDescription &desc);
66 void ReadyForRead(int sock);
67 void ReadyForWrite(int sock);
68 void ReadyForWriteBuffer(int sock);
69 void ReadyForSendMsg(int sock);
70 void ReadyForAccept(int sock);
71 void ProcessQueue(void);
73 void CloseSocket(int sock);
75 struct SocketDescription {
80 InterfaceID interfaceID;
81 GenericSocketService *service;
84 std::queue<SendMsgData> sendMsgDataQueue;
97 SocketDescription& CreateDefaultReadSocketDescription(int sock, bool timeout);
99 typedef std::vector<SocketDescription> SocketDescriptionVector;
102 ConnectionID connectionID;
107 ConnectionID connectionID;
108 SendMsgData sendMsgData;
114 bool operator<(const Timeout &second) const {
115 return time > second.time; // mininum first!
119 SocketDescriptionVector m_socketDescriptionVector;
124 std::mutex m_eventQueueMutex;
125 std::queue<WriteBuffer> m_writeBufferQueue;
126 std::queue<WriteData> m_writeDataQueue;
127 std::queue<ConnectionID> m_closeQueue;
130 std::priority_queue<Timeout> m_timeoutQueue;
133 } // namespace SecurityManager
135 #endif // _SECURITY_MANAGER_SOCKET_MANAGER_