From 3f266e3460eeea05a7a80aa4d2a29d2f418c13da Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 15 Aug 2004 13:15:18 +0000 Subject: Rename ServerInfo.{cc,hh} to ServerInfoManager.{cc,hh} git-svn-id: file:///home/lennart/svn/public/paman/trunk@10 cdefa82f-4ce1-0310-97f5-ab6066f37c3c --- configure.ac | 4 +- src/ClientWindow.hh | 2 +- src/MainWindow.hh | 2 +- src/Makefile.am | 2 +- src/ModuleWindow.hh | 2 +- src/ServerInfo.cc | 407 ----------------------------------------------- src/ServerInfo.hh | 130 --------------- src/ServerInfoManager.cc | 407 +++++++++++++++++++++++++++++++++++++++++++++++ src/ServerInfoManager.hh | 130 +++++++++++++++ src/SinkWindow.hh | 2 +- src/paman.hh | 3 +- 11 files changed, 545 insertions(+), 546 deletions(-) delete mode 100644 src/ServerInfo.cc delete mode 100644 src/ServerInfo.hh create mode 100644 src/ServerInfoManager.cc create mode 100644 src/ServerInfoManager.hh diff --git a/configure.ac b/configure.ac index d2fb3bc..be10066 100644 --- a/configure.ac +++ b/configure.ac @@ -40,8 +40,8 @@ AC_SUBST(GUILIBS_CFLAGS) AC_SUBST(GUILIBS_LIBS) if test -d ../polypaudio ; then - POLYP_CFLAGS='-I$(TOPDIR)/../polypaudio' - POLYP_LIBS='-L$(TOPDIR)/../polypaudio/polyp/.libs -lpolyp -lpolyp-mainloop-glib -lpolyp-mainloop-glib -lpolyp-error' + POLYP_CFLAGS='-I$(top_srcdir)/../polypaudio' + POLYP_LIBS='-L$(top_srcdir)/../polypaudio/polyp/.libs -lpolyp -lpolyp-mainloop-glib -lpolyp-mainloop-glib -lpolyp-error' echo "*** Found polypaudio in ../polypaudio, using that version ***" else PKG_CHECK_MODULES(POLYP, [ polyplib polyplib-mainloop polyplib-mainloop-glib polyplib-error ]) diff --git a/src/ClientWindow.hh b/src/ClientWindow.hh index 61a1973..8440daf 100644 --- a/src/ClientWindow.hh +++ b/src/ClientWindow.hh @@ -6,7 +6,7 @@ class ClientWindow; -#include "ServerInfo.hh" +#include "ServerInfoManager.hh" class ClientWindow : public Gtk::Window { public: diff --git a/src/MainWindow.hh b/src/MainWindow.hh index 2d5f173..0157f9c 100644 --- a/src/MainWindow.hh +++ b/src/MainWindow.hh @@ -7,7 +7,7 @@ class MainWinow; -#include "ServerInfo.hh" +#include "ServerInfoManager.hh" class MainWindow : public Gtk::Window { public: diff --git a/src/Makefile.am b/src/Makefile.am index 3905db3..ff42d0e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,7 +4,7 @@ bin_PROGRAMS=paman paman_SOURCES=MainWindow.cc MainWindow.hh \ SinkWindow.cc SinkWindow.hh \ SourceWindow.cc SourceWindow.hh \ - ServerInfo.cc ServerInfo.hh \ + ServerInfoManager.cc ServerInfoManager.hh \ paman.cc paman.hh \ ClientWindow.cc ClientWindow.hh \ ModuleWindow.cc ModuleWindow.hh diff --git a/src/ModuleWindow.hh b/src/ModuleWindow.hh index c28af52..989e85a 100644 --- a/src/ModuleWindow.hh +++ b/src/ModuleWindow.hh @@ -6,7 +6,7 @@ class ModuleWindow; -#include "ServerInfo.hh" +#include "ServerInfoManager.hh" class ModuleWindow : public Gtk::Window { public: diff --git a/src/ServerInfo.cc b/src/ServerInfo.cc deleted file mode 100644 index 8362f75..0000000 --- a/src/ServerInfo.cc +++ /dev/null @@ -1,407 +0,0 @@ -#include -#include - -#include "ServerInfo.hh" -#include "paman.hh" - -SinkInfo::SinkInfo(const struct pa_sink_info &i) : - name(i.name), - description(i.description), - index(i.index), - sample_spec(i.sample_spec), - monitor_source(i.monitor_source), - owner_module(i.owner_module), - volume(i.volume), - latency(i.latency), - window(NULL) { -} - -SinkInfo::~SinkInfo() { - if (window) - delete window; -} - -void SinkInfo::update(const struct pa_sink_info &i) { - name = Glib::ustring(i.name); - description = i.description; - index = i.index; - sample_spec = i.sample_spec; - monitor_source = i.monitor_source; - owner_module = i.owner_module; - volume = i.volume; - latency = i.latency; - - if (window) - window->updateInfo(*this); - g_assert(mainWindow); - mainWindow->updateInfo(*this); -} - -void SinkInfo::showWindow() { - if (window) - window->present(); - else { - window = SinkWindow::create(); - window->updateInfo(*this); - window->show(); - } -} - -SourceInfo::SourceInfo(const struct pa_source_info &i) : - name(i.name), - description(i.description), - index(i.index), - sample_spec(i.sample_spec), - owner_module(i.owner_module), - monitor_of_sink(i.monitor_of_sink), - window(NULL) { -} - -SourceInfo::~SourceInfo() { - if (window) - delete window; -} - -void SourceInfo::update(const struct pa_source_info &i) { - name = i.name; - description = i.description; - index = i.index; - sample_spec = i.sample_spec; - owner_module = i.owner_module; - monitor_of_sink = i.monitor_of_sink; - - if (window) - window->updateInfo(*this); - g_assert(mainWindow); - mainWindow->updateInfo(*this); -} - -void SourceInfo::showWindow() { - if (window) - window->present(); - else { - window = SourceWindow::create(); - window->updateInfo(*this); - window->show(); - } -} - -ClientInfo::ClientInfo(const struct pa_client_info &i) : - index(i.index), - name(i.name), - protocol_name(i.protocol_name), - owner_module(i.owner_module), - window(NULL) { -} - -ClientInfo::~ClientInfo() { - if (window) - delete window; -} - -void ClientInfo::update(const struct pa_client_info &i) { - name = i.name; - protocol_name = i.protocol_name; - index = i.index; - owner_module = i.owner_module; - - if (window) - window->updateInfo(*this); - - g_assert(mainWindow); - mainWindow->updateInfo(*this); -} - -void ClientInfo::showWindow() { - if (window) - window->present(); - else { - window = ClientWindow::create(); - window->updateInfo(*this); - window->show(); - } -} - -ModuleInfo::ModuleInfo(const struct pa_module_info &i) : - index(i.index), - name(i.name), - argument(i.argument), - autoloaded(i.auto_unload), - used(i.n_used), - window(NULL) { -} - -ModuleInfo::~ModuleInfo() { - if (window) - delete window; -} - -void ModuleInfo::update(const struct pa_module_info &i) { - name = i.name; - argument = i.argument; - index = i.index; - autoloaded = i.auto_unload; - used = i.n_used; - - if (window) - window->updateInfo(*this); - g_assert(mainWindow); - mainWindow->updateInfo(*this); -} - -void ModuleInfo::showWindow() { - if (window) - window->present(); - else { - window = ModuleWindow::create(); - window->updateInfo(*this); - window->show(); - } -} - -extern "C" { - static void server_info_callback(struct pa_context *c, const struct pa_server_info *i, void *userdata); - static void sink_info_callback(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata); - static void source_info_callback(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata); - static void client_info_callback(struct pa_context *c, const struct pa_client_info *i, int is_last, void *userdata); - static void module_info_callback(struct pa_context *c, const struct pa_module_info *i, int is_last, void *userdata); - static void subscribe_callback(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata); -}; - -static void server_info_callback(struct pa_context *c, const struct pa_server_info *i, void *userdata) { - ServerInfoManager *si = (ServerInfoManager*) userdata; - - if (!i) { - mainWindow->showFailure(pa_strerror(pa_context_errno(c))); - return; - } - - mainWindow->updateInfo(*i); -} - -static void sink_info_callback(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata) { - ServerInfoManager *si = (ServerInfoManager*) userdata; - if (i) si->updateInfo(*i); -} - -static void source_info_callback(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata) { - ServerInfoManager *si = (ServerInfoManager*) userdata; - if (i) si->updateInfo(*i); -} - -static void client_info_callback(struct pa_context *c, const struct pa_client_info *i, int is_last, void *userdata) { - ServerInfoManager *si = (ServerInfoManager*) userdata; - if (i) si->updateInfo(*i); -} - -static void module_info_callback(struct pa_context *c, const struct pa_module_info *i, int is_last, void *userdata) { - ServerInfoManager *si = (ServerInfoManager*) userdata; - if (i) si->updateInfo(*i); -} - -static void subscribe_callback(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata) { - ServerInfoManager *si = (ServerInfoManager*) userdata; - - //fprintf(stderr, "EV: %u %u\n", t, index); - - switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { - case PA_SUBSCRIPTION_EVENT_SINK: - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) - si->removeSinkInfo(index); - else - pa_operation_unref(pa_context_get_sink_info_by_index(c, index, sink_info_callback, si)); - break; - case PA_SUBSCRIPTION_EVENT_SOURCE: - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) - si->removeSourceInfo(index); - else - pa_operation_unref(pa_context_get_source_info_by_index(c, index, source_info_callback, si)); - break; - case PA_SUBSCRIPTION_EVENT_MODULE: - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) - si->removeModuleInfo(index); - else - pa_operation_unref(pa_context_get_module_info(c, index, module_info_callback, si)); - break; - case PA_SUBSCRIPTION_EVENT_CLIENT: - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) - si->removeClientInfo(index); - else - pa_operation_unref(pa_context_get_client_info(c, index, client_info_callback, si)); - break; - case PA_SUBSCRIPTION_EVENT_SINK_INPUT: -// fprintf(stderr, "SINK INPUT EVENT\n"); - break; - case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT: -// fprintf(stderr, "SOURCE OUTPUT EVENT\n"); - break; - default: -// fprintf(stderr, "OTHER EVENT\n"); - break; - } -} - -ServerInfoManager::ServerInfoManager(struct pa_context &c) : - context(c) { - pa_operation_unref(pa_context_get_server_info(&c, server_info_callback, this)); - pa_operation_unref(pa_context_get_sink_info_list(&c, sink_info_callback, this)); - pa_operation_unref(pa_context_get_source_info_list(&c, source_info_callback, this)); - pa_operation_unref(pa_context_get_module_info_list(&c, module_info_callback, this)); - pa_operation_unref(pa_context_get_client_info_list(&c, client_info_callback, this)); - - pa_context_set_subscribe_callback(&c, subscribe_callback, this); - - pa_operation_unref(pa_context_subscribe(&c, (enum pa_subscription_mask) - (PA_SUBSCRIPTION_MASK_SINK| - PA_SUBSCRIPTION_MASK_SOURCE| - PA_SUBSCRIPTION_MASK_MODULE| - PA_SUBSCRIPTION_MASK_SINK_INPUT| - PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| - PA_SUBSCRIPTION_MASK_CLIENT), NULL, NULL)); -} - - -ServerInfoManager::~ServerInfoManager() { - for (std::map::iterator i = sinks.begin(); i != sinks.end(); i++) - delete i->second; - - for (std::map::iterator i = sources.begin(); i != sources.end(); i++) - delete i->second; - - for (std::map::iterator i = clients.begin(); i != clients.end(); i++) - delete i->second; - - for (std::map::iterator i = modules.begin(); i != modules.end(); i++) - delete i->second; -} - -void ServerInfoManager::updateInfo(const struct pa_sink_info &i) { - SinkInfo *si; - if ((si = sinks[i.index])) - si->update(i); - else { - SinkInfo *n = new SinkInfo(i); - sinks[i.index] = n; - mainWindow->updateInfo(*n); - } -} - -void ServerInfoManager::updateInfo(const struct pa_source_info &i) { - SourceInfo *si; - if ((si = sources[i.index])) - si->update(i); - else { - SourceInfo *n = new SourceInfo(i); - sources[i.index] = n; - mainWindow->updateInfo(*n); - } -} - -void ServerInfoManager::updateInfo(const struct pa_client_info &i) { - ClientInfo *ci; - - if ((ci = clients[i.index])) - ci->update(i); - else { - ClientInfo *n = new ClientInfo(i); - clients[i.index] = n; - mainWindow->updateInfo(*n); - } -} -void ServerInfoManager::updateInfo(const struct pa_module_info &i) { - ModuleInfo *si; - if ((si = modules[i.index])) - si->update(i); - else { - ModuleInfo *n = new ModuleInfo(i); - modules[i.index] = n; - mainWindow->updateInfo(*n); - } -} - -void ServerInfoManager::showSinkWindow(uint32_t index) { - SinkInfo *i; - - if ((i = sinks[index])) - i->showWindow(); -} - -void ServerInfoManager::showSourceWindow(uint32_t index) { - SourceInfo *i; - - if ((i = sources[index])) - i->showWindow(); -} - -void ServerInfoManager::showClientWindow(uint32_t index) { - ClientInfo *i; - - if ((i = clients[index])) - i->showWindow(); -} - -void ServerInfoManager::showModuleWindow(uint32_t index) { - ModuleInfo *i; - - if ((i = modules[index])) - i->showWindow(); -} - - -SourceInfo* ServerInfoManager::getSourceInfo(uint32_t index) { - return sources[index]; -} - -SinkInfo* ServerInfoManager::getSinkInfo(uint32_t index) { - return sinks[index]; -} - -ClientInfo* ServerInfoManager::getClientInfo(uint32_t index) { - return clients[index]; -} - -ModuleInfo* ServerInfoManager::getModuleInfo(uint32_t index) { - return modules[index]; -} - -void ServerInfoManager::removeSinkInfo(uint32_t index) { - SinkInfo *i; - - if ((i = sinks[index])) { - sinks.erase(index); - mainWindow->removeInfo(*i); - delete i; - } -} - -void ServerInfoManager::removeSourceInfo(uint32_t index) { - SourceInfo *i; - if ((i = sources[index])) { - sources.erase(index); - mainWindow->removeInfo(*i); - delete i; - } -} - -void ServerInfoManager::removeClientInfo(uint32_t index) { - ClientInfo *i; - - if ((i = clients[index])) { - clients.erase(index); - mainWindow->removeInfo(*i); - delete i; - } -} - -void ServerInfoManager::removeModuleInfo(uint32_t index) { - ModuleInfo *i; - if ((i = modules[index])) { - modules.erase(index); - mainWindow->removeInfo(*i); - delete i; - } -} - -void ServerInfoManager::setSinkVolume(uint32_t index, uint32_t volume) { - pa_operation_unref(pa_context_set_sink_volume_by_index(&context, index, volume, NULL, NULL)); -} diff --git a/src/ServerInfo.hh b/src/ServerInfo.hh deleted file mode 100644 index 5c22f64..0000000 --- a/src/ServerInfo.hh +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef fooserverinfohhfoo -#define fooserverinfohhfoo - -#include -#include - -#include - -class SinkInfo; -class SourceInfo; -class ServerInfo; -class ClientInfo; -class ModuleInfo; - -#include "SinkWindow.hh" -#include "SourceWindow.hh" -#include "ClientWindow.hh" -#include "ModuleWindow.hh" -#include "MainWindow.hh" - -class SinkInfo { -public: - - SinkInfo(const struct pa_sink_info &i); - ~SinkInfo(); - - void update(const struct pa_sink_info &i); - void showWindow(); - - Glib::ustring name, description; - uint32_t index; - struct pa_sample_spec sample_spec; - uint32_t monitor_source; - uint32_t owner_module; - uint32_t volume; - uint32_t latency; - - Gtk::TreeRowReference treeRef; - - SinkWindow *window; -}; - -class SourceInfo { -public: - SourceInfo(const struct pa_source_info &i); - ~SourceInfo(); - - void update(const struct pa_source_info &i); - void showWindow(); - - Glib::ustring name, description; - uint32_t index; - struct pa_sample_spec sample_spec; - uint32_t owner_module; - uint32_t monitor_of_sink; - - Gtk::TreeRowReference treeRef; - SourceWindow *window; -}; - -class ModuleInfo { -public: - ModuleInfo(const struct pa_module_info &i); - ~ModuleInfo(); - - void update(const struct pa_module_info &i); - void showWindow(); - - uint32_t index; - Glib::ustring name, argument; - bool autoloaded; - uint32_t used; - - Gtk::TreeRowReference treeRef; - ModuleWindow *window; -}; - -class ClientInfo { -public: - ClientInfo(const struct pa_client_info &i); - ~ClientInfo(); - - void update(const struct pa_client_info &i); - void showWindow(); - - uint32_t index; - Glib::ustring name, protocol_name; - uint32_t owner_module; - - Gtk::TreeRowReference treeRef; - ClientWindow *window; -}; - -class ServerInfoManager { -public: - ServerInfoManager(struct pa_context &c); - ~ServerInfoManager(); - - void updateInfo(const struct pa_sink_info &i); - void updateInfo(const struct pa_source_info &i); - void updateInfo(const struct pa_client_info &i); - void updateInfo(const struct pa_module_info &i); - - void showSinkWindow(uint32_t index); - void showSourceWindow(uint32_t index); - void showClientWindow(uint32_t index); - void showModuleWindow(uint32_t index); - - SourceInfo* getSourceInfo(uint32_t index); - SinkInfo* getSinkInfo(uint32_t index); - ClientInfo* getClientInfo(uint32_t index); - ModuleInfo* getModuleInfo(uint32_t index); - - void removeSinkInfo(uint32_t index); - void removeSourceInfo(uint32_t index); - void removeClientInfo(uint32_t index); - void removeModuleInfo(uint32_t index); - - void setSinkVolume(uint32_t index, uint32_t volume); - -protected: - std::map sinks; - std::map sources; - std::map clients; - std::map modules; - - struct pa_context &context; -}; - -#endif diff --git a/src/ServerInfoManager.cc b/src/ServerInfoManager.cc new file mode 100644 index 0000000..c816f21 --- /dev/null +++ b/src/ServerInfoManager.cc @@ -0,0 +1,407 @@ +#include +#include + +#include "ServerInfoManager.hh" +#include "paman.hh" + +SinkInfo::SinkInfo(const struct pa_sink_info &i) : + name(i.name), + description(i.description), + index(i.index), + sample_spec(i.sample_spec), + monitor_source(i.monitor_source), + owner_module(i.owner_module), + volume(i.volume), + latency(i.latency), + window(NULL) { +} + +SinkInfo::~SinkInfo() { + if (window) + delete window; +} + +void SinkInfo::update(const struct pa_sink_info &i) { + name = Glib::ustring(i.name); + description = i.description; + index = i.index; + sample_spec = i.sample_spec; + monitor_source = i.monitor_source; + owner_module = i.owner_module; + volume = i.volume; + latency = i.latency; + + if (window) + window->updateInfo(*this); + g_assert(mainWindow); + mainWindow->updateInfo(*this); +} + +void SinkInfo::showWindow() { + if (window) + window->present(); + else { + window = SinkWindow::create(); + window->updateInfo(*this); + window->show(); + } +} + +SourceInfo::SourceInfo(const struct pa_source_info &i) : + name(i.name), + description(i.description), + index(i.index), + sample_spec(i.sample_spec), + owner_module(i.owner_module), + monitor_of_sink(i.monitor_of_sink), + window(NULL) { +} + +SourceInfo::~SourceInfo() { + if (window) + delete window; +} + +void SourceInfo::update(const struct pa_source_info &i) { + name = i.name; + description = i.description; + index = i.index; + sample_spec = i.sample_spec; + owner_module = i.owner_module; + monitor_of_sink = i.monitor_of_sink; + + if (window) + window->updateInfo(*this); + g_assert(mainWindow); + mainWindow->updateInfo(*this); +} + +void SourceInfo::showWindow() { + if (window) + window->present(); + else { + window = SourceWindow::create(); + window->updateInfo(*this); + window->show(); + } +} + +ClientInfo::ClientInfo(const struct pa_client_info &i) : + index(i.index), + name(i.name), + protocol_name(i.protocol_name), + owner_module(i.owner_module), + window(NULL) { +} + +ClientInfo::~ClientInfo() { + if (window) + delete window; +} + +void ClientInfo::update(const struct pa_client_info &i) { + name = i.name; + protocol_name = i.protocol_name; + index = i.index; + owner_module = i.owner_module; + + if (window) + window->updateInfo(*this); + + g_assert(mainWindow); + mainWindow->updateInfo(*this); +} + +void ClientInfo::showWindow() { + if (window) + window->present(); + else { + window = ClientWindow::create(); + window->updateInfo(*this); + window->show(); + } +} + +ModuleInfo::ModuleInfo(const struct pa_module_info &i) : + index(i.index), + name(i.name), + argument(i.argument), + autoloaded(i.auto_unload), + used(i.n_used), + window(NULL) { +} + +ModuleInfo::~ModuleInfo() { + if (window) + delete window; +} + +void ModuleInfo::update(const struct pa_module_info &i) { + name = i.name; + argument = i.argument; + index = i.index; + autoloaded = i.auto_unload; + used = i.n_used; + + if (window) + window->updateInfo(*this); + g_assert(mainWindow); + mainWindow->updateInfo(*this); +} + +void ModuleInfo::showWindow() { + if (window) + window->present(); + else { + window = ModuleWindow::create(); + window->updateInfo(*this); + window->show(); + } +} + +extern "C" { + static void server_info_callback(struct pa_context *c, const struct pa_server_info *i, void *userdata); + static void sink_info_callback(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata); + static void source_info_callback(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata); + static void client_info_callback(struct pa_context *c, const struct pa_client_info *i, int is_last, void *userdata); + static void module_info_callback(struct pa_context *c, const struct pa_module_info *i, int is_last, void *userdata); + static void subscribe_callback(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata); +}; + +static void server_info_callback(struct pa_context *c, const struct pa_server_info *i, void *userdata) { + ServerInfoManager *si = (ServerInfoManager*) userdata; + + if (!i) { + mainWindow->showFailure(pa_strerror(pa_context_errno(c))); + return; + } + + mainWindow->updateInfo(*i); +} + +static void sink_info_callback(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata) { + ServerInfoManager *si = (ServerInfoManager*) userdata; + if (i) si->updateInfo(*i); +} + +static void source_info_callback(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata) { + ServerInfoManager *si = (ServerInfoManager*) userdata; + if (i) si->updateInfo(*i); +} + +static void client_info_callback(struct pa_context *c, const struct pa_client_info *i, int is_last, void *userdata) { + ServerInfoManager *si = (ServerInfoManager*) userdata; + if (i) si->updateInfo(*i); +} + +static void module_info_callback(struct pa_context *c, const struct pa_module_info *i, int is_last, void *userdata) { + ServerInfoManager *si = (ServerInfoManager*) userdata; + if (i) si->updateInfo(*i); +} + +static void subscribe_callback(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata) { + ServerInfoManager *si = (ServerInfoManager*) userdata; + + //fprintf(stderr, "EV: %u %u\n", t, index); + + switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { + case PA_SUBSCRIPTION_EVENT_SINK: + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) + si->removeSinkInfo(index); + else + pa_operation_unref(pa_context_get_sink_info_by_index(c, index, sink_info_callback, si)); + break; + case PA_SUBSCRIPTION_EVENT_SOURCE: + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) + si->removeSourceInfo(index); + else + pa_operation_unref(pa_context_get_source_info_by_index(c, index, source_info_callback, si)); + break; + case PA_SUBSCRIPTION_EVENT_MODULE: + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) + si->removeModuleInfo(index); + else + pa_operation_unref(pa_context_get_module_info(c, index, module_info_callback, si)); + break; + case PA_SUBSCRIPTION_EVENT_CLIENT: + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) + si->removeClientInfo(index); + else + pa_operation_unref(pa_context_get_client_info(c, index, client_info_callback, si)); + break; + case PA_SUBSCRIPTION_EVENT_SINK_INPUT: +// fprintf(stderr, "SINK INPUT EVENT\n"); + break; + case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT: +// fprintf(stderr, "SOURCE OUTPUT EVENT\n"); + break; + default: +// fprintf(stderr, "OTHER EVENT\n"); + break; + } +} + +ServerInfoManager::ServerInfoManager(struct pa_context &c) : + context(c) { + pa_operation_unref(pa_context_get_server_info(&c, server_info_callback, this)); + pa_operation_unref(pa_context_get_sink_info_list(&c, sink_info_callback, this)); + pa_operation_unref(pa_context_get_source_info_list(&c, source_info_callback, this)); + pa_operation_unref(pa_context_get_module_info_list(&c, module_info_callback, this)); + pa_operation_unref(pa_context_get_client_info_list(&c, client_info_callback, this)); + + pa_context_set_subscribe_callback(&c, subscribe_callback, this); + + pa_operation_unref(pa_context_subscribe(&c, (enum pa_subscription_mask) + (PA_SUBSCRIPTION_MASK_SINK| + PA_SUBSCRIPTION_MASK_SOURCE| + PA_SUBSCRIPTION_MASK_MODULE| + PA_SUBSCRIPTION_MASK_SINK_INPUT| + PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| + PA_SUBSCRIPTION_MASK_CLIENT), NULL, NULL)); +} + + +ServerInfoManager::~ServerInfoManager() { + for (std::map::iterator i = sinks.begin(); i != sinks.end(); i++) + delete i->second; + + for (std::map::iterator i = sources.begin(); i != sources.end(); i++) + delete i->second; + + for (std::map::iterator i = clients.begin(); i != clients.end(); i++) + delete i->second; + + for (std::map::iterator i = modules.begin(); i != modules.end(); i++) + delete i->second; +} + +void ServerInfoManager::updateInfo(const struct pa_sink_info &i) { + SinkInfo *si; + if ((si = sinks[i.index])) + si->update(i); + else { + SinkInfo *n = new SinkInfo(i); + sinks[i.index] = n; + mainWindow->updateInfo(*n); + } +} + +void ServerInfoManager::updateInfo(const struct pa_source_info &i) { + SourceInfo *si; + if ((si = sources[i.index])) + si->update(i); + else { + SourceInfo *n = new SourceInfo(i); + sources[i.index] = n; + mainWindow->updateInfo(*n); + } +} + +void ServerInfoManager::updateInfo(const struct pa_client_info &i) { + ClientInfo *ci; + + if ((ci = clients[i.index])) + ci->update(i); + else { + ClientInfo *n = new ClientInfo(i); + clients[i.index] = n; + mainWindow->updateInfo(*n); + } +} +void ServerInfoManager::updateInfo(const struct pa_module_info &i) { + ModuleInfo *si; + if ((si = modules[i.index])) + si->update(i); + else { + ModuleInfo *n = new ModuleInfo(i); + modules[i.index] = n; + mainWindow->updateInfo(*n); + } +} + +void ServerInfoManager::showSinkWindow(uint32_t index) { + SinkInfo *i; + + if ((i = sinks[index])) + i->showWindow(); +} + +void ServerInfoManager::showSourceWindow(uint32_t index) { + SourceInfo *i; + + if ((i = sources[index])) + i->showWindow(); +} + +void ServerInfoManager::showClientWindow(uint32_t index) { + ClientInfo *i; + + if ((i = clients[index])) + i->showWindow(); +} + +void ServerInfoManager::showModuleWindow(uint32_t index) { + ModuleInfo *i; + + if ((i = modules[index])) + i->showWindow(); +} + + +SourceInfo* ServerInfoManager::getSourceInfo(uint32_t index) { + return sources[index]; +} + +SinkInfo* ServerInfoManager::getSinkInfo(uint32_t index) { + return sinks[index]; +} + +ClientInfo* ServerInfoManager::getClientInfo(uint32_t index) { + return clients[index]; +} + +ModuleInfo* ServerInfoManager::getModuleInfo(uint32_t index) { + return modules[index]; +} + +void ServerInfoManager::removeSinkInfo(uint32_t index) { + SinkInfo *i; + + if ((i = sinks[index])) { + sinks.erase(index); + mainWindow->removeInfo(*i); + delete i; + } +} + +void ServerInfoManager::removeSourceInfo(uint32_t index) { + SourceInfo *i; + if ((i = sources[index])) { + sources.erase(index); + mainWindow->removeInfo(*i); + delete i; + } +} + +void ServerInfoManager::removeClientInfo(uint32_t index) { + ClientInfo *i; + + if ((i = clients[index])) { + clients.erase(index); + mainWindow->removeInfo(*i); + delete i; + } +} + +void ServerInfoManager::removeModuleInfo(uint32_t index) { + ModuleInfo *i; + if ((i = modules[index])) { + modules.erase(index); + mainWindow->removeInfo(*i); + delete i; + } +} + +void ServerInfoManager::setSinkVolume(uint32_t index, uint32_t volume) { + pa_operation_unref(pa_context_set_sink_volume_by_index(&context, index, volume, NULL, NULL)); +} diff --git a/src/ServerInfoManager.hh b/src/ServerInfoManager.hh new file mode 100644 index 0000000..5c22f64 --- /dev/null +++ b/src/ServerInfoManager.hh @@ -0,0 +1,130 @@ +#ifndef fooserverinfohhfoo +#define fooserverinfohhfoo + +#include +#include + +#include + +class SinkInfo; +class SourceInfo; +class ServerInfo; +class ClientInfo; +class ModuleInfo; + +#include "SinkWindow.hh" +#include "SourceWindow.hh" +#include "ClientWindow.hh" +#include "ModuleWindow.hh" +#include "MainWindow.hh" + +class SinkInfo { +public: + + SinkInfo(const struct pa_sink_info &i); + ~SinkInfo(); + + void update(const struct pa_sink_info &i); + void showWindow(); + + Glib::ustring name, description; + uint32_t index; + struct pa_sample_spec sample_spec; + uint32_t monitor_source; + uint32_t owner_module; + uint32_t volume; + uint32_t latency; + + Gtk::TreeRowReference treeRef; + + SinkWindow *window; +}; + +class SourceInfo { +public: + SourceInfo(const struct pa_source_info &i); + ~SourceInfo(); + + void update(const struct pa_source_info &i); + void showWindow(); + + Glib::ustring name, description; + uint32_t index; + struct pa_sample_spec sample_spec; + uint32_t owner_module; + uint32_t monitor_of_sink; + + Gtk::TreeRowReference treeRef; + SourceWindow *window; +}; + +class ModuleInfo { +public: + ModuleInfo(const struct pa_module_info &i); + ~ModuleInfo(); + + void update(const struct pa_module_info &i); + void showWindow(); + + uint32_t index; + Glib::ustring name, argument; + bool autoloaded; + uint32_t used; + + Gtk::TreeRowReference treeRef; + ModuleWindow *window; +}; + +class ClientInfo { +public: + ClientInfo(const struct pa_client_info &i); + ~ClientInfo(); + + void update(const struct pa_client_info &i); + void showWindow(); + + uint32_t index; + Glib::ustring name, protocol_name; + uint32_t owner_module; + + Gtk::TreeRowReference treeRef; + ClientWindow *window; +}; + +class ServerInfoManager { +public: + ServerInfoManager(struct pa_context &c); + ~ServerInfoManager(); + + void updateInfo(const struct pa_sink_info &i); + void updateInfo(const struct pa_source_info &i); + void updateInfo(const struct pa_client_info &i); + void updateInfo(const struct pa_module_info &i); + + void showSinkWindow(uint32_t index); + void showSourceWindow(uint32_t index); + void showClientWindow(uint32_t index); + void showModuleWindow(uint32_t index); + + SourceInfo* getSourceInfo(uint32_t index); + SinkInfo* getSinkInfo(uint32_t index); + ClientInfo* getClientInfo(uint32_t index); + ModuleInfo* getModuleInfo(uint32_t index); + + void removeSinkInfo(uint32_t index); + void removeSourceInfo(uint32_t index); + void removeClientInfo(uint32_t index); + void removeModuleInfo(uint32_t index); + + void setSinkVolume(uint32_t index, uint32_t volume); + +protected: + std::map sinks; + std::map sources; + std::map clients; + std::map modules; + + struct pa_context &context; +}; + +#endif diff --git a/src/SinkWindow.hh b/src/SinkWindow.hh index 32557c4..b0417aa 100644 --- a/src/SinkWindow.hh +++ b/src/SinkWindow.hh @@ -6,7 +6,7 @@ class SinkWindow; -#include "ServerInfo.hh" +#include "ServerInfoManager.hh" class SinkWindow : public Gtk::Window { public: diff --git a/src/paman.hh b/src/paman.hh index 7f2127f..241378d 100644 --- a/src/paman.hh +++ b/src/paman.hh @@ -1,7 +1,7 @@ #ifndef foopamanhhfoo #define foopamanhhfoo -#include "ServerInfo.hh" +#include "ServerInfoManager.hh" #define GLADE_FILE "paman.glade" @@ -11,5 +11,4 @@ extern struct pa_context *context; void create_connection(); - #endif -- cgit