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 generic-socket-manager.h
20 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 * @brief Implementation of GenericSocketService and GenericSocketManager.
25 #ifndef _SECURITY_MANAGER_GENERIC_SERVICE_MANAGER_
26 #define _SECURITY_MANAGER_GENERIC_SERVICE_MANAGER_
31 #include <dpl/exception.h>
33 #include <generic-event.h>
39 namespace SecurityManager {
41 typedef int InterfaceID;
44 int sock; // This is decriptor used for connection
45 int counter; // Unique handler per socket
46 inline bool operator<(const ConnectionID &second) const {
47 return counter < second.counter;
51 typedef std::vector<unsigned char> RawBuffer;
53 struct GenericSocketManager;
55 struct GenericSocketService {
56 typedef std::string SmackLabel;
57 typedef std::string ServiceHandlerPath;
58 struct ServiceDescription {
59 ServiceDescription(const char *path,
60 const char *smackLabel,
61 InterfaceID interfaceID = 0,
62 bool useSendMsg = false,
63 bool systemdOnly = false)
64 : smackLabel(smackLabel)
65 , interfaceID(interfaceID)
66 , serviceHandlerPath(path)
67 , useSendMsg(useSendMsg)
68 , systemdOnly(systemdOnly)
71 SmackLabel smackLabel; // Smack label for socket
72 InterfaceID interfaceID; // All data from serviceHandlerPath will be marked with this interfaceHandler
73 ServiceHandlerPath serviceHandlerPath; // Path to file
78 typedef std::vector<ServiceDescription> ServiceDescriptionVector;
80 struct AcceptEvent : public GenericEvent {
81 ConnectionID connectionID;
82 InterfaceID interfaceID;
85 struct WriteEvent : public GenericEvent {
86 ConnectionID connectionID;
91 struct ReadEvent : public GenericEvent {
92 ConnectionID connectionID;
96 struct CloseEvent : public GenericEvent {
97 ConnectionID connectionID;
100 virtual void SetSocketManager(GenericSocketManager *manager) {
101 m_serviceManager = manager;
104 virtual ServiceDescriptionVector GetServiceDescription() = 0;
105 virtual void Event(const AcceptEvent &event) = 0;
106 virtual void Event(const WriteEvent &event) = 0;
107 virtual void Event(const ReadEvent &event) = 0;
108 virtual void Event(const CloseEvent &event) = 0;
110 GenericSocketService() : m_serviceManager(NULL) {}
111 virtual ~GenericSocketService(){}
113 GenericSocketManager *m_serviceManager;
121 SendMsgData(int resultCode, int fileDesc, int flags = 0);
122 SendMsgData(const SendMsgData &second);
123 SendMsgData& operator=(const SendMsgData &second);
124 virtual ~SendMsgData();
135 struct GenericSocketManager {
136 virtual void MainLoop() = 0;
137 virtual void RegisterSocketService(GenericSocketService *ptr) = 0;
138 virtual void Close(ConnectionID connectionID) = 0;
139 virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer) = 0;
140 virtual void Write(ConnectionID connectionID, const SendMsgData &sendMsgData) = 0;
141 virtual ~GenericSocketManager(){}
144 } // namespace SecurityManager
146 #endif // _SECURITY_MANAGER_GENERIC_SERVICE_MANAGER_