murphyif: Free the connect timer when unloading
[profile/ivi/pulseaudio-module-murphy-ivi.git] / murphy / router.h
1 /*
2  * module-murphy-ivi -- PulseAudio module for providing audio routing support
3  * Copyright (c) 2012, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU Lesser General Public License,
7  * version 2.1, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
17  * MA 02110-1301 USA.
18  *
19  */
20 #ifndef foomirrouterfoo
21 #define foomirrouterfoo
22
23 #include <sys/types.h>
24
25 #include <murphy/resource/data-types.h>
26
27 #include "userdata.h"
28 #include "list.h"
29
30 typedef bool (*mir_rtgroup_accept_t)(struct userdata *, mir_rtgroup *,
31                                           mir_node *);
32 typedef int       (*mir_rtgroup_compare_t)(struct userdata *, mir_rtgroup *,
33                                            mir_node *, mir_node *);
34
35 typedef struct {
36     pa_hashmap *input;
37     pa_hashmap *output;
38 } pa_rtgroup_hash;
39
40 typedef struct {
41     mir_rtgroup **input[MRP_ZONE_MAX];
42     mir_rtgroup **output[MRP_ZONE_MAX];
43 } pa_rtgroup_classmap;
44
45 struct pa_router {
46     pa_rtgroup_hash      rtgroups;
47     int                  maplen;   /**< length of the class- and priormap */
48     pa_rtgroup_classmap  classmap; /**< to map device node types to rtgroups */
49     int                 *priormap; /**< stream node priorities */
50     mir_dlist            nodlist;  /**< priorized list of the stream nodes
51                                         (entry in node: rtprilist) */
52     mir_dlist            connlist; /**< listhead of the connections */
53 };
54
55
56 struct mir_rtentry {
57     mir_dlist    link;        /**< rtgroup chain */
58     mir_dlist    nodchain;    /**< node chain */
59     mir_rtgroup *group;       /**< back pointer to the group  */
60     mir_node    *node;        /**< pointer to the owning node */
61     bool         blocked;     /**< weather this routing entry is active */
62     uint32_t     stamp;
63 };
64
65 struct mir_rtgroup {
66     char                  *name;      /**< name of the rtgroup */
67     mir_dlist              entries;   /**< listhead of ordered rtentries */
68     mir_rtgroup_accept_t   accept;    /**< wheter to accept a node or not */
69     mir_rtgroup_compare_t  compare;   /**< comparision function for ordering */
70     scripting_rtgroup     *scripting; /**< data for scripting, if any */
71 };
72
73 struct mir_connection {
74     mir_dlist     link;     /**< list of connections */
75     bool     blocked;  /**< true if this conflicts with another route */
76     uint16_t      amid;     /**< audio manager connection id */
77     uint32_t      from;     /**< source node index */
78     uint32_t      to;       /**< destination node index */
79     uint32_t      stream;   /**< index of the sink-input to be routed */
80 };
81
82
83 pa_router *pa_router_init(struct userdata *);
84 void pa_router_done(struct userdata *);
85
86 void mir_router_assign_class_priority(struct userdata *, mir_node_type, int);
87
88 mir_rtgroup *mir_router_create_rtgroup(struct userdata *,
89                                        mir_direction, const char *,
90                                        mir_rtgroup_accept_t,
91                                        mir_rtgroup_compare_t);
92 void mir_router_destroy_rtgroup(struct userdata *, mir_direction,
93                                 const char *);
94 bool mir_router_assign_class_to_rtgroup(struct userdata *, mir_node_type,
95                                              uint32_t, mir_direction,
96                                              const char *);
97
98 void mir_router_register_node(struct userdata *, mir_node *);
99 void mir_router_unregister_node(struct userdata *, mir_node *);
100
101 mir_node *mir_router_make_prerouting(struct userdata *, mir_node *);
102 void mir_router_make_routing(struct userdata *);
103
104 mir_connection *mir_router_add_explicit_route(struct userdata *, uint16_t,
105                                               mir_node *, mir_node *);
106 void mir_router_remove_explicit_route(struct userdata *, mir_connection *);
107
108
109 int mir_router_print_rtgroups(struct userdata *, char *, int);
110
111 bool mir_router_default_accept(struct userdata *, mir_rtgroup *,
112                                     mir_node *);
113 bool mir_router_phone_accept(struct userdata *, mir_rtgroup *,
114                                   mir_node *);
115
116 int mir_router_default_compare(struct userdata *, mir_rtgroup *,
117                                mir_node *, mir_node *);
118 int mir_router_phone_compare(struct userdata *, mir_rtgroup *,
119                              mir_node *, mir_node *);
120
121
122 #endif  /* foomirrouterfoo */
123
124
125 /*
126  * Local Variables:
127  * c-basic-offset: 4
128  * indent-tabs-mode: nil
129  * End:
130  *
131  */