void DSMCall::process(AmEvent* event) { DBG("DSMCall::process\n"); if (event->event_id == DSM_EVENT_ID) { DSMEvent* dsm_event = dynamic_cast<DSMEvent*>(event); if (dsm_event) { engine.runEvent(this, this, DSMCondition::DSMEvent, &dsm_event->params); return; } } AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event); if(audio_event && ((audio_event->event_id == AmAudioEvent::cleared) || (audio_event->event_id == AmAudioEvent::noAudio))){ map<string, string> params; params["type"] = audio_event->event_id == AmAudioEvent::cleared?"cleared":"noAudio"; engine.runEvent(this, this, DSMCondition::NoAudio, ¶ms); return; } AmPluginEvent* plugin_event = dynamic_cast<AmPluginEvent*>(event); if(plugin_event && plugin_event->name == "timer_timeout") { int timer_id = plugin_event->data.get(0).asInt(); map<string, string> params; params["id"] = int2str(timer_id); engine.runEvent(this, this, DSMCondition::Timer, ¶ms); } AmPlaylistSeparatorEvent* sep_ev = dynamic_cast<AmPlaylistSeparatorEvent*>(event); if (sep_ev) { map<string, string> params; params["id"] = int2str(sep_ev->event_id); engine.runEvent(this, this, DSMCondition::PlaylistSeparator, ¶ms); } ConferenceEvent * conf_ev = dynamic_cast<ConferenceEvent*>(event); if (conf_ev) { map<string, string> params; params["type"] = "conference_event"; params["id"] = int2str(conf_ev->event_id); engine.runEvent(this, this, DSMCondition::DSMEvent, ¶ms); } // todo: give modules the possibility to define/process events JsonRpcEvent* jsonrpc_ev = dynamic_cast<JsonRpcEvent*>(event); if (jsonrpc_ev) { DBG("received jsonrpc event\n"); JsonRpcResponseEvent* resp_ev = dynamic_cast<JsonRpcResponseEvent*>(jsonrpc_ev); if (resp_ev) { map<string, string> params; params["ev_type"] = "JsonRpcResponse"; params["id"] = resp_ev->response.id; params["is_error"] = resp_ev->response.is_error ? "true":"false"; // decode result for easy use from script varPrintArg(resp_ev->response.data, params, resp_ev->response.is_error ? "error": "result"); // decode udata for easy use from script varPrintArg(resp_ev->udata, params, "udata"); // save reference to full parameters as avar avar[DSM_AVAR_JSONRPCRESPONSEDATA] = AmArg(&resp_ev->response.data); avar[DSM_AVAR_JSONRPCRESPONSEUDATA] = AmArg(&resp_ev->udata); engine.runEvent(this, this, DSMCondition::JsonRpcResponse, ¶ms); avar.erase(DSM_AVAR_JSONRPCRESPONSEUDATA); avar.erase(DSM_AVAR_JSONRPCRESPONSEDATA); return; } JsonRpcRequestEvent* req_ev = dynamic_cast<JsonRpcRequestEvent*>(jsonrpc_ev); if (req_ev) { map<string, string> params; params["ev_type"] = "JsonRpcRequest"; params["is_notify"] = req_ev->isNotification() ? "true" : "false"; params["method"] = req_ev->method; if (!req_ev->id.empty()) params["id"] = req_ev->id; // decode request params result for easy use from script varPrintArg(req_ev->params, params, "params"); // save reference to full parameters avar[DSM_AVAR_JSONRPCREQUESTDATA] = AmArg(&req_ev->params); engine.runEvent(this, this, DSMCondition::JsonRpcRequest, ¶ms); avar.erase(DSM_AVAR_JSONRPCREQUESTDATA); return; } } if (event->event_id == E_SIP_SUBSCRIPTION) { SIPSubscriptionEvent* sub_ev = dynamic_cast<SIPSubscriptionEvent*>(event); if (sub_ev) { DBG("DSM Call received SIP Subscription Event\n"); map<string, string> params; params["status"] = sub_ev->getStatusText(); params["code"] = int2str(sub_ev->code); params["reason"] = sub_ev->reason; params["expires"] = int2str(sub_ev->expires); params["has_body"] = sub_ev->notify_body.get()?"true":"false"; if (sub_ev->notify_body.get()) { avar[DSM_AVAR_SIPSUBSCRIPTION_BODY] = AmArg(sub_ev->notify_body.get()); } engine.runEvent(this, this, DSMCondition::SIPSubscription, ¶ms); avar.erase(DSM_AVAR_SIPSUBSCRIPTION_BODY); } } AmRtpTimeoutEvent* timeout_ev = dynamic_cast<AmRtpTimeoutEvent*>(event); if (timeout_ev) { map<string, string> params; params["type"] = "rtp_timeout"; params["timeout_value"] = int2str(AmConfig::DeadRtpTime); engine.runEvent(this, this, DSMCondition::RTPTimeout, ¶ms); return; } AmB2BCallerSession::process(event); }
void SystemDSM::process(AmEvent* event) { AmPluginEvent* plugin_event = dynamic_cast<AmPluginEvent*>(event); if(plugin_event && plugin_event->name == "timer_timeout") { int timer_id = plugin_event->data.get(0).asInt(); map<string, string> params; params["id"] = int2str(timer_id); engine.runEvent(&dummy_session, this, DSMCondition::Timer, ¶ms); } if (event->event_id == DSM_EVENT_ID) { DSMEvent* dsm_event = dynamic_cast<DSMEvent*>(event); if (dsm_event) { engine.runEvent(&dummy_session, this, DSMCondition::DSMEvent, &dsm_event->params); return; } } // todo: give modules the possibility to define/process events JsonRpcEvent* jsonrpc_ev = dynamic_cast<JsonRpcEvent*>(event); if (jsonrpc_ev) { DBG("received jsonrpc event\n"); JsonRpcResponseEvent* resp_ev = dynamic_cast<JsonRpcResponseEvent*>(jsonrpc_ev); if (resp_ev) { map<string, string> params; params["ev_type"] = "JsonRpcResponse"; params["id"] = resp_ev->response.id; params["is_error"] = resp_ev->response.is_error ? "true":"false"; // decode result for easy use from script varPrintArg(resp_ev->response.data, params, resp_ev->response.is_error ? "error": "result"); // decode udata for easy use from script varPrintArg(resp_ev->udata, params, "udata"); // save reference to full parameters avar[DSM_AVAR_JSONRPCRESPONSEDATA] = AmArg(&resp_ev->response.data); avar[DSM_AVAR_JSONRPCRESPONSEUDATA] = AmArg(&resp_ev->udata); engine.runEvent(&dummy_session, this, DSMCondition::JsonRpcResponse, ¶ms); avar.erase(DSM_AVAR_JSONRPCRESPONSEUDATA); avar.erase(DSM_AVAR_JSONRPCRESPONSEDATA); return; } JsonRpcRequestEvent* req_ev = dynamic_cast<JsonRpcRequestEvent*>(jsonrpc_ev); if (req_ev) { map<string, string> params; params["ev_type"] = "JsonRpcRequest"; params["is_notify"] = req_ev->isNotification() ? "true" : "false"; params["method"] = req_ev->method; if (!req_ev->id.empty()) params["id"] = req_ev->id; // decode request params result for easy use from script varPrintArg(req_ev->params, params, "params"); // save reference to full parameters avar[DSM_AVAR_JSONRPCREQUESTDATA] = AmArg(&req_ev->params); engine.runEvent(&dummy_session, this, DSMCondition::JsonRpcRequest, ¶ms); avar.erase(DSM_AVAR_JSONRPCREQUESTDATA); return; } } if (event->event_id == E_SIP_SUBSCRIPTION) { SIPSubscriptionEvent* sub_ev = dynamic_cast<SIPSubscriptionEvent*>(event); if (sub_ev) { DBG("SystemDSM received SIP Subscription Event\n"); map<string, string> params; params["status"] = sub_ev->getStatusText(); params["code"] = int2str(sub_ev->code); params["reason"] = sub_ev->reason; params["expires"] = int2str(sub_ev->expires); params["has_body"] = sub_ev->notify_body.get()?"true":"false"; if (sub_ev->notify_body.get()) { avar[DSM_AVAR_SIPSUBSCRIPTION_BODY] = AmArg(sub_ev->notify_body.get()); } engine.runEvent(&dummy_session, this, DSMCondition::SIPSubscription, ¶ms); avar.erase(DSM_AVAR_SIPSUBSCRIPTION_BODY); } } if (event->event_id == E_SYSTEM) { AmSystemEvent* sys_ev = dynamic_cast<AmSystemEvent*>(event); if(sys_ev){ DBG("SystemDSM received system Event\n"); map<string, string> params; params["type"] = AmSystemEvent::getDescription(sys_ev->sys_event); engine.runEvent(&dummy_session, this, DSMCondition::System, ¶ms); // stop_requested.set(true); return; } } }