[+] Network interfaces API

[+] Logger IFormatter API
[*] Clean up
This commit is contained in:
Reece Wilson 2022-12-14 20:08:52 +00:00
parent c79a20c7fe
commit 85a575eb95
41 changed files with 773 additions and 142 deletions

View File

@ -62,7 +62,8 @@
"Ntdll.lib",
"Wer.lib",
"wintrust.lib",
"Winmm.lib"
"Winmm.lib",
"Iphlpapi.lib"
]
}
},

View File

@ -0,0 +1,29 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: INetAdapter.hpp
Date: 2022-12-11
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct INetAdapter
{
virtual const AuString &ToName() = 0;
virtual const AuString &ToDevice() = 0;
virtual AuUInt16 GetIndex() = 0;
virtual EIPProtocol ToFamily() = 0;
virtual IPAddress ToAddress() = 0;
virtual IPAddress ToBroadcastAddress() = 0;
virtual IPAddress ToAnycastAddress() = 0;
virtual IPAddress ToSubnetMask() = 0;
virtual IPAddress ToGateway() = 0;
virtual AuList<IPAddress> GetDNS() = 0;
};
};

View File

@ -13,20 +13,26 @@ namespace Aurora::IO::Net
struct INetSrvResolve;
struct INetSrvSockets;
struct INetSrvWorkers;
struct INetSrvInterfaces;
struct INetInterface
{
virtual AuSPtr<INetSrvWorkers> GetWorkersService() = 0;
virtual void Shutdown() = 0;
virtual AuSPtr<INetSrvResolve> GetResolveService() = 0;
virtual AuSPtr<INetSrvSockets> GetSocketService() = 0;
virtual AuSPtr<INetSrvDatagram> GetDatagramService() = 0;
virtual void Destroy() = 0;
virtual bool TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit) = 0;
virtual void Shutdown() = 0;
virtual void Destroy() = 0;
virtual AuSPtr<INetSrvWorkers> GetWorkersService() = 0;
virtual AuSPtr<INetSrvResolve> GetResolveService() = 0;
virtual AuSPtr<INetSrvSockets> GetSocketService() = 0;
virtual AuSPtr<INetSrvDatagram> GetDatagramService() = 0;
virtual AuSPtr<INetSrvInterfaces> GetInterfacesService() = 0;
};
AUKN_SYM AuSPtr<INetInterface> NewNetworkInterface();

View File

@ -0,0 +1,18 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: INetSrvInterfaces.hpp
Date: 2022-12-11
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct INetSrvInterfaces
{
virtual const AuString & GetHostname() = 0;
virtual void ResetAdapterCache() = 0;
virtual AuList<AuSPtr<INetAdapter>> GetAdapters() = 0;
};
};

View File

@ -35,6 +35,9 @@
#include "IResolver.hpp"
#include "INetAdapter.hpp"
#include "INetSrvInterfaces.hpp"
#include "INetSrvDatagram.hpp"
#include "INetSrvResolve.hpp"
#include "INetSrvSockets.hpp"

View File

@ -0,0 +1,16 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IFormattedSink.hpp
Date: 2022-11-14
Author: Reece
***/
#pragma once
namespace Aurora::Logging
{
struct IFormattedSink : IBasicSink, IFormatterContainer
{
};
}

View File

@ -0,0 +1,15 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IFormatter.hpp
Date: 2022-11-14
Author: Reece
***/
#pragma once
namespace Aurora::Logging
{
AUKN_INTERFACE(IFormatter,
AUI_METHOD(AuString, Format, (AuUInt8, level, const Console::ConsoleMessage &, msg))
);
}

View File

@ -0,0 +1,17 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IFormatterContainer.hpp
Date: 2022-11-14
Author: Reece
***/
#pragma once
namespace Aurora::Logging
{
struct IFormatterContainer
{
virtual AuSPtr<IFormatter> GetFormatter() = 0;
virtual void SetFormatter(const AuSPtr<IFormatter> &pFormatter) = 0;
};
}

View File

@ -7,8 +7,11 @@
***/
#pragma once
#include "IFormatter.hpp"
#include "IFormatterContainer.hpp"
#include "ILogger.hpp"
#include "IBasicSink.hpp"
#include "IFormattedSink.hpp"
#include "IBasicSinkRB.hpp"
#include "IIPCLogger.hpp"
#include "Sinks.hpp"

View File

