Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding simple processor thread interface (#8)
* Adding simple sensor thread interface

* Adding simple style guides (#7)

* Adding simple style guides

* Update style.hpp

* [Broken]: For Display purposes only

* IO Processor interface

* Adding cpp file for IOProc and moving to includes

* Adding simple sensor thread interface

* [Broken]: For Display purposes only

* IO Processor interface

* Adding cpp file for IOProc and moving to includes

* Fixing include gaurds

* Removing unnecessary spaces in cmakelists
  • Loading branch information
grf14003 committed Nov 4, 2019
1 parent 46cfff0 commit af68184
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 4 deletions.
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})
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

0 comments on commit af68184

Please sign in to comment.