Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
IpcVariantList.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 * IpcVariantList.h
21 *
22 * Created on:
23 * Author:
24 */
25
26#ifndef AI_IPC_IPCVARIANTLIST_H
27#define AI_IPC_IPCVARIANTLIST_H
28
29#include "IpcFileDescriptor.h"
30
31#include <string>
32#include <map>
33#include <vector>
34#include <functional>
35#include <memory>
36
37// The boost variant class has a variable that triggers the -Wshadow
38// gcc warning. However it is benign, therefore we temporary disable
39// the warning here
40#pragma GCC diagnostic push
41#pragma GCC diagnostic ignored "-Wshadow"
42#pragma GCC diagnostic ignored "-Waddress"
43#if __GNUC__ > 5
44#pragma GCC diagnostic ignored "-Wnonnull-compare"
45#endif
46#include <boost/variant.hpp>
47#pragma GCC diagnostic pop
48
49
50namespace AI_IPC
51{
52
56using UnixFd = IpcFileDescriptor;
57
62{
63 bool operator==(const DbusObjectPath& rhs) const { return objectPath == rhs.objectPath; }
64
65 explicit DbusObjectPath(const char* obj) : objectPath(obj) {}
66 explicit DbusObjectPath(const std::string& obj) : objectPath(obj) { }
67 DbusObjectPath(const DbusObjectPath& other) : objectPath(other.objectPath) { }
68
69 std::string objectPath;
70};
71
80typedef boost::variant<uint8_t, // BYTE y(121) Unsigned 8-bit integer
81 bool, // BOOLEAN b(98) Boolean value: 0 is false, 1 is true, any other value allowed by the marshalling format is invalid
82 int16_t, // INT16 n(110) Signed (two's complement) 16-bit integer
83 uint16_t, // UINT16 q(113) Unsigned 16-bit integer
84 int32_t, // INT32 i(105) Signed (two's complement) 32-bit integer
85 uint32_t, // UINT32 u(117) Unsigned 32-bit integer
86 int64_t, // INT64 x(120) Signed (two's complement) 64-bit integer (mnemonic: x and t are the first characters in "sixty" not already used for something more common)
87 uint64_t, // UINT64 t(116) Unsigned 64-bit integer
88 UnixFd, // UNIX_FD h(104) Unsigned 32-bit integer representing an index into an out-of-band array of file descriptors, transferred via some platform-specific mechanism (mnemonic: h for handle)
89 std::string, // STRING s(115) No extra constraints
90 DbusObjectPath // OBJECT_PATH o(111) Must be a syntactically valid object path
91 //double, // DOUBLE d(100) IEEE 754 double-precision floating point
92 > DictDataType;
93
97typedef boost::variant<uint8_t,
98 bool,
99 int16_t,
100 uint16_t,
101 int32_t,
102 uint32_t,
103 int64_t,
104 uint64_t,
105 UnixFd,
106 std::string,
108 std::vector< uint8_t >,
109 std::vector< uint16_t >,
110 std::vector< int32_t >,
111 std::vector< uint32_t >,
112 std::vector< uint64_t >,
113 std::vector< UnixFd >,
114 std::vector< DbusObjectPath >,
115 std::vector< std::string >,
116 std::map<std::string, DictDataType>
117 > Variant;
118
122typedef std::vector<Variant> VariantList;
123
124
125
126// Gubbins required for functional variadic templates, see below
127struct _pass { template<typename ...T> _pass(T...) {} };
128
149template<typename... Ts>
150bool parseVariantList(const AI_IPC::VariantList& returns, Ts *...args)
151{
152 // Check the number of args in the list matches the number of templated args
153 const size_t numArgs = sizeof...(args);
154 if (returns.size() != numArgs)
155 {
156 // AI_LOG_ERROR("invalid number of args (expected:%zu, actual:%zu)",
157 // numArgs, returns.size());
158 return false;
159 }
160
161 // Get an iterator and point it to the first arg
162 AI_IPC::VariantList::const_iterator it = returns.begin();
163
164 // tbh I don't really know how the following works, but the upshot is that
165 // processVal() will get called for each argument in order
166 bool result = true;
167 int unused[]{(processVal(&result, it++, args), 1)...};
168 _pass{unused};
169
170 return result;
171}
172
173template <typename T>
174void processVal(bool *result, const AI_IPC::VariantList::const_iterator & it, T * arg);
175
176
177
178} // namespace AI_IPC
179
180#endif // AI_IPC_IPCVARIANTLIST_H
181
Definition IpcFileDescriptor.h:33
Light wrapper around a file descriptor so it can be used safely with dbus.
Structure to store dbus object path.
Definition IpcVariantList.h:62
Definition IpcVariantList.h:127