Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impose clang format #180

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ on:
workflow_dispatch:

jobs:
check_format:
name: Check codebase format with clang-format
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run clang-format dry-run
run: find include/ tests/ examples/ -iname "*.hxx" -o -iname "*.cxx" | xargs clang-format -n -Werror

build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
3 changes: 2 additions & 1 deletion examples/simple/universal/z_simple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class CustomSubscriber {

void on_receive(const Sample& sample) {
CustomStruct s = sample.get_payload().deserialize<CustomStruct>(CustomCodec());
std::cout << "Received: " << "{" << s.u << ", " << s.d << ", " << s.s << "}\n";
std::cout << "Received: "
<< "{" << s.u << ", " << s.d << ", " << s.s << "}\n";
}
};

Expand Down
1 change: 1 addition & 0 deletions examples/simple/zenohc/zc_simple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//

#include <iostream>

#include "zenoh.hxx"
using namespace zenoh;

Expand Down
12 changes: 6 additions & 6 deletions examples/universal/z_get_attachment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ int _main(int argc, char **argv) {
std::condition_variable done_signal;
bool done = false;

auto on_reply = [](const Reply& reply) {
auto on_reply = [](const Reply &reply) {
if (reply.is_ok()) {
const Sample& sample = reply.get_ok();
const Sample &sample = reply.get_ok();
std::cout << "Received ('" << sample.get_keyexpr().as_string_view() << "' : '"
<< sample.get_payload().deserialize<std::string>() << "')\n";
auto attachment = sample.get_attachment();
if (!attachment.has_value()) return;
// we expect attachment in the form of key-value pairs
auto attachment_deserialized = attachment->get().deserialize<std::unordered_map<std::string, std::string>>();
for (auto&& [key, value]: attachment_deserialized) {
auto attachment_deserialized =
attachment->get().deserialize<std::unordered_map<std::string, std::string>>();
for (auto &&[key, value] : attachment_deserialized) {
std::cout << " attachment: " << key << ": '" << value << "'\n";
}
} else {
Expand All @@ -79,8 +80,7 @@ int _main(int argc, char **argv) {

session.get(
keyexpr, "", on_reply, on_done,
{.target = Z_QUERY_TARGET_ALL, .payload = Bytes::serialize(value), .attachment = Bytes::serialize(attachment)}
);
{.target = Z_QUERY_TARGET_ALL, .payload = Bytes::serialize(value), .attachment = Bytes::serialize(attachment)});

std::unique_lock lock(m);
done_signal.wait(lock, [&done] { return done; });
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_get_channel_non_blocking.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int _main(int argc, char **argv) {
std::cout << ".";
std::this_thread::sleep_for(1s);
continue;
} else { // channel is closed - no more replies will be received
} else { // channel is closed - no more replies will be received
break;
}
}
Expand Down
7 changes: 3 additions & 4 deletions examples/universal/z_ping.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#include <chrono>
#include <condition_variable>
#include <cstring>
#include <iostream>
#include <mutex>
#include <cstring>
#include <numeric>

#include "zenoh.hxx"
Expand Down Expand Up @@ -57,9 +57,8 @@ int _main(int argc, char** argv) {
std::cout << "Opening session...\n";
auto session = Session::open(std::move(config));

auto sub = session.declare_subscriber(KeyExpr("test/pong"),
[&condvar](const Sample&) mutable { condvar.notify_one(); }, closures::none
);
auto sub = session.declare_subscriber(
KeyExpr("test/pong"), [&condvar](const Sample&) mutable { condvar.notify_one(); }, closures::none);
auto pub = session.declare_publisher(KeyExpr("test/ping"));
std::vector<uint8_t> data(args.size);
std::iota(data.begin(), data.end(), uint8_t{0});
Expand Down
4 changes: 3 additions & 1 deletion examples/universal/z_pong.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ int _main(int, char **) {

auto pub = session.declare_publisher(KeyExpr("test/pong"));
auto sub = session.declare_subscriber(
KeyExpr("test/ping"), [pub = std::move(pub)](const Sample &sample) mutable { pub.put(sample.get_payload().clone()); }, closures::none);
KeyExpr("test/ping"),
[pub = std::move(pub)](const Sample &sample) mutable { pub.put(sample.get_payload().clone()); },
closures::none);
std::cout << "Pong ready, press any key to quit\n";
std::getchar();
return 0;
Expand Down
9 changes: 4 additions & 5 deletions examples/universal/z_pub_attachment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include <stdio.h>
#include <string.h>

#include <chrono>
#include <iostream>
#include <limits>
#include <sstream>
#include <thread>
#include <chrono>

#include "../getargs.h"
#include "zenoh.hxx"
Expand Down Expand Up @@ -64,9 +64,7 @@ int _main(int argc, char **argv) {
std::cout << "Publisher on '" << keyexpr << "' declared" << std::endl;

// allocate attachment map
std::unordered_map<std::string, std::string> attachment_map = {
{"source", "C++"}
};
std::unordered_map<std::string, std::string> attachment_map = {{"source", "C++"}};

std::cout << "Press CTRL-C to quit..." << std::endl;
for (int idx = 0; idx < std::numeric_limits<int>::max(); ++idx) {
Expand All @@ -77,7 +75,8 @@ int _main(int argc, char **argv) {
std::cout << "Putting Data ('" << keyexpr << "': '" << s << "')...\n";
// add some other attachment value
attachment_map["index"] = std::to_string(idx);
pub.put(Bytes::serialize(s), {.encoding = Encoding("text/plain"), .attachment = Bytes::serialize(attachment_map)});
pub.put(Bytes::serialize(s),
{.encoding = Encoding("text/plain"), .attachment = Bytes::serialize(attachment_map)});
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_pub_thr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <stdio.h>
#include <string.h>

#include <vector>
#include <numeric>
#include <vector>

#include "../getargs.h"
#include "zenoh.hxx"
Expand Down
3 changes: 2 additions & 1 deletion examples/universal/z_put.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ int _main(int argc, char **argv) {
std::cout << "Opening session...\n";
auto session = Session::open(std::move(config));

std::cout << "Putting Data (" << "'" << keyexpr << "': '" << value << "')...\n";
std::cout << "Putting Data ("
<< "'" << keyexpr << "': '" << value << "')...\n";

std::unordered_map<std::string, std::string> attachment_map = {{"serial_number", "123"},
{"coordinates", "48.7082,2.1498"}};
Expand Down
11 changes: 5 additions & 6 deletions examples/universal/z_queryable_attachment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <stdio.h>
#include <string.h>

#include <chrono>
#include <iostream>
#include <thread>
#include <chrono>

#include "../getargs.h"
#include "zenoh.hxx"
Expand Down Expand Up @@ -58,7 +58,7 @@ int _main(int argc, char **argv) {
std::cout << "Declaring Queryable on '" << expr << "'...\n";

auto on_query = [](const Query &query) {
const KeyExpr& keyexpr = query.get_keyexpr();
const KeyExpr &keyexpr = query.get_keyexpr();
auto params = query.get_parameters();
auto payload = query.get_payload();
std::cout << ">> [Queryable ] Received Query '" << keyexpr.as_string_view() << "?" << params;
Expand All @@ -72,13 +72,12 @@ int _main(int argc, char **argv) {
if (attachment.has_value()) {
// read attachment as a key-value map
attachment_map = attachment->get().deserialize<std::unordered_map<std::string, std::string>>();
for (auto&& [key, value]: attachment_map) {
for (auto &&[key, value] : attachment_map) {
std::cout << " attachment: " << key << ": '" << value << "'\n";
}
}
query.reply(
KeyExpr(expr), Bytes::serialize(value), {.encoding = Encoding("text/palin"), .attachment = Bytes::serialize(attachment_map)}
);
query.reply(KeyExpr(expr), Bytes::serialize(value),
{.encoding = Encoding("text/palin"), .attachment = Bytes::serialize(attachment_map)});
};

auto on_drop_queryable = []() { std::cout << "Destroying queryable\n"; };
Expand Down
5 changes: 3 additions & 2 deletions examples/universal/z_sub_attachment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// ZettaScale Zenoh Team, <[email protected]>
//
#include <stdio.h>
#include <thread>

#include <chrono>
#include <iostream>
#include <thread>

#include "../getargs.h"
#include "zenoh.hxx"
Expand Down Expand Up @@ -64,7 +65,7 @@ int _main(int argc, char **argv) {
if (!attachment.has_value()) return;
// we expect attachment in the form of key-value pairs
auto attachment_data = attachment->get().deserialize<std::unordered_map<std::string, std::string>>();
for (auto&& [key, value]: attachment_data) {
for (auto &&[key, value] : attachment_data) {
std::cout << " attachment: " << key << ": '" << value << "'\n";
}
};
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_sub_thr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int _main(int argc, char **argv) {
KeyExpr keyexpr = session.declare_keyexpr(KeyExpr("test/thr"));

Stats stats;
auto on_receive = [&stats](const Sample& s) { stats(s); };
auto on_receive = [&stats](const Sample &s) { stats(s); };
auto on_drop = [&stats]() { stats(); };
auto subscriber = session.declare_subscriber(keyexpr, on_receive, on_drop);

Expand Down
2 changes: 1 addition & 1 deletion examples/zenohc/z_get_liveliness.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int _main(int argc, char **argv) {
auto replies = session.liveliness_get(keyexpr, channels::FifoChannel(16));

for (auto res = replies.recv(); std::holds_alternative<Reply>(res); res = replies.recv()) {
const Reply& reply = std::get<Reply>(res);
const Reply &reply = std::get<Reply>(res);
if (reply.is_ok()) {
const auto &sample = reply.get_ok();
std::cout << "Alive token ('" << sample.get_keyexpr().as_string_view() << "')\n";
Expand Down
3 changes: 2 additions & 1 deletion examples/zenohc/z_ping_shm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ int _main(int argc, char** argv) {
}
auto rtt =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count();
std::cout << args.size << " bytes: seq=" << i << " rtt=" << rtt << "µs" << " lat=" << rtt / 2 << "µs\n";
std::cout << args.size << " bytes: seq=" << i << " rtt=" << rtt << "µs"
<< " lat=" << rtt / 2 << "µs\n";
}
lock.unlock();
return 0;
Expand Down
8 changes: 4 additions & 4 deletions examples/zenohc/z_queryable_shm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ int _main(int argc, char **argv) {

const char *payload_type = "";
if (payload.has_value()) {
ZResult result;
ZResult result;
payload->get().deserialize<ZShm>(&result);
if (result == Z_OK) {
if (result == Z_OK) {
payload_type = "SHM";
} else {
payload_type = "RAW";
Expand All @@ -77,8 +77,8 @@ int _main(int argc, char **argv) {

const KeyExpr &keyexpr = query.get_keyexpr();
auto params = query.get_parameters();
std::cout << ">> [Queryable ] Received Query [" << payload_type << "] '" << keyexpr.as_string_view() << "?"
<< params;
std::cout << ">> [Queryable ] Received Query [" << payload_type << "] '" << keyexpr.as_string_view() << "?"
<< params;
if (payload.has_value()) {
std::cout << "' value = '" << payload->get().deserialize<std::string>();
}
Expand Down
6 changes: 3 additions & 3 deletions include/zenoh/api.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
#if defined UNSTABLE
#include "api/id.hxx"
#endif
#include "api/channels.hxx"
#include "api/keyexpr.hxx"
#include "api/logging.hxx"
#include "api/publisher.hxx"
#include "api/query_consolidation.hxx"
#include "api/query.hxx"
#include "api/query_consolidation.hxx"
#include "api/queryable.hxx"
#include "api/reply.hxx"
#include "api/sample.hxx"
#include "api/scout.hxx"
#include "api/session.hxx"
#include "api/subscriber.hxx"
#include "api/timestamp.hxx"
#include "api/channels.hxx"
#include "api/logging.hxx"
#if defined SHARED_MEMORY && defined UNSTABLE
#include "api/shm/shm.hxx"
#endif
Loading
Loading