From caf4d9b8b8b0d26856d2d64f00ab23756867a923 Mon Sep 17 00:00:00 2001 From: Michal Ratajsky Date: Sat, 24 May 2014 00:15:24 +0200 Subject: Initial commit --- libmatemixer/Makefile.am | 60 ++++++++ libmatemixer/matemixer-backend-module.c | 161 ++++++++++++++++++++ libmatemixer/matemixer-backend-module.h | 75 +++++++++ libmatemixer/matemixer-backend.c | 60 ++++++++ libmatemixer/matemixer-backend.h | 59 +++++++ libmatemixer/matemixer-control.c | 210 +++++++++++++++++++++++++ libmatemixer/matemixer-control.h | 66 ++++++++ libmatemixer/matemixer-device-port.c | 220 +++++++++++++++++++++++++++ libmatemixer/matemixer-device-port.h | 69 +++++++++ libmatemixer/matemixer-device-profile.c | 165 ++++++++++++++++++++ libmatemixer/matemixer-device-profile.h | 63 ++++++++ libmatemixer/matemixer-device.c | 68 +++++++++ libmatemixer/matemixer-device.h | 51 +++++++ libmatemixer/matemixer-enum-types.c.template | 36 +++++ libmatemixer/matemixer-enum-types.h.template | 26 ++++ libmatemixer/matemixer-enums.h | 35 +++++ libmatemixer/matemixer-private.h | 30 ++++ libmatemixer/matemixer-track.c | 29 ++++ libmatemixer/matemixer-track.h | 47 ++++++ libmatemixer/matemixer.c | 158 +++++++++++++++++++ libmatemixer/matemixer.h | 34 +++++ 21 files changed, 1722 insertions(+) create mode 100644 libmatemixer/Makefile.am create mode 100644 libmatemixer/matemixer-backend-module.c create mode 100644 libmatemixer/matemixer-backend-module.h create mode 100644 libmatemixer/matemixer-backend.c create mode 100644 libmatemixer/matemixer-backend.h create mode 100644 libmatemixer/matemixer-control.c create mode 100644 libmatemixer/matemixer-control.h create mode 100644 libmatemixer/matemixer-device-port.c create mode 100644 libmatemixer/matemixer-device-port.h create mode 100644 libmatemixer/matemixer-device-profile.c create mode 100644 libmatemixer/matemixer-device-profile.h create mode 100644 libmatemixer/matemixer-device.c create mode 100644 libmatemixer/matemixer-device.h create mode 100644 libmatemixer/matemixer-enum-types.c.template create mode 100644 libmatemixer/matemixer-enum-types.h.template create mode 100644 libmatemixer/matemixer-enums.h create mode 100644 libmatemixer/matemixer-private.h create mode 100644 libmatemixer/matemixer-track.c create mode 100644 libmatemixer/matemixer-track.h create mode 100644 libmatemixer/matemixer.c create mode 100644 libmatemixer/matemixer.h (limited to 'libmatemixer') diff --git a/libmatemixer/Makefile.am b/libmatemixer/Makefile.am new file mode 100644 index 0000000..a986a98 --- /dev/null +++ b/libmatemixer/Makefile.am @@ -0,0 +1,60 @@ +lib_LTLIBRARIES = libmatemixer.la + +AM_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libmatemixer \ + -DG_LOG_DOMAIN=\"libmatemixer\" \ + -DLIBMATEMIXER_BACKEND_DIR=\"$(libdir)/libmatemixer\" + +BUILT_SOURCES = \ + matemixer-enum-types.c \ + matemixer-enum-types.h + +libmatemixer_includedir = $(includedir)/libmatemixer + +libmatemixer_include_HEADERS = \ + matemixer.h \ + matemixer-control.h \ + matemixer-device.h \ + matemixer-device-port.h \ + matemixer-device-profile.h \ + matemixer-enums.h \ + matemixer-track.h + +libmatemixer_la_SOURCES = \ + matemixer.c \ + matemixer-private.h \ + matemixer-backend.c \ + matemixer-backend.h \ + matemixer-backend-module.c \ + matemixer-control.c \ + matemixer-device.c \ + matemixer-device-port.c \ + matemixer-device-profile.c \ + matemixer-track.c \ + $(BUILD_SOURCES) + +libmatemixer_la_LIBADD = $(GLIB_LIBS) + +libmatemixer_la_LDFLAGS = \ + -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ + -export-dynamic + +libmatemixer_ENUM_TYPES = matemixer-enums.h + +matemixer-enum-types.h: $(libmatemixer_ENUM_TYPES) + $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template matemixer-enum-types.h.template \ + $(libmatemixer_ENUM_TYPES) ) > matemixer-enum-types.h.tmp \ + && mv matemixer-enum-types.h.tmp matemixer-enum-types.h \ + || rm -f matemixer-enum-type.h.tmp + +matemixer-enum-types.c: $(libmatemixer_ENUM_TYPES) + $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template matemixer-enum-types.c.template \ + $(libmatemixer_ENUM_TYPES) ) > matemixer-enum-types.c.tmp \ + && mv matemixer-enum-types.c.tmp matemixer-enum-types.c \ + || rm -f matemixer-enum-type.c.tmp + +CLEANFILES = $(BUILT_SOURCES) + +-include $(top_srcdir)/git.mk diff --git a/libmatemixer/matemixer-backend-module.c b/libmatemixer/matemixer-backend-module.c new file mode 100644 index 0000000..0acd786 --- /dev/null +++ b/libmatemixer/matemixer-backend-module.c @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include +#include + +#include "matemixer-backend.h" +#include "matemixer-backend-module.h" + +G_DEFINE_TYPE (MateMixerBackendModule, mate_mixer_backend_module, G_TYPE_TYPE_MODULE); + +struct _MateMixerBackendModulePrivate +{ + GModule *gmodule; + gchar *path; + + void (*init) (GTypeModule *type_module); + void (*free) (void); + + const MateMixerBackendModuleInfo *(*get_info) (void); +}; + +static gboolean mate_mixer_backend_module_load (GTypeModule *gmodule); +static void mate_mixer_backend_module_unload (GTypeModule *gmodule); + +static void +mate_mixer_backend_module_init (MateMixerBackendModule *module) +{ + module->priv = G_TYPE_INSTANCE_GET_PRIVATE ( + module, + MATE_MIXER_TYPE_BACKEND_MODULE, + MateMixerBackendModulePrivate); +} + +static void +mate_mixer_backend_module_finalize (GObject *object) +{ + MateMixerBackendModule *module; + + module = MATE_MIXER_BACKEND_MODULE (object); + + g_free (module->priv->path); + + G_OBJECT_CLASS (mate_mixer_backend_module_parent_class)->finalize (object); +} + +static void +mate_mixer_backend_module_class_init (MateMixerBackendModuleClass *klass) +{ + GObjectClass *object_class; + GTypeModuleClass *gtype_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = mate_mixer_backend_module_finalize; + + gtype_class = G_TYPE_MODULE_CLASS (klass); + gtype_class->load = mate_mixer_backend_module_load; + gtype_class->unload = mate_mixer_backend_module_unload; + + g_type_class_add_private (object_class, sizeof (MateMixerBackendModulePrivate)); +} + +static gboolean +mate_mixer_backend_module_load (GTypeModule *type_module) +{ + MateMixerBackendModule *module; + + module = MATE_MIXER_BACKEND_MODULE (type_module); + + module->priv->gmodule = g_module_open ( + module->priv->path, + G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); + + if (module->priv->gmodule == NULL) { + g_warning ("Failed to load backend module %s: %s", + module->priv->path, + g_module_error ()); + + return FALSE; + } + + /* Validate library symbols that each backend module must provide */ + if (!g_module_symbol (module->priv->gmodule, + "backend_module_init", + (gpointer *) &module->priv->init) || + !g_module_symbol (module->priv->gmodule, + "backend_module_free", + (gpointer *) &module->priv->free) || + !g_module_symbol (module->priv->gmodule, + "backend_module_get_info", + (gpointer *) &module->priv->get_info)) { + g_warning ("Failed to load backend module %s: %s", + module->priv->path, + g_module_error ()); + + g_module_close (module->priv->gmodule); + return FALSE; + } + + g_debug ("Loaded backend module %s", module->priv->path); + + module->priv->init (type_module); + return TRUE; +} + +static void +mate_mixer_backend_module_unload (GTypeModule *type_module) +{ + MateMixerBackendModule *module; + + module = MATE_MIXER_BACKEND_MODULE (type_module); + module->priv->free (); + + g_module_close (module->priv->gmodule); +} + +MateMixerBackendModule * +mate_mixer_backend_module_new (const gchar *path) +{ + MateMixerBackendModule *module; + + g_return_val_if_fail (path != NULL, NULL); + + module = g_object_newv (MATE_MIXER_TYPE_BACKEND_MODULE, 0, NULL); + module->priv->path = g_strdup (path); + + g_type_module_set_name (G_TYPE_MODULE (module), path); + + return module; +} + +const MateMixerBackendModuleInfo * +mate_mixer_backend_module_get_info (MateMixerBackendModule *module) +{ + g_return_val_if_fail (MATE_MIXER_IS_BACKEND_MODULE (module), NULL); + + return module->priv->get_info (); +} + +const gchar * +mate_mixer_backend_module_get_path (MateMixerBackendModule *module) +{ + g_return_val_if_fail (MATE_MIXER_IS_BACKEND_MODULE (module), NULL); + + return module->priv->path; +} diff --git a/libmatemixer/matemixer-backend-module.h b/libmatemixer/matemixer-backend-module.h new file mode 100644 index 0000000..4cba866 --- /dev/null +++ b/libmatemixer/matemixer-backend-module.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_BACKEND_MODULE_H +#define MATEMIXER_BACKEND_MODULE_H + +#include +#include + +#include "matemixer-enums.h" + +G_BEGIN_DECLS + +#define MATE_MIXER_TYPE_BACKEND_MODULE \ + (mate_mixer_backend_module_get_type ()) +#define MATE_MIXER_BACKEND_MODULE(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_MIXER_TYPE_BACKEND_MODULE, MateMixerBackendModule)) +#define MATE_MIXER_IS_BACKEND_MODULE(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_MIXER_TYPE_BACKEND_MODULE)) +#define MATE_MIXER_BACKEND_MODULE_CLASS(k) \ + (G_TYPE_CHECK_CLASS_CAST ((k), MATE_MIXER_TYPE_BACKEND_MODULE, MateMixerBackendModuleClass)) +#define MATE_MIXER_IS_BACKEND_MODULE_CLASS(k) \ + (G_TYPE_CLASS_CHECK_CLASS_TYPE ((k), MATE_MIXER_TYPE_BACKEND_MODULE)) +#define MATE_MIXER_BACKEND_MODULE_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_MIXER_TYPE_BACKEND_MODULE, MateMixerBackendModuleClass)) + +typedef struct _MateMixerBackendModule MateMixerBackendModule; +typedef struct _MateMixerBackendModuleClass MateMixerBackendModuleClass; +typedef struct _MateMixerBackendModuleInfo MateMixerBackendModuleInfo; +typedef struct _MateMixerBackendModulePrivate MateMixerBackendModulePrivate; + +struct _MateMixerBackendModuleInfo +{ + gchar *name; + guint priority; + GType g_type; + + MateMixerBackendType backend_type; +}; + +struct _MateMixerBackendModule +{ + GTypeModule parent; + + MateMixerBackendModulePrivate *priv; +}; + +struct _MateMixerBackendModuleClass +{ + GTypeModuleClass parent; +}; + +GType mate_mixer_backend_module_get_type (void) G_GNUC_CONST; + +MateMixerBackendModule *mate_mixer_backend_module_new (const gchar *path); +const MateMixerBackendModuleInfo *mate_mixer_backend_module_get_info (MateMixerBackendModule *module); +const gchar *mate_mixer_backend_module_get_path (MateMixerBackendModule *module); + +G_END_DECLS + +#endif /* MATEMIXER_BACKEND_MODULE_H */ diff --git a/libmatemixer/matemixer-backend.c b/libmatemixer/matemixer-backend.c new file mode 100644 index 0000000..9533e0f --- /dev/null +++ b/libmatemixer/matemixer-backend.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include + +#include "matemixer-backend.h" + +G_DEFINE_INTERFACE (MateMixerBackend, mate_mixer_backend, G_TYPE_OBJECT) + +static void +mate_mixer_backend_default_init (MateMixerBackendInterface *iface) +{ +} + +gboolean +mate_mixer_backend_open (MateMixerBackend *backend) +{ + g_return_val_if_fail (MATE_MIXER_IS_BACKEND (backend), NULL); + + return MATE_MIXER_BACKEND_GET_INTERFACE (backend)->open (backend); +} + +void +mate_mixer_backend_close (MateMixerBackend *backend) +{ + g_return_val_if_fail (MATE_MIXER_IS_BACKEND (backend), NULL); + + MATE_MIXER_BACKEND_GET_INTERFACE (backend)->close (backend); +} + +const GList * +mate_mixer_backend_list_devices (MateMixerBackend *backend) +{ + g_return_val_if_fail (MATE_MIXER_IS_BACKEND (backend), NULL); + + return MATE_MIXER_BACKEND_GET_INTERFACE (backend)->list_devices (backend); +} + +const GList * +mate_mixer_backend_list_tracks (MateMixerBackend *backend) +{ + g_return_val_if_fail (MATE_MIXER_IS_BACKEND (backend), NULL); + + return MATE_MIXER_BACKEND_GET_INTERFACE (backend)->list_tracks (backend); +} diff --git a/libmatemixer/matemixer-backend.h b/libmatemixer/matemixer-backend.h new file mode 100644 index 0000000..6b0c318 --- /dev/null +++ b/libmatemixer/matemixer-backend.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_BACKEND_H +#define MATEMIXER_BACKEND_H + +#include +#include + +#include + +G_BEGIN_DECLS + +#define MATE_MIXER_TYPE_BACKEND \ + (mate_mixer_backend_get_type ()) +#define MATE_MIXER_BACKEND(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_MIXER_TYPE_BACKEND, MateMixerBackend)) +#define MATE_MIXER_IS_BACKEND(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_MIXER_TYPE_BACKEND)) +#define MATE_MIXER_BACKEND_GET_INTERFACE(o) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((o), MATE_MIXER_TYPE_BACKEND, MateMixerBackendInterface)) + +typedef struct _MateMixerBackend MateMixerBackend; /* dummy object */ +typedef struct _MateMixerBackendInterface MateMixerBackendInterface; + +struct _MateMixerBackendInterface +{ + GTypeInterface parent; + + gboolean (*open) (MateMixerBackend *backend); + void (*close) (MateMixerBackend *backend); + const GList *(*list_devices) (MateMixerBackend *backend); + const GList *(*list_tracks) (MateMixerBackend *backend); +}; + +GType mate_mixer_backend_get_type (void) G_GNUC_CONST; + +gboolean mate_mixer_backend_open (MateMixerBackend *backend); +void mate_mixer_backend_close (MateMixerBackend *backend); +const GList *mate_mixer_backend_list_devices (MateMixerBackend *backend); +const GList *mate_mixer_backend_list_tracks (MateMixerBackend *backend); + +G_END_DECLS + +#endif /* MATEMIXER_BACKEND_H */ diff --git a/libmatemixer/matemixer-control.c b/libmatemixer/matemixer-control.c new file mode 100644 index 0000000..c3489e6 --- /dev/null +++ b/libmatemixer/matemixer-control.c @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include + +#include "matemixer-backend.h" +#include "matemixer-backend-module.h" +#include "matemixer-control.h" +#include "matemixer-enums.h" +#include "matemixer-private.h" +#include "matemixer-track.h" + +struct _MateMixerControlPrivate +{ + MateMixerBackend *backend; + GHashTable *devices; + GHashTable *tracks; +}; + +G_DEFINE_TYPE (MateMixerControl, mate_mixer_control, G_TYPE_OBJECT); + +G_LOCK_DEFINE_STATIC (mixer_control_get_modules_lock); + +static MateMixerBackend *mixer_control_init_module (MateMixerBackendModule *module); + +static void +mate_mixer_control_init (MateMixerControl *control) +{ + control->priv = G_TYPE_INSTANCE_GET_PRIVATE ( + control, + MATE_MIXER_TYPE_CONTROL, + MateMixerControlPrivate); + + control->priv->devices = g_hash_table_new_full ( + g_direct_hash, + g_direct_equal, + NULL, + g_object_unref); + + control->priv->tracks = g_hash_table_new_full ( + g_direct_hash, + g_direct_equal, + NULL, + g_object_unref); +} + +static void +mate_mixer_control_finalize (GObject *object) +{ + MateMixerControl *control; + + control = MATE_MIXER_CONTROL (object); + + g_object_unref (control->priv->backend); + g_hash_table_destroy (control->priv->devices); + g_hash_table_destroy (control->priv->tracks); + + G_OBJECT_CLASS (mate_mixer_control_parent_class)->finalize (object); +} + +static void +mate_mixer_control_class_init (MateMixerControlClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = mate_mixer_control_finalize; + + g_type_class_add_private (object_class, sizeof (MateMixerControlPrivate)); +} + +MateMixerControl * +mate_mixer_control_new (void) +{ + GList *modules; + MateMixerControl *control; + MateMixerBackend *backend = NULL; + + if (!mate_mixer_is_initialized ()) { + g_critical ("The library has not been initialized"); + return NULL; + } + + G_LOCK (mixer_control_get_modules_lock); + + modules = mate_mixer_get_modules (); + while (modules) { + MateMixerBackendModule *module; + + module = MATE_MIXER_BACKEND_MODULE (modules->data); + backend = mixer_control_init_module (module); + if (backend != NULL) + break; + + modules = modules->next; + } + + G_UNLOCK (mixer_control_get_modules_lock); + + /* The last module in the priority list is the "null" module which + * should always be initialized correctly, but in case "null" is absent + * all the other modules might fail their initializations */ + if (backend == NULL) + return NULL; + + control = g_object_new (MATE_MIXER_TYPE_CONTROL, NULL); + control->priv->backend = backend; + + return control; +} + +MateMixerControl * +mate_mixer_control_new_backend (MateMixerBackendType backend_type) +{ + GList *modules; + MateMixerControl *control; + MateMixerBackend *backend = NULL; + + if (!mate_mixer_is_initialized ()) { + g_critical ("The library has not been initialized"); + return NULL; + } + + G_LOCK (mixer_control_get_modules_lock); + + modules = mate_mixer_get_modules (); + + while (modules) { + MateMixerBackendModule *module; + const MateMixerBackendModuleInfo *info; + + module = MATE_MIXER_BACKEND_MODULE (modules->data); + info = mate_mixer_backend_module_get_info (module); + + if (info->backend_type == backend_type) { + backend = mixer_control_init_module (module); + break; + } + modules = modules->next; + } + + G_UNLOCK (mixer_control_get_modules_lock); + + /* The initialization might fail or the selected module might be absent */ + if (backend == NULL) + return NULL; + + control = g_object_new (MATE_MIXER_TYPE_CONTROL, NULL); + control->priv->backend = backend; + + return control; +} + +const GList * +mate_mixer_control_list_devices (MateMixerControl *control) +{ + g_return_val_if_fail (MATE_MIXER_IS_CONTROL (control), NULL); + + // XXX + // this is the midpoint between MateMixerDevice implementation and + // the application, probably the list could be cached here but the + // implementation uses a hash table, figure out how to do this properly + + return mate_mixer_backend_list_devices (MATE_MIXER_BACKEND (control->priv->backend)); +} + +const GList * +mate_mixer_control_list_tracks (MateMixerControl *control) +{ + g_return_val_if_fail (MATE_MIXER_IS_CONTROL (control), NULL); + + return mate_mixer_backend_list_tracks (MATE_MIXER_BACKEND (control->priv->backend)); +} + +static MateMixerBackend * +mixer_control_init_module (MateMixerBackendModule *module) +{ + MateMixerBackend *backend; + const MateMixerBackendModuleInfo *info; + + info = mate_mixer_backend_module_get_info (module); + if (G_UNLIKELY (info == NULL)) { + g_warning ("Backend module %s does not provide module information", + mate_mixer_backend_module_get_path (module)); + return NULL; + } + + backend = g_object_newv (info->g_type, 0, NULL); + + if (!mate_mixer_backend_open (backend)) { + g_object_unref (backend); + return NULL; + } + return backend; +} diff --git a/libmatemixer/matemixer-control.h b/libmatemixer/matemixer-control.h new file mode 100644 index 0000000..010cbfa --- /dev/null +++ b/libmatemixer/matemixer-control.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_CONTROL_H +#define MATEMIXER_CONTROL_H + +#include +#include + +#include "matemixer-enums.h" + +G_BEGIN_DECLS + +#define MATE_MIXER_TYPE_CONTROL \ + (mate_mixer_control_get_type ()) +#define MATE_MIXER_CONTROL(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_MIXER_TYPE_CONTROL, MateMixerControl)) +#define MATE_MIXER_IS_CONTROL(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_MIXER_TYPE_CONTROL)) +#define MATE_MIXER_CONTROL_CLASS(k) \ + (G_TYPE_CHECK_CLASS_CAST ((k), MATE_MIXER_TYPE_CONTROL, MateMixerControlClass)) +#define MATE_MIXER_IS_CONTROL_CLASS(k) \ + (G_TYPE_CLASS_CHECK_CLASS_TYPE ((k), MATE_MIXER_TYPE_CONTROL)) +#define MATE_MIXER_CONTROL_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_MIXER_TYPE_CONTROL, MateMixerControlClass)) + +typedef struct _MateMixerControl MateMixerControl; +typedef struct _MateMixerControlClass MateMixerControlClass; +typedef struct _MateMixerControlPrivate MateMixerControlPrivate; + +struct _MateMixerControl +{ + GObject parent; + + MateMixerControlPrivate *priv; +}; + +struct _MateMixerControlClass +{ + GObjectClass parent; +}; + +GType mate_mixer_control_get_type (void) G_GNUC_CONST; + +MateMixerControl *mate_mixer_control_new (void); +MateMixerControl *mate_mixer_control_new_backend (MateMixerBackendType backend_type); +const GList *mate_mixer_control_list_devices (MateMixerControl *control); +const GList *mate_mixer_control_list_tracks (MateMixerControl *control); + +G_END_DECLS + +#endif /* MATEMIXER_CONTROL_H */ diff --git a/libmatemixer/matemixer-device-port.c b/libmatemixer/matemixer-device-port.c new file mode 100644 index 0000000..9443879 --- /dev/null +++ b/libmatemixer/matemixer-device-port.c @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include + +#include "matemixer-device-port.h" +#include "matemixer-enums.h" + +struct _MateMixerDevicePortPrivate +{ + gchar *identifier; + gchar *name; + gchar *icon; + guint32 priority; + gint64 latency_offset; + + MateMixerDevicePortDirection direction; + MateMixerDevicePortStatus status; +}; + +enum +{ + PROP_0, + PROP_IDENTIFIER, + PROP_NAME, + PROP_ICON, + PROP_PRIORITY, + // PROP_DIRECTION, + // PROP_STATUS, + PROP_LATENCY_OFFSET, + N_PROPERTIES +}; + +static GParamSpec *properties[N_PROPERTIES] = { NULL, }; + +G_DEFINE_TYPE (MateMixerDevicePort, mate_mixer_device_port, G_TYPE_OBJECT); + +static void +mate_mixer_device_port_init (MateMixerDevicePort *port) +{ + port->priv = G_TYPE_INSTANCE_GET_PRIVATE ( + port, + MATE_MIXER_TYPE_DEVICE_PORT, + MateMixerDevicePortPrivate); +} + +static void +mate_mixer_device_port_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + MateMixerDevicePort *port; + + port = MATE_MIXER_DEVICE_PORT (object); + + switch (param_id) { + case PROP_IDENTIFIER: + g_value_set_string (value, port->priv->identifier); + break; + case PROP_NAME: + g_value_set_string (value, port->priv->name); + break; + case PROP_ICON: + g_value_set_string (value, port->priv->icon); + break; + case PROP_PRIORITY: + g_value_set_uint (value, port->priv->priority); + break; + // case PROP_DIRECTION: + // break; + // case PROP_STATUS: + // break; + case PROP_LATENCY_OFFSET: + g_value_set_int64 (value, port->priv->latency_offset); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + +static void +mate_mixer_device_port_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + MateMixerDevicePort *port; + + port = MATE_MIXER_DEVICE_PORT (object); + + switch (param_id) { + case PROP_IDENTIFIER: + port->priv->identifier = g_strdup (g_value_get_string (value)); + break; + case PROP_NAME: + port->priv->name = g_strdup (g_value_get_string (value)); + break; + case PROP_ICON: + port->priv->icon = g_strdup (g_value_get_string (value)); + break; + case PROP_PRIORITY: + port->priv->priority = g_value_get_uint (value); + break; + // case PROP_DIRECTION: + // break; + // case PROP_STATUS: + // break; + case PROP_LATENCY_OFFSET: + port->priv->latency_offset = g_value_get_int64 (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + +static void +mate_mixer_device_port_finalize (GObject *object) +{ + MateMixerDevicePort *port; + + port = MATE_MIXER_DEVICE_PORT (object); + + g_free (port->priv->identifier); + g_free (port->priv->name); + g_free (port->priv->icon); + + G_OBJECT_CLASS (mate_mixer_device_port_parent_class)->finalize (object); +} + +static void +mate_mixer_device_port_class_init (MateMixerDevicePortClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = mate_mixer_device_port_finalize; + object_class->get_property = mate_mixer_device_port_get_property; + object_class->set_property = mate_mixer_device_port_set_property; + + properties[PROP_IDENTIFIER] = g_param_spec_string( + "identifier", + "Identifier", + "Identifier of the device port", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + properties[PROP_NAME] = g_param_spec_string( + "name", + "Name", + "Name of the device port", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + properties[PROP_ICON] = g_param_spec_string( + "icon", + "Icon", + "Icon name for the device port", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + properties[PROP_PRIORITY] = g_param_spec_uint( + "priority", + "Priority", + "Priority of the device port", + 0, + G_MAXUINT32, + 0, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + properties[PROP_LATENCY_OFFSET] = g_param_spec_int64( + "latency-offset", + "Latency offset", + "Latency offset of the device port", + G_MININT64, + G_MAXINT64, + 0, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + g_object_class_install_properties (object_class, N_PROPERTIES, properties); + + g_type_class_add_private (object_class, sizeof (MateMixerDevicePortPrivate)); +} + +MateMixerDevicePort * +mate_mixer_device_port_new (const gchar *identifier, + const gchar *name, + const gchar *icon, + guint32 priority, + MateMixerDevicePortDirection direction, + MateMixerDevicePortStatus status, + gint64 latency_offset) +{ + return g_object_new (MATE_MIXER_TYPE_DEVICE_PORT, + "identifier", identifier, + "name", name, + "icon", icon, + "priority", priority, + //"direction", direction, + //"status", status, + "latency-offset", latency_offset, + NULL); +} diff --git a/libmatemixer/matemixer-device-port.h b/libmatemixer/matemixer-device-port.h new file mode 100644 index 0000000..d411c89 --- /dev/null +++ b/libmatemixer/matemixer-device-port.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_DEVICE_PORT_H +#define MATEMIXER_DEVICE_PORT_H + +#include +#include + +#include + +G_BEGIN_DECLS + +#define MATE_MIXER_TYPE_DEVICE_PORT \ + (mate_mixer_device_port_get_type ()) +#define MATE_MIXER_DEVICE_PORT(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_MIXER_TYPE_DEVICE_PORT, MateMixerDevicePort)) +#define MATE_MIXER_IS_DEVICE_PORT(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_MIXER_TYPE_DEVICE_PORT)) +#define MATE_MIXER_DEVICE_PORT_CLASS(k) \ + (G_TYPE_CHECK_CLASS_CAST ((k), MATE_MIXER_TYPE_DEVICE_PORT, MateMixerDevicePortClass)) +#define MATE_MIXER_IS_DEVICE_PORT_CLASS(k) \ + (G_TYPE_CLASS_CHECK_CLASS_TYPE ((k), MATE_MIXER_TYPE_DEVICE_PORT)) +#define MATE_MIXER_DEVICE_PORT_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_MIXER_TYPE_DEVICE_PORT, MateMixerDevicePortClass)) + +typedef struct _MateMixerDevicePort MateMixerDevicePort; +typedef struct _MateMixerDevicePortClass MateMixerDevicePortClass; +typedef struct _MateMixerDevicePortPrivate MateMixerDevicePortPrivate; + +struct _MateMixerDevicePort +{ + GObject parent; + + MateMixerDevicePortPrivate *priv; +}; + +struct _MateMixerDevicePortClass +{ + GObjectClass parent; +}; + +GType mate_mixer_device_port_get_type (void) G_GNUC_CONST; + +MateMixerDevicePort *mate_mixer_device_port_new (const gchar *identifier, + const gchar *name, + const gchar *icon, + guint32 priority, + MateMixerDevicePortDirection direction, + MateMixerDevicePortStatus status, + gint64 latency_offset); + +G_END_DECLS + +#endif /* MATEMIXER_PORT_H */ diff --git a/libmatemixer/matemixer-device-profile.c b/libmatemixer/matemixer-device-profile.c new file mode 100644 index 0000000..bfcbe6a --- /dev/null +++ b/libmatemixer/matemixer-device-profile.c @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include + +#include "matemixer-device-profile.h" + +struct _MateMixerDeviceProfilePrivate +{ + gchar *identifier; + gchar *name; + guint32 priority; +}; + +enum +{ + PROP_0, + PROP_IDENTIFIER, + PROP_NAME, + PROP_PRIORITY, + N_PROPERTIES +}; + +static GParamSpec *properties[N_PROPERTIES] = { NULL, }; + +G_DEFINE_TYPE (MateMixerDeviceProfile, mate_mixer_device_profile, G_TYPE_OBJECT); + +static void +mate_mixer_device_profile_init (MateMixerDeviceProfile *profile) +{ + profile->priv = G_TYPE_INSTANCE_GET_PRIVATE ( + profile, + MATE_MIXER_TYPE_DEVICE_PROFILE, + MateMixerDeviceProfilePrivate); +} + +static void +mate_mixer_device_profile_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + MateMixerDeviceProfile *profile; + + profile = MATE_MIXER_DEVICE_PROFILE (object); + + switch (param_id) { + case PROP_IDENTIFIER: + g_value_set_string (value, profile->priv->identifier); + break; + case PROP_NAME: + g_value_set_string (value, profile->priv->name); + break; + case PROP_PRIORITY: + g_value_set_uint (value, profile->priv->priority); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + +static void +mate_mixer_device_profile_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + MateMixerDeviceProfile *profile; + + profile = MATE_MIXER_DEVICE_PROFILE (object); + + switch (param_id) { + case PROP_IDENTIFIER: + profile->priv->identifier = g_strdup (g_value_get_string (value)); + break; + case PROP_NAME: + profile->priv->name = g_strdup (g_value_get_string (value)); + break; + case PROP_PRIORITY: + profile->priv->priority = g_value_get_uint (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + +static void +mate_mixer_device_profile_finalize (GObject *object) +{ + MateMixerDeviceProfile *profile; + + profile = MATE_MIXER_DEVICE_PROFILE (object); + + g_free (profile->priv->identifier); + g_free (profile->priv->name); + + G_OBJECT_CLASS (mate_mixer_device_profile_parent_class)->finalize (object); +} + +static void +mate_mixer_device_profile_class_init (MateMixerDeviceProfileClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = mate_mixer_device_profile_finalize; + object_class->get_property = mate_mixer_device_profile_get_property; + object_class->set_property = mate_mixer_device_profile_set_property; + + properties[PROP_IDENTIFIER] = g_param_spec_string( + "identifier", + "Identifier", + "Identifier of the device profile", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + properties[PROP_NAME] = g_param_spec_string( + "name", + "Name", + "Name of the device profile", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + properties[PROP_PRIORITY] = g_param_spec_uint( + "priority", + "Priority", + "Priority of the device profile", + 0, + G_MAXUINT32, + 0, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + g_object_class_install_properties (object_class, N_PROPERTIES, properties); + + g_type_class_add_private (object_class, sizeof (MateMixerDeviceProfilePrivate)); +} + +MateMixerDeviceProfile * +mate_mixer_device_profile_new (const gchar *identifier, + const gchar *name, + guint32 priority) +{ + return g_object_new (MATE_MIXER_TYPE_DEVICE_PROFILE, + "identifier", identifier, + "name", name, + "priority", priority, + NULL); +} diff --git a/libmatemixer/matemixer-device-profile.h b/libmatemixer/matemixer-device-profile.h new file mode 100644 index 0000000..fa750b8 --- /dev/null +++ b/libmatemixer/matemixer-device-profile.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_DEVICE_PROFILE_H +#define MATEMIXER_DEVICE_PROFILE_H + +#include +#include + +G_BEGIN_DECLS + +#define MATE_MIXER_TYPE_DEVICE_PROFILE \ + (mate_mixer_device_profile_get_type ()) +#define MATE_MIXER_DEVICE_PROFILE(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_MIXER_TYPE_DEVICE_PROFILE, MateMixerDeviceProfile)) +#define MATE_MIXER_IS_DEVICE_PROFILE(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_MIXER_TYPE_DEVICE_PROFILE)) +#define MATE_MIXER_DEVICE_PROFILE_CLASS(k) \ + (G_TYPE_CHECK_CLASS_CAST ((k), MATE_MIXER_TYPE_DEVICE_PROFILE, MateMixerDeviceProfileClass)) +#define MATE_MIXER_IS_DEVICE_PROFILE_CLASS(k) \ + (G_TYPE_CLASS_CHECK_CLASS_TYPE ((k), MATE_MIXER_TYPE_DEVICE_PROFILE)) +#define MATE_MIXER_DEVICE_PROFILE_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_MIXER_TYPE_DEVICE_PROFILE, MateMixerDeviceProfileClass)) + +typedef struct _MateMixerDeviceProfile MateMixerDeviceProfile; +typedef struct _MateMixerDeviceProfileClass MateMixerDeviceProfileClass; +typedef struct _MateMixerDeviceProfilePrivate MateMixerDeviceProfilePrivate; + +struct _MateMixerDeviceProfile +{ + GObject parent; + + MateMixerDeviceProfilePrivate *priv; +}; + +struct _MateMixerDeviceProfileClass +{ + GObjectClass parent; +}; + +GType mate_mixer_device_profile_get_type (void) G_GNUC_CONST; + +MateMixerDeviceProfile *mate_mixer_device_profile_new (const gchar *identifier, + const gchar *name, + guint32 priority); + +G_END_DECLS + +#endif /* MATEMIXER_PROFILE_H */ diff --git a/libmatemixer/matemixer-device.c b/libmatemixer/matemixer-device.c new file mode 100644 index 0000000..0c36b0b --- /dev/null +++ b/libmatemixer/matemixer-device.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include + +#include "matemixer-device.h" +#include "matemixer-device-profile.h" + +G_DEFINE_INTERFACE (MateMixerDevice, mate_mixer_device, G_TYPE_OBJECT) + +static void +mate_mixer_device_default_init (MateMixerDeviceInterface *iface) +{ + g_object_interface_install_property ( + iface, + g_param_spec_string ("identifier", + "Identifier", + "Identifier of the sound device", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); + + g_object_interface_install_property ( + iface, + g_param_spec_string ("name", + "Name", + "Name of the sound device", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); + + g_object_interface_install_property ( + iface, + g_param_spec_string ("icon", + "Icon", + "Name of the sound device icon", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); + + g_object_interface_install_property ( + iface, + g_param_spec_object ("active-profile", + "Active profile", + "Identifier of the currently active profile", + MATE_MIXER_TYPE_DEVICE_PROFILE, + G_PARAM_CONSTRUCT | G_PARAM_READWRITE)); +} + +const GList * +mate_mixer_device_list_tracks (MateMixerDevice *device) +{ + g_return_val_if_fail (MATE_MIXER_IS_DEVICE (device), NULL); + + return MATE_MIXER_DEVICE_GET_INTERFACE (device)->list_tracks (device); +} diff --git a/libmatemixer/matemixer-device.h b/libmatemixer/matemixer-device.h new file mode 100644 index 0000000..af5a1ce --- /dev/null +++ b/libmatemixer/matemixer-device.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_DEVICE_H +#define MATEMIXER_DEVICE_H + +#include +#include + +G_BEGIN_DECLS + +#define MATE_MIXER_TYPE_DEVICE \ + (mate_mixer_device_get_type ()) +#define MATE_MIXER_DEVICE(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_MIXER_TYPE_DEVICE, MateMixerDevice)) +#define MATE_MIXER_IS_DEVICE(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_MIXER_TYPE_DEVICE)) +#define MATE_MIXER_DEVICE_GET_INTERFACE(o) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((o), MATE_MIXER_TYPE_DEVICE, MateMixerDeviceInterface)) + +typedef struct _MateMixerDevice MateMixerDevice; /* dummy object */ +typedef struct _MateMixerDeviceInterface MateMixerDeviceInterface; + +struct _MateMixerDeviceInterface +{ + GTypeInterface parent; + + const GList *(*list_tracks) (MateMixerDevice *device); +}; + +GType mate_mixer_device_get_type (void) G_GNUC_CONST; + +const GList *mate_mixer_device_list_tracks (MateMixerDevice *device); + +G_END_DECLS + +#endif /* MATEMIXER_DEVICE_H */ diff --git a/libmatemixer/matemixer-enum-types.c.template b/libmatemixer/matemixer-enum-types.c.template new file mode 100644 index 0000000..475aed7 --- /dev/null +++ b/libmatemixer/matemixer-enum-types.c.template @@ -0,0 +1,36 @@ +/*** BEGIN file-header ***/ +#include "matemixer-enum-types.h" + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ +#include "@filename@" + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type (void) +{ + static GType etype = 0; + + if (etype == 0) { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + etype = g_@type@_register_static ( + g_intern_static_string ("@EnumName@"), + values); + } + return etype; +} + +/*** END value-tail ***/ diff --git a/libmatemixer/matemixer-enum-types.h.template b/libmatemixer/matemixer-enum-types.h.template new file mode 100644 index 0000000..55f405a --- /dev/null +++ b/libmatemixer/matemixer-enum-types.h.template @@ -0,0 +1,26 @@ +/*** BEGIN file-header ***/ +#ifndef MATEMIXER_ENUM_TYPES_H +#define MATEMIXER_ENUM_TYPES_H + +#include + +G_BEGIN_DECLS + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* Enumerations from "@filename@" */ + +/*** END file-production ***/ + +/*** BEGIN enumeration-production ***/ +#define MATE_MIXER_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) +GType @enum_name@_get_type (void) G_GNUC_CONST; + +/*** END enumeration-production ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +#endif /* MATEMIXER_ENUM_TYPES_H */ +/*** END file-tail ***/ diff --git a/libmatemixer/matemixer-enums.h b/libmatemixer/matemixer-enums.h new file mode 100644 index 0000000..445af7d --- /dev/null +++ b/libmatemixer/matemixer-enums.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_ENUMS_H +#define MATEMIXER_ENUMS_H + +typedef enum { + MATE_MIXER_BACKEND_TYPE_PULSE, + MATE_MIXER_BACKEND_TYPE_NULL +} MateMixerBackendType; + +typedef enum { /*< flags >*/ + MATE_MIXER_DEVICE_PORT_DIRECTION_INPUT = 1 << 0, + MATE_MIXER_DEVICE_PORT_DIRECTION_OUTPUT = 1 << 1 +} MateMixerDevicePortDirection; + +typedef enum { /*< flags >*/ + MATE_MIXER_DEVICE_PORT_STATUS_AVAILABLE = 1 << 0 +} MateMixerDevicePortStatus; + +#endif /* MATEMIXER_ENUMS_H */ diff --git a/libmatemixer/matemixer-private.h b/libmatemixer/matemixer-private.h new file mode 100644 index 0000000..8f95664 --- /dev/null +++ b/libmatemixer/matemixer-private.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_PRIVATE_H +#define MATEMIXER_PRIVATE_H + +#include + +G_BEGIN_DECLS + +GList *mate_mixer_get_modules (void); +gboolean mate_mixer_is_initialized (void); + +G_END_DECLS + +#endif /* MATEMIXER_PRIVATE_H */ diff --git a/libmatemixer/matemixer-track.c b/libmatemixer/matemixer-track.c new file mode 100644 index 0000000..f78c4f8 --- /dev/null +++ b/libmatemixer/matemixer-track.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include + +#include "matemixer-track.h" + +G_DEFINE_INTERFACE (MateMixerTrack, mate_mixer_track, G_TYPE_OBJECT) + +static void +mate_mixer_track_default_init (MateMixerTrackInterface *iface) +{ + // TODO: properties +} diff --git a/libmatemixer/matemixer-track.h b/libmatemixer/matemixer-track.h new file mode 100644 index 0000000..a535b59 --- /dev/null +++ b/libmatemixer/matemixer-track.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_TRACK_H +#define MATEMIXER_TRACK_H + +#include +#include + +G_BEGIN_DECLS + +#define MATE_MIXER_TYPE_TRACK \ + (mate_mixer_track_get_type ()) +#define MATE_MIXER_TRACK(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_MIXER_TYPE_TRACK, MateMixerTrack)) +#define MATE_MIXER_IS_TRACK(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_MIXER_TYPE_TRACK)) +#define MATE_MIXER_TRACK_GET_INTERFACE(o) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((o), MATE_MIXER_TYPE_TRACK, MateMixerTrackInterface)) + +typedef struct _MateMixerTrack MateMixerTrack; /* dummy object */ +typedef struct _MateMixerTrackInterface MateMixerTrackInterface; + +struct _MateMixerTrackInterface +{ + GTypeInterface parent; +}; + +GType mate_mixer_track_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* MATEMIXER_TRACK_H */ diff --git a/libmatemixer/matemixer.c b/libmatemixer/matemixer.c new file mode 100644 index 0000000..6c25cc5 --- /dev/null +++ b/libmatemixer/matemixer.c @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "config.h" + +#include +#include +#include + +#include "matemixer.h" +#include "matemixer-private.h" +#include "matemixer-backend-module.h" + +static gboolean mixer_load_backends (void); +static gint mixer_compare_modules (gconstpointer a, gconstpointer b); + +static GList *mixer_modules = NULL; +static gboolean mixer_initialized = FALSE; + +gboolean +mate_mixer_init (void) +{ + if (!mixer_initialized) + mixer_initialized = mixer_load_backends (); + + return mixer_initialized; +} + +void +mate_mixer_deinit (void) +{ + GList *list; + + if (!mixer_initialized) + return; + + list = mixer_modules; + while (list) { + MateMixerBackendModule *module; + + module = MATE_MIXER_BACKEND_MODULE (list->data); + + g_type_module_unuse (G_TYPE_MODULE (module)); + + // XXX it is not possible to unref the module, figure out how + // to handle repeated initialization + // g_object_unref (module); + + list = list->next; + } + g_list_free (mixer_modules); + + mixer_initialized = FALSE; +} + +/* Internal function: return a *shared* list of loaded backend modules */ +GList * +mate_mixer_get_modules (void) +{ + return mixer_modules; +} + +/* Internal function: return TRUE if the library has been initialized */ +gboolean +mate_mixer_is_initialized (void) +{ + gboolean initialized; + + G_LOCK_DEFINE_STATIC (mixer_initialized_lock); + + G_LOCK (mixer_initialized_lock); + initialized = mixer_initialized; + G_UNLOCK (mixer_initialized_lock); + + return initialized; +} + +static gboolean +mixer_load_backends (void) +{ + GDir *dir; + GError *error = NULL; + + if (!g_module_supported ()) { + g_critical ("Unable to load backend modules: GModule not supported"); + return FALSE; + } + + /* Read the directory which contains module libraries and load them */ + dir = g_dir_open (LIBMATEMIXER_BACKEND_DIR, 0, &error); + if (dir != NULL) { + const gchar *name; + + while ((name = g_dir_read_name (dir)) != NULL) { + gchar *file; + MateMixerBackendModule *module; + + if (!g_str_has_suffix (name, "." G_MODULE_SUFFIX)) + continue; + + file = g_build_filename (LIBMATEMIXER_BACKEND_DIR, name, NULL); + module = mate_mixer_backend_module_new (file); + + /* Load the backend module and make sure it includes all the + * required symbols */ + if (g_type_module_use (G_TYPE_MODULE (module))) + mixer_modules = g_list_prepend (mixer_modules, module); + else + g_object_unref (module); + + g_free (file); + } + + if (mixer_modules == NULL) + g_critical ("No usable backend modules have been found"); + + g_dir_close (dir); + } else { + g_critical ("%s", error->message); + g_error_free (error); + } + + if (mixer_modules) { + mixer_modules = g_list_sort (mixer_modules, mixer_compare_modules); + return TRUE; + } + + /* As we include a "null" backend module to provide no functionality, + * we fail the initialization in case no module could be loaded */ + return FALSE; +} + +/* GCompareFunc function to sort backend modules by the priority, lower + * number means higher priority */ +static gint +mixer_compare_modules (gconstpointer a, gconstpointer b) +{ + const MateMixerBackendModuleInfo *info1, *info2; + + info1 = mate_mixer_backend_module_get_info (MATE_MIXER_BACKEND_MODULE (a)); + info2 = mate_mixer_backend_module_get_info (MATE_MIXER_BACKEND_MODULE (b)); + + return info1->priority - info2->priority; +} diff --git a/libmatemixer/matemixer.h b/libmatemixer/matemixer.h new file mode 100644 index 0000000..8a62320 --- /dev/null +++ b/libmatemixer/matemixer.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014 Michal Ratajsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the licence, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MATEMIXER_H +#define MATEMIXER_H + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +gboolean mate_mixer_init (void); +void mate_mixer_deinit (void); + +G_END_DECLS + +#endif /* MATEMIXER_H */ -- cgit v1.2.1