(ADD) Name, NameScope, Catlog, Object, String, Attribute, Char, Registry, Utils, Type, <Platform Support>, <Global Constants>, README (MOD) Array, Var, Status, MemMan, <Common>
106 lines
2.9 KiB
C
Executable File
106 lines
2.9 KiB
C
Executable File
#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);
|