Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
IpcCommon.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2020 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 /*
20  * IpcCommon.h
21  *
22  * Created on: 5 Jun 2015
23  * Author: riyadh
24  */
25 
26 #ifndef AI_IPC_IPCCOMMON_H
27 #define AI_IPC_IPCCOMMON_H
28 
29 #include "IpcVariantList.h"
30 
31 #include <sys/types.h>
32 
33 #include <string>
34 #include <map>
35 #include <vector>
36 #include <functional>
37 #include <memory>
38 
39 namespace AI_IPC
40 {
41 
51 {
52  enum Type
53  {
54  METHOD,
55  SIGNAL
56  };
57 
58  Type type;
59  std::string service;
60  std::string object;
61  std::string interface;
62  std::string name;
63 
64  bool isValid() const
65  {
66  if (object.empty() || interface.empty() || name.empty())
67  return false;
68  if ((type == METHOD) && service.empty())
69  return false;
70  return true;
71  }
72 
73  operator bool() const
74  {
75  return isValid();
76  }
77 
78 protected:
79  RemoteEntry(Type type_)
80  : type(type_) {}
81 
82  RemoteEntry(Type type_, const std::string& service_, const std::string& object_, const std::string& interface_, const std::string& name_)
83  : type(type_), service(service_), object(object_), interface(interface_), name(name_) {}
84 };
85 
89 struct Method : public RemoteEntry
90 {
91  Method()
92  : RemoteEntry(METHOD) {}
93 
94  Method(const std::string& service_, const std::string& object_, const std::string& interface_, const std::string& name_)
95  : RemoteEntry(METHOD, service_, object_, interface_, name_) {}
96 
97 };
98 
104 struct Signal : public RemoteEntry
105 {
106  Signal()
107  : RemoteEntry(SIGNAL) {}
108 
109  Signal(const std::string& object_, const std::string& interface_, const std::string& name_)
110  : RemoteEntry(SIGNAL, std::string(), object_, interface_, name_) {}
111 };
112 
117 {
118 public:
119  virtual ~IAsyncReplySender() = default;
120 
124  virtual VariantList getMethodCallArguments() const = 0;
125 
134  virtual bool sendReply(const VariantList& replyArgs) = 0;
135 
139  virtual uid_t getSenderUid() const = 0;
140 
144  virtual std::string getSenderName() const = 0;
145 };
146 
151 {
152 public:
153  virtual ~IAsyncReplyGetter() = default;
154 
163  virtual bool getReply(VariantList& argList) = 0;
164 };
165 
169 typedef enum
170 {
171  MethodCallEvent,
172  MethodReturnEvent,
173  SignalEvent,
174  ErrorEvent,
175 } EventType;
176 
180 typedef std::function<void(std::shared_ptr<IAsyncReplySender>)> MethodHandler;
181 
185 typedef std::function<void(const VariantList&)> SignalHandler;
186 
190 typedef std::function<void(EventType,
191  unsigned int,
192  const std::string&,
193  const std::string&,
194  const std::string&,
195  const std::string&,
196  const std::string&,
197  const VariantList&)> MonitorHandler;
198 
199 }
200 
201 #endif /* AI_IPC_IPCCOMMON_H */
Helper class to get reply.
Definition: IpcCommon.h:151
virtual bool getReply(VariantList &argList)=0
Get reply.
Helper class to send reply of a method call asynchronously.
Definition: IpcCommon.h:117
virtual std::string getSenderName() const =0
Gets the unique name of the connection which originated this message.
virtual VariantList getMethodCallArguments() const =0
Get method call arguments.
virtual uid_t getSenderUid() const =0
Get Id of the user (unix user Id) who invoked the method.
virtual bool sendReply(const VariantList &replyArgs)=0
Send reply.
Method identified by a service, object, interface and method name itself.
Definition: IpcCommon.h:90
Remote entry, which can be either a signal or method.
Definition: IpcCommon.h:51
Method identified by object, interface and signal name itself.
Definition: IpcCommon.h:105