diff --git a/include/data.hpp b/include/data.hpp new file mode 100644 index 0000000..6a2bc51 --- /dev/null +++ b/include/data.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include +#include + +#include + +#include "idle.hpp" + +using namespace std; + +enum SubscriptionType { + SUBSCRIPTION_TYPE_IDLE, + SUBSCRIPTION_TYPE_DRY_BOTH, + SUBSCRIPTION_TYPE_DRY_SINK, + SUBSCRIPTION_TYPE_DRY_SOURCE, +}; +enum EventType { + EVENT_TYPE_IDLE, + EVENT_TYPE_DRY_BOTH, + EVENT_TYPE_DRY_SINK, + EVENT_TYPE_DRY_SOURCE, + EVENT_TYPE_NONE, +}; + +struct Data { + pa_threaded_mainloop *mainloop; + pa_mainloop_api *mainloop_api; + pa_context *context; + + EventType eventCalled = EVENT_TYPE_NONE; + bool activeSource = false; + bool activeSink = false; + + SubscriptionType subscriptionType; + pa_subscription_mask_t pa_subscriptionType; + + Idle *idle = NULL; + + bool failed = false; + + Data(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api, + SubscriptionType subscriptionType, + pa_subscription_mask_t pa_subscriptionType, EventType eventType); + + void quit(int returnValue = 0); + + void handleAction(); + + private: + void print(bool isRunning); +}; diff --git a/include/idle.hpp b/include/idle.hpp new file mode 100644 index 0000000..a80e159 --- /dev/null +++ b/include/idle.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "idle-inhibit-unstable-v1-client-protocol.h" + +using namespace std; + +class Idle { + struct wl_compositor *compositor = NULL; + struct zwp_idle_inhibit_manager_v1 *wl_idle_inhibit_manager = NULL; + struct wl_surface *surface = NULL; + struct wl_display *display = NULL; + struct zwp_idle_inhibitor_v1 *idle = NULL; + + static void global_add(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t); + + static void global_remove(void *, struct wl_registry *, uint32_t); + + public: + Idle(); + + void update(bool isRunning); +}; diff --git a/include/pulse.hpp b/include/pulse.hpp new file mode 100644 index 0000000..6b76ec8 --- /dev/null +++ b/include/pulse.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "data.hpp" +#include "idle.hpp" + +class Pulse { + public: + int init(SubscriptionType subscriptionType, + pa_subscription_mask_t pa_subscriptionType, EventType eventType); + + private: + static void sink_input_info_callback(pa_context *, + const pa_sink_input_info *i, int, + void *userdata); + + static void source_output_info_callback(pa_context *, + const pa_source_output_info *i, int, + void *userdata); + + void getRunning(EventType eventType, Data *data, pa_context *context); + + static void subscribe_callback(pa_context *, + pa_subscription_event_type_t type, uint32_t, + void *userdata); + + static void context_state_callback(pa_context *c, void *userdata); + + static pa_context *getContext(pa_threaded_mainloop *mainloop, + pa_mainloop_api *mainloop_api, void *userdata); + + void connect(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api, + SubscriptionType subscriptionType, + pa_subscription_mask_t pa_subscriptionType, EventType eventType); + + pa_threaded_mainloop *getMainLoop(); + + pa_mainloop_api *getMainLoopApi(pa_threaded_mainloop *mainloop); +}; diff --git a/meson.build b/meson.build index 29e7f35..805772e 100644 --- a/meson.build +++ b/meson.build @@ -40,9 +40,13 @@ executable( 'sway-audio-idle-inhibit', [ './src/main.cpp', + './src/data.cpp', './src/pulse.cpp', './src/idle.cpp', ], + include_directories: [ + include_directories('include') + ], dependencies: [ dependency('libpulse', version: '>= 15.0'), wayland_protos, diff --git a/src/data.cpp b/src/data.cpp new file mode 100644 index 0000000..fb67004 --- /dev/null +++ b/src/data.cpp @@ -0,0 +1,40 @@ +#include "data.hpp" + +Data::Data(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api, + SubscriptionType subscriptionType, + pa_subscription_mask_t pa_subscriptionType, EventType eventType) { + this->mainloop = mainloop; + this->mainloop_api = mainloop_api; + this->subscriptionType = subscriptionType; + this->pa_subscriptionType = pa_subscriptionType; + this->eventCalled = eventType; + + if (subscriptionType == SUBSCRIPTION_TYPE_IDLE) idle = new Idle(); +} + +void Data::quit(int returnValue) { + mainloop_api->quit(mainloop_api, returnValue); + pa_threaded_mainloop_stop(mainloop); + pa_threaded_mainloop_free(mainloop); +} + +void Data::handleAction() { + switch (subscriptionType) { + case SUBSCRIPTION_TYPE_IDLE: + idle->update(activeSink || activeSource); + break; + case SUBSCRIPTION_TYPE_DRY_BOTH: + this->print(activeSink || activeSource); + break; + case SUBSCRIPTION_TYPE_DRY_SINK: + this->print(activeSink); + break; + case SUBSCRIPTION_TYPE_DRY_SOURCE: + this->print(activeSource); + break; + } +} + +void Data::print(bool isRunning) { + cout << (isRunning ? "RUNNING" : "NOT RUNNING") << endl; +} diff --git a/src/idle.cpp b/src/idle.cpp index 73f3295..e535b0a 100644 --- a/src/idle.cpp +++ b/src/idle.cpp @@ -1,81 +1,69 @@ +#include "idle.hpp" + #include -#include #include -#include "idle-inhibit-unstable-v1-client-protocol.h" - using namespace std; -class Idle { - struct wl_compositor *compositor = NULL; - struct zwp_idle_inhibit_manager_v1 *wl_idle_inhibit_manager = NULL; - struct wl_surface *surface = NULL; - struct wl_display *display = NULL; - struct zwp_idle_inhibitor_v1 *idle = NULL; - - static void global_add(void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t) { - Idle *idle = (Idle *)data; - if (strcmp(interface, wl_compositor_interface.name) == 0) { - idle->compositor = (wl_compositor *)wl_registry_bind( - registry, name, &wl_compositor_interface, 1); - } else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == - 0) { - idle->wl_idle_inhibit_manager = - (zwp_idle_inhibit_manager_v1 *)wl_registry_bind( - registry, name, &zwp_idle_inhibit_manager_v1_interface, 1); - } +void Idle::global_add(void *data, struct wl_registry *registry, uint32_t name, + const char *interface, uint32_t) { + Idle *idle = (Idle *)data; + if (strcmp(interface, wl_compositor_interface.name) == 0) { + idle->compositor = (wl_compositor *)wl_registry_bind( + registry, name, &wl_compositor_interface, 1); + } else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == + 0) { + idle->wl_idle_inhibit_manager = + (zwp_idle_inhibit_manager_v1 *)wl_registry_bind( + registry, name, &zwp_idle_inhibit_manager_v1_interface, 1); } +} - static void global_remove(void *, struct wl_registry *, uint32_t) { - // Do nothing - } - - public: - Idle() { - display = wl_display_connect(NULL); - if (display == NULL) { - fprintf(stderr, "failed to connect to wl_display\n"); - exit(1); - } +void Idle::global_remove(void *, struct wl_registry *, uint32_t) {} - const struct wl_registry_listener registry_listener = { - .global = global_add, - .global_remove = global_remove, - }; +Idle::Idle() { + display = wl_display_connect(NULL); + if (display == NULL) { + fprintf(stderr, "failed to connect to wl_display\n"); + exit(1); + } - struct wl_registry *registry = wl_display_get_registry(display); - wl_registry_add_listener(registry, ®istry_listener, this); - wl_display_roundtrip(display); + const struct wl_registry_listener registry_listener = { + .global = global_add, + .global_remove = global_remove, + }; - if (wl_idle_inhibit_manager == NULL) { - fprintf(stderr, "wl_idle_inhibit_manager is NULL\n"); - exit(1); - } - if (compositor == NULL) { - fprintf(stderr, "compositor is NULL\n"); - exit(1); - } + struct wl_registry *registry = wl_display_get_registry(display); + wl_registry_add_listener(registry, ®istry_listener, this); + wl_display_roundtrip(display); - surface = wl_compositor_create_surface(compositor); + if (wl_idle_inhibit_manager == NULL) { + fprintf(stderr, "wl_idle_inhibit_manager is NULL\n"); + exit(1); } + if (compositor == NULL) { + fprintf(stderr, "compositor is NULL\n"); + exit(1); + } + + surface = wl_compositor_create_surface(compositor); +} - void update(bool isRunning) { - if (isRunning) { - if (idle == NULL) { - idle = zwp_idle_inhibit_manager_v1_create_inhibitor( - wl_idle_inhibit_manager, surface); - wl_display_roundtrip(display); - } - cout << "IDLE INHIBITED" << endl; - } else { - if (idle != NULL) { - zwp_idle_inhibitor_v1_destroy(idle); - idle = NULL; - wl_display_roundtrip(display); - } - cout << "NOT IDLE INHIBITED" << endl; +void Idle::update(bool isRunning) { + if (isRunning) { + if (idle == NULL) { + idle = zwp_idle_inhibit_manager_v1_create_inhibitor( + wl_idle_inhibit_manager, surface); + wl_display_roundtrip(display); + } + cout << "IDLE INHIBITED" << endl; + } else { + if (idle != NULL) { + zwp_idle_inhibitor_v1_destroy(idle); + idle = NULL; + wl_display_roundtrip(display); } + cout << "NOT IDLE INHIBITED" << endl; } -}; +} diff --git a/src/main.cpp b/src/main.cpp index aa043dc..ea351ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include -#include "./pulse.cpp" +#include "pulse.hpp" void showHelp(char **argv) { cout << "Usage:" << endl; diff --git a/src/pulse.cpp b/src/pulse.cpp index 70a0e00..a9dc09b 100644 --- a/src/pulse.cpp +++ b/src/pulse.cpp @@ -1,3 +1,5 @@ +#include "pulse.hpp" + #include #include #include @@ -8,279 +10,202 @@ #include #include -#include "./idle.cpp" - -enum SubscriptionType { - SUBSCRIPTION_TYPE_IDLE, - SUBSCRIPTION_TYPE_DRY_BOTH, - SUBSCRIPTION_TYPE_DRY_SINK, - SUBSCRIPTION_TYPE_DRY_SOURCE, -}; -enum EventType { - EVENT_TYPE_IDLE, - EVENT_TYPE_DRY_BOTH, - EVENT_TYPE_DRY_SINK, - EVENT_TYPE_DRY_SOURCE, - EVENT_TYPE_NONE, -}; - -struct Data { - pa_threaded_mainloop *mainloop; - pa_mainloop_api *mainloop_api; - pa_context *context; - - EventType eventCalled = EVENT_TYPE_NONE; - bool activeSource = false; - bool activeSink = false; - - SubscriptionType subscriptionType; - pa_subscription_mask_t pa_subscriptionType; - - Idle *idle = NULL; - - bool failed = false; - - Data(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api, - SubscriptionType subscriptionType, - pa_subscription_mask_t pa_subscriptionType, EventType eventType) { - this->mainloop = mainloop; - this->mainloop_api = mainloop_api; - this->subscriptionType = subscriptionType; - this->pa_subscriptionType = pa_subscriptionType; - this->eventCalled = eventType; - - if (subscriptionType == SUBSCRIPTION_TYPE_IDLE) idle = new Idle(); +int Pulse::init(SubscriptionType subscriptionType, + pa_subscription_mask_t pa_subscriptionType, + EventType eventType) { + pa_threaded_mainloop *mainloop = getMainLoop(); + pa_mainloop_api *mainloop_api = getMainLoopApi(mainloop); + if (pa_threaded_mainloop_start(mainloop)) { + fprintf(stderr, "pa_threaded_mainloop_start() failed.\n"); + return 1; } - - void quit(int returnValue = 0) { - mainloop_api->quit(mainloop_api, returnValue); - pa_threaded_mainloop_stop(mainloop); - pa_threaded_mainloop_free(mainloop); + connect(mainloop, mainloop_api, subscriptionType, pa_subscriptionType, + eventType); + return 0; +} + +void Pulse::sink_input_info_callback(pa_context *, const pa_sink_input_info *i, + int, void *userdata) { + Data *data = (Data *)userdata; + if (i && !i->corked) data->activeSink = true; + pa_threaded_mainloop_signal(data->mainloop, 0); +} + +void Pulse::source_output_info_callback(pa_context *, + const pa_source_output_info *i, int, + void *userdata) { + Data *data = (Data *)userdata; + if (i && !i->corked) data->activeSource = true; + pa_threaded_mainloop_signal(data->mainloop, 0); +} + +void Pulse::getRunning(EventType eventType, Data *data, pa_context *context) { + pa_threaded_mainloop_lock(data->mainloop); + pa_operation *op = NULL; + switch (eventType) { + case EVENT_TYPE_DRY_SINK: + data->activeSink = false; + op = pa_context_get_sink_input_info_list(context, + sink_input_info_callback, data); + break; + case EVENT_TYPE_DRY_SOURCE: + data->activeSource = false; + op = pa_context_get_source_output_info_list( + context, source_output_info_callback, data); + break; + default: + fprintf(stderr, "Operation Default!\n"); + pa_threaded_mainloop_unlock(data->mainloop); + return; } - - void handleAction() { - switch (subscriptionType) { - case SUBSCRIPTION_TYPE_IDLE: - idle->update(activeSink || activeSource); - break; - case SUBSCRIPTION_TYPE_DRY_BOTH: - this->print(activeSink || activeSource); - break; - case SUBSCRIPTION_TYPE_DRY_SINK: - this->print(activeSink); - break; - case SUBSCRIPTION_TYPE_DRY_SOURCE: - this->print(activeSource); - break; - } + if (!op) { + pa_threaded_mainloop_unlock(data->mainloop); + fprintf(stderr, "Operation failed!\n"); + return; } - - private: - void print(bool isRunning) { - cout << (isRunning ? "RUNNING" : "NOT RUNNING") << endl; + while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) { + pa_threaded_mainloop_wait(data->mainloop); } -}; - -class Pulse { - public: - int init(SubscriptionType subscriptionType, - pa_subscription_mask_t pa_subscriptionType, EventType eventType) { - pa_threaded_mainloop *mainloop = getMainLoop(); - pa_mainloop_api *mainloop_api = getMainLoopApi(mainloop); - if (pa_threaded_mainloop_start(mainloop)) { - fprintf(stderr, "pa_threaded_mainloop_start() failed.\n"); - return 1; - } - connect(mainloop, mainloop_api, subscriptionType, pa_subscriptionType, - eventType); - return 0; + pa_operation_unref(op); + pa_threaded_mainloop_unlock(data->mainloop); +} + +void Pulse::subscribe_callback(pa_context *, pa_subscription_event_type_t type, + uint32_t, void *userdata) { + Data *data = (Data *)userdata; + EventType eventType; + switch (type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { + case PA_SUBSCRIPTION_EVENT_SINK: + eventType = EVENT_TYPE_DRY_SINK; + break; + case PA_SUBSCRIPTION_EVENT_SOURCE: + eventType = EVENT_TYPE_DRY_SOURCE; + break; + default: + return; } - - private: - static void sink_input_info_callback(pa_context *, - const pa_sink_input_info *i, int, - void *userdata) { - Data *data = (Data *)userdata; - if (i && !i->corked) data->activeSink = true; - pa_threaded_mainloop_signal(data->mainloop, 0); + if (data->subscriptionType == SUBSCRIPTION_TYPE_IDLE) { + eventType = EVENT_TYPE_IDLE; + } else if (data->subscriptionType == SUBSCRIPTION_TYPE_DRY_BOTH) { + eventType = EVENT_TYPE_DRY_BOTH; } - - static void source_output_info_callback(pa_context *, - const pa_source_output_info *i, int, - void *userdata) { - Data *data = (Data *)userdata; - if (i && !i->corked) data->activeSource = true; - pa_threaded_mainloop_signal(data->mainloop, 0); + data->eventCalled = eventType; + pa_threaded_mainloop_signal(data->mainloop, 0); +} + +void Pulse::context_state_callback(pa_context *c, void *userdata) { + Data *data = (Data *)userdata; + switch (pa_context_get_state(c)) { + case PA_CONTEXT_CONNECTING: + case PA_CONTEXT_AUTHORIZING: + case PA_CONTEXT_SETTING_NAME: + break; + case PA_CONTEXT_READY: + pa_threaded_mainloop_signal(data->mainloop, 0); + break; + case PA_CONTEXT_TERMINATED: + case PA_CONTEXT_FAILED: + fprintf(stderr, "PulseAudio connection lost. Will retry connection.\n"); + data->failed = true; + pa_threaded_mainloop_signal(data->mainloop, 0); + break; + default: + fprintf(stderr, "Connection failure: %s\n", + pa_strerror(pa_context_errno(c))); + data->quit(1); + exit(1); + break; } +} - void getRunning(EventType eventType, Data *data, pa_context *context) { - pa_threaded_mainloop_lock(data->mainloop); - pa_operation *op = NULL; - switch (eventType) { - case EVENT_TYPE_DRY_SINK: - data->activeSink = false; - op = pa_context_get_sink_input_info_list( - context, sink_input_info_callback, data); - break; - case EVENT_TYPE_DRY_SOURCE: - data->activeSource = false; - op = pa_context_get_source_output_info_list( - context, source_output_info_callback, data); - break; - default: - fprintf(stderr, "Operation Default!\n"); - pa_threaded_mainloop_unlock(data->mainloop); - 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); - } - pa_operation_unref(op); - pa_threaded_mainloop_unlock(data->mainloop); - } +pa_context *Pulse::getContext(pa_threaded_mainloop *mainloop, + pa_mainloop_api *mainloop_api, void *userdata) { + Data *data = (Data *)userdata; - static void subscribe_callback(pa_context *, - pa_subscription_event_type_t type, uint32_t, - void *userdata) { - Data *data = (Data *)userdata; - EventType eventType; - switch (type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { - case PA_SUBSCRIPTION_EVENT_SINK: - eventType = EVENT_TYPE_DRY_SINK; - break; - case PA_SUBSCRIPTION_EVENT_SOURCE: - eventType = EVENT_TYPE_DRY_SOURCE; - break; - default: - return; - } - if (data->subscriptionType == SUBSCRIPTION_TYPE_IDLE) { - eventType = EVENT_TYPE_IDLE; - } else if (data->subscriptionType == SUBSCRIPTION_TYPE_DRY_BOTH) { - eventType = EVENT_TYPE_DRY_BOTH; - } - data->eventCalled = eventType; - pa_threaded_mainloop_signal(data->mainloop, 0); + pa_context *context = pa_context_new(mainloop_api, "PulseAudio Test"); + if (!context) { + fprintf(stderr, "pa_context_new() failed\n"); + exit(1); } - static void context_state_callback(pa_context *c, void *userdata) { - Data *data = (Data *)userdata; - switch (pa_context_get_state(c)) { - case PA_CONTEXT_CONNECTING: - case PA_CONTEXT_AUTHORIZING: - case PA_CONTEXT_SETTING_NAME: - break; - case PA_CONTEXT_READY: - pa_threaded_mainloop_signal(data->mainloop, 0); - break; - case PA_CONTEXT_TERMINATED: - case PA_CONTEXT_FAILED: - fprintf(stderr, "PulseAudio connection lost. Will retry connection.\n"); - data->failed = true; - pa_threaded_mainloop_signal(data->mainloop, 0); - break; - default: - fprintf(stderr, "Connection failure: %s\n", - pa_strerror(pa_context_errno(c))); - data->quit(1); - exit(1); - break; - } + pa_threaded_mainloop_lock(mainloop); + if (pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { + fprintf(stderr, "pa_context_connect() failed: %s\n", + pa_strerror(pa_context_errno(context))); + exit(1); } + pa_context_set_state_callback(context, context_state_callback, data); + while (pa_context_get_state(context) != PA_CONTEXT_READY) { + pa_threaded_mainloop_wait(mainloop); + } + pa_threaded_mainloop_unlock(mainloop); - static pa_context *getContext(pa_threaded_mainloop *mainloop, - pa_mainloop_api *mainloop_api, void *userdata) { - Data *data = (Data *)userdata; - - pa_context *context = pa_context_new(mainloop_api, "PulseAudio Test"); - if (!context) { - fprintf(stderr, "pa_context_new() failed\n"); - exit(1); - } - - pa_threaded_mainloop_lock(mainloop); - if (pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { - fprintf(stderr, "pa_context_connect() failed: %s\n", - pa_strerror(pa_context_errno(context))); - exit(1); - } - pa_context_set_state_callback(context, context_state_callback, data); - while (pa_context_get_state(context) != PA_CONTEXT_READY) { - pa_threaded_mainloop_wait(mainloop); - } - pa_threaded_mainloop_unlock(mainloop); - - data->context = context; - data->failed = false; + data->context = context; + data->failed = false; - pa_context_set_subscribe_callback(context, subscribe_callback, data); - pa_context_subscribe(context, data->pa_subscriptionType, NULL, data); - return context; - } + pa_context_set_subscribe_callback(context, subscribe_callback, data); + pa_context_subscribe(context, data->pa_subscriptionType, NULL, data); + return context; +} - void connect(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api, - SubscriptionType subscriptionType, - pa_subscription_mask_t pa_subscriptionType, - EventType eventType) { - Data *data = new Data(mainloop, mainloop_api, subscriptionType, - pa_subscriptionType, eventType); +void Pulse::connect(pa_threaded_mainloop *mainloop, + pa_mainloop_api *mainloop_api, + SubscriptionType subscriptionType, + pa_subscription_mask_t pa_subscriptionType, + EventType eventType) { + Data *data = new Data(mainloop, mainloop_api, subscriptionType, + pa_subscriptionType, eventType); - pa_context *context = getContext(mainloop, mainloop_api, data); + pa_context *context = getContext(mainloop, mainloop_api, data); - for (;;) { - if (data->failed) { - context = getContext(data->mainloop, data->mainloop_api, data); - } - switch (data->eventCalled) { - case EVENT_TYPE_IDLE: - case EVENT_TYPE_DRY_BOTH: - 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; - } + for (;;) { + if (data->failed) { + context = getContext(data->mainloop, data->mainloop_api, data); + } + switch (data->eventCalled) { + case EVENT_TYPE_IDLE: + case EVENT_TYPE_DRY_BOTH: + 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; } } +} - pa_threaded_mainloop *getMainLoop() { - pa_threaded_mainloop *mainloop = pa_threaded_mainloop_new(); - if (!mainloop) { - fprintf(stderr, "pa_mainloop_new() failed.\n"); - exit(1); - } - return mainloop; +pa_threaded_mainloop *Pulse::getMainLoop() { + pa_threaded_mainloop *mainloop = pa_threaded_mainloop_new(); + if (!mainloop) { + fprintf(stderr, "pa_mainloop_new() failed.\n"); + exit(1); } + return mainloop; +} - pa_mainloop_api *getMainLoopApi(pa_threaded_mainloop *mainloop) { - pa_threaded_mainloop_lock(mainloop); - pa_mainloop_api *mainloop_api = pa_threaded_mainloop_get_api(mainloop); - pa_threaded_mainloop_unlock(mainloop); +pa_mainloop_api *Pulse::getMainLoopApi(pa_threaded_mainloop *mainloop) { + pa_threaded_mainloop_lock(mainloop); + pa_mainloop_api *mainloop_api = pa_threaded_mainloop_get_api(mainloop); + pa_threaded_mainloop_unlock(mainloop); - if (pa_signal_init(mainloop_api) != 0) { - fprintf(stderr, "pa_signal_init() failed\n"); - exit(1); - } - return mainloop_api; + if (pa_signal_init(mainloop_api) != 0) { + fprintf(stderr, "pa_signal_init() failed\n"); + exit(1); } -}; + return mainloop_api; +}