Skip to content

Commit

Permalink
Add a device search function and improve the orderly shutdown
Browse files Browse the repository at this point in the history
- Add the 'searchDevices' function to initialize and search for devices
- Implement the 'stopAllDevices' function to stop all devices and delete device lists
- Update the 'consoleHandler' to use 'searchDevices'
- Integrate 'stopAllDevices' into 'signalHandler' for a more comprehensive shutdown process
- Add CLI flag '--search' to allow users to search for devices via the command line
- Ensure an orderly shutdown on SIGINT by stopping all devices

These changes improve the application by providing a dedicated device search function and ensuring a thorough cleanup on shutdown.
  • Loading branch information
arkadiusz committed Jul 26, 2024
1 parent 3920485 commit 391b9da
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ void initDevices() {
// std::cout << "Device initialization complete.\n";
}

void searchDevices() {
initDevices();
if (devices.empty()) {
std::cout << "No devices found.\n";
}
stopAllDevices();
}

void stopAllDevices() {
if (sampler.has_value()) {
for (auto &device : sampler->sampleDevices) {
device.first->send(Omniscope::Stop{});
}
}
devices.clear();
deviceManager.clearDevices();
}

void consoleHandler(bool &flagPaused, std::set<std::string>& selected_serials) {
std::string input;
while (running) {
Expand All @@ -53,9 +71,8 @@ void consoleHandler(bool &flagPaused, std::set<std::string>& selected_serials) {
input.erase(0, pos + 1);
}
selected_serials.insert(input);
}
else {
std::cout << "No devices fpound.\n";
} else {
std::cout << "No devices found.\n";
}
}
else if (input == "Start") {
Expand Down Expand Up @@ -97,5 +114,6 @@ void signalHandler(int signal) {
if (signal == SIGINT) {
std::cout << "\nSIGINT received, shutting down gracefully...\n";
running = false;
stopAllDevices();
}
}
3 changes: 3 additions & 0 deletions src/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ inline std::map<Omniscope::Id, std::vector<std::pair<double, double>>> captureDa
inline std::atomic<bool> running{true};

void initDevices();
void searchDevices(std::set<std::string>& selected_serials);
void consoleHandler(bool &flagPaused, std::set<std::string>& selected_serials);
void signalHandler(int signal);
void stopAllDevices();
void searchDevices();

#endif
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ int main(int argc, char** argv) {
bool flagPaused{true};
std::set<std::string> selected_serials;
std::string wsURI;
bool search = false;

CLI::App app{"OmniView"};

app.add_option("-w, --wsuri", wsURI, "WebSocket URI")->type_name("");
app.add_flag("--search", search, "Search for devices");

CLI11_PARSE(app, argc, argv);

if (search) {
searchDevices();
return 0;
}

WebSocketHandler wsHandler(wsURI);

// Signal handler for SIGINT
Expand Down

0 comments on commit 391b9da

Please sign in to comment.