2 * Copyright (c) 2000 - 2013 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 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 : smackLabel(smackLabel)
64 , interfaceID(interfaceID)
65 , serviceHandlerPath(path)
66 , useSendMsg(useSendMsg)
69 SmackLabel smackLabel; // Smack label for socket
70 InterfaceID interfaceID; // All data from serviceHandlerPath will be marked with this interfaceHandler
71 ServiceHandlerPath serviceHandlerPath; // Path to file
75 typedef std::vector<ServiceDescription> ServiceDescriptionVector;
77 struct AcceptEvent : public GenericEvent {
78 ConnectionID connectionID;
79 InterfaceID interfaceID;
82 struct WriteEvent : public GenericEvent {
83 ConnectionID connectionID;
88 struct ReadEvent : public GenericEvent {
89 ConnectionID connectionID;
93 struct CloseEvent : public GenericEvent {
94 ConnectionID connectionID;
97 virtual void SetSocketManager(GenericSocketManager *manager) {
98 m_serviceManager = manager;
101 virtual ServiceDescriptionVector GetServiceDescription() = 0;
102 virtual void Event(const AcceptEvent &event) = 0;
103 virtual void Event(const WriteEvent &event) = 0;
104 virtual void Event(const ReadEvent &event) = 0;
105 virtual void Event(const CloseEvent &event) = 0;
107 GenericSocketService() : m_serviceManager(NULL) {}
108 virtual ~GenericSocketService(){}
110 GenericSocketManager *m_serviceManager;
118 SendMsgData(int resultCode, int fileDesc, int flags = 0);
119 SendMsgData(const SendMsgData &second);
120 SendMsgData& operator=(const SendMsgData &second);
121 virtual ~SendMsgData();
132 struct GenericSocketManager {
133 virtual void MainLoop() = 0;
134 virtual void RegisterSocketService(GenericSocketService *ptr) = 0;
135 virtual void Close(ConnectionID connectionID) = 0;
136 virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer) = 0;
137 virtual void Write(ConnectionID connectionID, const SendMsgData &sendMsgData) = 0;
138 virtual ~GenericSocketManager(){}
141 } // namespace SecurityManager
143 #endif // _SECURITY_MANAGER_GENERIC_SERVICE_MANAGER_