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.h 2170 2014-09-09 05:19:48Z achaloyan@gmail.com $ 17 */ 18 19 #ifndef MRCP_CONNECTION_H 20 #define MRCP_CONNECTION_H 21 22 /** 23 * @file mrcp_connection.h 24 * @brief MRCP Connection 25 */ 26 27 #include <apr_poll.h> 28 #include <apr_hash.h> 29 #ifdef WIN32 30 #pragma warning(disable: 4127) 31 #endif 32 #include <apr_ring.h> 33 #include "mrcp_connection_types.h" 34 #include "mrcp_stream.h" 35 36 APT_BEGIN_EXTERN_C 37 38 /** Size of the buffer used for MRCP rx/tx stream */ 39 #define MRCP_STREAM_BUFFER_SIZE 1024 40 41 /** MRCPv2 connection */ 42 struct mrcp_connection_t { 43 /** Ring entry */ 44 APR_RING_ENTRY(mrcp_connection_t) link; 45 46 /** Memory pool */ 47 apr_pool_t *pool; 48 49 /** Accepted/Connected socket */ 50 apr_socket_t *sock; 51 /** Socket poll descriptor */ 52 apr_pollfd_t sock_pfd; 53 /** Local sockaddr */ 54 apr_sockaddr_t *l_sockaddr; 55 /** Remote sockaddr */ 56 apr_sockaddr_t *r_sockaddr; 57 /** Remote IP */ 58 apt_str_t remote_ip; 59 /** String identifier used for traces */ 60 const char *id; 61 /** Transparently dump whatever received/sent on transport layer, 62 if verbose is set to TRUE (default) */ 63 apt_bool_t verbose; 64 65 /** Reference count */ 66 apr_size_t access_count; 67 /** Opaque agent */ 68 void *agent; 69 70 /** Table of control channels */ 71 apr_hash_t *channel_table; 72 73 /** Rx buffer */ 74 char *rx_buffer; 75 /** Rx buffer size */ 76 apr_size_t rx_buffer_size; 77 /** Rx stream */ 78 apt_text_stream_t rx_stream; 79 /** MRCP parser to parser MRCP messages out of rx stream */ 80 mrcp_parser_t *parser; 81 82 /** Tx buffer */ 83 char *tx_buffer; 84 /** Tx buffer size */ 85 apr_size_t tx_buffer_size; 86 /** MRCP generator to generate MRCP messages into tx stream */ 87 mrcp_generator_t *generator; 88 }; 89 90 /** Create MRCP connection. */ 91 mrcp_connection_t* mrcp_connection_create(void); 92 93 /** Destroy MRCP connection. */ 94 void mrcp_connection_destroy(mrcp_connection_t *connection); 95 96 /** Add Control Channel to MRCP connection. */ 97 apt_bool_t mrcp_connection_channel_add(mrcp_connection_t *connection, mrcp_control_channel_t *channel); 98 99 /** Find Control Channel by Channel Identifier. */ 100 mrcp_control_channel_t* mrcp_connection_channel_find(const mrcp_connection_t *connection, const apt_str_t *identifier); 101 102 /** Remove Control Channel from MRCP connection. */ 103 apt_bool_t mrcp_connection_channel_remove(mrcp_connection_t *connection, mrcp_control_channel_t *channel); 104 105 /** Raise disconnect event for each channel from the specified connection. */ 106 apt_bool_t mrcp_connection_disconnect_raise(mrcp_connection_t *connection, const mrcp_connection_event_vtable_t *vtable); 107 108 APT_END_EXTERN_C 109 110 #endif /* MRCP_CONNECTION_H */ 111