1 /*
2  * Copyright 2008-2014 Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Id: mrcp_engine_types.h 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17  */
18 
19 #ifndef MRCP_ENGINE_TYPES_H
20 #define MRCP_ENGINE_TYPES_H
21 
22 /**
23  * @file mrcp_engine_types.h
24  * @brief MRCP Engine Types
25  */
26 
27 #include <apr_tables.h>
28 #include "mrcp_state_machine.h"
29 #include "mpf_types.h"
30 #include "apt_string.h"
31 
32 APT_BEGIN_EXTERN_C
33 
34 /** MRCP engine declaration */
35 typedef struct mrcp_engine_t mrcp_engine_t;
36 /** MRCP engine config declaration */
37 typedef struct mrcp_engine_config_t mrcp_engine_config_t;
38 /** MRCP engine vtable declaration */
39 typedef struct mrcp_engine_method_vtable_t mrcp_engine_method_vtable_t;
40 /** MRCP engine event vtable declaration */
41 typedef struct mrcp_engine_event_vtable_t mrcp_engine_event_vtable_t;
42 /** MRCP engine channel declaration */
43 typedef struct mrcp_engine_channel_t mrcp_engine_channel_t;
44 /** MRCP engine channel virtual method table declaration */
45 typedef struct mrcp_engine_channel_method_vtable_t mrcp_engine_channel_method_vtable_t;
46 /** MRCP engine channel virtual event table declaration */
47 typedef struct mrcp_engine_channel_event_vtable_t mrcp_engine_channel_event_vtable_t;
48 
49 /** Table of channel virtual methods */
50 struct mrcp_engine_channel_method_vtable_t {
51 	/** Virtual destroy */
52 	apt_bool_t (*destroy)(mrcp_engine_channel_t *channel);
53 	/** Virtual open */
54 	apt_bool_t (*open)(mrcp_engine_channel_t *channel);
55 	/** Virtual close */
56 	apt_bool_t (*close)(mrcp_engine_channel_t *channel);
57 	/** Virtual process_request */
58 	apt_bool_t (*process_request)(mrcp_engine_channel_t *channel, mrcp_message_t *request);
59 };
60 
61 /** Table of channel virtual event handlers */
62 struct mrcp_engine_channel_event_vtable_t {
63 	/** Open event handler */
64 	apt_bool_t (*on_open)(mrcp_engine_channel_t *channel, apt_bool_t status);
65 	/** Close event handler */
66 	apt_bool_t (*on_close)(mrcp_engine_channel_t *channel);
67 	/** Message event handler */
68 	apt_bool_t (*on_message)(mrcp_engine_channel_t *channel, mrcp_message_t *message);
69 };
70 
71 /** MRCP engine channel declaration */
72 struct mrcp_engine_channel_t {
73 	/** Table of virtual methods */
74 	const mrcp_engine_channel_method_vtable_t *method_vtable;
75 	/** External object used with virtual methods */
76 	void                                      *method_obj;
77 	/** Table of virtual event handlers */
78 	const mrcp_engine_channel_event_vtable_t  *event_vtable;
79 	/** External object used with event handlers */
80 	void                                      *event_obj;
81 	/** Media termination */
82 	mpf_termination_t                         *termination;
83 	/** Back pointer to engine */
84 	mrcp_engine_t                             *engine;
85 	/** Unique identifier to be used in traces */
86 	apt_str_t                                  id;
87 	/** MRCP version */
88 	mrcp_version_e                             mrcp_version;
89 	/** Is channel successfully opened */
90 	apt_bool_t                                is_open;
91 	/** Pool to allocate memory from */
92 	apr_pool_t                                *pool;
93 };
94 
95 /** Table of MRCP engine virtual methods */
96 struct mrcp_engine_method_vtable_t {
97 	/** Virtual destroy */
98 	apt_bool_t (*destroy)(mrcp_engine_t *engine);
99 	/** Virtual open */
100 	apt_bool_t (*open)(mrcp_engine_t *engine);
101 	/** Virtual close */
102 	apt_bool_t (*close)(mrcp_engine_t *engine);
103 	/** Virtual channel create */
104 	mrcp_engine_channel_t* (*create_channel)(mrcp_engine_t *engine, apr_pool_t *pool);
105 };
106 
107 /** Table of MRCP engine virtual event handlers */
108 struct mrcp_engine_event_vtable_t {
109 	/** Open event handler */
110 	apt_bool_t (*on_open)(mrcp_engine_t *channel, apt_bool_t status);
111 	/** Close event handler */
112 	apt_bool_t (*on_close)(mrcp_engine_t *channel);
113 };
114 
115 /** MRCP engine */
116 struct mrcp_engine_t {
117 	/** Identifier of the engine */
118 	const char                        *id;
119 	/** Resource identifier */
120 	mrcp_resource_id                   resource_id;
121 	/** External object associated with engine */
122 	void                              *obj;
123 	/** Table of virtual methods */
124 	const mrcp_engine_method_vtable_t *method_vtable;
125 	/** Table of virtual event handlers */
126 	const mrcp_engine_event_vtable_t  *event_vtable;
127 	/** External object used with event handlers */
128 	void                              *event_obj;
129 	/** Codec manager */
130 	const mpf_codec_manager_t         *codec_manager;
131 	/** Dir layout structure */
132 	const apt_dir_layout_t            *dir_layout;
133 	/** Config of engine */
134 	mrcp_engine_config_t              *config;
135 	/** Number of simultaneous channels currently in use */
136 	apr_size_t                         cur_channel_count;
137 	/** Is engine successfully opened */
138 	apt_bool_t                         is_open;
139 	/** Pool to allocate memory from */
140 	apr_pool_t                        *pool;
141 
142 	/** Create state machine */
143 	mrcp_state_machine_t* (*create_state_machine)(void *obj, mrcp_version_e version, apr_pool_t *pool);
144 };
145 
146 /** MRCP engine config */
147 struct mrcp_engine_config_t {
148 	/** Max number of simultaneous channels */
149 	apr_size_t   max_channel_count;
150 	/** Table of name/value string params */
151 	apr_table_t *params;
152 };
153 
154 APT_END_EXTERN_C
155 
156 #endif /* MRCP_ENGINE_TYPES_H */
157