diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..1ff0c42
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
diff --git a/.gitignore b/.gitignore
index c674098..9491a2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,363 @@
-# ---> Linux
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Oo]ut/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
-# temporary files which can be created if a process still has a handle open of a deleted file
-.fuse_hidden*
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
-# KDE directory preferences
-.directory
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
-# Linux trash folder which might appear on any partition or disk
-.Trash-*
+# RIA/Silverlight projects
+Generated_Code/
-# .nfs files are created when an open file is removed but is still being accessed
-.nfs*
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
\ No newline at end of file
diff --git a/CommonLib/.cproject b/CommonLib/.cproject
new file mode 100644
index 0000000..63a0516
--- /dev/null
+++ b/CommonLib/.cproject
@@ -0,0 +1,146 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CommonLib/.project b/CommonLib/.project
new file mode 100644
index 0000000..b243fd8
--- /dev/null
+++ b/CommonLib/.project
@@ -0,0 +1,27 @@
+
+
+ CommonLib
+
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.core.ccnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
diff --git a/CommonLib/.settings/language.settings.xml b/CommonLib/.settings/language.settings.xml
new file mode 100644
index 0000000..a955046
--- /dev/null
+++ b/CommonLib/.settings/language.settings.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CommonLib/.settings/org.eclipse.cdt.core.prefs b/CommonLib/.settings/org.eclipse.cdt.core.prefs
new file mode 100644
index 0000000..c8ec5df
--- /dev/null
+++ b/CommonLib/.settings/org.eclipse.cdt.core.prefs
@@ -0,0 +1,6 @@
+doxygen/doxygen_new_line_after_brief=true
+doxygen/doxygen_use_brief_tag=false
+doxygen/doxygen_use_javadoc_tags=true
+doxygen/doxygen_use_pre_tag=false
+doxygen/doxygen_use_structural_commands=false
+eclipse.preferences.version=1
diff --git a/CommonLib/.settings/org.eclipse.core.resources.prefs b/CommonLib/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/CommonLib/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/CommonLib/src/Common/AutomationMessages/AutomationMsgHandler.cpp b/CommonLib/src/Common/AutomationMessages/AutomationMsgHandler.cpp
new file mode 100644
index 0000000..c7db484
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/AutomationMsgHandler.cpp
@@ -0,0 +1,176 @@
+#include
+#include
+#include
+#include
+#include
+
+#include "AutomationMsgHandler.hpp"
+#include "Exception.hpp"
+#include "MessageHeader.hpp"
+#include "MessageIDs.hpp"
+#include "ErrorLog.hpp"
+#include "LinuxProc.hpp"
+#include "IniFile.hpp"
+#include "GenericRspMessage.hpp"
+#include "Condition.hpp"
+
+#include "TransferGutsVideosCmdMessage.hpp"
+#include "TransferAFileCmdMessage.hpp"
+#include "MoveGutsVideosToSubFolderCmdMessage.hpp"
+#include "WaitForLastTaskCompletionCmdMessage.hpp"
+//-----------------------------------------------------------------------------
+
+AutomationMsgHandler::AutomationMsgHandler()
+{
+}
+
+//-----------------------------------------------------------------------------
+
+AutomationMsgHandler::~AutomationMsgHandler(){}
+
+//-----------------------------------------------------------------------------
+
+AutomationMsgHandler& AutomationMsgHandler::Instance()
+{
+ static AutomationMsgHandler handler;
+ return handler;
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgHandler::handleMsg(const unsigned char* pData, const unsigned int& id)
+{
+ bool selfThrown = false;
+ try
+ {
+ MessageIDs::MsgIds msgId = (MessageIDs::MsgIds)id;
+
+ if (msgId != MessageIDs::WAIT_FOR_COMPLETION_CMD)
+ WaitForLastTaskCompletionCmdMessage::s_commandCompletionSuccess = true;
+
+ if (msgId == MessageIDs::TRANSFER_GUTS_VIDEOS_CMD)
+ {
+ handleTransferGutsVideosMessage(pData);
+ }
+ else if (msgId == MessageIDs::TRANSFER_A_FILE_CMD)
+ {
+ handleTransferAFileMessage(pData);
+ }
+ else if (msgId == MessageIDs::MOVE_GUTS_VIDEOS_TO_SUB_FOLDER_CMD)
+ {
+ handleMoveGutsVideosToSubFolderMessage(pData);
+ }
+ else if (msgId == MessageIDs::WAIT_FOR_COMPLETION_CMD)
+ {
+ handleWaitForLastTaskCompletionMessage(pData);
+ }
+ else
+ {
+ std::stringstream ss;
+ ss << "unknown message id: " << id;
+
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ss.str());
+ }
+ }
+ catch (Exception& e)
+ {
+ LinuxProc::Instance().getEvent(EventNames::COMMAND_EXECUTTION_IN_PROGRESS).reset();
+ LinuxProc::Instance().getEvent(EventNames::COMMAND_EXECUTION_COMPLETE).signal();
+
+ WaitForLastTaskCompletionCmdMessage::s_commandCompletionSuccess = false;
+
+ if (!selfThrown)
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgHandler::handleTransferGutsVideosMessage(const unsigned char* pData)
+{
+ try {
+ TransferGutsVideosCmdMessage cmd("");
+
+ cmd.parse(pData);
+
+ if (LinuxProc::Instance().getConfig().getBool("GENERAL", "VERBOSE_LOGGING"))
+ ErrorLog::Instance().log(cmd.toString(), false, ErrorLog::INFO);
+
+ cmd.executeMessage();
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgHandler::handleTransferAFileMessage(const unsigned char* pData)
+{
+ try {
+ TransferAFileCmdMessage cmd;
+
+ cmd.parse(pData);
+
+ if (LinuxProc::Instance().getConfig().getBool("GENERAL", "VERBOSE_LOGGING"))
+ ErrorLog::Instance().log(cmd.toString(), false, ErrorLog::INFO);
+
+ cmd.executeMessage();
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgHandler::handleMoveGutsVideosToSubFolderMessage(const unsigned char* pData)
+{
+ try {
+ MoveGutsVideosToSubFolderCmdMessage cmd;
+
+ cmd.parse(pData);
+
+ if (LinuxProc::Instance().getConfig().getBool("GENERAL", "VERBOSE_LOGGING"))
+ ErrorLog::Instance().log(cmd.toString(), false, ErrorLog::INFO);
+
+ cmd.executeMessage();
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgHandler::handleWaitForLastTaskCompletionMessage(const unsigned char* pData)
+{
+ try {
+ WaitForLastTaskCompletionCmdMessage cmd;
+
+ cmd.parse(pData);
+
+ if (LinuxProc::Instance().getConfig().getBool("GENERAL", "VERBOSE_LOGGING"))
+ ErrorLog::Instance().log(cmd.toString(), false, ErrorLog::INFO);
+
+ cmd.executeMessage();
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
diff --git a/CommonLib/src/Common/AutomationMessages/AutomationMsgHandler.hpp b/CommonLib/src/Common/AutomationMessages/AutomationMsgHandler.hpp
new file mode 100644
index 0000000..c33d3b2
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/AutomationMsgHandler.hpp
@@ -0,0 +1,98 @@
+#pragma once
+
+#include "MessageIDs.hpp"
+#include
+
+class AutomationMsgHandler
+{
+public:
+ //>---------------------------------------------------------------------------
+ // Function: instance
+ //
+ // Purpose: singleton
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ static AutomationMsgHandler& Instance();
+
+ //>---------------------------------------------------------------------------
+ // Function: ~Proc
+ //
+ // Purpose: Destroyer
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ ~AutomationMsgHandler();
+
+ //>---------------------------------------------------------------------------
+ // Function: parseMsg
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void handleMsg(const unsigned char* pData, const unsigned int& id);
+
+ private:
+ //>---------------------------------------------------------------------------
+ // Function: AutomationMsgHandler
+ //
+ // Purpose: Ctor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ AutomationMsgHandler();
+
+ //>---------------------------------------------------------------------------
+ // Function: HandleTransferGutsVideosMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void handleTransferGutsVideosMessage(const unsigned char* pData);
+
+ //>---------------------------------------------------------------------------
+ // Function: HandleTransferAFileMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void handleTransferAFileMessage(const unsigned char* pData);
+
+ //>---------------------------------------------------------------------------
+ // Function: HandleMoveGutsVideosToSubFolderMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void handleMoveGutsVideosToSubFolderMessage(const unsigned char* pData);
+
+ //>---------------------------------------------------------------------------
+ // Function: HandleWaitForLastTaskCompletionMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void handleWaitForLastTaskCompletionMessage(const unsigned char* pData);
+};
+
diff --git a/CommonLib/src/Common/AutomationMessages/AutomationMsgParser.cpp b/CommonLib/src/Common/AutomationMessages/AutomationMsgParser.cpp
new file mode 100644
index 0000000..e532da4
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/AutomationMsgParser.cpp
@@ -0,0 +1,164 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "AutomationMsgParser.hpp"
+#include "Exception.hpp"
+#include "MessageHeader.hpp"
+#include "MessageIDs.hpp"
+#include "StringUtil.hpp"
+
+//-----------------------------------------------------------------------------
+
+AutomationMsgParser::AutomationMsgParser()
+{
+ gatherCmdMessageIds();
+}
+
+//-----------------------------------------------------------------------------
+
+AutomationMsgParser::~AutomationMsgParser(){}
+
+//-----------------------------------------------------------------------------
+
+AutomationMsgParser& AutomationMsgParser::Instance()
+{
+ static AutomationMsgParser parser;
+ return parser;
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgParser::gatherCmdMessageIds()
+{
+ try {
+ msgIdsVec.push_back(MessageIDs::TRANSFER_A_FILE_CMD);
+ msgIdsVec.push_back(MessageIDs::TRANSFER_A_FOLDER_CMD);
+ msgIdsVec.push_back(MessageIDs::TRANSFER_GUTS_VIDEOS_CMD);
+ msgIdsVec.push_back(MessageIDs::MOVE_GUTS_VIDEOS_TO_SUB_FOLDER_CMD);
+ msgIdsVec.push_back(MessageIDs::WAIT_FOR_COMPLETION_CMD);
+
+ } catch (Exception& e) {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgParser::parseMsg(unsigned char* pData, unsigned int numBytes, unsigned int* pMsgId)
+{
+ bool selfThrown = false;
+ try
+ {
+ MessageHeader header;
+
+ if (numBytes < header.getHeaderLength())
+ {
+ std::stringstream ss;
+ ss << "Number of bytes received: " << numBytes << ". Expected minimum: " << header.getHeaderLength();
+
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ss.str());
+ }
+
+ // check to see if we recognize the header
+ unsigned int msgId = 0;
+ unsigned int msgLen = 0;
+
+ memcpy(&msgId, &pData[0], 4);
+ memcpy(&msgLen, &pData[4], 4);
+
+ if (std::find(msgIdsVec.begin(), msgIdsVec.end(), msgId) == msgIdsVec.end())
+ {
+ std::stringstream ss;
+ ss << "unexpected msg id: " << msgId;
+
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ss.str());
+ }
+
+ if ( msgLen != numBytes)
+ {
+ std::stringstream ss;
+ ss << "Number of bytes received: " << numBytes << ". Expected only: " << msgLen;
+
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ss.str());
+ }
+
+ if (numBytes > header.getHeaderLength())
+ verifyDataFormat(pData, numBytes);
+
+ *pMsgId = msgId;
+ }
+ catch (Exception& e)
+ {
+ if (!selfThrown)
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void AutomationMsgParser::verifyDataFormat(unsigned char* pData, unsigned int numBytes)
+{
+ MessageHeader header;
+ bool selfThrown = false;
+ unsigned char* pTempDataStart = pData + header.getHeaderLength();
+ unsigned char* pTempDataEnd = pData + numBytes - 1;
+
+ // data format is
+ // [data header - 4 bytes][data - variable size]
+ // [data header][data][data header][data][data header][data][data header][data]
+ const unsigned int DATA_HEADER_LENGTH = 4;
+
+ try {
+ std::stringstream ssError;
+
+ ssError << "Data structure is incorrect. Data: " << Util::Strings::ByteArrayToHexString(pData+header.getHeaderLength(), numBytes - header.getHeaderLength());
+
+ // want to make sure data size is at least 5 bytes
+ if (pTempDataStart+DATA_HEADER_LENGTH > pTempDataEnd)
+ {
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ssError.str());
+ }
+
+ while (pTempDataStart < pTempDataEnd)
+ {
+ unsigned int dataSize = *(reinterpret_cast(pTempDataStart));
+
+ if (dataSize == 0)
+ {
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ssError.str());
+
+ }
+
+ pTempDataStart += DATA_HEADER_LENGTH + dataSize;
+
+ if (pTempDataStart-1 > pTempDataEnd)
+ {
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ssError.str());
+ }
+ else if (pTempDataStart-1 == pTempDataEnd)
+ break;
+ }
+ }
+ catch (Exception& e)
+ {
+ if (!selfThrown)
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
diff --git a/CommonLib/src/Common/AutomationMessages/AutomationMsgParser.hpp b/CommonLib/src/Common/AutomationMessages/AutomationMsgParser.hpp
new file mode 100644
index 0000000..a7e5ae3
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/AutomationMsgParser.hpp
@@ -0,0 +1,78 @@
+#pragma once
+
+#include "MessageIDs.hpp"
+#include
+
+class AutomationMsgParser
+{
+public:
+ //>---------------------------------------------------------------------------
+ // Function: instance
+ //
+ // Purpose: singleton
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ static AutomationMsgParser& Instance();
+
+ //>---------------------------------------------------------------------------
+ // Function: ~Proc
+ //
+ // Purpose: Destroyer
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ ~AutomationMsgParser();
+
+ //>---------------------------------------------------------------------------
+ // Function: parseMsg
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void parseMsg(unsigned char* pData, unsigned int numBytes,unsigned int* pMsgId);
+
+ private:
+ //>---------------------------------------------------------------------------
+ // Function: AutomationMsgParser
+ //
+ // Purpose: Ctor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ AutomationMsgParser();
+
+ //>---------------------------------------------------------------------------
+ // Function: gatherCmdMessageIds
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void gatherCmdMessageIds();
+
+ //>---------------------------------------------------------------------------
+ // Function: verifyDataFormat
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ void verifyDataFormat(unsigned char* pData, unsigned int numBytes);
+
+ std::vector msgIdsVec;
+};
+
diff --git a/CommonLib/src/Common/AutomationMessages/GenericRspMessage.cpp b/CommonLib/src/Common/AutomationMessages/GenericRspMessage.cpp
new file mode 100644
index 0000000..9e99556
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/GenericRspMessage.cpp
@@ -0,0 +1,103 @@
+#include
+#include
+#include "GenericRspMessage.hpp"
+#include "Exception.hpp"
+
+//------------------------------------------------------------------------
+
+GenericRspMessage::GenericRspMessage(const bool& wasCommandSuccessful):
+ Message(MessageIDs::GENERIC_RSP, "GENERIC_RSP", sizeof(MessageStruct)),
+ m_messageStruct()
+{
+ m_messageStruct.wasCommandSuccessful = static_cast(wasCommandSuccessful);
+}
+
+//------------------------------------------------------------------------
+
+GenericRspMessage::GenericRspMessage(const GenericRspMessage& copy) :
+ Message(copy),
+ m_messageStruct(copy.m_messageStruct)
+{
+}
+
+//------------------------------------------------------------------------
+
+GenericRspMessage::~GenericRspMessage()
+{
+}
+
+//------------------------------------------------------------------------
+
+Message* GenericRspMessage::cloneSelf()
+{
+ GenericRspMessage* pMsg = new GenericRspMessage(*this);
+ return pMsg;
+}
+
+//------------------------------------------------------------------------
+
+void GenericRspMessage::executeMessage()
+{
+ try
+ {
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void GenericRspMessage::formatData(unsigned char* pData)
+{
+ // Here's how the data is formatted
+ // each data item is preceded by a 4-byte header which tells us the size of the data item
+ // 1 data item will have [header][data]
+ // 2 data items will have [header][data][header][data]
+ unsigned int dataLen = 0;
+ const unsigned char* pTempDataStart = pData + getHeaderLength();
+
+ buildByteArray(&pTempDataStart, reinterpret_cast(&m_messageStruct.wasCommandSuccessful), sizeof(m_messageStruct.wasCommandSuccessful), dataLen);
+
+ // we want update total size of the entire message
+ m_header.setMessageLength(static_cast(dataLen));
+ m_header.format(pData);
+}
+
+//------------------------------------------------------------------------
+
+void GenericRspMessage::parseData(const unsigned char* pData)
+{
+ const unsigned char* pTempDataStart = pData;
+ const unsigned char* pTempDataEnd = pData + m_header.getMessageLength() - m_header.getHeaderLength() - 1;
+ std::stringstream ss;
+
+ int sizeOfData = 0;
+ try {
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ // make sure byte number match between what we're expected and what we receive
+ compareByteNumber(sizeof(m_messageStruct.wasCommandSuccessful), sizeOfData);
+ memcpy(&m_messageStruct.wasCommandSuccessful, pTempDataStart, sizeOfData);
+
+ }
+ catch (Exception & e) {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+std::string GenericRspMessage::toString() const
+{
+ std::stringstream ss;
+
+ ss << Message::toString()
+ << "wasCommandSuccessful: " << m_messageStruct.wasCommandSuccessful << "\n"
+ << "\n";
+
+ return ss.str();
+}
diff --git a/CommonLib/src/Common/AutomationMessages/GenericRspMessage.hpp b/CommonLib/src/Common/AutomationMessages/GenericRspMessage.hpp
new file mode 100644
index 0000000..d5051d7
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/GenericRspMessage.hpp
@@ -0,0 +1,122 @@
+#pragma once
+
+#include "Message.hpp"
+#include "MessageIDs.hpp"
+#include "MessageHeader.hpp"
+
+class GenericRspMessage : public Message
+{
+public:
+ //>---------------------------------------------------------------------------
+ // Function: GenericRspMessage
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ GenericRspMessage(const bool& wasCommandSuccessful);
+
+ //>---------------------------------------------------------------------------
+ // Function: GenericRspMessage
+ //
+ // Purpose: copy constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ GenericRspMessage(const GenericRspMessage ©);
+
+ //>---------------------------------------------------------------------------
+ // Function: ~GenericRspMessage
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual ~GenericRspMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: GetSuccessfulFlag
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ bool getSuccessfulFlag(){return static_cast(m_messageStruct.wasCommandSuccessful);}
+
+ //>---------------------------------------------------------------------------
+ // Function: ExecuteMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void executeMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: ToString
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual std::string toString() const;
+
+protected:
+ //>---------------------------------------------------------------------------
+ // Function: CloneSelf
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual Message* cloneSelf();
+
+ //>---------------------------------------------------------------------------
+ // Function: FormatData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void formatData(unsigned char* pData);
+
+ //>---------------------------------------------------------------------------
+ // Function: ParseData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void parseData(const unsigned char* pData);
+
+private:
+ // do not allow
+ GenericRspMessage &operator=(const GenericRspMessage &rhs);
+
+#pragma pack(1)
+ struct MessageStruct
+ {
+ unsigned int wasCommandSuccessful;
+ };
+#pragma pack()
+
+ MessageStruct m_messageStruct;
+};
diff --git a/CommonLib/src/Common/AutomationMessages/Message.cpp b/CommonLib/src/Common/AutomationMessages/Message.cpp
new file mode 100644
index 0000000..8bc903a
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/Message.cpp
@@ -0,0 +1,176 @@
+#include
+#include
+
+#include "Message.hpp"
+#include "Exception.hpp"
+#include "StringUtil.hpp"
+//------------------------------------------------------------------------
+
+Message::Message(const MessageIDs::MsgIds& id,
+ const std::string& description,
+ const unsigned short& messageLen) :
+ m_header(id, messageLen),
+ m_description(description)
+{
+}
+
+//------------------------------------------------------------------------
+
+Message::Message(const Message& copy) :
+ m_header(copy.m_header),
+ m_description(copy.m_description)
+{
+}
+
+//------------------------------------------------------------------------
+
+Message::~Message()
+{
+}
+
+//------------------------------------------------------------------------
+
+Message* Message::clone()
+{
+ return cloneSelf();
+}
+
+//------------------------------------------------------------------------
+
+void Message::format(unsigned char* pBuffer)
+{
+ try
+ {
+ m_header.format(pBuffer);
+ formatData(pBuffer);
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+std::string Message::getDescription() const
+{
+ return m_description;
+}
+
+//------------------------------------------------------------------------
+
+void Message::parse(const unsigned char* pData)
+{
+ try
+ {
+ m_header.parse(pData);
+ parseData(pData + getHeaderLength());
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void Message::setMessageLength(const unsigned short& length)
+{
+ m_header.setMessageLength(length);
+}
+
+//------------------------------------------------------------------------
+
+std::string Message::toString() const
+{
+ std::stringstream ss;
+ ss << "Description: " << getDescription() << "\n" << m_header.toString();
+
+ return ss.str();
+}
+
+//------------------------------------------------------------------------
+
+int Message::getNextDataItem(const unsigned char** pStartBuf, const unsigned char* pEndBuf, int& sizeOfPreviousData)
+{
+ bool selfThrown = false;
+ int sizeOfDataHeader = 4;
+ int sizeOfData = 0;
+ std::stringstream ssError;
+
+ *pStartBuf += sizeOfPreviousData;
+ ssError << "Data structure is incorrect. Data: " << Util::Strings::ByteArrayToHexString(const_cast(*pStartBuf), pEndBuf - *pStartBuf + 1);
+ try {
+ // make sure 4 bytes of header information is present
+ if (*pStartBuf + sizeOfDataHeader > pEndBuf)
+ {
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ssError.str());
+ }
+
+ sizeOfData = *(*pStartBuf);
+
+ // we want to make sure the nth header and nth data information match
+ // header tells us how many bytes in the nth data item, and the bytes
+ // of data is present in the buffer
+ if (*pStartBuf + sizeOfDataHeader + sizeOfData -1 <= pEndBuf)
+ {
+ // points to the address of the nth data item
+ *pStartBuf += sizeOfDataHeader;
+ }
+ else
+ {
+ selfThrown = true;
+ throw Exception(__PRETTY_FUNCTION__," - " + ssError.str());
+ }
+ } catch (Exception& e) {
+ if (!selfThrown)
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+
+ return sizeOfData;
+}
+
+//------------------------------------------------------------------------
+
+void Message::buildByteArray(const unsigned char** pStartBuf, const char* data, const int& sizeOfDataBytes, unsigned int& totalBytesInArray)
+{
+ // copy the header information for this data item
+ memcpy(const_cast(*pStartBuf), &sizeOfDataBytes, sizeof(sizeOfDataBytes));
+ *pStartBuf += sizeof(sizeOfDataBytes);
+ totalBytesInArray += sizeof(sizeOfDataBytes);
+
+ // copy the data for this data item
+ memcpy(const_cast(*pStartBuf), data, sizeOfDataBytes);
+ *pStartBuf += sizeOfDataBytes;
+ totalBytesInArray += sizeOfDataBytes;
+}
+
+//------------------------------------------------------------------------
+
+void Message::compareByteNumber(int expectedNumBytes, int actualNumbyte)
+{
+ bool selfThrown = false;
+ std::stringstream ss;
+
+ try
+ {
+ if (expectedNumBytes != actualNumbyte)
+ {
+ selfThrown = true;
+
+ ss << "Expected number of bytes received: " << expectedNumBytes << ". Actual number of bytes received: " << actualNumbyte;
+ throw Exception(__PRETTY_FUNCTION__," - " + ss.str());
+ }
+ }
+ catch (Exception & e) {
+ if (!selfThrown)
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
diff --git a/CommonLib/src/Common/AutomationMessages/Message.hpp b/CommonLib/src/Common/AutomationMessages/Message.hpp
new file mode 100644
index 0000000..ef9bba7
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/Message.hpp
@@ -0,0 +1,241 @@
+#pragma once
+
+#include
+#include "MessageIDs.hpp"
+#include "MessageHeader.hpp"
+
+class Message
+{
+public:
+ //>---------------------------------------------------------------------
+ // Function: ~Message()
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual ~Message();
+
+ //>---------------------------------------------------------------------
+ // Function: Clone()
+ //
+ // Purpose: Get a copy of this object
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: a copy of this object
+ //<---------------------------------------------------------------------
+ virtual Message* clone();
+
+ //>---------------------------------------------------------------------
+ // Function: ExecuteMessage()
+ //
+ // Purpose: Executes this message
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void executeMessage() = 0;
+
+ //>---------------------------------------------------------------------
+ // Function: Format()
+ //
+ // Purpose: Formats this message for sending
+ //----------------------------------------------------------------------
+ // Arguments: pBuffer - the buffer to put the formatting data in
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void format(unsigned char* pBuffer);
+
+ //>---------------------------------------------------------------------
+ // Function: GetDescription()
+ //
+ // Purpose: Getter for this objects description
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The description
+ //<---------------------------------------------------------------------
+ virtual std::string getDescription() const;
+
+ //>---------------------------------------------------------------------
+ // Function: GetMessageID()
+ //
+ // Purpose: Getter for this objects message id
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The id
+ //<---------------------------------------------------------------------
+ virtual MessageIDs::MsgIds getMessageID() { return m_header.getMessageId(); }
+
+ //>---------------------------------------------------------------------
+ // Function: GetEntireMessageLength()
+ //
+ // Purpose: Getter for this objects message number of bytes, including the header
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The entire message number of bytes
+ //<---------------------------------------------------------------------
+ virtual unsigned int getEntireMessageLength() const { return m_header.getMessageLength();}
+
+ //>---------------------------------------------------------------------
+ // Function: GetHeaderLength()
+ //
+ // Purpose: Getter for this objects message number of header bytes
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The header number of bytes
+ //<---------------------------------------------------------------------
+ virtual unsigned short getHeaderLength() const { return m_header.getHeaderLength();}
+
+ //>---------------------------------------------------------------------
+ // Function: Parse()
+ //
+ // Purpose: Takes an array of bytes and populates this object
+ //----------------------------------------------------------------------
+ // Arguments: The array of bytes
+ //----------------------------------------------------------------------
+ // Return Value: None
+ //<---------------------------------------------------------------------
+ virtual void parse(const unsigned char* pData);
+
+ //>---------------------------------------------------------------------
+ // Function: ToString()
+ //
+ // Purpose: Converts this object into a string
+ //----------------------------------------------------------------------
+ // Arguments: None
+ //----------------------------------------------------------------------
+ // Return Value: The string form of this object
+ //<---------------------------------------------------------------------
+ virtual std::string toString() const;
+
+protected:
+ //>---------------------------------------------------------------------
+ // Function: Constructor
+ //
+ // Purpose: The constructor for the childern to call
+ //----------------------------------------------------------------------
+ // Arguments: id - the message id
+ // description - the message description
+ // messageLen - the number of bytes in the message payload (not including the header)
+ //----------------------------------------------------------------------
+ // Return Value: The object
+ //<---------------------------------------------------------------------
+ Message(const MessageIDs::MsgIds& id,
+ const std::string& description,
+ const unsigned short& messageLen = 0);
+
+ //>---------------------------------------------------------------------
+ // Function: Copy Constructor
+ //
+ // Purpose: Create a copy of this object
+ //----------------------------------------------------------------------
+ // Arguments: copy - the object to copy
+ //----------------------------------------------------------------------
+ // Return Value: The object
+ //<---------------------------------------------------------------------
+ Message(const Message ©);
+
+ //>---------------------------------------------------------------------
+ // Function: CloneSelf
+ //
+ // Purpose: Pure virtual function for children to implement.
+ // Create a clone of this object
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The object
+ //<---------------------------------------------------------------------
+ virtual Message* cloneSelf() = 0;
+
+ //>---------------------------------------------------------------------
+ // Function: FormatData
+ //
+ // Purpose: Pure virtual function for children to implement.
+ // Format the data
+ //----------------------------------------------------------------------
+ // Arguments: pData - the buffer to format to
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void formatData(unsigned char* pData) = 0;
+
+ //>---------------------------------------------------------------------
+ // Function: ParseData
+ //
+ // Purpose: Pure virtual function for children to implement.
+ // Parse the data
+ //----------------------------------------------------------------------
+ // Arguments: pData - the buffer to parse from
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void parseData(const unsigned char* pData) = 0;
+
+ //>---------------------------------------------------------------------
+ // Function: SetMessageLength
+ //
+ // Purpose: Sets the message length of the payload of the message (not the header)
+ //----------------------------------------------------------------------
+ // Arguments: length - the number of bytes in the payload
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void setMessageLength(const unsigned short& length);
+
+ //>---------------------------------------------------------------------
+ // Function: getNextDataItem
+ //
+ // Purpose:
+ // get the next data item
+ // data format:
+ // [data header][data][data header][data]...
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ int getNextDataItem(const unsigned char** pStartBuf, const unsigned char* pEndBuf, int& sizeOfPreviousData);
+
+ //>---------------------------------------------------------------------
+ // Function: buildByteArray
+ //
+ // Purpose:
+ // this will add to the byte array a data item
+ // data format:
+ // [data header][data]
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ void buildByteArray(const unsigned char** pStartBuf, const char* data, const int& sizeOfDataBytes, unsigned int& totalBytesInArray);
+
+ //>---------------------------------------------------------------------
+ // Function: compareByteNumber
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ void compareByteNumber(int expectedNumBytes, int actualNumbyte);
+
+ MessageHeader m_header;
+
+private:
+ // do not allow
+ Message();
+ Message &operator=(const Message &rhs);
+
+ std::string m_description;
+};
diff --git a/CommonLib/src/Common/AutomationMessages/MessageHeader.cpp b/CommonLib/src/Common/AutomationMessages/MessageHeader.cpp
new file mode 100644
index 0000000..8df7bae
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/MessageHeader.cpp
@@ -0,0 +1,86 @@
+#include
+#include
+#include "MessageHeader.hpp"
+
+//------------------------------------------------------------------------
+
+MessageHeader::MessageHeader(const MessageIDs::MsgIds& id, const unsigned short& messageLen) :
+ m_headerStruct()
+{
+ m_headerStruct.messageId = id;
+ m_headerStruct.messageLength = messageLen + getHeaderLength();
+}
+
+//------------------------------------------------------------------------
+
+MessageHeader::MessageHeader() :
+ m_headerStruct()
+{
+ m_headerStruct.messageId = 0;
+ m_headerStruct.messageLength = 0;
+}
+
+//------------------------------------------------------------------------
+
+MessageHeader::MessageHeader(const MessageHeader& copy) :
+ m_headerStruct(copy.m_headerStruct)
+{
+}
+
+//------------------------------------------------------------------------
+
+MessageHeader::~MessageHeader()
+{
+}
+
+//------------------------------------------------------------------------
+
+void MessageHeader::format(unsigned char* pData)
+{
+ memcpy(pData, &m_headerStruct, getHeaderLength());
+}
+
+//------------------------------------------------------------------------
+
+MessageIDs::MsgIds MessageHeader::getMessageId()
+{
+ return (MessageIDs::MsgIds)m_headerStruct.messageId;
+}
+
+//------------------------------------------------------------------------
+
+unsigned short MessageHeader::getHeaderLength() const
+{
+ return sizeof(m_headerStruct);
+}
+
+//------------------------------------------------------------------------
+
+unsigned int MessageHeader::getMessageLength() const
+{
+ return m_headerStruct.messageLength;
+}
+
+//------------------------------------------------------------------------
+
+void MessageHeader::parse(const unsigned char* pData)
+{
+ ::memcpy(&m_headerStruct, pData, getHeaderLength());
+}
+
+//------------------------------------------------------------------------
+
+void MessageHeader::setMessageLength(const unsigned short& length)
+{
+ m_headerStruct.messageLength = length + getHeaderLength();
+}
+
+//------------------------------------------------------------------------
+
+std::string MessageHeader::toString() const
+{
+ std::stringstream ss;
+ ss << "msg id: " << m_headerStruct.messageId << "\n" << "msg len: " << m_headerStruct.messageLength << "\n";
+
+ return ss.str();
+}
diff --git a/CommonLib/src/Common/AutomationMessages/MessageHeader.hpp b/CommonLib/src/Common/AutomationMessages/MessageHeader.hpp
new file mode 100644
index 0000000..2059807
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/MessageHeader.hpp
@@ -0,0 +1,145 @@
+#pragma once
+
+#include "MessageIDs.hpp"
+
+class MessageHeader
+{
+public:
+ //>---------------------------------------------------------------------
+ // Function: MessageHeader
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------
+ // Arguments: id - the message id
+ // messageLen - the number of bytes of the entire message including the header
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ MessageHeader(const MessageIDs::MsgIds& id, const unsigned short& messageLen);
+
+ //>---------------------------------------------------------------------
+ // Function: MessageHeader
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ MessageHeader();
+
+ //>---------------------------------------------------------------------
+ // Function: Copy Constructor
+ //
+ // Purpose: Create a copy of this object
+ //----------------------------------------------------------------------
+ // Arguments: copy - the object to copy
+ //----------------------------------------------------------------------
+ // Return Value: The object
+ //<---------------------------------------------------------------------
+ MessageHeader(const MessageHeader ©);
+
+ //>---------------------------------------------------------------------
+ // Function: ~MessageHeader()
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual ~MessageHeader();
+
+ //>---------------------------------------------------------------------
+ // Function: Format()
+ //
+ // Purpose: Formats this message for sending
+ //----------------------------------------------------------------------
+ // Arguments: pBuffer - the buffer to put the formatting data in
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ void format(unsigned char* pData);
+
+ //>---------------------------------------------------------------------
+ // Function: GetHeaderLength()
+ //
+ // Purpose: Get the number of bytes in the header
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: number of bytes in the header
+ //<---------------------------------------------------------------------
+ unsigned short getHeaderLength() const;
+
+ //>---------------------------------------------------------------------
+ // Function: GetMessageLength()
+ //
+ // Purpose: Get the number of bytes in the entire message, including header
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: number of bytes in the message
+ //<---------------------------------------------------------------------
+ unsigned int getMessageLength() const;
+
+ //>---------------------------------------------------------------------
+ // Function: GetMessageId()
+ //
+ // Purpose: Get the message id
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: the message id
+ //<---------------------------------------------------------------------
+ MessageIDs::MsgIds getMessageId();
+
+ //>---------------------------------------------------------------------
+ // Function: Parse()
+ //
+ // Purpose: Takes an array of bytes and populates this object
+ //----------------------------------------------------------------------
+ // Arguments: The array of bytes
+ //----------------------------------------------------------------------
+ // Return Value: None
+ //<---------------------------------------------------------------------
+ void parse(const unsigned char* pData);
+
+ //>---------------------------------------------------------------------
+ // Function: SetMessageLength
+ //
+ // Purpose: Sets the message length of the payload of the message (not the header)
+ //----------------------------------------------------------------------
+ // Arguments: length - the number of bytes in the payload
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ void setMessageLength(const unsigned short& length);
+
+ //>---------------------------------------------------------------------
+ // Function: ToString()
+ //
+ // Purpose: Converts this object into a string
+ //----------------------------------------------------------------------
+ // Arguments: None
+ //----------------------------------------------------------------------
+ // Return Value: The string form of this object
+ //<---------------------------------------------------------------------
+ std::string toString() const;
+
+protected:
+
+private:
+ // do not allow
+ MessageHeader &operator=(const MessageHeader &rhs);
+
+#pragma pack(1)
+ struct HeaderStruct
+ {
+ unsigned int messageId;
+ unsigned int messageLength;
+ };
+#pragma pack()
+
+ HeaderStruct m_headerStruct;
+};
diff --git a/CommonLib/src/Common/AutomationMessages/MessageIDs.hpp b/CommonLib/src/Common/AutomationMessages/MessageIDs.hpp
new file mode 100644
index 0000000..4f6de3b
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/MessageIDs.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+
+namespace MessageIDs
+{
+ enum MsgIds
+ {
+ TRANSFER_A_FILE_CMD = 0xCA001001,
+ TRANSFER_A_FOLDER_CMD = 0xCA001002,
+ TRANSFER_GUTS_VIDEOS_CMD = 0xCA001003,
+ MOVE_GUTS_VIDEOS_TO_SUB_FOLDER_CMD = 0xCA001004,
+ WAIT_FOR_COMPLETION_CMD = 0xCA001005,
+
+ GENERIC_RSP = 0xCA002001
+ };
+}
diff --git a/CommonLib/src/Common/AutomationMessages/MoveGutsVideosToSubFolderCmdMessage.cpp b/CommonLib/src/Common/AutomationMessages/MoveGutsVideosToSubFolderCmdMessage.cpp
new file mode 100644
index 0000000..da735b5
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/MoveGutsVideosToSubFolderCmdMessage.cpp
@@ -0,0 +1,117 @@
+#include
+#include
+#include "MoveGutsVideosToSubFolderCmdMessage.hpp"
+#include "Exception.hpp"
+#include "StringUtil.hpp"
+#include "LinuxProc.hpp"
+#include "IniFile.hpp"
+#include "GenericRspMessage.hpp"
+#include "Condition.hpp"
+
+//------------------------------------------------------------------------
+
+MoveGutsVideosToSubFolderCmdMessage::MoveGutsVideosToSubFolderCmdMessage(std::string subFolder):
+ Message(MessageIDs::MOVE_GUTS_VIDEOS_TO_SUB_FOLDER_CMD, "MOVE_GUTS_VIDEOS_TO_SUB_FOLDER_CMD"),
+ m_subFolder(subFolder)
+{
+}
+
+//------------------------------------------------------------------------
+
+MoveGutsVideosToSubFolderCmdMessage::MoveGutsVideosToSubFolderCmdMessage(const MoveGutsVideosToSubFolderCmdMessage& copy) :
+ Message(copy),
+ m_subFolder(copy.m_subFolder)
+{
+}
+
+//------------------------------------------------------------------------
+
+MoveGutsVideosToSubFolderCmdMessage::~MoveGutsVideosToSubFolderCmdMessage()
+{
+}
+
+//------------------------------------------------------------------------
+
+Message* MoveGutsVideosToSubFolderCmdMessage::cloneSelf()
+{
+ MoveGutsVideosToSubFolderCmdMessage* pMsg = new MoveGutsVideosToSubFolderCmdMessage(*this);
+ return pMsg;
+}
+
+//------------------------------------------------------------------------
+
+void MoveGutsVideosToSubFolderCmdMessage::executeMessage()
+{
+ try
+ {
+ Condition& commandExecutingEvent = LinuxProc::Instance().getEvent(EventNames::COMMAND_EXECUTTION_IN_PROGRESS);
+ Condition& completeEvent = LinuxProc::Instance().getEvent(EventNames::COMMAND_EXECUTION_COMPLETE);
+
+ completeEvent.reset();
+ if (commandExecutingEvent.timedWait(0,0)) // a command is current executing
+ {
+ completeEvent.wait(); // wait until current command finish executing
+ }
+
+ // signal this command is currently executing to prevent any other command from executing
+ commandExecutingEvent.signal();
+
+ /// code to execute commands here
+
+ commandExecutingEvent.reset();
+ completeEvent.signal();
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void MoveGutsVideosToSubFolderCmdMessage::formatData(unsigned char* pData)
+{
+ // Here's how the data is formatted
+ // each data item is preceded by a 4-byte header which tells us the size of the data item
+ // 1 data item will have [header][data]
+ // 2 data items will have [header][data][header][data]
+ unsigned int dataLen = 0;
+ const unsigned char* pTempDataStart = pData + getHeaderLength();
+
+ buildByteArray(&pTempDataStart, m_subFolder.c_str(), m_subFolder.length(), dataLen);
+
+ // we want update total size of the entire message
+ m_header.setMessageLength(static_cast(dataLen));
+ m_header.format(pData);
+}
+
+//------------------------------------------------------------------------
+
+void MoveGutsVideosToSubFolderCmdMessage::parseData(const unsigned char* pData)
+{
+ const unsigned char* pTempDataStart = pData;
+ const unsigned char* pTempDataEnd = pData + m_header.getMessageLength() - m_header.getHeaderLength() - 1;
+
+ int sizeOfData = 0;
+ try {
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ m_subFolder = Util::Strings::ByteArrayToString(const_cast(pTempDataStart), sizeOfData);
+
+ } catch (Exception& e) {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+std::string MoveGutsVideosToSubFolderCmdMessage::toString() const
+{
+ std::stringstream ss;
+
+ ss << Message::toString() << ". Subfolder name: " << m_subFolder;
+
+ return ss.str();
+}
diff --git a/CommonLib/src/Common/AutomationMessages/MoveGutsVideosToSubFolderCmdMessage.hpp b/CommonLib/src/Common/AutomationMessages/MoveGutsVideosToSubFolderCmdMessage.hpp
new file mode 100644
index 0000000..5798434
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/MoveGutsVideosToSubFolderCmdMessage.hpp
@@ -0,0 +1,104 @@
+#pragma once
+
+#include "Message.hpp"
+#include "MessageIDs.hpp"
+#include "MessageHeader.hpp"
+
+class MoveGutsVideosToSubFolderCmdMessage : public Message
+{
+public:
+ //>---------------------------------------------------------------------------
+ // Function: MoveGutsVideosToSubFolderCmdMessage
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ MoveGutsVideosToSubFolderCmdMessage(std::string subFolder = "");
+
+ //>---------------------------------------------------------------------------
+ // Function: MoveGutsVideosToSubFolderCmdMessage
+ //
+ // Purpose: copy constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ MoveGutsVideosToSubFolderCmdMessage(const MoveGutsVideosToSubFolderCmdMessage ©);
+
+ //>---------------------------------------------------------------------------
+ // Function: ~MoveGutsVideosToSubFolderCmdMessage
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual ~MoveGutsVideosToSubFolderCmdMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: ExecuteMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void executeMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: ToString
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual std::string toString() const;
+
+protected:
+ //>---------------------------------------------------------------------------
+ // Function: CloneSelf
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual Message* cloneSelf();
+
+ //>---------------------------------------------------------------------------
+ // Function: FormatData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void formatData(unsigned char* pData);
+
+ //>---------------------------------------------------------------------------
+ // Function: ParseData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void parseData(const unsigned char* pData);
+
+private:
+ // do not allow
+ MoveGutsVideosToSubFolderCmdMessage &operator=(const MoveGutsVideosToSubFolderCmdMessage &rhs);
+
+ std::string m_subFolder;
+};
diff --git a/CommonLib/src/Common/AutomationMessages/TransferAFileCmdMessage.cpp b/CommonLib/src/Common/AutomationMessages/TransferAFileCmdMessage.cpp
new file mode 100644
index 0000000..92d90d8
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/TransferAFileCmdMessage.cpp
@@ -0,0 +1,123 @@
+#include
+#include
+#include "TransferAFileCmdMessage.hpp"
+#include "Proc.hpp"
+#include "Exception.hpp"
+#include "StringUtil.hpp"
+#include "GenericRspMessage.hpp"
+#include "UdpSocket.hpp"
+
+//------------------------------------------------------------------------
+
+TransferAFileCmdMessage::TransferAFileCmdMessage(std::string fromFile, std::string toFile, bool deleteSource):
+ Message(MessageIDs::TRANSFER_A_FILE_CMD, "TRANSFER_A_FILE_CMD"),
+ m_fromFile(fromFile),
+ m_toFile(toFile),
+ m_deleteSource(static_cast(deleteSource))
+{
+}
+
+//------------------------------------------------------------------------
+
+TransferAFileCmdMessage::TransferAFileCmdMessage(const TransferAFileCmdMessage& copy) :
+ Message(copy),
+ m_fromFile(copy.m_fromFile),
+ m_toFile(copy.m_toFile),
+ m_deleteSource(copy.m_deleteSource)
+{
+}
+
+//------------------------------------------------------------------------
+
+TransferAFileCmdMessage::~TransferAFileCmdMessage()
+{
+}
+
+//------------------------------------------------------------------------
+
+Message* TransferAFileCmdMessage::cloneSelf()
+{
+ TransferAFileCmdMessage* pMsg = new TransferAFileCmdMessage(*this);
+ return pMsg;
+}
+
+//------------------------------------------------------------------------
+
+void TransferAFileCmdMessage::executeMessage()
+{
+ try
+ {
+ GenericRspMessage rsp(true);
+
+ //Proc::instance().sendAMessage(rsp);
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void TransferAFileCmdMessage::formatData(unsigned char* pData)
+{
+ // Here's how the data is formatted
+ // each data item is preceded by a 4-byte header which tells us the size of the data item
+ // 1 data item will have [header][data]
+ // 2 data items will have [header][data][header][data]
+ unsigned int dataLen = 0;
+ const unsigned char* pTempDataStart = pData + getHeaderLength();
+
+ buildByteArray(&pTempDataStart, m_fromFile.c_str(), m_fromFile.length(), dataLen);
+ buildByteArray(&pTempDataStart, m_toFile.c_str(), m_toFile.length(), dataLen);
+ buildByteArray(&pTempDataStart, reinterpret_cast(&m_deleteSource), sizeof(m_deleteSource), dataLen);
+
+ // we want update total size of the entire message
+ m_header.setMessageLength(static_cast(dataLen));
+ m_header.format(pData);
+}
+
+//------------------------------------------------------------------------
+
+void TransferAFileCmdMessage::parseData(const unsigned char* pData)
+{
+ const unsigned char* pTempDataStart = pData;
+ const unsigned char* pTempDataEnd = pData + m_header.getMessageLength() - m_header.getHeaderLength() - 1;
+
+ int sizeOfData = 0;
+ try {
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ m_fromFile = Util::Strings::ByteArrayToString(const_cast(pTempDataStart), sizeOfData);
+
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ m_toFile = Util::Strings::ByteArrayToString(const_cast(pTempDataStart), sizeOfData);
+
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ // make sure byte number match between what we're expected and what we receive
+ compareByteNumber(sizeof(m_deleteSource), sizeOfData);
+ memcpy(&m_deleteSource, pTempDataStart, sizeOfData);
+
+ } catch (Exception& e) {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+std::string TransferAFileCmdMessage::toString() const
+{
+ std::stringstream ss;
+
+ ss << Message::toString() << ". From file: " << m_fromFile << ". To file: " << m_toFile << ". Delete source: " << m_deleteSource;
+
+ return ss.str();
+}
diff --git a/CommonLib/src/Common/AutomationMessages/TransferAFileCmdMessage.hpp b/CommonLib/src/Common/AutomationMessages/TransferAFileCmdMessage.hpp
new file mode 100644
index 0000000..10c6d80
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/TransferAFileCmdMessage.hpp
@@ -0,0 +1,108 @@
+#pragma once
+
+#include "Message.hpp"
+#include "MessageIDs.hpp"
+#include "MessageHeader.hpp"
+
+class TransferAFileCmdMessage : public Message
+{
+public:
+ //>---------------------------------------------------------------------------
+ // Function: TransferAFileCmdMessage
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ TransferAFileCmdMessage(std::string fromFile = "", std::string toFile = "", bool deleteSource = false);
+
+ //>---------------------------------------------------------------------------
+ // Function: TransferAFileCmdMessage
+ //
+ // Purpose: copy constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ TransferAFileCmdMessage(const TransferAFileCmdMessage ©);
+
+ //>---------------------------------------------------------------------------
+ // Function: ~TransferAFileCmdMessage
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual ~TransferAFileCmdMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: ExecuteMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void executeMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: ToString
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual std::string toString() const;
+
+protected:
+ //>---------------------------------------------------------------------------
+ // Function: CloneSelf
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual Message* cloneSelf();
+
+ //>---------------------------------------------------------------------------
+ // Function: FormatData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void formatData(unsigned char* pData);
+
+ //>---------------------------------------------------------------------------
+ // Function: ParseData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void parseData(const unsigned char* pData);
+
+private:
+ // do not allow
+ TransferAFileCmdMessage &operator=(const TransferAFileCmdMessage &rhs);
+
+ std::string m_fromFile;
+
+ std::string m_toFile;
+
+ unsigned int m_deleteSource;
+};
diff --git a/CommonLib/src/Common/AutomationMessages/TransferGutsVideosCmdMessage.cpp b/CommonLib/src/Common/AutomationMessages/TransferGutsVideosCmdMessage.cpp
new file mode 100644
index 0000000..eb91592
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/TransferGutsVideosCmdMessage.cpp
@@ -0,0 +1,153 @@
+#include
+#include
+#include "TransferGutsVideosCmdMessage.hpp"
+#include "LinuxProc.hpp"
+#include "Exception.hpp"
+#include "Condition.hpp"
+#include "StringUtil.hpp"
+#include "GenericRspMessage.hpp"
+#include "IniFile.hpp"
+
+//------------------------------------------------------------------------
+
+TransferGutsVideosCmdMessage::TransferGutsVideosCmdMessage(std::string currentTestFolder, unsigned int transferEverything, unsigned int deleteSource):
+ Message(MessageIDs::TRANSFER_GUTS_VIDEOS_CMD, "TRANSFER_GUTS_VIDEOS_CMD"),
+ m_currentTestFolder(currentTestFolder),
+ m_transferEverything(transferEverything),
+ m_deleteSource(deleteSource)
+{
+}
+
+//------------------------------------------------------------------------
+
+TransferGutsVideosCmdMessage::TransferGutsVideosCmdMessage(const TransferGutsVideosCmdMessage& copy) :
+ Message(copy),
+ m_currentTestFolder(copy.m_currentTestFolder),
+ m_transferEverything(copy.m_transferEverything),
+ m_deleteSource(copy.m_deleteSource)
+{
+}
+
+//------------------------------------------------------------------------
+
+TransferGutsVideosCmdMessage::~TransferGutsVideosCmdMessage()
+{
+}
+
+//------------------------------------------------------------------------
+
+Message* TransferGutsVideosCmdMessage::cloneSelf()
+{
+ TransferGutsVideosCmdMessage* pMsg = new TransferGutsVideosCmdMessage(*this);
+ return pMsg;
+}
+
+//------------------------------------------------------------------------
+
+void TransferGutsVideosCmdMessage::executeMessage()
+{
+ try
+ {
+ Condition& commandExecutingEvent = LinuxProc::Instance().getEvent(EventNames::COMMAND_EXECUTTION_IN_PROGRESS);
+ Condition& completeEvent = LinuxProc::Instance().getEvent(EventNames::COMMAND_EXECUTION_COMPLETE);
+
+ completeEvent.reset();
+ if (commandExecutingEvent.timedWait(0,0)) // a command is current executing
+ {
+ completeEvent.wait(); // wait until current command finish executing
+ }
+
+ // signal this command is currently executing to prevent any other command from executing
+ commandExecutingEvent.signal();
+
+ GenericRspMessage rsp(true);
+
+ //LinuxProc::instance().sendAMessage(rsp);
+
+ gatherInfo();
+
+ Condition& event = LinuxProc::Instance().getEvent(EventNames::START_FILE_TRANSFER);
+ event.signal();
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void TransferGutsVideosCmdMessage::gatherInfo()
+{
+ try
+ {
+
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void TransferGutsVideosCmdMessage::formatData(unsigned char* pData)
+{
+ // Here's how the data is formatted
+ // each data item is preceded by a 4-byte header which tells us the size of the data item
+ // 1 data item will have [header][data]
+ // 2 data items will have [header][data][header][data]
+ unsigned int dataLen = 0;
+ const unsigned char* pTempDataStart = pData + getHeaderLength();
+
+ buildByteArray(&pTempDataStart, m_currentTestFolder.c_str(), m_currentTestFolder.length(), dataLen);
+ buildByteArray(&pTempDataStart, reinterpret_cast(&m_transferEverything), sizeof(m_transferEverything), dataLen);
+ buildByteArray(&pTempDataStart, reinterpret_cast(&m_deleteSource), sizeof(m_deleteSource), dataLen);
+
+ // we want update total size of the entire message
+ m_header.setMessageLength(static_cast(dataLen));
+ m_header.format(pData);
+}
+
+//------------------------------------------------------------------------
+
+void TransferGutsVideosCmdMessage::parseData(const unsigned char* pData)
+{
+ const unsigned char* pTempDataStart = pData;
+ const unsigned char* pTempDataEnd = pData + m_header.getMessageLength() - m_header.getHeaderLength() - 1;
+
+ int sizeOfData = 0;
+ try {
+ // get the address of the 1st data item
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ m_currentTestFolder = Util::Strings::ByteArrayToString(const_cast(pTempDataStart), sizeOfData);
+
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ // make sure byte number match between what we're expected and what we receive
+ compareByteNumber(sizeof(m_transferEverything), sizeOfData);
+ memcpy(&m_transferEverything, pTempDataStart, sizeOfData);
+
+ sizeOfData = getNextDataItem(&pTempDataStart, pTempDataEnd, sizeOfData);
+ // make sure byte number match between what we're expected and what we receive
+ compareByteNumber(sizeof(m_deleteSource), sizeOfData);
+ memcpy(&m_deleteSource, pTempDataStart, sizeOfData);
+
+ } catch (Exception& e) {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+std::string TransferGutsVideosCmdMessage::toString() const
+{
+ std::stringstream ss;
+
+ ss << Message::toString() << ". current test folder: " << m_currentTestFolder << ". transfer everything: " << m_transferEverything << ". Delete source: " << m_deleteSource;
+
+ return ss.str();
+}
diff --git a/CommonLib/src/Common/AutomationMessages/TransferGutsVideosCmdMessage.hpp b/CommonLib/src/Common/AutomationMessages/TransferGutsVideosCmdMessage.hpp
new file mode 100644
index 0000000..6c013fa
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/TransferGutsVideosCmdMessage.hpp
@@ -0,0 +1,126 @@
+#pragma once
+
+#include "Message.hpp"
+#include "MessageIDs.hpp"
+#include "MessageHeader.hpp"
+
+class TransferGutsVideosCmdMessage : public Message
+{
+public:
+ //>---------------------------------------------------------------------
+ // Function: TransferGutsVideosCmdMessage
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ TransferGutsVideosCmdMessage(std::string currentTestFolder, unsigned int transferEverything = 0, unsigned int deleteSource = 0);
+
+ //>---------------------------------------------------------------------
+ // Function: TransferGutsVideosCmdMessage
+ //
+ // Purpose: copy constructor
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ TransferGutsVideosCmdMessage(const TransferGutsVideosCmdMessage ©);
+
+ //>---------------------------------------------------------------------
+ // Function: ~TransferGutsVideosCmdMessage
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual ~TransferGutsVideosCmdMessage();
+
+ //>---------------------------------------------------------------------
+ // Function: ExecuteMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void executeMessage();
+
+ //>---------------------------------------------------------------------
+ // Function: ToString
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual std::string toString() const;
+
+protected:
+ //>---------------------------------------------------------------------
+ // Function: CloneSelf
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual Message* cloneSelf();
+
+ //>---------------------------------------------------------------------
+ // Function: FormatData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void formatData(unsigned char* pData);
+
+ //>---------------------------------------------------------------------
+ // Function: ParseData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual void parseData(const unsigned char* pData);
+
+ //>---------------------------------------------------------------------
+ // Function: gatherInfo
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ void gatherInfo();
+
+private:
+ // do not allow
+ TransferGutsVideosCmdMessage &operator=(const TransferGutsVideosCmdMessage &rhs);
+
+ std::string m_currentTestFolder;
+ unsigned int m_transferEverything;
+ unsigned int m_deleteSource;
+};
diff --git a/CommonLib/src/Common/AutomationMessages/WaitForLastTaskCompletionCmdMessage.cpp b/CommonLib/src/Common/AutomationMessages/WaitForLastTaskCompletionCmdMessage.cpp
new file mode 100644
index 0000000..728d175
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/WaitForLastTaskCompletionCmdMessage.cpp
@@ -0,0 +1,82 @@
+#include
+#include
+#include "WaitForLastTaskCompletionCmdMessage.hpp"
+#include "Exception.hpp"
+#include "Condition.hpp"
+#include "LinuxProc.hpp"
+#include "GenericRspMessage.hpp"
+
+bool WaitForLastTaskCompletionCmdMessage::s_commandCompletionSuccess = true;
+
+//------------------------------------------------------------------------
+
+WaitForLastTaskCompletionCmdMessage::WaitForLastTaskCompletionCmdMessage():
+ Message(MessageIDs::WAIT_FOR_COMPLETION_CMD, "WAIT_FOR_COMPLETION_CMD")
+{
+}
+
+//------------------------------------------------------------------------
+
+WaitForLastTaskCompletionCmdMessage::WaitForLastTaskCompletionCmdMessage(const WaitForLastTaskCompletionCmdMessage& copy) :
+ Message(copy)
+{
+}
+
+//------------------------------------------------------------------------
+
+WaitForLastTaskCompletionCmdMessage::~WaitForLastTaskCompletionCmdMessage()
+{
+}
+
+//------------------------------------------------------------------------
+
+Message* WaitForLastTaskCompletionCmdMessage::cloneSelf()
+{
+ WaitForLastTaskCompletionCmdMessage* pMsg = new WaitForLastTaskCompletionCmdMessage(*this);
+ return pMsg;
+}
+
+//------------------------------------------------------------------------
+
+void WaitForLastTaskCompletionCmdMessage::executeMessage()
+{
+ try
+ {
+ Condition& event = LinuxProc::Instance().getEvent(EventNames::COMMAND_EXECUTION_COMPLETE);
+ event.wait(false);
+
+ GenericRspMessage rsp(s_commandCompletionSuccess);
+
+ //Proc::instance().sendAMessage(rsp);
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void WaitForLastTaskCompletionCmdMessage::formatData(unsigned char*)
+{
+ // no data to send
+}
+
+//------------------------------------------------------------------------
+
+void WaitForLastTaskCompletionCmdMessage::parseData(const unsigned char*)
+{
+ // no data to process
+}
+
+//------------------------------------------------------------------------
+
+std::string WaitForLastTaskCompletionCmdMessage::toString() const
+{
+ std::stringstream ss;
+
+ ss << Message::toString() << ". No member data";
+
+ return ss.str();
+}
diff --git a/CommonLib/src/Common/AutomationMessages/WaitForLastTaskCompletionCmdMessage.hpp b/CommonLib/src/Common/AutomationMessages/WaitForLastTaskCompletionCmdMessage.hpp
new file mode 100644
index 0000000..b57f557
--- /dev/null
+++ b/CommonLib/src/Common/AutomationMessages/WaitForLastTaskCompletionCmdMessage.hpp
@@ -0,0 +1,105 @@
+#pragma once
+
+#include "Message.hpp"
+#include "MessageIDs.hpp"
+#include "MessageHeader.hpp"
+
+class WaitForLastTaskCompletionCmdMessage : public Message
+{
+public:
+ //>---------------------------------------------------------------------------
+ // Function: WaitForLastTaskCompletionCmdMessage
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ WaitForLastTaskCompletionCmdMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: WaitForLastTaskCompletionCmdMessage
+ //
+ // Purpose: copy constructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ WaitForLastTaskCompletionCmdMessage(const WaitForLastTaskCompletionCmdMessage ©);
+
+ //>---------------------------------------------------------------------------
+ // Function: ~WaitForLastTaskCompletionCmdMessage
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual ~WaitForLastTaskCompletionCmdMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: ExecuteMessage
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void executeMessage();
+
+ //>---------------------------------------------------------------------------
+ // Function: ToString
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual std::string toString() const;
+
+ // indicate command executed successfully or not
+ static bool s_commandCompletionSuccess;
+
+protected:
+ //>---------------------------------------------------------------------------
+ // Function: CloneSelf
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual Message* cloneSelf();
+
+ //>---------------------------------------------------------------------------
+ // Function: FormatData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void formatData(unsigned char* pData);
+
+ //>---------------------------------------------------------------------------
+ // Function: ParseData
+ //
+ // Purpose:
+ //----------------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------------
+ // Return Value:
+ //----------------------------------------------------------------------------
+ virtual void parseData(const unsigned char* pData);
+
+private:
+ // do not allow
+ WaitForLastTaskCompletionCmdMessage &operator=(const WaitForLastTaskCompletionCmdMessage &rhs);
+};
diff --git a/CommonLib/src/Common/Comm/CommInterface.hpp b/CommonLib/src/Common/Comm/CommInterface.hpp
new file mode 100644
index 0000000..5940f8a
--- /dev/null
+++ b/CommonLib/src/Common/Comm/CommInterface.hpp
@@ -0,0 +1,70 @@
+#pragma once
+
+#include
+
+class CommInterface
+{
+public:
+ //>---------------------------------------------------------------------
+ // Function: CommInterface
+ //
+ // Purpose: COnstructor
+ //----------------------------------------------------------------------
+ // Arguments: name - the name of this comm interface
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ CommInterface(const std::string& name) {m_name = name;};
+
+ //>---------------------------------------------------------------------
+ // Function: ~CommInterface()
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual ~CommInterface(){};
+
+ //>---------------------------------------------------------------------
+ // Function: GetName
+ //
+ // Purpose: Get the name of this comm interface
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The name of the interface
+ //<---------------------------------------------------------------------
+ std::string& getName() {return m_name;};
+
+ //>---------------------------------------------------------------------
+ // Function: Read
+ //
+ // Purpose: Read data from this comm interface
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The number of bytes read
+ //<---------------------------------------------------------------------
+ virtual int read(char* pDataBuffer, const unsigned int& bufferSize, const unsigned int& timeoutSec) = 0;
+
+ //>---------------------------------------------------------------------
+ // Function: Write
+ //
+ // Purpose: Write data to this comm interface
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: The number of bytes written
+ //<---------------------------------------------------------------------
+ virtual int write(const char* pDataToWrite, const unsigned int& numBytesToWrite) = 0;
+
+private:
+ // do not allow
+ CommInterface();
+ CommInterface(const CommInterface ©);
+ CommInterface &operator=(const CommInterface &rhs);
+
+ std::string m_name;
+};
diff --git a/CommonLib/src/Common/Comm/UdpSocket.cpp b/CommonLib/src/Common/Comm/UdpSocket.cpp
new file mode 100644
index 0000000..f941d16
--- /dev/null
+++ b/CommonLib/src/Common/Comm/UdpSocket.cpp
@@ -0,0 +1,131 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "UdpSocket.hpp"
+#include "TimeoutError.hpp"
+#include "NetworkUtil.hpp"
+
+UdpSocket::UdpSocket(const std::string& name, const int& localPort, const int& remotePort, const std::string& remoteAddy):
+ CommInterface(name),
+ m_localPort(localPort),
+ m_remotePort(remotePort),
+ m_sock(-1),
+ m_localSockInfo(),
+ m_remoteSockInfo()
+{
+ try
+ {
+ m_remoteAddy = Util::Network::ConvertHostnameToIp(remoteAddy);
+ bindSocket();
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void UdpSocket::bindSocket()
+{
+ try
+ {
+ m_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+ if (m_sock < 0)
+ {
+ std::stringstream ss;
+ ss << "socket create failed: " << m_sock;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ memset((char*)&m_localSockInfo, 0, sizeof(m_localSockInfo));
+ m_localSockInfo.sin_family = AF_INET;
+
+ m_localSockInfo.sin_addr.s_addr = htonl(INADDR_ANY);
+ m_localSockInfo.sin_port = htons(m_localPort);
+
+ int ret = bind(m_sock, (struct sockaddr*)&m_localSockInfo, sizeof(m_localSockInfo));
+
+ if(ret < 0)
+ {
+ std::stringstream ss;
+ ss << "bind failed: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ if (m_remotePort > 1 && m_remoteAddy.length() > 1)
+ {
+ memset((char*)&m_remoteSockInfo, 0, sizeof(m_remoteSockInfo));
+ m_remoteSockInfo.sin_family = AF_INET;
+
+ m_remoteSockInfo.sin_addr.s_addr = inet_addr(m_remoteAddy.c_str());
+ m_remoteSockInfo.sin_port = htons(m_remotePort);
+ }
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+int UdpSocket::read(char* pDataBuffer, const unsigned int& bufferSize, const unsigned int& timeoutSec)
+{
+ try
+ {
+ // set the timeout
+ struct timeval to;
+ to.tv_sec = timeoutSec;
+ to.tv_usec = 0;
+
+ if (timeoutSec != CommonLibConstants::INFINITE)
+ {
+ int ret = setsockopt(m_sock, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof(to));
+
+ if (ret < 0)
+ {
+ std::stringstream ss;
+ ss << "unable to set timeout: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+ }
+
+ socklen_t clntLen = sizeof(m_remoteSockInfo);
+
+ int bytesRcv = recvfrom(m_sock, pDataBuffer, bufferSize, 0, (struct sockaddr *)&m_remoteSockInfo, &clntLen);
+
+ if (errno == 11)
+ {
+ throw TimeoutError(__PRETTY_FUNCTION__, "timed out", TimeoutError::TIME_OUT_SOCKET);
+ }
+
+ return bytesRcv;
+ }
+ catch (TimeoutError& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+int UdpSocket::write(const char* pDataToWrite, const unsigned int& numBytesToWrite)
+{
+ unsigned int bytesSent = sendto(m_sock, pDataToWrite, numBytesToWrite, 0, (struct sockaddr *)&m_remoteSockInfo, sizeof(m_remoteSockInfo));
+
+ return bytesSent;
+}
diff --git a/CommonLib/src/Common/Comm/UdpSocket.hpp b/CommonLib/src/Common/Comm/UdpSocket.hpp
new file mode 100644
index 0000000..47af2c9
--- /dev/null
+++ b/CommonLib/src/Common/Comm/UdpSocket.hpp
@@ -0,0 +1,93 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include "CommInterface.hpp"
+#include "Constants.hpp"
+
+class UdpSocket: public CommInterface
+{
+public:
+ //>---------------------------------------------------------------------
+ // Function: UdpSocket()
+ //
+ // Purpose: Constructor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: the object
+ //<---------------------------------------------------------------------
+ UdpSocket(const std::string& name, const int& localPort, const int& remotePort = -1, const std::string& remoteAddy = "");
+
+ //>---------------------------------------------------------------------
+ // Function: ~UdpSocket
+ //
+ // Purpose: Destroyer
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual ~UdpSocket() {}
+
+ //>---------------------------------------------------------------------
+ // Function: BindSocket
+ //
+ // Purpose: Bind the socket
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ void bindSocket();
+
+ //>---------------------------------------------------------------------
+ // Function: Read
+ //
+ // Purpose: Read from the socket
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: number of bytes read
+ //<---------------------------------------------------------------------
+ virtual int read(char* pDataBuffer, const unsigned int& bufferSize, const unsigned int& timeoutSec = CommonLibConstants::INFINITE);
+
+ //>---------------------------------------------------------------------
+ // Function: Write
+ //
+ // Purpose: Write to the socket
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: number of bytes written
+ //<---------------------------------------------------------------------
+ virtual int write(const char* pDataToWrite, const unsigned int& numBytesToWrite);
+
+ //>---------------------------------------------------------------------
+ // Function: Close
+ //
+ // Purpose: close the file descriptor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ void close(){shutdown(m_sock, SHUT_RDWR);}
+
+private:
+ // dont allow
+ UdpSocket(const UdpSocket& rhs);
+ UdpSocket& operator=(const UdpSocket& rhs);
+
+ int m_localPort;
+ int m_remotePort;
+ std::string m_remoteAddy;
+ int m_sock;
+
+ struct sockaddr_in m_localSockInfo;
+ struct sockaddr_in m_remoteSockInfo;
+};
+
diff --git a/CommonLib/src/Common/Exceptions/Exception.cpp b/CommonLib/src/Common/Exceptions/Exception.cpp
new file mode 100644
index 0000000..46d8266
--- /dev/null
+++ b/CommonLib/src/Common/Exceptions/Exception.cpp
@@ -0,0 +1,110 @@
+#include "Exception.hpp"
+#include "PosixRegexUtil.hpp"
+#include "StringUtil.hpp"
+
+#include
+
+//------------------------------------------------------------------------
+
+Exception::Exception(std::string functionName, const std::string& errorMsg, const std::string& exceptionClass) :
+ exception()
+{
+ std::string className = "";
+ if (exceptionClass.length() == 0)
+ className = std::string(typeid(this).name());
+ else
+ className = exceptionClass;
+
+ // get the name of the class without the extra add-ons
+ std::vector vecMatches = Util::PosixRegex::GetMatchesFromRegex(className, "[a-z][0-9]+([a-z].+)");
+
+ if (vecMatches.size() > 1)
+ m_message = vecMatches[1];
+ else
+ m_message = "Exception";
+
+ m_message += ": ";
+
+ m_lastFunction = functionName;
+
+ vecMatches = Util::PosixRegex::GetMatchesFromRegex(functionName, "([^ \\(]+\\()");
+
+ if (vecMatches.size() > 1)
+ functionName = vecMatches[1] + ")";
+
+ m_message += functionName + " - " + errorMsg;
+ m_fullStackTraceMessage = m_message;
+ m_message = errorMsg;
+}
+
+//------------------------------------------------------------------------
+
+Exception::Exception(const Exception &rhs)
+{
+ copy(rhs);
+}
+
+//------------------------------------------------------------------------
+
+Exception &Exception::operator=(const Exception &rhs)
+{
+ return copy(rhs);
+}
+
+//------------------------------------------------------------------------
+
+std::string Exception::getMessage(Message_Format msgFormat)
+{
+ std::string msg = m_message;
+
+ if (msgFormat == ERROR_MESSAGE_WITH_STACKTRACE)
+ msg = m_fullStackTraceMessage;
+
+ return msg;
+}
+
+//------------------------------------------------------------------------
+
+void Exception::buildStackTrace(std::string functionName, const std::string& errorMsg)
+{
+ if (!Util::Strings::StringsAreEqual(functionName, m_lastFunction))
+ {
+ m_lastFunction = functionName;
+
+ std::vectorvecMatches = Util::PosixRegex::GetMatchesFromRegex(functionName, "([^ \\(]+\\()");
+
+ if (vecMatches.size() > 1)
+ functionName = vecMatches[1] + ")";
+
+ m_fullStackTraceMessage.append(" -> ");
+ m_fullStackTraceMessage.append(functionName);
+
+ if (errorMsg.length() > 0)
+ {
+ m_fullStackTraceMessage.append(" - " + errorMsg);
+ m_message = errorMsg;
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+
+Exception &Exception::copy(const Exception &rhs)
+{
+ if (this == &rhs)
+ {
+ return *this;
+ }
+
+ m_message = rhs.m_message;
+ m_fullStackTraceMessage = rhs.m_fullStackTraceMessage;
+ m_lastFunction = rhs.m_lastFunction;
+
+ return *this;
+}
+
+//------------------------------------------------------------------------
+
+Exception::~Exception() throw()
+{
+}
diff --git a/CommonLib/src/Common/Exceptions/Exception.hpp b/CommonLib/src/Common/Exceptions/Exception.hpp
new file mode 100644
index 0000000..b4efc96
--- /dev/null
+++ b/CommonLib/src/Common/Exceptions/Exception.hpp
@@ -0,0 +1,106 @@
+#pragma once
+
+#include
+#include
+
+class Exception : public std::exception
+{
+public:
+ enum Message_Format
+ {
+ ERROR_MESSAGE_WITH_STACKTRACE, // entire stack trace
+ ERROR_MESSAGE_ONLY // the function that throw the exception
+ };
+
+ //>---------------------------------------------------------------------
+ // Function: Exception()
+ //
+ // Purpose: constructor
+ //----------------------------------------------------------------------
+ // Arguments:
+ // functionName - should use custom macro __FUNCTION_NAME__
+ // to get the name of offending function
+ // errorMsg - description of what caused the exception
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ Exception(const std::string functionName, const std::string& errorMsg, const std::string& exceptionClass = "");
+
+ //>---------------------------------------------------------------------
+ // Function: Exception()
+ //
+ // Purpose: copy constructor
+ // this gets called when "throw ex" executes rather than throw
+ // throw; throws the same exception object
+ // throw ex; throws a new exception
+ //----------------------------------------------------------------------
+ // Arguments: const Exception & - reference to Exception obj
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ Exception(const Exception &rhs);
+
+ //>---------------------------------------------------------------------
+ // Function: ~Exception()
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual ~Exception() throw();
+
+ //>---------------------------------------------------------------------
+ // Function: getMessage()
+ //
+ // Purpose: to get the message data member
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: std::string - the message string
+ //<---------------------------------------------------------------------
+ std::string getMessage(Message_Format msgFormat= ERROR_MESSAGE_WITH_STACKTRACE);
+
+ //>---------------------------------------------------------------------
+ // Function: buildStackTrace()
+ //
+ // Purpose: Build the stack trace of function calls for debugging purposes
+ //----------------------------------------------------------------------
+ // Arguments:
+ // functionName - should use custom macro __PRETTY_FUNCTION__
+ // to get the name of offending function
+ //
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ void buildStackTrace(std::string functionName, const std::string& errorMsg = "");
+
+protected:
+ std::string m_message;
+ std::string m_fullStackTraceMessage;
+ std::string m_lastFunction;
+
+private:
+ //>---------------------------------------------------------------------
+ // Function: operator&()
+ //
+ // Purpose: assignment operator
+ //----------------------------------------------------------------------
+ // Arguments: const Exception & - reference to Exception obj
+ //----------------------------------------------------------------------
+ // Return Value: reference to Exception obj
+ //<---------------------------------------------------------------------
+ Exception &operator=(const Exception &rhs);
+
+ //>---------------------------------------------------------------------
+ // Function: copy()
+ //
+ // Purpose: to do the work for assignment operator and copy ctor
+ //----------------------------------------------------------------------
+ // Arguments: const Exception &rhs - const reference to Exception obj
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ Exception ©(const Exception &rhs);
+};
diff --git a/CommonLib/src/Common/Exceptions/TimeoutError.cpp b/CommonLib/src/Common/Exceptions/TimeoutError.cpp
new file mode 100644
index 0000000..0ee4b2e
--- /dev/null
+++ b/CommonLib/src/Common/Exceptions/TimeoutError.cpp
@@ -0,0 +1,17 @@
+#include "TimeoutError.hpp"
+
+#include
+
+//------------------------------------------------------------------------
+
+TimeoutError::TimeoutError(std::string functionName, const std::string& errorMsg, TIME_OUT_TYPE timeOutType) :
+ Exception(functionName, errorMsg, std::string(typeid(this).name())),
+ m_timeOutType(timeOutType)
+{
+}
+
+//------------------------------------------------------------------------
+
+TimeoutError::~TimeoutError() throw()
+{
+}
diff --git a/CommonLib/src/Common/Exceptions/TimeoutError.hpp b/CommonLib/src/Common/Exceptions/TimeoutError.hpp
new file mode 100644
index 0000000..a164bcc
--- /dev/null
+++ b/CommonLib/src/Common/Exceptions/TimeoutError.hpp
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "Exception.hpp"
+
+class TimeoutError : public Exception
+{
+public:
+ enum TIME_OUT_TYPE
+ {
+ TIME_OUT_GENERIC,
+ TIME_OUT_SOCKET
+ };
+
+ //>---------------------------------------------------------------------
+ // Function: TimeoutError()
+ //
+ // Purpose: default and non-default constructor
+ //----------------------------------------------------------------------
+ // Arguments: std::string msg - a message to be printed
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ TimeoutError(std::string functionName, const std::string& errorMsg, TIME_OUT_TYPE timeOutType = TIME_OUT_GENERIC);
+
+ //>---------------------------------------------------------------------
+ // Function: ~TimeoutError()
+ //
+ // Purpose: destructor
+ //----------------------------------------------------------------------
+ // Arguments: none
+ //----------------------------------------------------------------------
+ // Return Value: none
+ //<---------------------------------------------------------------------
+ virtual ~TimeoutError() throw();
+
+ TIME_OUT_TYPE m_timeOutType;
+};
diff --git a/CommonLib/src/Common/Lib/Condition.cpp b/CommonLib/src/Common/Lib/Condition.cpp
new file mode 100644
index 0000000..b220f95
--- /dev/null
+++ b/CommonLib/src/Common/Lib/Condition.cpp
@@ -0,0 +1,333 @@
+#include
+#include
+#include
+#include "Condition.hpp"
+#include "Exception.hpp"
+#include "TimeoutError.hpp"
+
+Condition::Condition(const std::string& name) :
+ OSObject(name),
+ m_state(NOT_SIGNALED)
+{
+ try
+ {
+ pthread_condattr_t attr;
+ int ret = pthread_condattr_init(&attr);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_condattr_init returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ ret = pthread_cond_init(&m_condition, &attr);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_cond_init returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ pthread_mutexattr_t mutexAttr;
+ ret = pthread_mutexattr_init(&mutexAttr);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_mutexattr_init returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ ret = pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_mutexattr_settype returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ ret = pthread_mutex_init(&m_mutex, &mutexAttr);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_mutex_lock returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+}
+
+//------------------------------------------------------------------------
+
+Condition::~Condition()
+{
+ int ret = pthread_cond_destroy(&m_condition);
+
+ if (ret != 0)
+ {
+ // it is being destroyed, nothing to do
+ }
+}
+
+//------------------------------------------------------------------------
+
+void Condition::broadcast()
+{
+ try
+ {
+ lockMutex();
+
+ int ret = pthread_cond_broadcast(&m_condition);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_cond_broadcast returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ m_state = SIGNALED;
+
+ unlockMutex();
+ }
+ catch (Exception& e)
+ {
+ m_state = NOT_SIGNALED;
+
+ unlockMutex();
+
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+
+void Condition::lockMutex()
+{
+ int ret = pthread_mutex_lock(&m_mutex);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_mutex_lock returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+}
+
+//------------------------------------------------------------------------
+
+void Condition::reset()
+{
+ try
+ {
+ lockMutex();
+ m_state = NOT_SIGNALED;
+ unlockMutex();
+ }
+ catch (Exception& e)
+ {
+ unlockMutex();
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void Condition::signal()
+{
+ try
+ {
+ lockMutex();
+
+ m_state = SIGNALED;
+
+ int ret = pthread_cond_signal(&m_condition);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_cond_signal returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ unlockMutex();
+ }
+ catch (Exception& e)
+ {
+ m_state = NOT_SIGNALED;
+
+ unlockMutex();
+
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+bool Condition::timedWait(const unsigned long seconds, const unsigned long nanoseconds, bool shallWeReset)
+{
+ try
+ {
+ lockMutex();
+
+ // looping because pthread_cond_wait can return even if not signaled
+ while (m_state != SIGNALED)
+ {
+ timespec waitTime;
+ int status = 0;
+
+ if( ( 0 != seconds ) || ( 0 != nanoseconds ) )
+ {
+ status = clock_gettime(CLOCK_REALTIME , &waitTime);
+
+ if( 0 != status )
+ {
+ std::stringstream ss;
+ ss << "clock_gettime returned: " << status;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+ else
+ {
+ waitTime.tv_nsec += nanoseconds;
+
+ // check for more than one second's worth of nanoseconds
+ if( 999999999L < waitTime.tv_nsec )
+ {
+ waitTime.tv_nsec -= 1000000000L;
+ waitTime.tv_sec += 1;
+ }
+
+ waitTime.tv_sec += seconds;
+ }
+ }
+ else
+ {
+ waitTime.tv_sec = 0;
+ waitTime.tv_nsec = 0;
+ }
+
+ status = pthread_cond_timedwait(&m_condition, &m_mutex, &waitTime);
+
+ //@@@
+ /*if (status == TIMEDOUT)
+ {
+ std::stringstream ss;
+ ss << "Condition::TimedWait() - pthread_cond_timedwait returned: " << status;
+ throw TimeoutError(ss.str());
+ }*/
+ if(status != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_cond_timedwait returned: " << status;
+ throw TimeoutError(__PRETTY_FUNCTION__,ss.str());
+ }
+ }// end while
+
+ if (shallWeReset == true)
+ {
+ reset();
+ }
+
+ unlockMutex();
+
+ return true;
+ }
+ catch (TimeoutError& e)
+ {
+ if (shallWeReset == true)
+ {
+ reset();
+ }
+
+ unlockMutex();
+
+ return false;
+ }
+ catch (Exception& e)
+ {
+ if (shallWeReset == true)
+ {
+ reset();
+ }
+
+ unlockMutex();
+
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void Condition::unlockMutex()
+{
+ try
+ {
+ int ret = pthread_mutex_unlock(&m_mutex);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_mutex_unlock returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//------------------------------------------------------------------------
+
+void Condition::wait(bool shallWeReset)
+{
+ try
+ {
+ lockMutex();
+
+ // looping because pthread_cond_wait can return even if not signaled
+ while (m_state != SIGNALED)
+ {
+ int ret = pthread_cond_wait(&m_condition, &m_mutex);
+
+ if (ret != 0)
+ {
+ std::stringstream ss;
+ ss << "pthread_cond_wait returned: " << ret;
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+ }
+
+ if (shallWeReset == true)
+ {
+ reset();
+ }
+
+ unlockMutex();
+ }
+ catch (Exception& e)
+ {
+ if (shallWeReset == true)
+ {
+ reset();
+ }
+
+ unlockMutex();
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
diff --git a/CommonLib/src/Common/Lib/Condition.hpp b/CommonLib/src/Common/Lib/Condition.hpp
new file mode 100644
index 0000000..1defe3e
--- /dev/null
+++ b/CommonLib/src/Common/Lib/Condition.hpp
@@ -0,0 +1,106 @@
+#pragma once
+
+#include
+#include "OSObject.hpp"
+
+class Condition : public OSObject
+{
+public:
+ enum State
+ {
+ NOT_SIGNALED,
+ SIGNALED
+ };
+
+ //>---------------------------------------------------------------------
+ // Function: Condition
+ //
+ // Purpose: The constructor
+ //----------------------------------------------------------------------
+ // Arguments: name - the name of the condition
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ Condition(const std::string& name);
+
+ //>---------------------------------------------------------------------
+ // Function: ~Condition
+ //
+ // Purpose: The destroyer
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ virtual ~Condition();
+
+ //>---------------------------------------------------------------------
+ // Function: Broadcast
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ void broadcast();
+
+ //>---------------------------------------------------------------------
+ // Function: Reset
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ void reset();
+
+ //>---------------------------------------------------------------------
+ // Function: Signal
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ void signal();
+
+ //>---------------------------------------------------------------------
+ // Function: TimedWait
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ bool timedWait(const unsigned long seconds, const unsigned long nanoseconds, bool shallWeReset = true);
+
+ //>---------------------------------------------------------------------
+ // Function: Wait
+ //
+ // Purpose:
+ //----------------------------------------------------------------------
+ // Arguments:
+ //----------------------------------------------------------------------
+ // Return Value:
+ //<---------------------------------------------------------------------
+ void wait(bool shallWeReset = true);
+
+private:
+ // dont allow
+ Condition(const Condition& rhs);
+ Condition& operator=(const Condition& rhs);
+
+ void lockMutex();
+
+ void unlockMutex();
+
+ pthread_cond_t m_condition;
+
+ pthread_mutex_t m_mutex;
+
+ State m_state;
+};
diff --git a/CommonLib/src/Common/Lib/Constants.hpp b/CommonLib/src/Common/Lib/Constants.hpp
new file mode 100644
index 0000000..8933f9d
--- /dev/null
+++ b/CommonLib/src/Common/Lib/Constants.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include
+
+namespace CommonLibConstants
+{
+ const unsigned int MAIL_BUFFER_SIZE = 512;
+ const unsigned int INFINITE = 0xFFFFFFFF;
+}
diff --git a/CommonLib/src/Common/Lib/ErrorLog.cpp b/CommonLib/src/Common/Lib/ErrorLog.cpp
new file mode 100644
index 0000000..0276a14
--- /dev/null
+++ b/CommonLib/src/Common/Lib/ErrorLog.cpp
@@ -0,0 +1,87 @@
+#include
+#include
+#include
+
+#include "ErrorLog.hpp"
+#include "Exception.hpp"
+#include "LockMutex.hpp"
+#include "Timestamp.hpp"
+
+//-----------------------------------------------------------------------------
+
+ErrorLog &ErrorLog::Instance(const std::string& filename)
+{
+ try
+ {
+ static ErrorLog fileAndConsoleWriter(filename);
+ return fileAndConsoleWriter;
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+ErrorLog::ErrorLog(const std::string& filename):
+ m_mutex("ErrorLog - Mutex")
+{
+ try
+ {
+ m_outlog.open(filename.c_str(), std::ios_base::app);
+ }
+ catch (Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw e;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+ErrorLog::~ErrorLog()
+{
+ m_outlog.close();
+}
+
+//-----------------------------------------------------------------------------
+
+void ErrorLog::log(const std::string& msg, const bool putToConsole, ErrorLog::LogLevel level)
+{
+ try
+ {
+ LockMutex lock(&m_mutex);
+
+ // build the string to log
+ std::stringstream msgToLogSs;
+
+ if (level == INFO)
+ {
+ msgToLogSs << "INFO, " << msg + "\n";
+ }
+ else
+ {
+ msgToLogSs << "ERROR, " << msg + "\n";
+ }
+
+ // log out data to console
+ if (putToConsole == true)
+ {
+ std::cout << msgToLogSs.str();
+ }
+
+ m_outlog << Timestamp::GetCurrentDateTimeString(Timestamp::DateTimeFormat::YYYYMMDD) << "_" << Timestamp::GetCurrentDateTimeString(Timestamp::DateTimeFormat::HHMMSSMM, "_") + "_" + msgToLogSs.str();
+
+ m_outlog.flush();
+ }
+ catch (...)
+ {
+ // if we cant log, just continue on
+ }
+}
+
+
+
+
diff --git a/CommonLib/src/Common/Lib/ErrorLog.hpp b/CommonLib/src/Common/Lib/ErrorLog.hpp
new file mode 100644
index 0000000..093ee6f
--- /dev/null
+++ b/CommonLib/src/Common/Lib/ErrorLog.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include "Mutex.hpp"
+
+class ErrorLog
+{
+public:
+ enum LogLevel
+ {
+ INFO,
+ ERROR
+ };
+
+ static ErrorLog &Instance(const std::string& filename = "");
+
+ ~ErrorLog();
+
+ void log(const std::string& msg, const bool putToConsole = true, LogLevel logLevel = ERROR);
+
+private:
+ // do not allow
+ ErrorLog(const ErrorLog& rhs);
+ ErrorLog& operator=(const ErrorLog& rhs);
+
+
+ ErrorLog(const std::string& filename);
+
+ std::string m_filename;
+ std::ofstream m_outlog;
+
+ Mutex m_mutex;
+};
+
+
+
diff --git a/CommonLib/src/Common/Lib/IniFile.cpp b/CommonLib/src/Common/Lib/IniFile.cpp
new file mode 100644
index 0000000..c994761
--- /dev/null
+++ b/CommonLib/src/Common/Lib/IniFile.cpp
@@ -0,0 +1,439 @@
+#include
+#include
+
+#include "IniFile.hpp"
+#include "Exception.hpp"
+#include "StringUtil.hpp"
+
+// INI-file delimiters
+static const char COMMENT_CHAR = '#';
+static const char KEY_VALUE_DELIMITER = '=';
+static const char SECTION_HDR_START_CHAR = '[';
+static const char SECTION_HDR_END_CHAR = ']';
+
+//------------------------------------------------------------------------
+
+IniFile::IniFile(const std::string& fileName)
+{
+ try
+ {
+ readFile(fileName);
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+IniFile::~IniFile()
+{
+}
+
+//------------------------------------------------------------------------
+
+void IniFile::addKeyValuePair(const std::string& section,
+ const std::string& key,
+ const std::string& value)
+{
+ configMap[section].insert(KeyValuePair(key, value));
+}
+
+//------------------------------------------------------------------------
+
+bool IniFile::getBool(const std::string& section ,
+ const std::string& key) const
+{
+ try
+ {
+ std::stringstream ss;
+
+ ss.str(Util::Strings::ToLower(getString(section , key)));
+ ss.setf(std::ios_base::boolalpha);
+ bool tmp;
+ ss >> tmp;
+
+ return tmp;
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+double IniFile::getDouble(const std::string& section,
+ const std::string& key) const
+{
+ try
+ {
+ std::stringstream ss;
+
+ ss.str(getString(section , key));
+ double tmp;
+ ss >> tmp;
+
+ return tmp;
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+void IniFile::getKeys(const std::string& section,
+ std::vector& keys) const
+{
+ try
+ {
+ keys.clear(); // empty list
+
+ // make sure section exists
+ SectionIter sectionIt = configMap.find(section);
+
+ if (sectionIt == configMap.end())
+ {
+ std::ostringstream oss;
+
+ oss << "section '" << section.c_str() << "' does not exist\n";
+
+ throw Exception(__PRETTY_FUNCTION__,oss.str());
+ }
+
+ // fill up vector with keys
+ for (KeyValueIter keyValueIt = sectionIt->second.begin();
+ keyValueIt != sectionIt->second.end();
+ ++keyValueIt)
+ {
+ keys.push_back(keyValueIt->first);
+ }
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+void IniFile::getKeyValue(const std::string& line,
+ std::string& key,
+ std::string& value) const
+{
+ try
+ {
+ size_t equalPos;
+
+ // everything to left of delimiter is key
+ equalPos = line.find(KEY_VALUE_DELIMITER);
+ key = line.substr(0 , equalPos);
+
+ // everything to right of delimiter is value (except possible comment)
+ value = line.substr(equalPos + 1);
+
+ size_t commentPos;
+ commentPos = value.find(COMMENT_CHAR);
+
+ if (commentPos != std::string::npos)
+ {
+ value = value.substr(0 , commentPos);
+ }
+
+ // trim leading/trailing spaces on key and value
+ key = Util::Strings::TrimSpaces(key);
+ value = Util::Strings::TrimSpaces(value);
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+IniFile::LineType IniFile::getLineType(const std::string& line) const
+{
+ try
+ {
+ // trim leading/trailing spaces
+ std::string tempLine = Util::Strings::TrimSpaces(line);
+
+ // blank line?
+ if (tempLine.length() == 0)
+ {
+ return BLANK_LINE;
+ }
+
+ // commment?
+ if (tempLine[0] == COMMENT_CHAR)
+ {
+ return COMMENT;
+ }
+
+ // section header?
+ if (tempLine[0] == SECTION_HDR_START_CHAR)
+ {
+ // check for end of section header
+ if (tempLine.find(SECTION_HDR_END_CHAR) != std::string::npos)
+ {
+ return SECTION_HEADER;
+ }
+ else // starts out as a section header, but no end char
+ {
+ return BAD_LINE;
+ }
+ }
+
+ // Assume everything else is a key/value pair.
+ // Previously checked for "=" and returned BAD_LINE if it didn't exist.
+ // However, this did not allow for keys with no values.
+ return KEY_VALUE_PAIR;
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+int IniFile::getInt(const std::string& section, const std::string& key) const
+{
+ try
+ {
+ std::stringstream ss;
+
+ ss.str(getString(section , key));
+ int tmp = 0;
+ ss >> tmp;
+
+ return tmp;
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+unsigned int IniFile::getUint(const std::string& section,
+ const std::string& key,
+ bool isHexString) const
+{
+ try
+ {
+ std::stringstream ss;
+
+ unsigned int tmp = 0;
+
+ if (isHexString == false)
+ {
+ std::string iniVal = getString(section , key);
+ ss << iniVal;
+ ss >> tmp;
+ }
+ else
+ {
+ std::string iniVal = getString(section , key);
+ ss << std::hex << iniVal;
+ ss >> tmp;
+ }
+
+ return tmp;
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+std::string IniFile::getString(const std::string& section,
+ const std::string& key) const
+{
+ try
+ {
+ // make sure section exists
+ SectionIter sectionIt = configMap.find(section);
+
+ if (sectionIt == configMap.end())
+ {
+ std::stringstream ss;
+ ss << "section '" << section << "' does not exist";
+ throw Exception(__PRETTY_FUNCTION__,ss.str());
+ }
+
+ // make sure key exists
+ KeyValueIter keyValueIt = sectionIt->second.find(key);
+
+ if (keyValueIt == sectionIt->second.end())
+ {
+ std::ostringstream oss;
+
+ oss << "key '" << key << "' does not exist";
+
+ throw Exception(__PRETTY_FUNCTION__,oss.str());
+ }
+
+ return keyValueIt->second;
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
+
+bool IniFile::isSection(const std::string& section) const
+{
+ return configMap.find(section) != configMap.end();
+}
+
+//------------------------------------------------------------------------
+
+void IniFile::readFile(const std::string& fileName)
+{
+ try
+ {
+ // open file
+ std::ifstream cfgStream(fileName.c_str());
+
+ if (cfgStream.fail())
+ {
+ std::string s = "could not open file: " + fileName;
+ throw Exception(__PRETTY_FUNCTION__,s);
+ }
+
+ // read line-by-line
+ // - skip comments, blank lines
+ // - save last section name
+ // - add key/value pairs as ecnountered
+ std::string section;
+ bool bHaveSection = false;
+
+ while (!cfgStream.eof())
+ {
+ std::string line = "";
+
+ std::getline(cfgStream, line);
+
+ if(line != "")
+ {
+ char lastChar = line[line.length() - 1];
+
+ if(lastChar == '\r')
+ {
+ line = line.substr(0, line.length() - 1);
+ }
+ }
+
+ LineType lineType = getLineType(line);
+
+ switch (lineType)
+ {
+ case BLANK_LINE:
+ case COMMENT:
+ // do nothing
+ break;
+
+ case SECTION_HEADER:
+ {
+ // save section
+ size_t first = line.find_first_of('[');
+ size_t last = line.find_first_of(']');
+ section = line.substr(first + 1 , last - first - 1);
+
+ bHaveSection = true;
+ }
+ break;
+
+ case KEY_VALUE_PAIR:
+ if (bHaveSection)
+ {
+ // add to map
+ std::string key;
+ std::string value;
+ getKeyValue(line , key , value);
+
+ addKeyValuePair(section, key, value);
+ }
+ else
+ {
+ throw Exception(__PRETTY_FUNCTION__,"key/value pair before section");
+ }
+
+ break;
+
+ case BAD_LINE:
+ std::string errMsg;
+
+ errMsg = "bad line: '" + line + "'";
+
+ throw Exception(__PRETTY_FUNCTION__,errMsg.c_str());
+ }
+ }
+ }
+ catch(Exception& e)
+ {
+ e.buildStackTrace(__PRETTY_FUNCTION__);
+ throw;
+ }
+ catch(...)
+ {
+ throw Exception(__PRETTY_FUNCTION__,"caught unknown error");
+ }
+}
+
+//------------------------------------------------------------------------
diff --git a/CommonLib/src/Common/Lib/IniFile.hpp b/CommonLib/src/Common/Lib/IniFile.hpp
new file mode 100644
index 0000000..010ff0d
--- /dev/null
+++ b/CommonLib/src/Common/Lib/IniFile.hpp
@@ -0,0 +1,224 @@
+#pragma once
+
+#include