@ -24,8 +24,8 @@ namespace Aurora::Logging
* @brief Constructs a UTF8 output sink.
* Backed by stdconsole; supports posix fd stdin/out localized, visual studio debugger, and conhost
*/
AUKN_SHARED_API(NewStdSink, IBasicSink);
AUKN_SHARED_API(NewStdSink, IFormattedSink);
/**
* @brief Unimplemented systemd or service (?) backend
*/
@ -44,7 +44,7 @@ namespace Aurora::Logging
/**
* @brief Constructs a text of binary log file sink
*/
AUKN_SHARED_API(NewFileSink, IBasicSink, const AuString &path, bool binary = false);
AUKN_SHARED_API(NewFileSink, IFormattedSink, const AuString &path, bool binary = false);
/**
* @brief Constructs a dedicated log directory subject to erasure as defined by defined DirectoryLogger

View File

@ -209,7 +209,10 @@ namespace Aurora
bool asyncVSLog {false};
/// Should stdout print the full date or a mere HH MM SS prefix?
bool stdOutShortTime {false};
bool bStdOutShortTime { false };
///
bool bStdOutUseLocalTime { true };
#if 1
/// FIO config

View File

@ -9,7 +9,7 @@
#include "Console.hpp"
#include "Commands/Commands.hpp"
#include "Hooks/Hooks.hpp"
#include "Logging/Logger.hpp"
#include "Logging/AuLogger.hpp"
#include "ConsoleStd/ConsoleStd.hpp"
#include "ConsoleWxWidgets/ConsoleWxWidgets.hpp"
#include "ConsoleFIO/ConsoleFIO.hpp"

View File

@ -11,7 +11,9 @@
namespace Aurora::Console
{
static AuString StringifyTimeEx(const ConsoleMessage &msg, bool simple, bool utc)
static AuString StringifyTimeEx(const ConsoleMessage &msg,
bool simple,
bool utc)
{
try
{
@ -38,94 +40,64 @@ namespace Aurora::Console
{
AuUInt8 ref;
deserialize.Read(ref);
color = static_cast<EAnsiColor>(ref);
deserialize.Read(prefix);
deserialize.Read(line);
deserialize.Read(time);
deserialize.Read(tid);
this->color = static_cast<EAnsiColor>(ref);
deserialize.Read(this->prefix);
deserialize.Read(this->line);
deserialize.Read(this->time);
deserialize.Read(this->tid);
}
AUKN_SYM void ConsoleMessage::Write(Memory::ByteBuffer &serialize) const
{
serialize.Write(static_cast<AuUInt8>(color));
serialize.Write(prefix);
serialize.Write(line);
serialize.Write(time);
serialize.Write(tid);
serialize.Write(static_cast<AuUInt8>(this->color));
serialize.Write(this->prefix);
serialize.Write(this->line);
serialize.Write(this->time);
serialize.Write(this->tid);
}
AuString ConsoleMessage::StringifyTime(bool simple) const
{
try
{
return StringifyTimeEx(*this, simple, false);
}
catch (...)
{
return {};
}
return StringifyTimeEx(*this,
simple,
false);
}
AuString ConsoleMessage::StringifyTimeUTC() const
{
try
{
return StringifyTimeEx(*this, false, true);
}
catch (...)
{
return {};
}
return StringifyTimeEx(*this,
false,
true);
}
AuString ConsoleMessage::GetWrappedTag() const
{
return "[" + prefix + "]";
return "[" + this->prefix + "]";
}
AuString ConsoleMessage::ToConsole() const
{
try
if (gRuntimeConfig.console.bStdOutUseLocalTime)
{
return fmt::format("[{}] {:<8} | {}",
StringifyTime(gRuntimeConfig.console.stdOutShortTime),
GetWrappedTag(),
line);//,
//kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(EAnsiColor::eReset)]);
return this->ToPersistentString();
}
catch (...)
{
return {};
}
return fmt::format("[{}] {:<8} | {}",
StringifyTime(gRuntimeConfig.console.bStdOutShortTime),
GetWrappedTag(),
this->line);
}
AuString ConsoleMessage::ToPersistentString() const
{
try
{
return fmt::format("[{}] {:<7} | {}",
StringifyTimeUTC(),
GetWrappedTag(),
line);
}
catch (...)
{
return {};
}
return fmt::format("[{}] {:<8} | {}",
StringifyTimeUTC(),
GetWrappedTag(),
this->line);
}
AuString ConsoleMessage::ToSimplified() const
{
try
{
return fmt::format("{:<9} {:<8} | {}", StringifyTime(true), GetWrappedTag(), line);
}
catch (...)
{
return {};
}
return fmt::format("{:<9} {:<8} | {}", StringifyTime(true), GetWrappedTag(), this->line);
}
}

View File

@ -90,7 +90,7 @@ namespace Aurora::Console::ConsoleStd
#define IS_STREAM_HANDLE_VALID(h) (h != DEFAULT_HANDLE_VAL)
static bool AsyncReadAnyOrReadStreamBlock();
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg);
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg, const AuString &formatted);
static const AuMach kLineBufferMax = 2048;
static AuUInt8 gLineEncodedBuffer[kLineBufferMax];
@ -1005,10 +1005,10 @@ namespace Aurora::Console::ConsoleStd
FlushStdOutNb();
}
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg)
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg, const AuString &formatted)
{
bool bUseAlt {};
auto writeLine = msg.ToConsole();
auto writeLine = formatted;
if (!gSupportsColorOutput)
{

View File

@ -25,7 +25,7 @@ namespace Aurora::Console::ConsoleStd
AuUInt32 ReadStdIn(void *data, AuUInt32 length);
AuUInt32 WriteStdOut(const void *data, AuUInt32 length);
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg);
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg, const AuString &formatted);
inline bool gSupportsColorOutput { true };

View File

@ -118,7 +118,18 @@ namespace Aurora::Console::ConsoleTTY
{
AU_LOCK_GUARD(this->messageLock);
AuTryInsert(this->messagesPending, msg);
AuConsole::ConsoleMessage msg2(msg);
msg2.line = msg.ToConsole();
AuTryInsert(this->messagesPending, msg2); // TODO: !
}
void TTYConsole::BufferMessage(const AuConsole::ConsoleMessage &msg, const AuString &input)
{
AU_LOCK_GUARD(this->messageLock);
AuConsole::ConsoleMessage msg2(msg);
msg2.line = input;
AuTryInsert(this->messagesPending, msg2); // TODO: !
}
void TTYConsole::NoncanonicalTick()
@ -808,7 +819,7 @@ namespace Aurora::Console::ConsoleTTY
{
for (auto &message : messages)
{
auto str = message.ToConsole();
auto str = message.line; // Note: we replaced the line in BufferMessage
while (str.size())
{
@ -2122,6 +2133,11 @@ x
gTTYConsole.BufferMessage(msg);
}
void WriteTTYOut(const AuConsole::ConsoleMessage &msg, const AuString &input)
{
gTTYConsole.BufferMessage(msg, input);
}
void Pump()
{
// :(
@ -2171,7 +2187,7 @@ x
}
void WriteTTYOut(const AuConsole::ConsoleMessage &msg)
void WriteTTYOut(const AuConsole::ConsoleMessage &msg, const AuString &input)
{
}

View File

@ -17,6 +17,9 @@ namespace Aurora::Console::ConsoleTTY
struct TTYConsole : ITTYConsole
{
void BufferMessage(const AuConsole::ConsoleMessage &msg) override;
void BufferMessage(const AuConsole::ConsoleMessage &msg, const AuString &input) ;
//
void Pump();
void PumpHistory();
@ -268,6 +271,7 @@ namespace Aurora::Console::ConsoleTTY
void Exit();
void OnEnter();
void WriteTTYOut(const AuConsole::ConsoleMessage &msg);
void WriteTTYOut(const AuConsole::ConsoleMessage &msg, const AuString &input);
AUKN_SYM AuSPtr<ITTYConsole> GetTTYConsole();
void PumpForce();
}

View File

@ -10,7 +10,7 @@
#include "ConsoleFIO/ConsoleFIO.hpp"
#include "ConsoleStd/ConsoleStd.hpp"
#include "Logging/Logger.hpp"
#include "Logging/AuLogger.hpp"
namespace Aurora::Console
{

View File

@ -13,7 +13,7 @@
#include <Source/RuntimeInternal.hpp>
#include "AuGrug.hpp"
#include <Source/Logging/Logger.hpp>
#include <Source/Logging/AuLogger.hpp>
#include <Source/Console/ConsoleFIO/ConsoleFIO.hpp>
#include <Source/RuntimeInternal.hpp>
#include <Source/Console/Flusher.hpp>

View File

View File

View File

@ -0,0 +1,226 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetAdapter.NT.cpp
Date: 2022-11-14
Author: Reece
***/
#include "Networking.hpp"
#include "AuNetAdapter.hpp"
#include "AuNetEndpoint.hpp"
#include <winsock2.h>
#include <iphlpapi.h>
namespace Aurora::IO::Net
{
static AuList<AuSPtr<INetAdapter>> gIpv4Adapters;
static AuList<AuSPtr<INetAdapter>> gIpv6Adapters;
AuString NetAdapter::GetHostname()
{
#if defined(AURORA_PLATFORM_WIN32)
wchar_t buffer[128];
DWORD dwLength { AuArraySize(buffer) };
if (!::GetComputerNameExW(ComputerNameDnsHostname, buffer, &dwLength))
{
return {};
}
return AuLocale::ConvertFromWChar(buffer, dwLength);
#else
return "";
#endif
}
#if defined(AURORA_PLATFORM_WIN32)
AuSPtr<IP_ADAPTER_ADDRESSES> GetAddressesForFamily(ULONG uFamily)
{
static const auto kDefSize = 15 * 1024;
AuSPtr<IP_ADAPTER_ADDRESSES> pAddresses;
DWORD outBufLen { kDefSize };
DWORD dwRetVal;
DWORD dwFlags = GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS;
DWORD dwIterations {};
do
{
pAddresses = AuReinterpretCast<IP_ADAPTER_ADDRESSES>(AuMakeSharedArray<AuUInt8>(kDefSize));
SysAssert(pAddresses);
dwRetVal = ::GetAdaptersAddresses(uFamily, dwFlags, NULL, pAddresses.get(), &outBufLen);
if (dwRetVal == 0)
{
break;
}
else if (dwRetVal != ERROR_BUFFER_OVERFLOW)
{
}
else
{
SysPushErrorNet("Fail");
break;
}
dwIterations++;
}
while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (dwIterations < 5));
return dwRetVal == NO_ERROR ? pAddresses : AuSPtr<IP_ADAPTER_ADDRESSES> {};
}
AU_NOINLINE void AddressesToList(AuSPtr<IP_ADAPTER_ADDRESSES> pAddresses, AuList<AuSPtr<INetAdapter>> &adaptersOut)
{
auto pCurrAddresses = pAddresses.get();
while (pCurrAddresses)
{
auto pAdapter = AuMakeSharedThrow<NetAdapter>();
auto &adapter = *pAdapter.get();
adapter.device = pCurrAddresses->AdapterName;
adapter.name = AuLocale::ConvertFromWChar(pCurrAddresses->FriendlyName);
auto pUnicast = pCurrAddresses->FirstUnicastAddress;
if (pUnicast)
{
NetEndpoint ep;
if (pUnicast->Address.iSockaddrLength <= sizeof(ep.hint))
{
AuMemcpy(ep.hint, pUnicast->Address.lpSockaddr, pUnicast->Address.iSockaddrLength);
DeoptimizeEndpoint(ep);
}
adapter.address = ep.ip;
}
auto pMulticast = pCurrAddresses->FirstMulticastAddress;
if (pMulticast)
{
NetEndpoint ep;
if (pMulticast->Address.iSockaddrLength <= sizeof(ep.hint))
{
AuMemcpy(ep.hint, pMulticast->Address.lpSockaddr, pMulticast->Address.iSockaddrLength);
DeoptimizeEndpoint(ep);
}
adapter.broadcast = ep.ip;
}
auto pAnycast = pCurrAddresses->FirstAnycastAddress;
if (pAnycast)
{
NetEndpoint ep;
if (pAnycast->Address.iSockaddrLength <= sizeof(ep.hint))
{
AuMemcpy(ep.hint, pAnycast->Address.lpSockaddr, pAnycast->Address.iSockaddrLength);
DeoptimizeEndpoint(ep);
}
adapter.anycast = ep.ip;
}
auto pGateway = pCurrAddresses->FirstGatewayAddress;
if (pAnycast)
{
NetEndpoint ep;
if (pGateway->Address.iSockaddrLength <= sizeof(ep.hint))
{
AuMemcpy(ep.hint, pGateway->Address.lpSockaddr, pGateway->Address.iSockaddrLength);
DeoptimizeEndpoint(ep);
}
adapter.anycast = ep.ip;
}
auto pDnsServers = pCurrAddresses->FirstDnsServerAddress;
if (pDnsServers)
{
do
{
NetEndpoint ep;
if (pDnsServers->Address.iSockaddrLength <= sizeof(ep.hint))
{
AuMemcpy(ep.hint, pDnsServers->Address.lpSockaddr, pDnsServers->Address.iSockaddrLength);
DeoptimizeEndpoint(ep);
}
adapter.dns.push_back(ep.ip);
}
while (pDnsServers = pDnsServers->Next);
}
adaptersOut.push_back(pAdapter);
pCurrAddresses = pCurrAddresses->Next;
}
}
#endif
static void PrecacheAdapters()
{
#if 0
ULONG ulOutBufLen = 0;
DWORD dwSize = 0;
DWORD dwRetVal = 0;
dwRetVal = ::GetInterfaceInfo(NULL, &ulOutBufLen);
if (dwRetVal == ERROR_INSUFFICIENT_BUFFER)
{
gIpInfo = AuReinterpretCast<IP_INTERFACE_INFO>(AuMakeSharedArray<AuUInt8>(ulOutBufLen));
SysAssert(gIpInfo);
}
dwRetVal = ::GetInterfaceInfo(gIpInfo.get(), &ulOutBufLen);
if (dwRetVal != NO_ERROR)
{
if (dwRetVal == ERROR_NO_DATA)
{
return;
}
SysPushErrorNet("Couldn't fetch interfaces");
return;
}
for (AuUInt i = 0;
i < gIpInfo->NumAdapters;
i++)
{
printf("Adapter Index[%d]: %ld\n", i,
gIpInfo->Adapter[i].Index);
printf("Adapter Name[%d]: %ws\n\n", i,
gIpInfo->Adapter[i].Name);
}
#endif
auto pAdaptersV4 = GetAddressesForFamily(AF_INET);
auto pAdaptersV6 = GetAddressesForFamily(AF_INET6);
AddressesToList(pAdaptersV4, gIpv4Adapters);
AddressesToList(pAdaptersV6, gIpv6Adapters);
}
AuList<AuSPtr<INetAdapter>> NetAdapter::GetIPv4s()
{
#if defined(AURORA_PLATFORM_WIN32)
PrecacheAdapters();
return gIpv4Adapters;
#else
return {};
#endif
}
AuList<AuSPtr<INetAdapter>> NetAdapter::GetIPv6s()
{
#if defined(AURORA_PLATFORM_WIN32)
return gIpv6Adapters;
#else
return {};
#endif
}
}

