-
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.
Abstracting IO Processor into its own class
- Loading branch information
Showing
10 changed files
with
111 additions
and
52 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
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,22 @@ | ||
<?xml version = "1.0"?> | ||
<algorithm> | ||
<name>TestAlgo</name> | ||
<type>Breadcrumbs</type> | ||
<logger> | ||
<level>4</level> | ||
</logger> | ||
</algorithm> | ||
<io_processor> | ||
<name>VirtualInputProcessor0</name> | ||
<type>VirtualInputProcessor</type> | ||
<logger> | ||
<level>2</level> | ||
</logger> | ||
</io_processor> | ||
<io_processor> | ||
<name>VirtualOutputProcessor0</name> | ||
<type>VirtualOutputProcessor</type> | ||
<logger> | ||
<level>1</level> | ||
</logger> | ||
</io_processor> |
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,18 @@ | ||
#ifndef VIRTUAL_OUTPUT_IO_PROCESSOR_HPP | ||
#define VIRTUAL_OUTPUT_IO_PROCESSOR_HPP | ||
|
||
#include "IOProcessor.hpp" | ||
|
||
class VirtualOutputIOProcessor : public IOProcessor | ||
{ | ||
public: | ||
using IOProcessor::IOProcessor; | ||
|
||
void loop(); | ||
bool loopCondition(); | ||
|
||
private: | ||
int iterations = 10; | ||
}; | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
|
||
#include "IOProcessor.hpp" | ||
|
||
|
||
IOProcessor::IOProcessor() | ||
{ | ||
comms = new DataSyncThread(NULL); | ||
} | ||
|
||
IOProcessor::~IOProcessor() | ||
{ | ||
delete comms; | ||
} | ||
|
||
int IOProcessor::init() | ||
{ | ||
int result = comms->connectToAlgorithm("localhost"); | ||
if (!result) | ||
comms->startComms(); | ||
return result; | ||
} | ||
|
||
int IOProcessor::close() | ||
{ | ||
int result = static_cast<int>(comms->stopComms()); | ||
WSACleanup(); | ||
return result; | ||
} |
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,16 @@ | ||
|
||
#include "VirtualOutputIOProcessor.hpp" | ||
|
||
|
||
void VirtualOutputIOProcessor::loop() | ||
{ | ||
char testValue = 'a' + iterations; | ||
Attribute attrib("testKey1", 1, &testValue); | ||
getComms()->sendAttribute(attrib); | ||
iterations--; | ||
} | ||
|
||
bool VirtualOutputIOProcessor::loopCondition() | ||
{ | ||
return iterations > 0; | ||
} |
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,26 +1,23 @@ | ||
|
||
#include "DataSyncThread.hpp" | ||
#include <iostream> | ||
|
||
#include "DataSyncThread.hpp" | ||
#include "VirtualOutputIOProcessor.hpp" | ||
|
||
|
||
int main() | ||
{ | ||
DataSyncThread client(NULL); | ||
if (!client.connectToAlgorithm("localhost")) | ||
IOProcessor* client = new VirtualOutputIOProcessor; | ||
|
||
if (!client->init()) | ||
{ | ||
client.startComms(); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
char testValue = 'a' + i; | ||
Attribute attrib("testKey1", 1, &testValue); | ||
client.sendAttribute(attrib); | ||
} | ||
|
||
client.stopComms(); | ||
WSACleanup(); | ||
while (client->loopCondition()) | ||
client->loop(); | ||
|
||
return 0; | ||
int result = client->close(); | ||
delete client; | ||
return result; | ||
} | ||
|
||
return 1; | ||
} |