Skip to content

Commit

Permalink
Merge branch 'jb17974' into 'master'
Browse files Browse the repository at this point in the history
Re-send device infos when policy decision point restarts.



See merge request !7
  • Loading branch information
Juho Hamalainen committed Oct 25, 2016
2 parents a84e5ec + 7832ef3 commit 8694653
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 60 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.am
Expand Up @@ -14,7 +14,8 @@ module_policy_enforcement_la_SOURCES = \
classify.c \
policy-group.c \
context.c \
dbusif.c
dbusif.c \
policy.c
module_policy_enforcement_la_LDFLAGS = -module -avoid-version
module_policy_enforcement_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) $(LIBPULSECORE_LIBS) $(LIBPULSE_LIBS) $(MEEGOCOMMON_LIBS)
module_policy_enforcement_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) $(LIBPULSE_CFLAGS) $(LIBPULSECORE_CFLAGS) $(MEEGOCOMMON_CFLAGS) -DPULSEAUDIO_VERSION=@PA_MAJOR@
5 changes: 1 addition & 4 deletions src/card-ext.c
Expand Up @@ -9,10 +9,7 @@
#include "card-ext.h"
#include "classify.h"
#include "context.h"

/* this included for the sake of pa_policy_send_device_state()
which is temporarily hosted by sink-ext.c*/
#include "sink-ext.h"
#include "policy.h"


/* hooks */
Expand Down
10 changes: 9 additions & 1 deletion src/dbusif.c
Expand Up @@ -66,6 +66,7 @@ struct pa_policy_dbusif {
char *actrule; /* match rule to catch action signals */
char *strrule; /* match rule to catch stream info signals */
int regist; /* wheter or not registered to policy daemon*/
int re_regist;
};

struct actdsc { /* action descriptor */
Expand Down Expand Up @@ -422,6 +423,7 @@ static void handle_admin_message(struct userdata *u, DBusMessage *msg)
pa_log_debug("policy decision point is up");

if (!dbusif->regist) {
dbusif->re_regist = 1;
register_to_pdp(dbusif, u);
}
}
Expand Down Expand Up @@ -963,8 +965,14 @@ static void registration_cb(DBusPendingCall *pend, void *data)
else {
pa_log_info("got reply to registration");

if (u->dbusif)
if (u->dbusif) {
u->dbusif->regist = 1;

if (u->dbusif->re_regist) {
pa_log_info("re-send device state infos to policy decision point");
pa_policy_send_device_state_full(u);
}
}
}

dbus_message_unref(reply);
Expand Down
108 changes: 108 additions & 0 deletions src/policy.c
@@ -0,0 +1,108 @@
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <pulsecore/log.h>

#include "policy.h"
#include "dbusif.h"
#include "classify.h"

void pa_policy_send_device_state(struct userdata *u, const char *state,
char *typelist)
{
#define MAX_TYPE 256

const char *types[MAX_TYPE];
int ntype;
char buf[1024];
char *p, *q, c;

if (typelist && typelist[0]) {

ntype = 0;

p = typelist - 1;
q = buf;

do {
p++;

if (ntype < MAX_TYPE)
types[ntype] = q;
else {
pa_log("%s() list overflow", __FUNCTION__);
return;
}

while ((c = *p) != ' ' && c != '\0') {
if (q < buf + sizeof(buf)-1)
*q++ = *p++;
else {
pa_log("%s() buffer overflow", __FUNCTION__);
return;
}
}
*q++ = '\0';
ntype++;

} while (*p);

pa_policy_dbusif_send_device_state(u, state, types, ntype);
}

#undef MAX_TYPE
}

