Module: sems Branch: master Commit: f4fb79bfad7b498f22101bdf54fa1110aefb0b5d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=f4fb79bfad7b498f22101bdf54fa1110aefb0b5d
Author: Raphael Coeffic <[email protected]> Committer: Raphael Coeffic <[email protected]> Date: Wed Mar 6 17:17:05 2013 +0100 sbc: added event log --- apps/sbc/SBCEventLog.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++ apps/sbc/SBCEventLog.h | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 0 deletions(-) diff --git a/apps/sbc/SBCEventLog.cpp b/apps/sbc/SBCEventLog.cpp new file mode 100644 index 0000000..49387ed --- /dev/null +++ b/apps/sbc/SBCEventLog.cpp @@ -0,0 +1,49 @@ +#include "SBCEventLog.h" +#include "AmAppTimer.h" + +#include "AmArg.h" +#include "ampi/MonitoringAPI.h" +#include "AmSessionContainer.h" // monitoring ptr + +struct MonitoringEventLogHandler + : public SBCEventLogHandler +{ + void logEvent(long int timestamp, const string& id, const AmArg& event) { + if(NULL != MONITORING_GLOBAL_INTERFACE) { + AmArg di_args,ret; + di_args.push(id); + di_args.push("ts"); + di_args.push(timestamp); + di_args.push("attrs"); + di_args.push(event); + + MONITORING_GLOBAL_INTERFACE-> + invoke("log", di_args, ret); + } + } +}; + +void _SBCEventLog::useMonitoringLog() +{ + if(NULL != MONITORING_GLOBAL_INTERFACE) { + setEventLogHandler(new MonitoringEventLogHandler()); + INFO("SBC event log will use the monitoring module\n"); + } + else { + ERROR("SBC event log cannot use the monitoring module" + " as it is not loaded\n"); + } +} + +void _SBCEventLog::setEventLogHandler(SBCEventLogHandler* lh) +{ + log_handler.reset(lh); +} + +void _SBCEventLog::logEvent(const string& id, const AmArg& event) +{ + if(log_handler.get()) { + log_handler->logEvent(AmAppTimer::instance()->unix_clock.get(), + id, event); + } +} diff --git a/apps/sbc/SBCEventLog.h b/apps/sbc/SBCEventLog.h new file mode 100644 index 0000000..f35d53e --- /dev/null +++ b/apps/sbc/SBCEventLog.h @@ -0,0 +1,36 @@ +#ifndef _SBCEventLog_h_ +#define _SBCEventLog_h_ + +#include "singleton.h" +#include "AmArg.h" + +#include <memory> +#include <string> +#include <map> +using std::auto_ptr; +using std::string; +using std::map; + +struct SBCEventLogHandler +{ + virtual void logEvent(long int timestamp, const string& id, + const AmArg& ev)=0; +}; + +class _SBCEventLog +{ + auto_ptr<SBCEventLogHandler> log_handler; + +protected: + _SBCEventLog() {} + ~_SBCEventLog() {} + +public: + void useMonitoringLog(); + void setEventLogHandler(SBCEventLogHandler* lh); + void logEvent(const string& id, const AmArg& event); +}; + +typedef singleton<_SBCEventLog> SBCEventLog; + +#endif _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
