Skip to content

Commit a397516

Browse files
Merge pull request #4 from kevinbackhouse/clang-format
clang-format
2 parents 0ad5dac + a5a0554 commit a397516

File tree

20 files changed

+1484
-2242
lines changed

20 files changed

+1484
-2242
lines changed

include/DBusParse/dbus.hpp

Lines changed: 421 additions & 543 deletions
Large diffs are not rendered by default.

include/DBusParse/dbus_auth.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with DBusParse. If not, see <https://www.gnu.org/licenses/>.
1717

18-
1918
#pragma once
2019

2120
#include <sys/types.h>

include/DBusParse/dbus_print.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with DBusParse. If not, see <https://www.gnu.org/licenses/>.
1717

18-
1918
#pragma once
2019

2120
#include "dbus.hpp"
@@ -31,12 +30,11 @@ class PrinterFD final : public Printer {
3130

3231
const size_t tabsize_;
3332

34-
void printBytes(const char* buf, size_t bufsize);
33+
void printBytes(const char *buf, size_t bufsize);
3534

3635
public:
37-
PrinterFD(int fd, size_t base, size_t tabsize) :
38-
fd_(fd), base_(base), tabsize_(tabsize)
39-
{}
36+
PrinterFD(int fd, size_t base, size_t tabsize)
37+
: fd_(fd), base_(base), tabsize_(tabsize) {}
4038

4139
void printChar(char c) override;
4240
void printUint8(uint8_t x) override;
@@ -48,7 +46,7 @@ class PrinterFD final : public Printer {
4846
void printUint64(uint64_t x) override;
4947
void printInt64(int64_t x) override;
5048
void printDouble(double x) override;
51-
void printString(const std::string& str) override;
49+
void printString(const std::string &str) override;
5250

5351
// Print a newline character, followed by `tabsize_ * indent`
5452
// space chracters.

include/DBusParse/dbus_random.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with DBusParse. If not, see <https://www.gnu.org/licenses/>.
1717

18-
1918
#pragma once
2019

21-
#include <random>
2220
#include "dbus.hpp"
21+
#include <random>
2322

2423
// Parameters for generating random DBus types and objects.
2524
class DBusRandom {
@@ -77,15 +76,10 @@ class DBusRandomMersenne : public DBusRandom {
7776
};
7877

7978
// Generate a random DBusType.
80-
const DBusType& randomType(
81-
DBusRandom& r,
82-
DBusTypeStorage& typeStorage, // Type allocator
83-
const size_t maxdepth
84-
);
79+
const DBusType &randomType(DBusRandom &r,
80+
DBusTypeStorage &typeStorage, // Type allocator
81+
const size_t maxdepth);
8582

8683
// Generate a random DBusObject.
87-
std::unique_ptr<DBusObject> randomObject(
88-
DBusRandom& r,
89-
const DBusType& t,
90-
const size_t maxdepth
91-
);
84+
std::unique_ptr<DBusObject> randomObject(DBusRandom &r, const DBusType &t,
85+
const size_t maxdepth);

include/DBusParse/dbus_serialize.hpp

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with DBusParse. If not, see <https://www.gnu.org/licenses/>.
1717

18-
1918
#pragma once
2019

21-
#include <string.h>
2220
#include "dbus.hpp"
21+
#include <string.h>
2322

2423
// Round pos up to a multiple of alignment.
2524
inline size_t alignup(size_t pos, size_t alignment) {
@@ -37,7 +36,9 @@ class SerializerDryRunBase : public Serializer {
3736
SerializerDryRunBase() : pos_(0) {}
3837

3938
virtual void writeByte(char) override { pos_ += sizeof(char); }
40-
virtual void writeBytes(const char*, size_t bufsize) override { pos_ += bufsize; }
39+
virtual void writeBytes(const char *, size_t bufsize) override {
40+
pos_ += bufsize;
41+
}
4142
virtual void writeUint16(uint16_t) override { pos_ += sizeof(uint16_t); }
4243
virtual void writeUint32(uint32_t) override { pos_ += sizeof(uint32_t); }
4344
virtual void writeUint64(uint64_t) override { pos_ += sizeof(uint64_t); }
@@ -58,84 +59,78 @@ class SerializerDryRun final : public SerializerDryRunBase {
5859

5960
size_t getArrayCount() const { return arrayCount_; }
6061

61-
virtual void recordArraySize(
62-
const std::function<uint32_t(uint32_t)>& f
63-
) override;
62+
virtual void
63+
recordArraySize(const std::function<uint32_t(uint32_t)> &f) override;
6464
};
6565

6666
class SerializerInitArraySizes final : public SerializerDryRunBase {
67-
std::vector<uint32_t>& arraySizes_; // Not owned
67+
std::vector<uint32_t> &arraySizes_; // Not owned
6868

6969
public:
70-
SerializerInitArraySizes(std::vector<uint32_t>& arraySizes) :
71-
arraySizes_(arraySizes)
72-
{}
70+
SerializerInitArraySizes(std::vector<uint32_t> &arraySizes)
71+
: arraySizes_(arraySizes) {}
7372

74-
virtual void recordArraySize(
75-
const std::function<uint32_t(uint32_t)>& f
76-
) override;
73+
virtual void
74+
recordArraySize(const std::function<uint32_t(uint32_t)> &f) override;
7775
};
7876

7977
class SerializeToBufferBase : public Serializer {
8078
size_t arrayCount_;
81-
const std::vector<uint32_t>& arraySizes_; // Not owned
79+
const std::vector<uint32_t> &arraySizes_; // Not owned
8280

8381
public:
84-
SerializeToBufferBase(const std::vector<uint32_t>& arraySizes) :
85-
arrayCount_(0), arraySizes_(arraySizes)
86-
{}
82+
SerializeToBufferBase(const std::vector<uint32_t> &arraySizes)
83+
: arrayCount_(0), arraySizes_(arraySizes) {}
8784

88-
virtual void recordArraySize(
89-
const std::function<uint32_t(uint32_t)>& f
90-
) override;
85+
virtual void
86+
recordArraySize(const std::function<uint32_t(uint32_t)> &f) override;
9187
};
9288

9389
template <Endianness endianness>
9490
class SerializeToBuffer final : public SerializeToBufferBase {
9591
size_t pos_;
96-
char* buf_; // Not owned by this class
92+
char *buf_; // Not owned by this class
9793

9894
public:
99-
SerializeToBuffer(const std::vector<uint32_t>& arraySizes, char* buf) :
100-
SerializeToBufferBase(arraySizes), pos_(0), buf_(buf)
101-
{}
95+
SerializeToBuffer(const std::vector<uint32_t> &arraySizes, char *buf)
96+
: SerializeToBufferBase(arraySizes), pos_(0), buf_(buf) {}
10297

10398
virtual void writeByte(char c) override {
10499
buf_[pos_] = c;
105100
pos_ += sizeof(char);
106101
}
107102

108-
virtual void writeBytes(const char* buf, size_t bufsize) override {
103+
virtual void writeBytes(const char *buf, size_t bufsize) override {
109104
memcpy(&buf_[pos_], buf, bufsize);
110105
pos_ += bufsize;
111106
}
112107

113108
virtual void writeUint16(uint16_t x) override {
114109
static_assert(endianness == LittleEndian || endianness == BigEndian);
115110
if (endianness == LittleEndian) {
116-
*(uint16_t*)&buf_[pos_] = htole16(x);
111+
*(uint16_t *)&buf_[pos_] = htole16(x);
117112
} else {
118-
*(uint16_t*)&buf_[pos_] = htobe16(x);
113+
*(uint16_t *)&buf_[pos_] = htobe16(x);
119114
}
120115
pos_ += sizeof(uint16_t);
121116
}
122117

123118
virtual void writeUint32(uint32_t x) override {
124119
static_assert(endianness == LittleEndian || endianness == BigEndian);
125120
if (endianness == LittleEndian) {
126-
*(uint32_t*)&buf_[pos_] = htole32(x);
121+
*(uint32_t *)&buf_[pos_] = htole32(x);
127122
} else {
128-
*(uint32_t*)&buf_[pos_] = htobe32(x);
123+
*(uint32_t *)&buf_[pos_] = htobe32(x);
129124
}
130125
pos_ += sizeof(uint32_t);
131126
}
132127

133128
virtual void writeUint64(uint64_t x) override {
134129
static_assert(endianness == LittleEndian || endianness == BigEndian);
135130
if (endianness == LittleEndian) {
136-
*(uint64_t*)&buf_[pos_] = htole64(x);
131+
*(uint64_t *)&buf_[pos_] = htole64(x);
137132
} else {
138-
*(uint64_t*)&buf_[pos_] = htobe64(x);
133+
*(uint64_t *)&buf_[pos_] = htobe64(x);
139134
}
140135
pos_ += sizeof(uint64_t);
141136
}
@@ -170,18 +165,15 @@ class SerializeToBuffer final : public SerializeToBufferBase {
170165
// they're ok.)
171166
template <Endianness endianness>
172167
class SerializeToString final : public SerializeToBufferBase {
173-
std::string& str_; // Not owned
168+
std::string &str_; // Not owned
174169

175170
public:
176-
SerializeToString(const std::vector<uint32_t>& arraySizes, std::string& str) :
177-
SerializeToBufferBase(arraySizes), str_(str)
178-
{}
171+
SerializeToString(const std::vector<uint32_t> &arraySizes, std::string &str)
172+
: SerializeToBufferBase(arraySizes), str_(str) {}
179173

180-
virtual void writeByte(char c) override {
181-
str_.push_back(c);
182-
}
174+
virtual void writeByte(char c) override { str_.push_back(c); }
183175

184-
virtual void writeBytes(const char* buf, size_t bufsize) override {
176+
virtual void writeBytes(const char *buf, size_t bufsize) override {
185177
str_.append(buf, bufsize);
186178
}
187179

@@ -192,7 +184,7 @@ class SerializeToString final : public SerializeToBufferBase {
192184
} else {
193185
x = htobe16(x);
194186
}
195-
writeBytes((const char*)&x, sizeof(x));
187+
writeBytes((const char *)&x, sizeof(x));
196188
}
197189

198190
virtual void writeUint32(uint32_t x) override {
@@ -202,7 +194,7 @@ class SerializeToString final : public SerializeToBufferBase {
202194
} else {
203195
x = htobe32(x);
204196
}
205-
writeBytes((const char*)&x, sizeof(x));
197+
writeBytes((const char *)&x, sizeof(x));
206198
}
207199

208200
virtual void writeUint64(uint64_t x) override {
@@ -212,7 +204,7 @@ class SerializeToString final : public SerializeToBufferBase {
212204
} else {
213205
x = htobe64(x);
214206
}
215-
writeBytes((const char*)&x, sizeof(x));
207+
writeBytes((const char *)&x, sizeof(x));
216208
}
217209

218210
virtual void writeDouble(double d) override {

include/DBusParse/dbus_utils.hpp

Lines changed: 34 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,88 +15,58 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with DBusParse. If not, see <https://www.gnu.org/licenses/>.
1717

18-
1918
#pragma once
2019

21-
#include <memory>
2220
#include "dbus.hpp"
21+
#include <memory>
2322

24-
void send_dbus_message_with_fds(
25-
const int fd, const DBusMessage& message,
26-
const size_t nfds, const int* fds
27-
);
23+
void send_dbus_message_with_fds(const int fd, const DBusMessage &message,
24+
const size_t nfds, const int *fds);
2825

29-
void send_dbus_message(const int fd, const DBusMessage& message);
26+
void send_dbus_message(const int fd, const DBusMessage &message);
3027

31-
void print_dbus_object(const int fd, const DBusObject& obj);
28+
void print_dbus_object(const int fd, const DBusObject &obj);
3229

33-
void print_dbus_message(const int fd, const DBusMessage& message);
30+
void print_dbus_message(const int fd, const DBusMessage &message);
3431

3532
std::unique_ptr<DBusMessage> receive_dbus_message(const int fd);
3633

3734
std::unique_ptr<DBusMessage> mk_dbus_method_call_msg(
38-
const uint32_t serialNumber,
39-
std::unique_ptr<DBusMessageBody>&& body,
40-
std::string&& path,
41-
std::string&& interface,
42-
std::string&& destination,
43-
std::string&& member,
44-
const size_t nfds,
45-
const MessageFlags flags
46-
);
35+
const uint32_t serialNumber, std::unique_ptr<DBusMessageBody> &&body,
36+
std::string &&path, std::string &&interface, std::string &&destination,
37+
std::string &&member, const size_t nfds, const MessageFlags flags);
4738

4839
std::unique_ptr<DBusMessage> mk_dbus_method_reply_msg(
49-
const uint32_t serialNumber,
50-
const uint32_t replySerialNumber, // serial number that we are replying to
51-
std::unique_ptr<DBusMessageBody>&& body,
52-
std::string&& destination
53-
);
40+
const uint32_t serialNumber,
41+
const uint32_t replySerialNumber, // serial number that we are replying to
42+
std::unique_ptr<DBusMessageBody> &&body, std::string &&destination);
5443

5544
std::unique_ptr<DBusMessage> mk_dbus_method_error_reply_msg(
56-
const uint32_t serialNumber,
57-
const uint32_t replySerialNumber, // serial number that we are replying to
58-
std::string&& destination,
59-
std::string&& errmsg
60-
);
61-
62-
void dbus_method_call_with_fds(
63-
const int fd,
64-
const uint32_t serialNumber,
65-
std::unique_ptr<DBusMessageBody>&& body,
66-
std::string&& path,
67-
std::string&& interface,
68-
std::string&& destination,
69-
std::string&& member,
70-
const size_t nfds,
71-
const int* fds,
72-
const MessageFlags flags = MSGFLAGS_EMPTY
73-
);
74-
75-
void dbus_method_call(
76-
const int fd,
77-
const uint32_t serialNumber,
78-
std::unique_ptr<DBusMessageBody>&& body,
79-
std::string&& path,
80-
std::string&& interface,
81-
std::string&& destination,
82-
std::string&& member,
83-
const MessageFlags flags = MSGFLAGS_EMPTY
84-
);
45+
const uint32_t serialNumber,
46+
const uint32_t replySerialNumber, // serial number that we are replying to
47+
std::string &&destination, std::string &&errmsg);
48+
49+
void dbus_method_call_with_fds(const int fd, const uint32_t serialNumber,
50+
std::unique_ptr<DBusMessageBody> &&body,
51+
std::string &&path, std::string &&interface,
52+
std::string &&destination, std::string &&member,
53+
const size_t nfds, const int *fds,
54+
const MessageFlags flags = MSGFLAGS_EMPTY);
55+
56+
void dbus_method_call(const int fd, const uint32_t serialNumber,
57+
std::unique_ptr<DBusMessageBody> &&body,
58+
std::string &&path, std::string &&interface,
59+
std::string &&destination, std::string &&member,
60+
const MessageFlags flags = MSGFLAGS_EMPTY);
8561

8662
void dbus_method_reply(
87-
const int fd,
88-
const uint32_t serialNumber,
89-
const uint32_t replySerialNumber, // serial number that we are replying to
90-
std::unique_ptr<DBusMessageBody>&& body,
91-
std::string&& destination
92-
);
63+
const int fd, const uint32_t serialNumber,
64+
const uint32_t replySerialNumber, // serial number that we are replying to
65+
std::unique_ptr<DBusMessageBody> &&body, std::string &&destination);
9366

9467
void dbus_method_error_reply(
95-
const int fd,
96-
const uint32_t serialNumber,
97-
const uint32_t replySerialNumber, // serial number that we are replying to
98-
std::string&& destination,
99-
std::string&& errmsg
100-
);
68+
const int fd, const uint32_t serialNumber,
69+
const uint32_t replySerialNumber, // serial number that we are replying to
70+
std::string &&destination, std::string &&errmsg);
10171

10272
void dbus_send_hello(const int fd);

include/DBusParseUtils/endianness.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with DBusParse. If not, see <https://www.gnu.org/licenses/>.
1717

18-
1918
#pragma once
2019

21-
enum Endianness {
22-
LittleEndian,
23-
BigEndian
24-
};
20+
enum Endianness { LittleEndian, BigEndian };

0 commit comments

Comments
 (0)