View File

View File

@ -0,0 +1,63 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetAdapter.cpp
Date: 2022-11-14
Author: Reece
***/
#include "Networking.hpp"
#include "AuNetAdapter.hpp"
#include "AuNetAdapter.hpp"
namespace Aurora::IO::Net
{
const AuString &NetAdapter::ToName()
{
return this->name.empty() ? this->device : this->name;
}
IPAddress NetAdapter::ToAddress()
{
return this->address;
}
IPAddress NetAdapter::ToBroadcastAddress()
{
return this->broadcast;
}
IPAddress NetAdapter::ToSubnetMask()
{
return this->subnet;
}
const AuString &NetAdapter::ToDevice()
{
return this->device;
}
EIPProtocol NetAdapter::ToFamily()
{
return this->address.ip;
}
AuUInt16 NetAdapter::GetIndex()
{
return this->index;
}
IPAddress NetAdapter::ToAnycastAddress()
{
return this->anycast;
}
IPAddress NetAdapter::ToGateway()
{
return this->gateway;
}
AuList<IPAddress> NetAdapter::GetDNS()
{
return this->dns;
}
}

View File

@ -0,0 +1,47 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetAdapter.hpp
Date: 2022-11-14
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct NetAdapter : INetAdapter
{
const AuString &ToName() override;
const AuString &ToDevice() override;
AuUInt16 GetIndex() override;
EIPProtocol ToFamily() override;
IPAddress ToAddress() override;
IPAddress ToBroadcastAddress() override;
IPAddress ToAnycastAddress() override;
IPAddress ToSubnetMask() override;
IPAddress ToGateway() override;
AuList<IPAddress> GetDNS() override;
// FriendlyName
static AuString GetHostname();
static AuList<AuSPtr<INetAdapter>> GetIPv4s(); // must be called first under lock
static AuList<AuSPtr<INetAdapter>> GetIPv6s(); // followed by me
// other protocols can go here
AuString name;
AuString device;
IPAddress address;
IPAddress broadcast;
IPAddress anycast;
IPAddress subnet;
IPAddress gateway;
AuList<IPAddress> dns;
AuUInt16 index {};
};
}

