2 * Copyright (c) 2000-2019 Samsung Electronics Co., Ltd. All rights reserved
4 * Contact: Dongsun Lee <ds73.lee@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 generic-socket-manager.h
20 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21 * @author Zofia Abramowska (z.abramowska@samsung.com)
23 * @brief Implementation of GenericSocketService and GenericSocketManager.
26 #ifndef _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_
27 #define _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_
32 #include <sys/types.h>
34 #include <dpl/exception.h>
35 #include <generic-event.h>
36 #include <dpl/raw-buffer.h>
37 #include <ckm/ckm-type.h>
38 #include <credentials.h>
39 #include <service-messages.h>
47 typedef int InterfaceID;
50 int sock; // This is decriptor used for connection
51 int counter; // Unique handler per socket
52 inline bool operator<(const ConnectionID &second) const
54 return counter < second.counter;
58 struct GenericSocketManager;
60 struct GenericSocketService {
61 typedef std::string ServiceHandlerPath;
62 struct ServiceDescription {
63 ServiceDescription(const char *path,
64 const char *privilege,
65 InterfaceID interfaceID = 0,
66 bool useSendMsg = false) :
68 interfaceID(interfaceID),
69 serviceHandlerPath(path),
70 useSendMsg(useSendMsg) {}
72 std::string privilege;
74 // All data from serviceHandlerPath will be marked with this interfaceHandler
75 InterfaceID interfaceID;
78 ServiceHandlerPath serviceHandlerPath;
82 typedef std::vector<ServiceDescription> ServiceDescriptionVector;
84 struct AcceptEvent : public GenericEvent {
85 ConnectionID connectionID;
86 InterfaceID interfaceID;
87 Credentials credentials;
90 struct WriteEvent : public GenericEvent {
91 ConnectionID connectionID;
96 struct ReadEvent : public GenericEvent {
97 ConnectionID connectionID;
101 struct CloseEvent : public GenericEvent {
102 ConnectionID connectionID;
105 struct SecurityEvent : public GenericEvent {
106 ConnectionID connectionID;
110 virtual void SetSocketManager(GenericSocketManager *manager)
112 m_serviceManager = manager;
115 virtual void SetCommManager(CommMgr *manager)
120 virtual ServiceDescriptionVector GetServiceDescription() = 0;
121 virtual void Event(const AcceptEvent &event) = 0;
122 virtual void Event(const WriteEvent &event) = 0;
123 virtual void Event(const ReadEvent &event) = 0;
124 virtual void Event(const CloseEvent &event) = 0;
125 virtual void Event(const SecurityEvent &event) = 0;
127 virtual void Start() = 0;
128 virtual void Stop() = 0;
130 GenericSocketService() : m_serviceManager(NULL), m_commMgr(NULL) {}
131 virtual ~GenericSocketService() {}
134 GenericSocketManager *m_serviceManager;
138 struct GenericSocketManager {
139 virtual void MainLoop() = 0;
140 virtual void MainLoopStop() = 0;
141 virtual void RegisterSocketService(GenericSocketService *ptr) = 0;
142 virtual void CynaraSocket(int oldFd, int newFd, bool isRW) = 0;
143 virtual void Close(ConnectionID connectionID) = 0;
144 virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer) = 0;
145 virtual void SecurityCheck(ConnectionID connectionID) = 0;
146 virtual ~GenericSocketManager() {}
151 #endif // _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_