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 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 <dpl/exception.h>
34 #include <generic-event.h>
40 namespace CentralKeyManager {
42 typedef int InterfaceID;
45 int sock; // This is decriptor used for connection
46 int counter; // Unique handler per socket
47 inline bool operator<(const ConnectionID &second) const {
48 return counter < second.counter;
52 typedef std::vector<unsigned char> RawBuffer;
54 struct GenericSocketManager;
56 struct GenericSocketService {
57 typedef std::string SmackLabel;
58 typedef std::string ServiceHandlerPath;
59 struct ServiceDescription {
60 ServiceDescription(const char *path,
61 const char *smackLabel,
62 InterfaceID interfaceID = 0,
63 bool useSendMsg = false)
64 : smackLabel(smackLabel)
65 , interfaceID(interfaceID)
66 , serviceHandlerPath(path)
67 , useSendMsg(useSendMsg)
70 SmackLabel smackLabel; // Smack label for socket
71 InterfaceID interfaceID; // All data from serviceHandlerPath will be marked with this interfaceHandler
72 ServiceHandlerPath serviceHandlerPath; // Path to file
76 typedef std::vector<ServiceDescription> ServiceDescriptionVector;
78 struct AcceptEvent : public GenericEvent {
79 ConnectionID connectionID;
80 InterfaceID interfaceID;
83 struct WriteEvent : public GenericEvent {
84 ConnectionID connectionID;
89 struct ReadEvent : public GenericEvent {
90 ConnectionID connectionID;
94 struct CloseEvent : public GenericEvent {
95 ConnectionID connectionID;
98 virtual void SetSocketManager(GenericSocketManager *manager) {
99 m_serviceManager = manager;
102 virtual ServiceDescriptionVector GetServiceDescription() = 0;
103 virtual void Event(const AcceptEvent &event) = 0;
104 virtual void Event(const WriteEvent &event) = 0;
105 virtual void Event(const ReadEvent &event) = 0;
106 virtual void Event(const CloseEvent &event) = 0;
108 GenericSocketService() : m_serviceManager(NULL) {}
109 virtual ~GenericSocketService(){}
111 GenericSocketManager *m_serviceManager;
114 struct GenericSocketManager {
115 virtual void MainLoop() = 0;
116 virtual void RegisterSocketService(GenericSocketService *ptr) = 0;
117 virtual void Close(ConnectionID connectionID) = 0;
118 virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer) = 0;
119 virtual ~GenericSocketManager(){}
122 } // namespace CentralKeyManager
124 #endif // _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_