
6 changed files with 137 additions and 73 deletions
@ -1,59 +1,59 @@ |
|||||
#include "../src/PityUnit.hh" |
#include "../src/PityUnit.hh" |
||||
|
#include "../src/PityModel.hh" |
||||
#include "../../../src/std_utils.hh" |
#include "../../../src/std_utils.hh" |
||||
#include <iostream> |
|
||||
#include <fstream> |
|
||||
#include <algorithm> |
|
||||
|
|
||||
using namespace std; |
|
||||
using namespace pEp; |
using namespace pEp; |
||||
|
using namespace pEp::Adapter; |
||||
using namespace pEp::PityTest11; |
using namespace pEp::PityTest11; |
||||
|
|
||||
void send(const PityUnit<>& myself) |
void test_node1(const PityUnit<PityModel>& unit) |
||||
{ |
{ |
||||
setenv("HOME", myself.processDir().c_str(), 1); |
unit.log("ModelName:" + unit.getModel()->getName()); |
||||
myself.log("HOME=" + string(getenv("HOME"))); |
unit.log("own_node:" + unit.getModel()->own_node->getName()); |
||||
ofstream msgfile = Utils::file_create(myself.processDir() + "/transport.msg"); |
unit.log("partner:" + unit.getModel()->own_node->partner); |
||||
msgfile << "G4rbage" << endl; |
unit.log("peers:\n" + Utils::to_string(unit.getModel()->own_node->peers)); |
||||
msgfile.close(); |
|
||||
Utils::sleep_millis(400000); |
std::string msg = "Message from: " + unit.getPathShort(); |
||||
} |
int throttle = 2000; |
||||
|
while (true) { |
||||
void receive(const PityUnit<>& myself) |
Utils::sleep_millis(throttle); |
||||
{ |
for (auto peer : unit.getModel()->own_node->peers) { |
||||
setenv("HOME", myself.processDir().c_str(), 1); |
unit.log("sending to:" + peer); |
||||
myself.log("HOME=" + string(getenv("HOME"))); |
unit.getModel()->sendMsg(peer, msg); |
||||
// Utils::dir_list_files()
|
Utils::sleep_millis(throttle); |
||||
Utils::sleep_millis(400000); |
} |
||||
|
|
||||
|
while (unit.getModel()->hasMsg()) { |
||||
|
unit.log("MSG RX:" + unit.getModel()->receiveMsg()); |
||||
|
Utils::sleep_millis(throttle); |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
|
|
||||
int main(int argc, char* argv[]) |
int main(int argc, char* argv[]) |
||||
{ |
{ |
||||
|
// debug log per class
|
||||
|
PityModel::debug_log_enabled = false; |
||||
|
PityNode::debug_log_enabled = false; |
||||
PityUnit<>::debug_log_enabled = false; |
PityUnit<>::debug_log_enabled = false; |
||||
PityUnit<> root = PityUnit<>{ nullptr, "test_transport" }; |
|
||||
|
|
||||
// 1
|
|
||||
PityUnit<> node1 = PityUnit<>{ &root, |
|
||||
"node 1", |
|
||||
[](const PityUnit<>& mynode) { |
|
||||
|
|
||||
}, |
|
||||
nullptr, |
|
||||
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL }; |
|
||||
|
|
||||
PityUnit<> node1_send = PityUnit<>{ &node1, "send", &send }; |
|
||||
|
|
||||
|
|
||||
// 2
|
|
||||
PityUnit<> node2 = PityUnit<>{ &root, |
|
||||
"node 2", |
|
||||
[](const PityUnit<>& mynode) { |
|
||||
|
|
||||
}, |
|
||||
nullptr, |
|
||||
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL }; |
|
||||
|
|
||||
PityUnit<> node2_receive = PityUnit<>{ &node2, "receive", &receive }; |
|
||||
|
|
||||
// root._init();
|
// Create model with 3 nodes
|
||||
root.run(); |
PityModel model{ "test_transport", 3 }; |
||||
|
|
||||
|
// //Configure model
|
||||
|
// model.nodeNr(0)->partner = model.nodeNr(1)->getName();
|
||||
|
// model.nodeNr(1)->partner = model.nodeNr(2)->getName();
|
||||
|
// model.nodeNr(2)->partner = model.nodeNr(0)->getName();
|
||||
|
|
||||
|
PityUnit<PityModel> node1_test1 = PityUnit<PityModel>{ model.unitOfNodeNr(0), |
||||
|
"test1", |
||||
|
&test_node1 }; |
||||
|
PityUnit<PityModel> node2_test1 = PityUnit<PityModel>{ model.unitOfNodeNr(1), |
||||
|
"test1", |
||||
|
&test_node1 }; |
||||
|
PityUnit<PityModel> node3_test1 = PityUnit<PityModel>{ model.unitOfNodeNr(2), |
||||
|
"test1", |
||||
|
&test_node1 }; |
||||
|
|
||||
|
model.run(); |
||||
} |
} |
Loading…
Reference in new issue