classification: add media role for binary overrides 03/10503/1
authorJanos Kovacs <jankovac503@gmail.com>
Mon, 30 Sep 2013 15:10:18 +0000 (18:10 +0300)
committerJaska Uimonen <jaska.uimonen@helsinki.fi>
Wed, 2 Oct 2013 20:52:06 +0000 (23:52 +0300)
Change-Id: I58acfd3b04270ba7b8069a9ebc0b5f37619730b0

murphy/classify.c
murphy/murphy-config.c
murphy/murphy-ivi.lua
murphy/node.c
murphy/node.h
murphy/scripting.c

index 48c4df9..b0ace55 100644 (file)
@@ -301,11 +301,12 @@ mir_node_type pa_classify_guess_stream_node_type(struct userdata *u,
                     break;
 
                 if (aul_app_get_appid_bypid(pid, buf, sizeof(buf)) < 0) {
-                    pa_log("can't obtain real application name for wrt '%s' (pid %d)", bin, pid);
+                    pa_log("can't obtain real application name for wrt '%s' "
+                           "(pid %d)", bin, pid);
                     break;
                 }
 
-               if ((name = strrchr(buf, '.')))
+                if ((name = strrchr(buf, '.')))
                     name++;
                 else
                     name = buf;
@@ -316,9 +317,12 @@ mir_node_type pa_classify_guess_stream_node_type(struct userdata *u,
                 bin = buf;
             }
 
-            if ((map = pa_nodeset_get_map_by_binary(u, bin)))
+            if ((map = pa_nodeset_get_map_by_binary(u, bin))) {
+                if (map->role)
+                    pa_proplist_sets(pl, PA_PROP_MEDIA_ROLE, map->role);
                 break;
-       }
+            }
+        }
 
         if ((role = pa_proplist_gets(pl, PA_PROP_MEDIA_ROLE)) &&
             (map = pa_nodeset_get_map_by_role(u, role)))
index 5184ac0..9a7079b 100644 (file)
@@ -230,7 +230,7 @@ static pa_bool_t use_default_configuration(struct userdata *u)
         pa_nodeset_add_role(u, t->id, t->type, NULL);
 
     for (t = binmap; t->id; t++)
-        pa_nodeset_add_binary(u, t->id, t->type, NULL);
+        pa_nodeset_add_binary(u, t->id, t->type, NULL, NULL);
 
     for (p = priormap;  p->class;  p++)
         mir_router_assign_class_priority(u, p->class, p->priority);
index a49d850..d128bac 100644 (file)
@@ -108,7 +108,7 @@ application_class {
     },
     roles = { music   = {0, "mandatory", "exclusive"},
               video   = {0, "mandatory", "exclusive"},
-             test    = {0, "mandatory", "exclusive"}
+                 test    = {0, "mandatory", "exclusive"}
     },
     binaries = { ['t8j6HTRpuz.MediaPlayer'] = no_resource }
 }
