detach PIHTTPServer::Endpoint to base struct PIHTTP::ServerEndpoint (private header), no functionality changes in HTTP server
Ready to implement this private base struct to MQTT client
This commit is contained in:
@@ -10,18 +10,57 @@
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
using namespace PIHTTP;
|
||||
using namespace PIUnits::Class;
|
||||
|
||||
int rcnt = 0, scnt = 0;
|
||||
|
||||
inline PIByteArray SMBusTypeInfo_genHash(PIString n) {
|
||||
PICrypt c;
|
||||
return piSerialize(c.shorthash(n.removeAll(" "), PIString("SMBusDataHashKey").toByteArray()));
|
||||
}
|
||||
|
||||
PIKbdListener kbd;
|
||||
|
||||
MessageMutable createMessage(Code c, const char * path, const MessageConst & msg) {
|
||||
piCout << "path" << path << "args" << msg.pathArguments();
|
||||
return MessageMutable().setCode(c);
|
||||
};
|
||||
int main(int argc, char * argv[]) {
|
||||
piCout << "start ...";
|
||||
PIHTTPServer server;
|
||||
server.registerUnhandled([](const MessageConst & msg) { return createMessage(Code::BadRequest, "unhadled", msg); });
|
||||
server.registerPath("api/v1/status", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/status", msg);
|
||||
});
|
||||
server.registerPath("api/v1/plugins", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/plugins", msg);
|
||||
});
|
||||
server.registerPath("api/v1/task-status", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/task-status", msg);
|
||||
});
|
||||
server.registerPath("api/v1/task/{taskID}/status", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/task/{taskID}/status", msg);
|
||||
});
|
||||
server.registerPath("api/v1/bort/list", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/bort/list", msg);
|
||||
});
|
||||
server.registerPath("api/v1/all", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/all", msg);
|
||||
});
|
||||
server.registerPath("api/v1/all/bort{A}/f", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/all/*/f", msg);
|
||||
});
|
||||
server.registerPath("api/v1/all2/**", Method::Get, [](const MessageConst & msg) {
|
||||
return createMessage(Code::Accepted, "api/v1/all2/**", msg);
|
||||
});
|
||||
server.listenAll(12345);
|
||||
|
||||
kbd.enableExitCapture('Q');
|
||||
WAIT_FOR_EXIT
|
||||
piCout << "exiting ...";
|
||||
server.stop();
|
||||
|
||||
return 0;
|
||||
|
||||
PISystemMonitor mon;
|
||||
mon.startOnSelf();
|
||||
PISystemMonitor::totalRAM();
|
||||
2_s .sleep();
|
||||
|
||||
return 0;
|
||||
PIMQTT::Client cl;
|
||||
cl.setConnectTimeout(2_s);
|
||||
CONNECTL(&cl, connected, [&cl] {
|
||||
@@ -36,7 +75,7 @@ int main(int argc, char * argv[]) {
|
||||
cl.connect("localhost", "PIP");
|
||||
});
|
||||
CONNECTL(&cl, received, [](const PIMQTT::MessageConst & message) {
|
||||
piCout << "received" << message.topic() << message.payload().size();
|
||||
piCout << "received" << message.topic() << message.pathArguments() << message.payload().size();
|
||||
});
|
||||
|
||||
cl.connect("localhost", "PIP");
|
||||
@@ -45,126 +84,4 @@ int main(int argc, char * argv[]) {
|
||||
WAIT_FOR_EXIT
|
||||
|
||||
piCout << "exiting ...";
|
||||
return 0;
|
||||
|
||||
PICrypt _crypt;
|
||||
// auto ba = PIFile::readAll("logo.png");
|
||||
PIString str = "hello!"_a;
|
||||
PIByteArray ba = str.toAscii();
|
||||
PIByteArray key = PIString("SMBusDataHashKey").toByteArray();
|
||||
|
||||
const int times = 1000000;
|
||||
PITimeMeasurer tm;
|
||||
PISystemTime el;
|
||||
|
||||
tm.reset();
|
||||
piForTimes(times) {
|
||||
PIDigest::calculateWithKey(ba, key, PIDigest::Type::SipHash_2_4_128);
|
||||
}
|
||||
el = tm.elapsed();
|
||||
piCout << "PIDigest" << el.toString();
|
||||
|
||||
tm.reset();
|
||||
piForTimes(times) {
|
||||
_crypt.shorthash(str, key);
|
||||
}
|
||||
el = tm.elapsed();
|
||||
piCout << " sodium" << el.toString();
|
||||
|
||||
tm.reset();
|
||||
piForTimes(times) {
|
||||
PIDigest::calculateWithKey(ba, key, PIDigest::Type::BLAKE2b_128);
|
||||
}
|
||||
el = tm.elapsed();
|
||||
piCout << " blake" << el.toString();
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
PIEthernet *eth_r, *eth_s;
|
||||
eth_r = PIIODevice::createFromFullPath("eth://udp: 192.168.1.25 :10000")->cast<PIEthernet>();
|
||||
eth_s = PIIODevice::createFromFullPath("eth://udp: : : 192.168.1.25:10000")->cast<PIEthernet>();
|
||||
|
||||
eth_r->setReadBufferSize(1_MiB);
|
||||
CONNECTL(eth_r, threadedReadEvent, [](const uchar * readed, ssize_t size) {
|
||||
// piCout << "rec";
|
||||
piMSleep(1);
|
||||
++rcnt;
|
||||
});
|
||||
eth_r->startThreadedRead();
|
||||
|
||||
PIByteArray _ba(1400);
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
eth_s->write(_ba);
|
||||
++scnt;
|
||||
}
|
||||
|
||||
0.2_s .sleep();
|
||||
|
||||
piCout << "snd" << scnt;
|
||||
piCout << "rec" << rcnt;
|
||||
|
||||
piDeleteSafety(eth_r);
|
||||
piDeleteSafety(eth_s);
|
||||
return 0;
|
||||
|
||||
PITranslator::loadLang("ru");
|
||||
/*auto ucl = PIUnits::allClasses();
|
||||
for (auto c: ucl) {
|
||||
piCout << (c->className() + ":");
|
||||
for (auto t: c->allTypes()) {
|
||||
piCout << " " << c->name(t) << "->" << c->unit(t);
|
||||
}
|
||||
}*/
|
||||
|
||||
// PIUnits::Value(1);
|
||||
// piCout << PIUnits::name(PIUnits::Class::Information::Bit);
|
||||
// piCout << PIUnits::name(PIUnits::Class::Information::Byte);
|
||||
// piCout << PIUnits::name(PIUnits::Class::Information::_LastType);
|
||||
// piCout << PIUnits::name((int)PIUnits::Class::Angle::Degree);
|
||||
|
||||
// piCout << PIUnits::unit(PIUnits::Class::Information::Bit);
|
||||
// piCout << PIUnits::unit(PIUnits::Class::Information::Byte);
|
||||
// piCout << PIUnits::unit(PIUnits::Class::Information::_LastType);
|
||||
// piCout << PIUnits::unit((int)PIUnits::Class::Angle::Degree);
|
||||
|
||||
// for (int i = -10; i < 10; ++i)
|
||||
// piCout << PIUnits::Value(pow10(i * 0.99), PIUnits::Class::Distance::Meter).toString();
|
||||
|
||||
auto v = PIUnits::Value(M_PI, Angle::Radian);
|
||||
piCout << v << "=" << v.converted(Angle::Degree);
|
||||
|
||||
v = PIUnits::Value(45, Angle::Degree);
|
||||
piCout << v << "=" << v.converted(Angle::Radian);
|
||||
|
||||
piCout << PIUnits::Value(5E-5, Time::Second);
|
||||
piCout << PIUnits::Value(3E-3, Time::Second);
|
||||
piCout << PIUnits::Value(0.8, Time::Second);
|
||||
piCout << PIUnits::Value(1.2, Time::Second);
|
||||
piCout << PIUnits::Value(1001, Time::Second);
|
||||
piCout << PIUnits::Value(1000001, Time::Second);
|
||||
|
||||
piCout << PIUnits::Value(1_KB, Information::Byte);
|
||||
piCout << PIUnits::Value(1_MB, Information::Byte);
|
||||
piCout << PIUnits::Value(1_MiB, Information::Byte);
|
||||
piCout << PIUnits::Value(1_MB, Information::Byte).converted(Information::Bit);
|
||||
piCout << PIUnits::Value(1_MiB, Information::Byte).converted(Information::Bit);
|
||||
|
||||
piCout << PIUnits::Value(0., Temperature::Celsius).converted(Temperature::Kelvin);
|
||||
piCout << PIUnits::Value(0., Temperature::Celsius).converted(Temperature::Fahrenheit);
|
||||
piCout << PIUnits::Value(100., Temperature::Celsius).converted(Temperature::Fahrenheit);
|
||||
|
||||
piCout << PIUnits::Value(1., Pressure::Atmosphere).converted(Pressure::Pascal);
|
||||
piCout << PIUnits::Value(1., Pressure::Atmosphere).converted(Pressure::MillimetreOfMercury);
|
||||
piCout << PIUnits::Value(766., Pressure::MillimetreOfMercury).converted(Pressure::Atmosphere);
|
||||
|
||||
piCout << PIUnits::Value(5E-5, Time::Second).converted(Time::Hertz);
|
||||
piCout << PIUnits::Value(3E-3, Time::Second).converted(Time::Hertz);
|
||||
piCout << PIUnits::Value(0.8, Time::Second).converted(Time::Hertz);
|
||||
piCout << PIUnits::Value(1.2, Time::Second).converted(Time::Hertz);
|
||||
piCout << PIUnits::Value(1001, Time::Second).converted(Time::Hertz);
|
||||
piCout << PIUnits::Value(1000001, Time::Second).converted(Time::Hertz);
|
||||
// piCout << PIUnits::Value(0.2, Time::Second).converted(Time::Hertz);
|
||||
// piCout << PIUnits::Value(5E-5, Time::Second).converted(Time::Hertz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user