(SOC) Storage Only Commit

(ADD) Name, NameScope, Catlog, Object, String, Attribute, Char, Registry, Utils, Type, <Platform Support>, <Global Constants>, README

(MOD) Array, Var, Status, MemMan, <Common>
This commit is contained in:
William
2024-05-16 00:04:42 +08:00
parent 989e512f8f
commit 5f7a6c6f93
32 changed files with 1694 additions and 195 deletions

105
catlog.c Executable file
View File

@@ -0,0 +1,105 @@
#include <Compound/catlog.h>
#include <Compound/status.h>
Status CatlogMsg_Create(CatlogMsg *inst, CatlogLevel level,
char const *originator, char const *msg)
{
/* Skip unavailable instances and parameters. */
fails(inst, UnavailableInstance);
state((originator == NULL || msg == NULL), InvalidParameter);
inst->time = time(NULL);
inst->level = level;
*inst->originator = *originator;
*inst->msg = *msg;
return NormalStatus;
}
Status CatlogMsg_CopyOf(CatlogMsg *inst, CatlogMsg *other)
{
/* Skip unavailable instances and parameters. */
fails(inst, UnavailableInstance);
fails(other, InvalidParameter);
*inst = *other;
return NormalStatus;
}
bool CatlogMsg_Equal(CatlogMsg *inst, CatlogMsg *other)
{
/* Skip unavailable instances and parameters. */
state((inst == NULL || other == NULL), false);
return (
inst->time == other->time &&
inst->level == other->level &&
(!strcmp(inst->originator, other->originator)) &&
(!strcmp(inst->msg, other->msg))
);
}
Status CatlogSender_Create(CatlogSender *inst, CatlogMsg *msg, FILE *dst)
{
/* Skip unavailable instances and parameters. */
fails(inst, UnavailableInstance);
fails(msg, InvalidParameter);
/* Copy and assign, with detections. */
inst->msg = *msg;
inst->dst = (dst == NULL ? (stdout) : dst);
inst->successful = false;
inst->elapsed = (struct timespec){.tv_sec = 0, .tv_nsec = 0};
return NormalStatus;
}
Status CatlogSender_CopyOf(CatlogSender *inst, CatlogSender *other)
{
/* Skip unavailable instances and parameters. */
fails(inst, UnavailableInstance);
fails(other, InvalidParameter);
/* Copy and assign */
inst->msg = other->msg;
inst->dst = other->dst;
inst->successful = other->successful;
inst->elapsed = other->elapsed;
return NormalStatus;
}
bool CatlogSender_Equal(CatlogSender *inst, CatlogSender *other)
{
/* Skip unavailable instances and parameters. */
state((inst == NULL || other == NULL), false);
return (
CatlogMsg_Equal(&inst->msg, &other->msg) &&
inst->dst == other->dst &&
inst->successful == other->successful &&
((inst->elapsed.tv_sec == other->elapsed.tv_sec) &&
(inst->elapsed.tv_nsec == other->elapsed.tv_nsec))
);
}
Status CatlogSender_Send(CatlogSender *inst, int *store, bool append)
throws(ReadWriteError)
{
/* Skip unavailable instances and parameters. */
fails(inst, UnavailableInstance);
fails(store, InvalidParameter);
/* Open file. */
ensure(CatlogUtils_OpenFile(inst->dst, "r"), "Unable to open file.");
ensure(CatlogMsg_Create(&(CatlogMsg){}, 0, "", ""), "Failed!");
/* Read file. */
/* Creating buffer, */
// TODO(william): Finish this function.
}
Status CatlogUtils_CalcElapsed(struct timespec t1, struct timespec t2);
Status CatlogUtils_OpenFile(FILE *store, const char const *__restrict mode);