Fixed the Logging system to actually be able to handle errors. Database is also fixed to use directories.

This commit is contained in:
Arron David Nelson 2024-04-23 22:29:49 -07:00
parent 2734cc00fb
commit f030ac62ae
61 changed files with 884 additions and 602 deletions

View File

@ -9,26 +9,53 @@
namespace ehs namespace ehs
{ {
class Log;
typedef void (*LogRaisedCb)(const Log &);
typedef void (*LogOutputCb)(const Array<Log> &);
enum class LogType : UInt_8
{
SUCCESS,
ERR,
WARN,
INFO
};
/// A helper class for holding error information and handling them. /// A helper class for holding error information and handling them.
/// @tparam T The character data type to use. /// @tparam T The character data type to use.
/// @tparam N The number data type to use. /// @tparam N The number data type to use.
class Log class Log
{ {
private: private:
static void (*logCb)(const Log&); static void DefaultRaisedCb(const Log &log);
static void DefaultOutputCb(const Array<Log> &logs);
static LogRaisedCb raisedCb;
static LogOutputCb outputCb;
static Array<Log> logs;
static Log lastLog; static Log lastLog;
static bool immediate;
LogType type;
Array<Str_8> tags; Array<Str_8> tags;
UInt_64 code; UInt_64 code;
Str_8 msg; Str_8 msg;
public: public:
static void SetCallback(void (*newLogCb)(const Log&)); static void SetRaisedCallback(LogRaisedCb newCb);
static void Raise(const Log& log); static void SetOutputCallback(LogOutputCb newCb);
static void OnExit();
static void Raise(Log log);
/// Retrieves the last log raised. /// Retrieves the last log raised.
static Log GetLastLog(); static Log GetLastLog();
static void EnableImmediateMode(bool enable);
/// Default members initialization. /// Default members initialization.
Log(); Log();
@ -36,18 +63,22 @@ namespace ehs
/// @param [in] tags The tags to associate this log with. /// @param [in] tags The tags to associate this log with.
/// @param [in] code The unique code to use. /// @param [in] code The unique code to use.
/// @param [in] msg Detailed information about what happened. /// @param [in] msg Detailed information about what happened.
Log(std::initializer_list<Str_8> tags, const UInt_64 code, const Str_8& msg); Log(LogType type, const std::initializer_list<Str_8> &tags, UInt_64 code, Str_8 msg);
/// Initializes members with the given information. /// Initializes members with the given information.
/// @param [in] tags The tags to associate this log with. /// @param [in] tags The tags to associate this log with.
/// @param [in] code The unique code to use. /// @param [in] code The unique code to use.
/// @param [in] msg Detailed information about what happened. /// @param [in] msg Detailed information about what happened.
Log(Array<Str_8>& tags, const UInt_64 code, const Str_8& msg); Log(LogType type, Array<Str_8> tags, UInt_64 code, Str_8 msg);
Log(Log &&log) noexcept;
/// Copies all members from the given log. /// Copies all members from the given log.
/// @param [in] log The log to copy from. /// @param [in] log The log to copy from.
Log(const Log &log); Log(const Log &log);
Log &operator=(Log &&log) noexcept;
/// Copies all members from the given log. /// Copies all members from the given log.
/// @param [in] log The log to copy from. /// @param [in] log The log to copy from.
/// @returns The log that has been assigned to. /// @returns The log that has been assigned to.
@ -65,10 +96,12 @@ namespace ehs
bool operator!=(const Log log); bool operator!=(const Log log);
*/ */
LogType GetType() const;
/// Checks whether or not this log has the given tags. /// Checks whether or not this log has the given tags.
/// @param [in] tags The tags to look for. /// @param [in] tags The tags to look for.
/// @returns True if all tags were found, otherwise false. /// @returns True if all tags were found, otherwise false.
bool HasTags(const std::initializer_list<Str_8> tags) const; bool HasTags(const std::initializer_list<Str_8> &tags) const;
/// Checks whether or not this log has the given tags. /// Checks whether or not this log has the given tags.
/// @param [in] tags The tags to look for. /// @param [in] tags The tags to look for.
@ -82,7 +115,7 @@ namespace ehs
/// Retrieves all the tags. /// Retrieves all the tags.
/// @returns The result. /// @returns The result.
Array<Str_8> GetTags() const; const Array<Str_8> &GetTags() const;
UInt_64 GetCode() const; UInt_64 GetCode() const;
@ -101,16 +134,20 @@ namespace ehs
#ifndef EHS_LOG_INT #ifndef EHS_LOG_INT
#ifdef EHS_DEBUG #ifdef EHS_DEBUG
#define EHS_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), EHS_FILE, EHS_FUNC, Str_8::FromNum((UInt_32)EHS_LINE)}, code, msg}) #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
#else #else
#define EHS_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), EHS_FUNC}, code, msg}) #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FUNC}, code, msg})
#endif #endif
#endif #endif
#ifndef EHS_LOG #ifndef EHS_LOG
#ifdef EHS_DEBUG #ifdef EHS_DEBUG
#define EHS_LOG(type, code, msg) ehs::Log::Raise({{type, ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg}) #define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
#else #else
#define EHS_LOG(type, code, msg) ehs::Log::Raise({{type, ehs::GetAppName_8(), EHS_FUNC}, code, msg}) #define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FUNC}, code, msg})
#endif #endif
#endif #endif
#ifndef EHS_LOG_SUCCESS
#define EHS_LOG_SUCCESS() ehs::Log::Raise({})
#endif

View File

@ -130,7 +130,7 @@ namespace ehs
case 3: case 3:
return h; return h;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
return x; return x;
} }
} }
@ -148,7 +148,7 @@ namespace ehs
case 3: case 3:
return h; return h;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
return x; return x;
} }
} }

View File

@ -87,7 +87,7 @@ namespace ehs
{ {
if (index >= size) if (index >= size)
{ {
EHS_LOG_INT("Warning", 0, "Cannot insert value at " + Str_8::FromNum(index) + " because it is outside of array range of " + size + "."); EHS_LOG_INT(LogType::WARN, 0, "Cannot insert value at " + Str_8::FromNum(index) + " because it is outside of array range of " + size + ".");
return; return;
} }

View File

@ -1075,7 +1075,7 @@ namespace ehs
return result; return result;
} }
template<typename T, typename O> template<typename T = Char_8, typename O = UInt_64>
Str<T, O> ReadStr(O size = 0) Str<T, O> ReadStr(O size = 0)
{ {
bool sizeKnown = size; bool sizeKnown = size;

View File

@ -229,7 +229,7 @@ namespace ehs
case 1: case 1:
return y; return y;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
return x; return x;
} }
} }
@ -243,7 +243,7 @@ namespace ehs
case 1: case 1:
return y; return y;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
return x; return x;
} }
} }

View File

@ -266,7 +266,7 @@ namespace ehs
case 2: case 2:
return z; return z;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
return x; return x;
} }
} }
@ -282,7 +282,7 @@ namespace ehs
case 2: case 2:
return z; return z;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
return x; return x;
} }
} }

View File

@ -279,7 +279,7 @@ namespace ehs
case 3: case 3:
return w; return w;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
return x; return x;
} }
} }
@ -297,7 +297,7 @@ namespace ehs
case 3: case 3:
return w; return w;
default: default:
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4."); EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
return x; return x;
} }
} }

View File

@ -12,13 +12,14 @@ namespace ehs
Str_8 id; Str_8 id;
Version version; Version version;
Array<DbTable> tables; Array<DbTable> tables;
Str_8 dir;
public: public:
Database(); Database();
Database(Str_8 id, const Version& version); Database(Str_8 id, const Version& version);
Database(const Str_8& filePath); Database(Str_8 filePath);
Database(Database&& db) noexcept; Database(Database&& db) noexcept;
@ -48,6 +49,8 @@ namespace ehs
DbTable* GetTable(const Str_8& id) const; DbTable* GetTable(const Str_8& id) const;
void Save(const Str_8& directory) const; Str_8 GetDirectory() const;
void Save(Str_8 directory);
}; };
} }

View File

@ -8,12 +8,16 @@
namespace ehs namespace ehs
{ {
class Database;
class DbTable class DbTable
{ {
private: private:
friend class Database; friend class Database;
friend class DbVar; friend class DbVar;
friend class DbObject;
Database *parent;
UInt_64 hashId; UInt_64 hashId;
Str_8 id; Str_8 id;
Array<DbVarTmpl> varTmpls; Array<DbVarTmpl> varTmpls;
@ -55,8 +59,8 @@ namespace ehs
private: private:
DbVarTmpl *GetVariableTemplate(UInt_64 hashId) const; DbVarTmpl *GetVariableTemplate(UInt_64 hashId) const;
void Serialize(Serializer<UInt_64>& data) const; void Serialize(const Str_8 &dir, Serializer<UInt_64>& data) const;
void Deserialize(Serializer<UInt_64>& data); void Deserialize(const Str_8 &dir, Serializer<UInt_64>& data);
}; };
} }

View File

@ -9,5 +9,9 @@ namespace ehs
{ {
public: public:
static Array<Str_8> GetAllFiles(const Str_8 &dir); static Array<Str_8> GetAllFiles(const Str_8 &dir);
static void CreateRecursive(Str_8 dir);
static void Create(const Str_8 &dir);
}; };
} }

View File

@ -8,5 +8,9 @@ namespace ehs
{ {
public: public:
static Array<Str_8> GetAllFiles(const Str_8 &dir); static Array<Str_8> GetAllFiles(const Str_8 &dir);
static void CreateRecursive(Str_8 dir);
static void Create(const Str_8 &dir);
}; };
} }

View File

@ -97,30 +97,10 @@ namespace ehs
} }
} }
void LogRaised(const ehs::Log& log)
{
ehs::Array<ehs::Str_8> tags = log.GetTags();
ehs::Str_8 result = "{";
for (ehs::UInt_32 i = 0; i < tags.Size(); ++i)
{
result += tags[i];
if (i != tags.Size() - 1)
result += ", ";
}
result += "} (" + ehs::Str_8::FromNum(log.GetCode()) + "): " + log.GetMsg();
ehs::Console::Write_8(result);
}
int main() int main()
{ {
ehs::Console::Attach(); ehs::Console::Attach();
ehs::Log::SetCallback(LogRaised);
ehs::Audio::AddCodec({ ehs::Audio::AddCodec({
"Waveform Audio", "Waveform Audio",
"wav", "wav",
@ -165,9 +145,11 @@ int main()
const ehs::SInt_32 code = Main(&ehs::appName, &ehs::appVerId, &ehs::appVer); const ehs::SInt_32 code = Main(&ehs::appName, &ehs::appVerId, &ehs::appVer);
if (code) if (code)
EHS_LOG("Warning", 0, "Executable exited with code #" + ehs::Str_8::FromNum(code) + "."); EHS_LOG_INT(ehs::LogType::WARN, 0, "Executable exited with code #" + ehs::Str_8::FromNum(code) + ".");
ehs::GarbageCollector::Stop(); ehs::GarbageCollector::Stop();
ehs::Log::OnExit();
return code; return code;
} }

View File

@ -60,7 +60,7 @@ namespace ehs
/* /*
if (Has(obj)) if (Has(obj))
{ {
EHS_LOG_INT("Warning", 1, obj->GetTypeId() + " object with address of, \"" + Str_8::FromNum<USize>((USize)obj) + "\" is already in garbage."); EHS_LOG_INT(LogType::WARN, 1, obj->GetTypeId() + " object with address of, \"" + Str_8::FromNum<USize>((USize)obj) + "\" is already in garbage.");
return; return;
} }
*/ */

View File

@ -1,51 +1,119 @@
#include "ehs/Log.h" #include "ehs/Log.h"
#include "ehs/io/Console.h"
#include "ehs/io/File.h"
namespace ehs namespace ehs
{ {
void (*Log::logCb)(const Log&) = nullptr; void Log::DefaultRaisedCb(const Log &log)
Log Log::lastLog;
void Log::SetCallback(void (*newLogCb)(const Log&))
{ {
logCb = newLogCb; Console::Write_8(log.ToStr());
} }
void Log::Raise(const Log& log) void Log::DefaultOutputCb(const Array<Log> &logs)
{ {
if (logCb) File output("Logs.txt", Mode::WRITE, Disposition::CREATE_PERSISTENT);
logCb(log); output.SeekBeginning();
lastLog = log; for (UInt_64 i = 0; i < logs.Size(); ++i)
output.WriteStr_8(logs[i].ToStr() + "\n");
}
LogRaisedCb Log::raisedCb = DefaultRaisedCb;
LogOutputCb Log::outputCb = DefaultOutputCb;
Array<Log> Log::logs;
Log Log::lastLog;
bool Log::immediate = false;
void Log::SetRaisedCallback(const LogRaisedCb newCb)
{
raisedCb = newCb;
}
void Log::SetOutputCallback(const LogOutputCb newCb)
{
outputCb = newCb;
}
void Log::OnExit()
{
if (lastLog.GetType() != LogType::SUCCESS)
logs.Push(lastLog);
lastLog = {};
if (outputCb)
outputCb(logs);
}
void Log::Raise(Log log)
{
if (log.GetType() == LogType::INFO || (log.GetType() != LogType::SUCCESS && immediate))
if (raisedCb)
raisedCb(log);
if (lastLog.GetType() != LogType::SUCCESS)
logs.Push((Log&&)lastLog);
lastLog = (Log&&)log;
} }
Log Log::GetLastLog() Log Log::GetLastLog()
{ {
Log result = lastLog; Log result = lastLog;
lastLog = Log(); lastLog = {};
return result; return result;
} }
void Log::EnableImmediateMode(const bool enable)
{
immediate = enable;
}
Log::Log() Log::Log()
: code(0) : type(LogType::SUCCESS), code(0)
{ {
} }
Log::Log(std::initializer_list<Str_8> tags, const UInt_64 code, const Str_8& msg) Log::Log(LogType type, const std::initializer_list<Str_8> &tags, const UInt_64 code, Str_8 msg)
: tags(tags.size()), code(code), msg(msg) : type(type), tags(tags.size()), code(code), msg((Str_8&&)msg)
{ {
UInt_64 i = 0; UInt_64 i = 0;
for (auto v = tags.begin(); v != tags.end(); ++v) for (auto v = tags.begin(); v != tags.end(); ++v)
this->tags[i++] = *v; this->tags[i++] = *v;
} }
Log::Log(Array<Str_8>& tags, const UInt_64 code, const Str_8& msg) Log::Log(LogType type, Array<Str_8> tags, const UInt_64 code, Str_8 msg)
: tags(tags), code(code), msg(msg) : type(type), tags((Array<Str_8>&&)tags), code(code), msg((Str_8&&)msg)
{ {
} }
Log::Log(const Log& log) Log::Log(Log &&log) noexcept
: tags(log.tags), code(log.code), msg(log.msg) : type(log.type), tags((Array<Str_8>&&)log.tags), code(log.code), msg((Str_8&&)log.msg)
{ {
log.type = LogType::INFO;
log.code = 0;
}
Log::Log(const Log &log)
: type(log.type), tags(log.tags), code(log.code), msg(log.msg)
{
}
Log & Log::operator=(Log &&log) noexcept
{
if (this == &log)
return *this;
type = log.type;
tags = (Array<Str_8>&&)log.tags;
code = log.code;
msg = (Str_8&&)log.msg;
log.type = LogType::INFO;
log.code = 0;
return *this;
} }
Log& Log::operator=(const Log &log) Log& Log::operator=(const Log &log)
@ -53,6 +121,7 @@ namespace ehs
if (this == &log) if (this == &log)
return *this; return *this;
type = log.type;
tags = log.tags; tags = log.tags;
code = log.code; code = log.code;
msg = log.msg; msg = log.msg;
@ -72,7 +141,12 @@ namespace ehs
} }
*/ */
bool Log::HasTags(const std::initializer_list<Str_8> tags) const LogType Log::GetType() const
{
return type;
}
bool Log::HasTags(const std::initializer_list<Str_8> &tags) const
{ {
UInt_64 i = 0; UInt_64 i = 0;
UInt_64 c = 0; UInt_64 c = 0;
@ -110,7 +184,7 @@ namespace ehs
return false; return false;
} }
Array<Str_8> Log::GetTags() const const Array<Str_8> &Log::GetTags() const
{ {
return tags; return tags;
} }
@ -127,7 +201,32 @@ namespace ehs
Str_8 Log::ToStr() const Str_8 Log::ToStr() const
{ {
Str_8 result = "["; Str_8 result = "<";
switch (type)
{
case LogType::SUCCESS:
{
result += "Success";
break;
}
case LogType::ERR:
{
result += "Error";
break;
}
case LogType::WARN:
{
result += "Warning";
break;
}
case LogType::INFO:
{
result += "Information";
}
}
result += ">[";
for (UInt_64 i = 0; i < tags.Size(); ++i) for (UInt_64 i = 0; i < tags.Size(); ++i)
{ {

View File

@ -189,7 +189,7 @@ namespace ehs
{ {
if (working) if (working)
{ {
EHS_LOG_INT("Warning", 0, "Attempted to give work while task is still working."); EHS_LOG_INT(LogType::WARN, 0, "Attempted to give work while task is still working.");
return; return;
} }

View File

@ -1,4 +1,6 @@
#include "ehs/db/Database.h" #include "ehs/db/Database.h"
#include "ehs/io/Directory_LNX.h"
#include "ehs/io/File.h" #include "ehs/io/File.h"
namespace ehs namespace ehs
@ -13,9 +15,25 @@ namespace ehs
{ {
} }
Database::Database(const Str_8& filePath) Database::Database(Str_8 filePath)
{ {
filePath = filePath.ReplaceAll("\\", "/");
UInt_64 i = 0;
if (filePath.Find("/", &i, SearchPattern::RIGHT_LEFT))
dir = filePath.Sub(0, i);
else
dir = "./";
File file(filePath, Mode::READ, Disposition::OPEN); File file(filePath, Mode::READ, Disposition::OPEN);
Log log = Log::GetLastLog();
if (log.GetType() == LogType::ERR && log.GetCode() == 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Database file not found at, \"" + filePath + "\".");
return;
}
id = file.GetName(); id = file.GetName();
hashId = id.Hash_64(); hashId = id.Hash_64();
Serializer<UInt_64> data = file.ReadSerializer_64(Endianness::LE, file.Size()); Serializer<UInt_64> data = file.ReadSerializer_64(Endianness::LE, file.Size());
@ -25,19 +43,30 @@ namespace ehs
tables.Resize(data.Read<UInt_64>()); tables.Resize(data.Read<UInt_64>());
for (UInt_64 i = 0; i < tables.Size(); ++i) for (UInt_64 i = 0; i < tables.Size(); ++i)
tables[i].Deserialize(data); {
tables[i].parent = this;
tables[i].Deserialize(dir, data);
}
EHS_LOG_SUCCESS();
} }
Database::Database(Database&& db) noexcept Database::Database(Database&& db) noexcept
: hashId(db.hashId), id((Str_8&&)db.id), version(db.version), tables((Array<DbTable>&&)db.tables) : hashId(db.hashId), id((Str_8&&)db.id), version(db.version), tables((Array<DbTable>&&)db.tables),
dir((Str_8&&)db.dir)
{ {
for (UInt_64 i = 0; i < tables.Size(); ++i)
tables[i].parent = this;
db.hashId = 0; db.hashId = 0;
db.version = {0, 0, 0}; db.version = {0, 0, 0};
} }
Database::Database(const Database& db) Database::Database(const Database& db)
: hashId(db.hashId), id(db.id), version(db.version), tables(db.tables) : hashId(db.hashId), id(db.id), version(db.version), tables(db.tables), dir(db.dir)
{ {
for (UInt_64 i = 0; i < tables.Size(); ++i)
tables[i].parent = this;
} }
Database& Database::operator=(Database&& db) noexcept Database& Database::operator=(Database&& db) noexcept
@ -48,7 +77,12 @@ namespace ehs
hashId = db.hashId; hashId = db.hashId;
id = (Str_8&&)db.id; id = (Str_8&&)db.id;
version = db.version; version = db.version;
tables = (Array<DbTable>&&)db.tables; tables = (Array<DbTable>&&)db.tables;
for (UInt_64 i = 0; i < tables.Size(); ++i)
tables[i].parent = this;
dir = (Str_8&&)db.dir;
db.hashId = 0; db.hashId = 0;
db.version = {0, 0, 0}; db.version = {0, 0, 0};
@ -64,7 +98,12 @@ namespace ehs
hashId = db.hashId; hashId = db.hashId;
id = db.id; id = db.id;
version = db.version; version = db.version;
tables = db.tables; tables = db.tables;
for (UInt_64 i = 0; i < tables.Size(); ++i)
tables[i].parent = this;
dir = db.dir;
return *this; return *this;
} }
@ -116,7 +155,9 @@ namespace ehs
tables.Push(DbTable((Str_8&&)id)); tables.Push(DbTable((Str_8&&)id));
return &tables[tables.End()]; DbTable *tbl = &tables[tables.End()];
tbl->parent = this;
return tbl;
} }
DbTable* Database::GetTable(UInt_64 hashId) const DbTable* Database::GetTable(UInt_64 hashId) const
@ -133,16 +174,25 @@ namespace ehs
return GetTable(id.Hash_64()); return GetTable(id.Hash_64());
} }
void Database::Save(const Str_8& directory) const Str_8 Database::GetDirectory() const
{ {
return dir;
}
void Database::Save(Str_8 directory)
{
dir = (Str_8&&)directory;
Serializer<UInt_64> data(Endianness::LE); Serializer<UInt_64> data(Endianness::LE);
data.WriteVersion(version); data.WriteVersion(version);
data.Write(tables.Size()); data.Write(tables.Size());
for (UInt_64 i = 0; i < tables.Size(); ++i) Directory::CreateRecursive(dir);
tables[i].Serialize(data);
File file(directory + "/" + id + ".ehd", Mode::WRITE, Disposition::CREATE_PERSISTENT); for (UInt_64 i = 0; i < tables.Size(); ++i)
tables[i].Serialize(dir, data);
File file(dir + "/" + id + ".ehd", Mode::WRITE, Disposition::CREATE_PERSISTENT);
file.WriteSerializer_64(data); file.WriteSerializer_64(data);
} }
} }

View File

@ -1,6 +1,8 @@
#include "ehs/db/DbObject.h" #include "ehs/db/DbObject.h"
#include "ehs/db/DbTable.h" #include "ehs/db/DbTable.h"
#include "ehs/Serializer.h" #include "ehs/Serializer.h"
#include "ehs/db/Database.h"
#include "ehs/io/Directory_LNX.h"
#include "ehs/io/File.h" #include "ehs/io/File.h"
namespace ehs namespace ehs
@ -100,7 +102,9 @@ namespace ehs
for (UInt_64 i = 0; i < vars.Size(); ++i) for (UInt_64 i = 0; i < vars.Size(); ++i)
vars[i].Serialize(data); vars[i].Serialize(data);
File file(parent->GetId() + "/" + Str_8::FromNum(id) + ".eho", Mode::WRITE, Disposition::CREATE_PERSISTENT); Directory::CreateRecursive(parent->parent->GetDirectory() + "/" + parent->GetId());
File file(parent->parent->GetDirectory() + "/" + parent->GetId() + "/" + Str_8::FromNum(id) + ".eho", Mode::WRITE, Disposition::CREATE_PERSISTENT);
file.SeekBeginning(); file.SeekBeginning();
file.WriteSerializer_64(data); file.WriteSerializer_64(data);
} }
@ -110,7 +114,7 @@ namespace ehs
if (IsLoaded()) if (IsLoaded())
return; return;
File file(parent->GetId() + "/" + Str_8::FromNum(id) + ".eho", Mode::READ, Disposition::OPEN); File file(parent->parent->GetDirectory() + "/" + parent->GetId() + "/" + Str_8::FromNum(id) + ".eho", Mode::READ, Disposition::OPEN);
Serializer<UInt_64> data = file.ReadSerializer_64(Endianness::LE, file.Size()); Serializer<UInt_64> data = file.ReadSerializer_64(Endianness::LE, file.Size());
file.Release(); file.Release();

