Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
runei committed Jul 24, 2024
1 parent 7d804df commit 8d74794
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/internal_modules/roc_sndio/pump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ status::StatusCode Pump::run() {
code = status::StatusOK; // EOF is fine
}

code = close_devices_();
code = close_all_devices_();

roc_log(LogDebug, "pump: exiting main loop");

Expand All @@ -83,18 +83,20 @@ void Pump::stop() {
stop_ = 1;
}

status::StatusCode Pump::close_devices_() {
// Array of device pointers
status::StatusCode Pump::close_device_(IDevice* device) {
if (device) {
return device->close();
}
return status::StatusOK;
}

status::StatusCode Pump::close_all_devices_() {
IDevice* devices[] = { &main_source_, &sink_, backup_source_, current_source_ };

// Iterate over all devices and try to close them
for (size_t i = 0; i < sizeof(devices) / sizeof(devices[0]); ++i) {
IDevice* device = devices[i];
if (device) {
status::StatusCode device_code = device->close();
if (device_code != status::StatusOK) {
return device_code;
}
status::StatusCode device_code = close_device_(devices[i]);
if (device_code != status::StatusOK) {
return device_code;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/internal_modules/roc_sndio/pump.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class Pump : public core::NonCopyable<> {
status::StatusCode next_();
status::StatusCode switch_source_(ISource* new_source);
status::StatusCode transfer_frame_(ISource& source, ISink& sink);
status::StatusCode close_devices_();
status::StatusCode close_device_(IDevice* device);
status::StatusCode close_all_devices_();

audio::FrameFactory frame_factory_;

Expand Down

0 comments on commit 8d74794

Please sign in to comment.