[pulseaudio-discuss] [PATCH] call-state-tracker: New component.

Maarten Bosmans mkbosmans at gmail.com
Tue Apr 5 14:57:41 PDT 2011


What are the users of this state tracker? Is it only some out-of-tree
Meego modules? Are you planning to submit those too? At least a
snippet of how it should be used would be nice.

If I read correctly it is a global boolean state tracker that is a
thin wrapper around pa_shared. Is it possible to add the update-hook
capability pa_shared and just use that from the modules. It would
probably mean a couple of lines more in the modules, but the
functionality in pulsecore would be more generic and more widely
usable then.

Maarten

2011/4/5 Tanu Kaskinen <tanu.kaskinen at digia.com>:
> From: Tanu Kaskinen <ext-tanu.kaskinen at nokia.com>
>
> ---
>  src/Makefile.am                    |    1 +
>  src/pulsecore/call-state-tracker.c |  127 ++++++++++++++++++++++++++++++++++++
>  src/pulsecore/call-state-tracker.h |   54 +++++++++++++++
>  3 files changed, 182 insertions(+), 0 deletions(-)
>  create mode 100644 src/pulsecore/call-state-tracker.c
>  create mode 100644 src/pulsecore/call-state-tracker.h
>
> diff --git a/src/Makefile.am b/src/Makefile.am
> index bdedded..85c5602 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -835,6 +835,7 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \
>                pulsecore/asyncmsgq.c pulsecore/asyncmsgq.h \
>                pulsecore/asyncq.c pulsecore/asyncq.h \
>                pulsecore/auth-cookie.c pulsecore/auth-cookie.h \
> +               pulsecore/call-state-tracker.c pulsecore/call-state-tracker.h \
>                pulsecore/cli-command.c pulsecore/cli-command.h \
>                pulsecore/cli-text.c pulsecore/cli-text.h \
>                pulsecore/client.c pulsecore/client.h \
> diff --git a/src/pulsecore/call-state-tracker.c b/src/pulsecore/call-state-tracker.c
> new file mode 100644
> index 0000000..a605685
> --- /dev/null
> +++ b/src/pulsecore/call-state-tracker.c
> @@ -0,0 +1,127 @@
> +/***
> +  This file is part of PulseAudio.
> +
> +  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
> +
> +  PulseAudio 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.1 of the License,
> +  or (at your option) any later version.
> +
> +  PulseAudio 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
> +  General Public License for more details.
> +
> +  You should have received a copy of the GNU Lesser General Public License
> +  along with PulseAudio; if not, write to the Free Software
> +  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> +  USA.
> +***/
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <pulsecore/core.h>
> +#include <pulsecore/hook-list.h>
> +#include <pulsecore/log.h>
> +#include <pulsecore/macro.h>
> +#include <pulsecore/refcnt.h>
> +#include <pulsecore/shared.h>
> +
> +#include "call-state-tracker.h"
> +
> +struct pa_call_state_tracker {
> +    PA_REFCNT_DECLARE;
> +
> +    pa_core *core;
> +    pa_bool_t active;
> +    pa_hook hooks[PA_CALL_STATE_HOOK_MAX];
> +};
> +
> +static pa_call_state_tracker* call_state_tracker_new(pa_core *c) {
> +    pa_call_state_tracker *t;
> +    pa_call_state_hook_t h;
> +
> +    pa_assert(c);
> +
> +    t = pa_xnew0(pa_call_state_tracker, 1);
> +    PA_REFCNT_INIT(t);
> +    t->core = pa_core_ref(c);
> +    t->active = FALSE;
> +
> +    for (h = 0; h < PA_CALL_STATE_HOOK_MAX; h++)
> +        pa_hook_init(&t->hooks[h], t);
> +
> +    pa_assert_se(pa_shared_set(c, "call-state-tracker", t) >= 0);
> +
> +    return t;
> +}
> +
> +pa_call_state_tracker *pa_call_state_tracker_get(pa_core *core) {
> +    pa_call_state_tracker *t;
> +
> +    if ((t = pa_shared_get(core, "call-state-tracker")))
> +        return pa_call_state_tracker_ref(t);
> +
> +    return call_state_tracker_new(core);
> +}
> +
> +pa_call_state_tracker *pa_call_state_tracker_ref(pa_call_state_tracker *t) {
> +    pa_assert(t);
> +    pa_assert(PA_REFCNT_VALUE(t) >= 1);
> +
> +    PA_REFCNT_INC(t);
> +
> +    return t;
> +}
> +
> +void pa_call_state_tracker_unref(pa_call_state_tracker *t) {
> +    pa_call_state_hook_t h;
> +
> +    pa_assert(t);
> +    pa_assert(PA_REFCNT_VALUE(t) >= 1);
> +
> +    if (PA_REFCNT_DEC(t) > 0)
> +        return;
> +
> +    for (h = 0; h < PA_CALL_STATE_HOOK_MAX; h++)
> +        pa_hook_done(&t->hooks[h]);
> +
> +    pa_assert_se(pa_shared_remove(t->core, "call-state-tracker") >= 0);
> +
> +    pa_core_unref(t->core);
> +
> +    pa_xfree(t);
> +}
> +
> +pa_bool_t pa_call_state_tracker_get_active(pa_call_state_tracker *t) {
> +    pa_assert(t);
> +    pa_assert(PA_REFCNT_VALUE(t) >= 1);
> +
> +    return t->active;
> +}
> +
> +void pa_call_state_tracker_set_active(pa_call_state_tracker *t, pa_bool_t active) {
> +    pa_bool_t changed;
> +
> +    pa_assert(t);
> +    pa_assert(PA_REFCNT_VALUE(t) >= 1);
> +
> +    changed = active != t->active;
> +
> +    t->active = active;
> +
> +    if (changed)
> +        pa_hook_fire(&t->hooks[PA_CALL_STATE_HOOK_CHANGED], (void *) active);
> +
> +    pa_log_debug("Call state set %s (%s)", active ? "active" : "inactive", changed ? "changed" : "not changed");
> +}
> +
> +pa_hook *pa_call_state_tracker_hooks(pa_call_state_tracker *t) {
> +    pa_assert(t);
> +    pa_assert(PA_REFCNT_VALUE(t) >= 1);
> +
> +    return t->hooks;
> +}
> diff --git a/src/pulsecore/call-state-tracker.h b/src/pulsecore/call-state-tracker.h
> new file mode 100644
> index 0000000..9a6c60b
> --- /dev/null
> +++ b/src/pulsecore/call-state-tracker.h
> @@ -0,0 +1,54 @@
> +#ifndef foocallstatetrackerhfoo
> +#define foocallstatetrackerhfoo
> +
> +/***
> +  This file is part of PulseAudio.
> +
> +  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
> +
> +  PulseAudio 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.1 of the License,
> +  or (at your option) any later version.
> +
> +  PulseAudio 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
> +  General Public License for more details.
> +
> +  You should have received a copy of the GNU Lesser General Public License
> +  along with PulseAudio; if not, write to the Free Software
> +  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> +  USA.
> +***/
> +
> +/* This is a shared singleton object, currently used by Meego's voice and
> + * policy enforcement modules. The purpose of the object is just to maintain
> + * a boolean state of "call is active" or "call is not active", and to provide
> + * notification hooks for tracking state changes. So one module will be setting
> + * the state (the voice module) and one or more modules will follow the state
> + * through the hooks (the policy enforcement module). */
> +
> +#include <pulsecore/core.h>
> +#include <pulsecore/hook-list.h>
> +
> +typedef struct pa_call_state_tracker pa_call_state_tracker;
> +
> +/* Hook data: pa_call_state_tracker pointer. */
> +typedef enum pa_call_state_hook {
> +    PA_CALL_STATE_HOOK_CHANGED, /* Call data: NULL. */
> +    PA_CALL_STATE_HOOK_MAX
> +} pa_call_state_hook_t;
> +
> +pa_call_state_tracker *pa_call_state_tracker_get(pa_core *core);
> +pa_call_state_tracker *pa_call_state_tracker_ref(pa_call_state_tracker *t);
> +void pa_call_state_tracker_unref(pa_call_state_tracker *t);
> +
> +/* If the value has not been explicitly set, returns FALSE. */
> +pa_bool_t pa_call_state_tracker_get_active(pa_call_state_tracker *t);
> +
> +void pa_call_state_tracker_set_active(pa_call_state_tracker *t, pa_bool_t active);
> +
> +pa_hook *pa_call_state_tracker_hooks(pa_call_state_tracker *t);
> +
> +#endif
> --
> 1.7.4.2
>
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at mail.0pointer.de
> https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss
>



More information about the pulseaudio-discuss mailing list