Skip to content

Commit

Permalink
adding full build support
Browse files Browse the repository at this point in the history
  • Loading branch information
MelamudMichael committed Mar 10, 2024
1 parent 2d94d6f commit ca74d0a
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 41 deletions.
67 changes: 54 additions & 13 deletions pubsub/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,57 @@
cmake_minimum_required(VERSION 3.20)
project(pubsub VERSION 0.1.0 LANGUAGES CXX)

find_package(up-client-zenoh-cpp REQUIRED)

# sub
add_executable(sub src/main_sub.cpp)
target_link_libraries(sub
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)

# pub
add_executable(pub src/main_pub.cpp)
target_link_libraries(pub
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)
find_package(spdlog REQUIRED)

if(BUILD_UNBUNDLED)
find_package(up-client-zenoh-cpp REQUIRED)
endif()

add_definitions(-DSPDLOG_FMT_EXTERNAL)

if(BUILD_UNBUNDLED)
# sub
add_executable(sub src/main_sub.cpp)
target_link_libraries(sub
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)

target_include_directories(sub
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})

# pub
add_executable(pub src/main_pub.cpp)
target_link_libraries(pub
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)

target_include_directories(pub
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})
else()
# sub
add_executable(sub src/main_sub.cpp)
target_link_libraries(sub
PRIVATE
up-cpp
up-client-zenoh-cpp)

target_include_directories(sub
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})
# pub
add_executable(pub src/main_pub.cpp)
target_link_libraries(pub
PRIVATE
up-cpp
up-client-zenoh-cpp)

target_include_directories(pub
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})
endif()
12 changes: 7 additions & 5 deletions pubsub/src/main_pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
#include <spdlog/spdlog.h>
#include <up-client-zenoh-cpp/transport/zenohUTransport.h>
#include <up-cpp/uuid/factory/Uuidv8Factory.h>
#include <up-cpp/transport/builder/UAttributesBuilder.h>
#include <up-cpp/uri/serializer/LongUriSerializer.h>
#include <up-core-api/ustatus.pb.h>
#include <up-core-api/uri.pb.h>
#include <up-core-api/uattributes.pb.h>

using namespace uprotocol::utransport;
using namespace uprotocol::uri;
Expand Down Expand Up @@ -90,7 +88,7 @@ UCode sendMessage(ZenohUTransport *transport,

auto uuid = Uuidv8Factory::create();

UAttributesBuilder builder(uuid, UMessageType::UMESSAGE_TYPE_PUBLISH, UPriority::UPRIORITY_CS1);
UAttributesBuilder builder(uuid, UMessageType::PUBLISH, UPriority::STANDARD);
UAttributes attributes = builder.build();

UPayload payload(buffer, size, UPayloadType::VALUE);
Expand All @@ -105,8 +103,12 @@ UCode sendMessage(ZenohUTransport *transport,

/* The sample pub applications demonstrates how to send data using uTransport -
* There are three topics that are published - random number, current time and a counter */
int main(int argc, char **argv) {
int main(int argc,
char **argv) {

(void)argc;
(void)argv;

signal(SIGINT, signalHandler);

UStatus status;
Expand Down Expand Up @@ -154,4 +156,4 @@ int main(int argc, char **argv) {
}

return 0;
}
}
8 changes: 6 additions & 2 deletions pubsub/src/main_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ class CustomListener : public UListener {

/* The sample sub applications demonstrates how to consume data using uTransport -
* There are three topics that are received - random number, current time and a counter */
int main(int argc, char** argv) {
int main(int argc,
char** argv) {

(void)argc;
(void)argv;

signal(SIGINT, signalHandler);

UStatus status;
Expand Down Expand Up @@ -145,4 +149,4 @@ int main(int argc, char** argv) {
}

return 0;
}
}
67 changes: 54 additions & 13 deletions rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,57 @@
cmake_minimum_required(VERSION 3.20)
project(rpc VERSION 0.1.0 LANGUAGES CXX)

find_package(up-client-zenoh-cpp REQUIRED)

# rpc server
add_executable(rpc_server src/main_rpc_server.cpp)
target_link_libraries(rpc_server
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)

# rpc client
add_executable(rpc_client src/main_rpc_client.cpp)
target_link_libraries(rpc_client
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)
find_package(spdlog REQUIRED)

if(BUILD_UNBUNDLED)
find_package(up-client-zenoh-cpp REQUIRED)
endif()

add_definitions(-DSPDLOG_FMT_EXTERNAL)

if(BUILD_UNBUNDLED)
# rpc client
add_executable(rpc_client src/main_rpc_client.cpp)
target_link_libraries(rpc_client
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)

target_include_directories(rpc_client
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})

# rpc server
add_executable(rpc_server src/main_rpc_server.cpp)
target_link_libraries(rpc_server
PRIVATE
up-client-zenoh-cpp::up-client-zenoh-cpp)

target_include_directories(rpc_server
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})
else()
# rpc client
add_executable(rpc_client src/main_rpc_client.cpp)
target_link_libraries(rpc_client
PRIVATE
up-cpp
up-client-zenoh-cpp)

target_include_directories(rpc_client
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})
# pub
add_executable(rpc_server src/main_rpc_server.cpp)
target_link_libraries(rpc_server
PRIVATE
up-cpp
up-client-zenoh-cpp)