View File

@ -39,6 +39,15 @@ namespace Aurora::IO::Net
return AuSPtr<INetSrvDatagram>(AuSharedFromThis(), &this->netServiceDatagram_);
}
AuSPtr<INetSrvInterfaces> NetInterface::GetInterfacesService()
{
if (!this->netServiceInterfaces_.IsSupportedOnOS())
{
return {};
}
return AuSPtr<INetSrvInterfaces>(AuSharedFromThis(), &this->netServiceInterfaces_);
}
bool NetInterface::TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit)
{
auto workerId = AuAtomicAdd<AuUInt>(&this->atomicCounter_, 1u) - 1u;

View File

@ -11,6 +11,7 @@
#include "AuNetSrvSockets.hpp"
#include "AuNetSrvResolve.hpp"
#include "AuNetSrvDatagram.hpp"
#include "AuNetSrvInterfaces.hpp"
namespace Aurora::IO::Net
{
@ -23,8 +24,11 @@ namespace Aurora::IO::Net
AuSPtr<INetSrvResolve> GetResolveService() override;
AuSPtr<INetSrvSockets> GetSocketService() override;
AuSPtr<INetSrvDatagram> GetDatagramService() override;
AuSPtr<INetSrvInterfaces> GetInterfacesService() override;
bool TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit) override;
AuSPtr<NetWorker> TryScheduleEx();
@ -33,11 +37,10 @@ namespace Aurora::IO::Net
private:
NetSrvWorkers netServiceWorkers_; // Soviet Union Anthem
NetSrvSockets netServiceSockets_;
NetSrvResolve netServiceResolve_;
NetSrvDatagram netServiceDatagram_;
NetSrvInterfaces netServiceInterfaces_;
AuUInt atomicCounter_;
};

