HelloAurora/Tests/Public/B. Open Mutex/Main.cpp
2023-07-28 17:31:59 +01:00

56 lines
1.3 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
static void TestPath(const AuString &path)
{
auto mutex = AuIO::IPC::ImportMutex(path);
AuLogDbg("Got mutex: {}", fmt::ptr(mutex.get()));
mutex->WaitOn(0);
AuThreading::Sleep(2000);
AuLogDbg("Exiting");
}
static void Read()
{
AuLogInfo("Awaiting input (10s)");
auto loop = AuLoop::NewLoopQueue();
auto source = AuConsole::StdInBufferLoopSource();
SysAssert(loop->SourceAdd(source));
SysAssert(loop->Commit());
if (loop->WaitAll(10 * 1000))
{
char binary[512];
int length = AuConsole::ReadStdIn(binary, AuArraySize(binary));
AuString path(binary, binary + length - AuLocale::NewLine().size());
SysAssert(!source->IsSignaled());
SysAssert(!source->WaitOn(100));
TestPath(path);
}
else
{
AuLogInfo("Got nothing");
}
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.enableStdPassthrough = true; // for ReadStdIn
info.console.enableStdOut = false; // give back stdout to the logger
info.console.fio.bEnableLogging = false;
Aurora::RuntimeStart(info);
Read();
}