Skip to content

Commit

Permalink
Add command line argument parsing with CLI11
Browse files Browse the repository at this point in the history
- The 'main.cpp' file is updated to include CLI11 for parsing command line arguments
- A new command line option '-w' and '--wsuri' to specify the WebSocket URI is added
- The main function is changed to accept the 'argc' and 'argv' parameters for argument parsing

These changes allow the parsing of command line arguments for the configuration of the WebSocket URI, increasing the flexibility of the application.
  • Loading branch information
arkadiusz committed Jul 25, 2024
1 parent 41b5da2 commit 5fcb351
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@
#include <thread>
#include <CLI/CLI.hpp>

int main() {
int main(int argc, char** argv) {

bool flagPaused{true};
std::set<std::string> selected_serials;
bool flagPaused{true};
std::set<std::string> selected_serials;
std::string wsURI;

CLI::App app{"OmniView"};

WebSocketHandler wsHandler("ws://localhost:8080/");
app.add_option("-w, --wsuri", wsURI, "WebSocket URI")->type_name("");

// Start console handler thread
std::thread consoleThread(consoleHandler, std::ref(flagPaused), std::ref(selected_serials));
CLI11_PARSE(app, argc, argv);

// WebSocket handler thread
std::thread webSocketThread([&]() {
while (true) {
if (sampler.has_value() && !flagPaused) {
sampler->copyOut(captureData);
wsHandler.send(captureData, selected_serials);
}
WebSocketHandler wsHandler(wsURI);

// Start console handler thread
std::thread consoleThread(consoleHandler, std::ref(flagPaused), std::ref(selected_serials));

// WebSocket handler thread
std::thread webSocketThread([&]() {
while (true) {
if (sampler.has_value() && !flagPaused) {
sampler->copyOut(captureData);
wsHandler.send(captureData, selected_serials);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
});
}
});

consoleThread.join();
webSocketThread.detach();
consoleThread.join();
webSocketThread.detach();

return 0;
return 0;
}

0 comments on commit 5fcb351

Please sign in to comment.