View File

@ -0,0 +1,63 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetSrvInterfaces.cpp
Date: 2022-11-14
Author: Reece
***/
#include "Networking.hpp"
#include "AuNetSrvInterfaces.hpp"
#include "AuNetAdapter.hpp"
namespace Aurora::IO::Net
{
const AuString &NetSrvInterfaces::GetHostname()
{
AU_LOCK_GUARD(this->lock);
if (this->bShouldUpdateCache)
{
UpdateCache();
}
return hostname;
}
void NetSrvInterfaces::ResetAdapterCache()
{
AU_LOCK_GUARD(this->lock);
this->bShouldUpdateCache = true;
}
void NetSrvInterfaces::UpdateCache()
{
this->hostname = NetAdapter::GetHostname();
auto ipv4s = NetAdapter::GetIPv4s();
auto ipv6s = NetAdapter::GetIPv6s();
this->adapters.clear();
this->adapters.insert(this->adapters.end(), ipv4s.begin(), ipv4s.end());
this->adapters.insert(this->adapters.end(), ipv6s.begin(), ipv6s.end());
}
AuList<AuSPtr<INetAdapter>> NetSrvInterfaces::GetAdapters()
{
AU_LOCK_GUARD(this->lock);
if (this->bShouldUpdateCache)
{
UpdateCache();
}
return this->adapters;
}
bool NetSrvInterfaces::IsSupportedOnOS()
{
#if defined(AURORA_PLATFORM_WIN32)
return true;
#endif
#if defined(AURORA_PLATFORM_LINUX)
//return true;
#endif
return false;
}
}

