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_connection_types.h 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17 */
18
19 #ifndef MRCP_CONNECTION_TYPES_H
20 #define MRCP_CONNECTION_TYPES_H
21
22 /**
23 * @file mrcp_connection_types.h
24 * @brief MRCP Connection Types Declaration
25 */
26
27 #include <apr_network_io.h>
28 #include "apt_string.h"
29 #include "apt_timer_queue.h"
30 #include "mrcp_types.h"
31
32 APT_BEGIN_EXTERN_C
33
34 /** Opaque MRCPv2 control descriptor declaration */
35 typedef struct mrcp_control_descriptor_t mrcp_control_descriptor_t;
36
37 /** Opaque MRCPv2 connection declaration */
38 typedef struct mrcp_connection_t mrcp_connection_t;
39
40 /** Opaque MRCPv2 control channel declaration */
41 typedef struct mrcp_control_channel_t mrcp_control_channel_t;
42
43 /** Opaque MRCPv2 connection agent declaration */
44 typedef struct mrcp_connection_agent_t mrcp_connection_agent_t;
45
46 /** Opaque MRCPv2 connection agent factory declaration */
47 typedef struct mrcp_ca_factory_t mrcp_ca_factory_t;
48
49 /** MRCPv2 connection event vtable declaration */
50 typedef struct mrcp_connection_event_vtable_t mrcp_connection_event_vtable_t;
51
52 /** MRCPv2 connection event vtable */
53 struct mrcp_connection_event_vtable_t {
54 /** Channel add event handler */
55 apt_bool_t (*on_add)(mrcp_control_channel_t *channel, mrcp_control_descriptor_t *descriptor, apt_bool_t status);
56 /** Channel modify event handler */
57 apt_bool_t (*on_modify)(mrcp_control_channel_t *channel, mrcp_control_descriptor_t *descriptor, apt_bool_t status);
58 /** Channel remove event handler */
59 apt_bool_t (*on_remove)(mrcp_control_channel_t *channel, apt_bool_t status);
60 /** Message receive event handler */
61 apt_bool_t (*on_receive)(mrcp_control_channel_t *channel, mrcp_message_t *message);
62 /** Disconnect event handler */
63 apt_bool_t (*on_disconnect)(mrcp_control_channel_t *channel);
64 };
65
66 /** MRCPv2 control channel */
67 struct mrcp_control_channel_t {
68 /** MRCPv2 Connection agent */
69 mrcp_connection_agent_t *agent;
70 /** MRCPv2 (shared) connection */
71 mrcp_connection_t *connection;
72 /** Request sent to the server and waiting for a response */
73 mrcp_message_t *active_request;
74 /** Timer used for request timeouts */
75 apt_timer_t *request_timer;
76 /** Indicate removed connection (safe to destroy) */
77 apt_bool_t removed;
78 /** External object associated with the channel */
79 void *obj;
80 /** External logger object associated with the channel */
81 void *log_obj;
82 /** Pool to allocate memory from */
83 apr_pool_t *pool;
84 /** Channel identifier (id at resource) */
85 apt_str_t identifier;
86 };
87
88 /** Send channel add response */
mrcp_control_channel_add_respond(const mrcp_connection_event_vtable_t * vtable,mrcp_control_channel_t * channel,mrcp_control_descriptor_t * descriptor,apt_bool_t status)89 static APR_INLINE apt_bool_t mrcp_control_channel_add_respond(
90 const mrcp_connection_event_vtable_t *vtable,
91 mrcp_control_channel_t *channel,
92 mrcp_control_descriptor_t *descriptor,
93 apt_bool_t status)
94 {
95 if(vtable && vtable->on_add) {
96 return vtable->on_add(channel,descriptor,status);
97 }
98 return FALSE;
99 }
100
101 /** Send channel modify response */
mrcp_control_channel_modify_respond(const mrcp_connection_event_vtable_t * vtable,mrcp_control_channel_t * channel,mrcp_control_descriptor_t * descriptor,apt_bool_t status)102 static APR_INLINE apt_bool_t mrcp_control_channel_modify_respond(
103 const mrcp_connection_event_vtable_t *vtable,
104 mrcp_control_channel_t *channel,
105 mrcp_control_descriptor_t *descriptor,
106 apt_bool_t status)
107 {
108 if(vtable && vtable->on_modify) {
109 return vtable->on_modify(channel,descriptor,status);
110 }
111 return FALSE;
112 }
113
114 /** Send channel remove response */
mrcp_control_channel_remove_respond(const mrcp_connection_event_vtable_t * vtable,mrcp_control_channel_t * channel,apt_bool_t status)115 static APR_INLINE apt_bool_t mrcp_control_channel_remove_respond(
116 const mrcp_connection_event_vtable_t *vtable,
117 mrcp_control_channel_t *channel,
118 apt_bool_t status)
119 {
120 if(vtable && vtable->on_remove) {
121 return vtable->on_remove(channel,status);
122 }
123 return FALSE;
124 }
125
126 /** Send MRCP message receive event */
mrcp_connection_message_receive(const mrcp_connection_event_vtable_t * vtable,mrcp_control_channel_t * channel,mrcp_message_t * message)127 static APR_INLINE apt_bool_t mrcp_connection_message_receive(
128 const mrcp_connection_event_vtable_t *vtable,
129 mrcp_control_channel_t *channel,
130 mrcp_message_t *message)
131 {
132 if(vtable && vtable->on_receive) {
133 return vtable->on_receive(channel,message);
134 }
135 return FALSE;
136 }
137
138 APT_END_EXTERN_C
139
140 #endif /* MRCP_CONNECTION_TYPES_H */
141