View File

@ -1,28 +1,30 @@
#include "ehs/db/DbTable.h" #include "ehs/db/DbTable.h"
#include "ehs/db/Database.h"
#include "ehs/io/Directory.h" #include "ehs/io/Directory.h"
#include "ehs/io/File_UNX.h" #include "ehs/io/File_UNX.h"
namespace ehs namespace ehs
{ {
DbTable::DbTable() DbTable::DbTable()
: hashId(0) : parent(nullptr), hashId(0)
{ {
} }
DbTable::DbTable(Str_8 id) DbTable::DbTable(Str_8 id)
: hashId(id.Hash_64()), id((Str_8&&)id) : parent(nullptr), hashId(id.Hash_64()), id((Str_8&&)id)
{ {
} }
DbTable::DbTable(DbTable&& table) noexcept DbTable::DbTable(DbTable&& table) noexcept
: hashId(table.hashId), id((Str_8&&)table.id), varTmpls((Array<DbVarTmpl>&&)table.varTmpls), : parent(table.parent), hashId(table.hashId), id((Str_8&&)table.id), varTmpls((Array<DbVarTmpl>&&)table.varTmpls),
objects((Array<DbObject>&&)table.objects) objects((Array<DbObject>&&)table.objects)
{ {
table.parent = nullptr;
table.hashId = 0; table.hashId = 0;
} }
DbTable::DbTable(const DbTable& table) DbTable::DbTable(const DbTable& table)
: hashId(table.hashId), id(table.id), varTmpls(table.varTmpls), objects(table.objects) : parent(nullptr), hashId(table.hashId), id(table.id), varTmpls(table.varTmpls), objects(table.objects)
{ {
} }
@ -31,14 +33,16 @@ namespace ehs
if (this == &table) if (this == &table)
return *this; return *this;
parent = table.parent;
hashId = table.hashId; hashId = table.hashId;
id = (Str_8&&)table.id; id = (Str_8&&)table.id;
varTmpls = (Array<DbVarTmpl>&&)table.varTmpls; varTmpls = (Array<DbVarTmpl>&&)table.varTmpls;
objects = (Array<DbObject>&&)table.objects;
objects = (Array<DbObject>&&)table.objects;
for (UInt_64 i = 0; i < objects.Size(); ++i) for (UInt_64 i = 0; i < objects.Size(); ++i)
objects[i].parent = this; objects[i].parent = this;
table.parent = nullptr;
table.hashId = 0; table.hashId = 0;
return *this; return *this;
@ -49,11 +53,12 @@ namespace ehs
if (this == &table) if (this == &table)
return *this; return *this;
parent = nullptr;
hashId = table.hashId; hashId = table.hashId;
id = table.id; id = table.id;
varTmpls = table.varTmpls; varTmpls = table.varTmpls;
objects = table.objects;
objects = table.objects;
for (UInt_64 i = 0; i < objects.Size(); ++i) for (UInt_64 i = 0; i < objects.Size(); ++i)
objects[i].parent = this; objects[i].parent = this;
@ -158,7 +163,7 @@ namespace ehs
return nullptr; return nullptr;
} }
void DbTable::Serialize(Serializer<UInt_64>& data) const void DbTable::Serialize(const Str_8 &dir, Serializer<UInt_64>& data) const
{ {
data.WriteStr(id); data.WriteStr(id);
data.Write(varTmpls.Size()); data.Write(varTmpls.Size());
@ -166,11 +171,14 @@ namespace ehs
for (UInt_64 i = 0; i < varTmpls.Size(); ++i) for (UInt_64 i = 0; i < varTmpls.Size(); ++i)
varTmpls[i].Serialize(data); varTmpls[i].Serialize(data);
if (objects.Size())
Directory::Create(dir + "/" + id);
for (UInt_64 i = 0; i < objects.Size(); ++i) for (UInt_64 i = 0; i < objects.Size(); ++i)
objects[i].Save(); objects[i].Save();
} }
void DbTable::Deserialize(Serializer<UInt_64>& data) void DbTable::Deserialize(const Str_8 &dir, Serializer<UInt_64>& data)
{ {
id = data.ReadStr<Char_8, UInt_64>(); id = data.ReadStr<Char_8, UInt_64>();
hashId = id.Hash_64(); hashId = id.Hash_64();
@ -180,7 +188,7 @@ namespace ehs
for (UInt_64 i = 0; i < varTmpls.Size(); ++i) for (UInt_64 i = 0; i < varTmpls.Size(); ++i)
varTmpls[i].Deserialize(data); varTmpls[i].Deserialize(data);
Array<Str_8> files = Directory::GetAllFiles(id); Array<Str_8> files = Directory::GetAllFiles(dir + "/" + id);
for (UInt_64 i = 0; i < files.Size(); ++i) for (UInt_64 i = 0; i < files.Size(); ++i)
{ {
if (File::ParseExt_8(files[i]) != "eho") if (File::ParseExt_8(files[i]) != "eho")

View File

@ -9,7 +9,7 @@ namespace ehs
} }
DbVarTmpl::DbVarTmpl() DbVarTmpl::DbVarTmpl()
: hashId(0), size(0), def(nullptr) : hashId(0), def(nullptr), size(0)
{ {
} }
@ -40,12 +40,12 @@ namespace ehs
hashId = varTmpl.hashId; hashId = varTmpl.hashId;
id = (Str_8&&)varTmpl.id; id = (Str_8&&)varTmpl.id;
size = varTmpl.size;
def = varTmpl.def; def = varTmpl.def;
size = varTmpl.size;
varTmpl.hashId = 0; varTmpl.hashId = 0;
varTmpl.size = 0;
varTmpl.def = nullptr; varTmpl.def = nullptr;
varTmpl.size = 0;
return *this; return *this;
} }
@ -59,8 +59,8 @@ namespace ehs
hashId = varTmpl.hashId; hashId = varTmpl.hashId;
id = varTmpl.id; id = varTmpl.id;
size = varTmpl.size;
def = new Byte[varTmpl.size]; def = new Byte[varTmpl.size];
size = varTmpl.size;
Util::Copy(def, varTmpl.def, varTmpl.size); Util::Copy(def, varTmpl.def, varTmpl.size);
@ -106,6 +106,14 @@ namespace ehs
size = 0; size = 0;
data.ReadArray(def, &size); data.ReadArray(def, &size);
delete[] def;
if (!size)
{
def = nullptr;
return;
}
def = new Byte[size]; def = new Byte[size];
data.ReadArray(def, &size); data.ReadArray(def, &size);
} }

View File

@ -1,9 +1,23 @@
#include "ehs/io/BaseDirectory.h" #include "ehs/io/BaseDirectory.h"
#include "ehs/Log.h"
namespace ehs namespace ehs
{ {
Array<Str_8> BaseDirectory::GetAllFiles(const Str_8 &dir) Array<Str_8> BaseDirectory::GetAllFiles(const Str_8 &dir)
{ {
EHS_LOG_INT(LogType::ERR, 0, "The feature is not supported for this operating system.");
return {}; return {};
} }
void BaseDirectory::CreateRecursive(Str_8 dir)
{
EHS_LOG_INT(LogType::ERR, 0, "The feature is not supported for this operating system.");
}
void BaseDirectory::Create(const Str_8 &dir)
{
EHS_LOG_INT(LogType::ERR, 0, "The feature is not supported for this operating system.");
}
} }

View File

@ -52,7 +52,7 @@ namespace ehs
UInt_64 written = Write(&((Byte*)str)[total], size - total); UInt_64 written = Write(&((Byte*)str)[total], size - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(size) + ")."); Str_8::FromNum(size) + ").");
break; break;
} }
@ -74,7 +74,7 @@ namespace ehs
UInt_64 written = Write(&str.ToBytes()[total], str.Size(true) - total); UInt_64 written = Write(&str.ToBytes()[total], str.Size(true) - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(str.Size()) + ")."); Str_8::FromNum(str.Size()) + ").");
break; break;
} }
@ -96,7 +96,7 @@ namespace ehs
UInt_64 written = Write(&((Byte*)str)[total], size - total); UInt_64 written = Write(&((Byte*)str)[total], size - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(size) + ")."); Str_8::FromNum(size) + ").");
break; break;
} }
@ -118,7 +118,7 @@ namespace ehs
UInt_64 written = Write(&str.ToBytes()[total], str.Size(true) - total); UInt_64 written = Write(&str.ToBytes()[total], str.Size(true) - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(str.Size()) + ")."); Str_8::FromNum(str.Size()) + ").");
break; break;
} }
@ -140,7 +140,7 @@ namespace ehs
UInt_64 written = Write(&((Byte*)str)[total], size - total); UInt_64 written = Write(&((Byte*)str)[total], size - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(size) + ")."); Str_8::FromNum(size) + ").");
break; break;
} }
@ -162,7 +162,7 @@ namespace ehs
UInt_64 written = Write(&str.ToBytes()[total], str.Size(true) - total); UInt_64 written = Write(&str.ToBytes()[total], str.Size(true) - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(str.Size()) + ")."); Str_8::FromNum(str.Size()) + ").");
break; break;
} }
@ -184,7 +184,7 @@ namespace ehs
UInt_64 written = Write(&vec[total], vec.Size() - total); UInt_64 written = Write(&vec[total], vec.Size() - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(vec.Size()) + ")."); Str_8::FromNum(vec.Size()) + ").");
break; break;
} }
@ -206,7 +206,7 @@ namespace ehs
UInt_64 written = Write(&arr[total], arr.Size() - total); UInt_64 written = Write(&arr[total], arr.Size() - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(arr.Size()) + ")."); Str_8::FromNum(arr.Size()) + ").");
break; break;
} }
@ -228,7 +228,7 @@ namespace ehs
UInt_64 written = Write(&ser[total], ser.Size() - total); UInt_64 written = Write(&ser[total], ser.Size() - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(ser.Size()) + ")."); Str_8::FromNum(ser.Size()) + ").");
break; break;
} }
@ -250,7 +250,7 @@ namespace ehs
UInt_64 written = Write(&ser[total], ser.Size() - total); UInt_64 written = Write(&ser[total], ser.Size() - total);
if (!written) if (!written)
{ {
EHS_LOG_INT("Error", 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" + EHS_LOG_INT(LogType::ERR, 0, "Failed to write all data (" + Str_8::FromNum(total) + "/" +
Str_8::FromNum(ser.Size()) + ")."); Str_8::FromNum(ser.Size()) + ").");
break; break;
} }

View File

@ -24,7 +24,7 @@ namespace ehs
nullptr); nullptr);
if (hdl == INVALID_HANDLE_VALUE) if (hdl == INVALID_HANDLE_VALUE)
{ {
EHS_LOG_INT("Error", 0, "Failed to create handle at COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create handle at COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -33,7 +33,7 @@ namespace ehs
if (!GetCommState(hdl, &dcb)) if (!GetCommState(hdl, &dcb))
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve COM" + Str_8::FromNum(port) + " state with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve COM" + Str_8::FromNum(port) + " state with error #" + Str_8::FromNum(GetLastError()) + ".");
UnInitialize(); UnInitialize();
return; return;
} }
@ -46,7 +46,7 @@ namespace ehs
if (!SetCommState(hdl, &dcb)) if (!SetCommState(hdl, &dcb))
{ {
EHS_LOG_INT("Error", 2, "Failed to set COM" + Str_8::FromNum(port) + " state with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to set COM" + Str_8::FromNum(port) + " state with error #" + Str_8::FromNum(GetLastError()) + ".");
UnInitialize(); UnInitialize();
return; return;
} }
@ -63,7 +63,7 @@ namespace ehs
if (hdl) if (hdl)
{ {
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
EHS_LOG_INT("Error", 0, "Failed to close COM" + Str_8::FromNum(port) + " handle with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close COM" + Str_8::FromNum(port) + " handle with error #" + Str_8::FromNum(GetLastError()) + ".");
hdl = nullptr; hdl = nullptr;
} }
@ -77,7 +77,7 @@ namespace ehs
if (!WaitCommEvent(hdl, (DWORD*)&event, nullptr)) if (!WaitCommEvent(hdl, (DWORD*)&event, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed to wait for COM" + Str_8::FromNum(port) + " event with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to wait for COM" + Str_8::FromNum(port) + " event with error #" + Str_8::FromNum(GetLastError()) + ".");
UnInitialize(); UnInitialize();
} }
@ -91,7 +91,7 @@ namespace ehs
if (!TransmitCommChar(hdl, data)) if (!TransmitCommChar(hdl, data))
{ {
EHS_LOG_INT("Error", 0, "Failed to transmit character to COM" + Str_8::FromNum(port) + " with error #" + EHS_LOG_INT(LogType::ERR, 0, "Failed to transmit character to COM" + Str_8::FromNum(port) + " with error #" +
Str_8::FromNum(GetLastError()) + "."); Str_8::FromNum(GetLastError()) + ".");
UnInitialize(); UnInitialize();
} }
@ -103,7 +103,7 @@ namespace ehs
if (!WriteFile(hdl, (void*)data, (DWORD)size, (DWORD*)&sent, nullptr)) if (!WriteFile(hdl, (void*)data, (DWORD)size, (DWORD*)&sent, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed to receive data from COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data from COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + ".");
UnInitialize(); UnInitialize();
} }
@ -116,7 +116,7 @@ namespace ehs
if (!ReadFile(hdl, (void*)data, (DWORD)size, (DWORD*)&received, nullptr)) if (!ReadFile(hdl, (void*)data, (DWORD)size, (DWORD*)&received, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed to receive data from COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data from COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + ".");
UnInitialize(); UnInitialize();
} }
@ -127,7 +127,7 @@ namespace ehs
{ {
if (!FlushFileBuffers(hdl)) if (!FlushFileBuffers(hdl))
{ {
EHS_LOG_INT("Error", 0, "Failed to flush data for COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to flush data for COM" + Str_8::FromNum(port) + " with error #" + Str_8::FromNum(GetLastError()) + ".");
UnInitialize(); UnInitialize();
} }
} }

View File

