diff options
author | Gerald Begumisa <ben_g@users.sourceforge.net> | 2007-12-20 02:53:14 +0000 |
---|---|---|
committer | Gerald Begumisa <ben_g@users.sourceforge.net> | 2007-12-20 02:53:14 +0000 |
commit | 0e9d7cb80716bd22e0e5234af0a7d3ba4d5a3091 (patch) | |
tree | c37832192a74edd2c0805cfd6b6e33d054ef1e23 /orkbasecxx | |
parent | b4f73de93002e79ccdf6ee62cd91a533c0f7ba1f (diff) |
Added a new feature that allows orkaudio to filter recordings by the remote or local party. If the configuration parameter <PartyFilter> is filled with a CSV list of numbers or ranges of numbers such as <PartyFilter>300,450-490,4000-6000</PartyFilter>, orkaudio will only produce recordings for cases where the remote or local parties match a specified number or fall within the specified number range (for the case where a range has been specified).
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@516 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx')
-rw-r--r-- | orkbasecxx/AudioTape.cpp | 70 | ||||
-rw-r--r-- | orkbasecxx/AudioTape.h | 2 | ||||
-rw-r--r-- | orkbasecxx/Config.cpp | 2 | ||||
-rw-r--r-- | orkbasecxx/Config.h | 3 | ||||
-rw-r--r-- | orkbasecxx/Makefile.am | 3 | ||||
-rw-r--r-- | orkbasecxx/PartyFilter.cpp | 101 | ||||
-rw-r--r-- | orkbasecxx/PartyFilter.h | 19 |
7 files changed, 198 insertions, 2 deletions
diff --git a/orkbasecxx/AudioTape.cpp b/orkbasecxx/AudioTape.cpp index e68df00..41abe5a 100644 --- a/orkbasecxx/AudioTape.cpp +++ b/orkbasecxx/AudioTape.cpp @@ -25,7 +25,7 @@ #include "messages/TapeMsg.h" #include "AudioTape.h" #include "ConfigManager.h" - +#include "PartyFilter.h" AudioTapeDescription::AudioTapeDescription() @@ -83,12 +83,14 @@ AudioTape::AudioTape(CStdString &portId) m_trackingId = portId; // to make sure this has a value before we get the capture tracking Id. m_bytesWritten = 0; m_lastLogWarning = 0; + m_passedPartyFilterTest = false; GenerateCaptureFilePathAndIdentifier(); } AudioTape::AudioTape(CStdString &portId, CStdString& file) { + m_passedPartyFilterTest = false; m_portId = portId; // Extract Path and Identifier @@ -119,6 +121,44 @@ void AudioTape::Write() { // Get the latest audio chunks and write them to disk bool done = false; + CStdString logMsg; + + if(m_state == StateCreated && PartyFilterActive()) + { + if(!m_passedPartyFilterTest) + { + logMsg.Format("[%s] rejected by PartyFilter", m_trackingId); + LOG4CXX_INFO(LOG.portLog, logMsg); + } + } + + if(!m_passedPartyFilterTest && PartyFilterActive()) + { + if(m_state == StateCreated) + { + m_state = StateActive; + } + + // Discard chunks + while(!done) + { + AudioChunkRef chunkRef; + { + if(m_chunkQueue.size() > 0) + { + chunkRef = m_chunkQueue.front(); + m_chunkQueue.pop(); + } + else + { + done = true; + } + } + } + + return; + } + while(!done && m_state != StateStopped && m_state != StateError) { // Get the oldest audio chunk @@ -279,9 +319,27 @@ void AudioTape::AddCaptureEvent(CaptureEventRef eventRef, bool send) break; case CaptureEvent::EtRemoteParty: m_remoteParty = eventRef->m_value; + if(!m_passedPartyFilterTest && PartyFilterActive()) + { + m_passedPartyFilterTest = PartyFilterMatches(m_remoteParty); + if(m_passedPartyFilterTest) + { + logMsg.Format("[%s] remote party passed PartyFilter test", m_trackingId); + LOG4CXX_INFO(LOG.portLog, logMsg); + } + } break; case CaptureEvent::EtLocalParty: m_localParty = eventRef->m_value; + if(!m_passedPartyFilterTest && PartyFilterActive()) + { + m_passedPartyFilterTest = PartyFilterMatches(m_localParty); + if(m_passedPartyFilterTest) + { + logMsg.Format("[%s] local party passed PartyFilter test", m_trackingId); + LOG4CXX_INFO(LOG.portLog, logMsg); + } + } break; case CaptureEvent::EtLocalEntryPoint: m_localEntryPoint = eventRef->m_value; @@ -323,6 +381,11 @@ void AudioTape::AddCaptureEvent(CaptureEventRef eventRef, bool send) void AudioTape::GetMessage(MessageRef& msgRef) { + if(!m_passedPartyFilterTest && PartyFilterActive()) + { + return; + } + CaptureEventRef captureEventRef; { MutexSentinel sentinel(m_mutex); @@ -358,6 +421,11 @@ void AudioTape::GetDetails(TapeMsg* msg) void AudioTape::PopulateTapeMessage(TapeMsg* msg, CaptureEvent::EventTypeEnum eventType) { + if(!m_passedPartyFilterTest && PartyFilterActive()) + { + return; + } + msg->m_recId = m_orkUid; msg->m_fileName = m_filePath + m_fileIdentifier + m_fileExtension; msg->m_stage = CaptureEvent::EventTypeToString(eventType); diff --git a/orkbasecxx/AudioTape.h b/orkbasecxx/AudioTape.h index 1464e5e..91a78c2 100644 --- a/orkbasecxx/AudioTape.h +++ b/orkbasecxx/AudioTape.h @@ -136,6 +136,8 @@ private: int m_bytesWritten; time_t m_lastLogWarning; + + bool m_passedPartyFilterTest; }; typedef boost::shared_ptr<AudioTape> AudioTapeRef; diff --git a/orkbasecxx/Config.cpp b/orkbasecxx/Config.cpp index 27adb30..d86ce3c 100644 --- a/orkbasecxx/Config.cpp +++ b/orkbasecxx/Config.cpp @@ -67,6 +67,7 @@ Config::Config() m_lookBackRecording = LOOKBACK_RECORDING_DEFAULT; m_allowAutomaticRecording = ALLOW_AUTOMATIC_RECORDING_DEFAULT; m_captureFileSizeLimitKb = CAPTURE_FILE_SIZE_LIMIT_KB_DEFAULT; + m_partyFilter.clear(); } void Config::Define(Serializer* s) @@ -138,6 +139,7 @@ void Config::Define(Serializer* s) s->BoolValue(LOOKBACK_RECORDING_PARAM, m_lookBackRecording); s->BoolValue(ALLOW_AUTOMATIC_RECORDING_PARAM, m_allowAutomaticRecording); // only valid in non-lookback mode s->IntValue(CAPTURE_FILE_SIZE_LIMIT_KB_PARAM, m_captureFileSizeLimitKb); + s->CsvValue(PARTY_FILTER_PARAM, m_partyFilter); } void Config::Validate() diff --git a/orkbasecxx/Config.h b/orkbasecxx/Config.h index fb98405..5630a71 100644 --- a/orkbasecxx/Config.h +++ b/orkbasecxx/Config.h @@ -102,6 +102,8 @@ #define ALLOW_AUTOMATIC_RECORDING_DEFAULT true #define CAPTURE_FILE_SIZE_LIMIT_KB_PARAM "CaptureFileSizeLimitKb" #define CAPTURE_FILE_SIZE_LIMIT_KB_DEFAULT 300000 +#define PARTY_FILTER_PARAM "PartyFilter" +#define PARTY_FILTER_DEFAULT "" class DLL_IMPORT_EXPORT_ORKBASE Config : public Object { @@ -160,6 +162,7 @@ public: bool m_lookBackRecording; bool m_allowAutomaticRecording; int m_captureFileSizeLimitKb; + std::list<CStdString> m_partyFilter; private: log4cxx::LoggerPtr m_log; diff --git a/orkbasecxx/Makefile.am b/orkbasecxx/Makefile.am index f9aadf5..3bcd0ad 100644 --- a/orkbasecxx/Makefile.am +++ b/orkbasecxx/Makefile.am @@ -14,7 +14,8 @@ liborkbase_la_SOURCES = Filter.cpp g711.c \ MemUtils.cpp BatchProcessing.cpp \ CapturePluginProxy.cpp CapturePort.cpp \ Daemon.cpp ImmediateProcessing.cpp \ - Reporting.cpp TapeFileNaming.cpp + Reporting.cpp TapeFileNaming.cpp \ + PartyFilter.cpp #INCLUDES = -I/projects/ext/xmlrpc++/xmlrpc++0.7/src SUBDIRS = messages serializers audiofile filters liborkbase_la_LIBADD = $(top_builddir)/serializers/libserializers.la \ diff --git a/orkbasecxx/PartyFilter.cpp b/orkbasecxx/PartyFilter.cpp new file mode 100644 index 0000000..57fa0d5 --- /dev/null +++ b/orkbasecxx/PartyFilter.cpp @@ -0,0 +1,101 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ +#pragma warning( disable: 4786 ) + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "ConfigManager.h" +#include "Utils.h" + +#ifdef WIN32 +# ifndef snprintf +# define snprintf _snprintf +# endif +#endif + +bool PartyFilterActive(void) +{ + if(!CONFIG.m_partyFilter.size()) + { + return false; + } + + return true; +} + +bool PartyFilterMatches(CStdString& party) +{ + char buf[1024]; + char *lval = NULL; + char *rval = NULL; + long leftval = 0; + long rightval = 0; + bool res = false; + long partyVal = 0; + + try { + partyVal = StringToInt(party); + } catch (CStdString& e) { + partyVal = 0; + } + + for(std::list<CStdString>::iterator it = CONFIG.m_partyFilter.begin(); it != CONFIG.m_partyFilter.end(); it++) + { + CStdString pattern = *it; + + memset(buf, 0, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s", pattern.c_str()); + leftval = 0; + rightval = 0; + + lval = buf; + if((rval = strchr(buf, '-'))) + { + *rval++ = '\0'; + } + else + { + rval = NULL; + } + + + if(lval && strlen(lval)) + { + leftval = strtol(lval, NULL, 10); + } + else + { + continue; + } + + if(rval && strlen(rval)) + { + rightval = strtol(rval, NULL, 10); + if(partyVal >= leftval && partyVal <= rightval) + { + res = true; + break; + } + } + else + { + if(strcmp(lval, party.c_str()) == 0) + { + res = true; + break; + } + } + } + + return res; +} diff --git a/orkbasecxx/PartyFilter.h b/orkbasecxx/PartyFilter.h new file mode 100644 index 0000000..11d2aaa --- /dev/null +++ b/orkbasecxx/PartyFilter.h @@ -0,0 +1,19 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ +#ifndef __PARTYFILTER_H__ +#define __PARTYFILTER_H__ 1 + +bool DLL_IMPORT_EXPORT_ORKBASE PartyFilterActive(void); +bool DLL_IMPORT_EXPORT_ORKBASE PartyFilterMatches(CStdString& party); + +#endif |