2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bumjin Im <bj.im@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)
21 * @author Zofia Abramowska (z.abramowska@samsung.com)
23 * @brief SocketManager implementation.
26 #ifndef _CENT_KEY_MNG_SOCKET_MANAGER_
27 #define _CENT_KEY_MNG_SOCKET_MANAGER_
35 #include <dpl/exception.h>
37 #include <generic-socket-manager.h>
41 class SocketManager : public GenericSocketManager {
45 DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
46 DECLARE_EXCEPTION_TYPE(Base, InitFailed)
49 virtual ~SocketManager();
50 virtual void MainLoop();
51 virtual void MainLoopStop();
53 virtual void RegisterSocketService(GenericSocketService *service);
54 virtual void Close(ConnectionID connectionID);
55 virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer);
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 {
79 InterfaceID interfaceID;
80 GenericSocketService *service;
94 SocketDescription& CreateDefaultReadSocketDescription(int sock, bool timeout);
96 typedef std::vector<SocketDescription> SocketDescriptionVector;
99 ConnectionID connectionID;
106 bool operator<(const Timeout &second) const {
107 return time > second.time; // mininum first!
111 SocketDescriptionVector m_socketDescriptionVector;
116 std::mutex m_eventQueueMutex;
117 std::queue<WriteBuffer> m_writeBufferQueue;
118 std::queue<ConnectionID> m_closeQueue;
121 std::priority_queue<Timeout> m_timeoutQueue;
126 #endif // _CENT_KEY_MNG_SOCKET_MANAGER_