@ -41,7 +41,7 @@ namespace ehs
{ {
//DWORD code = WaitForSingleObject(hdlIn, 15000); //DWORD code = WaitForSingleObject(hdlIn, 15000);
//if (code == WAIT_FAILED || code == WAIT_TIMEOUT || code == WAIT_ABANDONED) //if (code == WAIT_FAILED || code == WAIT_TIMEOUT || code == WAIT_ABANDONED)
// EHS_LOG_INT("Error", 0, "Failed to wait for console input."); // EHS_LOG_INT(LogType::ERR, 0, "Failed to wait for console input.");
isConsole = true; isConsole = true;
} }
@ -63,10 +63,10 @@ namespace ehs
hdlOut = GetStdHandle(STD_OUTPUT_HANDLE); hdlOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (WaitForSingleObject(hdlIn, EHS_INFINITE) == WAIT_FAILED) if (WaitForSingleObject(hdlIn, EHS_INFINITE) == WAIT_FAILED)
EHS_LOG_INT("Error", 2, "Failed to wait for console input."); EHS_LOG_INT(LogType::ERR, 2, "Failed to wait for console input.");
//if (!SetConsoleActiveScreenBuffer(hdlOut)) //if (!SetConsoleActiveScreenBuffer(hdlOut))
// EHS_LOG_INT("Error", 3, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); // EHS_LOG_INT(LogType::ERR, 3, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
isConsole = true; isConsole = true;
#endif #endif
@ -78,15 +78,15 @@ namespace ehs
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (!FreeConsole()) if (!FreeConsole())
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
int code = close(hdlOut); int code = close(hdlOut);
if (code == -1) if (code == -1)
EHS_LOG_INT("Error", 0, "Failed to free the console output with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to free the console output with error #" + Str_8::FromNum(errno) + ".");
code = close(hdlIn); code = close(hdlIn);
if (code == -1) if (code == -1)
EHS_LOG_INT("Error", 0, "Failed to free the console input with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to free the console input with error #" + Str_8::FromNum(errno) + ".");
#endif #endif
hdlOut = 0; hdlOut = 0;
@ -118,7 +118,7 @@ namespace ehs
{ {
DWORD written = 0; DWORD written = 0;
if (!WriteConsoleW(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr)) if (!WriteConsoleW(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
offset += written; offset += written;
} }
@ -136,7 +136,7 @@ namespace ehs
{ {
DWORD written = 0; DWORD written = 0;
if (!WriteFile(hdlOut, &((Char_8*)r)[offset], (DWORD)r.Size(true) - offset, &written, nullptr)) if (!WriteFile(hdlOut, &((Char_8*)r)[offset], (DWORD)r.Size(true) - offset, &written, nullptr))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
offset += written; offset += written;
} }
@ -152,7 +152,7 @@ namespace ehs
ssize_t written = write(hdlOut, result, result.Size(true)); ssize_t written = write(hdlOut, result, result.Size(true));
if (written == -1) if (written == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to write to console with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to write to console with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
offset += written; offset += written;
@ -178,7 +178,7 @@ namespace ehs
{ {
DWORD written = 0; DWORD written = 0;
if (!WriteConsoleW(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr)) if (!WriteConsoleW(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
offset += written; offset += written;
} }
@ -196,7 +196,7 @@ namespace ehs
{ {
DWORD written = 0; DWORD written = 0;
if (!WriteFile(hdlOut, &((Char_8*)r)[offset], (DWORD)r.Size(true) - offset, &written, nullptr)) if (!WriteFile(hdlOut, &((Char_8*)r)[offset], (DWORD)r.Size(true) - offset, &written, nullptr))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
offset += written; offset += written;
} }
@ -212,7 +212,7 @@ namespace ehs
ssize_t written = write(hdlOut, result, result.Size(true)); ssize_t written = write(hdlOut, result, result.Size(true));
if (written == -1) if (written == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to write to console with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to write to console with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
offset += written; offset += written;
@ -236,7 +236,7 @@ namespace ehs
{ {
DWORD written = 0; DWORD written = 0;
if (!WriteConsoleW(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr)) if (!WriteConsoleW(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
offset += written; offset += written;
} }
@ -254,7 +254,7 @@ namespace ehs
{ {
DWORD written = 0; DWORD written = 0;
if (!WriteFile(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr)) if (!WriteFile(hdlOut, &r[offset], (DWORD)r.Size() - offset, &written, nullptr))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
offset += written; offset += written;
} }
@ -270,7 +270,7 @@ namespace ehs
ssize_t written = write(hdlOut, result, result.Size()); ssize_t written = write(hdlOut, result, result.Size());
if (written == -1) if (written == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to write to console with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to write to console with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
offset += written; offset += written;
@ -299,7 +299,7 @@ namespace ehs
if (!ReadConsoleW(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr)) if (!ReadConsoleW(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
return U""; return U"";
} }
@ -329,7 +329,7 @@ namespace ehs
if (!ReadFile(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr)) if (!ReadFile(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
return U""; return U"";
} }
@ -355,7 +355,7 @@ namespace ehs
read = ::read(hdlIn, input, bufferSize); read = ::read(hdlIn, input, bufferSize);
if (read == -1) if (read == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to read from console with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to read from console with error #" + Str_8::FromNum(errno) + ".");
return result; return result;
} }
result.Push(input, read); result.Push(input, read);
@ -388,7 +388,7 @@ namespace ehs
if (!ReadConsoleW(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr)) if (!ReadConsoleW(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
return L""; return L"";
} }
@ -418,7 +418,7 @@ namespace ehs
if (!ReadFile(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr)) if (!ReadFile(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
return L""; return L"";
} }
@ -444,7 +444,7 @@ namespace ehs
read = ::read(hdlIn, input, bufferSize); read = ::read(hdlIn, input, bufferSize);
if (read == -1) if (read == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to read from console with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to read from console with error #" + Str_8::FromNum(errno) + ".");
return result; return result;
} }
result.Push(input, read); result.Push(input, read);
@ -477,7 +477,7 @@ namespace ehs
if (!ReadConsoleW(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr)) if (!ReadConsoleW(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
return ""; return "";
} }
@ -507,7 +507,7 @@ namespace ehs
if (!ReadFile(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr)) if (!ReadFile(hdlIn, &result[offset], (DWORD)bufferSize, &read, nullptr))
{ {
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
return ""; return "";
} }
@ -533,7 +533,7 @@ namespace ehs
read = ::read(hdlIn, input, bufferSize); read = ::read(hdlIn, input, bufferSize);
if (read == -1) if (read == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to read from console with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to read from console with error #" + Str_8::FromNum(errno) + ".");
return result; return result;
} }
result.Push(input, read); result.Push(input, read);
@ -573,7 +573,7 @@ namespace ehs
ssize_t written = write(hdlOut, code, sizeof(code)); ssize_t written = write(hdlOut, code, sizeof(code));
if (written == -1) if (written == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to clear console with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to clear console with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
offset += written; offset += written;
@ -586,7 +586,7 @@ namespace ehs
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (!SetConsoleTitleW(UTF::To_16(title))) if (!SetConsoleTitleW(UTF::To_16(title)))
EHS_LOG_INT("Error", 0, "Failed to set console title with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set console title with error #" + Str_8::FromNum(GetLastError()) + ".");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
Str_32 code = U"\033]0;" + title + U"\007"; Str_32 code = U"\033]0;" + title + U"\007";
UInt_64 offset = 0; UInt_64 offset = 0;
@ -594,7 +594,7 @@ namespace ehs
ssize_t written = write(hdlOut, code, code.Size(true)); ssize_t written = write(hdlOut, code, code.Size(true));
if (written == -1) if (written == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to set console title with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set console title with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
offset += written; offset += written;
@ -607,7 +607,7 @@ namespace ehs
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (!SetConsoleTitleW(title)) if (!SetConsoleTitleW(title))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
Str_16 code = L"\033]0;" + title + L"\007"; Str_16 code = L"\033]0;" + title + L"\007";
UInt_64 offset = 0; UInt_64 offset = 0;
@ -615,7 +615,7 @@ namespace ehs
ssize_t written = write(hdlOut, code, code.Size(true)); ssize_t written = write(hdlOut, code, code.Size(true));
if (written == -1) if (written == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to set console title with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set console title with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
offset += written; offset += written;
@ -628,7 +628,7 @@ namespace ehs
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (!SetConsoleTitleW(UTF::To_16(title))) if (!SetConsoleTitleW(UTF::To_16(title)))
EHS_LOG_INT("Error", 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed with error #" + Str_8::FromNum(GetLastError()) + ".");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
Str_8 code = "\033]0;" + title + "\007"; Str_8 code = "\033]0;" + title + "\007";
UInt_64 offset = 0; UInt_64 offset = 0;
@ -636,7 +636,7 @@ namespace ehs
ssize_t written = write(hdlOut, code, code.Size()); ssize_t written = write(hdlOut, code, code.Size());
if (written == -1) if (written == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to set console title with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set console title with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
offset += written; offset += written;
@ -788,7 +788,7 @@ namespace ehs
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
void* hdl = FindWindowW(nullptr, GetTitle_16()); void* hdl = FindWindowW(nullptr, GetTitle_16());
if (hdl == nullptr) if (hdl == nullptr)
EHS_LOG_INT("Error", 0, "Failed to retrieve native handle with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve native handle with error #" + Str_8::FromNum(GetLastError()) + ".");
return hdl; return hdl;
#else #else

View File

@ -2,6 +2,8 @@
#include "ehs/Log.h" #include "ehs/Log.h"
#include <dirent.h> #include <dirent.h>
#include <cerrno>
#include <sys/stat.h>
namespace ehs namespace ehs
{ {
@ -9,10 +11,16 @@ namespace ehs
{ {
Array<Str_8> result; Array<Str_8> result;
DIR* hdl = opendir(dir); if (!dir.Size())
if (!dir)
{ {
EHS_LOG_INT("Error", 0, "Failed to open directory, \"" + dir + "\"."); EHS_LOG_INT(LogType::WARN, 2, "The given directory was empty.");
return result;
}
DIR* hdl = opendir(dir);
if (!hdl)
{
EHS_LOG_INT(LogType::ERR, 3, "Failed to open directory, \"" + dir + "\".");
return result; return result;
} }
@ -21,8 +29,55 @@ namespace ehs
if (entry->d_type == DT_REG) if (entry->d_type == DT_REG)
result.Push(entry->d_name); result.Push(entry->d_name);
closedir(hdl); if (closedir(hdl) == -1)
{
EHS_LOG_INT(LogType::ERR, 4, "Failed to close directory, \"" + dir + "\".");
return result;
}
EHS_LOG_SUCCESS();
return result; return result;
} }
void Directory::CreateRecursive(Str_8 dir)
{
dir = dir.ReplaceAll("\\", "/");
const Vector<Str_8> dirs = dir.Split("/");
for (UInt_64 i = 0; i < dirs.Size(); ++i)
{
const Str_8 final = (Str_8&&)dirs[i];
for (UInt_64 x = 0; x < i; ++x)
dirs[i] += dirs[x] + "/";
dirs[i] += final;
if (mkdir(dirs[i], S_IRWXU | S_IRWXG | S_IRWXO) == -1)
{
if (const SInt_32 code = errno; code != EEXIST)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to create directory, \"" + dirs[i] + "\" with error #" + Str_8::FromNum(code) + ".");
return;
}
}
}
EHS_LOG_SUCCESS();
}
void Directory::Create(const Str_8 &dir)
{
if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == -1)
{
if (const SInt_32 code = errno; code != EEXIST)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to create directory with error #" + Str_8::FromNum(code) + ".");
return;
}
}
EHS_LOG_SUCCESS();
}
} }

View File

@ -83,14 +83,14 @@ namespace ehs
hdl = inotify_init(); hdl = inotify_init();
if (hdl < 0) if (hdl < 0)
{ {
EHS_LOG_INT("Error", 0, "Failed to initialize inotify."); EHS_LOG_INT(LogType::ERR, 0, "Failed to initialize inotify.");
return; return;
} }
int flags = fcntl(hdl, F_GETFL, 0); int flags = fcntl(hdl, F_GETFL, 0);
if (flags == -1) if (flags == -1)
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve flags with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve flags with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
@ -98,14 +98,14 @@ namespace ehs
if (fcntl(hdl, F_SETFL, flags) == -1) if (fcntl(hdl, F_SETFL, flags) == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to set flags with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to set flags with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
wd = inotify_add_watch( hdl, filePath, IN_MODIFY | IN_DELETE_SELF | IN_MOVE_SELF | IN_ACCESS); wd = inotify_add_watch( hdl, filePath, IN_MODIFY | IN_DELETE_SELF | IN_MOVE_SELF | IN_ACCESS);
if (wd < 0) if (wd < 0)
{ {
EHS_LOG_INT("Error", 3, "Failed to add watch."); EHS_LOG_INT(LogType::ERR, 3, "Failed to add watch.");
close(hdl); close(hdl);
hdl = -1; hdl = -1;
return; return;
@ -137,7 +137,7 @@ namespace ehs
{ {
UInt_8 code = errno; UInt_8 code = errno;
if (code != EWOULDBLOCK) if (code != EWOULDBLOCK)
EHS_LOG_INT("Error", 0, "Failed to read with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to read with error #" + Str_8::FromNum(code) + ".");
return mask; return mask;
} }

View File

@ -12,7 +12,7 @@ namespace ehs
return; return;
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
EHS_LOG_INT("Error", 0, "Failed to close file at file path, \"" + filePath + "\", with error #" + GetLastError() + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close file at file path, \"" + filePath + "\", with error #" + GetLastError() + ".");
} }
FileMonitor::FileMonitor() FileMonitor::FileMonitor()
@ -82,7 +82,7 @@ namespace ehs
hdl = CreateFileW(UTF::To_16(filePath), GENERIC_READ, FILE_SHARE_READ, hdl = CreateFileW(UTF::To_16(filePath), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hdl == INVALID_HANDLE_VALUE) if (hdl == INVALID_HANDLE_VALUE)
EHS_LOG_INT("Error", 0, "Failed to open file at file path, \"" + filePath + "\", with error #" + GetLastError() + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to open file at file path, \"" + filePath + "\", with error #" + GetLastError() + ".");
} }
void FileMonitor::Release() void FileMonitor::Release()
@ -91,7 +91,7 @@ namespace ehs
return; return;
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
EHS_LOG_INT("Error", 0, "Failed to close file at file path, \"" + filePath + "\", with error #" + GetLastError() + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close file at file path, \"" + filePath + "\", with error #" + GetLastError() + ".");
hdl = nullptr; hdl = nullptr;
} }

View File

@ -13,10 +13,10 @@ namespace ehs
File::~File() File::~File()
{ {
if (map != MAP_FAILED && munmap(map, mapSize) == -1) if (map != MAP_FAILED && munmap(map, mapSize) == -1)
EHS_LOG_INT("Error", 0, "Failed to unmap with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap with error #" + Str_8::FromNum(errno) + ".");
if (hdl >= 0 && close(hdl) == -1) if (hdl >= 0 && close(hdl) == -1)
EHS_LOG_INT("Error", 0, "Failed to close file handle with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close file handle with error #" + Str_8::FromNum(errno) + ".");
} }
File::File() File::File()
@ -64,21 +64,29 @@ namespace ehs
hdl = open64(path, linuxMode | linuxDisp, S_IRUSR | S_IWUSR); hdl = open64(path, linuxMode | linuxDisp, S_IRUSR | S_IWUSR);
if (hdl == -1) if (hdl == -1)
{ {
SInt_32 code = errno; const SInt_32 code = errno;
if (code == EEXIST && (disposition == Disposition::CREATE_PERSISTENT || disposition == Disposition::OPEN_PERSISTENT)) if (code == EEXIST && (disposition == Disposition::CREATE_PERSISTENT || disposition == Disposition::OPEN_PERSISTENT))
{ {
hdl = open64(path, linuxMode, S_IRUSR | S_IWUSR); hdl = open64(path, linuxMode, S_IRUSR | S_IWUSR);
if (hdl == -1) if (hdl == -1)
EHS_LOG_INT("Error", 0, strerror(errno)); {
EHS_LOG_INT(LogType::ERR, 1, strerror(errno));
return;
}
} }
else else
{ {
if (code == ENOENT) if (code == ENOENT)
EHS_LOG_INT("Error", 0, "File at filepath, \"" + filePath + "\" not found."); EHS_LOG_INT(LogType::ERR, 0, "File at filepath, \"" + filePath + "\" not found.");
else else
EHS_LOG_INT("Error", 0, strerror(code)); EHS_LOG_INT(LogType::ERR, 1, strerror(code));
return;
} }
} }
EHS_LOG_SUCCESS();
} }
File::File(File&& file) noexcept File::File(File&& file) noexcept
@ -137,12 +145,12 @@ namespace ehs
void File::Release() void File::Release()
{ {
if (IsMapped() && munmap(map, mapSize) == -1) if (IsMapped() && munmap(map, mapSize) == -1)
EHS_LOG_INT("Error", 0, "Failed to unmap with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap with error #" + Str_8::FromNum(errno) + ".");
map = MAP_FAILED; map = MAP_FAILED;
mapSize = 0; mapSize = 0;
if (IsValid() && close(hdl) == -1) if (IsValid() && close(hdl) == -1)
EHS_LOG_INT("Error", 0, "Failed to close file handle with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close file handle with error #" + Str_8::FromNum(errno) + ".");
hdl = -1; hdl = -1;
} }
@ -178,7 +186,7 @@ namespace ehs
map = mmap64(nullptr, size, linuxMode, MAP_SHARED, hdl, (off64_t)offset); map = mmap64(nullptr, size, linuxMode, MAP_SHARED, hdl, (off64_t)offset);
if (map == MAP_FAILED) if (map == MAP_FAILED)
{ {
EHS_LOG_INT("Error", 0, "Failed to map with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to map with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
@ -191,7 +199,7 @@ namespace ehs
return; return;
if (munmap(map, mapSize) == -1) if (munmap(map, mapSize) == -1)
EHS_LOG_INT("Error", 0, "Failed to unmap with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap with error #" + Str_8::FromNum(errno) + ".");
map = MAP_FAILED; map = MAP_FAILED;
mapSize = 0; mapSize = 0;
@ -203,7 +211,7 @@ namespace ehs
return; return;
if (msync((void*)map, mapSize, MS_SYNC) == -1) if (msync((void*)map, mapSize, MS_SYNC) == -1)
EHS_LOG_INT("Error", 0, "Failed to flush view with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to flush view with error #" + Str_8::FromNum(errno) + ".");
} }
UInt_64 File::Write(const Byte *const data, const UInt_64 size) UInt_64 File::Write(const Byte *const data, const UInt_64 size)
@ -214,7 +222,7 @@ namespace ehs
SInt_64 written = 0; SInt_64 written = 0;
written = write(hdl, data, size); written = write(hdl, data, size);
if (written == -1) if (written == -1)
EHS_LOG_INT("Error", 0, "Failed to write to file, \"" + path + "\", with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to write to file, \"" + path + "\", with error #" + Str_8::FromNum(errno) + ".");
return (UInt_64)written; return (UInt_64)written;
} }
@ -227,7 +235,7 @@ namespace ehs
SInt_64 read = 0; SInt_64 read = 0;
read = ::read(hdl, data, (size_t)size); read = ::read(hdl, data, (size_t)size);
if (read == -1) if (read == -1)
EHS_LOG_INT("Error", 0, "Failed to read from file, \"" + path + "\", with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to read from file, \"" + path + "\", with error #" + Str_8::FromNum(errno) + ".");
return (UInt_64)read; return (UInt_64)read;
} }
@ -238,7 +246,7 @@ namespace ehs
return; return;
if (lseek64(hdl, (off64_t)index, SEEK_SET) == -1) if (lseek64(hdl, (off64_t)index, SEEK_SET) == -1)
EHS_LOG_INT("Error", 0, "Failed to seek with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to seek with error #" + Str_8::FromNum(errno) + ".");
} }
void File::SeekBeginning() void File::SeekBeginning()
@ -247,7 +255,7 @@ namespace ehs
return; return;
if (lseek64(hdl, 0, SEEK_SET) == -1) if (lseek64(hdl, 0, SEEK_SET) == -1)
EHS_LOG_INT("Error", 0, "Failed to seek with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to seek with error #" + Str_8::FromNum(errno) + ".");
} }
void File::SeekEnd() void File::SeekEnd()
@ -256,7 +264,7 @@ namespace ehs
return; return;
if (lseek64(hdl, 0, SEEK_END) == -1) if (lseek64(hdl, 0, SEEK_END) == -1)
EHS_LOG_INT("Error", 0, "Failed to seek with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to seek with error #" + Str_8::FromNum(errno) + ".");
} }
void File::Truncate(const UInt_64 size) void File::Truncate(const UInt_64 size)
@ -265,7 +273,7 @@ namespace ehs
return; return;
if (ftruncate64(hdl, (off64_t)size) == -1) if (ftruncate64(hdl, (off64_t)size) == -1)
EHS_LOG_INT("Error", 0, "Failed to truncate with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to truncate with error #" + Str_8::FromNum(errno) + ".");
} }
UInt_64 File::Size() const UInt_64 File::Size() const
@ -273,7 +281,7 @@ namespace ehs
struct stat64 info = {}; struct stat64 info = {};
if (fstat64(hdl, &info) == -1) if (fstat64(hdl, &info) == -1)
EHS_LOG_INT("Error", 0, "Failed to retrieve file size with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve file size with error #" + Str_8::FromNum(errno) + ".");
return info.st_size; return info.st_size;
} }
@ -302,6 +310,6 @@ namespace ehs
path = filePath.Sub(0, index); path = filePath.Sub(0, index);
if (rename(filePath, path + newName) == -1) if (rename(filePath, path + newName) == -1)
EHS_LOG_INT("Error", 0, "Failed to rename file with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to rename file with error #" + Str_8::FromNum(errno) + ".");
} }
} }

View File

@ -5,13 +5,13 @@ namespace ehs
File::~File() File::~File()
{ {
if (view && !UnmapViewOfFile(view)) if (view && !UnmapViewOfFile(view))
EHS_LOG_INT("Error", 0, "Failed to unmap view with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap view with error #" + Str_8::FromNum(GetLastError()) + ".");
if (map != INVALID_HANDLE_VALUE && !CloseHandle(map)) if (map != INVALID_HANDLE_VALUE && !CloseHandle(map))
EHS_LOG_INT("Error", 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + ".");
if (hdl != INVALID_HANDLE_VALUE && !CloseHandle(hdl)) if (hdl != INVALID_HANDLE_VALUE && !CloseHandle(hdl))
EHS_LOG_INT("Error", 0, "Failed to close file handle with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close file handle with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
File::File() File::File()
@ -62,12 +62,14 @@ namespace ehs
{ {
DWORD code = GetLastError(); DWORD code = GetLastError();
if (code == ERROR_FILE_NOT_FOUND) if (code == ERROR_FILE_NOT_FOUND)
EHS_LOG_INT("Error", 1, "File not found at path, \"" + path + "\"."); EHS_LOG_INT(LogType::ERR, 0, "File not found at path, \"" + path + "\".");
else if (code != ERROR_SUCCESS) else if (code != ERROR_SUCCESS)
EHS_LOG_INT("Error", 2, "Failed to create handle for file, \"" + path + "\", with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to create handle for file, \"" + path + "\", with error #" + Str_8::FromNum(code) + ".");
return; return;
} }
EHS_LOG_SUCCESS();
} }
File::File(File&& file) noexcept File::File(File&& file) noexcept
@ -132,16 +134,16 @@ namespace ehs
void File::Release() void File::Release()
{ {
if (view && !UnmapViewOfFile(view)) if (view && !UnmapViewOfFile(view))
EHS_LOG_INT("Error", 0, "Failed to unmap view with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap view with error #" + Str_8::FromNum(GetLastError()) + ".");
view = nullptr; view = nullptr;
viewSize = 0; viewSize = 0;
if (IsMapped() && !CloseHandle(map)) if (IsMapped() && !CloseHandle(map))
EHS_LOG_INT("Error", 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + ".");
map = INVALID_HANDLE_VALUE; map = INVALID_HANDLE_VALUE;
if (IsValid() && !CloseHandle(hdl)) if (IsValid() && !CloseHandle(hdl))
EHS_LOG_INT("Error", 0, "Failed to close file handle with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close file handle with error #" + Str_8::FromNum(GetLastError()) + ".");
hdl = INVALID_HANDLE_VALUE; hdl = INVALID_HANDLE_VALUE;
} }
@ -177,7 +179,7 @@ namespace ehs
map = CreateFileMappingW(hdl, nullptr, winMode, 0, 0, nullptr); map = CreateFileMappingW(hdl, nullptr, winMode, 0, 0, nullptr);
if (!map) if (!map)
{ {
EHS_LOG_INT("Error", 0, "Failed to create map handle with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create map handle with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -197,10 +199,10 @@ namespace ehs
view = (Byte*)MapViewOfFile(map, winMode, ((DWORD*)&offset)[1], (DWORD)offset, size); view = (Byte*)MapViewOfFile(map, winMode, ((DWORD*)&offset)[1], (DWORD)offset, size);
if (!view) if (!view)
{ {
EHS_LOG_INT("Error", 0, "Failed to map view with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to map view with error #" + Str_8::FromNum(GetLastError()) + ".");
if (!CloseHandle(map)) if (!CloseHandle(map))
EHS_LOG_INT("Error", 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + ".");
map = INVALID_HANDLE_VALUE; map = INVALID_HANDLE_VALUE;
} }
@ -213,12 +215,12 @@ namespace ehs
return; return;
if (!UnmapViewOfFile(view)) if (!UnmapViewOfFile(view))
EHS_LOG_INT("Error", 0, "Failed to unmap view with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap view with error #" + Str_8::FromNum(GetLastError()) + ".");
view = nullptr; view = nullptr;
viewSize = 0; viewSize = 0;
if (!CloseHandle(map)) if (!CloseHandle(map))
EHS_LOG_INT("Error", 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unmap with error #" + Str_8::FromNum(GetLastError()) + ".");
map = INVALID_HANDLE_VALUE; map = INVALID_HANDLE_VALUE;
} }
@ -228,7 +230,7 @@ namespace ehs
return; return;
if (!FlushViewOfFile(view, viewSize)) if (!FlushViewOfFile(view, viewSize))
EHS_LOG_INT("Error", 0, "Failed to flush view with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to flush view with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
UInt_64 File::Write(const Byte *const data, const UInt_64 size) UInt_64 File::Write(const Byte *const data, const UInt_64 size)
@ -239,7 +241,7 @@ namespace ehs
SInt_64 written = 0; SInt_64 written = 0;
if (!WriteFile(hdl, data, (DWORD)size, (DWORD*)&written, nullptr)) if (!WriteFile(hdl, data, (DWORD)size, (DWORD*)&written, nullptr))
EHS_LOG_INT("Error", 0, "Failed to write to file, \"" + path + "\", with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to write to file, \"" + path + "\", with error #" + Str_8::FromNum(GetLastError()) + ".");
return (UInt_64)written; return (UInt_64)written;
} }
@ -252,7 +254,7 @@ namespace ehs
SInt_64 read = 0; SInt_64 read = 0;
if (!ReadFile(hdl, data, (DWORD)size, (DWORD*)&read, nullptr)) if (!ReadFile(hdl, data, (DWORD)size, (DWORD*)&read, nullptr))
EHS_LOG_INT("Error", 0, "Failed to read from file, \"" + path + "\", with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to read from file, \"" + path + "\", with error #" + Str_8::FromNum(GetLastError()) + ".");
return (UInt_64)read; return (UInt_64)read;
} }
@ -263,7 +265,7 @@ namespace ehs
return; return;
if (SetFilePointer(hdl, (LONG)index, (PLONG)&((UInt_32*)&index)[1], FILE_BEGIN) == INVALID_SET_FILE_POINTER) if (SetFilePointer(hdl, (LONG)index, (PLONG)&((UInt_32*)&index)[1], FILE_BEGIN) == INVALID_SET_FILE_POINTER)
EHS_LOG_INT("Error", 0, "Failed to seek with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to seek with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void File::SeekBeginning() void File::SeekBeginning()
@ -272,7 +274,7 @@ namespace ehs
return; return;
if (SetFilePointer(hdl, 0, nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER) if (SetFilePointer(hdl, 0, nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
EHS_LOG_INT("Error", 0, "Failed to seek with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to seek with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void File::SeekEnd() void File::SeekEnd()
@ -281,7 +283,7 @@ namespace ehs
return; return;
if (SetFilePointer(hdl, 0, nullptr, FILE_END) == INVALID_SET_FILE_POINTER) if (SetFilePointer(hdl, 0, nullptr, FILE_END) == INVALID_SET_FILE_POINTER)
EHS_LOG_INT("Error", 0, "Failed to seek with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to seek with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void File::Truncate(const UInt_64 size) void File::Truncate(const UInt_64 size)
@ -292,7 +294,7 @@ namespace ehs
Seek(size); Seek(size);
if (!::SetEndOfFile(hdl)) if (!::SetEndOfFile(hdl))
EHS_LOG_INT("Error", 0, "Failed to set end of file with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set end of file with error #" + Str_8::FromNum(GetLastError()) + ".");
SeekBeginning(); SeekBeginning();
} }
@ -305,7 +307,7 @@ namespace ehs
LARGE_INTEGER size = {}; LARGE_INTEGER size = {};
if (!GetFileSizeEx(hdl, &size)) if (!GetFileSizeEx(hdl, &size))
EHS_LOG_INT("Error", 0, "Failed to retrieve file size with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve file size with error #" + Str_8::FromNum(GetLastError()) + ".");
return (UInt_64)size.QuadPart; return (UInt_64)size.QuadPart;
} }
@ -329,7 +331,7 @@ namespace ehs
path = filePath.Sub(0, index); path = filePath.Sub(0, index);
if (!MoveFileW(filePath, path + newName)) if (!MoveFileW(filePath, path + newName))
EHS_LOG_INT("Error", 0, "Failed to rename file with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to rename file with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void File::Rename_8(const Str_8& filePath, const Str_8& newName) void File::Rename_8(const Str_8& filePath, const Str_8& newName)

View File

@ -27,7 +27,7 @@ namespace ehs
Version ver = fData.ReadVersion(); Version ver = fData.ReadVersion();
if (ver != Version(1, 0, 0)) if (ver != Version(1, 0, 0))
{ {
EHS_LOG_INT("Error", 2, "The Event Horizon Font file, \"" + filePath + "\", must be version 1.0.0, but was version " + EHS_LOG_INT(LogType::ERR, 2, "The Event Horizon Font file, \"" + filePath + "\", must be version 1.0.0, but was version " +
Str_8::FromNum(ver.major) + "." + Str_8::FromNum(ver.minor) + "." + Str_8::FromNum(ver.major) + "." + Str_8::FromNum(ver.minor) + "." +
Str_8::FromNum(ver.patch) + "."); Str_8::FromNum(ver.patch) + ".");
return; return;

View File

@ -12,7 +12,7 @@ namespace ehs
Str_8 riffId = data.ReadStr<Char_8, UInt_64>(4); Str_8 riffId = data.ReadStr<Char_8, UInt_64>(4);
if (riffId != "RIFF") if (riffId != "RIFF")
{ {
EHS_LOG_INT("Error", 0, "File at file path, \"" + filePath + "\", is not a valid RIFF file."); EHS_LOG_INT(LogType::ERR, 0, "File at file path, \"" + filePath + "\", is not a valid RIFF file.");
return; return;
} }
@ -36,7 +36,7 @@ namespace ehs
Str_8 riffId = data.ReadStr<Char_8, UInt_64>(4); Str_8 riffId = data.ReadStr<Char_8, UInt_64>(4);
if (riffId != "RIFF") if (riffId != "RIFF")
{ {
EHS_LOG_INT("Error", 0, "Data is not in RIFF format."); EHS_LOG_INT(LogType::ERR, 0, "Data is not in RIFF format.");
return; return;
} }

View File

@ -65,32 +65,32 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Cannot initialize with an invalid object."); EHS_LOG_INT(LogType::ERR, 0, "Cannot initialize with an invalid object.");
return; return;
} }
if (IsInitialized()) if (IsInitialized())
{ {
EHS_LOG_INT("Warning", 1, "Object is already initialized."); EHS_LOG_INT(LogType::WARN, 1, "Object is already initialized.");
return; return;
} }
hdl = open("/dev/bus/usb/" + Str_8::FromNum(GetBus()) + "/" + Str_8::FromNum(GetAddress()), O_RDWR); hdl = open("/dev/bus/usb/" + Str_8::FromNum(GetBus()) + "/" + Str_8::FromNum(GetAddress()), O_RDWR);
if (hdl == -1) if (hdl == -1)
EHS_LOG_INT("Error", 2, "Failed to connect to USB device."); EHS_LOG_INT(LogType::ERR, 2, "Failed to connect to USB device.");
} }
void Usb::Release() void Usb::Release()
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Cannot release with an invalid object."); EHS_LOG_INT(LogType::ERR, 0, "Cannot release with an invalid object.");
return; return;
} }
if (!IsInitialized()) if (!IsInitialized())
{ {
EHS_LOG_INT("Warning", 1, "Object is already released."); EHS_LOG_INT(LogType::WARN, 1, "Object is already released.");
return; return;
} }

