Skip to content

Commit

Permalink
Upgrade the UDP Forwarder plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangzp committed Mar 16, 2022
1 parent 655a7c0 commit 6492b8a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ find_package(fmt REQUIRED)
# make plug-ins
add_subdirectory(plugin-demo)
add_subdirectory(plugin-echoprobe)
#add_subdirectory(plugin-forwarder)
add_subdirectory(plugin-forwarder)

# include CPack settings
include(CPack-Settings.txt)
6 changes: 3 additions & 3 deletions plugin-forwarder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ADD_LIBRARY(PDK-Forwarder SHARED UDPBasedPacketForwarder.cpp)
TARGET_LINK_LIBRARIES(PDK-Forwarder Utilities ${Boost_LIBRARIES})
install(TARGETS PDK-Forwarder DESTINATION ${INSTALL_PLUGIN_DIR})
ADD_LIBRARY(PDK-UDPForwarder SHARED UDPBasedPacketForwarder.cpp)
TARGET_LINK_LIBRARIES(PDK-UDPForwarder Utilities ${Boost_LIBRARIES})
install(TARGETS PDK-UDPForwarder DESTINATION ${INSTALL_PLUGIN_DIR})
18 changes: 11 additions & 7 deletions plugin-forwarder/UDPBasedPacketForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "UDPBasedPacketForwarder.h"
#include "boost/algorithm/string.hpp"

std::string UDPBasedPacketForwarder::getPluginName() {
return "Forwarder";
Expand All @@ -17,8 +18,7 @@ std::shared_ptr<boost::program_options::options_description> UDPBasedPacketForwa
static std::once_flag onceFlag;
std::call_once(onceFlag, [&] {
options->add_options()
("forward-to-ip", po::value<std::string>(), "Destination IP for PlugIn UDPBasedPacketForwarder")
("forward-to-port", po::value<uint16_t>(), "Destination Port for PlugIn UDPBasedPacketForwarder");
("forward-to", po::value<std::string>(), "Destination address and port, e.g., 192.168.10.1:50000");
});
return options;
}
Expand All @@ -33,12 +33,16 @@ void UDPBasedPacketForwarder::parseAndExecuteCommands(const std::string &command
po::store(po::command_line_parser(po::split_unix(commandString)).options(*pluginOptionsDescription().get()).allow_unregistered().run(), vm);
po::notify(vm);

if (vm.count("forward-to-ip")) {
destinationIP = vm["forward-to-ip"].as<std::string>();
}
if (vm.count("forward-to")) {
auto input = destinationIP = vm["forward-to"].as<std::string>();
std::vector<std::string> segments;
boost::split(segments, input, boost::is_any_of(":"), boost::token_compress_on);
boost::trim(segments[0]);
boost::trim(segments[1]);
destinationIP = segments[0];
destinationPort = boost::lexical_cast<uint16_t>(segments[1]);

if (vm.count("forward-to-port")) {
destinationPort = vm["forward-to-port"].as<uint16_t>();
LoggingService_info_print("UDP Forwarder destination: {}/{}\n", destinationIP, destinationPort);
}
}

Expand Down
8 changes: 6 additions & 2 deletions plugin-forwarder/UDPBasedPacketForwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define PICOSCENES_RXSBROADCASTPLUGIN_H

#include <PicoScenes/AbstractPicoScenesPlugin.hxx>
#include <PicoScenes/UDPService.h>
#include <PicoScenes/UDPService.hxx>


class UDPBasedPacketForwarder : public AbstractPicoScenesPlugin {
Expand All @@ -23,11 +23,15 @@ class UDPBasedPacketForwarder : public AbstractPicoScenesPlugin {

void rxHandle(const ModularPicoScenesRxFrame &rxframe) override;

static boost::shared_ptr<UDPBasedPacketForwarder> create() {
return boost::make_shared<UDPBasedPacketForwarder>();
}

private:
std::string destinationIP = "127.0.0.1";
uint16_t destinationPort = 50000;
};

PICOSCENES_PLUGIN_INIT(UDPBasedPacketForwarder)
BOOST_DLL_ALIAS(UDPBasedPacketForwarder::create, initPicoScenesPlugin)

#endif //PICOSCENES_RXSBROADCASTPLUGIN_H

0 comments on commit 6492b8a

Please sign in to comment.