From 82e2017ce707d1ff5b4e68cc1d32bad931d014a6 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Wed, 11 Mar 2009 02:13:02 +0000 Subject: [PATCH] add DI API: postDSMEvent Example (with direct_export=dsm;monitoring): s.postDSMEvent(s.list()[0], [["action", "kick"]]) transition "DI xmlrpc kick event" room - eventTest(#action==kick) / stop(true) -> end; git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1308 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/dsm/DSM.cpp | 33 +++++++++++++++++++++++++++++---- apps/dsm/DSM.h | 11 ++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/apps/dsm/DSM.cpp b/apps/dsm/DSM.cpp index bdd9a78c..b14f296a 100644 --- a/apps/dsm/DSM.cpp +++ b/apps/dsm/DSM.cpp @@ -30,17 +30,18 @@ #include "AmPlugIn.h" #include "log.h" #include "AmConfigReader.h" +#include "AmSessionContainer.h" + #include "DSMDialog.h" #include "DSMChartReader.h" #include #include - #define MOD_NAME "dsm" -// session creator export -extern "C" void* session_factory_create() { +extern "C" void* plugin_class_create() +{ return DSMFactory::instance(); } @@ -59,7 +60,7 @@ map DSMFactory::config; bool DSMFactory::RunInviteEvent; DSMFactory::DSMFactory(const string& _app_name) - : AmSessionFactory(_app_name), + : AmSessionFactory(_app_name),AmDynInvokeFactory(_app_name), loaded(false) { } @@ -291,3 +292,27 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req, return s; } + +void DSMFactory::invoke(const string& method, const AmArg& args, + AmArg& ret) +{ + if(method == "postDSMEvent"){ + assertArgCStr(args.get(0)) + + DSMEvent* ev = new DSMEvent(); + for (size_t i=0;iparams[args[1][i][0].asCStr()] = args[1][i][1].asCStr(); + + if (AmSessionContainer::instance()->postEvent(args.get(0).asCStr(), ev)) { + ret.push(AmArg(200)); + ret.push(AmArg("OK")); + } else { + ret.push(AmArg(404)); + ret.push(AmArg("Session not found")); + } + + } else if(method == "_list"){ + ret.push(AmArg("postDSMEvent")); + } else + throw AmDynInvoke::NotImplemented(method); +} diff --git a/apps/dsm/DSM.h b/apps/dsm/DSM.h index f4145b2c..03a304ca 100644 --- a/apps/dsm/DSM.h +++ b/apps/dsm/DSM.h @@ -46,7 +46,9 @@ class DSMDialog; class DSMModule; /** \brief Factory for announcement sessions */ class DSMFactory - : public AmSessionFactory + : public AmSessionFactory, + public AmDynInvoke, + public AmDynInvokeFactory { AmPromptCollection prompts; DSMStateDiagramCollection diags; @@ -73,6 +75,13 @@ public: AmSession* onInvite(const AmSipRequest& req); AmSession* onInvite(const AmSipRequest& req, AmArg& session_params); + // DI + // DI factory + AmDynInvoke* getInstance() { return instance(); } + // DI API + void invoke(const string& method, + const AmArg& args, AmArg& ret); + }; #endif