View File

@ -95,7 +95,7 @@ namespace ehs
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, data, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize) if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, data, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize)
{ {
EHS_LOG_INT("Error", 0, "Getting raw input returned incorrect size."); EHS_LOG_INT(LogType::ERR, 0, "Getting raw input returned incorrect size.");
delete[] data; delete[] data;
return DefWindowProcW(hWnd, uMsg, wParam, lParam); return DefWindowProcW(hWnd, uMsg, wParam, lParam);
} }
@ -113,7 +113,7 @@ namespace ehs
if (GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0) if (GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve device name."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve device name.");
return 0; return 0;
} }
@ -139,7 +139,7 @@ namespace ehs
if (GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0) if (GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0)
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve device name."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve device name.");
return 0; return 0;
} }
@ -202,7 +202,7 @@ namespace ehs
if (win->cursorConstrained) if (win->cursorConstrained)
{ {
if (!ClipCursor(nullptr)) if (!ClipCursor(nullptr))
EHS_LOG_INT("Error", 0, "Failed to free cursor after losing focus with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to free cursor after losing focus with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
win->ih.ResetAllStates(); win->ih.ResetAllStates();
@ -220,7 +220,7 @@ namespace ehs
if (!GetClientRect(win->GetHdl(), &client)) if (!GetClientRect(win->GetHdl(), &client))
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve client scale with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve client scale with error #" + Str_8::FromNum(GetLastError()) + ".");
return DefWindowProcW(hWnd, uMsg, wParam, lParam); return DefWindowProcW(hWnd, uMsg, wParam, lParam);
} }
@ -228,7 +228,7 @@ namespace ehs
if (!ClientToScreen(win->GetHdl(), &pos)) if (!ClientToScreen(win->GetHdl(), &pos))
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve client's absolute position with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve client's absolute position with error #" + Str_8::FromNum(GetLastError()) + ".");
return DefWindowProcW(hWnd, uMsg, wParam, lParam); return DefWindowProcW(hWnd, uMsg, wParam, lParam);
} }
@ -239,7 +239,7 @@ namespace ehs
if (!ClientToScreen(win->GetHdl(), &scale)) if (!ClientToScreen(win->GetHdl(), &scale))
{ {
EHS_LOG_INT("Error", 2, "Failed to retrieve client's absolute scale with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to retrieve client's absolute scale with error #" + Str_8::FromNum(GetLastError()) + ".");
return DefWindowProcW(hWnd, uMsg, wParam, lParam); return DefWindowProcW(hWnd, uMsg, wParam, lParam);
} }
@ -248,7 +248,7 @@ namespace ehs
if (!ClipCursor(&client)) if (!ClipCursor(&client))
{ {
EHS_LOG_INT("Error", 3, "Failed to confine cursor with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to confine cursor with error #" + Str_8::FromNum(GetLastError()) + ".");
return DefWindowProcW(hWnd, uMsg, wParam, lParam); return DefWindowProcW(hWnd, uMsg, wParam, lParam);
} }
} }
@ -347,7 +347,7 @@ namespace ehs
wcex.lpszClassName = title; wcex.lpszClassName = title;
if (!RegisterClassExW(&wcex)) if (!RegisterClassExW(&wcex))
EHS_LOG_INT("Error", 0, "Failed to register window."); EHS_LOG_INT(LogType::ERR, 0, "Failed to register window.");
hdl = CreateWindowExW( hdl = CreateWindowExW(
0, 0,
@ -362,7 +362,7 @@ namespace ehs
if (!hdl) if (!hdl)
{ {
EHS_LOG_INT("Error", 1, "Failed to create window."); EHS_LOG_INT(LogType::ERR, 1, "Failed to create window.");
return; return;
} }
@ -391,7 +391,7 @@ namespace ehs
if (RegisterRawInputDevices(rid, 2, sizeof(rid[0])) == false) if (RegisterRawInputDevices(rid, 2, sizeof(rid[0])) == false)
{ {
EHS_LOG_INT("Error", 2, "Failed to register raw input devices."); EHS_LOG_INT(LogType::ERR, 2, "Failed to register raw input devices.");
return; return;
} }
@ -434,7 +434,7 @@ namespace ehs
void Window::SetTitle_32(const Str_32& title) void Window::SetTitle_32(const Str_32& title)
{ {
if (!SetWindowTextW(hdl, UTF::To_16(title))) if (!SetWindowTextW(hdl, UTF::To_16(title)))
EHS_LOG_INT("Error", 0, "Failed to set window title with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set window title with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
Str_32 Window::GetTitle_32() const Str_32 Window::GetTitle_32() const
@ -445,7 +445,7 @@ namespace ehs
DWORD err = GetLastError(); DWORD err = GetLastError();
if (err) if (err)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + ".");
return {}; return {};
} }
@ -459,7 +459,7 @@ namespace ehs
DWORD err = GetLastError(); DWORD err = GetLastError();
if (err) if (err)
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + ".");
return {}; return {};
} }
@ -471,7 +471,7 @@ namespace ehs
void Window::SetTitle_16(const Str_16& title) void Window::SetTitle_16(const Str_16& title)
{ {
if (!SetWindowTextW(hdl, title)) if (!SetWindowTextW(hdl, title))
EHS_LOG_INT("Error", 0, "Failed to set window title with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set window title with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
Str_16 Window::GetTitle_16() const Str_16 Window::GetTitle_16() const
@ -482,7 +482,7 @@ namespace ehs
DWORD err = GetLastError(); DWORD err = GetLastError();
if (err) if (err)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + ".");
return {}; return {};
} }
@ -496,7 +496,7 @@ namespace ehs
DWORD err = GetLastError(); DWORD err = GetLastError();
if (err) if (err)
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + ".");
return {}; return {};
} }
@ -508,7 +508,7 @@ namespace ehs
void Window::SetTitle_8(const Str_8& title) void Window::SetTitle_8(const Str_8& title)
{ {
if (!SetWindowTextW(hdl, UTF::To_16(title))) if (!SetWindowTextW(hdl, UTF::To_16(title)))
EHS_LOG_INT("Error", 0, "Failed to set window title with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set window title with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
Str_8 Window::GetTitle_8() const Str_8 Window::GetTitle_8() const
@ -519,7 +519,7 @@ namespace ehs
DWORD err = GetLastError(); DWORD err = GetLastError();
if (err) if (err)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + ".");
return {}; return {};
} }
@ -533,7 +533,7 @@ namespace ehs
DWORD err = GetLastError(); DWORD err = GetLastError();
if (err) if (err)
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve the window's title length with error #" + Str_8::FromNum(err) + ".");
return {}; return {};
} }
@ -547,7 +547,7 @@ namespace ehs
Handle icon = LoadImageW(nullptr, UTF::To_16(filePath), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE); Handle icon = LoadImageW(nullptr, UTF::To_16(filePath), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
if (!icon) if (!icon)
{ {
EHS_LOG_INT("Error", 0, "Failed to load icon at file path, \"" + filePath + "\" with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to load icon at file path, \"" + filePath + "\" with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -634,7 +634,7 @@ namespace ehs
RECT rect = {}; RECT rect = {};
if (!GetClientRect(hdl, &rect)) if (!GetClientRect(hdl, &rect))
EHS_LOG_INT("Error", 0, "Failed to retrieve client size with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve client size with error #" + Str_8::FromNum(GetLastError()) + ".");
return {(UInt_32)rect.right, (UInt_32)rect.bottom}; return {(UInt_32)rect.right, (UInt_32)rect.bottom};
} }
@ -677,7 +677,7 @@ namespace ehs
if (!GetClientRect(GetHdl(), &client)) if (!GetClientRect(GetHdl(), &client))
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve client scale with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve client scale with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -685,7 +685,7 @@ namespace ehs
if (!ClientToScreen(GetHdl(), &pos)) if (!ClientToScreen(GetHdl(), &pos))
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve client's absolute position with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve client's absolute position with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -696,7 +696,7 @@ namespace ehs
if (!ClientToScreen(GetHdl(), &scale)) if (!ClientToScreen(GetHdl(), &scale))
{ {
EHS_LOG_INT("Error", 2, "Failed to retrieve client's absolute scale with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to retrieve client's absolute scale with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -705,7 +705,7 @@ namespace ehs
if (!ClipCursor(&client)) if (!ClipCursor(&client))
{ {
EHS_LOG_INT("Error", 3, "Failed to confine cursor with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to confine cursor with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
} }

View File

@ -66,7 +66,7 @@ namespace ehs
display = wl_display_connect(nullptr); display = wl_display_connect(nullptr);
if (!display) if (!display)
{ {
EHS_LOG_INT("Error", 0, "Failed to connect to display server."); EHS_LOG_INT(LogType::ERR, 0, "Failed to connect to display server.");
return; return;
} }
@ -87,7 +87,7 @@ namespace ehs
if (!compositor || !xdgShell) if (!compositor || !xdgShell)
{ {
EHS_LOG_INT("Error", 1, "Can't find required interfaces."); EHS_LOG_INT(LogType::ERR, 1, "Can't find required interfaces.");
return; return;
} }
@ -98,7 +98,7 @@ namespace ehs
surface = wl_compositor_create_surface(compositor); surface = wl_compositor_create_surface(compositor);
if (!surface) if (!surface)
{ {
EHS_LOG_INT("Error", 2, "Can't create surface."); EHS_LOG_INT(LogType::ERR, 2, "Can't create surface.");
return; return;
} }

View File

@ -112,7 +112,7 @@ namespace ehs
server = xcb_connect(nullptr, nullptr); server = xcb_connect(nullptr, nullptr);
if (xcb_connection_has_error(server)) if (xcb_connection_has_error(server))
{ {
EHS_LOG_INT("Error", 0, "Failed to connect to display server."); EHS_LOG_INT(LogType::ERR, 0, "Failed to connect to display server.");
return; return;
} }
@ -151,7 +151,7 @@ namespace ehs
{ {
xcb_disconnect(server); xcb_disconnect(server);
EHS_LOG_INT("Warning", 1, "Failed to query for XCB XInput extension."); EHS_LOG_INT(LogType::WARN, 1, "Failed to query for XCB XInput extension.");
return; return;
} }
@ -159,7 +159,7 @@ namespace ehs
{ {
xcb_disconnect(server); xcb_disconnect(server);
EHS_LOG_INT("Warning", 2, "XCB XInput extension is not available."); EHS_LOG_INT(LogType::WARN, 2, "XCB XInput extension is not available.");
return; return;
} }
@ -459,7 +459,7 @@ namespace ehs
if (!reply || reply->status != XCB_GRAB_STATUS_SUCCESS) if (!reply || reply->status != XCB_GRAB_STATUS_SUCCESS)
{ {
free(reply); free(reply);
EHS_LOG_INT("Error", 0, "Failed to constrain cursor."); EHS_LOG_INT(LogType::ERR, 0, "Failed to constrain cursor.");
return; return;
} }
@ -522,7 +522,7 @@ namespace ehs
xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(server, geom_cookie, nullptr); xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(server, geom_cookie, nullptr);
if (!geom) if (!geom)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve window position."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve window position.");
return result; return result;
} }
@ -548,7 +548,7 @@ namespace ehs
xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(server, geom_cookie, nullptr); xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(server, geom_cookie, nullptr);
if (!geom) if (!geom)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve window scale."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve window scale.");
return result; return result;
} }
@ -569,7 +569,7 @@ namespace ehs
if (clipboard_atom == XCB_ATOM_NONE || utf8_string_atom == XCB_ATOM_NONE || property_atom == XCB_ATOM_NONE) if (clipboard_atom == XCB_ATOM_NONE || utf8_string_atom == XCB_ATOM_NONE || property_atom == XCB_ATOM_NONE)
{ {
EHS_LOG_INT("Error", 1, "Failed to retrieve atoms."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve atoms.");
return result; return result;
} }
@ -604,7 +604,7 @@ namespace ehs
const xcb_atom_t clipboard_atom = RetrieveAtom(false, "CLIPBOARD"); const xcb_atom_t clipboard_atom = RetrieveAtom(false, "CLIPBOARD");
if (clipboard_atom == XCB_ATOM_NONE) if (clipboard_atom == XCB_ATOM_NONE)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve atom."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve atom.");
return; return;
} }
@ -683,7 +683,7 @@ namespace ehs
if (!device_reply) if (!device_reply)
{ {
EHS_LOG_INT("Error", 0, "Failed to query primary devices."); EHS_LOG_INT(LogType::ERR, 0, "Failed to query primary devices.");
return; return;
} }
@ -715,7 +715,7 @@ namespace ehs
if (!device_reply) if (!device_reply)
{ {
EHS_LOG_INT("Error", 0, "Failed to query device name from the id, \"" + Str_8::FromNum(id) + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Failed to query device name from the id, \"" + Str_8::FromNum(id) + "\".");
return result; return result;
} }

View File

@ -69,7 +69,7 @@ namespace ehs
const AudioCodec* codec = GetCodec(ext); const AudioCodec* codec = GetCodec(ext);
if (!codec) if (!codec)
{ {
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Codec not found for file extension, \"" + ext + "\".");
return; return;
} }
@ -92,7 +92,7 @@ namespace ehs
const AudioCodec* codec = GetCodec(ext); const AudioCodec* codec = GetCodec(ext);
if (!codec) if (!codec)
{ {
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Codec not found for file extension, \"" + ext + "\".");
return; return;
} }
@ -332,7 +332,7 @@ namespace ehs
} }
else else
{ {
EHS_LOG_INT("Error", 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to 2 channels is unsupported."); EHS_LOG_INT(LogType::ERR, 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to 2 channels is unsupported.");
} }
return result; return result;
@ -363,7 +363,7 @@ namespace ehs
} }
else else
{ {
EHS_LOG_INT("Error", 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to 6 channels is unsupported."); EHS_LOG_INT(LogType::ERR, 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to 6 channels is unsupported.");
} }
return result; return result;
@ -394,7 +394,7 @@ namespace ehs
} }
else else
{ {
EHS_LOG_INT("Error", 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to 8 channels is unsupported."); EHS_LOG_INT(LogType::ERR, 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to 8 channels is unsupported.");
} }
return result; return result;
@ -779,7 +779,7 @@ namespace ehs
} }
else else
{ {
EHS_LOG_INT("Error", 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to " + EHS_LOG_INT(LogType::ERR, 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to " +
Str_8::FromNum(newChannels) + " channels is unsupported."); Str_8::FromNum(newChannels) + " channels is unsupported.");
return; return;
} }
@ -878,7 +878,7 @@ namespace ehs
} }
else else
{ {
EHS_LOG_INT("Error", 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to " + EHS_LOG_INT(LogType::ERR, 0, "Conversion from " + Str_8::FromNum(channels) + " channels, to " +
Str_8::FromNum(newChannels) + " channels is unsupported."); Str_8::FromNum(newChannels) + " channels is unsupported.");
return result; return result;
@ -901,7 +901,7 @@ namespace ehs
const AudioCodec* codec = GetCodec(ext); const AudioCodec* codec = GetCodec(ext);
if (!codec) if (!codec)
{ {
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Codec not found for file extension, \"" + ext + "\".");
return false; return false;
} }
@ -1927,7 +1927,7 @@ namespace ehs
Version version = in.ReadVersion(); Version version = in.ReadVersion();
if (version != Version(1, 0, 0)) if (version != Version(1, 0, 0))
{ {
EHS_LOG_INT("Error", 0, "Incompatible audio file version."); EHS_LOG_INT(LogType::ERR, 0, "Incompatible audio file version.");
return false; return false;
} }
@ -1954,14 +1954,14 @@ namespace ehs
if (riff.GetType() != "WAVE") if (riff.GetType() != "WAVE")
{ {
EHS_LOG_INT("Error", 0, "Data is not in WAVE format."); EHS_LOG_INT(LogType::ERR, 0, "Data is not in WAVE format.");
return false; return false;
} }
RIFF_Chunk fmt = riff.GetChunk("fmt "); RIFF_Chunk fmt = riff.GetChunk("fmt ");
if (!fmt.IsValid()) if (!fmt.IsValid())
{ {
EHS_LOG_INT("Error", 1, "Wave does not have a format chunk."); EHS_LOG_INT(LogType::ERR, 1, "Wave does not have a format chunk.");
return false; return false;
} }
@ -1970,59 +1970,59 @@ namespace ehs
RIFF_Chunk dChunk = riff.GetChunk("data"); RIFF_Chunk dChunk = riff.GetChunk("data");
if (!dChunk.IsValid()) if (!dChunk.IsValid())
{ {
EHS_LOG_INT("Error", 2, "Wave does not have a data chunk."); EHS_LOG_INT(LogType::ERR, 2, "Wave does not have a data chunk.");
return false; return false;
} }
UInt_16 compression = fmtSer.Read<UInt_16>(); UInt_16 compression = fmtSer.Read<UInt_16>();
if (compression == 0x2) if (compression == 0x2)
{ {
EHS_LOG_INT("Error", 3, "Microsoft ADPCM compression unsupported."); EHS_LOG_INT(LogType::ERR, 3, "Microsoft ADPCM compression unsupported.");
return false; return false;
} }
else if (compression == 0x6) else if (compression == 0x6)
{ {
EHS_LOG_INT("Error", 4, "ITU G.711 a-law compression unsupported."); EHS_LOG_INT(LogType::ERR, 4, "ITU G.711 a-law compression unsupported.");
return false; return false;
} }
else if (compression == 0x7) else if (compression == 0x7)
{ {
EHS_LOG_INT("Error", 5, "ITU G.711 µ-law compression unsupported."); EHS_LOG_INT(LogType::ERR, 5, "ITU G.711 µ-law compression unsupported.");
return false; return false;
} }
else if (compression == 0x11) else if (compression == 0x11)
{ {
EHS_LOG_INT("Error", 6, "IMA ADPCM compression unsupported."); EHS_LOG_INT(LogType::ERR, 6, "IMA ADPCM compression unsupported.");
return false; return false;
} }
else if (compression == 0x16) else if (compression == 0x16)
{ {
EHS_LOG_INT("Error", 7, "TU G.723 ADPCM (Yamaha) compression unsupported."); EHS_LOG_INT(LogType::ERR, 7, "TU G.723 ADPCM (Yamaha) compression unsupported.");
return false; return false;
} }
else if (compression == 0x31) else if (compression == 0x31)
{ {
EHS_LOG_INT("Error", 8, "GSM 6.10 compression unsupported."); EHS_LOG_INT(LogType::ERR, 8, "GSM 6.10 compression unsupported.");
return false; return false;
} }
else if (compression == 0x40) else if (compression == 0x40)
{ {
EHS_LOG_INT("Error", 9, "ITU G.721 ADPCM compression unsupported."); EHS_LOG_INT(LogType::ERR, 9, "ITU G.721 ADPCM compression unsupported.");
return false; return false;
} }
else if (compression == 0x50) else if (compression == 0x50)
{ {
EHS_LOG_INT("Error", 10, "MPEG compression unsupported."); EHS_LOG_INT(LogType::ERR, 10, "MPEG compression unsupported.");
return false; return false;
} }
else if (compression == 0xFFFF) else if (compression == 0xFFFF)
{ {
EHS_LOG_INT("Error", 11, "Experimental compression unsupported."); EHS_LOG_INT(LogType::ERR, 11, "Experimental compression unsupported.");
return false; return false;
} }
else if (compression != 0x1 && compression != 0x3) else if (compression != 0x1 && compression != 0x3)
{ {
EHS_LOG_INT("Error", 12, "Wave has unknown compression of " + Str_8::FromNum(compression) + "."); EHS_LOG_INT(LogType::ERR, 12, "Wave has unknown compression of " + Str_8::FromNum(compression) + ".");
return false; return false;
} }

View File

