feat: progress AyuSync implementation

This commit is contained in:
ZavaruKitsu 2023-07-08 00:08:13 +00:00
parent d37022c9f4
commit acb335ea2b
6 changed files with 37 additions and 19 deletions

View file

@ -138,7 +138,7 @@ public:
{
native_mode = mode & std::ios_base::in ? PIPE_ACCESS_INBOUND : PIPE_ACCESS_OUTBOUND;
handle = CreateNamedPipeW(std::data(native_name), native_mode, PIPE_READMODE_BYTE | PIPE_WAIT, 1, buf_size, buf_size, 0, nullptr);
handle = CreateNamedPipeW(std::data(native_name), native_mode, PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, buf_size, buf_size, 0, nullptr);
if(handle == INVALID_HANDLE_VALUE)
return false;

View file

@ -43,19 +43,27 @@ namespace AyuSync {
if (!isAgentRunning()) {
auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json");
auto process = nes::process{AgentPath, {configPath.string()}};
auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none};
process.detach();
}
pipe = std::make_unique<ayu_pipe_wrapper>();
std::thread receiverThread(&ayu_sync_controller::receiver, this);
receiverThread.detach();
}
void ayu_sync_controller::receiver() {
pipe = std::make_unique<ayu_pipe_wrapper>();
while (true) {
auto p = pipe->receive();
invokeHandler(p);
if (p == std::nullopt) {
continue;
}
std::string s = p->dump();
LOG(("[AyuSync] Received message: %1").arg(QString::fromStdString(s)));
invokeHandler(p.value());
}
}

View file

@ -14,9 +14,9 @@ using json = nlohmann::json;
const std::string AgentFilename =
#ifdef _WIN32
"AyuSyncAgent.exe";
"AyuSync.Agent.exe";
#else
"AyuSyncAgent";
"AyuSync.Agent";
#endif
const std::string AgentPath = "./AyuSync/" + AgentFilename;

View file

@ -11,22 +11,31 @@
template<class T>
void ayu_pipe_wrapper::send(T obj) {
auto s = json(obj).dump();
auto length = s.length();
char lengthBuff[4];
bit_converter::i32_to_bytes(length, false, lengthBuff);
os.write(lengthBuff, 4);
os.write(s.c_str(), length);
os.flush();
// auto s = json(obj).dump();
// auto length = s.length();
// char lengthBuff[4];
// bit_converter::i32_to_bytes(length, false, lengthBuff);
//
// os.write(lengthBuff, 4);
// os.write(s.c_str(), length);
// os.flush();
throw std::logic_error("not implemented");
}
json ayu_pipe_wrapper::receive() {
std::optional<json> ayu_pipe_wrapper::receive() {
if (!is.is_open()) {
return std::nullopt;
}
char lengthBuff[4];
is.read(lengthBuff, 4);
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
if (length <= 0) {
return std::nullopt;
}
auto sb = std::stringbuf();
char buff[4096];

View file

@ -18,9 +18,8 @@ public:
template<class T>
void send(T obj);
json receive();
std::optional<json> receive();
private:
nes::basic_pipe_istream<char> is{"AyuSync"};
nes::basic_pipe_ostream<char> os{"AyuSync"};
nes::pipe_istream is{"AyuSync"};
};

View file

@ -414,6 +414,8 @@ namespace Settings {
AddSkip(container);
SetupAyuSync(container);
AddDivider(container);
AddSkip(container);
SetupBetaFunctions(container);