|
|
@ -1,12 +1,12 @@ |
|
|
|
// // #define NUM_OF_RUNNERS 2
|
|
|
|
// // #define NUM_OF_RUNNERS 2
|
|
|
|
|
|
|
|
|
|
|
|
#include "../lib/asynco.hpp" |
|
|
|
#include "../lib/asynco.hpp" |
|
|
|
#include "../lib/event.hpp" |
|
|
|
#include "../lib/trigger.hpp" |
|
|
|
#include "../lib/filesystem.hpp" |
|
|
|
#include "../lib/filesystem.hpp" |
|
|
|
#include "../lib/timers.hpp" |
|
|
|
#include "../lib/timers.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using namespace marcelb::asynco; |
|
|
|
using namespace marcelb::asynco; |
|
|
|
using namespace events; |
|
|
|
using namespace triggers; |
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
@ -53,9 +53,9 @@ class clm { |
|
|
|
|
|
|
|
|
|
|
|
// ------------------ EXTEND OWN CLASS WITH EVENTS -------------------
|
|
|
|
// ------------------ EXTEND OWN CLASS WITH EVENTS -------------------
|
|
|
|
|
|
|
|
|
|
|
|
class myOwnClass : public event<int> { |
|
|
|
class myOwnClass : public trigger<int> { |
|
|
|
public: |
|
|
|
public: |
|
|
|
myOwnClass() : event() {}; |
|
|
|
myOwnClass() : trigger() {}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -216,74 +216,74 @@ int main () { |
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
// // --------------- EVENTS -------------------
|
|
|
|
// --------------- EVENTS -------------------
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
/**
|
|
|
|
// * initialization of typed events
|
|
|
|
* initialization of typed events |
|
|
|
// */
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
// event<int, int> ev2int;
|
|
|
|
trigger<int, int> ev2int; |
|
|
|
// event<int, string> evintString;
|
|
|
|
trigger<int, string> evintString; |
|
|
|
// event<> evoid;
|
|
|
|
trigger<> evoid; |
|
|
|
|
|
|
|
|
|
|
|
// ev2int.on("sum", [](int a, int b) {
|
|
|
|
ev2int.on("sum", [](int a, int b) { |
|
|
|
// cout << "Sum " << a+b << endl;
|
|
|
|
cout << "Sum " << a+b << endl; |
|
|
|
// });
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// ev2int.on("sum", [](int a, int b) {
|
|
|
|
ev2int.on("sum", [](int a, int b) { |
|
|
|
// cout << "Sum done" << endl;
|
|
|
|
cout << "Sum done" << endl; |
|
|
|
// });
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// evintString.on("substract", [](int a, string b) {
|
|
|
|
evintString.on("substract", [](int a, string b) { |
|
|
|
// cout << "Substract " << a-stoi(b) << endl;
|
|
|
|
cout << "Substract " << a-stoi(b) << endl; |
|
|
|
// });
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// evoid.on("void", []() {
|
|
|
|
evoid.on("void", []() { |
|
|
|
// cout << "Void emited" << endl;
|
|
|
|
cout << "Void emited" << endl; |
|
|
|
// });
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// string emited2 = "2";
|
|
|
|
string emited2 = "2"; |
|
|
|
|
|
|
|
|
|
|
|
// evoid.on("void", [&]() {
|
|
|
|
evoid.on("void", [&]() { |
|
|
|
// cout << "Void emited " << emited2 << endl;
|
|
|
|
cout << "Void emited " << emited2 << endl; |
|
|
|
// });
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// evoid.emit("void");
|
|
|
|
evoid.tick("void"); |
|
|
|
// sleep(1);
|
|
|
|
sleep(1); |
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
/**
|
|
|
|
// * Emit
|
|
|
|
* Emit |
|
|
|
// */
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
// ev2int.emit("sum", 5, 8);
|
|
|
|
ev2int.tick("sum", 5, 8); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sleep(1);
|
|
|
|
sleep(1); |
|
|
|
// evintString.emit("substract", 3, to_string(2));
|
|
|
|
evintString.tick("substract", 3, to_string(2)); |
|
|
|
|
|
|
|
|
|
|
|
// sleep(1);
|
|
|
|
sleep(1); |
|
|
|
// evoid.off("void");
|
|
|
|
evoid.off("void"); |
|
|
|
// evoid.emit("void");
|
|
|
|
evoid.tick("void"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cout << "Ukupno 2 int " << ev2int.listeners() << endl;
|
|
|
|
cout << "Ukupno 2 int " << ev2int.listeners() << endl; |
|
|
|
// cout << "Ukupno evintString " << evintString.listeners() << endl;
|
|
|
|
cout << "Ukupno evintString " << evintString.listeners() << endl; |
|
|
|
// cout << "Ukupno evoid " << evoid.listeners() << endl;
|
|
|
|
cout << "Ukupno evoid " << evoid.listeners() << endl; |
|
|
|
// cout << "Ukupno 2 int " << ev2int.listeners("sum") << endl;
|
|
|
|
cout << "Ukupno 2 int " << ev2int.listeners("sum") << endl; |
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
/**
|
|
|
|
// * Own class
|
|
|
|
* Own class
|
|
|
|
// */
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
// myOwnClass myclass;
|
|
|
|
myOwnClass myclass; |
|
|
|
|
|
|
|
|
|
|
|
// delayed t( [&] {
|
|
|
|
delayed t( [&] { |
|
|
|
// myclass.emit("constructed", 1);
|
|
|
|
myclass.tick("constructed", 1); |
|
|
|
// }, 200);
|
|
|
|
}, 200); |
|
|
|
|
|
|
|
|
|
|
|
// myclass.on("constructed", [] (int i) {
|
|
|
|
myclass.on("constructed", [] (int i) { |
|
|
|
// cout << "Constructed " << i << endl;
|
|
|
|
cout << "Constructed " << i << endl; |
|
|
|
// });
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|