Skip to content

Adding simple processor thread interface #8

Merged
merged 12 commits into from Nov 4, 2019
11 changes: 8 additions & 3 deletions breadcrumbs/CMakeLists.txt
Expand Up @@ -30,11 +30,16 @@ 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
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})
20 changes: 20 additions & 0 deletions 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
}
30 changes: 30 additions & 0 deletions 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;
};
40 changes: 40 additions & 0 deletions breadcrumbs/include/IOProcessor.hpp
@@ -0,0 +1,40 @@
/*
*
* Stores the interface for building a sensor thread
* implementation.
*
*/


#ifndef SENSOR_INTERFACE_HPP
#define SENSOR_INTERFACE_HPP


#include <stdio.h>
#include <Windows.h>


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
12 changes: 11 additions & 1 deletion breadcrumbs/src/Breadcrumbs.cpp
@@ -1,7 +1,17 @@
#include <stdio.h>

#include "io/out_procs/VirtualOutputProcessor.hpp"


int main() {
printf("Hello world!\n");

int threadID = 0;
IOProcessor *processor;
processor = new VirtualOutputProcessor();
processor->startThread(&threadID);

processor->waitForThread();
delete processor;

return 0;
}
43 changes: 43 additions & 0 deletions 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)
{

}
8 changes: 8 additions & 0 deletions breadcrumbs/src/io/out_procs/VirtualOutputProcessor.cpp
@@ -0,0 +1,8 @@

#include "VirtualOutputProcessor.hpp"


void VirtualOutputProcessor::threadRuntime()
{
printf("VirtualOutputProcessor %d started.\n", *((int*) threadArgs));
}
17 changes: 17 additions & 0 deletions breadcrumbs/src/io/out_procs/VirtualOutputProcessor.hpp
@@ -0,0 +1,17 @@

#ifndef VIRTUAL_OUTPUT_PROCESSOR_HPP
#define VIRTUAL_OUTPUT_PROCESSOR_HPP


#include <stdio.h>

#include "IOProcessor.hpp"


class VirtualOutputProcessor : public IOProcessor
{
public:
void threadRuntime();
};

#endif