Skip to content

Commit

Permalink
Updating working branch with newest commit
Browse files Browse the repository at this point in the history
  • Loading branch information
grf14003 committed Dec 5, 2019
1 parent 94cc09c commit 0c24eb9
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 86 deletions.
6 changes: 4 additions & 2 deletions breadcrumbs/CMakeConfig.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// the configured options and settings for Tutorial

#define Tutorial_VERSION_MAJOR @Bfs_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Bfs_VERSION_MINOR@
#define VERSION_MAJOR @Bfs_VERSION_MAJOR@
#define VERSION_MINOR @Bfs_VERSION_MINOR@

#define ALGORITHM_SERVER_PORT @Bfs_ALGORITHM_SERVER_PORT@
2 changes: 2 additions & 0 deletions breadcrumbs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ message("Library directory: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
message("Header file directory: ${INCLUDES_DIRECTORY}")

# Configure a header file to pass some of the CMake settings to the source code
set (Bfs_ALGORITHM_SERVER_PORT \"27634\")

configure_file (
"${PROJECT_SOURCE_DIR}/CMakeConfig.h.in"
"${CMAKE_INCLUDE_PATH}/CMakeConfig.h"
Expand Down
4 changes: 2 additions & 2 deletions breadcrumbs/include/AlgoBreadcrumbs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class AlgoBreadcrumbs : public Algorithm
public:
using Algorithm::Algorithm;

VOID loop();
BOOLEAN loopCondition();
void loop();
bool loopCondition();
private:
INT iterations = 1;
};
Expand Down
36 changes: 4 additions & 32 deletions breadcrumbs/include/Algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,19 @@
#ifndef ALGORITHM_HPP
#define ALGORITHM_HPP

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>

#include "DataSyncThread.hpp"

// Need to link with Ws2_32.lib
#pragma comment (lib, "Ws2_32.lib")

#define DEFAULT_PORT 10101
#include "AlgorithmServer.hpp"

class Algorithm
{
public:
explicit Algorithm(size_t numProcs);
~Algorithm();

virtual void loop() = 0;
virtual bool loopCondition() { return false; };

void serverThreadRuntime();
static DWORD serverThreadInit(LPVOID pThreadArgs)
{
Algorithm* pAlgorithmThread = (Algorithm*)pThreadArgs;
pAlgorithmThread->serverThreadRuntime();
return NULL;
}

// Updates Algorithm key/value store with IO key/value updates
void pollForUpdates();
private:
HANDLE hThread;
DWORD dwThreadId;
bool continueThread = false;

size_t numIO;
std::vector<DataSyncThread> ioComms;

void startServer();
size_t numIoProcs = 0;
AlgorithmServer* server;
};

#endif
46 changes: 46 additions & 0 deletions breadcrumbs/include/AlgorithmServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,52 @@
#ifndef ALGORITHM_SERVER_HPP
#define ALGORITHM_SERVER_HPP


#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>

#include "CMakeConfig.h"
#include "DataSyncThread.hpp"

#define ALGORITHM_PORT "10101"
#define MAX_ACCEPT_FAILURES 5

#pragma comment (lib, "Ws2_32.lib")

class AlgorithmServer
{
public:
AlgorithmServer(size_t numClients);
~AlgorithmServer();

void serverThreadRuntime();
static DWORD serverThreadInit(LPVOID pThreadArgs)
{
AlgorithmServer* pAlgorithmServerThread = (AlgorithmServer*)pThreadArgs;
pAlgorithmServerThread->serverThreadRuntime();
return NULL;
}

// Updates Algorithm key/value store with IO key/value updates
void pollForUpdates();
void startServer();
void stopServer();

private:
HANDLE hThread;
DWORD dwThreadId;
bool continueThread = false;

size_t numClients;
std::vector<DataSyncThread> clientThreads;
};

#endif
6 changes: 4 additions & 2 deletions breadcrumbs/include/CMakeConfig.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// the configured options and settings for Tutorial

#define Tutorial_VERSION_MAJOR 1
#define Tutorial_VERSION_MINOR 0
#define VERSION_MAJOR 1
#define VERSION_MINOR 0

#define ALGORITHM_SERVER_PORT "27634"
4 changes: 3 additions & 1 deletion breadcrumbs/include/DataSyncThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#ifndef DATA_SYNC_THREAD_HPP
#define DATA_SYNC_THREAD_HPP

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>

#include "Attribute.hpp"
#include "AlgorithmServer.hpp"
#include "CMakeConfig.h"

// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
Expand Down
2 changes: 1 addition & 1 deletion breadcrumbs/include/VirtualOutputProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VirtualOutputProcessor : public IOProcessor
public:
using IOProcessor::IOProcessor;

VOID threadRuntime(IOProcessor* ioProc);
void threadRuntime(IOProcessor* ioProc);
};

#endif
8 changes: 1 addition & 7 deletions breadcrumbs/src/Breadcrumbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@

int main()
{
Algorithm* algorithm = new AlgoBreadcrumbs(NULL, 0, 1);
Algorithm* algorithm = new AlgoBreadcrumbs(1);

// Loop
while (algorithm->loopCondition())
{
algorithm->pollInputs();
algorithm->loop();
algorithm->pollOutputs();
}

// Cleanup
processor->waitForThread();
delete processor;

return 0;
}
4 changes: 2 additions & 2 deletions breadcrumbs/src/algos/AlgoBreadcrumbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#include "AlgoBreadcrumbs.hpp"


VOID AlgoBreadcrumbs::loop()
void AlgoBreadcrumbs::loop()
{
printf("Breadcrumbs algorithm loop!\n");
}

BOOLEAN AlgoBreadcrumbs::loopCondition()
bool AlgoBreadcrumbs::loopCondition()
{
return --iterations >= 0;
}
37 changes: 5 additions & 32 deletions breadcrumbs/src/algos/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,14 @@
#include "Algorithm.hpp"

Algorithm::Algorithm(size_t numProcs)
{
numIO = numProcs;
ioComms.reserve(numIO);

startServer();
}

void Algorithm::pollForUpdates()
{
/*
Polls DataSyncThreads for new updates
Updates master storage accordingly
*/
for (DataSyncThread dst : ioComms)
{
// TODO: Implement this!
}
}
numIoProcs = numProcs;
server = new AlgorithmServer(numProcs);

void Algorithm::startServer()
{
/*
Starts the server socket thread
*/
continueThread = true;
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
serverThreadInit, // thread function name
this, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
server->startServer();
}

void Algorithm::serverThreadRuntime()
Algorithm::~Algorithm()
{

delete server;
}
Loading

0 comments on commit 0c24eb9

Please sign in to comment.