summaryrefslogtreecommitdiff
path: root/orkbasecxx
diff options
context:
space:
mode:
authorHenri Herscher <henri@oreka.org>2007-06-06 13:43:28 +0000
committerHenri Herscher <henri@oreka.org>2007-06-06 13:43:28 +0000
commit9845d2476c05c14226ab2456dcc4636677f34897 (patch)
tree2e930cd3dc3762d2ed353a5f0e61c6b491520bcd /orkbasecxx
parent2501598d00dac0b63904efc01cbc95ac15e2e19b (diff)
Enhanced configurable tape file naming and added configurable tape path naming support.
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@443 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx')
-rw-r--r--orkbasecxx/AudioCapture.cpp12
-rw-r--r--orkbasecxx/AudioCapture.h4
-rw-r--r--orkbasecxx/AudioTape.cpp469
-rw-r--r--orkbasecxx/AudioTape.h54
-rw-r--r--orkbasecxx/Config.cpp3
-rw-r--r--orkbasecxx/Config.h4
6 files changed, 533 insertions, 13 deletions
diff --git a/orkbasecxx/AudioCapture.cpp b/orkbasecxx/AudioCapture.cpp
index 20aa0d7..706c657 100644
--- a/orkbasecxx/AudioCapture.cpp
+++ b/orkbasecxx/AudioCapture.cpp
@@ -186,6 +186,18 @@ CaptureEvent::CaptureEvent()
m_type = EtUnknown;
}
+CStdString CaptureEvent::DirectionToShortString(int direction)
+{
+ switch(direction)
+ {
+ case DirIn:
+ return DIR_IN_SHORT;
+ case DirOut:
+ return DIR_OUT_SHORT;
+ }
+ return DIR_UNKN_SHORT;
+}
+
CStdString CaptureEvent::DirectionToString(int direction)
{
switch(direction)
diff --git a/orkbasecxx/AudioCapture.h b/orkbasecxx/AudioCapture.h
index cb4cfc0..1d6ae78 100644
--- a/orkbasecxx/AudioCapture.h
+++ b/orkbasecxx/AudioCapture.h
@@ -107,12 +107,16 @@ public:
#define DIR_IN "in"
#define DIR_OUT "out"
#define DIR_UNKN "unkn"
+#define DIR_IN_SHORT "I"
+#define DIR_OUT_SHORT "O"
+#define DIR_UNKN_SHORT "U"
typedef enum {
DirIn = 0,
DirOut = 1,
DirUnkn = 2
} DirectionEnum;
static CStdString DirectionToString(int);
+ static CStdString DirectionToShortString(int direction);
static int DirectionToEnum(CStdString& dir);
#define ET_UNKNOWN "unknown"
diff --git a/orkbasecxx/AudioTape.cpp b/orkbasecxx/AudioTape.cpp
index 593f7c3..c54e8ca 100644
--- a/orkbasecxx/AudioTape.cpp
+++ b/orkbasecxx/AudioTape.cpp
@@ -346,11 +346,191 @@ void AudioTape::PopulateTapeMessage(TapeMsg* msg, CaptureEvent::EventTypeEnum ev
void AudioTape::GenerateCaptureFilePathAndIdentifier()
{
struct tm date = {0};
+
ACE_OS::localtime_r(&m_beginDate, &date);
int month = date.tm_mon + 1; // january=0, decembre=11
int year = date.tm_year + 1900;
+
m_filePath.Format("%.4d/%.2d/%.2d/%.2d/", year, month, date.tm_mday, date.tm_hour);
+
m_fileIdentifier.Format("%.4d%.2d%.2d_%.2d%.2d%.2d_%s", year, month, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec, m_portId);
+
+ m_year.Format("%.4d", year);
+ m_day.Format("%.2d", date.tm_mday);
+ m_month.Format("%.2d", month);
+ m_hour.Format("%.2d", date.tm_hour);
+ m_min.Format("%.2d", date.tm_min);
+ m_sec.Format("%.2d", date.tm_sec);
+}
+
+void AudioTape::GenerateFinalFilePath()
+{
+ if(CONFIG.m_tapePathNaming.size() > 0)
+ {
+ CStdString pathIdentifier;
+ std::list<CStdString>::iterator it;
+
+ for(it = CONFIG.m_tapePathNaming.begin(); it != CONFIG.m_tapePathNaming.end(); it++)
+ {
+ CStdString element = *it;
+ int tapeAttributeEnum = TapeAttributes::TapeAttributeToEnum(element);
+
+ switch(tapeAttributeEnum) {
+ case TapeAttributes::TaNativeCallId:
+ {
+ if(m_nativeCallId.size() > 0)
+ {
+ pathIdentifier += m_nativeCallId;
+ }
+ else
+ {
+ pathIdentifier += "nonativecallid";
+ }
+ break;
+ }
+ case TapeAttributes::TaTrackingId:
+ {
+ if(m_trackingId.size() > 0)
+ {
+ pathIdentifier += m_trackingId;
+ }
+ else
+ {
+ pathIdentifier += "notrackingid";
+ }
+ break;
+ }
+ case TapeAttributes::TaDirection:
+ {
+ pathIdentifier += CaptureEvent::DirectionToString(m_direction);
+ break;
+ }
+ case TapeAttributes::TaShortDirection:
+ {
+ pathIdentifier += CaptureEvent::DirectionToShortString(m_direction);
+ break;
+ }
+ case TapeAttributes::TaRemoteParty:
+ {
+ if(m_remoteParty.size() > 0)
+ {
+ pathIdentifier += m_remoteParty;
+ }
+ else
+ {
+ pathIdentifier += "noremoteparty";
+ }
+ break;
+ }
+ case TapeAttributes::TaLocalParty:
+ {
+ if(m_localParty.size() > 0)
+ {
+ pathIdentifier += m_localParty;
+ }
+ else
+ {
+ pathIdentifier += "nolocalparty";
+ }
+ break;
+ }
+ case TapeAttributes::TaLocalEntryPoint:
+ {
+ if(m_localEntryPoint.size() > 0)
+ {
+ pathIdentifier += m_localEntryPoint;
+ }
+ else
+ {
+ pathIdentifier += "nolocalentrypoint";
+ }
+ break;
+ }
+ case TapeAttributes::TaLocalIp:
+ {
+ if(m_localIp.size() > 0)
+ {
+ pathIdentifier += m_localIp;
+ }
+ else
+ {
+ pathIdentifier += "nolocalip";
+ }
+ break;
+ }
+ case TapeAttributes::TaRemoteIp:
+ {
+ if(m_remoteIp.size() > 0)
+ {
+ pathIdentifier += m_remoteIp;
+ }
+ else
+ {
+ pathIdentifier += "noremoteip";
+ }
+ break;
+ }
+ case TapeAttributes::TaHostname:
+ {
+ char host_name[255];
+
+ memset(host_name, 0, sizeof(host_name));
+ ACE_OS::hostname(host_name, sizeof(host_name));
+
+ if(strlen(host_name))
+ {
+ pathIdentifier += host_name;
+ }
+ else
+ {
+ pathIdentifier += "nohostname";
+ }
+
+ break;
+ }
+ case TapeAttributes::TaYear:
+ {
+ pathIdentifier += m_year;
+ break;
+ }
+ case TapeAttributes::TaDay:
+ {
+ pathIdentifier += m_day;
+ break;
+ }
+ case TapeAttributes::TaMonth:
+ {
+ pathIdentifier += m_month;
+ break;
+ }
+ case TapeAttributes::TaHour:
+ {
+ pathIdentifier += m_hour;
+ break;
+ }
+ case TapeAttributes::TaMin:
+ {
+ pathIdentifier += m_min;
+ break;
+ }
+ case TapeAttributes::TaSec:
+ {
+ pathIdentifier += m_sec;
+ break;
+ }
+ case TapeAttributes::TaUnknown:
+ {
+ pathIdentifier += element;
+ break;
+ }
+ }
+ }
+
+ if(pathIdentifier.size() > 0)
+ {
+ m_filePath = pathIdentifier;
+ }
+ }
}
void AudioTape::GenerateFinalFilePathAndIdentifier()
@@ -360,42 +540,184 @@ void AudioTape::GenerateFinalFilePathAndIdentifier()
// The config file specifies a naming scheme for the recordings, build the final file identifier
CStdString fileIdentifier;
std::list<CStdString>::iterator it;
+
for(it = CONFIG.m_tapeFileNaming.begin(); it != CONFIG.m_tapeFileNaming.end(); it++)
{
CStdString element = *it;
- if(element.CompareNoCase("nativecallid") == 0)
+ int tapeAttributeEnum = TapeAttributes::TapeAttributeToEnum(element);
+
+ switch(tapeAttributeEnum) {
+ case TapeAttributes::TaNativeCallId:
{
if(m_nativeCallId.size() > 0)
+ {
+ fileIdentifier += m_nativeCallId;
+ }
+ else
+ {
+ fileIdentifier += "nonativecallid";
+ }
+ break;
+ }
+ case TapeAttributes::TaTrackingId:
+ {
+ if(m_trackingId.size() > 0)
{
- fileIdentifier += m_nativeCallId;
+ fileIdentifier += m_trackingId;
}
else
{
- fileIdentifier += "nonativecallid";
+ fileIdentifier += "notrackingid";
}
+ break;
}
- else if (element.CompareNoCase("trackingid") == 0)
+ case TapeAttributes::TaDirection:
+ {
+ fileIdentifier += CaptureEvent::DirectionToString(m_direction);
+ break;
+ }
+ case TapeAttributes::TaShortDirection:
{
- if(m_trackingId.size() > 0)
+ fileIdentifier += CaptureEvent::DirectionToShortString(m_direction);
+ break;
+ }
+ case TapeAttributes::TaRemoteParty:
+ {
+ if(m_remoteParty.size() > 0)
{
- fileIdentifier += m_trackingId;
+ fileIdentifier += m_remoteParty;
}
else
{
- fileIdentifier += "notrackingid";
+ fileIdentifier += "noremoteparty";
}
+ break;
}
- else
+ case TapeAttributes::TaLocalParty:
{
- fileIdentifier += element;
+ if(m_localParty.size() > 0)
+ {
+ fileIdentifier += m_localParty;
+ }
+ else
+ {
+ fileIdentifier += "nolocalparty";
+ }
+ break;
+ }
+ case TapeAttributes::TaLocalEntryPoint:
+ {
+ if(m_localEntryPoint.size() > 0)
+ {
+ fileIdentifier += m_localEntryPoint;
+ }
+ else
+ {
+ fileIdentifier += "nolocalentrypoint";
+ }
+ break;
+ }
+ case TapeAttributes::TaLocalIp:
+ {
+ if(m_localIp.size() > 0)
+ {
+ fileIdentifier += m_localIp;
+ }
+ else
+ {
+ fileIdentifier += "nolocalip";
+ }
+ break;
+ }
+ case TapeAttributes::TaRemoteIp:
+ {
+ if(m_remoteIp.size() > 0)
+ {
+ fileIdentifier += m_remoteIp;
+ }
+ else
+ {
+ fileIdentifier += "noremoteip";
+ }
+ break;
+ }
+ case TapeAttributes::TaHostname:
+ {
+ char host_name[255];
+
+ memset(host_name, 0, sizeof(host_name));
+ ACE_OS::hostname(host_name, sizeof(host_name));
+
+ if(strlen(host_name))
+ {
+ fileIdentifier += host_name;
+ }
+ else
+ {
+ fileIdentifier += "nohostname";
+ }
+
+ break;
+ }
+ case TapeAttributes::TaYear:
+ {
+ fileIdentifier += m_year;
+ break;
+ }
+ case TapeAttributes::TaDay:
+ {
+ fileIdentifier += m_day;
+ break;
+ }
+ case TapeAttributes::TaMonth:
+ {
+ fileIdentifier += m_month;
+ break;
+ }
+ case TapeAttributes::TaHour:
+ {
+ fileIdentifier += m_hour;
+ break;
+ }
+ case TapeAttributes::TaMin:
+ {
+ fileIdentifier += m_min;
+ break;
+ }
+ case TapeAttributes::TaSec:
+ {
+ fileIdentifier += m_sec;
+ break;
+ }
+ case TapeAttributes::TaUnknown:
+ {
+ std::map<CStdString, CStdString>::iterator pair;
+ CStdString correctKey, mTagsValue;
+
+ // Remove the []
+ correctKey = element.substr(1, element.size()-2);
+ pair = m_tags.find(correctKey);
+
+ if(pair != m_tags.end()) {
+ mTagsValue = pair->second;
+ fileIdentifier += mTagsValue;
+ } else {
+ fileIdentifier += element;
+ }
+
+ break;
+ }
}
}
+
if(fileIdentifier.size() > 0)
{
m_fileIdentifier = fileIdentifier;
}
- m_filePath = "";
- CStdString path = CONFIG.m_audioOutputPath + "/";
+
+ GenerateFinalFilePath();
+
+ CStdString path = CONFIG.m_audioOutputPath + "/" + m_filePath + "/";
PreventFileIdentifierCollision(path, m_fileIdentifier , m_fileExtension);
}
}
@@ -466,4 +788,129 @@ bool AudioTape::IsReadyForBatchProcessing()
return false;
}
+//=================================
+
+CStdString TapeAttributes::TapeAttributeToString(int ta)
+{
+ switch(ta) {
+ case TaNativeCallId:
+ return TA_NATIVECALLID;
+ case TaTrackingId:
+ return TA_TRACKINGID;
+ case TaDirection:
+ return TA_DIRECTION;
+ case TaShortDirection:
+ return TA_SHORTDIRECTION;
+ case TaRemoteParty:
+ return TA_REMOTEPARTY;
+ case TaLocalParty:
+ return TA_LOCALPARTY;
+ case TaLocalEntryPoint:
+ return TA_LOCALENTRYPOINT;
+ case TaLocalIp:
+ return TA_LOCALIP;
+ case TaRemoteIp:
+ return TA_REMOTEIP;
+ case TaHostname:
+ return TA_HOSTNAME;
+ case TaYear:
+ return TA_YEAR;
+ case TaDay:
+ return TA_DAY;
+ case TaMonth:
+ return TA_MONTH;
+ case TaHour:
+ return TA_HOUR;
+ case TaMin:
+ return TA_MIN;
+ case TaSec:
+ return TA_SEC;
+ }
+
+ return "[UnknownAttribute]";
+}
+
+int TapeAttributes::TapeAttributeToEnum(CStdString& ta)
+{
+ if(ta.CompareNoCase(TA_NATIVECALLID) == 0)
+ {
+ return TaNativeCallId;
+ }
+ if(ta.CompareNoCase(TA_TRACKINGID) == 0)
+ {
+ return TaTrackingId;
+ }
+
+ if(ta.CompareNoCase(TA_DIRECTION) == 0)
+ {
+ return TaDirection;
+ }
+
+ if(ta.CompareNoCase(TA_SHORTDIRECTION) == 0)
+ {
+ return TaShortDirection;
+ }
+
+ if(ta.CompareNoCase(TA_REMOTEPARTY) == 0)
+ {
+ return TaRemoteParty;
+ }
+
+ if(ta.CompareNoCase(TA_LOCALPARTY) == 0)
+ {
+ return TaLocalParty;
+ }
+
+ if(ta.CompareNoCase(TA_LOCALENTRYPOINT) == 0)
+ {
+ return TaLocalEntryPoint;
+ }
+
+ if(ta.CompareNoCase(TA_LOCALIP) == 0)
+ {
+ return TaLocalIp;
+ }
+
+ if(ta.CompareNoCase(TA_REMOTEIP) == 0)
+ {
+ return TaRemoteIp;
+ }
+
+ if(ta.CompareNoCase(TA_HOSTNAME) == 0)
+ {
+ return TaHostname;
+ }
+
+ if(ta.CompareNoCase(TA_YEAR) == 0)
+ {
+ return TaYear;
+ }
+
+ if(ta.CompareNoCase(TA_DAY) == 0)
+ {
+ return TaDay;
+ }
+
+ if(ta.CompareNoCase(TA_MONTH) == 0)
+ {
+ return TaMonth;
+ }
+
+ if(ta.CompareNoCase(TA_HOUR) == 0)
+ {
+ return TaHour;
+ }
+
+ if(ta.CompareNoCase(TA_MIN) == 0)
+ {
+ return TaMin;
+ }
+
+ if(ta.CompareNoCase(TA_SEC) == 0)
+ {
+ return TaSec;
+ }
+
+ return TaUnknown;
+}
diff --git a/orkbasecxx/AudioTape.h b/orkbasecxx/AudioTape.h
index 91ffccb..4cc6e3a 100644
--- a/orkbasecxx/AudioTape.h
+++ b/orkbasecxx/AudioTape.h
@@ -98,6 +98,7 @@ public:
private:
void GenerateCaptureFilePathAndIdentifier();
void GenerateFinalFilePathAndIdentifier();
+ void GenerateFinalFilePath();
void PreventFileIdentifierCollision(CStdString& path, CStdString& identifier, CStdString& extension);
void PopulateTapeMessage(TapeMsg* msg, CaptureEvent::EventTypeEnum eventType);
@@ -105,6 +106,13 @@ private:
CStdString m_fileIdentifier;
CStdString m_fileExtension; //Corresponds to the extension the tape will have after compression
+ CStdString m_year;
+ CStdString m_day;
+ CStdString m_month;
+ CStdString m_hour;
+ CStdString m_min;
+ CStdString m_sec;
+
std::queue<AudioChunkRef> m_chunkQueue;
std::queue<CaptureEventRef> m_eventQueue;
@@ -122,5 +130,51 @@ private:
typedef boost::shared_ptr<AudioTape> AudioTapeRef;
+//==========================================================
+
+class TapeAttributes
+{
+public:
+#define TA_NATIVECALLID "[nativecallid]"
+#define TA_TRACKINGID "[trackingid]"
+#define TA_DIRECTION "[direction]"
+#define TA_SHORTDIRECTION "[shortdirection]"
+#define TA_REMOTEPARTY "[remoteparty]"
+#define TA_LOCALPARTY "[localparty]"
+#define TA_LOCALENTRYPOINT "[localentrypoint]"
+#define TA_LOCALIP "[localip]"
+#define TA_REMOTEIP "[remoteip]"
+#define TA_HOSTNAME "[hostname]"
+#define TA_YEAR "[year]"
+#define TA_DAY "[day]"
+#define TA_MONTH "[month]"
+#define TA_HOUR "[hour]"
+#define TA_MIN "[min]"
+#define TA_SEC "[sec]"
+
+ typedef enum {
+ TaUnknown = 0,
+ TaNativeCallId = 1,
+ TaTrackingId = 2,
+ TaDirection = 3,
+ TaShortDirection = 4,
+ TaRemoteParty = 5,
+ TaLocalParty = 6,
+ TaLocalEntryPoint = 7,
+ TaLocalIp = 8,
+ TaRemoteIp = 9,
+ TaHostname = 10,
+ TaYear = 11,
+ TaDay = 12,
+ TaMonth = 13,
+ TaHour = 14,
+ TaMin = 15,
+ TaSec = 16
+ } TapeAttributeEnum;
+
+ static int TapeAttributeToEnum(CStdString& ta);
+ static CStdString TapeAttributeToString(int ta);
+};
+
#endif
diff --git a/orkbasecxx/Config.cpp b/orkbasecxx/Config.cpp
index d2400bb..e93a762 100644
--- a/orkbasecxx/Config.cpp
+++ b/orkbasecxx/Config.cpp
@@ -21,7 +21,7 @@
Config::Config()
{
m_log = log4cxx::Logger::getLogger("config");
-
+ m_serviceStartedTime = time(NULL);
m_logMessages = LOG_MESSAGES_DEFAULT;
m_logRms = LOG_RMS_DEFAULT;
m_enableReporting = ENABLE_REPORTING_DEFAULT;
@@ -94,6 +94,7 @@ void Config::Define(Serializer* s)
s->IntValue(CAPTURE_FILE_BATCH_SIZE_KBYTE_PARAM, m_captureFileBatchSizeKByte);
s->BoolValue(DEBUG_PARAM, m_debug);
s->CsvValue(TAPE_FILE_NAMING_PARAM, m_tapeFileNaming);
+ s->CsvValue(TAPE_PATH_NAMING_PARAM, m_tapePathNaming);
s->CsvValue(REMOTE_PROCESSING_INPUT_PATH_PARAM, m_remoteProcessingInputPath);
s->StringValue(REMOTE_PROCESSING_OUTPUT_PATH_PARAM, m_remoteProcessingOutputPath);
s->StringValue(REMOTE_PROCESSING_HOSTNAME_PARAM, m_remoteProcessingHostname);
diff --git a/orkbasecxx/Config.h b/orkbasecxx/Config.h
index c728860..50271c9 100644
--- a/orkbasecxx/Config.h
+++ b/orkbasecxx/Config.h
@@ -77,6 +77,7 @@
#define DEBUG_PARAM "Debug"
#define DEBUG_DEFAULT false
#define TAPE_FILE_NAMING_PARAM "TapeFileNaming"
+#define TAPE_PATH_NAMING_PARAM "TapePathNaming"
#define REMOTE_PROCESSING_INPUT_PATH_PARAM "RemoteProcessingInputPath"
#define REMOTE_PROCESSING_OUTPUT_PATH_PARAM "RemoteProcessingOutputPath"
#define REMOTE_PROCESSING_HOSTNAME_PARAM "RemoteProcessingHostname"
@@ -96,7 +97,7 @@ public:
CStdString GetClassName();
ObjectRef NewInstance();
inline ObjectRef Process() {return ObjectRef();};
-
+ time_t m_serviceStartedTime;
bool m_logMessages;
bool m_logRms;
bool m_enableReporting;
@@ -129,6 +130,7 @@ public:
int m_captureFileBatchSizeKByte;
bool m_debug;
std::list<CStdString> m_tapeFileNaming;
+ std::list<CStdString> m_tapePathNaming;
std::list<CStdString> m_remoteProcessingInputPath;
CStdString m_remoteProcessingOutputPath;
CStdString m_remoteProcessingHostname;