Add volume context changes; accidentally fix whitespace.
authorIsmo Puustinen <ismo.puustinen@intel.com>
Wed, 21 May 2014 07:19:49 +0000 (10:19 +0300)
committerJaska Uimonen <jaska.uimonen@helsinki.fi>
Thu, 22 May 2014 12:24:03 +0000 (15:24 +0300)
Change-Id: Iab35e42bf076a07978b96829160f528d89f510f5

murphy/Makefile.am
murphy/murphy-ivi.lua
murphy/murphyif.c
murphy/scripting.c
murphy/volume.c
murphy/volume.h

index c4c8323..e73d375 100644 (file)
@@ -63,7 +63,7 @@ module_murphy_ivi_la_LIBADD = $(AM_LIBADD) $(CONDITIONAL_LIBS)              \
                               $(LIBPULSE_LIBS) $(PULSEDEVEL_LIBS)           \
                               $(MURPHYCOMMON_LIBS) $(MURPHYDOMCTL_LIBS)     \
                               $(LUAUTILS_LIBS) $(LUA_LIBS)                  \
-                              $(AUL_LIBS)
+                              $(AUL_LIBS) -lmain-volume-policy
 module_murphy_ivi_la_CFLAGS = $(AM_CFLAGS) $(CONDITIONAL_CFLAGS)            \
                               $(LIBPULSE_CFLAGS) $(PULSEDEVEL_CFLAGS)       \
                               $(MURPHYCOMMON_CFLAGS) $(MURPHYDOMCTL_CFLAGS) \
index fc3dd50..b2b40dc 100644 (file)
@@ -170,6 +170,14 @@ mdb.import {
     update = builtin.method.make_volumes
 }
 