View File

@ -0,0 +1,30 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetSrvInterfaces.hpp
Date: 2022-11-14
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct NetSrvInterfaces : INetSrvInterfaces
{
const AuString &GetHostname() override;
void ResetAdapterCache() override;
AuList<AuSPtr<INetAdapter>> GetAdapters() override;
bool IsSupportedOnOS();
private:
void UpdateCache();
AuThreadPrimitives::SpinLock lock;
AuString hostname;
bool bShouldUpdateCache { true };
AuList<AuSPtr<INetAdapter>> adapters;
};
}

View File

@ -0,0 +1,22 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuFormatterContainer.cpp
Date: 2022-11-14
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "AuFormatterContainer.hpp"
namespace Aurora::Logging
{
AuSPtr<IFormatter> FormatterContainer::GetFormatter()
{
return this->pFormatter;
}
void FormatterContainer::SetFormatter(const AuSPtr<IFormatter> &pFormatter)
{
this->pFormatter = pFormatter;
}
}

View File

@ -0,0 +1,59 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuFormatterContainer.hpp
Date: 2022-11-14
Author: Reece
***/
#pragma once
namespace Aurora::Logging
{
struct FormatterContainer : IFormatterContainer
{
AuSPtr<IFormatter> GetFormatter() override;
void SetFormatter(const AuSPtr<IFormatter> &pFormatter) override;
AuSPtr<IFormatter> pFormatter;
};
}
#define ADD_FORMATTER_CONTAINER \
FormatterContainer formatter; \
AuString FormatMessageHelper(AuUInt8 level, \
const ConsoleMessage &msg, \
bool bConsoleMode, \
bool bPersistentString, \
bool bSimplified) \
{ \
if (auto pFormatter = this->formatter.GetFormatter()) \
{ \
return pFormatter->Format(level, msg); \
} \
else \
{ \
if (bConsoleMode) \
{ \
return msg.ToConsole(); \
} \
\
if (bPersistentString) \
{ \
return msg.ToPersistentString(); \
} \
\
if (bSimplified) \
{ \
return msg.ToSimplified(); \
} \
\
return msg.line; \
} \
} \
AuSPtr<IFormatter> GetFormatter() override \
{ \
return this->formatter.GetFormatter(); \
} \
void SetFormatter(const AuSPtr<IFormatter> &pFormatter) override \
{ \
this->formatter.SetFormatter(pFormatter); \
}

View File

@ -1,12 +1,12 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Sinks.cpp
File: AuLogSinks.cpp
Date: 2022-1-21
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Sinks.hpp"
#include "AuLogSinks.hpp"
#include "Sinks/FileSink.hpp"
#include "Sinks/StdConsole.hpp"
@ -28,12 +28,12 @@
namespace Aurora::Logging
{
AUKN_SYM IBasicSink *NewStdSinkNew()
AUKN_SYM IFormattedSink *NewStdSinkNew()
{
return Sinks::NewStdSinkNew();
}
AUKN_SYM void NewStdSinkRelease(IBasicSink *sink)
AUKN_SYM void NewStdSinkRelease(IFormattedSink *sink)
{
Sinks::NewStdSinkRelease(sink);
}
@ -88,12 +88,12 @@ namespace Aurora::Logging
}
AUKN_SYM IBasicSink *NewFileSinkNew(const AuString &path, bool binary)
AUKN_SYM IFormattedSink *NewFileSinkNew(const AuString &path, bool binary)
{
return Sinks::NewFileSinkNew(path, binary);
}
AUKN_SYM void NewFileSinkRelease(IBasicSink *sink)
AUKN_SYM void NewFileSinkRelease(IFormattedSink *sink)
{
Sinks::NewFileSinkRelease(sink);
}

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Sinks.hpp
File: AuLogSinks.hpp
Date: 2022-1-21
Author: Reece
***/

