2 * Copyright (c) 2014-2021 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
54 struct GenericSocketManager;
56 struct GenericSocketService {
57 typedef std::string ServiceHandlerPath;
58 struct ServiceDescription {
59 ServiceDescription(const char *path,
60 const char *privilege,
61 InterfaceID interfaceID = 0,
62 bool useSendMsg = false) :
64 interfaceID(interfaceID),
65 serviceHandlerPath(path),
66 useSendMsg(useSendMsg) {}
68 std::string privilege;
70 // All data from serviceHandlerPath will be marked with this interfaceHandler
71 InterfaceID interfaceID;
74 ServiceHandlerPath serviceHandlerPath;
78 typedef std::vector<ServiceDescription> ServiceDescriptionVector;
80 struct AcceptEvent : public GenericEvent {
81 ConnectionID connectionID;
82 InterfaceID interfaceID;
83 Credentials credentials;
86 struct WriteEvent : public GenericEvent {
87 ConnectionID connectionID;
92 struct ReadEvent : public GenericEvent {
93 ConnectionID connectionID;
97 struct CloseEvent : public GenericEvent {
98 ConnectionID connectionID;
101 struct SecurityEvent : public GenericEvent {
102 ConnectionID connectionID;
106 virtual void SetSocketManager(GenericSocketManager *manager)
108 m_serviceManager = manager;
111 virtual void SetCommManager(CommMgr *manager)
116 virtual ServiceDescriptionVector GetServiceDescription() = 0;
117 virtual void Event(const AcceptEvent &event) = 0;
118 virtual void Event(const WriteEvent &event) = 0;
119 virtual void Event(const ReadEvent &event) = 0;
120 virtual void Event(const CloseEvent &event) = 0;
121 virtual void Event(const SecurityEvent &event) = 0;
123 virtual void Start() = 0;
124 virtual void Stop() = 0;
126 GenericSocketService() : m_serviceManager(NULL), m_commMgr(NULL) {}
127 virtual ~GenericSocketService() {}
130 GenericSocketManager *m_serviceManager;
134 struct GenericSocketManager {
135 virtual void MainLoop() = 0;
136 virtual void MainLoopStop() = 0;
137 virtual void RegisterSocketService(GenericSocketService *ptr) = 0;
138 virtual void CynaraSocket(int oldFd, int newFd, bool isRW) = 0;
139 virtual void Close(ConnectionID connectionID) = 0;
140 virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer) = 0;
141 virtual void SecurityCheck(ConnectionID connectionID) = 0;
142 virtual ~GenericSocketManager() {}
147 #endif // _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_