+mdb.import {
+    table = "volume_context",
+    columns = {"value"},
+    condition = "id = 1",
+    maxrow = 1,
+    update = builtin.method.change_volume_context
+}
+
 volume_limit {
     name = "speed_adjust",
     type = volume_limit.generic,
index 4ff7891..0f2d8bc 100644 (file)
@@ -307,7 +307,7 @@ pa_murphyif *pa_murphyif_init(struct userdata *u,
             if (resource_transport_connect(rif) == DISCONNECTED)
                 schedule_connect(u, rif);
         }
-    }    
+    }
 
     rif->seqno.request = 1;
     rif->nodes.rsetid = pa_hashmap_new(pa_idxset_string_hash_func,
@@ -419,7 +419,7 @@ void pa_murphyif_add_table(struct userdata *u,
     mrp_domctl_table_t *t;
     size_t size;
     size_t idx;
-    
+
     pa_assert(u);
     pa_assert(table);
     pa_assert(columns);
@@ -447,7 +447,7 @@ int pa_murphyif_add_watch(struct userdata *u,
     mrp_domctl_watch_t *w;
     size_t size;
     size_t idx;
-    
+
     pa_assert(u);
     pa_assert(table);
     pa_assert(columns);
@@ -969,7 +969,7 @@ static mrp_msg_t *resource_create_request(uint32_t seqno,
 
     if (!msg)
         pa_log("can't to create new resource message");
+
     return msg;
 }
 
@@ -1396,7 +1396,7 @@ static bool resource_push_attributes(mrp_msg_t *msg,
             if (!PUSH_VALUE(msg, ATTRIBUTE_VALUE, SINT8, *v.i32))
                 return false;
             break;
-            
+
         case mqi_unsignd:
             if (sts < 0)
                 v.u32 = &attr->def.value.unsignd;
@@ -1405,7 +1405,7 @@ static bool resource_push_attributes(mrp_msg_t *msg,
             if (!PUSH_VALUE(msg, ATTRIBUTE_VALUE, SINT8, *v.u32))
                 return false;
             break;
-            
+
         case mqi_floating:
             if (sts < 0)
                 v.dbl = &attr->def.value.floating;
@@ -1465,12 +1465,12 @@ static void resource_recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
     PA_LLIST_FOREACH_SAFE(req, n, rif->reqs) {
         if (req->seqno <= seqno) {
             nodidx = req->nodidx;
-            
+
             if (req->reqid == reqid) {
                 PA_LLIST_REMOVE(resource_request, rif->reqs, req);
                 pa_xfree(req);
             }
-            
+
             if (!(node = mir_node_find_by_index(u, nodidx))) {
                 if (reqid != RESPROTO_DESTROY_RESOURCE_SET) {
                     pa_log("got response (reqid:%u seqno:%u) but can't "
@@ -1486,7 +1486,7 @@ static void resource_recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
                     pa_log_debug("got response (reqid:%u seqno:%u "
                                  "node:'%s')", reqid, seqno,
                                  node ? node->amname : "<unknown>");
-                    
+
                     switch (reqid) {
                     case RESPROTO_CREATE_RESOURCE_SET:
                         resource_set_create_response(u, node, msg, &curs);
@@ -1530,7 +1530,7 @@ static void resource_set_create_response(struct userdata *u, mir_node *node,
     }
 
     node->rsetid = pa_sprintf_malloc("%d", rsetid);
-    
+
     if (pa_murphyif_add_node(u, node) == 0) {
         pa_log_debug("resource set was successfully created");
         mir_node_print(node, buf, sizeof(buf));
@@ -1738,7 +1738,7 @@ static void connect_attempt(pa_mainloop_api *a,
     struct userdata *u = (struct userdata *)data;
     pa_murphyif *murphyif;
     resource_interface *rif;
-    
+
     int state;
 
     pa_assert(u);
@@ -1761,7 +1761,7 @@ static void connect_attempt(pa_mainloop_api *a,
         case CONNECTED:
             cancel_schedule(u, rif);
             break;
-            
+
         case DISCONNECTED:
             schedule_connect(u, rif);
             break;
@@ -1862,7 +1862,7 @@ static void node_enforce_resource_policy(struct userdata *u,
     pa_assert(node);
     pa_assert(rset);
     pa_assert(rset->policy);
-    
+
 
     if (pa_streq(rset->policy, "relaxed"))
         req = PA_STREAM_RUN;
@@ -1976,7 +1976,7 @@ static int pid_hashmap_put(struct userdata *u, const char *pid,
     pa_assert(pid);
     pa_assert(node || rset);
     pa_assert_se((murphyif = u->murphyif));
-    
+
     rif = &murphyif->resource;
 
     ph = pa_xnew0(pid_hash, 1);
@@ -2001,7 +2001,7 @@ static mir_node *pid_hashmap_get_node(struct userdata *u, const char *pid)
     pa_assert(u);
     pa_assert(pid);
     pa_assert(murphyif = u->murphyif);
-    
+
     rif = &murphyif->resource;
 
     if ((ph = pa_hashmap_get(rif->nodes.pid, pid)))
@@ -2019,7 +2019,7 @@ static rset_data *pid_hashmap_get_rset(struct userdata *u, const char *pid)
     pa_assert(u);
     pa_assert(pid);
     pa_assert(murphyif = u->murphyif);
-    
+
     rif = &murphyif->resource;
 
     if ((ph = pa_hashmap_get(rif->nodes.pid, pid)))
@@ -2104,7 +2104,7 @@ static rset_hash *rset_hashmap_put(struct userdata *u,
     pa_assert(rsetid);
     pa_assert(node);
     pa_assert_se((murphyif = u->murphyif));
-    
+
     rif = &murphyif->resource;
 
     if ((rh = pa_hashmap_get(rif->nodes.rsetid, rsetid))) {
@@ -2149,7 +2149,7 @@ static rset_hash *rset_hashmap_get(struct userdata *u, const char *rsetid)
     pa_assert(u);
     pa_assert(rsetid);
     pa_assert(murphyif = u->murphyif);
-    
+
     rif = &murphyif->resource;
 
     if ((rh = pa_hashmap_get(rif->nodes.rsetid, rsetid)))
@@ -2207,7 +2207,7 @@ static pa_proplist *get_node_proplist(struct userdata *u, mir_node *node)
     pa_assert(u);
     pa_assert(node);
     pa_assert_se((core = u->core));
-    
+
     if (node->implement == mir_stream && node->paidx != PA_IDXSET_INVALID) {
         if (node->direction == mir_input) {
             if ((i = pa_idxset_get_by_index(core->sink_inputs, node->paidx)))
@@ -2227,7 +2227,7 @@ static const char *get_node_pid(struct userdata *u, mir_node *node)
     pa_proplist *pl;
 
     pa_assert(u);
+
     if (node && (pl = get_node_proplist(u, node)))
         return pa_proplist_gets(pl, PA_PROP_APPLICATION_PROCESS_ID);
 
index 52a5468..a7a3c8e 100644 (file)
@@ -278,6 +278,9 @@ static bool accept_bridge(lua_State *, void *, const char *,
 static bool compare_bridge(lua_State *, void *, const char *,
                            mrp_funcbridge_value_t *, char *,
                            mrp_funcbridge_value_t *);
+static bool change_bridge(lua_State *, void *, const char *,
+                           mrp_funcbridge_value_t *, char *,
+                           mrp_funcbridge_value_t *);
 
 static int  apclass_create(lua_State *);
 static int  apclass_getfield(lua_State *);
@@ -668,7 +671,7 @@ static int import_setfield(lua_State *L)
 
     f = luaL_checkstring(L, 2);
     luaL_error(L, "attempt to set '%s' field of read-only mdb.import", f);
-    
+
     MRP_LUA_LEAVE(0);
 }
 
@@ -787,7 +790,7 @@ static void import_data_changed(struct userdata *u,
         pa_assert(imp->update);
         pa_assert_se((ptval = imp->values));
         pa_assert_se((prow = ptval->array));
-        
+
         maxrow = -ptval->type;
         maxcol = imp->columns->nstring;
 
@@ -938,10 +941,10 @@ static int array_getfield(lua_State *L)
     arr = (pa_value *)luaL_checkudata(L, 1, ARRAY_CLASSID);
 
     pa_assert(arr->type < 0);
-    
+
     dimension = -arr->type;
     key_type = lua_type(L, 2);
-    
+
     switch (key_type) {
     case LUA_TNUMBER:
         idx = lua_tointeger(L, 2) - 1;
@@ -1006,7 +1009,7 @@ static int array_getlength(lua_State *L)
 #if 0
 static void array_destroy(void *data)
 {
-    pa_value *value = (pa_value *)data; 
+    pa_value *value = (pa_value *)data;
 
     MRP_LUA_ENTER;
 
@@ -1054,7 +1057,7 @@ void pa_scripting_node_destroy(struct userdata *u, mir_node *node)
 
     pa_assert(u);
     pa_assert(node);
-    
+
     pa_assert_se((scripting = u->scripting));
     pa_assert_se((L = scripting->L));
 
@@ -1115,7 +1118,7 @@ static int node_setfield(lua_State *L)
     const char *f;
 
     MRP_LUA_ENTER;
-    
+
     f = luaL_checkstring(L, 2);
     luaL_error(L, "attempt to set '%s' field of read-only node", f);
 
@@ -1229,7 +1232,7 @@ static int zone_setfield(lua_State *L)
 
     f = luaL_checkstring(L, 2);
     luaL_error(L, "attempt to set '%s' field of read-only zone", f);
-    
+
     MRP_LUA_LEAVE(0);
 }
 
@@ -1240,7 +1243,7 @@ static void zone_destroy(void *data)
     MRP_LUA_ENTER;
 
     pa_xfree((void *)zone->name);
-    
+
     zone->name = NULL;
 
     MRP_LUA_LEAVE_NOARG;
@@ -1362,7 +1365,7 @@ static int resource_setfield(lua_State *L)
 
     f = luaL_checkstring(L, 2);
     luaL_error(L, "attempt to set '%s' field of read-only resource_class", f);
-    
+
     MRP_LUA_LEAVE(0);
 }
 
@@ -1374,7 +1377,7 @@ static void resource_destroy(void *data)
 
     resource_names_destroy(res->name);
     attributes_destroy(res->attributes);
-    
+
     res->name = NULL;
     res->attributes = NULL;
 
@@ -1478,7 +1481,7 @@ static int rtgroup_setfield(lua_State *L)
 
     f = luaL_checkstring(L, 2);
     luaL_error(L, "attempt to set '%s' field of read-only routing_group", f);
-    
+
     MRP_LUA_LEAVE(0);
 }
 
@@ -1689,6 +1692,49 @@ static bool compare_bridge(lua_State *L, void *data,
 }
 
 
+static bool change_bridge(lua_State *L, void *data,
+                          const char *signature, mrp_funcbridge_value_t *args,
+                          char *ret_type, mrp_funcbridge_value_t *ret_val)
+{
+    mir_change_value_t change;
+    scripting_import *imp;
+    struct userdata *u;
+    bool success;
+    const char *s = "default";
+
+    (void)L;
+
+    pa_assert(signature);
+    pa_assert(args);
+    pa_assert(ret_type);
+    pa_assert(ret_val);
+
+    pa_assert_se((change = (mir_change_value_t)data));
+
+    if (strcmp(signature, "o"))
+        success = false;
+    else {
+        pa_assert_se((imp = args[0].pointer));
+        pa_assert_se((u = imp->userdata));
+
+        /* FIXME: is this how it is supposed to be done?! */
+
+        if (imp->values && imp->values->array && imp->values->array[0] &&
+              imp->values->array[0]->array &&
+              imp->values->array[0]->array[0] &&
+              imp->values->array[0]->array[0]->type == pa_value_string)
+            pa_assert_se((s = imp->values->array[0]->array[0]->string));
+
+        success = true;
+        *ret_type = MRP_FUNCBRIDGE_NO_DATA;
+        memset(ret_val, 0, sizeof(mrp_funcbridge_value_t));
+        change(u, s);
+    }
+
+    return success;
+}
+
+
 static int apclass_create(lua_State *L)
 {
     struct userdata *u;
@@ -1743,7 +1789,7 @@ static int apclass_create(lua_State *L)
 
     make_id(name, sizeof(name), "%s", mir_node_type_str(type));
 
-    mir_router_assign_class_priority(u, type, priority); 
+    mir_router_assign_class_priority(u, type, priority);
 
     ir = or = true;
 
@@ -1848,7 +1894,7 @@ static int apclass_setfield(lua_State *L)
 
     f = luaL_checkstring(L, 2);
     luaL_error(L,"attempt to set '%s' field of read-only application class",f);
-    
+
     MRP_LUA_LEAVE(0);
 }
 
@@ -2034,7 +2080,7 @@ static int route_push(lua_State *L, route_t *rt)
             route_definition_push(L, rt->input);
             lua_settable(L, -3);
         }
-        
+
         if (rt->output) {
             lua_pushstring(L, "output");
             route_definition_push(L, rt->output);
@@ -2207,7 +2253,7 @@ static int vollim_create(lua_State *L)
     }
     else if (correct) {
         /* *(double **)vlim->args = limit->value; */
-    
+
         memcpy(vlim->args, &limit->value, sizeof(limit->value));
     }
 
@@ -2265,7 +2311,7 @@ static int vollim_setfield(lua_State *L)
 
     f = luaL_checkstring(L, 2);
     luaL_error(L, "attempt to set '%s' field of read-only volume_limit", f);
-    
+
     MRP_LUA_LEAVE(0);
 }
 
@@ -2470,14 +2516,14 @@ static intarray_t *intarray_check(lua_State *L, int idx, int min, int max)
         for (i = 0;  i < len;  i++) {
             lua_pushnumber(L, (int)(i+1));
             lua_gettable(L, idx);
-            
+
             val = luaL_checkint(L, -1);
-            
+
             lua_pop(L, 1);
-            
+
             if (val < min || val >= max)
-                luaL_error(L, "array [%u]: out of range value (%d)", i, val); 
-            
+                luaL_error(L, "array [%u]: out of range value (%d)", i, val);
+
             arr->ints[i] = val;
         }
     }
@@ -2576,7 +2622,7 @@ static attribute_t *attributes_check(lua_State *L, int tbl)
         def = lua_gettop(L);
 
         attr->def.name = pa_xstrdup(fldnam);
-        
+
         if ((len = luaL_getn(L, def)) != 3)
             luaL_error(L, "invalid attribute definition '%s'", fldnam);
 
@@ -2671,7 +2717,7 @@ static map_t *map_check(lua_State *L, int tbl)
             m->needres = FALSE;
             m->role = mrp_strdup(lua_tostring(L, def));
             break;
-            
+
         case LUA_TTABLE:
             m->needres = true;
 
@@ -2950,14 +2996,14 @@ static field_t field_name_to_type(const char *name, size_t len)
     case 10:
         if (!strcmp(name, "attributes"))
             return ATTRIBUTES;
-        break;        
+        break;
 
     case 11:
         if (!strcmp(name, "autorelease"))
             return AUTORELEASE;
         if (!strcmp(name, "description"))
             return DESCRIPTION;
-        break;        
+        break;
 
     default:
         break;
@@ -3180,6 +3226,7 @@ static bool register_methods(lua_State *L)
         {"compare_phone"  ,"ooo", compare_bridge  ,mir_router_phone_compare  },
         {"volume_supress" ,"odo", calculate_bridge,mir_volume_suppress       },
         {"volume_correct" ,"odo", calculate_bridge,mir_volume_correction     },
+        {"change_volume_context","o",change_bridge,mir_volume_change_context},
         {       NULL      , NULL,      NULL       ,         NULL             }
     };
 
@@ -3226,7 +3273,7 @@ static int panic(lua_State *L)
     return 0;
 }
 
-                                  
+
 /*
  * Local Variables:
  * c-basic-offset: 4
index 6751162..a0f1f90 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <pulsecore/pulsecore-config.h>
 
+#include <pulsemodule/modules/main-volume-policy/main-volume-policy.h>
+
 #include <pulse/proplist.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/module.h>
@@ -246,7 +248,7 @@ double mir_volume_apply_limits(struct userdata *u,
 
     return attenuation;
 }
-                               
+
 
 double mir_volume_suppress(struct userdata *u, int class, mir_node *node,
                            void *arg)
@@ -291,6 +293,32 @@ double mir_volume_correction(struct userdata *u, int class, mir_node *node,
     return 0.0;
 }
 
+void mir_volume_change_context(struct userdata *u, const char *volume_class)
+{
+    pa_main_volume_policy *policy;
+    pa_main_volume_context *ctx;
+
+    pa_assert(u);
+
+    if (!volume_class) {
+        pa_log_error("no volume class set");
+        return;
+    }
+
+    policy = pa_main_volume_policy_get(u->core);
+
+    /* see if there is a context available that maps to the volume class */
+
+    ctx = (pa_main_volume_context *) pa_hashmap_get(policy->main_volume_contexts, volume_class);
+
+    if (ctx) {
+        pa_main_volume_policy_set_active_main_volume_context(policy, ctx);
+        pa_log_debug("volume context changed to: '%s'", volume_class);
+    }
+
+    /* TODO: change volume class here */
+}
+
 static void add_to_table(vlim_table *tbl, mir_volume_func_t func, void *arg)
 {
     size_t      size;
@@ -314,7 +342,7 @@ static void add_to_table(vlim_table *tbl, mir_volume_func_t func, void *arg)
 static void destroy_table(vlim_table *tbl)
 {
     pa_assert(tbl);
-    
+
     free(tbl->entries);
 }
 
@@ -404,7 +432,7 @@ static void add_volume_limit(struct userdata *u, mir_node *node, int class)
     }
     else {
         mask = ((uint32_t)1) << (class - mir_application_class_begin);
-        
+
         if (class < volume->classlen && volume->classlim[class].nentry > 0) {
             if (!(vlim->clmask & mask)) {
 
index 2ee95ad..25ef215 100644 (file)
@@ -27,7 +27,7 @@
 
 
 typedef double (*mir_volume_func_t)(struct userdata *, int, mir_node *, void*);
-
+typedef void (*mir_change_value_t)(struct userdata *, const char *);
 
 struct mir_vlim {
     size_t         maxentry;    /**< length of the class table  */
@@ -62,6 +62,8 @@ double mir_volume_apply_limits(struct userdata *, mir_node *, int, uint32_t);
 double mir_volume_suppress(struct userdata *, int, mir_node *, void *);
 double mir_volume_correction(struct userdata *, int, mir_node *, void *);
 
+void mir_volume_change_context(struct userdata *u, const char *volume_class);
+
 #endif  /* foomirvolumefoo */