Skip to content

Commit c1561de

Browse files
committed
Run all files through clang-format
1 parent a4226cb commit c1561de

22 files changed

+293
-249
lines changed

.clang-format

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BasedOnStyle: WebKit
2+
IndentWidth: 4
3+
BinPackArguments: false
4+
BinPackParameters: false
5+
ColumnLimit: 100
6+
Standard: Cpp11

src/inject.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <string>
55

66
class IInjectPlugin {
7-
public: virtual ~IInjectPlugin() { }
7+
public:
8+
virtual ~IInjectPlugin() {}
89

9-
public: virtual void inject(const std::vector<std::string>& paths) = 0;
10+
public:
11+
virtual void inject(const std::vector<std::string>& paths) = 0;
1012
};

src/inject_utimes.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "inject_utimes.h"
66

7-
UtimesInjectPlugin::~UtimesInjectPlugin() {
8-
}
7+
UtimesInjectPlugin::~UtimesInjectPlugin() {}
98

10-
void UtimesInjectPlugin::inject(const std::vector<std::string>& paths) {
9+
void UtimesInjectPlugin::inject(const std::vector<std::string>& paths)
10+
{
1111
for (const auto& path : paths) {
1212
utimes(path.c_str(), nullptr);
1313
}

src/inject_utimes.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "inject.h"
44

55
class UtimesInjectPlugin : public IInjectPlugin {
6-
public: virtual ~UtimesInjectPlugin();
6+
public:
7+
virtual ~UtimesInjectPlugin();
78

8-
public: virtual void inject(const std::vector<std::string>& paths);
9+
public:
10+
virtual void inject(const std::vector<std::string>& paths);
911
};

src/main.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
#include "main.h"
66

7-
static void print_usage(char* argv0) {
8-
fprintf(stderr, "Usage: %s (watch|receive)\n", argv0);
9-
}
7+
static void print_usage(char* argv0) { fprintf(stderr, "Usage: %s (watch|receive)\n", argv0); }
108

11-
int main(int argc, char** argv) {
9+
int main(int argc, char** argv)
10+
{
1211
if (argc < 2) {
1312
print_usage(argv[0]);
1413
return EX_USAGE;

src/main_receive.cc

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdlib.h>
2-
#include <sysexits.h>
32
#include <string.h>
3+
#include <sysexits.h>
44

55
#include "main.h"
66
#include "utils.h"
@@ -15,7 +15,8 @@
1515

1616
static IReceivePlugin* gCurrentReceiveInstance = nullptr;
1717

18-
static void handle_sigint(__unused int signal) {
18+
static void handle_sigint(__unused int signal)
19+
{
1920
if (gCurrentReceiveInstance) {
2021
gCurrentReceiveInstance->stop();
2122
}
@@ -24,14 +25,16 @@ static void handle_sigint(__unused int signal) {
2425
}
2526
}
2627

27-
static void print_usage(char *argv0) {
28+
static void print_usage(char* argv0)
29+
{
2830
fprintf(stderr, "Usage: %s receive [-p port]\n", argv0);
2931
fprintf(stderr, "\n");
3032
fprintf(stderr, " -p port specifies which ports to listen to. Defaults to 29324\n");
3133
fprintf(stderr, "\n");
3234
}
3335

34-
int main_receive(char* argv0, int argc, char** argv) {
36+
int main_receive(char* argv0, int argc, char** argv)
37+
{
3538
UtimesInjectPlugin injector;
3639

3740
short port = 29324;
@@ -48,9 +51,8 @@ int main_receive(char* argv0, int argc, char** argv) {
4851
return EX_USAGE;
4952
}
5053

51-
ReceiveCallback callback = [&injector](std::vector<std::string> paths) {
52-
injector.inject(paths);
53-
};
54+
ReceiveCallback callback
55+
= [&injector](std::vector<std::string> paths) { injector.inject(paths); };
5456

5557
UDPReceivePlugin receive_plugin(port, callback);
5658
SignalOverride(SIGINT, handle_sigint);

src/main_watch.cc

+26-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#include <stdlib.h>
2+
#include <string.h>
23
#include <sys/param.h>
34
#include <sysexits.h>
4-
#include <string.h>
55

66
#include <chrono>
77
#include <unordered_map>
88

99
#include "main.h"
10+
1011
#include "utils.h"
1112

1213
#include "watch.h"
1314
#include "watch_fsevents.h"
14-
#include "watch_null.h"
1515
#include "watch_inotify.h"
16+
#include "watch_null.h"
1617

1718
#include "notify.h"
1819
#include "notify_udp.h"
@@ -24,9 +25,10 @@ typedef std::chrono::time_point<Clock> TimePoint;
2425
typedef std::unordered_map<std::string, TimePoint> FeedbackMap;
2526
typedef std::vector<std::pair<std::string, std::string>> PrefixMap;
2627

27-
static IWatchPlugin *gCurrentWatchInstance = nullptr;
28+
static IWatchPlugin* gCurrentWatchInstance = nullptr;
2829

29-
static void handle_sigint(__unused int signal) {
30+
static void handle_sigint(__unused int signal)
31+
{
3032
if (gCurrentWatchInstance) {
3133
gCurrentWatchInstance->stop();
3234
}
@@ -35,7 +37,8 @@ static void handle_sigint(__unused int signal) {
3537
}
3638
}
3739

38-
static void print_usage(char *argv0) {
40+
static void print_usage(char* argv0)
41+
{
3942
fprintf(stderr, "Usage: %s watch [-c host[:port]] (<from> <to>)...\n", argv0);
4043
fprintf(stderr, "\n");
4144
fprintf(stderr, " (<from> <to>) pairs of paths, the first being the local path to watch\n");
@@ -44,7 +47,8 @@ static void print_usage(char *argv0) {
4447
fprintf(stderr, "\n");
4548
}
4649

47-
static std::string replace_prefix(const PrefixMap &prefix_map, std::string src) {
50+
static std::string replace_prefix(const PrefixMap& prefix_map, std::string src)
51+
{
4852
for (const auto& pair : prefix_map) {
4953

5054
if (src.substr(0, pair.first.size()) == pair.first) {
@@ -55,7 +59,8 @@ static std::string replace_prefix(const PrefixMap &prefix_map, std::string src)
5559
return src;
5660
}
5761

58-
static void clear_expired(FeedbackMap &feedback_map) {
62+
static void clear_expired(FeedbackMap& feedback_map)
63+
{
5964
TimePoint now = Clock::now();
6065

6166
for (auto it = feedback_map.begin(); it != feedback_map.end();) {
@@ -68,8 +73,9 @@ static void clear_expired(FeedbackMap &feedback_map) {
6873
}
6974
}
7075

71-
static std::vector<std::string> filter_feedback(FeedbackMap &feedback_map,
72-
std::vector<std::string> paths) {
76+
static std::vector<std::string> filter_feedback(
77+
FeedbackMap& feedback_map, std::vector<std::string> paths)
78+
{
7379
clear_expired(feedback_map);
7480

7581
std::vector<std::string> out_paths;
@@ -85,7 +91,8 @@ static std::vector<std::string> filter_feedback(FeedbackMap &feedback_map,
8591
return out_paths;
8692
}
8793

88-
int main_watch(char *argv0, int argc, char** argv) {
94+
int main_watch(char* argv0, int argc, char** argv)
95+
{
8996
std::vector<std::string> watch_paths;
9097
std::vector<std::pair<std::string, std::string>> prefix_map;
9198
FeedbackMap feedback_map;
@@ -128,20 +135,21 @@ int main_watch(char *argv0, int argc, char** argv) {
128135
}
129136

130137
watch_paths.emplace_back(out_path);
131-
prefix_map.emplace_back(out_path, argv[i+1]);
138+
prefix_map.emplace_back(out_path, argv[i + 1]);
132139
}
133140

134141
UDPNotifyPlugin notify_plugin(dest_addr, port);
135142

136-
WatchCallback callback = [&notify_plugin, &prefix_map, &feedback_map](std::vector<std::string> paths) {
137-
std::vector<std::string> out_paths;
143+
WatchCallback callback
144+
= [&notify_plugin, &prefix_map, &feedback_map](std::vector<std::string> paths) {
145+
std::vector<std::string> out_paths;
138146

139-
for (auto& path : paths) {
140-
out_paths.emplace_back(replace_prefix(prefix_map, path));
141-
}
147+
for (auto& path : paths) {
148+
out_paths.emplace_back(replace_prefix(prefix_map, path));
149+
}
142150

143-
notify_plugin.notify(filter_feedback(feedback_map, out_paths));
144-
};
151+
notify_plugin.notify(filter_feedback(feedback_map, out_paths));
152+
};
145153

146154
WATCH_PLUGIN_TYPE plugin(watch_paths, callback);
147155
SignalOverride(SIGINT, handle_sigint);

src/notify.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <string>
55

66
class INotifyPlugin {
7-
public: virtual ~INotifyPlugin() { }
7+
public:
8+
virtual ~INotifyPlugin() {}
89

9-
public: virtual void notify(const std::vector<std::string> &paths) = 0;
10+
public:
11+
virtual void notify(const std::vector<std::string>& paths) = 0;
1012
};

src/notify_udp.cc

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
#include <stdio.h>
2-
#include <unistd.h>
31
#include <arpa/inet.h>
2+
#include <netinet/in.h>
3+
#include <stdio.h>
44
#include <string.h>
55
#include <sys/socket.h>
6-
#include <netinet/in.h>
6+
#include <unistd.h>
77

88
#include "notify_udp.h"
99

1010
class UDPNotifyPluginImpl {
11-
public: int socket_fd;
12-
public: sockaddr_in dest_addr;
11+
public:
12+
int socket_fd;
13+
14+
public:
15+
sockaddr_in dest_addr;
1316
};
1417

1518
UDPNotifyPlugin::UDPNotifyPlugin(const std::string& addr, short port)
16-
: m_impl(new UDPNotifyPluginImpl()) {
19+
: m_impl(new UDPNotifyPluginImpl())
20+
{
1721
m_impl->socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
1822
if (m_impl->socket_fd == -1) {
1923
throw std::runtime_error("Could not create sending socket");
@@ -28,16 +32,17 @@ UDPNotifyPlugin::UDPNotifyPlugin(const std::string& addr, short port)
2832
m_impl->dest_addr = dest_addr;
2933
}
3034

31-
UDPNotifyPlugin::~UDPNotifyPlugin() {
35+
UDPNotifyPlugin::~UDPNotifyPlugin()
36+
{
3237
if (m_impl->socket_fd >= 0) {
3338
close(m_impl->socket_fd);
3439
}
3540
}
3641

37-
void UDPNotifyPlugin::notify(const std::vector<std::string>& paths) {
42+
void UDPNotifyPlugin::notify(const std::vector<std::string>& paths)
43+
{
3844
for (auto& path : paths) {
39-
ssize_t sent_bytes = sendto(
40-
m_impl->socket_fd,
45+
ssize_t sent_bytes = sendto(m_impl->socket_fd,
4146
path.c_str(),
4247
path.size(),
4348
0,

src/notify_udp.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
class UDPNotifyPluginImpl;
88

99
class UDPNotifyPlugin : public INotifyPlugin {
10-
public: UDPNotifyPlugin(const std::string& addr, short port);
11-
public: virtual ~UDPNotifyPlugin();
10+
public:
11+
UDPNotifyPlugin(const std::string& addr, short port);
1212

13-
public: virtual void notify(const std::vector<std::string> &paths);
13+
public:
14+
virtual ~UDPNotifyPlugin();
1415

15-
private: std::unique_ptr<UDPNotifyPluginImpl> m_impl;
16+
public:
17+
virtual void notify(const std::vector<std::string>& paths);
18+
19+
private:
20+
std::unique_ptr<UDPNotifyPluginImpl> m_impl;
1621
};

src/platform.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef __clang__
22

3-
# define __unused __attribute__((unused))
3+
#define __unused __attribute__((unused))
44

55
#endif

src/receive.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#pragma once
22

33
#include <functional>
4-
#include <vector>
54
#include <string>
5+
#include <vector>
66

77
typedef std::function<void(std::vector<std::string>)> ReceiveCallback;
88

99
class IReceivePlugin {
10-
public: virtual ~IReceivePlugin() { }
10+
public:
11+
virtual ~IReceivePlugin() {}
12+
13+
public:
14+
virtual void start() = 0;
1115

12-
public: virtual void start() = 0;
13-
public: virtual void stop() = 0;
16+
public:
17+
virtual void stop() = 0;
1418
};

0 commit comments

Comments
 (0)