Skip to content

Commit

Permalink
Merge pull request #103 from oteffahi/align-examples
Browse files Browse the repository at this point in the history
Align examples and remove reading from stdin
  • Loading branch information
milyin authored Apr 18, 2024
2 parents c2257ec + 7366f3b commit 1f78139
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 42 deletions.
3 changes: 2 additions & 1 deletion examples/universal/z_pub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ int _main(int argc, char **argv) {

PublisherPutOptions options;
options.set_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN);
for (int idx = 0; std::numeric_limits<int>::max(); ++idx) {
std::cout << "Press CTRL-C to quit..." << std::endl;
for (int idx = 0; idx < std::numeric_limits<int>::max(); ++idx) {
sleep(1);
std::ostringstream ss;
ss << "[" << idx << "] " << value;
Expand Down
3 changes: 2 additions & 1 deletion examples/universal/z_pub_attachment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ int _main(int argc, char **argv) {
// add some value
amap.insert(std::pair("source", "C++"));
#endif
for (int idx = 0; std::numeric_limits<int>::max(); ++idx) {
std::cout << "Press CTRL-C to quit..." << std::endl;
for (int idx = 0; idx < std::numeric_limits<int>::max(); ++idx) {
sleep(1);
std::ostringstream ss;
ss << "[" << idx << "] " << value;
Expand Down
6 changes: 6 additions & 0 deletions examples/universal/z_pub_thr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ int _main(int argc, char **argv) {
std::vector<char> payload(len, 1);

Config config;
#ifdef ZENOHCXX_ZENOHC
if (configfile) {
config = expect(config_from_file(configfile));
}
#endif
if (locator) {
#ifdef ZENOHCXX_ZENOHC
auto locator_json_str_list = std::string("[\"") + locator + "\"]";
Expand All @@ -62,6 +67,7 @@ int _main(int argc, char **argv) {
printf("Declaring Publisher on '%s'...\n", keyexpr);
auto pub = expect<Publisher>(session.declare_publisher(keyexpr, options));

printf("Press CTRL-C to quit...\n");
while (1) pub.put(payload);
}

Expand Down
15 changes: 6 additions & 9 deletions examples/universal/z_pull.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unistd.h>
#endif
#include <iostream>
#include <limits>

#include "../getargs.h"
#include "zenoh.hxx"
Expand Down Expand Up @@ -75,15 +76,11 @@ int _main(int argc, char **argv) {
printf("Declaring Subscriber on '%s'...\n", expr);
auto subscriber = expect<PullSubscriber>(session.declare_pull_subscriber(keyexpr, data_handler));

printf("Press <enter> to pull data...\n");
int c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
} else {
subscriber.pull();
}
printf("Press CTRL-C to quit...\n");
for (int idx = 0; idx < std::numeric_limits<int>::max(); ++idx) {
sleep(1);
printf("[%4d] Pulling...\n", idx);
subscriber.pull();
}

return 0;
Expand Down
10 changes: 3 additions & 7 deletions examples/universal/z_queryable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,9 @@ int _main(int argc, char **argv) {

auto queryable = expect<Queryable>(session.declare_queryable(keyexpr, {on_query, on_drop_queryable}));

printf("Enter 'q' to quit...\n");
int c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

return 0;
Expand Down
10 changes: 3 additions & 7 deletions examples/universal/z_queryable_attachment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ int _main(int argc, char **argv) {

auto queryable = expect<Queryable>(session.declare_queryable(keyexpr, {on_query, on_drop_queryable}));

printf("Enter 'q' to quit...\n");
int c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

return 0;
Expand Down
10 changes: 3 additions & 7 deletions examples/universal/z_sub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ int _main(int argc, char **argv) {
std::cout << "Subscriber on '" << subscriber.get_keyexpr().as_string_view() << "' declared" << std::endl;
#endif

printf("Enter 'q' to quit...\n");
int c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

return 0;
Expand Down
10 changes: 3 additions & 7 deletions examples/universal/z_sub_attachment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,9 @@ int _main(int argc, char **argv) {
std::cout << "Subscriber on '" << subscriber.get_keyexpr().as_string_view() << "' declared" << std::endl;
#endif

printf("Enter 'q' to quit...\n");
int c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

return 0;
Expand Down
14 changes: 11 additions & 3 deletions examples/universal/z_sub_thr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
//
#include <stdio.h>
#include <chrono>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#define sleep(x) Sleep(x * 1000)
#else
#include <unistd.h>
#endif

#include "../getargs.h"
#include "zenoh.hxx"
Expand Down Expand Up @@ -98,10 +104,12 @@ int _main(int argc, char **argv) {

Stats stats;
auto subscriber = expect<Subscriber>(session.declare_subscriber(keyexpr, {stats, stats}));
char c = 0;
while (c != 'q') {
c = fgetc(stdin);

printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

subscriber.drop();
stats.print();

Expand Down

0 comments on commit 1f78139

Please sign in to comment.