Parent Directory
|
Revision Log
Revision 84 - (view) (download)
| 1 : | amartin | 20 | /* |
| 2 : | * This file is part of the Dialogic Woomera Server project. | ||
| 3 : | * | ||
| 4 : | * | ||
| 5 : | * Copyright (C) 2009 Dialogic Corporation | ||
| 6 : | * All Rights Reserved | ||
| 7 : | * | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /*! | ||
| 11 : | jtarlton | 45 | * \file appwoomera.cxx |
| 12 : | amartin | 20 | * \brief Woomera HMP server. |
| 13 : | * \author John Tarlton <john.tarlton@dialogic.com> | ||
| 14 : | * \author Antony Martin <antony.martin@dialogic.com> | ||
| 15 : | * \version 0.1 | ||
| 16 : | */ | ||
| 17 : | |||
| 18 : | |||
| 19 : | /*----------------------------- Dependencies -------------------------------*/ | ||
| 20 : | |||
| 21 : | #include "logger.h" | ||
| 22 : | amartin | 28 | #include "getoption.h" |
| 23 : | #include "dialogicmanager.h" | ||
| 24 : | jtarlton | 83 | #include "ipmdevice.h" |
| 25 : | amartin | 20 | |
| 26 : | jtarlton | 80 | #include <srllib.h> |
| 27 : | #include <gclib.h> | ||
| 28 : | jtarlton | 83 | #include <ipmlib.h> |
| 29 : | jtarlton | 80 | |
| 30 : | amartin | 20 | #include <woomera.h> |
| 31 : | |||
| 32 : | /*--------------------------------------------------------------------------*/ | ||
| 33 : | jtarlton | 81 | |
| 34 : | amartin | 66 | DialogicManager* dm; //FIXME make singleton! |
| 35 : | amartin | 20 | |
| 36 : | jtarlton | 81 | |
| 37 : | /* | ||
| 38 : | jtarlton | 83 | * called from the libwoomera. |
| 39 : | jtarlton | 81 | */ |
| 40 : | jtarlton | 80 | void dialogicEventCallback( woomera_server_attr* attr ) |
| 41 : | { | ||
| 42 : | sr_waitevt(0); | ||
| 43 : | METAEVENT metaevent; | ||
| 44 : | jtarlton | 83 | if ( gc_GetMetaEvent(&metaevent) != GC_SUCCESS ) |
| 45 : | jtarlton | 80 | { |
| 46 : | /* serious problem - should never fail | ||
| 47 : | */ | ||
| 48 : | LOGDEBUG("gc_GetMetaEvent() failed"); | ||
| 49 : | } | ||
| 50 : | else | ||
| 51 : | { | ||
| 52 : | dm->dispatchEvent(metaevent); | ||
| 53 : | } | ||
| 54 : | } | ||
| 55 : | amartin | 20 | |
| 56 : | jtarlton | 54 | /* |
| 57 : | * ISDN protocol callback for Woomera messages. | ||
| 58 : | amartin | 20 | */ |
| 59 : | jtarlton | 54 | woomera_server_response* protocol_message_handler( woomera_callctlr_command* msg, |
| 60 : | void* prot_user_data ) | ||
| 61 : | amartin | 20 | { |
| 62 : | jtarlton | 54 | switch ( msg->e ) |
| 63 : | { | ||
| 64 : | case WOOMERA_CALLCTL_COMMAND_MAKE_CALL: | ||
| 65 : | { | ||
| 66 : | jtarlton | 83 | DialogicChannel* channel = dm->createDialogicChannel(msg->call_id); |
| 67 : | if ( !channel ) | ||
| 68 : | { | ||
| 69 : | return 0; | ||
| 70 : | } | ||
| 71 : | GcIsdnDevice* gc = channel->getGcDevice(); | ||
| 72 : | IpmDevice* ipm = channel->getIpmDevice(); | ||
| 73 : | |||
| 74 : | if ( (!ipm) || (!gc) ) | ||
| 75 : | { | ||
| 76 : | dm->deleteDialogicChannel(channel); | ||
| 77 : | return 0; | ||
| 78 : | } | ||
| 79 : | |||
| 80 : | jtarlton | 54 | woomera_callctlr_command_make_call* callParms = &msg->m.make_call; |
| 81 : | woomera_server_response* response = woomera_server_response_new(msg->connection_id); | ||
| 82 : | amartin | 20 | |
| 83 : | jtarlton | 83 | const char* audio = woomera_mime_get_string(msg->incoming_mime, |
| 84 : | woomera_key_raw_audio); | ||
| 85 : | //const char* audioFormat = woomera_mime_get_string(msg->incoming_mime, | ||
| 86 : | // woomera_key_raw_audio_format); | ||
| 87 : | |||
| 88 : | if ( !audio) | ||
| 89 : | { | ||
| 90 : | dm->deleteDialogicChannel(channel); | ||
| 91 : | return 0; | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | // extract the remote rtp ip address and port | ||
| 95 : | char* r_port = strchr((char *)audio, ':'); | ||
| 96 : | if ( !r_port ) | ||
| 97 : | { | ||
| 98 : | dm->deleteDialogicChannel(channel); | ||
| 99 : | return 0; | ||
| 100 : | } | ||
| 101 : | *r_port = '\0'; | ||
| 102 : | |||
| 103 : | char r_ip[50]; | ||
| 104 : | strncpy(r_ip, audio, 50); | ||
| 105 : | |||
| 106 : | r_port++; | ||
| 107 : | int r_nport = atoi(r_port); | ||
| 108 : | |||
| 109 : | // remote ip address and port. | ||
| 110 : | ipm->setRemoteAddress(r_ip, r_ip, r_nport, r_nport + 1); | ||
| 111 : | |||
| 112 : | // local ip address and port. | ||
| 113 : | std::string local_ip; | ||
| 114 : | unsigned short local_nport; | ||
| 115 : | ipm->getAddrInfo(MEDIATYPE_AUDIO_LOCAL_RTP_INFO, local_ip, local_nport); | ||
| 116 : | |||
| 117 : | std::stringstream mime_value; | ||
| 118 : | mime_value << local_ip << ":" << local_nport; | ||
| 119 : | woomera_mime_set_string(response->mime, | ||
| 120 : | woomera_key_raw_audio, | ||
| 121 : | mime_value.str().c_str()); | ||
| 122 : | |||
| 123 : | jtarlton | 54 | // get number to dial |
| 124 : | std::string remote_number; | ||
| 125 : | if ( woomera_mime_includes(msg->common_mime, woomera_key_remote_url) != 0 ) | ||
| 126 : | { | ||
| 127 : | jtarlton | 83 | remote_number = woomera_mime_get_string(msg->common_mime, |
| 128 : | woomera_key_remote_url); | ||
| 129 : | jtarlton | 54 | } |
| 130 : | else | ||
| 131 : | { | ||
| 132 : | remote_number = callParms->called_number; | ||
| 133 : | } | ||
| 134 : | |||
| 135 : | jtarlton | 83 | // FIXME pass caller name and number + media |
| 136 : | |||
| 137 : | if ( !dm->makeCall(msg->call_id, "1234", "local", remote_number) ) | ||
| 138 : | { | ||
| 139 : | dm->deleteDialogicChannel(channel); | ||
| 140 : | return 0; | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | jtarlton | 84 | for ( size_t i = 0; i < callParms->media_channel_count; i++ ) |
| 144 : | jtarlton | 83 | { |
| 145 : | callParms->media_channels[i].running = (strcmpi(callParms->media_channels[i].media_type, woomera_key_audio) == 0) ? 1 : 0; | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | jtarlton | 54 | response->response = 200; |
| 149 : | strcpy(response->args, "Call started"); | ||
| 150 : | return response; | ||
| 151 : | } | ||
| 152 : | break; | ||
| 153 : | |||
| 154 : | case WOOMERA_CALLCTL_COMMAND_HANGUP_CALL: | ||
| 155 : | { | ||
| 156 : | woomera_server_response* response = woomera_server_response_new(msg->connection_id); | ||
| 157 : | amartin | 71 | if ( !dm->hangup(msg->call_id) ) |
| 158 : | jtarlton | 54 | { |
| 159 : | response->response = 404; | ||
| 160 : | strcpy(response->args, "Call not found"); | ||
| 161 : | } | ||
| 162 : | amartin | 66 | else |
| 163 : | jtarlton | 54 | { |
| 164 : | response->response = 200; | ||
| 165 : | strcpy(response->args, "Call cleared"); | ||
| 166 : | } | ||
| 167 : | return response; | ||
| 168 : | } | ||
| 169 : | break; | ||
| 170 : | |||
| 171 : | case WOOMERA_CALLCTL_COMMAND_ANSWER_CALL: | ||
| 172 : | { | ||
| 173 : | woomera_server_response * response = woomera_server_response_new(msg->connection_id); | ||
| 174 : | amartin | 71 | if ( !dm->answer(msg->call_id) ) |
| 175 : | jtarlton | 54 | { |
| 176 : | response->response = 404; | ||
| 177 : | strcpy(response->args, "Call not found"); | ||
| 178 : | } | ||
| 179 : | amartin | 66 | else |
| 180 : | jtarlton | 54 | { |
| 181 : | response->response = 200; | ||
| 182 : | strcpy(response->args, "Call answered"); | ||
| 183 : | } | ||
| 184 : | return response; | ||
| 185 : | } | ||
| 186 : | break; | ||
| 187 : | |||
| 188 : | default: | ||
| 189 : | break; | ||
| 190 : | } | ||
| 191 : | return 0; | ||
| 192 : | amartin | 20 | } |
| 193 : | |||
| 194 : | |||
| 195 : | /* | ||
| 196 : | jtarlton | 54 | * ISDN protocol callback for Woomera media |
| 197 : | amartin | 20 | */ |
| 198 : | jtarlton | 54 | int protocol_media_handler( void* user_data, |
| 199 : | void* call_user_data, | ||
| 200 : | const char* call_id, | ||
| 201 : | unsigned session, | ||
| 202 : | unsigned int cmd, | ||
| 203 : | void* parm, | ||
| 204 : | int parmlen ) | ||
| 205 : | amartin | 20 | { |
| 206 : | jtarlton | 54 | switch ( cmd ) |
| 207 : | { | ||
| 208 : | amartin | 55 | case WOOMERA_MEDIA_CTL_READ_START: |
| 209 : | jtarlton | 54 | return 1; |
| 210 : | |||
| 211 : | amartin | 55 | case WOOMERA_MEDIA_CTL_READ_STOP: |
| 212 : | jtarlton | 54 | return 1; |
| 213 : | |||
| 214 : | amartin | 55 | case WOOMERA_MEDIA_CTL_READ: |
| 215 : | jtarlton | 54 | return 0; |
| 216 : | |||
| 217 : | amartin | 55 | case WOOMERA_MEDIA_CTL_WRITE_START: |
| 218 : | jtarlton | 54 | return 1; |
| 219 : | |||
| 220 : | amartin | 55 | case WOOMERA_MEDIA_CTL_WRITE_STOP: |
| 221 : | jtarlton | 54 | return 1; |
| 222 : | |||
| 223 : | amartin | 55 | case WOOMERA_MEDIA_CTL_WRITE: |
| 224 : | jtarlton | 54 | return 0; |
| 225 : | } | ||
| 226 : | amartin | 20 | return 0; |
| 227 : | } | ||
| 228 : | |||
| 229 : | |||
| 230 : | /* | ||
| 231 : | * Protocol definition. | ||
| 232 : | */ | ||
| 233 : | jtarlton | 54 | static woomera_protocol_def isdn_protocol = { |
| 234 : | amartin | 20 | WOOMERA_PROTOCOL_READ_PUSH | WOOMERA_PROTOCOL_WRITE_PUSH, |
| 235 : | jtarlton | 54 | protocol_message_handler, |
| 236 : | protocol_media_handler | ||
| 237 : | amartin | 20 | }; |
| 238 : | |||
| 239 : | |||
| 240 : | jtarlton | 83 | /* |
| 241 : | amartin | 20 | * |
| 242 : | */ | ||
| 243 : | amartin | 21 | void appwoomera_run(const GetOptions& opts) |
| 244 : | amartin | 20 | { |
| 245 : | amartin | 21 | |
| 246 : | LOGDEBUG("appwoomera_run()"); | ||
| 247 : | |||
| 248 : | /* Command line options | ||
| 249 : | */ | ||
| 250 : | std::string opt_woomera_port = opts.getValue("woomera-port"); | ||
| 251 : | if ( opt_woomera_port.empty() ) | ||
| 252 : | { | ||
| 253 : | opt_woomera_port = "42420"; | ||
| 254 : | } | ||
| 255 : | |||
| 256 : | amartin | 20 | /* initialise woomera subsystem |
| 257 : | */ | ||
| 258 : | woomera_init(); | ||
| 259 : | woomera_server* server = woomera_server_new(); | ||
| 260 : | woomera_callctlr* callctlr = woomera_callctlr_new(woomera_server_send_event, server); | ||
| 261 : | jtarlton | 54 | woomera_callctlr_add_protocol(callctlr, &isdn_protocol, "isdn", 0); |
| 262 : | amartin | 20 | |
| 263 : | jtarlton | 80 | /* create the woomera server |
| 264 : | amartin | 20 | */ |
| 265 : | woomera_server_attr * attr = woomera_server_attr_new(); | ||
| 266 : | attr->server = server; | ||
| 267 : | attr->callctlr = callctlr; | ||
| 268 : | amartin | 21 | attr->port = atoi(opt_woomera_port.c_str()); |
| 269 : | jtarlton | 79 | attr->timeout = 1000; |
| 270 : | attr->broadcast_port = 0; | ||
| 271 : | attr->community[0] = '\0'; | ||
| 272 : | |||
| 273 : | jtarlton | 81 | attr->callback = &dialogicEventCallback; |
| 274 : | amartin | 20 | attr->user_data = 0; |
| 275 : | jtarlton | 80 | |
| 276 : | /* initialise dialogic | ||
| 277 : | */ | ||
| 278 : | int nfds = sr_getfdcnt(); | ||
| 279 : | int* fdarray = (int *) malloc(sizeof(int) * nfds); | ||
| 280 : | sr_getfdinfo(fdarray); | ||
| 281 : | for ( int i = 0; i < nfds; i++ ) | ||
| 282 : | { | ||
| 283 : | woomera_server_set_event(server, fdarray[i], 0); | ||
| 284 : | } | ||
| 285 : | |||
| 286 : | dm = new DialogicManager; | ||
| 287 : | jtarlton | 81 | dm->setCallCtlr(callctlr); // XXXXX |
| 288 : | jtarlton | 80 | dm->init(); |
| 289 : | amartin | 20 | |
| 290 : | woomera_server_run(attr); | ||
| 291 : | |||
| 292 : | /* exit | ||
| 293 : | */ | ||
| 294 : | woomera_server_delete(server); | ||
| 295 : | } | ||
| 296 : | |||
| 297 : | |||
| 298 : | jtarlton | 41 | /* vim:ts=4:set nu: |
| 299 : | * EOF | ||
| 300 : | amartin | 20 | */ |
| No admin address has been configured | ViewVC Help |
| Powered by ViewVC 1.0.8 |