Skip to content

Commit

Permalink
Examples: Remove leading slashes from all topics
Browse files Browse the repository at this point in the history
  • Loading branch information
alerei committed Nov 1, 2024
1 parent a083274 commit 0c9f5ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
13 changes: 7 additions & 6 deletions examples/flunder_client_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@ int main(void)
void* flunder_client = flunder_client_new();

flunder_connect(flunder_client, FLECS_FLUNDER_HOST, FLECS_FLUNDER_PORT);
flunder_add_mem_storage(flunder_client, "flunder-c", "/flecs/flunder/**");
flunder_subscribe(flunder_client, "/flecs/flunder/c/int", &flunder_subscribe_callback);
flunder_subscribe(flunder_client, "/flecs/flunder/c/float", &flunder_subscribe_callback);
flunder_subscribe(flunder_client, "/flecs/flunder/external", &flunder_subscribe_callback);
flunder_add_mem_storage(flunder_client, "flunder-c", "flecs/flunder/**");
flunder_subscribe(flunder_client, "flecs/flunder/c/int", &flunder_subscribe_callback);
flunder_subscribe(flunder_client, "flecs/flunder/c/float", &flunder_subscribe_callback);
flunder_subscribe(flunder_client, "flecs/flunder/external", &flunder_subscribe_callback);

while (!g_stop) {
int i = 1234;
float f = 3.14159;
flunder_publish_int(flunder_client, "/flecs/flunder/c/int", i);
flunder_publish_float(flunder_client, "/flecs/flunder/c/float", f);
flunder_publish_int(flunder_client, "flecs/flunder/c/int", i);
flunder_publish_float(flunder_client, "flecs/flunder/c/float", f);
flunder_publish_string(flunder_client, "flecs/flunder/c/string", "Hello from C!");
sleep(5);

variable_t* vars;
Expand Down
22 changes: 11 additions & 11 deletions examples/flunder_client_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ void flunder_receive_callback(flunder::client_t* client, const flunder::variable
var->len(),
now);

if (var->topic() == "/flecs/flunder/cpp/int") {
if (var->topic() == "flecs/flunder/cpp/int") {
const auto i = std::atoll(var->value().data());
std::fprintf(stdout, "\tValue: %lld\n", i);
} else if (var->topic() == "/flecs/flunder/cpp/double") {
} else if (var->topic() == "flecs/flunder/cpp/double") {
const auto d = std::atof(var->value().data());
std::fprintf(stdout, "\tValue: %lf\n", d);
} else if (var->topic() == "/flecs/flunder/cpp/string") {
} else if (var->topic() == "flecs/flunder/cpp/string") {
std::fprintf(stdout, "\tValue: %s\n", var->value().data());
} else if (var->topic() == "/flecs/flunder/cpp/timestamp") {
} else if (var->topic() == "flecs/flunder/cpp/timestamp") {
const auto t1 = std::stoll(var->value().data());
const auto diff = now - t1;
std::fprintf(stdout, "\tMessage sent @%lld (%lld ns ago)\n", t1, diff);
Expand Down Expand Up @@ -84,27 +84,27 @@ int main()
auto flunder_client = flunder::client_t{};

flunder_client.connect();
flunder_client.add_mem_storage("flunder-cpp", "/flecs/flunder/**");
flunder_client.add_mem_storage("flunder-cpp", "flecs/flunder/**");

flunder_client.subscribe("/flecs/flunder/cpp/**", &flunder_receive_callback);
flunder_client.subscribe("flecs/flunder/cpp/**", &flunder_receive_callback);
const char* userdata = "Hello, world!";
flunder_client.subscribe(
"/flecs/flunder/external",
"flecs/flunder/external",
&flunder_receive_callback_userp,
(const void*)userdata);

while (!g_stop) {
const auto i = 1234;
flunder_client.publish("/flecs/flunder/cpp/int", i);
flunder_client.publish("flecs/flunder/cpp/int", i);

const auto d = 3.14159;
flunder_client.publish("/flecs/flunder/cpp/double", d);
flunder_client.publish("flecs/flunder/cpp/double", d);

const auto str = "Hello, world!";
flunder_client.publish("/flecs/flunder/cpp/string", str);
flunder_client.publish("flecs/flunder/cpp/string", str);

const auto t = std::chrono::high_resolution_clock::now().time_since_epoch().count();
flunder_client.publish("/flecs/flunder/cpp/timestamp", t);
flunder_client.publish("flecs/flunder/cpp/timestamp", t);

std::this_thread::sleep_for(std::chrono::seconds(5));
}
Expand Down

0 comments on commit 0c9f5ef

Please # to comment.