View File

@ -1,12 +1,12 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Logger.cpp
File: AuLogger.cpp
Date: 2022-1-21
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Logger.hpp"
#include "AuLogger.hpp"
#include <Source/Grug/AuGrug.hpp>
#include <Source/Console/Hooks/Hooks.hpp>
@ -24,7 +24,7 @@ namespace Aurora::Logging
AuMemset(shouldFilter, 0, sizeof(shouldFilter));
{
AU_LOCK_GUARD(gGlobalSpin);
AuTryInsert(gFlushableLoggers, this);
SysAssert(AuTryInsert(gFlushableLoggers, this));
}
}
@ -134,15 +134,8 @@ namespace Aurora::Logging
void Logger::PopFilter()
{
try
{
AU_LOCK_GUARD(spin);
filters.pop_back();
}
catch (...)
{
}
AU_LOCK_GUARD(this->spin);
this->filters.pop_back();
}
void ForceFlushLoggers()
@ -362,13 +355,13 @@ namespace Aurora::Logging
{
try
{
auto logger = _new Logger(sinks);
if (!logger)
auto pLogger = _new Logger(sinks);
if (!pLogger)
{
return nullptr;
}
return logger;
return pLogger;
}
catch (...)
{
@ -377,8 +370,8 @@ namespace Aurora::Logging
}
}
AUKN_SYM void NewLoggerRelease(ILogger *logger)
AUKN_SYM void NewLoggerRelease(ILogger *pLogger)
{
AuSafeDelete<Logger *>(logger);
AuSafeDelete<Logger *>(pLogger);
}
}

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Logger.hpp
File: AuLogger.hpp
Date: 2022-1-21
Author: Reece
***/

View File

@ -1,12 +1,12 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Logging.cpp
File: AuLogging.cpp
Date: 2022-1-21
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Logger.hpp"
#include "AuLogger.hpp"
#include <Source/Console/Hooks/Hooks.hpp>
#include <Source/Console/Console.hpp>

View File

@ -11,7 +11,8 @@
namespace Aurora::Logging::Sinks
{
static void EraseFilesByTimestamp(AuUInt32 maxLogs, const AuString &path, /*const its not worth reallocation*/ AuList<AuString> &files)
static void EraseFilesByTimestamp(AuUInt32 maxLogs,
const AuString &path, /*const its not worth reallocation*/ AuList<AuString> &files)
{
if (files.size() <= maxLogs)
{
@ -60,7 +61,9 @@ namespace Aurora::Logging::Sinks
// Didn't auRuntime v1.0 have this?
}
IBasicSink *NewDirectoryLoggerNew(const AuString &baseDirectory, DirectoryLogger meta, bool binary)
IBasicSink *NewDirectoryLoggerNew(const AuString &baseDirectory,
DirectoryLogger meta,
bool bBinary)
{
AuString path;
@ -72,11 +75,11 @@ namespace Aurora::Logging::Sinks
CleanupOldLogs(meta, baseDirectory);
return Sinks::NewFileSinkNew(path, binary);
return Sinks::NewFileSinkNew(path, bBinary);
}
void NewDirectoryLoggerRelease(IBasicSink *logger)
void NewDirectoryLoggerRelease(IBasicSink *pLogger)
{
Sinks::NewFileSinkRelease(logger);
Sinks::NewFileSinkRelease(AuStaticCast<IFormattedSink>(pLogger));
}
}

View File

@ -10,7 +10,9 @@
namespace Aurora::Logging::Sinks
{
FIOSink::FIOSink(const AuString &path, bool binary) : path_(path), binary_(binary)
FIOSink::FIOSink(const AuString &path, bool bBinary) :
path_(path),
bBinary_(bBinary)
{
}
@ -22,14 +24,14 @@ namespace Aurora::Logging::Sinks
return static_cast<bool>(this->file_) && static_cast<bool>(this->logMutex_);
}
void FIOSink::OnMessageBlocking(AuUInt8 level, const ConsoleMessage &msg)
void FIOSink::OnMessageBlocking(AuUInt8 uLevel, const ConsoleMessage &msg)
{
AU_LOCK_GUARD(this->logMutex_);
auto str = msg.ToPersistentString();
auto str = this->FormatMessageHelper(uLevel, msg, false, true, false);
auto startOffset = this->logBuffer_.GetWriteOffset();
if (this->binary_)
if (this->bBinary_)
{
msg.Write(this->logBuffer_);
}
@ -51,7 +53,8 @@ namespace Aurora::Logging::Sinks
}
}
bool FIOSink::OnMessageNonblocking(AuUInt8 level, const ConsoleMessage &msg)
bool FIOSink::OnMessageNonblocking(AuUInt8 uLevel,
const ConsoleMessage &msg)
{
return true;
}
@ -74,22 +77,22 @@ namespace Aurora::Logging::Sinks
this->logBuffer_.ResetPositions();
}
IBasicSink *NewFileSinkNew(const AuString &str, bool binary)
IFormattedSink *NewFileSinkNew(const AuString &str, bool bBinary)
{
try
{
auto logger = _new FIOSink(str, binary);
if (!logger)
auto pLogger = _new FIOSink(str, bBinary);
if (!pLogger)
{
return nullptr;
}
if (!logger->Init())
if (!pLogger->Init())
{
return nullptr;
}
return logger;
return pLogger;
}
catch (...)
{
@ -97,8 +100,8 @@ namespace Aurora::Logging::Sinks
}
}
void NewFileSinkRelease(IBasicSink *logger)
void NewFileSinkRelease(IFormattedSink *pLogger)
{
AuSafeDelete<FIOSink *>(logger);
AuSafeDelete<FIOSink *>(pLogger);
}
}

