-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First draft adding client code, skeleton of server code. * Updating working branch with newest commit
- Loading branch information
Showing
18 changed files
with
482 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
#ifndef ATTRIBUTE_HPP | ||
#define ATTRIBUTE_HPP | ||
|
||
typedef struct BinaryAttributeStructure { | ||
char key[8]; | ||
unsigned char length[2]; | ||
} bAttrib; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
#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 "CMakeConfig.h" | ||
|
||
// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib | ||
#pragma comment (lib, "Ws2_32.lib") | ||
#pragma comment (lib, "Mswsock.lib") | ||
#pragma comment (lib, "AdvApi32.lib") | ||
|
||
/* | ||
This class contains the thread for communicating back and forth along a socket to sync attributes | ||
*/ | ||
class DataSyncThread | ||
{ | ||
private: | ||
SOCKET sock; | ||
HANDLE hThread; | ||
DWORD dwThreadId; | ||
bool continueThread = false; | ||
public: | ||
DataSyncThread(SOCKET s) { sock = s; }; | ||
|
||
// Synchronous functions | ||
void threadRuntime(); | ||
static DWORD threadInit(LPVOID pThreadArgs) | ||
{ | ||
DataSyncThread* pDataSyncThread = (DataSyncThread*)pThreadArgs; | ||
pDataSyncThread->threadRuntime(); | ||
return NULL; | ||
} | ||
int recvBytes(void* buffer, size_t numBytes); | ||
|
||
// Async control | ||
void startComms(); | ||
bool stopComms(); | ||
int connectToAlgorithm(char* serverName); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
import os | ||
import multiprocessing as mp | ||
import subprocess | ||
|
||
|
||
def start_program(command): | ||
cmd_list = command.split(" ") | ||
return subprocess.call(cmd_list) | ||
|
||
|
||
def start_program_no_hang(command): | ||
print("Running %s from cwd %s" % (command, os.getcwd())) | ||
proc = mp.Process(target=start_program, args=(command,)) | ||
proc.start() | ||
return proc | ||
|
||
|
||
def main(): | ||
start_program_no_hang("start cmd.exe /k \"..\\bin\\Breadcrumbs.exe\"") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,15 @@ | ||
|
||
#include "Algorithm.hpp" | ||
|
||
Algorithm::Algorithm(IOProcessor* ins, SIZE_T numIns, IOProcessor* outs, SIZE_T numOuts) | ||
{ | ||
numInputs = numIns; numOutputs = numOuts; | ||
inputs = ins; outputs = outs; | ||
} | ||
|
||
VOID Algorithm::startIOProcessors() | ||
{ | ||
int i; | ||
for (i = 0; i < numInputs; i++) | ||
(inputs + i)->startThread(); | ||
for (i = 0; i < numOutputs; i++) | ||
(outputs + i)->startThread(); | ||
} | ||
|
||
VOID Algorithm::waitForIOProcessors() | ||
{ | ||
int i; | ||
for (i = 0; i < numInputs; i++) | ||
(inputs + i)->waitForThread(); | ||
for (i = 0; i < numOutputs; i++) | ||
(outputs + i)->waitForThread(); | ||
} | ||
|
||
VOID Algorithm::stopIOProcessors() | ||
{ | ||
waitForIOProcessors(); | ||
} | ||
|
||
VOID Algorithm::pollInputs() | ||
Algorithm::Algorithm(size_t numProcs) | ||
{ | ||
numIoProcs = numProcs; | ||
server = new AlgorithmServer(numProcs); | ||
|
||
server->startServer(); | ||
} | ||
|
||
VOID Algorithm::pollOutputs() | ||
Algorithm::~Algorithm() | ||
{ | ||
|
||
delete server; | ||
} |
Oops, something went wrong.