@ -89,7 +89,7 @@ namespace ehs
{ {
if (!encodeCb) if (!encodeCb)
{ {
EHS_LOG_INT("Error", 0, "Encoding is not supported for the " + id + " format."); EHS_LOG_INT(LogType::ERR, 0, "Encoding is not supported for the " + id + " format.");
return false; return false;
} }
@ -100,7 +100,7 @@ namespace ehs
{ {
if (!decodeCb) if (!decodeCb)
{ {
EHS_LOG_INT("Error", 0, "Decoding is not supported for the " + id + " format."); EHS_LOG_INT(LogType::ERR, 0, "Decoding is not supported for the " + id + " format.");
return false; return false;
} }

View File

@ -77,7 +77,7 @@ namespace ehs
if (snd_pcm_hw_params_set_access(hdl, params, SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0) if (snd_pcm_hw_params_set_access(hdl, params, SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0)
{ {
EHS_LOG_INT("Error", 0, "Failed to set access."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set access.");
return; return;
} }
@ -113,7 +113,7 @@ namespace ehs
} }
default: default:
{ {
EHS_LOG_INT("Error", 0, "Invalid data type."); EHS_LOG_INT(LogType::ERR, 0, "Invalid data type.");
return; return;
} }
} }
@ -125,7 +125,7 @@ namespace ehs
{ {
if (snd_pcm_hw_params_set_channels_near(hdl, params, &channels) < 0) if (snd_pcm_hw_params_set_channels_near(hdl, params, &channels) < 0)
{ {
EHS_LOG_INT("Error", 1, "Failed to set channels."); EHS_LOG_INT(LogType::ERR, 1, "Failed to set channels.");
return; return;
} }
} }
@ -134,26 +134,26 @@ namespace ehs
{ {
if (snd_pcm_hw_params_set_rate_near(hdl, params, &sampleRate, nullptr) < 0) if (snd_pcm_hw_params_set_rate_near(hdl, params, &sampleRate, nullptr) < 0)
{ {
EHS_LOG_INT("Error", 2, "Failed to set sample rate."); EHS_LOG_INT(LogType::ERR, 2, "Failed to set sample rate.");
return; return;
} }
} }
if (snd_pcm_hw_params_set_period_time_near(hdl, params, &period, nullptr) < 0) if (snd_pcm_hw_params_set_period_time_near(hdl, params, &period, nullptr) < 0)
{ {
EHS_LOG_INT("Error", 3, "Failed to set period."); EHS_LOG_INT(LogType::ERR, 3, "Failed to set period.");
return; return;
} }
if (snd_pcm_hw_params_set_buffer_time_near(hdl, params, &latency, nullptr) < 0) if (snd_pcm_hw_params_set_buffer_time_near(hdl, params, &latency, nullptr) < 0)
{ {
EHS_LOG_INT("Error", 4, "Failed to set latency."); EHS_LOG_INT(LogType::ERR, 4, "Failed to set latency.");
return; return;
} }
if (snd_pcm_hw_params(hdl, params) < 0) if (snd_pcm_hw_params(hdl, params) < 0)
{ {
EHS_LOG_INT("Error", 5, "Failed to apply hardware parameters."); EHS_LOG_INT(LogType::ERR, 5, "Failed to apply hardware parameters.");
return; return;
} }
@ -162,7 +162,7 @@ namespace ehs
snd_pcm_format_t format; snd_pcm_format_t format;
if (snd_pcm_hw_params_get_format(params, &format) < 0) if (snd_pcm_hw_params_get_format(params, &format) < 0)
{ {
EHS_LOG_INT("Error", 6, "Failed to retrieve audio device properties."); EHS_LOG_INT(LogType::ERR, 6, "Failed to retrieve audio device properties.");
return; return;
} }
@ -200,7 +200,7 @@ namespace ehs
} }
default: default:
{ {
EHS_LOG_INT("Error", 7, "Format unsupported."); EHS_LOG_INT(LogType::ERR, 7, "Format unsupported.");
break; break;
} }
} }
@ -210,7 +210,7 @@ namespace ehs
{ {
if (snd_pcm_hw_params_get_channels(params, &channels) < 0) if (snd_pcm_hw_params_get_channels(params, &channels) < 0)
{ {
EHS_LOG_INT("Error", 8, "Failed to retrieve channel count."); EHS_LOG_INT(LogType::ERR, 8, "Failed to retrieve channel count.");
return; return;
} }
} }
@ -220,14 +220,14 @@ namespace ehs
int dir; int dir;
if (snd_pcm_hw_params_get_rate(params, &sampleRate, &dir) < 0) if (snd_pcm_hw_params_get_rate(params, &sampleRate, &dir) < 0)
{ {
EHS_LOG_INT("Error", 9, "Failed to retrieve sample rate."); EHS_LOG_INT(LogType::ERR, 9, "Failed to retrieve sample rate.");
return; return;
} }
} }
if (snd_pcm_hw_params_get_buffer_size(params, &maxFrames) < 0) if (snd_pcm_hw_params_get_buffer_size(params, &maxFrames) < 0)
{ {
EHS_LOG_INT("Error", 10, "Failed to retrieve buffer size."); EHS_LOG_INT(LogType::ERR, 10, "Failed to retrieve buffer size.");
} }
snd_pcm_sw_params_t* swParams = nullptr; snd_pcm_sw_params_t* swParams = nullptr;
@ -235,31 +235,31 @@ namespace ehs
if (snd_pcm_sw_params_current(hdl, swParams) < 0) if (snd_pcm_sw_params_current(hdl, swParams) < 0)
{ {
EHS_LOG_INT("Error", 11, "Failed to retrieve software parameters."); EHS_LOG_INT(LogType::ERR, 11, "Failed to retrieve software parameters.");
return; return;
} }
if (snd_pcm_sw_params_set_silence_threshold(hdl, swParams, maxFrames) < 0) if (snd_pcm_sw_params_set_silence_threshold(hdl, swParams, maxFrames) < 0)
{ {
EHS_LOG_INT("Error", 12, "Failed to set silence threshold."); EHS_LOG_INT(LogType::ERR, 12, "Failed to set silence threshold.");
return; return;
} }
if (snd_pcm_sw_params_set_silence_size(hdl, swParams, maxFrames) < 0) if (snd_pcm_sw_params_set_silence_size(hdl, swParams, maxFrames) < 0)
{ {
EHS_LOG_INT("Error", 12, "Failed to set silence size."); EHS_LOG_INT(LogType::ERR, 12, "Failed to set silence size.");
return; return;
} }
if (snd_pcm_sw_params(hdl, swParams) < 0) if (snd_pcm_sw_params(hdl, swParams) < 0)
{ {
EHS_LOG_INT("Error", 13, "Failed to set software parameters."); EHS_LOG_INT(LogType::ERR, 13, "Failed to set software parameters.");
return; return;
} }
if (snd_pcm_prepare(hdl) < 0) if (snd_pcm_prepare(hdl) < 0)
{ {
EHS_LOG_INT("Error", 14, "Failed to prepare audio stream."); EHS_LOG_INT(LogType::ERR, 14, "Failed to prepare audio stream.");
return; return;
} }
@ -281,10 +281,10 @@ namespace ehs
snd_pcm_state_t state = snd_pcm_state(hdl); snd_pcm_state_t state = snd_pcm_state(hdl);
if (state == SND_PCM_STATE_XRUN) if (state == SND_PCM_STATE_XRUN)
{ {
EHS_LOG_INT("Warning", 0, "Buffer overrun/underrun occurred."); EHS_LOG_INT(LogType::WARN, 0, "Buffer overrun/underrun occurred.");
if (snd_pcm_recover(hdl, -EPIPE, 0) < 0) if (snd_pcm_recover(hdl, -EPIPE, 0) < 0)
{ {
EHS_LOG_INT("Error", 1, "Failed to recover from buffer overrun/underrun."); EHS_LOG_INT(LogType::ERR, 1, "Failed to recover from buffer overrun/underrun.");
return 0; return 0;
} }
return GetAvailFrames(); return GetAvailFrames();
@ -293,7 +293,7 @@ namespace ehs
{ {
if (snd_pcm_start(hdl) < 0) if (snd_pcm_start(hdl) < 0)
{ {
EHS_LOG_INT("Error", 2, "Failed to start audio stream."); EHS_LOG_INT(LogType::ERR, 2, "Failed to start audio stream.");
return 0; return 0;
} }
@ -305,10 +305,10 @@ namespace ehs
{ {
if (frames == -EPIPE) if (frames == -EPIPE)
{ {
EHS_LOG_INT("Warning", 3, "Buffer overrun/underrun occurred."); EHS_LOG_INT(LogType::WARN, 3, "Buffer overrun/underrun occurred.");
if (snd_pcm_recover(hdl, -EPIPE, 1) < 0) if (snd_pcm_recover(hdl, -EPIPE, 1) < 0)
{ {
EHS_LOG_INT("Error", 4, "Failed to recover from buffer overrun/underrun."); EHS_LOG_INT(LogType::ERR, 4, "Failed to recover from buffer overrun/underrun.");
return 0; return 0;
} }
@ -316,7 +316,7 @@ namespace ehs
} }
else else
{ {
EHS_LOG_INT("Error", 5, "Failed to retrieve available frames with error #" + Str_8::FromNum(frames) + "."); EHS_LOG_INT(LogType::ERR, 5, "Failed to retrieve available frames with error #" + Str_8::FromNum(frames) + ".");
return 0; return 0;
} }
} }
@ -329,7 +329,7 @@ namespace ehs
const snd_pcm_channel_area_t* areas; const snd_pcm_channel_area_t* areas;
if (snd_pcm_mmap_begin(hdl, &areas, offset, frames) < 0) if (snd_pcm_mmap_begin(hdl, &areas, offset, frames) < 0)
{ {
EHS_LOG_INT("Error", 0, "Failed to map audio buffer."); EHS_LOG_INT(LogType::ERR, 0, "Failed to map audio buffer.");
return nullptr; return nullptr;
} }
@ -341,7 +341,7 @@ namespace ehs
snd_pcm_sframes_t committed = snd_pcm_mmap_commit(hdl, offset, frames); snd_pcm_sframes_t committed = snd_pcm_mmap_commit(hdl, offset, frames);
if (committed < 0) if (committed < 0)
{ {
EHS_LOG_INT("Error", 0, "Failed to commit mapped audio buffer."); EHS_LOG_INT(LogType::ERR, 0, "Failed to commit mapped audio buffer.");
return; return;
} }
} }
@ -366,7 +366,7 @@ namespace ehs
} }
else else
{ {
EHS_LOG_INT("Error", 0, "Wrong value for the audio device type."); EHS_LOG_INT(LogType::ERR, 0, "Wrong value for the audio device type.");
return {}; return {};
} }

View File

@ -87,7 +87,7 @@ namespace ehs
HRESULT r = client->Stop(); HRESULT r = client->Stop();
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 0, "Failed to stop audio with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to stop audio with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
@ -103,7 +103,7 @@ namespace ehs
HRESULT r = hdl->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr, (void**)&client); HRESULT r = hdl->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr, (void**)&client);
if (FAILED(r)) if (FAILED(r))
EHS_LOG_INT("Error", 0, "Failed to create audio client with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create audio client with error #" + Str_8::FromNum(r) + ".");
WAVEFORMATEXTENSIBLE* format; WAVEFORMATEXTENSIBLE* format;
client->GetMixFormat((WAVEFORMATEX**)&format); client->GetMixFormat((WAVEFORMATEX**)&format);
@ -146,7 +146,7 @@ namespace ehs
{ {
if (r == AUDCLNT_E_UNSUPPORTED_FORMAT) if (r == AUDCLNT_E_UNSUPPORTED_FORMAT)
{ {
EHS_LOG_INT("Error", 1, EHS_LOG_INT(LogType::ERR, 1,
"The audio device, \"" + GetName_8() + "\" doesn't support the format {" + "The audio device, \"" + GetName_8() + "\" doesn't support the format {" +
Str_8::FromNum(format->Format.wBitsPerSample) + "-bit, " + Str_8::FromNum(format->Format.wBitsPerSample) + "-bit, " +
Str_8::FromNum(format->Format.nSamplesPerSec) + "Hz, " + Str_8::FromNum(format->Format.nSamplesPerSec) + "Hz, " +
@ -154,14 +154,14 @@ namespace ehs
); );
} }
else else
EHS_LOG_INT("Error", 2, "Failed to retrieve supported audio format with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to retrieve supported audio format with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
if (match) if (match)
{ {
EHS_LOG_INT("Error", 3, EHS_LOG_INT(LogType::ERR, 3,
"The audio device, \"" + GetName_8() + "\" doesn't support the format {" + "The audio device, \"" + GetName_8() + "\" doesn't support the format {" +
Str_8::FromNum(format->Format.wBitsPerSample) + "-bit, " + Str_8::FromNum(format->Format.wBitsPerSample) + "-bit, " +
Str_8::FromNum(format->Format.nSamplesPerSec) + "Hz, " + Str_8::FromNum(format->Format.nSamplesPerSec) + "Hz, " +
@ -185,78 +185,78 @@ namespace ehs
if (r == AUDCLNT_E_ALREADY_INITIALIZED) if (r == AUDCLNT_E_ALREADY_INITIALIZED)
{ {
EHS_LOG_INT("Error", 5, "Audio client is already initialized."); EHS_LOG_INT(LogType::ERR, 5, "Audio client is already initialized.");
return; return;
} }
else if (r == AUDCLNT_E_WRONG_ENDPOINT_TYPE) else if (r == AUDCLNT_E_WRONG_ENDPOINT_TYPE)
{ {
EHS_LOG_INT("Error", 6, "The AUDCLNT_STREAMFLAGS_LOOPBACK flag is set but the endpoint device is a capture device, not a rendering device."); EHS_LOG_INT(LogType::ERR, 6, "The AUDCLNT_STREAMFLAGS_LOOPBACK flag is set but the endpoint device is a capture device, not a rendering device.");
return; return;
} }
else if (r == AUDCLNT_E_BUFFER_SIZE_ERROR) else if (r == AUDCLNT_E_BUFFER_SIZE_ERROR)
{ {
EHS_LOG_INT("Error", 7, "Indicates that the buffer duration value requested by an exclusive-mode client is out of range. The requested duration value for pull mode must not be greater than 5000 milliseconds; for push mode the duration value must not be greater than 2 seconds."); EHS_LOG_INT(LogType::ERR, 7, "Indicates that the buffer duration value requested by an exclusive-mode client is out of range. The requested duration value for pull mode must not be greater than 5000 milliseconds; for push mode the duration value must not be greater than 2 seconds.");
return; return;
} }
else if (r == AUDCLNT_E_CPUUSAGE_EXCEEDED) else if (r == AUDCLNT_E_CPUUSAGE_EXCEEDED)
{ {
EHS_LOG_INT("Error", 8, "The audio endpoint device has been unplugged, or the audio hardware or associated hardware resources have been reconfigured, disabled, removed, or otherwise made unavailable for use."); EHS_LOG_INT(LogType::ERR, 8, "The audio endpoint device has been unplugged, or the audio hardware or associated hardware resources have been reconfigured, disabled, removed, or otherwise made unavailable for use.");
return; return;
} }
else if (r == AUDCLNT_E_DEVICE_IN_USE) else if (r == AUDCLNT_E_DEVICE_IN_USE)
{ {
EHS_LOG_INT("Error", 9, "The endpoint device is already in use. Either the device is being used in exclusive mode, or the device is being used in shared mode and the caller asked to use the device in exclusive mode."); EHS_LOG_INT(LogType::ERR, 9, "The endpoint device is already in use. Either the device is being used in exclusive mode, or the device is being used in shared mode and the caller asked to use the device in exclusive mode.");
return; return;
} }
else if (r == AUDCLNT_E_ENDPOINT_CREATE_FAILED) else if (r == AUDCLNT_E_ENDPOINT_CREATE_FAILED)
{ {
EHS_LOG_INT("Error", 10, "The method failed to create the audio endpoint for the render or the capture device. This can occur if the audio endpoint device has been unplugged, or the audio hardware or associated hardware resources have been reconfigured, disabled, removed, or otherwise made unavailable for use."); EHS_LOG_INT(LogType::ERR, 10, "The method failed to create the audio endpoint for the render or the capture device. This can occur if the audio endpoint device has been unplugged, or the audio hardware or associated hardware resources have been reconfigured, disabled, removed, or otherwise made unavailable for use.");
return; return;
} }
else if (r == AUDCLNT_E_INVALID_DEVICE_PERIOD) else if (r == AUDCLNT_E_INVALID_DEVICE_PERIOD)
{ {
EHS_LOG_INT("Error", 11, "Indicates that the device period requested by an exclusive-mode client is greater than 5000 milliseconds."); EHS_LOG_INT(LogType::ERR, 11, "Indicates that the device period requested by an exclusive-mode client is greater than 5000 milliseconds.");
return; return;
} }
else if (r == AUDCLNT_E_UNSUPPORTED_FORMAT) else if (r == AUDCLNT_E_UNSUPPORTED_FORMAT)
{ {
EHS_LOG_INT("Error", 12, "The audio engine (shared mode) or audio endpoint device (exclusive mode) does not support the specified format."); EHS_LOG_INT(LogType::ERR, 12, "The audio engine (shared mode) or audio endpoint device (exclusive mode) does not support the specified format.");
return; return;
} }
else if (r == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) else if (r == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED)
{ {
EHS_LOG_INT("Error", 13, "The caller is requesting exclusive-mode use of the endpoint device, but the user has disabled exclusive-mode use of the device."); EHS_LOG_INT(LogType::ERR, 13, "The caller is requesting exclusive-mode use of the endpoint device, but the user has disabled exclusive-mode use of the device.");
return; return;
} }
else if (r == AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL) else if (r == AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL)
{ {
EHS_LOG_INT("Error", 14, "The AUDCLNT_STREAMFLAGS_EVENTCALLBACK flag is set but parameters hnsBufferDuration and hnsPeriodicity are not equal."); EHS_LOG_INT(LogType::ERR, 14, "The AUDCLNT_STREAMFLAGS_EVENTCALLBACK flag is set but parameters hnsBufferDuration and hnsPeriodicity are not equal.");
return; return;
} }
else if (r == AUDCLNT_E_SERVICE_NOT_RUNNING) else if (r == AUDCLNT_E_SERVICE_NOT_RUNNING)
{ {
EHS_LOG_INT("Error", 15, "The Windows audio service is not running."); EHS_LOG_INT(LogType::ERR, 15, "The Windows audio service is not running.");
return; return;
} }
else if (r == E_POINTER) else if (r == E_POINTER)
{ {
EHS_LOG_INT("Error", 16, "Parameter pFormat is NULL."); EHS_LOG_INT(LogType::ERR, 16, "Parameter pFormat is NULL.");
return; return;
} }
else if (r == E_INVALIDARG) else if (r == E_INVALIDARG)
{ {
EHS_LOG_INT("Error", 17, "Parameter pFormat points to an invalid format description; or the AUDCLNT_STREAMFLAGS_LOOPBACK flag is set but ShareMode is not equal to AUDCLNT_SHAREMODE_SHARED; or the AUDCLNT_STREAMFLAGS_CROSSPROCESS flag is set but ShareMode is equal to AUDCLNT_SHAREMODE_EXCLUSIVE.\n" EHS_LOG_INT(LogType::ERR, 17, "Parameter pFormat points to an invalid format description; or the AUDCLNT_STREAMFLAGS_LOOPBACK flag is set but ShareMode is not equal to AUDCLNT_SHAREMODE_SHARED; or the AUDCLNT_STREAMFLAGS_CROSSPROCESS flag is set but ShareMode is equal to AUDCLNT_SHAREMODE_EXCLUSIVE.\n"
"A prior call to SetClientProperties was made with an invalid category for audio/render streams."); "A prior call to SetClientProperties was made with an invalid category for audio/render streams.");
return; return;
} }
else if (r == E_OUTOFMEMORY) else if (r == E_OUTOFMEMORY)
{ {
EHS_LOG_INT("Error", 18, "Out of memory."); EHS_LOG_INT(LogType::ERR, 18, "Out of memory.");
return; return;
} }
else if (FAILED(r)) else if (FAILED(r))
{ {
EHS_LOG_INT("Error", 19, "Failed to initialize audio stream with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 19, "Failed to initialize audio stream with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
@ -265,7 +265,7 @@ namespace ehs
r = client->GetService(__uuidof(IAudioRenderClient), (void**)&playbackClient); r = client->GetService(__uuidof(IAudioRenderClient), (void**)&playbackClient);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 27, "Failed to retrieve audio render client with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 27, "Failed to retrieve audio render client with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
} }
@ -274,7 +274,7 @@ namespace ehs
r = client->GetService(__uuidof(IAudioCaptureClient), (void**)&captureClient); r = client->GetService(__uuidof(IAudioCaptureClient), (void**)&captureClient);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 28, "Failed to retrieve audio capture client with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 28, "Failed to retrieve audio capture client with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
} }
@ -282,14 +282,14 @@ namespace ehs
r = client->GetBufferSize((UINT32*)&maxFrames); r = client->GetBufferSize((UINT32*)&maxFrames);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 29, "Failed to retrieve buffer size with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 29, "Failed to retrieve buffer size with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
r = client->Start(); r = client->Start();
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 30, "Failed to start audio with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 30, "Failed to start audio with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
@ -318,7 +318,7 @@ namespace ehs
HRESULT r = client->Stop(); HRESULT r = client->Stop();
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 0, "Failed to stop audio with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to stop audio with error #" + Str_8::FromNum(r) + ".");
return; return;
} }
@ -340,9 +340,9 @@ namespace ehs
{ {
HRESULT r = client->GetCurrentPadding(&sampleSize); HRESULT r = client->GetCurrentPadding(&sampleSize);
if (r == AUDCLNT_E_DEVICE_INVALIDATED) if (r == AUDCLNT_E_DEVICE_INVALIDATED)
EHS_LOG_INT("Error", 0, "The audio device has been invalidated."); EHS_LOG_INT(LogType::ERR, 0, "The audio device has been invalidated.");
else if (FAILED(r)) else if (FAILED(r))
EHS_LOG_INT("Error", 1, "Failed to retrieve samples padding with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve samples padding with error #" + Str_8::FromNum(r) + ".");
sampleSize = maxFrames - sampleSize; sampleSize = maxFrames - sampleSize;
} }
@ -350,9 +350,9 @@ namespace ehs
{ {
HRESULT r = captureClient->GetNextPacketSize(&sampleSize); HRESULT r = captureClient->GetNextPacketSize(&sampleSize);
if (r == AUDCLNT_E_DEVICE_INVALIDATED) if (r == AUDCLNT_E_DEVICE_INVALIDATED)
EHS_LOG_INT("Error", 0, "The audio device has been invalidated."); EHS_LOG_INT(LogType::ERR, 0, "The audio device has been invalidated.");
else if (FAILED(r)) else if (FAILED(r))
EHS_LOG_INT("Error", 1, "Failed to retrieve samples size with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve samples size with error #" + Str_8::FromNum(r) + ".");
} }
return sampleSize; return sampleSize;
@ -367,19 +367,19 @@ namespace ehs
HRESULT r = client->GetCurrentPadding((UINT32*)&offset); HRESULT r = client->GetCurrentPadding((UINT32*)&offset);
if (r == AUDCLNT_E_DEVICE_INVALIDATED) if (r == AUDCLNT_E_DEVICE_INVALIDATED)
EHS_LOG_INT("Error", 0, "The audio device has been invalidated."); EHS_LOG_INT(LogType::ERR, 0, "The audio device has been invalidated.");
else if (FAILED(r)) else if (FAILED(r))
EHS_LOG_INT("Error", 1, "Failed to retrieve samples padding with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to retrieve samples padding with error #" + Str_8::FromNum(r) + ".");
if (playbackClient) if (playbackClient)
{ {
r = playbackClient->GetBuffer(*frames, &buffer); r = playbackClient->GetBuffer(*frames, &buffer);
if (r == AUDCLNT_E_BUFFER_TOO_LARGE) if (r == AUDCLNT_E_BUFFER_TOO_LARGE)
EHS_LOG_INT("Error", 0, "The given frame size, " + Str_8::FromNum(*frames) + ", must be less than or equal to, " + Str_8::FromNum(maxFrames - *offset) + "."); EHS_LOG_INT(LogType::ERR, 0, "The given frame size, " + Str_8::FromNum(*frames) + ", must be less than or equal to, " + Str_8::FromNum(maxFrames - *offset) + ".");
else if (r == AUDCLNT_E_DEVICE_INVALIDATED) else if (r == AUDCLNT_E_DEVICE_INVALIDATED)
EHS_LOG_INT("Error", 1, "The audio device has been invalidated."); EHS_LOG_INT(LogType::ERR, 1, "The audio device has been invalidated.");
else if (FAILED(r)) else if (FAILED(r))
EHS_LOG_INT("Error", 2, "Failed to retrieve buffer with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to retrieve buffer with error #" + Str_8::FromNum(r) + ".");
} }
else if (captureClient) else if (captureClient)
{ {
@ -387,9 +387,9 @@ namespace ehs
r = captureClient->GetBuffer(&buffer, (UINT32*)frames, (DWORD*)&flags, nullptr, nullptr); r = captureClient->GetBuffer(&buffer, (UINT32*)frames, (DWORD*)&flags, nullptr, nullptr);
if (r == AUDCLNT_E_DEVICE_INVALIDATED) if (r == AUDCLNT_E_DEVICE_INVALIDATED)
EHS_LOG_INT("Error", 1, "The audio device has been invalidated."); EHS_LOG_INT(LogType::ERR, 1, "The audio device has been invalidated.");
else if (FAILED(r)) else if (FAILED(r))
EHS_LOG_INT("Error", 2, "Failed to retrieve buffer with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to retrieve buffer with error #" + Str_8::FromNum(r) + ".");
} }
return buffer; return buffer;
@ -404,17 +404,17 @@ namespace ehs
{ {
HRESULT r = playbackClient->ReleaseBuffer(frames, 0); HRESULT r = playbackClient->ReleaseBuffer(frames, 0);
if (r == AUDCLNT_E_DEVICE_INVALIDATED) if (r == AUDCLNT_E_DEVICE_INVALIDATED)
EHS_LOG_INT("Error", 0, "The audio device has been invalidated."); EHS_LOG_INT(LogType::ERR, 0, "The audio device has been invalidated.");
else if (FAILED(r)) else if (FAILED(r))
EHS_LOG_INT("Error", 1, "Failed to release buffer with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to release buffer with error #" + Str_8::FromNum(r) + ".");
} }
else if (captureClient) else if (captureClient)
{ {
HRESULT r = captureClient->ReleaseBuffer(frames); HRESULT r = captureClient->ReleaseBuffer(frames);
if (r == AUDCLNT_E_DEVICE_INVALIDATED) if (r == AUDCLNT_E_DEVICE_INVALIDATED)
EHS_LOG_INT("Error", 0, "The audio device has been invalidated."); EHS_LOG_INT(LogType::ERR, 0, "The audio device has been invalidated.");
else if (FAILED(r)) else if (FAILED(r))
EHS_LOG_INT("Error", 1, "Failed to release buffer with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to release buffer with error #" + Str_8::FromNum(r) + ".");
} }
} }
@ -429,7 +429,7 @@ namespace ehs
HRESULT r = hdl->OpenPropertyStore(STGM_READ, &pProps); HRESULT r = hdl->OpenPropertyStore(STGM_READ, &pProps);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve interface name with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve interface name with error #" + Str_8::FromNum(r) + ".");
return nullptr; return nullptr;
} }
@ -462,7 +462,7 @@ namespace ehs
HRESULT r = hdl->OpenPropertyStore(STGM_READ, &pProps); HRESULT r = hdl->OpenPropertyStore(STGM_READ, &pProps);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve name with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve name with error #" + Str_8::FromNum(r) + ".");
return nullptr; return nullptr;
} }
@ -496,7 +496,7 @@ namespace ehs
HRESULT r = CoInitialize(nullptr); HRESULT r = CoInitialize(nullptr);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 0, "Failed to initialize COM with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to initialize COM with error #" + Str_8::FromNum(r) + ".");
return result; return result;
} }
@ -504,7 +504,7 @@ namespace ehs
r = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&enumerator); r = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&enumerator);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 1, "Failed to initialize WASAPI with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to initialize WASAPI with error #" + Str_8::FromNum(r) + ".");
return result; return result;
} }
@ -512,7 +512,7 @@ namespace ehs
r = enumerator->GetDefaultAudioEndpoint((EDataFlow)type, eConsole, &deviceHdl); r = enumerator->GetDefaultAudioEndpoint((EDataFlow)type, eConsole, &deviceHdl);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 2, "Failed to retrieve default audio output device with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to retrieve default audio output device with error #" + Str_8::FromNum(r) + ".");
return result; return result;
} }
@ -531,7 +531,7 @@ namespace ehs
HRESULT r = CoInitialize(nullptr); HRESULT r = CoInitialize(nullptr);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 0, "Failed to initialize COM with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to initialize COM with error #" + Str_8::FromNum(r) + ".");
return devices; return devices;
} }
@ -539,7 +539,7 @@ namespace ehs
r = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&enumerator); r = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&enumerator);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 1, "Failed to initialize WASAPI with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to initialize WASAPI with error #" + Str_8::FromNum(r) + ".");
return devices; return devices;
} }
@ -547,7 +547,7 @@ namespace ehs
r = enumerator->EnumAudioEndpoints((EDataFlow)type, (DWORD)state, &collection); r = enumerator->EnumAudioEndpoints((EDataFlow)type, (DWORD)state, &collection);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 2, "Failed to retrieve audio device collection with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to retrieve audio device collection with error #" + Str_8::FromNum(r) + ".");
return devices; return devices;
} }
@ -555,7 +555,7 @@ namespace ehs
r = collection->GetCount((UINT*)&count); r = collection->GetCount((UINT*)&count);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 3, "Failed to retrieve audio device count with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to retrieve audio device count with error #" + Str_8::FromNum(r) + ".");
return devices; return devices;
} }
@ -566,7 +566,7 @@ namespace ehs
r = collection->Item(i, &deviceHdl); r = collection->Item(i, &deviceHdl);
if (FAILED(r)) if (FAILED(r))
{ {
EHS_LOG_INT("Error", 4, "Failed to retrieve audio device with error #" + Str_8::FromNum(r) + "."); EHS_LOG_INT(LogType::ERR, 4, "Failed to retrieve audio device with error #" + Str_8::FromNum(r) + ".");
return devices; return devices;
} }

