Skip to content

Commit 51ae1f6

Browse files
authored
Merge pull request #11 from mc-rtc/mergify/bp/main/pr-10
fix(options): fix connection options (backport #10)
2 parents 2b5be00 + 6c7fa44 commit 51ae1f6

6 files changed

Lines changed: 88 additions & 63 deletions

File tree

flake.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
inputs.mc-rtc-nix.url = "github:mc-rtc/nixpkgs";
55
inputs.mc-rtc-magnum-standalone.url = "github:mc-rtc/mc_rtc-magnum/nix";
66

7+
inputs.mc-rtc-imgui.url = "github:mc-rtc/mc_rtc-imgui/nix";
8+
inputs.mc-rtc-imgui.flake = false;
9+
710
outputs =
811
inputs:
912
inputs.mc-rtc-nix.lib.mkFlakoboros inputs (
1013
{ ... }:
1114
{
15+
overrideAttrs.mc-rtc-imgui = {
16+
src = inputs.mc-rtc-imgui;
17+
};
18+
1219
overrideAttrs.mc-rtc-magnum = {
1320
src = builtins.warn "warning: mc-rtc-magnum on main branch does not support nix, running from the latest locked commit in nix branch" inputs.mc-rtc-magnum-standalone;
1421
};

src/MagnumClient.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@
1717
namespace mc_rtc::magnum
1818
{
1919

20+
inline static std::pair<std::string, std::string> get_endpoints(const McRtcGuiConfiguration & config)
21+
{
22+
const auto & c = config;
23+
if(c.ipcConfig.use_ipc && c.tcpConfig.use_tcp)
24+
{
25+
mc_rtc::log::error_and_throw("Cannot use both TCP and IPC, please choose one of the two communication protocols");
26+
}
27+
else if(!c.ipcConfig.use_ipc && !c.tcpConfig.use_tcp)
28+
{
29+
mc_rtc::log::error_and_throw("No communication protocol specified, please choose one of TCP or IPC");
30+
}
31+
32+
if(c.ipcConfig.use_ipc) { return {c.ipcConfig.pub_uri, c.ipcConfig.sub_uri}; }
33+
else // c.tcpConfig.use_tcp
34+
{
35+
return {fmt::format("tcp://{}:{}", c.tcpConfig.host, c.tcpConfig.pub_port),
36+
fmt::format("tcp://{}:{}", c.tcpConfig.host, c.tcpConfig.sub_port)};
37+
}
38+
}
39+
40+
MagnumClient::MagnumClient(McRtcGui & gui, const McRtcGuiConfiguration & config)
41+
: mc_rtc::imgui::Client(get_endpoints(config).first, get_endpoints(config).second, 3.0), gui_(gui)
42+
{
43+
}
44+
2045
InteractiveMarkerPtr MagnumClient::make_marker(const sva::PTransformd & pose, ControlAxis mask)
2146
{
2247
return std::make_unique<InteractiveMarkerImpl>(gui_.camera(), pose, mask);

src/MagnumClient.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,28 @@ using ElementId = mc_rtc::imgui::ElementId;
1111

1212
struct McRtcGui;
1313

14+
// Todo convert into an mc_rtc::Schema loadable from a config.yaml
15+
struct McRtcGuiConfiguration
16+
{
17+
struct TcpConfig
18+
{
19+
bool use_tcp = false;
20+
std::string host = "localhost";
21+
unsigned sub_port = 4242;
22+
unsigned pub_port = 4343;
23+
} tcpConfig;
24+
struct IpcConfig
25+
{
26+
bool use_ipc = true;
27+
std::string sub_uri = "ipc:///tmp/mc_rtc_rep.ipc";
28+
std::string pub_uri = "ipc:///tmp/mc_rtc_pub.ipc";
29+
} ipcConfig;
30+
std::string confPath = "";
31+
};
32+
1433
struct MagnumClient : public mc_rtc::imgui::Client
1534
{
16-
MagnumClient(McRtcGui & gui) : mc_rtc::imgui::Client(), gui_(gui) {}
35+
MagnumClient(McRtcGui & gui, const McRtcGuiConfiguration & config);
1736

1837
InteractiveMarkerPtr make_marker(const sva::PTransformd & pose = sva::PTransformd::Identity(),
1938
ControlAxis mask = ControlAxis::NONE) override;

src/McRtcGui.cpp

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,13 @@ struct Grid : public SceneGraph::Drawable3D
4141
GL::Mesh mesh_;
4242
};
4343

44-
McRtcGui::McRtcGui(const McRtcGui::McRtcGuiConfiguration & config, const Arguments & arguments)
45-
: Platform::Application{
46-
arguments, Configuration{}
47-
.setTitle("mc_rtc - Magnum based GUI")
48-
.setWindowFlags(Configuration::WindowFlag::Resizable | Configuration::WindowFlag::Maximized)},
49-
50-
client_(*this)
44+
McRtcGui::McRtcGui(const mc_rtc::magnum::McRtcGuiConfiguration & config, const Arguments & arguments)
45+
: Platform::Application{arguments, Configuration{}
46+
.setTitle("mc_rtc - Magnum based GUI")
47+
.setWindowFlags(Configuration::WindowFlag::Resizable
48+
| Configuration::WindowFlag::Maximized)},
49+
client_(*this, config)
5150
{
52-
{
53-
const auto & c = config;
54-
if(c.ipcConfig.use_icp && c.tcpConfig.use_tcp)
55-
{
56-
std::cerr << "Cannot use both TCP and IPC, please choose one of the two communication protocols" << std::endl;
57-
this->exit(1);
58-
return;
59-
}
60-
else if(!c.ipcConfig.use_icp && !c.tcpConfig.use_tcp)
61-
{
62-
std::cerr << "No communication protocol specified, please choose one of TCP or IPC" << std::endl;
63-
this->exit(1);
64-
return;
65-
}
66-
67-
if(c.ipcConfig.use_icp)
68-
{
69-
client_.connect(c.ipcConfig.sub_uri, c.ipcConfig.pub_uri);
70-
}
71-
else if(c.tcpConfig.use_tcp)
72-
{
73-
client_.connect(fmt::format("tcp://{}:{}", c.tcpConfig.host, c.tcpConfig.sub_port),
74-
fmt::format("tcp://{}:{}", c.tcpConfig.host, c.tcpConfig.pub_port));
75-
}
76-
}
7751
{
7852
// Update runtime paths (robot modules, etc)
7953
// This is required in nix to ensure that plugins installed in different store location are available
@@ -442,15 +416,12 @@ void McRtcGui::draw(GL::Mesh & mesh, const Color4 & color, const Matrix4 & world
442416

443417
} // namespace mc_rtc::magnum
444418

445-
446-
void loadFromArgs(int argc, char ** argv)
447-
{
448-
}
419+
void loadFromArgs(int argc, char ** argv) {}
449420

450421
int main(int argc, char ** argv)
451422
{
452423
using McRtcGui = mc_rtc::magnum::McRtcGui;
453-
auto c = McRtcGui::McRtcGuiConfiguration{};
424+
auto c = mc_rtc::magnum::McRtcGuiConfiguration{};
454425
po::options_description desc("mc-rtc-magnum options");
455426
// clang-format off
456427
desc.add_options()
@@ -473,15 +444,18 @@ int main(int argc, char ** argv)
473444
po::notify(vm);
474445
if(vm.count("tcp"))
475446
{
447+
mc_rtc::log::warning("--tcp");
476448
c.tcpConfig.use_tcp = true;
477-
c.ipcConfig.use_icp = false;
449+
c.ipcConfig.use_ipc = false;
478450
c.tcpConfig.host = vm["tcp"].as<std::string>();
479-
std::cout << "Warning use of '--tcp' option is deprecated, use '--use-tcp --tcp-host <hostname>' instead" << std::endl;
451+
std::cout << "Warning use of '--tcp' option is deprecated, use '--use-tcp --tcp-host <hostname>' instead"
452+
<< std::endl;
480453
}
481-
if(vm.count("use-tcp"))
454+
if(vm["use-tcp"].as<bool>())
482455
{
456+
mc_rtc::log::warning("--use-tcp");
483457
c.tcpConfig.use_tcp = true;
484-
c.ipcConfig.use_icp = false;
458+
c.ipcConfig.use_ipc = false;
485459
}
486460
if(vm.count("help"))
487461
{
@@ -498,7 +472,7 @@ int main(int argc, char ** argv)
498472
)" << desc << "\n";
499473
exit(0);
500474
}
501-
475+
502476
auto app = McRtcGui{c, {argc, argv}};
503477
return app.exec();
504478
}

src/McRtcGui.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ struct MagnumClient;
1616

1717
struct McRtcGui : public Platform::Application
1818
{
19-
// Todo convert into an mc_rtc::Schema loadable from a config.yaml
20-
struct McRtcGuiConfiguration
21-
{
22-
struct TcpConfig
23-
{
24-
bool use_tcp = false;
25-
std::string host = "localhost";
26-
unsigned sub_port = 4242;
27-
unsigned pub_port = 4343;
28-
} tcpConfig;
29-
struct IpcConfig
30-
{
31-
bool use_icp = true;
32-
std::string sub_uri = "ipc:///tmp/mc_rtc_sub.ipc";
33-
std::string pub_uri = "ipc:///tmp/mc_rtc_pub.ipc";
34-
} ipcConfig;
35-
std::string confPath = "";
36-
37-
};
38-
3919
explicit McRtcGui(const McRtcGuiConfiguration & config, const Arguments & arguments);
4020

4121
void drawEvent() override;

0 commit comments

Comments
 (0)