(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:
105
catlog.c
Executable file
105
catlog.c
Executable 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);
|
Reference in New Issue
Block a user