View File

@ -69,7 +69,7 @@ namespace ehs
const ImgCodec* codec = GetCodec(ext); const ImgCodec* codec = GetCodec(ext);
if (!codec) if (!codec)
{ {
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Codec not found for file extension, \"" + ext + "\".");
return; return;
} }
@ -877,7 +877,7 @@ namespace ehs
const ImgCodec* codec = GetCodec(ext); const ImgCodec* codec = GetCodec(ext);
if (!codec) if (!codec)
{ {
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Codec not found for file extension, \"" + ext + "\".");
return false; return false;
} }
@ -1560,7 +1560,7 @@ namespace ehs
Str_8 imgType = in.ReadStr<Char_8, UInt_64>(4); Str_8 imgType = in.ReadStr<Char_8, UInt_64>(4);
if (imgType != "qoif") if (imgType != "qoif")
{ {
EHS_LOG_INT("Error", 0, "Given data is not in the qoif format."); EHS_LOG_INT(LogType::ERR, 0, "Given data is not in the qoif format.");
return false; return false;
} }
@ -1653,7 +1653,7 @@ namespace ehs
UInt_8 colorType = ihdrData->Read<UInt_8>(); UInt_8 colorType = ihdrData->Read<UInt_8>();
if (colorType == 3) if (colorType == 3)
{ {
EHS_LOG_INT("Error", 1, "Color type of " + Str_8::FromNum(colorType) + " is unsupported."); EHS_LOG_INT(LogType::ERR, 1, "Color type of " + Str_8::FromNum(colorType) + " is unsupported.");
return false; return false;
} }
@ -1670,21 +1670,21 @@ namespace ehs
UInt_8 compression = ihdrData->Read<UInt_8>(); UInt_8 compression = ihdrData->Read<UInt_8>();
if (compression) if (compression)
{ {
EHS_LOG_INT("Error", 2, "Compression method of " + Str_8::FromNum(compression) + " is unsupported."); EHS_LOG_INT(LogType::ERR, 2, "Compression method of " + Str_8::FromNum(compression) + " is unsupported.");
return false; return false;
} }
UInt_8 filter = ihdrData->Read<UInt_8>(); UInt_8 filter = ihdrData->Read<UInt_8>();
if (filter) if (filter)
{ {
EHS_LOG_INT("Error", 3, "Filter method of " + Str_8::FromNum(filter) + " is unsupported."); EHS_LOG_INT(LogType::ERR, 3, "Filter method of " + Str_8::FromNum(filter) + " is unsupported.");
return false; return false;
} }
UInt_8 interlaced = ihdrData->Read<UInt_8>(); UInt_8 interlaced = ihdrData->Read<UInt_8>();
if (interlaced) if (interlaced)
{ {
EHS_LOG_INT("Error", 4, "Interlacing method of " + Str_8::FromNum(interlaced) + " is unsupported."); EHS_LOG_INT(LogType::ERR, 4, "Interlacing method of " + Str_8::FromNum(interlaced) + " is unsupported.");
return false; return false;
} }
@ -1709,7 +1709,7 @@ namespace ehs
int code = inflateInit(&strm); int code = inflateInit(&strm);
if (code != Z_OK) if (code != Z_OK)
{ {
EHS_LOG_INT("Error", 5, "Failed to initialize zlib inflate with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 5, "Failed to initialize zlib inflate with error #" + Str_8::FromNum(code) + ".");
delete[] buffer; delete[] buffer;
return false; return false;
} }
@ -1719,7 +1719,7 @@ namespace ehs
code = inflate(&strm, Z_NO_FLUSH); code = inflate(&strm, Z_NO_FLUSH);
if (code != Z_STREAM_END && code != Z_OK) if (code != Z_STREAM_END && code != Z_OK)
{ {
EHS_LOG_INT("Error", 6, "Failed to zlib inflate with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 6, "Failed to zlib inflate with error #" + Str_8::FromNum(code) + ".");
delete[] buffer; delete[] buffer;
return false; return false;
} }
@ -1728,7 +1728,7 @@ namespace ehs
code = inflateEnd(&strm); code = inflateEnd(&strm);
if (code != Z_OK) if (code != Z_OK)
{ {
EHS_LOG_INT("Error", 7, "Failed to uninitialize zlib inflate with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 7, "Failed to uninitialize zlib inflate with error #" + Str_8::FromNum(code) + ".");
delete[] buffer; delete[] buffer;
return false; return false;
} }

View File

@ -89,7 +89,7 @@ namespace ehs
{ {
if (!encoder) if (!encoder)
{ {
EHS_LOG_INT("Error", 0, "Encoding is not supported for the " + id + " format."); EHS_LOG_INT(LogType::ERR, 0, "Encoding is not supported for the " + id + " format.");
return false; return false;
} }
@ -100,7 +100,7 @@ namespace ehs
{ {
if (!decoder) if (!decoder)
{ {
EHS_LOG_INT("Error", 0, "Decoding is not supported for the " + id + " format."); EHS_LOG_INT(LogType::ERR, 0, "Decoding is not supported for the " + id + " format.");
return false; return false;
} }

View File

@ -23,7 +23,7 @@ namespace ehs
Array<Byte, UInt_64> seq = data.ReadArray<Byte, UInt_64>(8); Array<Byte, UInt_64> seq = data.ReadArray<Byte, UInt_64>(8);
if (seq != pngSeq) if (seq != pngSeq)
{ {
EHS_LOG_INT("Error", 0, "File at file path, \"" + filePath + "\", is not a valid PNG file."); EHS_LOG_INT(LogType::ERR, 0, "File at file path, \"" + filePath + "\", is not a valid PNG file.");
return; return;
} }

View File

@ -60,7 +60,7 @@ namespace ehs
const MdlCodec* codec = GetCodec(ext); const MdlCodec* codec = GetCodec(ext);
if (!codec) if (!codec)
{ {
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Codec not found for file extension, \"" + ext + "\".");
return; return;
} }
@ -203,7 +203,7 @@ namespace ehs
const MdlCodec* codec = GetCodec(ext); const MdlCodec* codec = GetCodec(ext);
if (!codec) if (!codec)
{ {
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Codec not found for file extension, \"" + ext + "\".");
return false; return false;
} }
@ -248,7 +248,7 @@ namespace ehs
Version ver = data.ReadVersion(); Version ver = data.ReadVersion();
if (ver != Version(1, 0, 0)) if (ver != Version(1, 0, 0))
{ {
EHS_LOG_INT("Error", 0, "Cannot decode EHM file version " + Str_8::FromNum(ver.major) + "." + EHS_LOG_INT(LogType::ERR, 0, "Cannot decode EHM file version " + Str_8::FromNum(ver.major) + "." +
Str_8::FromNum(ver.minor) + "." + Str_8::FromNum(ver.patch) + Str_8::FromNum(ver.minor) + "." + Str_8::FromNum(ver.patch) +
", must be version 0.0.0."); ", must be version 0.0.0.");
return false; return false;
@ -293,7 +293,7 @@ namespace ehs
Bone* parent = skeleton.GetBone(parentId); Bone* parent = skeleton.GetBone(parentId);
if (!parent) if (!parent)
{ {
EHS_LOG_INT("Error", 0, "Invalid bone order."); EHS_LOG_INT(LogType::ERR, 0, "Invalid bone order.");
return false; return false;
} }

View File

@ -88,7 +88,7 @@ namespace ehs
{ {
if (!encoder) if (!encoder)
{ {
EHS_LOG_INT("Error", 0, "Encoding is not supported for the " + id + " format."); EHS_LOG_INT(LogType::ERR, 0, "Encoding is not supported for the " + id + " format.");
return false; return false;
} }
@ -99,7 +99,7 @@ namespace ehs
{ {
if (!decoder) if (!decoder)
{ {
EHS_LOG_INT("Error", 0, "Decoding is not supported for the " + id + " format."); EHS_LOG_INT(LogType::ERR, 0, "Decoding is not supported for the " + id + " format.");
return false; return false;
} }

View File

@ -87,7 +87,7 @@ namespace ehs
UInt_64 sent = Send((Byte*)&str[offset], size - offset); UInt_64 sent = Send((Byte*)&str[offset], size - offset);
if (!sent) if (!sent)
{ {
EHS_LOG_INT("Error", 0, "Failed to send data."); EHS_LOG_INT(LogType::ERR, 0, "Failed to send data.");
return; return;
} }
@ -269,7 +269,7 @@ namespace ehs
UInt_64 received = Receive((Byte*)&buffer[offset], contentLength - offset); UInt_64 received = Receive((Byte*)&buffer[offset], contentLength - offset);
if (!received) if (!received)
{ {
EHS_LOG_INT("Error", 0, "Failed to receive data."); EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data.");
return {}; return {};
} }
@ -292,7 +292,7 @@ namespace ehs
UInt_64 received = Receive((Byte*)&hexSize[offset], 1); UInt_64 received = Receive((Byte*)&hexSize[offset], 1);
if (!received) if (!received)
{ {
EHS_LOG_INT("Error", 0, "Failed to receive data."); EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data.");
return 0; return 0;
} }
else if (hexSize[offset] == '\r') else if (hexSize[offset] == '\r')
@ -322,7 +322,7 @@ namespace ehs
UInt_64 received = Receive((Byte*)&buffer[offset], chunkSize + 2 - offset); UInt_64 received = Receive((Byte*)&buffer[offset], chunkSize + 2 - offset);
if (!received) if (!received)
{ {
EHS_LOG_INT("Error", 0, "Failed to receive data."); EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data.");
return {}; return {};
} }

View File

@ -20,7 +20,7 @@ namespace ehs
Int_32 wsaCode = WSAStartup(MAKEWORD(2, 2), &data); Int_32 wsaCode = WSAStartup(MAKEWORD(2, 2), &data);
if (wsaCode) if (wsaCode)
{ {
EHS_LOG_INT("Error", 0, "Failed to start WSA with error #" + Str_8::FromNum(wsaCode) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to start WSA with error #" + Str_8::FromNum(wsaCode) + ".");
return {}; return {};
} }
#endif #endif
@ -30,14 +30,14 @@ namespace ehs
Int_32 code = getaddrinfo(hostname, nullptr, nullptr, &result); Int_32 code = getaddrinfo(hostname, nullptr, nullptr, &result);
if (code) if (code)
{ {
EHS_LOG_INT("Error", 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
return {}; return {};
} }
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (WSACleanup() == SOCKET_ERROR) if (WSACleanup() == SOCKET_ERROR)
{ {
EHS_LOG_INT("Error", 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return {}; return {};
} }
#endif #endif

View File

@ -130,7 +130,7 @@ namespace ehs
int err = SSL_accept(client->sslHdl); int err = SSL_accept(client->sslHdl);
if (!err) if (!err)
{ {
EHS_LOG_INT("Error", 0, "Failed SSL handshake with error #" + Str_8::FromNum(SSL_get_error(client->sslHdl, err)) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed SSL handshake with error #" + Str_8::FromNum(SSL_get_error(client->sslHdl, err)) + ".");
return {}; return {};
} }
@ -158,7 +158,7 @@ namespace ehs
{ {
int code = SSL_get_error(sslHdl, written); int code = SSL_get_error(sslHdl, written);
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
EHS_LOG_INT("Error", 0, "Failed to send data with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to send data with error #" + Str_8::FromNum(code) + ".");
return 0; return 0;
} }
@ -172,7 +172,7 @@ namespace ehs
{ {
int code = SSL_get_error(sslHdl, received); int code = SSL_get_error(sslHdl, received);
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
EHS_LOG_INT("Error", 0, "Failed to receive data with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data with error #" + Str_8::FromNum(code) + ".");
return 0; return 0;
} }
@ -184,13 +184,13 @@ namespace ehs
X509 *cert = d2i_X509(nullptr, &data, (long)size); X509 *cert = d2i_X509(nullptr, &data, (long)size);
if (!cert) if (!cert)
{ {
EHS_LOG_INT("Error", 0, "Invalid certificate."); EHS_LOG_INT(LogType::ERR, 0, "Invalid certificate.");
return; return;
} }
if (SSL_CTX_use_certificate(ctx, cert) != 1) if (SSL_CTX_use_certificate(ctx, cert) != 1)
{ {
EHS_LOG_INT("Error", 1, "Failed to use certificate."); EHS_LOG_INT(LogType::ERR, 1, "Failed to use certificate.");
return; return;
} }
@ -202,13 +202,13 @@ namespace ehs
EVP_PKEY *key = d2i_PrivateKey(EVP_PKEY_RSA, nullptr, &data, (long)size); EVP_PKEY *key = d2i_PrivateKey(EVP_PKEY_RSA, nullptr, &data, (long)size);
if (!key) if (!key)
{ {
EHS_LOG_INT("Error", 0, "Invalid private key."); EHS_LOG_INT(LogType::ERR, 0, "Invalid private key.");
return; return;
} }
if (SSL_CTX_use_PrivateKey(ctx, key) != 1) if (SSL_CTX_use_PrivateKey(ctx, key) != 1)
{ {
EHS_LOG_INT("Error", 1, "Failed to use private key."); EHS_LOG_INT(LogType::ERR, 1, "Failed to use private key.");
return; return;
} }

View File

@ -108,7 +108,7 @@ namespace ehc
int wsaCode = WSAStartup(MAKEWORD(2, 2), &data); int wsaCode = WSAStartup(MAKEWORD(2, 2), &data);
if (wsaCode) if (wsaCode)
{ {
EHS_LOG_INT("Error", 0, "WSAStartup failed with the error #" + Str_8::FromNum(wsaCode) + "."); EHS_LOG_INT(LogType::ERR, 0, "WSAStartup failed with the error #" + Str_8::FromNum(wsaCode) + ".");
return; return;
} }
#endif #endif
@ -130,11 +130,11 @@ namespace ehc
code = errno; code = errno;
#endif #endif
EHS_LOG_INT("Error", 1, "Failed to create socket with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to create socket with error #" + Str_8::FromNum(code) + ".");
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (WSACleanup() == SOCKET_ERROR) if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
#endif #endif
return; return;
@ -182,18 +182,18 @@ namespace ehc
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
code = closesocket(hdl); code = closesocket(hdl);
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
code = close(hdl); code = close(hdl);
if (code == -1) if (code == -1)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
#endif #endif
hdl = EHS_INVALID_SOCKET; hdl = EHS_INVALID_SOCKET;
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (WSACleanup() == SOCKET_ERROR) if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
#endif #endif
bound = false; bound = false;
@ -246,7 +246,7 @@ namespace ehc
if (msg.Size()) if (msg.Size())
dcMsg += " Reason: " + msg; dcMsg += " Reason: " + msg;
EHS_LOG_INT("Info", 0, dcMsg); EHS_LOG_INT(LogType::INFO, 0, dcMsg);
Serializer<> payload(Endianness::LE); Serializer<> payload(Endianness::LE);
payload.WriteStr(msg); payload.WriteStr(msg);
@ -389,7 +389,7 @@ namespace ehc
sPayload.Write(Status::IN_REMOTE_QUEUE); sPayload.Write(Status::IN_REMOTE_QUEUE);
sPayload.Write(end->GetQueueSlot()); sPayload.Write(end->GetQueueSlot());
EHS_LOG_INT("Info", 1, end->GetId() + " connected and is in queue slot " + end->GetQueueSlot() + "."); EHS_LOG_INT(LogType::INFO, 1, end->GetId() + " connected and is in queue slot " + end->GetQueueSlot() + ".");
} }
else else
{ {
@ -401,7 +401,7 @@ namespace ehc
sPayload.Write(Status::ACTIVE); sPayload.Write(Status::ACTIVE);
sPayload.Write(0); sPayload.Write(0);
EHS_LOG_INT("Info", 1, end->GetId() + " connected."); EHS_LOG_INT(LogType::INFO, 1, end->GetId() + " connected.");
} }
end->Send(false, true, false, internalSys, connectedOp, sPayload); end->Send(false, true, false, internalSys, connectedOp, sPayload);
@ -429,7 +429,7 @@ namespace ehc
else else
msg += "."; msg += ".";
EHS_LOG_INT("Info", 2, msg); EHS_LOG_INT(LogType::INFO, 2, msg);
} }
else if (!header.ensure && header.endpointId && header.system == internalSys && header.op == rejectedOp) else if (!header.ensure && header.endpointId && header.system == internalSys && header.op == rejectedOp)
{ {
@ -438,7 +438,7 @@ namespace ehc
Str_8 msg = payload.ReadStr<Char_8, UInt_64>(); Str_8 msg = payload.ReadStr<Char_8, UInt_64>();
if (msg.Size()) if (msg.Size())
EHS_LOG_INT("Info", 3, msg); EHS_LOG_INT(LogType::INFO, 3, msg);
} }
else if (!header.ensure && header.endpointId && header.system == internalSys && header.op == disconnectOp) else if (!header.ensure && header.endpointId && header.system == internalSys && header.op == disconnectOp)
{ {
@ -462,7 +462,7 @@ namespace ehc
if (msg.Size()) if (msg.Size())
dcMsg += " Reason: " + msg; dcMsg += " Reason: " + msg;
EHS_LOG_INT("Info", 4, dcMsg); EHS_LOG_INT(LogType::INFO, 4, dcMsg);
RemoveEndpoint(header.disposition, end->GetHashId()); RemoveEndpoint(header.disposition, end->GetHashId());
@ -493,11 +493,11 @@ namespace ehc
if (activeCb) if (activeCb)
activeCb(this, end); activeCb(this, end);
EHS_LOG_INT("Info", 5, "Your connection status to " + end->GetId() + " has now become active."); EHS_LOG_INT(LogType::INFO, 5, "Your connection status to " + end->GetId() + " has now become active.");
} }
else if (end->GetStatus() == Status::IN_REMOTE_QUEUE && newStatus == Status::IN_REMOTE_QUEUE) else if (end->GetStatus() == Status::IN_REMOTE_QUEUE && newStatus == Status::IN_REMOTE_QUEUE)
{ {
EHS_LOG_INT("Info", 5, "Your queue slot for " + end->GetId() + " is now " + newSlot + "."); EHS_LOG_INT(LogType::INFO, 5, "Your queue slot for " + end->GetId() + " is now " + newSlot + ".");
} }
end->SetStatus(newStatus); end->SetStatus(newStatus);
@ -548,7 +548,7 @@ namespace ehc
if (dropPackets && !header.ensure && header.id < end->GetNextRecvId()) if (dropPackets && !header.ensure && header.id < end->GetNextRecvId())
{ {
EHS_LOG_INT("Info", 6, "Old packet intentionally dropped."); EHS_LOG_INT(LogType::INFO, 6, "Old packet intentionally dropped.");
continue; continue;
} }
@ -568,7 +568,7 @@ namespace ehc
} }
else else
{ {
EHS_LOG_INT("Info", 7, "Corrupted packet."); EHS_LOG_INT(LogType::INFO, 7, "Corrupted packet.");
} }
} }
@ -853,7 +853,7 @@ namespace ehc
{ {
if (hdl == EHS_INVALID_SOCKET) if (hdl == EHS_INVALID_SOCKET)
{ {
EHS_LOG_INT("Error", 0, "Attempted to toggle blocking while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to toggle blocking while socket is not initialized.");
return; return;
} }
@ -862,10 +862,10 @@ namespace ehc
int result = ioctlsocket(hdl, FIONBIO, &r); int result = ioctlsocket(hdl, FIONBIO, &r);
if (result != NO_ERROR) if (result != NO_ERROR)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + ".");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
if (fcntl(hdl, F_SETFL, O_NONBLOCK, blocking) == -1) if (fcntl(hdl, F_SETFL, O_NONBLOCK, blocking) == -1)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + ".");
#endif #endif
} }
@ -874,7 +874,7 @@ namespace ehc
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
u_long r = 0; u_long r = 0;
if (ioctlsocket(hdl, FIONREAD, &r) == SOCKET_ERROR) if (ioctlsocket(hdl, FIONREAD, &r) == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to retrieve socket info."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve socket info.");
return (bool)r; return (bool)r;
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
@ -1043,7 +1043,7 @@ namespace ehc
{ {
if (endpoints[i]->GetTimeout() >= maxTimeout) if (endpoints[i]->GetTimeout() >= maxTimeout)
{ {
EHS_LOG_INT("Info", 0, "Failed to connect to, \"" + endpoints[i]->GetAddress() + ":" + Str_8::FromNum(endpoints[i]->GetPort()) + "\"."); EHS_LOG_INT(LogType::INFO, 0, "Failed to connect to, \"" + endpoints[i]->GetAddress() + ":" + Str_8::FromNum(endpoints[i]->GetPort()) + "\".");
delete endpoints[i]; delete endpoints[i];
@ -1059,7 +1059,7 @@ namespace ehc
{ {
if (endpoints[i]->GetTimeout() >= maxTimeout) if (endpoints[i]->GetTimeout() >= maxTimeout)
{ {
EHS_LOG_INT("Info", 6, endpoints[i]->GetId() + " timed out."); EHS_LOG_INT(LogType::INFO, 6, endpoints[i]->GetId() + " timed out.");
if (disconnectedCb) if (disconnectedCb)
disconnectedCb(this, endpoints[i]); disconnectedCb(this, endpoints[i]);
@ -1120,7 +1120,7 @@ namespace ehc
Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr); Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
@ -1133,7 +1133,7 @@ namespace ehc
dCode = errno; dCode = errno;
#endif #endif
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -1147,13 +1147,13 @@ namespace ehc
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
#endif #endif
@ -1172,7 +1172,7 @@ namespace ehc
code = inet_pton(AF_INET, address, &result.sin_addr); code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
@ -1185,7 +1185,7 @@ namespace ehc
dCode = errno; dCode = errno;
#endif #endif
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -1199,13 +1199,13 @@ namespace ehc
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
#endif #endif
@ -1215,13 +1215,13 @@ namespace ehc
{ {
if (hdl == EHS_INVALID_SOCKET) if (hdl == EHS_INVALID_SOCKET)
{ {
EHS_LOG_INT("Error", 0, "Attempted to receive while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to receive while socket is not initialized.");
return 0; return 0;
} }
if (type == AddrType::IPV4 && size > EHS_IPV4_UDP_PAYLOAD) if (type == AddrType::IPV4 && size > EHS_IPV4_UDP_PAYLOAD)
{ {
EHS_LOG_INT("Error", 1, "Attempted to receive with a buffer size of, \"" + Str_8::FromNum(size) EHS_LOG_INT(LogType::ERR, 1, "Attempted to receive with a buffer size of, \"" + Str_8::FromNum(size)
+ "\", that exceeds, \"" + Str_8::FromNum(EHS_IPV4_UDP_PAYLOAD) + "."); + "\", that exceeds, \"" + Str_8::FromNum(EHS_IPV4_UDP_PAYLOAD) + ".");
} }
@ -1238,13 +1238,13 @@ namespace ehc
{ {
UnInitialize(); UnInitialize();
EHS_LOG_INT("Error", 2, "The buffer size, \"" + Str_8::FromNum(size) + "\" is too small."); EHS_LOG_INT(LogType::ERR, 2, "The buffer size, \"" + Str_8::FromNum(size) + "\" is too small.");
} }
else if (code != WSAECONNRESET && code != WSAEWOULDBLOCK) else if (code != WSAECONNRESET && code != WSAEWOULDBLOCK)
{ {
UnInitialize(); UnInitialize();
EHS_LOG_INT("Error", 3, "Failed to receive with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
} }
return 0; return 0;
@ -1258,7 +1258,7 @@ namespace ehc
{ {
UnInitialize(); UnInitialize();
EHS_LOG_INT("Error", 2, "Failed to receive with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
} }
return 0; return 0;
@ -1280,7 +1280,7 @@ namespace ehc
code = errno; code = errno;
#endif #endif
EHS_LOG_INT("Error", 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
return received; return received;
} }
@ -1302,7 +1302,7 @@ namespace ehc
code = errno; code = errno;
#endif #endif
EHS_LOG_INT("Error", 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
return (UInt_16)received; return (UInt_16)received;
} }

View File

@ -18,11 +18,11 @@ namespace ehs
if (connection) if (connection)
{ {
if (shutdown(hdl, SHUT_RDWR) == -1) if (shutdown(hdl, SHUT_RDWR) == -1)
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + ".");
} }
if (close(hdl) == -1) if (close(hdl) == -1)
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
} }
TCP::TCP() TCP::TCP()
@ -89,7 +89,7 @@ namespace ehs
{ {
UInt_32 code = errno; UInt_32 code = errno;
EHS_LOG_INT("Error", 1, "Failed to create socket with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to create socket with error #" + Str_8::FromNum(code) + ".");
} }
} }
@ -101,11 +101,11 @@ namespace ehs
if (connection) if (connection)
{ {
if (shutdown(hdl, SHUT_RDWR) == -1) if (shutdown(hdl, SHUT_RDWR) == -1)
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + ".");
} }
if (close(hdl) == -1) if (close(hdl) == -1)
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
connection = false; connection = false;
bound = false; bound = false;
@ -138,7 +138,7 @@ namespace ehs
int code = listen(hdl, SOMAXCONN); int code = listen(hdl, SOMAXCONN);
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to listen with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to listen with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
@ -164,7 +164,7 @@ namespace ehs
if (client->hdl == EHS_INVALID_SOCKET) if (client->hdl == EHS_INVALID_SOCKET)
{ {
if (errno != EWOULDBLOCK) if (errno != EWOULDBLOCK)
EHS_LOG_INT("Error", 0, "Failed to accept client with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to accept client with error #" + Str_8::FromNum(errno) + ".");
delete client; delete client;
@ -177,7 +177,7 @@ namespace ehs
if (!inet_ntop(remote.sin6_family, &remote.sin6_addr, tmpAddr, INET6_ADDRSTRLEN)) if (!inet_ntop(remote.sin6_family, &remote.sin6_addr, tmpAddr, INET6_ADDRSTRLEN))
{ {
EHS_LOG_INT("Error", 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + ".");
delete client; delete client;
@ -193,7 +193,7 @@ namespace ehs
if (!inet_ntop(((sockaddr_in*)&remote)->sin_family, &((sockaddr_in*)&remote)->sin_addr, tmpAddr, INET_ADDRSTRLEN)) if (!inet_ntop(((sockaddr_in*)&remote)->sin_family, &((sockaddr_in*)&remote)->sin_addr, tmpAddr, INET_ADDRSTRLEN))
{ {
EHS_LOG_INT("Error", 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(errno) + ".");
delete client; delete client;
@ -228,13 +228,13 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to send while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to send while socket is not initialized.");
return 0; return 0;
} }
if ((!connection && !connected)) if ((!connection && !connected))
{ {
EHS_LOG_INT("Error", 1, "Attempted to send while socket is not connected or a connection."); EHS_LOG_INT(LogType::ERR, 1, "Attempted to send while socket is not connected or a connection.");
return 0; return 0;
} }
@ -245,10 +245,10 @@ namespace ehs
if (err == ECONNRESET) if (err == ECONNRESET)
{ {
Release(); Release();
EHS_LOG_INT("Information", 0, "Connection dropped."); EHS_LOG_INT(LogType::INFO, 0, "Connection dropped.");
} }
else else
EHS_LOG_INT("Error", 1, "Failed to send with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to send with error #" + Str_8::FromNum(err) + ".");
return 0; return 0;
} }
@ -260,13 +260,13 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to receive while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to receive while socket is not initialized.");
return 0; return 0;
} }
if ((!connection && !connected)) if ((!connection && !connected))
{ {
EHS_LOG_INT("Error", 1, "Attempted to receive while socket is not connected or a connection."); EHS_LOG_INT(LogType::ERR, 1, "Attempted to receive while socket is not connected or a connection.");
return 0; return 0;
} }
@ -277,11 +277,11 @@ namespace ehs
if (err == ECONNRESET) if (err == ECONNRESET)
{ {
Release(); Release();
EHS_LOG_INT("Information", 0, "Connection dropped."); EHS_LOG_INT(LogType::INFO, 0, "Connection dropped.");
} }
else if (err != EWOULDBLOCK) else if (err != EWOULDBLOCK)
{ {
EHS_LOG_INT("Error", 2, "Failed to receive with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to receive with error #" + Str_8::FromNum(err) + ".");
} }
return 0; return 0;
@ -294,14 +294,14 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to toggle blocking while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to toggle blocking while socket is not initialized.");
return; return;
} }
int flags = fcntl(hdl, F_GETFL, 0); int flags = fcntl(hdl, F_GETFL, 0);
if (flags == -1) if (flags == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve flags."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve flags.");
return; return;
} }
@ -311,7 +311,7 @@ namespace ehs
flags |= O_NONBLOCK; flags |= O_NONBLOCK;
if (fcntl(hdl, F_SETFL, flags) == -1) if (fcntl(hdl, F_SETFL, flags) == -1)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + ".");
} }
bool TCP::IsBlocking() const bool TCP::IsBlocking() const
@ -319,7 +319,7 @@ namespace ehs
int flags = fcntl(hdl, F_GETFL, 0); int flags = fcntl(hdl, F_GETFL, 0);
if (flags == -1) if (flags == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to retrieve flags."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve flags.");
return true; return true;
} }
@ -342,14 +342,14 @@ namespace ehs
int code = inet_pton(AF_INET6, address, &result.sin6_addr); int code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -361,7 +361,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6));
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
@ -378,14 +378,14 @@ namespace ehs
int code = inet_pton(AF_INET, address, &result.sin_addr); int code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -396,7 +396,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in));
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
@ -411,14 +411,14 @@ namespace ehs
int code = inet_pton(AF_INET6, address, &result.sin6_addr); int code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
@ -428,11 +428,11 @@ namespace ehs
int err = errno; int err = errno;
if (err == ETIMEDOUT) if (err == ETIMEDOUT)
{ {
EHS_LOG_INT("Information", 2, "Connection attempt timed-out."); EHS_LOG_INT(LogType::INFO, 2, "Connection attempt timed-out.");
} }
else else
{ {
EHS_LOG_INT("Error", 3, "Failed to connect with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
} }
return; return;
@ -448,14 +448,14 @@ namespace ehs
int code = inet_pton(AF_INET, address, &result.sin_addr); int code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
@ -465,11 +465,11 @@ namespace ehs
int err = errno; int err = errno;
if (err == ETIMEDOUT) if (err == ETIMEDOUT)
{ {
EHS_LOG_INT("Information", 2, "Connection attempt timed-out."); EHS_LOG_INT(LogType::INFO, 2, "Connection attempt timed-out.");
} }
else else
{ {
EHS_LOG_INT("Error", 3, "Failed to connect with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
} }
return; return;

View File

@ -17,15 +17,15 @@ namespace ehs
{ {
code = shutdown(hdl, SD_SEND); code = shutdown(hdl, SD_SEND);
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
code = closesocket(hdl); code = closesocket(hdl);
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
if (!connection && WSACleanup() == SOCKET_ERROR) if (!connection && WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
} }
TCP::TCP() TCP::TCP()
@ -86,7 +86,7 @@ namespace ehs
int code = WSAStartup(MAKEWORD(2, 2), &data); int code = WSAStartup(MAKEWORD(2, 2), &data);
if (code) if (code)
{ {
EHS_LOG_INT("Error", 0, "WSAStartup failed with the error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "WSAStartup failed with the error #" + Str_8::FromNum(code) + ".");
return; return;
} }
@ -101,10 +101,10 @@ namespace ehs
{ {
UInt_32 code = WSAGetLastError(); UInt_32 code = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to create socket with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to create socket with error #" + Str_8::FromNum(code) + ".");
if (WSACleanup() == SOCKET_ERROR) if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
} }
} }
@ -119,17 +119,17 @@ namespace ehs
{ {
code = shutdown(hdl, SD_SEND); code = shutdown(hdl, SD_SEND);
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
code = closesocket(hdl); code = closesocket(hdl);
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
hdl = EHS_INVALID_SOCKET; hdl = EHS_INVALID_SOCKET;
if (!connection && WSACleanup() == SOCKET_ERROR) if (!connection && WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
connection = false; connection = false;
bound = false; bound = false;
@ -161,7 +161,7 @@ namespace ehs
int code = listen(hdl, SOMAXCONN); int code = listen(hdl, SOMAXCONN);
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 0, "Failed to listen with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to listen with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
@ -189,7 +189,7 @@ namespace ehs
Int_32 code = WSAGetLastError(); Int_32 code = WSAGetLastError();
if (code != WSAEWOULDBLOCK) if (code != WSAEWOULDBLOCK)
EHS_LOG_INT("Error", 0, "Failed to accept client with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to accept client with error #" + Str_8::FromNum(code) + ".");
delete client; delete client;
@ -204,7 +204,7 @@ namespace ehs
{ {
Int_32 code = WSAGetLastError(); Int_32 code = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
delete client; delete client;
@ -222,7 +222,7 @@ namespace ehs
{ {
Int_32 code = WSAGetLastError(); Int_32 code = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
delete client; delete client;
@ -257,13 +257,13 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to send while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to send while socket is not initialized.");
return 0; return 0;
} }
if ((!connection && !connected)) if ((!connection && !connected))
{ {
EHS_LOG_INT("Error", 1, "Attempted to send while socket is not connected or a connection."); EHS_LOG_INT(LogType::ERR, 1, "Attempted to send while socket is not connected or a connection.");
return 0; return 0;
} }
@ -274,10 +274,10 @@ namespace ehs
if (err == WSAECONNRESET) if (err == WSAECONNRESET)
{ {
Release(); Release();
EHS_LOG_INT("Information", 0, "Connection dropped."); EHS_LOG_INT(LogType::INFO, 0, "Connection dropped.");
} }
else else
EHS_LOG_INT("Error", 1, "Failed to send with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to send with error #" + Str_8::FromNum(err) + ".");
return 0; return 0;
} }
@ -289,13 +289,13 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to receive while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to receive while socket is not initialized.");
return 0; return 0;
} }
if ((!connection && !connected)) if ((!connection && !connected))
{ {
EHS_LOG_INT("Error", 1, "Attempted to receive while socket is not connected or a connection."); EHS_LOG_INT(LogType::ERR, 1, "Attempted to receive while socket is not connected or a connection.");
return 0; return 0;
} }
@ -306,15 +306,15 @@ namespace ehs
if (err == WSAECONNRESET) if (err == WSAECONNRESET)
{ {
Release(); Release();
EHS_LOG_INT("Information", 0, "Connection dropped."); EHS_LOG_INT(LogType::INFO, 0, "Connection dropped.");
} }
else if (err == WSAECONNABORTED) else if (err == WSAECONNABORTED)
{ {
EHS_LOG_INT("Information", 1, "Receiving timed-out."); EHS_LOG_INT(LogType::INFO, 1, "Receiving timed-out.");
} }
else if (err != WSAEWOULDBLOCK) else if (err != WSAEWOULDBLOCK)
{ {
EHS_LOG_INT("Error", 2, "Failed to receive with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to receive with error #" + Str_8::FromNum(err) + ".");
} }
return 0; return 0;
@ -327,7 +327,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to toggle blocking while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to toggle blocking while socket is not initialized.");
return; return;
} }
@ -335,14 +335,14 @@ namespace ehs
int result = ioctlsocket(hdl, FIONBIO, &r); int result = ioctlsocket(hdl, FIONBIO, &r);
if (result != NO_ERROR) if (result != NO_ERROR)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + ".");
} }
bool TCP::IsBlocking() const bool TCP::IsBlocking() const
{ {
u_long r = 0; u_long r = 0;
if (ioctlsocket(hdl, FIONREAD, &r) == SOCKET_ERROR) if (ioctlsocket(hdl, FIONREAD, &r) == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to retrieve socket info."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve socket info.");
return (bool)r; return (bool)r;
} }
@ -363,14 +363,14 @@ namespace ehs
int code = inet_pton(AF_INET6, address, &result.sin6_addr); int code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -382,7 +382,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6));
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
@ -399,14 +399,14 @@ namespace ehs
int code = inet_pton(AF_INET, address, &result.sin_addr); int code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -418,7 +418,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in));
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
@ -433,14 +433,14 @@ namespace ehs
int code = inet_pton(AF_INET6, address, &result.sin6_addr); int code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
@ -450,11 +450,11 @@ namespace ehs
int err = WSAGetLastError(); int err = WSAGetLastError();
if (err == WSAETIMEDOUT) if (err == WSAETIMEDOUT)
{ {
EHS_LOG_INT("Information", 2, "Connection attempt timed-out."); EHS_LOG_INT(LogType::INFO, 2, "Connection attempt timed-out.");
} }
else else
{ {
EHS_LOG_INT("Error", 3, "Failed to connect with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
} }
return; return;
@ -470,14 +470,14 @@ namespace ehs
int code = inet_pton(AF_INET, address, &result.sin_addr); int code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
@ -487,11 +487,11 @@ namespace ehs
int err = WSAGetLastError(); int err = WSAGetLastError();
if (err == WSAETIMEDOUT) if (err == WSAETIMEDOUT)
{ {
EHS_LOG_INT("Information", 2, "Connection attempt timed-out."); EHS_LOG_INT(LogType::INFO, 2, "Connection attempt timed-out.");
} }
else else
{ {
EHS_LOG_INT("Error", 3, "Failed to connect with error #" + Str_8::FromNum(err) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
} }
return; return;

View File

@ -17,7 +17,7 @@ namespace ehs
Int_32 code = close(hdl); Int_32 code = close(hdl);
if (code == -1) if (code == -1)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
} }
UDP::UDP() UDP::UDP()
@ -39,7 +39,7 @@ namespace ehs
{ {
UInt_32 code = errno; UInt_32 code = errno;
EHS_LOG_INT("Error", 1, "Failed to create socket with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to create socket with error #" + Str_8::FromNum(code) + ".");
return; return;
} }
@ -87,9 +87,9 @@ namespace ehs
if (!IsValid()) if (!IsValid())
return; return;
Int_32 code = close(hdl); const Int_32 code = close(hdl);
if (code == -1) if (code == -1)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
hdl = EHS_INVALID_SOCKET; hdl = EHS_INVALID_SOCKET;
@ -126,7 +126,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to receive while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to receive while socket is not initialized.");
return 0; return 0;
} }
@ -142,7 +142,7 @@ namespace ehs
{ {
Release(); Release();
EHS_LOG_INT("Error", 1, "Failed to receive with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
} }
return 0; return 0;
@ -156,7 +156,7 @@ namespace ehs
{ {
Int_32 code = errno; Int_32 code = errno;
EHS_LOG_INT("Error", 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
return received; return received;
} }
@ -173,7 +173,7 @@ namespace ehs
{ {
Int_32 code = errno; Int_32 code = errno;
EHS_LOG_INT("Error", 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
return received; return received;
} }
@ -190,12 +190,12 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to toggle blocking while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to toggle blocking while socket is not initialized.");
return; return;
} }
if (fcntl(hdl, F_SETFL, O_NONBLOCK, blocking) == -1) if (fcntl(hdl, F_SETFL, O_NONBLOCK, blocking) == -1)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + ".");
} }
bool UDP::IsBlocking() const bool UDP::IsBlocking() const
@ -219,14 +219,14 @@ namespace ehs
Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr); Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -238,7 +238,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6));
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
} }
@ -254,14 +254,14 @@ namespace ehs
int code = inet_pton(AF_INET, address, &result.sin_addr); int code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -273,7 +273,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in));
if (code == -1) if (code == -1)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return; return;
} }
} }
@ -282,7 +282,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Info", 0, "Attempted to send while socket is not initialized."); EHS_LOG_INT(LogType::INFO, 0, "Attempted to send while socket is not initialized.");
return 0; return 0;
} }
@ -293,14 +293,14 @@ namespace ehs
Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr); Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 1, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + address + "\" is not valid.");
return 0; return 0;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return 0; return 0;
} }
@ -309,7 +309,7 @@ namespace ehs
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 3, "Failed to send with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to send with error #" + Str_8::FromNum(dCode) + ".");
Release(); Release();
@ -323,7 +323,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Info", 0, "Attempted to send while socket is not initialized."); EHS_LOG_INT(LogType::INFO, 0, "Attempted to send while socket is not initialized.");
return 0; return 0;
} }
@ -334,14 +334,14 @@ namespace ehs
int code = inet_pton(AF_INET, address, &result.sin_addr); int code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 1, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + address + "\" is not valid.");
return 0; return 0;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return 0; return 0;
} }
@ -350,7 +350,7 @@ namespace ehs
{ {
Int_32 dCode = errno; Int_32 dCode = errno;
EHS_LOG_INT("Error", 3, "Failed to send with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to send with error #" + Str_8::FromNum(dCode) + ".");
Release(); Release();

View File

@ -13,10 +13,10 @@ namespace ehs
Int_32 code = closesocket(hdl); Int_32 code = closesocket(hdl);
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
if (WSACleanup() == SOCKET_ERROR) if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
} }
UDP::UDP() UDP::UDP()
@ -32,7 +32,7 @@ namespace ehs
int code = WSAStartup(MAKEWORD(2, 2), &data); int code = WSAStartup(MAKEWORD(2, 2), &data);
if (code) if (code)
{ {
EHS_LOG_INT("Error", 0, "WSAStartup failed with the error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "WSAStartup failed with the error #" + Str_8::FromNum(code) + ".");
return; return;
} }
@ -47,10 +47,10 @@ namespace ehs
{ {
UInt_32 code = WSAGetLastError(); UInt_32 code = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to create socket with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to create socket with error #" + Str_8::FromNum(code) + ".");
if (WSACleanup() == SOCKET_ERROR) if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
@ -100,12 +100,12 @@ namespace ehs
Int_32 code = closesocket(hdl); Int_32 code = closesocket(hdl);
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
hdl = EHS_INVALID_SOCKET; hdl = EHS_INVALID_SOCKET;
if (WSACleanup() == SOCKET_ERROR) if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
bound = false; bound = false;
} }
@ -140,7 +140,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to receive while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to receive while socket is not initialized.");
return 0; return 0;
} }
@ -155,7 +155,7 @@ namespace ehs
{ {
Release(); Release();
EHS_LOG_INT("Error", 1, "Failed to receive with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
} }
return 0; return 0;
@ -169,7 +169,7 @@ namespace ehs
{ {
Int_32 code = WSAGetLastError(); Int_32 code = WSAGetLastError();
EHS_LOG_INT("Error", 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
return received; return received;
} }
@ -186,7 +186,7 @@ namespace ehs
{ {
Int_32 code = WSAGetLastError(); Int_32 code = WSAGetLastError();
EHS_LOG_INT("Error", 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
return received; return received;
} }
@ -203,7 +203,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Error", 0, "Attempted to toggle blocking while socket is not initialized."); EHS_LOG_INT(LogType::ERR, 0, "Attempted to toggle blocking while socket is not initialized.");
return; return;
} }
@ -211,14 +211,14 @@ namespace ehs
int result = ioctlsocket(hdl, FIONBIO, &r); int result = ioctlsocket(hdl, FIONBIO, &r);
if (result != NO_ERROR) if (result != NO_ERROR)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + ".");
} }
bool UDP::IsBlocking() const bool UDP::IsBlocking() const
{ {
u_long r = 0; u_long r = 0;
if (ioctlsocket(hdl, FIONREAD, &r) == SOCKET_ERROR) if (ioctlsocket(hdl, FIONREAD, &r) == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to retrieve socket info."); EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve socket info.");
return (bool)r; return (bool)r;
} }
@ -239,14 +239,14 @@ namespace ehs
Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr); Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -258,7 +258,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6));
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
} }
@ -274,14 +274,14 @@ namespace ehs
int code = inet_pton(AF_INET, address, &result.sin_addr); int code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return; return;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return; return;
} }
} }
@ -293,7 +293,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in)); int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in));
if (code == SOCKET_ERROR) if (code == SOCKET_ERROR)
{ {
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return; return;
} }
} }
@ -302,7 +302,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Info", 0, "Attempted to send while socket is not initialized."); EHS_LOG_INT(LogType::INFO, 0, "Attempted to send while socket is not initialized.");
return 0; return 0;
} }
@ -313,14 +313,14 @@ namespace ehs
Int_32 code = inet_pton(AF_INET6, addr, &result.sin6_addr); Int_32 code = inet_pton(AF_INET6, addr, &result.sin6_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 1, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + address + "\" is not valid.");
return 0; return 0;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return 0; return 0;
} }
@ -329,7 +329,7 @@ namespace ehs
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 3, "Failed to send with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to send with error #" + Str_8::FromNum(dCode) + ".");
Release(); Release();
@ -343,7 +343,7 @@ namespace ehs
{ {
if (!IsValid()) if (!IsValid())
{ {
EHS_LOG_INT("Info", 0, "Attempted to send while socket is not initialized."); EHS_LOG_INT(LogType::INFO, 0, "Attempted to send while socket is not initialized.");
return 0; return 0;
} }
@ -354,14 +354,14 @@ namespace ehs
int code = inet_pton(AF_INET, addr, &result.sin_addr); int code = inet_pton(AF_INET, addr, &result.sin_addr);
if (!code) if (!code)
{ {
EHS_LOG_INT("Error", 1, "The given address, \"" + address + "\" is not valid."); EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + address + "\" is not valid.");
return 0; return 0;
} }
else if (code == -1) else if (code == -1)
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return 0; return 0;
} }
@ -370,7 +370,7 @@ namespace ehs
{ {
Int_32 dCode = WSAGetLastError(); Int_32 dCode = WSAGetLastError();
EHS_LOG_INT("Error", 3, "Failed to send with error #" + Str_8::FromNum(dCode) + "."); EHS_LOG_INT(LogType::ERR, 3, "Failed to send with error #" + Str_8::FromNum(dCode) + ".");
Release(); Release();

View File

@ -91,19 +91,19 @@ namespace ehs
if (authRes.GetCode() == 400) if (authRes.GetCode() == 400)
{ {
EHS_LOG_INT("Error", 0, "Could not authorize with Spotify because the client id was invalid."); EHS_LOG_INT(LogType::ERR, 0, "Could not authorize with Spotify because the client id was invalid.");
return false; return false;
} }
else if (authRes.GetCode() == 403) else if (authRes.GetCode() == 403)
{ {
EHS_LOG_INT("Error", 1, "Could not authorize with Spotify because the secret was invalid."); EHS_LOG_INT(LogType::ERR, 1, "Could not authorize with Spotify because the secret was invalid.");
return false; return false;
} }
else if (authRes.GetCode() != 200) else if (authRes.GetCode() != 200)
{ {
EHS_LOG_INT("Error", 2, "Could not authorize with Spotify with code " + Str_8::FromNum(authRes.GetCode()) + "."); EHS_LOG_INT(LogType::ERR, 2, "Could not authorize with Spotify with code " + Str_8::FromNum(authRes.GetCode()) + ".");
return false; return false;
} }
@ -608,7 +608,7 @@ namespace ehs
if (res.GetCode() != 200) if (res.GetCode() != 200)
{ {
EHS_LOG_INT("Error", 0, "Failed to reauthorize with Spotify with code #" + Str_8::FromNum(res.GetCode()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to reauthorize with Spotify with code #" + Str_8::FromNum(res.GetCode()) + ".");
client.Release(); client.Release();
return false; return false;
} }

View File

@ -89,21 +89,21 @@ namespace ehs
{ {
client.Release(); client.Release();
EHS_LOG_INT("Error", 0, "Could not authorize with Twitch because the client id was invalid."); EHS_LOG_INT(LogType::ERR, 0, "Could not authorize with Twitch because the client id was invalid.");
return false; return false;
} else if (authRes.GetCode() == 403) } else if (authRes.GetCode() == 403)
{ {
client.Release(); client.Release();
EHS_LOG_INT("Error", 1, "Could not authorize with Twitch because the secret was invalid."); EHS_LOG_INT(LogType::ERR, 1, "Could not authorize with Twitch because the secret was invalid.");
return false; return false;
} else if (authRes.GetCode() != 200) } else if (authRes.GetCode() != 200)
{ {
client.Release(); client.Release();
EHS_LOG_INT("Error", 2, "Could not authorize with Twitch."); EHS_LOG_INT(LogType::ERR, 2, "Could not authorize with Twitch.");
return false; return false;
} }

View File

@ -211,7 +211,7 @@ namespace ehs
{ {
if (!isIndex) if (!isIndex)
{ {
EHS_LOG_INT("Error", 0, "Index has ended, but never started."); EHS_LOG_INT(LogType::ERR, 0, "Index has ended, but never started.");
return levels; return levels;
} }
@ -219,7 +219,7 @@ namespace ehs
levels.Push(Str_8(start, i - start)); levels.Push(Str_8(start, i - start));
else else
{ {
EHS_LOG_INT("Error", 1, "Index has no value."); EHS_LOG_INT(LogType::ERR, 1, "Index has no value.");
return levels; return levels;
} }
@ -228,7 +228,7 @@ namespace ehs
} }
else if (isIndex && (*i < '0' || *i > '9')) else if (isIndex && (*i < '0' || *i > '9'))
{ {
EHS_LOG_INT("Error", 2, "Index has an invalid character, \"" + Str_8(i, 1) + "\". Index must be a whole number."); EHS_LOG_INT(LogType::ERR, 2, "Index has an invalid character, \"" + Str_8(i, 1) + "\". Index must be a whole number.");
return levels; return levels;
} }
else if (*i == '.') else if (*i == '.')
@ -240,7 +240,7 @@ namespace ehs
} }
else if (!isIndex && *i != '-' && *i != '_' && (*i < 'A' || *i > 'Z') && (*i < 'a' || *i > 'z')) else if (!isIndex && *i != '-' && *i != '_' && (*i < 'A' || *i > 'Z') && (*i < 'a' || *i > 'z'))
{ {
EHS_LOG_INT("Error", 3, "Member variable has an invalid character, \"" + Str_8(i, 1) + "\"."); EHS_LOG_INT(LogType::ERR, 3, "Member variable has an invalid character, \"" + Str_8(i, 1) + "\".");
return levels; return levels;
} }
} }

