docs: further setting up structure
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#include <exception>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
@ -42,7 +43,10 @@ template <typename T>
|
||||
BlockingStringStream &BlockingStringStream::operator<<(const T &val) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (internalStream.peek() == EOF) internalStream.clear();
|
||||
if (internalStream.peek() == EOF) {
|
||||
internalStream.clear();
|
||||
internalStream.str("");
|
||||
}
|
||||
internalStream << val;
|
||||
}
|
||||
condition.notify_one();
|
||||
@ -61,4 +65,10 @@ BlockingStringStream &BlockingStringStream::operator>>(T &val) {
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
class SessionClass {
|
||||
std::stack<int> login_stack;
|
||||
std::string SessionToken;
|
||||
std::string OuthorizationKey;
|
||||
};
|
||||
#endif // PROTECTOR_UTILITY_H
|
@ -1,4 +1,11 @@
|
||||
#ifndef PROTECTOR_ENGINE_H
|
||||
#define PROTECTOR_ENGINE_H
|
||||
#include <string>
|
||||
class BookStoreEngineClass {
|
||||
std::string config_dir;
|
||||
|
||||
#endif // PROTECTOR_ENGINE_H
|
||||
public:
|
||||
BookStoreEngineClass() = delete;
|
||||
BookStoreEngineClass(std::string config_dir) : config_dir(config_dir) {}
|
||||
};
|
||||
#endif // PROTECTOR_ENGINE_H
|
@ -1,4 +1,23 @@
|
||||
#ifndef PROTECTOR_SCHEDULE_H
|
||||
#define PROTECTOR_SCHEDULE_H
|
||||
#include <string>
|
||||
|
||||
#endif // PROTECTOR_SCHEDULE_H
|
||||
#include "bs-utility.h"
|
||||
#include "engine.h"
|
||||
class BookStoreBackEndClass {
|
||||
std::string config_dir;
|
||||
BlockingStringStream *input_ptr;
|
||||
BlockingStringStream *output_ptr;
|
||||
BookStoreEngineClass *engine_ptr;
|
||||
|
||||
public:
|
||||
BookStoreBackEndClass() = delete;
|
||||
BookStoreBackEndClass(std::string config_dir, BlockingStringStream *input_ptr,
|
||||
BlockingStringStream *output_ptr)
|
||||
: config_dir(config_dir), input_ptr(input_ptr), output_ptr(output_ptr) {
|
||||
engine_ptr = new BookStoreEngineClass(config_dir);
|
||||
}
|
||||
~BookStoreBackEndClass() { delete engine_ptr; }
|
||||
void Run();
|
||||
};
|
||||
#endif // PROTECTOR_SCHEDULE_H
|
@ -2,15 +2,34 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "schedule.h"
|
||||
#include "bs-utility.h"
|
||||
#include "schedule.h"
|
||||
void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
std::ios::sync_with_stdio(false);
|
||||
if (!is_server) {
|
||||
; // TODO: run as client
|
||||
} else {
|
||||
throw FatalError("Server mode is not implemented yet", 1);
|
||||
std::cin.tie(nullptr);
|
||||
std::cout.rdbuf(nullptr);
|
||||
BlockingStringStream input;
|
||||
BlockingStringStream output;
|
||||
BookStoreBackEndClass backend(config_dir, &input, &output);
|
||||
std::thread backend_thread([&backend]() { backend.Run(); });
|
||||
std::thread input_thread([&input]() {
|
||||
std::string data;
|
||||
while (std::getline(std::cin, data)) {
|
||||
input << data << '\n';
|
||||
}
|
||||
});
|
||||
std::thread output_thread([&output]() {
|
||||
std::string data;
|
||||
while (true) {
|
||||
output.getline(data, '\n');
|
||||
std::cout << data << std::endl;
|
||||
}
|
||||
});
|
||||
input_thread.join();
|
||||
output_thread.join();
|
||||
backend_thread.join();
|
||||
}
|
||||
}
|
@ -7,27 +7,27 @@
|
||||
void test() {
|
||||
BlockingStringStream bss;
|
||||
|
||||
std::thread reader([&bss]() {
|
||||
std::string data;
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
// Use getline with string delimiter
|
||||
bss.getline(data, '\n');
|
||||
std::cerr << "Received: " << data << std::endl;
|
||||
}
|
||||
});
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::thread writer([&bss]() {
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
bss << "Data " << i << '\n';
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
});
|
||||
|
||||
std::thread reader([&bss]() {
|
||||
std::string data;
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
// Use getline with string delimiter
|
||||
bss.getline(data, '\n');
|
||||
std::cout << "Received: " << data << std::endl;
|
||||
}
|
||||
});
|
||||
reader.join();
|
||||
writer.join();
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
test();
|
||||
return 0;
|
||||
// test();
|
||||
// return 0;
|
||||
bool is_server = false;
|
||||
std::string config_dir = "";
|
||||
bool custom_config_dir = false;
|
||||
|
@ -1,2 +1,13 @@
|
||||
#include "schedule.h"
|
||||
#include "engine.h"
|
||||
#include "engine.h"
|
||||
|
||||
void BookStoreBackEndClass::Run()
|
||||
{
|
||||
std::string request_data;
|
||||
while(true)
|
||||
{
|
||||
input_ptr->getline(request_data, '\n');
|
||||
// std::string response_data = Engine::Process(request_data);
|
||||
// output_ptr << response_data << '\n';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user