Skip to content

Commit

Permalink
For loop now waits until subscription gets called
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed Aug 29, 2021
1 parent 87c179e commit 043874d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
project(
'SwayAudioIdleInhibit',
'c', 'cpp',
default_options: ['warning_level=2'],
version: '0.1',
default_options: ['warning_level=3', 'cpp_std=c++14'],
)

wayland_protos = dependency('wayland-protocols')
Expand Down
22 changes: 17 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ struct Data {
void handleAction() {
switch (subscriptionType) {
case SUBSCRIPTION_TYPE_IDLE:
if (!idle) idle = new Idle();
idle->update(activeSink || activeSource);
break;
case SUBSCRIPTION_TYPE_DRY_BOTH:
Expand Down Expand Up @@ -107,9 +106,15 @@ void getRunning(EventType eventType, Data *data, pa_context *context) {
context, source_output_info_callback, data);
break;
default:
fprintf(stderr, "Operation Default!\n");
pa_threaded_mainloop_unlock(data->mainloop);
return;
}
if (!op) return;
if (!op) {
pa_threaded_mainloop_unlock(data->mainloop);
fprintf(stderr, "Operation failed!\n");
return;
}
while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) {
pa_threaded_mainloop_wait(data->mainloop);
}
Expand All @@ -124,9 +129,11 @@ void subscribe_callback(pa_context *, pa_subscription_event_type_t type,
switch (type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
case PA_SUBSCRIPTION_EVENT_SINK:
data->eventCalled = isBoth ? EVENT_TYPE_IDLE : EVENT_TYPE_DRY_SINK;
pa_threaded_mainloop_signal(data->mainloop, 0);
break;
case PA_SUBSCRIPTION_EVENT_SOURCE:
data->eventCalled = isBoth ? EVENT_TYPE_IDLE : EVENT_TYPE_DRY_SOURCE;
pa_threaded_mainloop_signal(data->mainloop, 0);
break;
default:
return;
Expand Down Expand Up @@ -208,19 +215,24 @@ void connect(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api,
getRunning(EVENT_TYPE_DRY_SINK, data, context);
getRunning(EVENT_TYPE_DRY_SOURCE, data, context);
data->handleAction();
data->eventCalled = EVENT_TYPE_NONE;
break;
case EVENT_TYPE_DRY_SINK:
getRunning(data->eventCalled, data, context);
data->handleAction();
data->eventCalled = EVENT_TYPE_NONE;
break;
case EVENT_TYPE_DRY_SOURCE:
getRunning(data->eventCalled, data, context);
data->handleAction();
data->eventCalled = EVENT_TYPE_NONE;
break;
case EVENT_TYPE_NONE:
pa_threaded_mainloop_lock(mainloop);
pa_threaded_mainloop_wait(mainloop);
pa_threaded_mainloop_unlock(mainloop);
break;
default:
continue;
}
data->eventCalled = EVENT_TYPE_NONE;
}
}

Expand Down

0 comments on commit 043874d

Please sign in to comment.