From 041d9d131f1980ffb91da6e8f9cf522950373ea1 Mon Sep 17 00:00:00 2001 From: gregfoss Date: Sat, 19 Oct 2019 17:20:14 -0400 Subject: [PATCH 01/11] Adding simple sensor thread interface --- breadcrumbs/src/io/SensorInterface.cpp | 18 ++++++++++++++++++ breadcrumbs/src/io/SensorInterface.hpp | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 breadcrumbs/src/io/SensorInterface.cpp create mode 100644 breadcrumbs/src/io/SensorInterface.hpp diff --git a/breadcrumbs/src/io/SensorInterface.cpp b/breadcrumbs/src/io/SensorInterface.cpp new file mode 100644 index 0000000..f0f0e03 --- /dev/null +++ b/breadcrumbs/src/io/SensorInterface.cpp @@ -0,0 +1,18 @@ + +#include "SensorInterface.hpp" + + +int SensorThread::startThread() +{ + +} + +int SensorThread::stopThread() +{ + +} + +size_t SensorThread::getNewData(char* dataBuffer) +{ + +} diff --git a/breadcrumbs/src/io/SensorInterface.hpp b/breadcrumbs/src/io/SensorInterface.hpp new file mode 100644 index 0000000..7433d82 --- /dev/null +++ b/breadcrumbs/src/io/SensorInterface.hpp @@ -0,0 +1,22 @@ +/* + +Stores the interface for building a sensor thread +implementation. + +*/ + + +class SensorThread +{ +public: + SensorThread(void* targs) { implementationData = targs }; + int startThread(); + int stopThread(); + void* threadRuntime(void* targs) = 0; + int execute_command(char* command) = 0; + size_t getNewData(char* dataBuffer); +private: + char* ab_dataBuffer; + size_t ui_dataBufferSize; + void* implementationData; +}; From 46cfff0b605a4817e1f68f3e3af7a452d7661c46 Mon Sep 17 00:00:00 2001 From: Gregory M Foss Date: Mon, 21 Oct 2019 11:49:07 -0400 Subject: [PATCH 02/11] Adding simple style guides (#7) * Adding simple style guides * Update style.hpp --- breadcrumbs/doc/style/style.cpp | 20 ++++++++++++++++++++ breadcrumbs/doc/style/style.hpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 breadcrumbs/doc/style/style.cpp create mode 100644 breadcrumbs/doc/style/style.hpp diff --git a/breadcrumbs/doc/style/style.cpp b/breadcrumbs/doc/style/style.cpp new file mode 100644 index 0000000..26df8b9 --- /dev/null +++ b/breadcrumbs/doc/style/style.cpp @@ -0,0 +1,20 @@ +/* + +This file correspondes to style.hpp and is an example of +the .cpp files that would correspond to the .hpp file. + +*/ + + +#include "style.hpp" + + +char TestClass::attrTwoTimesTwo() +{ + return c_attrTwo << 1 +} + +int TestClass::getAttrSum() +{ + return c_attrTwo + i_attrOne +} diff --git a/breadcrumbs/doc/style/style.hpp b/breadcrumbs/doc/style/style.hpp new file mode 100644 index 0000000..a4b4c78 --- /dev/null +++ b/breadcrumbs/doc/style/style.hpp @@ -0,0 +1,30 @@ +/* + +This file contains the style of each programming construct +to use in this project. + +It should be followed to the letter! All spaces are +necessary! Make sure to take note of camel case and other +variable naming schemes! + +*/ + +// Header File: +class TestClass +{ +public: + // Constructors + TestClass(int AttrOne, char AttrTwo); + // Mutator methods + int getAttrSum(); + char attrTwoTimesTwo(); + void setAttrOne(int newAttrOne) { i_attrOne = newAttrOne } + void setAttrTwo(char newAttrTwo) { c_attrTwo = newAttrTwo } + // Accessor methods + int getAttrOne() { return i_attrOne } + char getAttrTwo() { return c_attrTwo } +private: + // Private variables + int i_attrOne = 0; + char c_attrTwo; +}; From 2bf62d70a04bf6a592594a130c77f687854de2b5 Mon Sep 17 00:00:00 2001 From: gregfoss Date: Thu, 31 Oct 2019 14:43:16 -0400 Subject: [PATCH 03/11] [Broken]: For Display purposes only --- breadcrumbs/src/Breadcrumbs.cpp | 21 ++++++- breadcrumbs/src/io/SensorInterface.cpp | 18 ------ breadcrumbs/src/io/SensorInterface.hpp | 57 ++++++++++++++----- .../io/out_procs/VirtualOutputProcessor.cpp | 8 +++ .../io/out_procs/VirtualOutputProcessor.hpp | 11 ++++ 5 files changed, 82 insertions(+), 33 deletions(-) delete mode 100644 breadcrumbs/src/io/SensorInterface.cpp create mode 100644 breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp create mode 100644 breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp diff --git a/breadcrumbs/src/Breadcrumbs.cpp b/breadcrumbs/src/Breadcrumbs.cpp index 8f4ffc9..61522c4 100644 --- a/breadcrumbs/src/Breadcrumbs.cpp +++ b/breadcrumbs/src/Breadcrumbs.cpp @@ -1,7 +1,26 @@ #include +#include "io/out_procs/VirtualOutputProcessor.hpp" + + +#define THREADS 5 + int main() { - printf("Hello world!\n"); + printf("Hello World!\n"); + + SensorThread* procs[THREADS]; + int targs[THREADS]; + + for (int i = 0; i < THREADS; i++) { + procs[i] = new VirtualOutputProcessor; + targs[i] = i + 1; + procs[i]->startThread(targs + i); + } + + for (int i = 0; i < THREADS; i++) { + procs[i]->waitForThread(); + delete procs[i]; + } return 0; } diff --git a/breadcrumbs/src/io/SensorInterface.cpp b/breadcrumbs/src/io/SensorInterface.cpp deleted file mode 100644 index f0f0e03..0000000 --- a/breadcrumbs/src/io/SensorInterface.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -#include "SensorInterface.hpp" - - -int SensorThread::startThread() -{ - -} - -int SensorThread::stopThread() -{ - -} - -size_t SensorThread::getNewData(char* dataBuffer) -{ - -} diff --git a/breadcrumbs/src/io/SensorInterface.hpp b/breadcrumbs/src/io/SensorInterface.hpp index 7433d82..a5478bf 100644 --- a/breadcrumbs/src/io/SensorInterface.hpp +++ b/breadcrumbs/src/io/SensorInterface.hpp @@ -1,22 +1,51 @@ /* + * + * Stores the interface for building a sensor thread + * implementation. + * + */ -Stores the interface for building a sensor thread -implementation. - -*/ +#include +#include class SensorThread { public: - SensorThread(void* targs) { implementationData = targs }; - int startThread(); - int stopThread(); - void* threadRuntime(void* targs) = 0; - int execute_command(char* command) = 0; - size_t getNewData(char* dataBuffer); -private: - char* ab_dataBuffer; - size_t ui_dataBufferSize; - void* implementationData; + + // Thread start 'caller' function + static DWORD __stdcall threadStart(LPVOID pUserData) { + ((SensorThread*) pUserData)->threadRuntime(); + return 0; + } + // Thread routine for implementation to override + virtual void threadRuntime() = 0; + + // Async control + UINT8 startThread(LPVOID targs)s + { + threadArgs = targs; + hThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + threadStart, // thread function name + this, // argument to thread function + 0, // use default creation flags + &dwThreadId); // returns the thread identifier + return TRUE; + }; + BOOL waitForThread() + { + WaitForSingleObject(hThread, INFINITE); + return TRUE; + }; + + // Sync control + BOOLEAN bufferDataAvailable() { return TRUE; }; + SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; + VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; +protected: + LPCVOID threadArgs; + DWORD dwThreadId; + HANDLE hThread; }; diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp new file mode 100644 index 0000000..1c78bdb --- /dev/null +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp @@ -0,0 +1,8 @@ + +#include "VirtualOutputProcessor.hpp" + + +void VirtualOutputProcessor::threadRuntime() +{ + printf("Hello from thread %d!\n", *((int*) threadArgs)); +} diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp new file mode 100644 index 0000000..4e283e6 --- /dev/null +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp @@ -0,0 +1,11 @@ + +#include + +#include "../SensorInterface.hpp" + + +class VirtualOutputProcessor : public SensorThread +{ +public: + virtual void threadRuntime(); +}; From 6973e6e9ade8f80cdfd6cff9a5a2453b23e1114a Mon Sep 17 00:00:00 2001 From: Greg Date: Sun, 3 Nov 2019 16:08:19 -0500 Subject: [PATCH 04/11] IO Processor interface --- breadcrumbs/CMakeLists.txt | 7 +- breadcrumbs/src/Breadcrumbs.cpp | 21 +--- .../{SensorInterface.hpp => IOProcessor.hpp} | 109 ++++++++++-------- .../io/out_procs/VirtualOutputProcessor.cpp | 2 +- .../io/out_procs/VirtualOutputProcessor.hpp | 11 +- 5 files changed, 79 insertions(+), 71 deletions(-) rename breadcrumbs/src/io/{SensorInterface.hpp => IOProcessor.hpp} (78%) diff --git a/breadcrumbs/CMakeLists.txt b/breadcrumbs/CMakeLists.txt index 611a3e7..2fb91de 100644 --- a/breadcrumbs/CMakeLists.txt +++ b/breadcrumbs/CMakeLists.txt @@ -35,6 +35,11 @@ configure_file ( include_directories("${CMAKE_INCLUDE_PATH}") # Adding private include files from source tree include_directories("${CMAKE_SOURCE_DIR}") + +# puts all .cpp files inside src to the SOURCES variable +# TODO: replace this with a script for collecting cpp files +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/*.cpp") +message("Source files: ${SOURCES}") # Adding executables -add_executable(Breadcrumbs ${CMAKE_SOURCE_DIR}/Breadcrumbs.cpp) +add_executable(Breadcrumbs ${SOURCES}) diff --git a/breadcrumbs/src/Breadcrumbs.cpp b/breadcrumbs/src/Breadcrumbs.cpp index 61522c4..4d360ac 100644 --- a/breadcrumbs/src/Breadcrumbs.cpp +++ b/breadcrumbs/src/Breadcrumbs.cpp @@ -3,24 +3,15 @@ #include "io/out_procs/VirtualOutputProcessor.hpp" -#define THREADS 5 - - int main() { - printf("Hello World!\n"); - SensorThread* procs[THREADS]; - int targs[THREADS]; + int threadID = 0; + IOProcessor *processor; + processor = new VirtualOutputProcessor(); + processor->startThread(&threadID); - for (int i = 0; i < THREADS; i++) { - procs[i] = new VirtualOutputProcessor; - targs[i] = i + 1; - procs[i]->startThread(targs + i); - } + processor->waitForThread(); + delete processor; - for (int i = 0; i < THREADS; i++) { - procs[i]->waitForThread(); - delete procs[i]; - } return 0; } diff --git a/breadcrumbs/src/io/SensorInterface.hpp b/breadcrumbs/src/io/IOProcessor.hpp similarity index 78% rename from breadcrumbs/src/io/SensorInterface.hpp rename to breadcrumbs/src/io/IOProcessor.hpp index a5478bf..b5ac2bb 100644 --- a/breadcrumbs/src/io/SensorInterface.hpp +++ b/breadcrumbs/src/io/IOProcessor.hpp @@ -1,51 +1,58 @@ -/* - * - * Stores the interface for building a sensor thread - * implementation. - * - */ - -#include -#include - - -class SensorThread -{ -public: - - // Thread start 'caller' function - static DWORD __stdcall threadStart(LPVOID pUserData) { - ((SensorThread*) pUserData)->threadRuntime(); - return 0; - } - // Thread routine for implementation to override - virtual void threadRuntime() = 0; - - // Async control - UINT8 startThread(LPVOID targs)s - { - threadArgs = targs; - hThread = CreateThread( - NULL, // default security attributes - 0, // use default stack size - threadStart, // thread function name - this, // argument to thread function - 0, // use default creation flags - &dwThreadId); // returns the thread identifier - return TRUE; - }; - BOOL waitForThread() - { - WaitForSingleObject(hThread, INFINITE); - return TRUE; - }; - - // Sync control - BOOLEAN bufferDataAvailable() { return TRUE; }; - SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; - VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; -protected: - LPCVOID threadArgs; - DWORD dwThreadId; - HANDLE hThread; -}; +/* + * + * Stores the interface for building a sensor thread + * implementation. + * + */ + +#ifndef SENSOR_INTERFACE +#define SENSOR_INTERFACE + + +#include +#include + + +class IOProcessor +{ +public: + // Thread routine for implementation to override + virtual VOID threadRuntime() = 0; + // Thread start 'caller' function + static DWORD __stdcall threadStart(LPVOID pUserData) + { + ((IOProcessor*) pUserData)->threadRuntime(); + return 0; + } + + // Async control + UINT8 startThread(LPVOID targs) + { + this->threadArgs = targs; + hThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + threadStart, // thread function name + this, // argument to thread function + 0, // use default creation flags + &dwThreadId); // returns the thread identifier + return TRUE; + }; + BOOL waitForThread() + { + WaitForSingleObject(hThread, INFINITE); + return TRUE; + }; + + // Sync control + BOOLEAN bufferDataAvailable() { return TRUE; }; + SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; + VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; +protected: + LPCVOID threadArgs; + DWORD dwThreadId; + HANDLE hThread; + +}; + +#endif diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp index 1c78bdb..8237789 100644 --- a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp @@ -4,5 +4,5 @@ void VirtualOutputProcessor::threadRuntime() { - printf("Hello from thread %d!\n", *((int*) threadArgs)); + printf("VirtualOutputProcessor %d started.\n", *((int*) threadArgs)); } diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp index 4e283e6..0fe587d 100644 --- a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp @@ -1,11 +1,16 @@ #include -#include "../SensorInterface.hpp" +#include "../IOProcessor.hpp" -class VirtualOutputProcessor : public SensorThread +#ifndef VIRTUAL_OUTPUT_PROCESSOR_H +#define VIRTUAL_OUTPUT_PROCESSOR_H + +class VirtualOutputProcessor : public IOProcessor { public: - virtual void threadRuntime(); + void threadRuntime(); }; + +#endif From 92c2a696712fddb4229f540688ff6fbb716fecdf Mon Sep 17 00:00:00 2001 From: gregfoss Date: Mon, 4 Nov 2019 16:13:48 -0500 Subject: [PATCH 05/11] Adding cpp file for IOProc and moving to includes --- breadcrumbs/include/IOProcessor.hpp | 39 +++++++++++++ breadcrumbs/src/io/IOProcessor.cpp | 43 ++++++++++++++ breadcrumbs/src/io/IOProcessor.hpp | 58 ------------------- .../io/out_procs/VirtualOutputProcessor.hpp | 2 +- 4 files changed, 83 insertions(+), 59 deletions(-) create mode 100644 breadcrumbs/include/IOProcessor.hpp create mode 100644 breadcrumbs/src/io/IOProcessor.cpp delete mode 100644 breadcrumbs/src/io/IOProcessor.hpp diff --git a/breadcrumbs/include/IOProcessor.hpp b/breadcrumbs/include/IOProcessor.hpp new file mode 100644 index 0000000..0fa5944 --- /dev/null +++ b/breadcrumbs/include/IOProcessor.hpp @@ -0,0 +1,39 @@ +/* + * + * Stores the interface for building a sensor thread + * implementation. + * + */ + +#ifndef SENSOR_INTERFACE_H +#define SENSOR_INTERFACE_H + + +#include +#include + + +class IOProcessor +{ +public: + // Thread routine for implementation to override + virtual VOID threadRuntime() = 0; + // Thread initialization, should not be called directly! + static DWORD threadInit(LPVOID pIOProcessor); + + // Async control + UINT8 startThread(LPVOID pThreadArgs); + BOOL waitForThread(); + + // Sync control + BOOLEAN bufferDataAvailable(); + SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray); + VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize); +protected: + LPCVOID threadArgs; + DWORD dwThreadId; + HANDLE hThread; + +}; + +#endif diff --git a/breadcrumbs/src/io/IOProcessor.cpp b/breadcrumbs/src/io/IOProcessor.cpp new file mode 100644 index 0000000..7693957 --- /dev/null +++ b/breadcrumbs/src/io/IOProcessor.cpp @@ -0,0 +1,43 @@ + +#include "IOProcessor.hpp" + + +DWORD IOProcessor::threadInit(LPVOID pIOProcessor) +{ + ((IOProcessor*) pIOProcessor)->threadRuntime(); + return 0; +} + +UINT8 IOProcessor::startThread(LPVOID pThreadArgs) +{ + this->threadArgs = pThreadArgs; + hThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + threadInit, // thread function name + this, // argument to thread function + 0, // use default creation flags + &dwThreadId); // returns the thread identifier + return TRUE; +} + +BOOL IOProcessor::waitForThread() +{ + WaitForSingleObject(hThread, INFINITE); + return TRUE; +} + +BOOLEAN bufferDataAvailable() +{ + return FALSE; +} + +SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) +{ + return 0; +} + +VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) +{ + +} diff --git a/breadcrumbs/src/io/IOProcessor.hpp b/breadcrumbs/src/io/IOProcessor.hpp deleted file mode 100644 index b5ac2bb..0000000 --- a/breadcrumbs/src/io/IOProcessor.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Stores the interface for building a sensor thread - * implementation. - * - */ - -#ifndef SENSOR_INTERFACE -#define SENSOR_INTERFACE - - -#include -#include - - -class IOProcessor -{ -public: - // Thread routine for implementation to override - virtual VOID threadRuntime() = 0; - // Thread start 'caller' function - static DWORD __stdcall threadStart(LPVOID pUserData) - { - ((IOProcessor*) pUserData)->threadRuntime(); - return 0; - } - - // Async control - UINT8 startThread(LPVOID targs) - { - this->threadArgs = targs; - hThread = CreateThread( - NULL, // default security attributes - 0, // use default stack size - threadStart, // thread function name - this, // argument to thread function - 0, // use default creation flags - &dwThreadId); // returns the thread identifier - return TRUE; - }; - BOOL waitForThread() - { - WaitForSingleObject(hThread, INFINITE); - return TRUE; - }; - - // Sync control - BOOLEAN bufferDataAvailable() { return TRUE; }; - SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; - VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; -protected: - LPCVOID threadArgs; - DWORD dwThreadId; - HANDLE hThread; - -}; - -#endif diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp index 0fe587d..b607d70 100644 --- a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp @@ -1,7 +1,7 @@ #include -#include "../IOProcessor.hpp" +#include "IOProcessor.hpp" #ifndef VIRTUAL_OUTPUT_PROCESSOR_H From 37bde2417e82eb769cbe02e33d67f9797f6ac510 Mon Sep 17 00:00:00 2001 From: gregfoss Date: Sat, 19 Oct 2019 17:20:14 -0400 Subject: [PATCH 06/11] Adding simple sensor thread interface --- breadcrumbs/src/io/SensorInterface.cpp | 18 ++++++++++++++++++ breadcrumbs/src/io/SensorInterface.hpp | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 breadcrumbs/src/io/SensorInterface.cpp create mode 100644 breadcrumbs/src/io/SensorInterface.hpp diff --git a/breadcrumbs/src/io/SensorInterface.cpp b/breadcrumbs/src/io/SensorInterface.cpp new file mode 100644 index 0000000..f0f0e03 --- /dev/null +++ b/breadcrumbs/src/io/SensorInterface.cpp @@ -0,0 +1,18 @@ + +#include "SensorInterface.hpp" + + +int SensorThread::startThread() +{ + +} + +int SensorThread::stopThread() +{ + +} + +size_t SensorThread::getNewData(char* dataBuffer) +{ + +} diff --git a/breadcrumbs/src/io/SensorInterface.hpp b/breadcrumbs/src/io/SensorInterface.hpp new file mode 100644 index 0000000..7433d82 --- /dev/null +++ b/breadcrumbs/src/io/SensorInterface.hpp @@ -0,0 +1,22 @@ +/* + +Stores the interface for building a sensor thread +implementation. + +*/ + + +class SensorThread +{ +public: + SensorThread(void* targs) { implementationData = targs }; + int startThread(); + int stopThread(); + void* threadRuntime(void* targs) = 0; + int execute_command(char* command) = 0; + size_t getNewData(char* dataBuffer); +private: + char* ab_dataBuffer; + size_t ui_dataBufferSize; + void* implementationData; +}; From b27b21239fe9c0027a166d8419fa3b690271ddb9 Mon Sep 17 00:00:00 2001 From: gregfoss Date: Thu, 31 Oct 2019 14:43:16 -0400 Subject: [PATCH 07/11] [Broken]: For Display purposes only --- breadcrumbs/src/Breadcrumbs.cpp | 21 ++++++- breadcrumbs/src/io/SensorInterface.cpp | 18 ------ breadcrumbs/src/io/SensorInterface.hpp | 57 ++++++++++++++----- .../io/out_procs/VirtualOutputProcessor.cpp | 8 +++ .../io/out_procs/VirtualOutputProcessor.hpp | 11 ++++ 5 files changed, 82 insertions(+), 33 deletions(-) delete mode 100644 breadcrumbs/src/io/SensorInterface.cpp create mode 100644 breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp create mode 100644 breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp diff --git a/breadcrumbs/src/Breadcrumbs.cpp b/breadcrumbs/src/Breadcrumbs.cpp index 8f4ffc9..61522c4 100644 --- a/breadcrumbs/src/Breadcrumbs.cpp +++ b/breadcrumbs/src/Breadcrumbs.cpp @@ -1,7 +1,26 @@ #include +#include "io/out_procs/VirtualOutputProcessor.hpp" + + +#define THREADS 5 + int main() { - printf("Hello world!\n"); + printf("Hello World!\n"); + + SensorThread* procs[THREADS]; + int targs[THREADS]; + + for (int i = 0; i < THREADS; i++) { + procs[i] = new VirtualOutputProcessor; + targs[i] = i + 1; + procs[i]->startThread(targs + i); + } + + for (int i = 0; i < THREADS; i++) { + procs[i]->waitForThread(); + delete procs[i]; + } return 0; } diff --git a/breadcrumbs/src/io/SensorInterface.cpp b/breadcrumbs/src/io/SensorInterface.cpp deleted file mode 100644 index f0f0e03..0000000 --- a/breadcrumbs/src/io/SensorInterface.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -#include "SensorInterface.hpp" - - -int SensorThread::startThread() -{ - -} - -int SensorThread::stopThread() -{ - -} - -size_t SensorThread::getNewData(char* dataBuffer) -{ - -} diff --git a/breadcrumbs/src/io/SensorInterface.hpp b/breadcrumbs/src/io/SensorInterface.hpp index 7433d82..a5478bf 100644 --- a/breadcrumbs/src/io/SensorInterface.hpp +++ b/breadcrumbs/src/io/SensorInterface.hpp @@ -1,22 +1,51 @@ /* + * + * Stores the interface for building a sensor thread + * implementation. + * + */ -Stores the interface for building a sensor thread -implementation. - -*/ +#include +#include class SensorThread { public: - SensorThread(void* targs) { implementationData = targs }; - int startThread(); - int stopThread(); - void* threadRuntime(void* targs) = 0; - int execute_command(char* command) = 0; - size_t getNewData(char* dataBuffer); -private: - char* ab_dataBuffer; - size_t ui_dataBufferSize; - void* implementationData; + + // Thread start 'caller' function + static DWORD __stdcall threadStart(LPVOID pUserData) { + ((SensorThread*) pUserData)->threadRuntime(); + return 0; + } + // Thread routine for implementation to override + virtual void threadRuntime() = 0; + + // Async control + UINT8 startThread(LPVOID targs)s + { + threadArgs = targs; + hThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + threadStart, // thread function name + this, // argument to thread function + 0, // use default creation flags + &dwThreadId); // returns the thread identifier + return TRUE; + }; + BOOL waitForThread() + { + WaitForSingleObject(hThread, INFINITE); + return TRUE; + }; + + // Sync control + BOOLEAN bufferDataAvailable() { return TRUE; }; + SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; + VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; +protected: + LPCVOID threadArgs; + DWORD dwThreadId; + HANDLE hThread; }; diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp new file mode 100644 index 0000000..1c78bdb --- /dev/null +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp @@ -0,0 +1,8 @@ + +#include "VirtualOutputProcessor.hpp" + + +void VirtualOutputProcessor::threadRuntime() +{ + printf("Hello from thread %d!\n", *((int*) threadArgs)); +} diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp new file mode 100644 index 0000000..4e283e6 --- /dev/null +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp @@ -0,0 +1,11 @@ + +#include + +#include "../SensorInterface.hpp" + + +class VirtualOutputProcessor : public SensorThread +{ +public: + virtual void threadRuntime(); +}; From 370348d6e3420a25d426b5df81c56955bef081d8 Mon Sep 17 00:00:00 2001 From: Greg Date: Sun, 3 Nov 2019 16:08:19 -0500 Subject: [PATCH 08/11] IO Processor interface --- breadcrumbs/CMakeLists.txt | 7 +- breadcrumbs/src/Breadcrumbs.cpp | 21 +--- .../{SensorInterface.hpp => IOProcessor.hpp} | 109 ++++++++++-------- .../io/out_procs/VirtualOutputProcessor.cpp | 2 +- .../io/out_procs/VirtualOutputProcessor.hpp | 11 +- 5 files changed, 79 insertions(+), 71 deletions(-) rename breadcrumbs/src/io/{SensorInterface.hpp => IOProcessor.hpp} (78%) diff --git a/breadcrumbs/CMakeLists.txt b/breadcrumbs/CMakeLists.txt index 611a3e7..2fb91de 100644 --- a/breadcrumbs/CMakeLists.txt +++ b/breadcrumbs/CMakeLists.txt @@ -35,6 +35,11 @@ configure_file ( include_directories("${CMAKE_INCLUDE_PATH}") # Adding private include files from source tree include_directories("${CMAKE_SOURCE_DIR}") + +# puts all .cpp files inside src to the SOURCES variable +# TODO: replace this with a script for collecting cpp files +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/*.cpp") +message("Source files: ${SOURCES}") # Adding executables -add_executable(Breadcrumbs ${CMAKE_SOURCE_DIR}/Breadcrumbs.cpp) +add_executable(Breadcrumbs ${SOURCES}) diff --git a/breadcrumbs/src/Breadcrumbs.cpp b/breadcrumbs/src/Breadcrumbs.cpp index 61522c4..4d360ac 100644 --- a/breadcrumbs/src/Breadcrumbs.cpp +++ b/breadcrumbs/src/Breadcrumbs.cpp @@ -3,24 +3,15 @@ #include "io/out_procs/VirtualOutputProcessor.hpp" -#define THREADS 5 - - int main() { - printf("Hello World!\n"); - SensorThread* procs[THREADS]; - int targs[THREADS]; + int threadID = 0; + IOProcessor *processor; + processor = new VirtualOutputProcessor(); + processor->startThread(&threadID); - for (int i = 0; i < THREADS; i++) { - procs[i] = new VirtualOutputProcessor; - targs[i] = i + 1; - procs[i]->startThread(targs + i); - } + processor->waitForThread(); + delete processor; - for (int i = 0; i < THREADS; i++) { - procs[i]->waitForThread(); - delete procs[i]; - } return 0; } diff --git a/breadcrumbs/src/io/SensorInterface.hpp b/breadcrumbs/src/io/IOProcessor.hpp similarity index 78% rename from breadcrumbs/src/io/SensorInterface.hpp rename to breadcrumbs/src/io/IOProcessor.hpp index a5478bf..b5ac2bb 100644 --- a/breadcrumbs/src/io/SensorInterface.hpp +++ b/breadcrumbs/src/io/IOProcessor.hpp @@ -1,51 +1,58 @@ -/* - * - * Stores the interface for building a sensor thread - * implementation. - * - */ - -#include -#include - - -class SensorThread -{ -public: - - // Thread start 'caller' function - static DWORD __stdcall threadStart(LPVOID pUserData) { - ((SensorThread*) pUserData)->threadRuntime(); - return 0; - } - // Thread routine for implementation to override - virtual void threadRuntime() = 0; - - // Async control - UINT8 startThread(LPVOID targs)s - { - threadArgs = targs; - hThread = CreateThread( - NULL, // default security attributes - 0, // use default stack size - threadStart, // thread function name - this, // argument to thread function - 0, // use default creation flags - &dwThreadId); // returns the thread identifier - return TRUE; - }; - BOOL waitForThread() - { - WaitForSingleObject(hThread, INFINITE); - return TRUE; - }; - - // Sync control - BOOLEAN bufferDataAvailable() { return TRUE; }; - SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; - VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; -protected: - LPCVOID threadArgs; - DWORD dwThreadId; - HANDLE hThread; -}; +/* + * + * Stores the interface for building a sensor thread + * implementation. + * + */ + +#ifndef SENSOR_INTERFACE +#define SENSOR_INTERFACE + + +#include +#include + + +class IOProcessor +{ +public: + // Thread routine for implementation to override + virtual VOID threadRuntime() = 0; + // Thread start 'caller' function + static DWORD __stdcall threadStart(LPVOID pUserData) + { + ((IOProcessor*) pUserData)->threadRuntime(); + return 0; + } + + // Async control + UINT8 startThread(LPVOID targs) + { + this->threadArgs = targs; + hThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + threadStart, // thread function name + this, // argument to thread function + 0, // use default creation flags + &dwThreadId); // returns the thread identifier + return TRUE; + }; + BOOL waitForThread() + { + WaitForSingleObject(hThread, INFINITE); + return TRUE; + }; + + // Sync control + BOOLEAN bufferDataAvailable() { return TRUE; }; + SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; + VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; +protected: + LPCVOID threadArgs; + DWORD dwThreadId; + HANDLE hThread; + +}; + +#endif diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp index 1c78bdb..8237789 100644 --- a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp @@ -4,5 +4,5 @@ void VirtualOutputProcessor::threadRuntime() { - printf("Hello from thread %d!\n", *((int*) threadArgs)); + printf("VirtualOutputProcessor %d started.\n", *((int*) threadArgs)); } diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp index 4e283e6..0fe587d 100644 --- a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp @@ -1,11 +1,16 @@ #include -#include "../SensorInterface.hpp" +#include "../IOProcessor.hpp" -class VirtualOutputProcessor : public SensorThread +#ifndef VIRTUAL_OUTPUT_PROCESSOR_H +#define VIRTUAL_OUTPUT_PROCESSOR_H + +class VirtualOutputProcessor : public IOProcessor { public: - virtual void threadRuntime(); + void threadRuntime(); }; + +#endif From 2d93da5954cb7c5ed72c8868d8b03df05d68cf8d Mon Sep 17 00:00:00 2001 From: gregfoss Date: Mon, 4 Nov 2019 16:13:48 -0500 Subject: [PATCH 09/11] Adding cpp file for IOProc and moving to includes --- breadcrumbs/include/IOProcessor.hpp | 39 +++++++++++++ breadcrumbs/src/io/IOProcessor.cpp | 43 ++++++++++++++ breadcrumbs/src/io/IOProcessor.hpp | 58 ------------------- .../io/out_procs/VirtualOutputProcessor.hpp | 2 +- 4 files changed, 83 insertions(+), 59 deletions(-) create mode 100644 breadcrumbs/include/IOProcessor.hpp create mode 100644 breadcrumbs/src/io/IOProcessor.cpp delete mode 100644 breadcrumbs/src/io/IOProcessor.hpp diff --git a/breadcrumbs/include/IOProcessor.hpp b/breadcrumbs/include/IOProcessor.hpp new file mode 100644 index 0000000..0fa5944 --- /dev/null +++ b/breadcrumbs/include/IOProcessor.hpp @@ -0,0 +1,39 @@ +/* + * + * Stores the interface for building a sensor thread + * implementation. + * + */ + +#ifndef SENSOR_INTERFACE_H +#define SENSOR_INTERFACE_H + + +#include +#include + + +class IOProcessor +{ +public: + // Thread routine for implementation to override + virtual VOID threadRuntime() = 0; + // Thread initialization, should not be called directly! + static DWORD threadInit(LPVOID pIOProcessor); + + // Async control + UINT8 startThread(LPVOID pThreadArgs); + BOOL waitForThread(); + + // Sync control + BOOLEAN bufferDataAvailable(); + SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray); + VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize); +protected: + LPCVOID threadArgs; + DWORD dwThreadId; + HANDLE hThread; + +}; + +#endif diff --git a/breadcrumbs/src/io/IOProcessor.cpp b/breadcrumbs/src/io/IOProcessor.cpp new file mode 100644 index 0000000..7693957 --- /dev/null +++ b/breadcrumbs/src/io/IOProcessor.cpp @@ -0,0 +1,43 @@ + +#include "IOProcessor.hpp" + + +DWORD IOProcessor::threadInit(LPVOID pIOProcessor) +{ + ((IOProcessor*) pIOProcessor)->threadRuntime(); + return 0; +} + +UINT8 IOProcessor::startThread(LPVOID pThreadArgs) +{ + this->threadArgs = pThreadArgs; + hThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + threadInit, // thread function name + this, // argument to thread function + 0, // use default creation flags + &dwThreadId); // returns the thread identifier + return TRUE; +} + +BOOL IOProcessor::waitForThread() +{ + WaitForSingleObject(hThread, INFINITE); + return TRUE; +} + +BOOLEAN bufferDataAvailable() +{ + return FALSE; +} + +SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) +{ + return 0; +} + +VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) +{ + +} diff --git a/breadcrumbs/src/io/IOProcessor.hpp b/breadcrumbs/src/io/IOProcessor.hpp deleted file mode 100644 index b5ac2bb..0000000 --- a/breadcrumbs/src/io/IOProcessor.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Stores the interface for building a sensor thread - * implementation. - * - */ - -#ifndef SENSOR_INTERFACE -#define SENSOR_INTERFACE - - -#include -#include - - -class IOProcessor -{ -public: - // Thread routine for implementation to override - virtual VOID threadRuntime() = 0; - // Thread start 'caller' function - static DWORD __stdcall threadStart(LPVOID pUserData) - { - ((IOProcessor*) pUserData)->threadRuntime(); - return 0; - } - - // Async control - UINT8 startThread(LPVOID targs) - { - this->threadArgs = targs; - hThread = CreateThread( - NULL, // default security attributes - 0, // use default stack size - threadStart, // thread function name - this, // argument to thread function - 0, // use default creation flags - &dwThreadId); // returns the thread identifier - return TRUE; - }; - BOOL waitForThread() - { - WaitForSingleObject(hThread, INFINITE); - return TRUE; - }; - - // Sync control - BOOLEAN bufferDataAvailable() { return TRUE; }; - SIZE_T getBufferData(LPCSTR* bufferKeyArray, LPCSTR* bufferValueArray) { return 0; }; - VOID setDataStoreValue(LPCSTR key, LPCVOID value, SIZE_T valueSize) {}; -protected: - LPCVOID threadArgs; - DWORD dwThreadId; - HANDLE hThread; - -}; - -#endif diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp index 0fe587d..b607d70 100644 --- a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp @@ -1,7 +1,7 @@ #include -#include "../IOProcessor.hpp" +#include "IOProcessor.hpp" #ifndef VIRTUAL_OUTPUT_PROCESSOR_H From 94f274aa0b1abbc6125b37209ffd8ad179ed724d Mon Sep 17 00:00:00 2001 From: gregfoss Date: Mon, 4 Nov 2019 16:21:21 -0500 Subject: [PATCH 10/11] Fixing include gaurds --- breadcrumbs/include/IOProcessor.hpp | 6 +++--- breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/breadcrumbs/include/IOProcessor.hpp b/breadcrumbs/include/IOProcessor.hpp index 0fa5944..8b2aed5 100644 --- a/breadcrumbs/include/IOProcessor.hpp +++ b/breadcrumbs/include/IOProcessor.hpp @@ -5,12 +5,12 @@ * */ -#ifndef SENSOR_INTERFACE_H -#define SENSOR_INTERFACE_H +#ifndef SENSOR_INTERFACE_HPP +#define SENSOR_INTERFACE_HPP -#include #include +#include class IOProcessor diff --git a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp index b607d70..d6423c6 100644 --- a/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp +++ b/breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp @@ -1,12 +1,14 @@ + +#ifndef VIRTUAL_OUTPUT_PROCESSOR_HPP +#define VIRTUAL_OUTPUT_PROCESSOR_HPP + + #include #include "IOProcessor.hpp" -#ifndef VIRTUAL_OUTPUT_PROCESSOR_H -#define VIRTUAL_OUTPUT_PROCESSOR_H - class VirtualOutputProcessor : public IOProcessor { public: From 06b550b5a24bfd1eb530e287b177c645d90686c3 Mon Sep 17 00:00:00 2001 From: gregfoss Date: Mon, 4 Nov 2019 16:30:46 -0500 Subject: [PATCH 11/11] Removing unnecessary spaces in cmakelists --- breadcrumbs/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/breadcrumbs/CMakeLists.txt b/breadcrumbs/CMakeLists.txt index 2fb91de..d214ccf 100644 --- a/breadcrumbs/CMakeLists.txt +++ b/breadcrumbs/CMakeLists.txt @@ -30,7 +30,7 @@ configure_file ( "${PROJECT_SOURCE_DIR}/CMakeConfig.h.in" "${CMAKE_INCLUDE_PATH}/CMakeConfig.h" ) - + # Adding public includes to include search path include_directories("${CMAKE_INCLUDE_PATH}") # Adding private include files from source tree @@ -40,6 +40,6 @@ include_directories("${CMAKE_SOURCE_DIR}") # TODO: replace this with a script for collecting cpp files file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/*.cpp") message("Source files: ${SOURCES}") - + # Adding executables add_executable(Breadcrumbs ${SOURCES})