void pa_policy_send_device_state_full(struct userdata *u)
{
void *state = NULL;
pa_idxset *idxset;
struct pa_card *card;
struct pa_sink *sink;
struct pa_source *source;
const char *typelist;
char buf[1024];
int len;

pa_assert(u);
pa_assert(u->core);

/* cards */
pa_assert_se((idxset = u->core->cards));
state = NULL;

while ((card = pa_idxset_iterate(idxset, &state, NULL))) {
len = pa_classify_card(u, card, PA_POLICY_DISABLE_NOTIFY, 0,
buf, sizeof(buf));
if (len > 0)
pa_policy_send_device_state(u, PA_POLICY_CONNECTED, buf);
}

/* sinks */
pa_assert_se((idxset = u->core->sinks));
state = NULL;

while ((sink = pa_idxset_iterate(idxset, &state, NULL))) {
len = pa_classify_sink(u, sink, PA_POLICY_DISABLE_NOTIFY, 0,
buf, sizeof(buf));
if (len > 0)
pa_policy_send_device_state(u, PA_POLICY_CONNECTED, buf);
}

/* sources */
pa_assert_se((idxset = u->core->sources));
state = NULL;

while ((source = pa_idxset_iterate(idxset, &state, NULL))) {
len = pa_classify_source(u, source, PA_POLICY_DISABLE_NOTIFY, 0,
buf, sizeof(buf));
if (len > 0)
pa_policy_send_device_state(u, PA_POLICY_CONNECTED, buf);
}
}
13 changes: 13 additions & 0 deletions src/policy.h
@@ -0,0 +1,13 @@
#ifndef foopolicyfoo
#define foopolicyfoo

#include "userdata.h"

#define PA_POLICY_CONNECTED "1"
#define PA_POLICY_DISCONNECTED "0"

void pa_policy_send_device_state(struct userdata *u, const char *state,
char *typelist);
void pa_policy_send_device_state_full(struct userdata *u);

#endif
47 changes: 1 addition & 46 deletions src/sink-ext.c
Expand Up @@ -21,6 +21,7 @@
#include "context.h"
#include "policy-group.h"
#include "dbusif.h"
#include "policy.h"

/* hooks */
static pa_hook_result_t sink_put(void *, void *, void *);
Expand Down Expand Up @@ -522,52 +523,6 @@ static void handle_removed_sink(struct userdata *u, struct pa_sink *sink)
}
}

void pa_policy_send_device_state(struct userdata *u, const char *state,
char *typelist)
{
#define MAX_TYPE 256

const char *types[MAX_TYPE];
int ntype;
char buf[1024];
char *p, *q, c;

if (typelist && typelist[0]) {

ntype = 0;

p = typelist - 1;
q = buf;

do {
p++;

if (ntype < MAX_TYPE)
types[ntype] = q;
else {
pa_log("%s() list overflow", __FUNCTION__);
return;
}

while ((c = *p) != ' ' && c != '\0') {
if (q < buf + sizeof(buf)-1)
*q++ = *p++;
else {
pa_log("%s() buffer overflow", __FUNCTION__);
return;
}
}
*q++ = '\0';
ntype++;

} while (*p);

pa_policy_dbusif_send_device_state(u, state, types, ntype);
}

#undef MAX_TYPE
}


/*
* Local Variables:
Expand Down
2 changes: 0 additions & 2 deletions src/sink-ext.h
Expand Up @@ -32,8 +32,6 @@ void pa_sink_ext_set_volumes(struct userdata *);
void pa_sink_ext_override_port(struct userdata *, struct pa_sink *, char *);
void pa_sink_ext_restore_port(struct userdata *, struct pa_sink *);

void pa_policy_send_device_state(struct userdata *, const char *, char *);

#endif /* foosinkextfoo */

/*
Expand Down
5 changes: 1 addition & 4 deletions src/source-ext.c
Expand Up @@ -17,10 +17,7 @@
#include "context.h"
#include "policy-group.h"
#include "dbusif.h"

/* this included for the sake of pa_policy_send_device_state()
which is temporarily hosted by sink-ext.c*/
#include "sink-ext.h"
#include "policy.h"

/* hooks */
static pa_hook_result_t source_put(void *, void *, void *);
Expand Down
2 changes: 0 additions & 2 deletions src/userdata.h
Expand Up @@ -6,8 +6,6 @@

#define PA_POLICY_DEFAULT_GROUP_NAME "othermedia"
#define PA_POLICY_DEFAULT_GROUP_PROPERTIES "media.role = x-maemo"
#define PA_POLICY_CONNECTED "1"
#define PA_POLICY_DISCONNECTED "0"

#define PA_PROP_APPLICATION_PROCESS_ARGS "application.process.args"
#define PA_PROP_APPLICATION_PROCESS_ARG0 "application.process.arg0"
Expand Down

0 comments on commit 8694653

Please sign in to comment.