target_include_directories(rpc_server
PRIVATE
${fmt_INCLUDE_DIR}
${spdlog_INCLUDE_DIR})
endif()
6 changes: 2 additions & 4 deletions rpc/src/main_rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <up-client-zenoh-cpp/rpc/zenohRpcClient.h>
#include <up-cpp/uuid/factory/Uuidv8Factory.h>
#include <up-cpp/uri/serializer/LongUriSerializer.h>
#include <up-cpp/transport/builder/UAttributesBuilder.h>
#include <up-core-api/uattributes.pb.h>

using namespace uprotocol::utransport;
using namespace uprotocol::uuid;
Expand All @@ -49,7 +47,7 @@ UPayload sendRPC(UUri& uri) {

auto uuid = Uuidv8Factory::create();

UAttributesBuilder builder(uuid, UMessageType::UMESSAGE_TYPE_REQUEST, UPriority::UPRIORITY_CS1);
UAttributesBuilder builder(uuid, UMessageType::REQUEST, UPriority::STANDARD);
UAttributes attributes = builder.build();

constexpr uint8_t BUFFER_SIZE = 1;
Expand Down Expand Up @@ -109,4 +107,4 @@ int main(int argc, char** argv) {
}

return 0;
}
}
11 changes: 7 additions & 4 deletions rpc/src/main_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <csignal>
#include <unistd.h>
#include <up-client-zenoh-cpp/transport/zenohUTransport.h>
#include <up-cpp/transport/builder/UAttributesBuilder.h>
#include <up-cpp/uuid/factory/Uuidv8Factory.h>
#include <up-cpp/uri/serializer/LongUriSerializer.h>
#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -60,7 +59,7 @@ class RpcListener : public UListener {

/* Build response attributes - the same UUID should be used to send the response
* it is also possible to send the response outside of the callback context */
UAttributesBuilder builder(attributes.id(), UMessageType::UMESSAGE_TYPE_RESPONSE, UPriority::UPRIORITY_CS1);
UAttributesBuilder builder(attributes.id(), UMessageType::RESPONSE, UPriority::STANDARD);
UAttributes responseAttributes = builder.build();

/* Send the response */
Expand All @@ -70,8 +69,12 @@ class RpcListener : public UListener {

/* The sample RPC server applications demonstrates how to receive RPC requests and send a response back to the client -
* The response in this example will be the current time */
int main(int argc, char** argv) {
int main(int argc,
char** argv) {

(void)argc;
(void)argv;

RpcListener listener;

signal(SIGINT, signalHandler);
Expand Down Expand Up @@ -113,4 +116,4 @@ int main(int argc, char** argv) {
}

return 0;
}
}

0 comments on commit ca74d0a

Please sign in to comment.