View File

@ -7,11 +7,13 @@
***/
#pragma once
#include "../AuFormatterContainer.hpp"
namespace Aurora::Logging::Sinks
{
struct FIOSink : IBasicSink
struct FIOSink : IFormattedSink
{
FIOSink(const AuString &path, bool binary);
FIOSink(const AuString &path, bool bBinary);
bool Init();
@ -22,11 +24,12 @@ namespace Aurora::Logging::Sinks
private:
const AuString path_;
AuIOFS::OpenWriteUnique_t file_;
bool binary_;
bool bBinary_;
AuByteBuffer logBuffer_;
AuThreadPrimitives::MutexUnique_t logMutex_;
ADD_FORMATTER_CONTAINER;
};
void NewFileSinkRelease(IBasicSink *logger);
IBasicSink *NewFileSinkNew(const AuString &str, bool binary);
void NewFileSinkRelease(IFormattedSink *logger);
IFormattedSink *NewFileSinkNew(const AuString &str, bool bBinary);
}

View File

@ -18,11 +18,11 @@ namespace Aurora::Logging::Sinks
if (Console::ConsoleTTY::gTTYConsoleEnabled)
{
Console::ConsoleTTY::WriteTTYOut(msg);
Console::ConsoleTTY::WriteTTYOut(msg, this->FormatMessageHelper(level, msg, true, false, false));
}
else
{
Console::ConsoleStd::WriteStdOut(level, msg);
Console::ConsoleStd::WriteStdOut(level, msg, this->FormatMessageHelper(level, msg, true, false, false));
}
}
@ -32,11 +32,11 @@ namespace Aurora::Logging::Sinks
if (Console::ConsoleTTY::gTTYConsoleEnabled)
{
Console::ConsoleTTY::WriteTTYOut(msg);
Console::ConsoleTTY::WriteTTYOut(msg, this->FormatMessageHelper(level, msg, true, false, false));
}
else
{
Console::ConsoleStd::WriteStdOut(level, msg);
Console::ConsoleStd::WriteStdOut(level, msg, this->FormatMessageHelper(level, msg, true, false, false));
}
return {};
@ -46,11 +46,11 @@ namespace Aurora::Logging::Sinks
void ConsoleStdLogger::OnFlush()
{}
IBasicSink *NewStdSinkNew()
IFormattedSink *NewStdSinkNew()
{
return &gStdConsoleSink;
}
void NewStdSinkRelease(IBasicSink *registry)
void NewStdSinkRelease(IFormattedSink *pSink)
{}
}

View File

@ -7,9 +7,11 @@
***/
#pragma once
#include "../AuFormatterContainer.hpp"
namespace Aurora::Logging::Sinks
{
struct ConsoleStdLogger : IBasicSink
struct ConsoleStdLogger : IFormattedSink
{
void OnMessageBlocking(AuUInt8 level, const ConsoleMessage &msg) override;
bool OnMessageNonblocking(AuUInt8 level, const ConsoleMessage &msg) override;
@ -17,10 +19,12 @@ namespace Aurora::Logging::Sinks
private:
//StringBuilder stringBuilder_;
ADD_FORMATTER_CONTAINER;
};
inline ConsoleStdLogger gStdConsoleSink;
IBasicSink *NewStdSinkNew();
void NewStdSinkRelease(IBasicSink *registry);
IFormattedSink *NewStdSinkNew();
void NewStdSinkRelease(IFormattedSink *registry);
}