View File

@ -11,7 +11,7 @@ namespace ehs
{ {
int code = chdir(dir); int code = chdir(dir);
if (code == -1) if (code == -1)
EHS_LOG_INT("Error", 0, strerror(errno)); EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
} }
Str_8 FileSystem::GetWorkingDir() Str_8 FileSystem::GetWorkingDir()
@ -19,7 +19,7 @@ namespace ehs
char result[EHS_MAX_PATH]; char result[EHS_MAX_PATH];
if (!getcwd(result, EHS_MAX_PATH)) if (!getcwd(result, EHS_MAX_PATH))
EHS_LOG_INT("Error", 0, strerror(errno)); EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
return result; return result;
} }
@ -27,6 +27,6 @@ namespace ehs
void FileSystem::SetOwner(const Str_8& dir, const UInt_32 userId, const UInt_32 groupId) void FileSystem::SetOwner(const Str_8& dir, const UInt_32 userId, const UInt_32 groupId)
{ {
if (chown(dir, userId, groupId) == -1) if (chown(dir, userId, groupId) == -1)
EHS_LOG_INT("Error", 0, strerror(errno)); EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
} }
} }

View File

@ -10,7 +10,7 @@ namespace ehs
return; return;
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
EHS_LOG_INT("Error", 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
Mutex::Mutex() Mutex::Mutex()
@ -43,7 +43,7 @@ namespace ehs
hdl = CreateMutexW(nullptr, FALSE, nullptr); hdl = CreateMutexW(nullptr, FALSE, nullptr);
if (!hdl) if (!hdl)
{ {
EHS_LOG_INT("Error", 0, "Failed to create mutex with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -56,7 +56,7 @@ namespace ehs
return; return;
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
EHS_LOG_INT("Error", 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
initialized = false; initialized = false;
} }
@ -68,7 +68,7 @@ namespace ehs
if (WaitForSingleObject(hdl, EHS_INFINITE) == WAIT_FAILED) if (WaitForSingleObject(hdl, EHS_INFINITE) == WAIT_FAILED)
{ {
EHS_LOG_INT("Error", 0, "Failed to lock mutex with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to lock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
@ -81,7 +81,7 @@ namespace ehs
return; return;
if (!ReleaseMutex(hdl)) if (!ReleaseMutex(hdl))
EHS_LOG_INT("Error", 0, "Failed to unlock mutex with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to unlock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
locked = false; locked = false;
} }

View File

@ -11,7 +11,7 @@ namespace ehs
return; return;
if (dlclose(hdl)) if (dlclose(hdl))
EHS_LOG_INT("Error", 0, "Failed to close."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close.");
} }
Open::Open() Open::Open()
@ -77,7 +77,7 @@ namespace ehs
hdl = dlopen(filePath, RTLD_LAZY); hdl = dlopen(filePath, RTLD_LAZY);
if (!hdl) if (!hdl)
{ {
EHS_LOG_INT("Error", 0, dlerror()); EHS_LOG_INT(LogType::ERR, 0, dlerror());
return; return;
} }
} }
@ -88,7 +88,7 @@ namespace ehs
return; return;
if (dlclose(hdl)) if (dlclose(hdl))
EHS_LOG_INT("Error", 0, "Failed to close."); EHS_LOG_INT(LogType::ERR, 0, "Failed to close.");
hdl = nullptr; hdl = nullptr;
} }
@ -102,7 +102,7 @@ namespace ehs
if (!func) if (!func)
{ {
dlerror(); dlerror();
EHS_LOG_INT("Error", 0, "Undefined symbol, \"" + symbol + "\"."); EHS_LOG_INT(LogType::ERR, 0, "Undefined symbol, \"" + symbol + "\".");
Release(); Release();
return nullptr; return nullptr;
} }