index 54437d7..9cd9d17 100644 (file)
@@ -141,6 +141,7 @@ int pa_nodeset_add_role(struct userdata *u,
     map = pa_xnew0(pa_nodeset_map, 1);
     map->name = pa_xstrdup(role);
     map->type = type;
+    map->role = pa_xstrdup(role);
 
     if (resdef) {
         map->resdef = pa_xnew(pa_nodeset_resdef, 1);
@@ -161,6 +162,7 @@ void pa_nodeset_delete_role(struct userdata *u, const char *role)
 
     if ((map = pa_hashmap_remove(ns->roles, role))) {
         pa_xfree((void *)map->name);
+        pa_xfree((void *)map->role);
         pa_xfree((void *)map->resdef);
     }
 }
@@ -186,6 +188,7 @@ pa_nodeset_map *pa_nodeset_get_map_by_role(struct userdata *u,
 int pa_nodeset_add_binary(struct userdata *u,
                           const char *bin,
                           mir_node_type type,
+                          const char *role,
                           pa_nodeset_resdef *resdef)
 {
     pa_nodeset *ns;
@@ -200,6 +203,7 @@ int pa_nodeset_add_binary(struct userdata *u,
     map = pa_xnew0(pa_nodeset_map, 1);
     map->name = pa_xstrdup(bin);
     map->type = type;
+    map->role = role ? pa_xstrdup(role) : NULL;
 
     if (resdef) {
         map->resdef = pa_xnew(pa_nodeset_resdef, 1);
@@ -220,6 +224,7 @@ void pa_nodeset_delete_binary(struct userdata *u, const char *bin)
 
     if ((map = pa_hashmap_remove(ns->binaries, bin))) {
         pa_xfree((void *)map->name);
+        pa_xfree((void *)map->role);
         pa_xfree((void *)map->resdef);
     }
 }
index efed7c0..890dd8a 100644 (file)
@@ -107,6 +107,7 @@ struct pa_nodeset_resdef {
 struct pa_nodeset_map {
     const char        *name;
     mir_node_type      type;
+    const char        *role;
     pa_nodeset_resdef *resdef;
 }; 
 
@@ -174,7 +175,7 @@ void pa_nodeset_delete_role(struct userdata *, const char *);
 pa_nodeset_map *pa_nodeset_get_map_by_role(struct userdata *, const char *);
 
 int pa_nodeset_add_binary(struct userdata *, const char *, mir_node_type,
-                        pa_nodeset_resdef *);
+                          const char *, pa_nodeset_resdef *);
 void pa_nodeset_delete_binary(struct userdata *, const char *);
 pa_nodeset_map *pa_nodeset_get_map_by_binary(struct userdata *, const char *);
 
index 502d0fd..202521f 100644 (file)
@@ -132,6 +132,7 @@ typedef struct {
 typedef struct {
     const char         *name;
     pa_bool_t           needres;
+    const char         *role;
     pa_nodeset_resdef   resource;
 } map_t;
 
@@ -1785,6 +1786,11 @@ static int apclass_create(lua_State *L)
         for (r = roles;  r->name;  r++) {
             resdef = r->needres ? &r->resource : NULL;
 
+            if (r->role && strcmp(r->role, r->name)) {
+                luaL_error(L, "conflicting roles in role definition '%s' (%s)",
+                           r->name, r->role);
+            }
+
             if (pa_nodeset_add_role(u, r->name, type, resdef)) {
                 luaL_error(L, "role '%s' is added to mutiple application "
                            "classes", r->name);
@@ -1796,7 +1802,7 @@ static int apclass_create(lua_State *L)
         for (b = binaries;  b->name;  b++) {
             resdef = b->needres ? &b->resource : NULL;
 
-            if (pa_nodeset_add_binary(u, b->name, type, resdef)) {
+            if (pa_nodeset_add_binary(u, b->name, type, b->role, resdef)) {
                 luaL_error(L, "binary '%s' is added to multiple application "
                            "classes", b->name);
             }
@@ -2602,7 +2608,8 @@ static map_t *map_check(lua_State *L, int tbl)
     int def;
     size_t namlen;
     const char *name;
-    const char *flag;
+    const char *option;
+    const char *role;
     map_t *m, *map = NULL;
     size_t n = 0;
     size_t i, len;
@@ -2631,6 +2638,11 @@ static map_t *map_check(lua_State *L, int tbl)
             m->needres = FALSE;
             break;
 
+        case LUA_TSTRING:
+            m->needres = FALSE;
+            m->role = mrp_strdup(lua_tostring(L, def));
+            break;
+            
         case LUA_TTABLE:
             m->needres = TRUE;
 
@@ -2652,19 +2664,24 @@ static map_t *map_check(lua_State *L, int tbl)
                     m->resource.priority = priority;
                 }
                 else {
-                    flag = luaL_checkstring(L, -1);
+                    option = luaL_checkstring(L, -1);
                     rd = &m->resource;
 
-                    if (pa_streq(flag, "autorelease"))
+                    if (pa_streq(option, "autorelease"))
                         rd->flags.rset |= RESPROTO_RSETFLAG_AUTORELEASE;
-                    else if (pa_streq(flag, "mandatory"))
+                    else if (pa_streq(option, "mandatory"))
                         rd->flags.audio |= RESPROTO_RESFLAG_MANDATORY;
-                    else if (pa_streq(flag, "shared"))
+                    else if (pa_streq(option, "shared"))
                         rd->flags.audio |= RESPROTO_RESFLAG_SHARED;
-                    else if (!pa_streq(flag, "optional") &&
-                             !pa_streq(flag, "exclusive") )
+                    else if (!pa_streq(option, "optional") &&
+                             !pa_streq(option, "exclusive") )
                     {
-                        luaL_error(L, "invalid flag '%s' for '%s'", flag,name);
+                        if (!m->role)
+                            m->role = pa_xstrdup(option);
+                        else {
+                            luaL_error(L, "multiple role definition '%s','%s'",
+                                       m->role, option);
+                        }
                     }
                 }
 
@@ -2693,11 +2710,17 @@ static int map_push(lua_State *L, map_t *map)
         lua_newtable(L);
 
         for (m = map;  m->name;  m++) {
-            if (!m->needres)
-                lua_pushnumber(L, 0);
+            if (!m->needres) {
+                if (m->role)
+                    lua_pushstring(L, m->role);
+                else
+                    lua_pushnumber(L, 0);
+            }
             else {
                 lua_newtable(L);
                 lua_pushinteger(L, m->resource.priority);
+                if (m->role)
+                    lua_pushstring(L, m->role);
                 if (m->resource.flags.rset & RESPROTO_RSETFLAG_AUTORELEASE)
                     lua_pushstring(L, "autorelease");
                 if (m->resource.flags.audio & RESPROTO_RESFLAG_MANDATORY)
@@ -2723,6 +2746,7 @@ static void map_destroy(map_t *map)
     if (map) {
         for (m = map;  m->name;  m++) {
             pa_xfree((void *)m->name);
+            pa_xfree((void *)m->role);
         }
         pa_xfree(map);
     }