View File

@ -13,7 +13,7 @@ namespace ehs
return; return;
if (sem_destroy(&hdl) == -1) if (sem_destroy(&hdl) == -1)
EHS_LOG_INT("Error", 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + ".");
valid = false; valid = false;
} }
@ -92,14 +92,14 @@ namespace ehs
{ {
sem_t* result = sem_open("/" + GetName(), O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, GetInitial()); sem_t* result = sem_open("/" + GetName(), O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, GetInitial());
if (!result) if (!result)
EHS_LOG_INT("Error", 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + ".");
hdl = *result; hdl = *result;
} }
else else
{ {
if (sem_init(&hdl, 0, GetInitial()) == -1) if (sem_init(&hdl, 0, GetInitial()) == -1)
EHS_LOG_INT("Error", 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + ".");
} }
valid = true; valid = true;
@ -111,7 +111,7 @@ namespace ehs
return; return;
if (sem_destroy(&hdl) == -1) if (sem_destroy(&hdl) == -1)
EHS_LOG_INT("Error", 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + ".");
hdl = {}; hdl = {};
@ -124,7 +124,7 @@ namespace ehs
return; return;
if (sem_post(&hdl) == -1) if (sem_post(&hdl) == -1)
EHS_LOG_INT("Error", 0, "Failed to signal semaphore with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to signal semaphore with error #" + Str_8::FromNum(errno) + ".");
} }
bool Semaphore::Wait(const UInt_32 timeout) bool Semaphore::Wait(const UInt_32 timeout)
@ -148,7 +148,7 @@ namespace ehs
{ {
int code = errno; int code = errno;
if (code != ETIMEDOUT) if (code != ETIMEDOUT)
EHS_LOG_INT("Error", 0, "Failed to wait for semaphore with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to wait for semaphore with error #" + Str_8::FromNum(errno) + ".");
return false; return false;
} }

View File

@ -12,7 +12,7 @@ namespace ehs
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
{ {
DWORD code = GetLastError(); DWORD code = GetLastError();
EHS_LOG_INT("Error", 0, Str_8("Failed to free semaphore with error #") + code + "."); EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to free semaphore with error #") + code + ".");
} }
} }
@ -82,7 +82,7 @@ namespace ehs
hdl = CreateSemaphoreW(nullptr, (LONG)GetInitial(), EHS_SINT_32_MAX, UTF::To_16(GetName())); hdl = CreateSemaphoreW(nullptr, (LONG)GetInitial(), EHS_SINT_32_MAX, UTF::To_16(GetName()));
if (!hdl) if (!hdl)
EHS_LOG_INT("Error", 0, Str_8("Failed to create semaphore with error #") + GetLastError() + "."); EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to create semaphore with error #") + GetLastError() + ".");
} }
void Semaphore::Release() void Semaphore::Release()
@ -93,7 +93,7 @@ namespace ehs
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
{ {
DWORD code = GetLastError(); DWORD code = GetLastError();
EHS_LOG_INT("Error", 0, Str_8("Failed to free semaphore with error #") + code + "."); EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to free semaphore with error #") + code + ".");
} }
hdl = nullptr; hdl = nullptr;
} }
@ -104,7 +104,7 @@ namespace ehs
return; return;
if (!ReleaseSemaphore(hdl, (LONG)inc, nullptr)) if (!ReleaseSemaphore(hdl, (LONG)inc, nullptr))
EHS_LOG_INT("Error", 0, Str_8("Failed to release semaphore with error #") + GetLastError() + "."); EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to release semaphore with error #") + GetLastError() + ".");
} }
bool Semaphore::Wait(const UInt_32 timeout) bool Semaphore::Wait(const UInt_32 timeout)
@ -115,12 +115,12 @@ namespace ehs
DWORD result = WaitForSingleObject(hdl, timeout); DWORD result = WaitForSingleObject(hdl, timeout);
if (result == WAIT_ABANDONED) if (result == WAIT_ABANDONED)
{ {
EHS_LOG_INT("Error", 0, "Wait abandoned."); EHS_LOG_INT(LogType::ERR, 0, "Wait abandoned.");
return false; return false;
} }
else if (result == WAIT_FAILED) else if (result == WAIT_FAILED)
{ {
EHS_LOG_INT("Error", 1, Str_8("Wait failed with error #") + GetLastError() + "."); EHS_LOG_INT(LogType::ERR, 1, Str_8("Wait failed with error #") + GetLastError() + ".");
return false; return false;
} }
else if (result == WAIT_TIMEOUT) else if (result == WAIT_TIMEOUT)

View File

@ -60,7 +60,7 @@ namespace ehs
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
hdl = CreateThread(nullptr, stackSize, (LPTHREAD_START_ROUTINE)cb, args, 0, (DWORD*)&id); hdl = CreateThread(nullptr, stackSize, (LPTHREAD_START_ROUTINE)cb, args, 0, (DWORD*)&id);
if (!hdl) if (!hdl)
EHS_LOG_INT("Error", 0, "Failed to start thread with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to start thread with error #" + Str_8::FromNum(GetLastError()) + ".");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
UInt_64* rArgs = new UInt_64[sizeof(UInt_64) * 2]; UInt_64* rArgs = new UInt_64[sizeof(UInt_64) * 2];
rArgs[0] = (UInt_64)cb; rArgs[0] = (UInt_64)cb;
@ -79,7 +79,7 @@ namespace ehs
unsigned int r = WaitForSingleObject(hdl, timeout); unsigned int r = WaitForSingleObject(hdl, timeout);
if (r == WAIT_ABANDONED) if (r == WAIT_ABANDONED)
{ {
EHS_LOG_INT("Error", 0, "Abandoned wait because a mutex was not released."); EHS_LOG_INT(LogType::ERR, 0, "Abandoned wait because a mutex was not released.");
return false; return false;
} }
else if (r == WAIT_TIMEOUT) else if (r == WAIT_TIMEOUT)
@ -88,7 +88,7 @@ namespace ehs
} }
else if (r == WAIT_FAILED) else if (r == WAIT_FAILED)
{ {
EHS_LOG_INT("Error", 1, "Failed to wait for thread with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to wait for thread with error #" + Str_8::FromNum(GetLastError()) + ".");
return false; return false;
} }
@ -96,7 +96,7 @@ namespace ehs
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
int code = pthread_join((pthread_t)hdl, nullptr); int code = pthread_join((pthread_t)hdl, nullptr);
if (code != 0) if (code != 0)
EHS_LOG_INT("Error", 1, "Failed to wait for thread with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 1, "Failed to wait for thread with error #" + Str_8::FromNum(code) + ".");
hdl = EHS_INVALID_THREAD; hdl = EHS_INVALID_THREAD;
#endif #endif
@ -112,7 +112,7 @@ namespace ehs
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
if (!CloseHandle(hdl)) if (!CloseHandle(hdl))
{ {
EHS_LOG_INT("Error", 0, "Failed to detach thread with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to detach thread with error #" + Str_8::FromNum(GetLastError()) + ".");
return; return;
} }
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
@ -155,7 +155,7 @@ namespace ehs
taskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&taskIndex); taskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&taskIndex);
if (!taskHdl) if (!taskHdl)
EHS_LOG_INT("Error", 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void Thread::SetTaskType_16(const Str_16& task) void Thread::SetTaskType_16(const Str_16& task)
@ -165,7 +165,7 @@ namespace ehs
taskHdl = AvSetMmThreadCharacteristicsW(task, (LPDWORD)&taskIndex); taskHdl = AvSetMmThreadCharacteristicsW(task, (LPDWORD)&taskIndex);
if (!taskHdl) if (!taskHdl)
EHS_LOG_INT("Error", 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void Thread::SetTaskType_8(const Str_8& task) void Thread::SetTaskType_8(const Str_8& task)
@ -175,7 +175,7 @@ namespace ehs
taskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&taskIndex); taskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&taskIndex);
if (!taskHdl) if (!taskHdl)
EHS_LOG_INT("Error", 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void Thread::RevertTaskType() void Thread::RevertTaskType()
@ -184,7 +184,7 @@ namespace ehs
return; return;
if (!AvRevertMmThreadCharacteristics(taskHdl)) if (!AvRevertMmThreadCharacteristics(taskHdl))
EHS_LOG_INT("Error", 0, "Failed to revert the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to revert the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
taskIndex = 0; taskIndex = 0;
} }
@ -212,7 +212,7 @@ namespace ehs
mainTaskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&mainTaskIndex); mainTaskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&mainTaskIndex);
if (!mainTaskHdl) if (!mainTaskHdl)
EHS_LOG_INT("Error", 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void Thread::SetMainTaskType_16(const Str_16& task) void Thread::SetMainTaskType_16(const Str_16& task)
@ -222,7 +222,7 @@ namespace ehs
mainTaskHdl = AvSetMmThreadCharacteristicsW(task, (LPDWORD)&mainTaskIndex); mainTaskHdl = AvSetMmThreadCharacteristicsW(task, (LPDWORD)&mainTaskIndex);
if (!mainTaskHdl) if (!mainTaskHdl)
EHS_LOG_INT("Error", 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void Thread::SetMainTaskType_8(const Str_8& task) void Thread::SetMainTaskType_8(const Str_8& task)
@ -232,7 +232,7 @@ namespace ehs
mainTaskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&mainTaskIndex); mainTaskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&mainTaskIndex);
if (!mainTaskHdl) if (!mainTaskHdl)
EHS_LOG_INT("Error", 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
} }
void Thread::RevertMainTaskType() void Thread::RevertMainTaskType()
@ -241,7 +241,7 @@ namespace ehs
return; return;
if (!AvRevertMmThreadCharacteristics(mainTaskHdl)) if (!AvRevertMmThreadCharacteristics(mainTaskHdl))
EHS_LOG_INT("Error", 0, "Failed to revert the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to revert the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
mainTaskIndex = 0; mainTaskIndex = 0;
} }

View File

@ -10,7 +10,7 @@ namespace ehs
void User::GetId(UInt_32* const real, UInt_32* const effective, UInt_32* const saved) void User::GetId(UInt_32* const real, UInt_32* const effective, UInt_32* const saved)
{ {
if (getresuid(real, effective, saved) == -1) if (getresuid(real, effective, saved) == -1)
EHS_LOG_INT("Error", 0, strerror(errno)); EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
} }
Str_8 User::GetName() Str_8 User::GetName()
@ -18,7 +18,7 @@ namespace ehs
SInt_64 max = sysconf(_SC_LOGIN_NAME_MAX); SInt_64 max = sysconf(_SC_LOGIN_NAME_MAX);
if (max == -1) if (max == -1)
{ {
EHS_LOG_INT("Error", 0, strerror(errno)); EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
return {}; return {};
} }
@ -27,7 +27,7 @@ namespace ehs
if (getlogin_r(name, max) == -1) if (getlogin_r(name, max) == -1)
{ {
delete[] name; delete[] name;
EHS_LOG_INT("Error", 1, strerror(errno)); EHS_LOG_INT(LogType::ERR, 1, strerror(errno));
return {}; return {};
} }