(SOC) Storage Only Commit - Sat 22 Jun 14:54:31 CST 2024
This commit is contained in:
@@ -63,46 +63,18 @@ typedef struct _Status {
|
||||
struct _Status *prev;
|
||||
} Status;
|
||||
|
||||
# define DEFSTATUS(i, v, d, c, p)\
|
||||
static const Status i = {\
|
||||
.identity = nameof(i),\
|
||||
.value = v,\
|
||||
.description = d,\
|
||||
.characteristic = c,\
|
||||
.loc = __GLOBAL__,\
|
||||
.prev = (Status *)p\
|
||||
# define DEFSTATUS(i, v, d, c, p) \
|
||||
static const Status i = { \
|
||||
.identity = nameof(i), \
|
||||
.value = v, \
|
||||
.description = d, \
|
||||
.characteristic = c, \
|
||||
.loc = __GLOBAL__, \
|
||||
.prev = (Status *)p \
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
{value "description" characteristic prev}
|
||||
|
||||
"%d \"%s\" %d %p"
|
||||
|
||||
*/
|
||||
|
||||
/* line, func, file */
|
||||
// # define LOCATION_LITERALISE_FORMAT "at line %d, in %s, %s"
|
||||
|
||||
/* file, line, func */
|
||||
# define LOCATION_LITERALISE_FORMAT "at %s:%d, in function `%s\'"
|
||||
# define LOCATION_LITERALISE_FORMAT_LENGTH 20
|
||||
|
||||
/* value, description, characteristic, prev */
|
||||
// # define STATUS_LITERALISE_FORMAT "%d \"%s\" %d %p"
|
||||
/* identity, prev->identity, value, characteristic, description, <loc> */
|
||||
// # define STATUS_LITERALISE_FORMAT "%s (prev: %s): $=%d @=%d\n\t\"%s\"\n\t%s"
|
||||
|
||||
// MaximumLiteralisationLengthExceeded (prev: MaximumLengthExceeded): $=1 @=1
|
||||
|
||||
/*
|
||||
MaximumLengthExceeded: "Buffer was too long."
|
||||
predecessor=<ArrayLengthError> value=(1) characteristic=[1]
|
||||
at line 40, in Main, /home/william/Documents/Projects/Compound/test.c
|
||||
|
||||
*/
|
||||
|
||||
// identity, description, prev->identity, value, characteristic, <loc>
|
||||
# define STATUS_LITERALISE_FORMAT \
|
||||
"%s: \"%s\"\n\tpredecessor=<%s> value=(%d) characteristic=[%d]\n\t%s\n"
|
||||
|
||||
@@ -116,7 +88,7 @@ typedef enum {
|
||||
REPORT_SENDING_PRIORITY_MINOR,
|
||||
REPORT_SENDING_PRIORITY_DEBUG,
|
||||
REPORT_SENDING_PRIORITY_NONE, // Lowest level, greatest value.
|
||||
} ReportSendingPriority;
|
||||
} ReportLevel;
|
||||
|
||||
typedef enum {
|
||||
REPORT_SENDING_TASK_STATUS_FINISHED = 0,
|
||||
@@ -124,21 +96,20 @@ typedef enum {
|
||||
REPORT_SENDING_TASK_STATUS_PROCEEDING,
|
||||
REPORT_SENDING_TASK_STATUS_PAUSED,
|
||||
REPORT_SENDING_TASK_STATUS_NOTFOUND
|
||||
} ReportSendingTaskStatus;
|
||||
} ReportStatus;
|
||||
|
||||
/* "Report" recollects essential informations, included but not limited to
|
||||
Status and others for making an report for debugging and such. */
|
||||
typedef struct {
|
||||
Status status;
|
||||
Status content;
|
||||
char *initiator;
|
||||
time_t time;
|
||||
ReportSendingPriority priority;
|
||||
ReportSendingTaskStatus taskprint_status;
|
||||
FILE *dest; // The destination where the report is sending to.
|
||||
ReportLevel level;
|
||||
ReportStatus status;
|
||||
FILE *dst; // The destination where the report is sending to.
|
||||
} Report;
|
||||
|
||||
/*
|
||||
|
||||
DATETIME [PRIORITY] STATUSNAME (ORIGINATOR): STATUS.DESCRIPTION
|
||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||
@@ -146,7 +117,7 @@ DATETIME [PRIORITY] STATUSNAME (ORIGINATOR): STATUS.DESCRIPTION
|
||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||
|
||||
|
||||
Fri 10 May 03:02:37 CST 2024 [EXCEPTIONAL] InvalidParameter (Nullity): Given buffer was unavailable.
|
||||
Fri 10 May 03:02:37 CST 2024 [URGENT] InvalidParameter (Nullity): Given buffer was unavailable.
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:104, Report_Literalise
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:114, ReportSender_Send
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:69, _throw
|
||||
@@ -155,33 +126,29 @@ Fri 10 May 03:02:37 CST 2024 [EXCEPTIONAL] InvalidParameter (Nullity): Given buf
|
||||
|
||||
*/
|
||||
|
||||
# define REPORT_LITERALISE_HEADER_FORMAT "%s [%s] %s (%s): %s"
|
||||
# define REPORT_LITERALISE_CHAINS_FORMAT " at %s:%d, %s"
|
||||
# define REPORT_LITERALISE_CHAINS_EXCLAIM_FORMAT "!!!!at %s:%d, %s"
|
||||
// DATETIME [LEVEL] STATUS.IDENTITY (INITIATOR): STATUS.DESCRIPTION
|
||||
# define REPORT_LITERALISE_FORMAT_HEADER "%s [%d] %s (%s): %s\n\tat %s:%d, %s\n%s"
|
||||
|
||||
// STATUS.IDENTITY, STATUS.PREV.IDENTITY, STATUS.VALUE, STATUS.CHARACTERISTIC,
|
||||
// FILE, LINE, FUNC
|
||||
# define REPORT_LITERALISE_FORMAT_DETAIL "\t%s(%s, %d, %d) at %s:%d, %s\n"
|
||||
|
||||
typedef enum {
|
||||
REPORT_SENDER_RESULT_FINISHED,
|
||||
REPORT_SENDER_RESULT_PROGRESSING,
|
||||
REPORT_SENDER_RESULT_PENDING
|
||||
} ReportSenderResult;
|
||||
REPORT_RESULT_SUCCEEDED,
|
||||
REPORT_RESULT_FAILED,
|
||||
REPORT_RESULT_PROGRESSING,
|
||||
REPORT_RESULT_PENDING,
|
||||
} ReportResult;
|
||||
|
||||
typedef struct {
|
||||
thrd_t thread;
|
||||
Report *report; // The report for sending.
|
||||
time_t elapsed; // The individual elapsed time for each report. (Array)
|
||||
ReportSenderResult result;
|
||||
bool successful;
|
||||
Report report;
|
||||
time_t elapsed;
|
||||
ReportResult result;
|
||||
} ReportSender;
|
||||
|
||||
typedef int (*ReportSendingTask)(Report *rep);
|
||||
typedef int ReportSendingTaskID;
|
||||
|
||||
typedef struct {
|
||||
ReportSendingTask *tasks; // Array Ref
|
||||
int sendercount;
|
||||
int finishedcount;
|
||||
int *results; // Array
|
||||
} ReportSendingManager;
|
||||
typedef int (*ReportTask)(Report *);
|
||||
typedef int ReportTaskID;
|
||||
|
||||
// typedef thrd_start_t ArgueStart;
|
||||
|
||||
@@ -218,6 +185,7 @@ typedef struct {
|
||||
Status Location_Literalise(Location *inst, char *buff);
|
||||
bool Location_Equals(Location lc1, Location lc2);
|
||||
Status Status_Literalise(Status *inst, char *buff);
|
||||
Status Status_LiteraliseForReport(Status *inst, char *buff);
|
||||
bool Status_Equal(Status *stat1, Status *stat2);
|
||||
void StatusUtils_Dump(Status *inst, Status *store, int idx);
|
||||
bool StatusUtils_HasPrev(Status inst);
|
||||
@@ -232,16 +200,12 @@ Status Report_Literalise(Report *inst, char *buff);
|
||||
void Report_Delete(Report *inst);
|
||||
bool Report_Equals(Report repo1, Report repo2);
|
||||
|
||||
// Status ReportSender_Create(ReportSender *inst, Report *report, thrd_start_t *handler);
|
||||
Status ReportSender_Create(ReportSender *inst, Report *report);
|
||||
Status ReportSender_Send(ReportSender *inst, ReportSendingTask task);
|
||||
// ReportSendingTaskStatus
|
||||
// ReportSender_GetStatus(ReportSender *inst);
|
||||
Status ReportSender_Send(ReportSender *inst, ReportTask task);
|
||||
|
||||
ReportSendingTaskID
|
||||
ReportSenderManager_AppendTask(ReportSendingManager *inst,
|
||||
ReportSendingTask task);
|
||||
Status ReportSenderManager_RemoveTask(ReportSendingManager *inst,
|
||||
ReportSendingTaskID taskid);
|
||||
// ReportTaskStatus
|
||||
// ReportSender_GetStatus(ReportSender *inst);
|
||||
|
||||
// Status
|
||||
// arguestarter_create(ArgueStartParam *inst, void *external_param);
|
||||
@@ -315,6 +279,10 @@ DEFSTATUS(RuntimeError, 1,
|
||||
"A runtime error occurred.",
|
||||
STATUS_ERROR, &ErrorStatus);
|
||||
|
||||
DEFSTATUS(InstanceCreatingFailure, 1,
|
||||
"Cannot create the instance.",
|
||||
STATUS_ERROR, &RuntimeError);
|
||||
|
||||
DEFSTATUS(ArrayLengthError, 1,
|
||||
"Given array length does not meet the requirement.",
|
||||
STATUS_ERROR, &ErrorStatus);
|
||||
@@ -403,72 +371,78 @@ DEFSTATUS(InvalidLiteralisingBuffer, 1,
|
||||
"Given buffer does not have a good integrity on its length.",
|
||||
STATUS_ERROR, &InvalidObject);
|
||||
|
||||
DEFSTATUS(NoBytesWereRead, 1,
|
||||
"Called function had returned ZERO indicating no bytes were read.",
|
||||
STATUS_ERROR, &ReadWriteError);
|
||||
|
||||
DEFSTATUS(NoBytesWereWritten, 1,
|
||||
"Called function had returned ZERO indicating no bytes were written.",
|
||||
STATUS_ERROR, &ReadWriteError);
|
||||
|
||||
// DEFSTATUS(ProgrammeConstructionError, 1,
|
||||
// "Failed on constructing programme at the entrance.",
|
||||
// STATUS_ERROR, &RuntimeError);
|
||||
|
||||
// ========================================================
|
||||
|
||||
static inline Status PrintStatus(Status s)
|
||||
{
|
||||
/* Literalise. */
|
||||
char buff[LITERALISATION_LENGTH_MAXIMUM];
|
||||
(void)Status_Literalise(&s, buff);
|
||||
|
||||
/* Handle returning value. */
|
||||
/* No bytes were written to buffer. */
|
||||
unsure(Status_Literalise(&s, buff), !_.value, {
|
||||
return apply(NoBytesWereWritten);
|
||||
})
|
||||
|
||||
/* Output. */
|
||||
where(fprintf(stderr, "%s\n", buff), {
|
||||
/* Pass on returning value. */
|
||||
return apply(value(TraditionalFunctionReturn, _));
|
||||
})
|
||||
}
|
||||
|
||||
static inline void PrintStatusDump(Status s)
|
||||
{
|
||||
Status stat = s;
|
||||
const int dump_len = StatusUtils_Depth(&stat);
|
||||
/* Create dump. */
|
||||
Status store = s;
|
||||
const int dump_len = StatusUtils_Depth(&store);
|
||||
Status dump[dump_len];
|
||||
StatusUtils_Dump(&stat, dump, 0);
|
||||
/* TODO(william): Replace following line with coloured-term-output function. */
|
||||
(void)printf("\e[1m======== STATUS STACK DUMP: %s ========\e[0m\n",
|
||||
stat.identity);
|
||||
StatusUtils_Dump(&store, dump, dump_len);
|
||||
|
||||
/* Output by iterating. */
|
||||
for (register int i = 0; i < dump_len; i++) {
|
||||
/* TODO(william): Replace following line with coloured-term-output function. */
|
||||
(void)printf("\e[1m[%d/%d]\e[0m\n", (dump_len - i), dump_len);
|
||||
seek(PrintStatus(dump[i]), {
|
||||
solve(!_.value, {
|
||||
(void)fprintf(stderr, "\e[38;5;9m!!!!!!!! PRINT DUMP FAILED !!!!!!!!"
|
||||
"\e[0m\n");
|
||||
(void)PrintStatus(_);
|
||||
})
|
||||
})
|
||||
seek(PrintStatus(dump[i]), { // Get returning status.
|
||||
|
||||
/* Handle TraditionalFunctionReturn. */
|
||||
nest(_, __, unsure(__, !__.value, { // No bytes were written to buffer.
|
||||
(void)fprintf(stderr, "Unable to literalise.\n");
|
||||
return;
|
||||
}));
|
||||
|
||||
// Handle abnormal status.
|
||||
nest(_, __, notok(__, {
|
||||
/* Output the description as explanation. */
|
||||
(void)fprintf(stderr, "%s\n", __.description);
|
||||
return;
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================
|
||||
|
||||
/* Throw the report created with $e if $e is abnormal, commented with $c. */
|
||||
# define ensure(e, c) { \
|
||||
Status stat = e; \
|
||||
solve(!(StatusUtils_IsOkay(stat)), { \
|
||||
Report rep = stamp(error(stat, c), (char *)__func__); \
|
||||
(void)throw(rep); \
|
||||
return ReportThrown; \
|
||||
}) \
|
||||
}
|
||||
|
||||
/* Throw the report created with $s if $e is abnormal, commented with $c. */
|
||||
# define match(s, e, c) { \
|
||||
Status stat = s; \
|
||||
solve(!(StatusUtils_IsOkay(e)), { \
|
||||
Report rep = stamp(error(stat, c), (char *)__func__); \
|
||||
(void)throw(rep); \
|
||||
return ReportThrown; \
|
||||
}) \
|
||||
}
|
||||
|
||||
/* Add location parameter requirement in order to give proper information
|
||||
* before throwing the report out. */
|
||||
# define throw(report) THROW(report, __HERE__)
|
||||
// # define throw(report) THROW(report, __HERE__)
|
||||
|
||||
/* Useless in C, only for human to see.
|
||||
Probably rewrite this in Classify. */
|
||||
# define throws(e)
|
||||
|
||||
ReportSendingTaskID THROW(Report report, Location loc);
|
||||
Report CATCH(ReportSendingTaskID taskid);
|
||||
// ReportTaskID THROW(Report report, Location loc);
|
||||
// Report CATCH(ReportTaskID taskid, Status (*handler)());
|
||||
int HANDLER(void *report);
|
||||
|
||||
#endif /* COMPOUND_STATUS_H */
|
||||
|
@@ -2,30 +2,18 @@
|
||||
|
||||
Status Location_Literalise(Location *inst, char *buff)
|
||||
{
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
fails(buff, apply(UnavailableBuffer));
|
||||
nonull(inst, apply(UnavailableInstance));
|
||||
nonull(buff, apply(UnavailableBuffer));
|
||||
|
||||
/* Literalise line. */
|
||||
char line_buff[LITERALISATION_LENGTH_MAXIMUM];
|
||||
Utils_LiteraliseInteger(inst->line, line_buff);
|
||||
|
||||
/* Concatenate every buff. */
|
||||
const long total_len = strlen(strnil(inst->file)) + strlen(strnil(line_buff))
|
||||
+ strlen(strnil(inst->func))
|
||||
+ LOCATION_LITERALISE_FORMAT_LENGTH;
|
||||
|
||||
state(total_len > LITERALISATION_LENGTH_MAXIMUM,
|
||||
apply(MaximumLiteralisationLengthExceeded));
|
||||
|
||||
/* Copy and assign. */
|
||||
// return value(UnknownStatus,
|
||||
// !sprintf(buff, LOCATION_LITERALISE_FORMAT,
|
||||
// inst->file, inst->line, inst->func));
|
||||
const int written =
|
||||
sprintf(buff, LOCATION_LITERALISE_FORMAT,inst->file,inst->line,inst->func);
|
||||
|
||||
// written in "value" is absolutely ZERO.
|
||||
state(!written, apply(value(UnknownStatus, written)));
|
||||
where(
|
||||
!snprintf(buff, LITERALISATION_LENGTH_MAXIMUM,
|
||||
LOCATION_LITERALISE_FORMAT,inst->file,inst->line,inst->func),
|
||||
return apply(value(TraditionalFunctionReturn, _));
|
||||
);
|
||||
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
@@ -56,8 +44,8 @@ bool Status_Equal(Status *stat1, Status *stat2)
|
||||
Status Status_Literalise(Status *inst, char *buff)
|
||||
{
|
||||
/* Skip unavailable instance and invalid parameter. */
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
fails(buff, apply(UnavailableBuffer));
|
||||
nonull(inst, apply(UnavailableInstance));
|
||||
nonull(buff, apply(UnavailableBuffer));
|
||||
|
||||
/* Literalise loc. */
|
||||
char loc_buff[LITERALISATION_LENGTH_MAXIMUM];
|
||||
@@ -80,13 +68,28 @@ Status Status_Literalise(Status *inst, char *buff)
|
||||
}
|
||||
|
||||
/* Concatenate every buffer. */
|
||||
where(sprintf(buff, fmt, inst->identity, inst->description,
|
||||
(!inst->prev
|
||||
? "(null)"
|
||||
: (inst->prev->identity)),
|
||||
inst->value, inst->characteristic, loc_buff), {
|
||||
where(
|
||||
snprintf(buff, LITERALISATION_LENGTH_MAXIMUM, fmt, inst->identity,
|
||||
inst->description,
|
||||
(!inst->prev ? "(null)" : (inst->prev->identity)),
|
||||
inst->value, inst->characteristic, loc_buff), {
|
||||
return apply(value(TraditionalFunctionReturn, _));
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
Status Status_LiteraliseForReport(Status *inst, char *buff)
|
||||
{
|
||||
/* Skip unavailable instance and invalid parameter. */
|
||||
nonull(inst, apply(UnavailableInstance));
|
||||
nonull(buff, apply(UnavailableBuffer));
|
||||
|
||||
where(
|
||||
snprintf(buff, LITERALISATION_LENGTH_MAXIMUM, REPORT_LITERALISE_FORMAT_DETAIL,
|
||||
strnil(inst->identity), strnil(inst->prev->identity),
|
||||
inst->value, inst->characteristic, inst->loc.file, inst->loc.line,
|
||||
inst->loc.func), {
|
||||
return apply(value(TraditionalFunctionReturn, _));
|
||||
});
|
||||
}
|
||||
|
||||
bool StatusUtils_HasPrev(Status stat)
|
||||
@@ -111,7 +114,7 @@ void StatusUtils_Dump(Status *inst, Status *store, int idx)
|
||||
|
||||
store[idx] = *inst;
|
||||
|
||||
StatusUtils_Dump(inst->prev, store, ++idx);
|
||||
StatusUtils_Dump(inst->prev, store, --idx);
|
||||
}
|
||||
|
||||
int StatusUtils_Depth(Status *stat)
|
||||
@@ -123,9 +126,11 @@ int StatusUtils_Depth(Status *stat)
|
||||
register int cnt;
|
||||
for (cnt = 0; (!StatusUtils_IsRecursive(*p)
|
||||
&& StatusUtils_HasPrev(*p)); cnt++) {
|
||||
(void)printf("Depth: %d\n", cnt);
|
||||
p = p->prev;
|
||||
}
|
||||
|
||||
(void)printf("Depth returns: %d\n", cnt);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -133,35 +138,35 @@ Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
||||
int priority)
|
||||
{
|
||||
/* Skip unavailable parameters. */
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
fails(stat, apply(error(InvalidParameter, "Given stat was null.")));
|
||||
fails(initiator, apply(error(InvalidParameter, "Given initiator was null.")));
|
||||
nonull(inst, apply(UnavailableInstance));
|
||||
nonull(stat, apply(error(InvalidParameter, "Given stat was null.")));
|
||||
nonull(initiator, apply(error(InvalidParameter, "Given initiator was null.")));
|
||||
state(priority < 0, apply(error(InvalidParameter, "Given priority was negative.")));
|
||||
|
||||
/* Copy and assign. */
|
||||
inst->status = *stat;
|
||||
inst->content = *stat;
|
||||
inst->initiator = calloc(strlen(initiator), sizeof(char));
|
||||
(void)strcpy(inst->initiator, initiator);
|
||||
inst->time = time(NULL);
|
||||
inst->priority = priority;
|
||||
inst->taskprint_status = REPORT_SENDING_TASK_STATUS_PENDING;
|
||||
inst->dest = (dest == NULL ? stdout : dest);
|
||||
inst->level = priority;
|
||||
inst->status = REPORT_SENDING_TASK_STATUS_PENDING;
|
||||
inst->dst = (dest == NULL ? stdout : dest);
|
||||
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
Status Report_CopyOf(Report *inst, Report *other)
|
||||
{
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
fails(other, apply(error(InvalidParameter, "Given report is unavailable.")));
|
||||
nonull(inst, apply(UnavailableInstance));
|
||||
nonull(other, apply(error(InvalidParameter, "Given report is unavailable.")));
|
||||
|
||||
// Status status;
|
||||
// char *initiator;
|
||||
// time_t time;
|
||||
// ReportSendingPriority priority;
|
||||
// ReportSendingTaskStatus taskprint_status;
|
||||
// ReportLevel priority;
|
||||
// ReportTaskStatus taskprint_status;
|
||||
// FILE *dest;
|
||||
inst->status = other->status;
|
||||
inst->content = other->content;
|
||||
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
@@ -172,94 +177,98 @@ void Report_Delete(Report *inst)
|
||||
|
||||
free(inst->initiator);
|
||||
inst->initiator = NULL;
|
||||
inst->dest = NULL;
|
||||
inst->priority = 0;
|
||||
inst->status = (Status){};
|
||||
inst->taskprint_status = REPORT_SENDING_TASK_STATUS_NOTFOUND;
|
||||
inst->dst = NULL;
|
||||
inst->level = 0;
|
||||
inst->content = (Status){};
|
||||
inst->status = REPORT_SENDING_TASK_STATUS_NOTFOUND;
|
||||
inst->time = 0;
|
||||
inst = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Status status;
|
||||
char *initiator;
|
||||
time_t time;
|
||||
ReportLevel priority;
|
||||
ReportTaskStatus taskprint_status;
|
||||
FILE *dest;
|
||||
*/
|
||||
Status Report_Literalise(Report *inst, char *buff)
|
||||
{
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
fails(buff, apply(UnavailableBuffer));
|
||||
// state(strlen(buff) != LITERALISATION_LENGTH_MAXIMUM,
|
||||
// InvalidLiteralisingBuffer);
|
||||
|
||||
nonull(inst, apply(UnavailableInstance));
|
||||
nonull(buff, apply(UnavailableBuffer));
|
||||
|
||||
/* Report literalisation. */
|
||||
int idx = 0;
|
||||
char report_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
|
||||
|
||||
/** Status literalisation. **/
|
||||
char status_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
(void)Status_Literalise(&inst->status, status_literalising);
|
||||
idx += strlen(status_literalising);
|
||||
/** fin **/
|
||||
|
||||
/** Initiator literalisation. **/
|
||||
idx += strlen(inst->initiator);
|
||||
/** fin **/
|
||||
|
||||
/** Time literalisation. **/
|
||||
char time_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger(inst->time, time_literalising);
|
||||
/** fin **/
|
||||
|
||||
/** Priority literalisation. **/
|
||||
char priority_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger(inst->priority, priority_literalising);
|
||||
/** fin **/
|
||||
|
||||
/** Taskprint_status literalisation. **/
|
||||
char taskprint_status_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger(inst->taskprint_status, taskprint_status_literalising);
|
||||
/** fin **/
|
||||
|
||||
/** Dest literalisation. **/
|
||||
char dest_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger((long long int)inst->dest, dest_literalising);
|
||||
/** fin **/
|
||||
|
||||
if (idx >= LITERALISATION_LENGTH_MAXIMUM) {
|
||||
buff = NULL;
|
||||
return MaximumLiteralisationLengthExceeded;
|
||||
}
|
||||
|
||||
strcpy(report_literalising, status_literalising);
|
||||
strcpy(report_literalising, time_literalising);
|
||||
strcpy(report_literalising, priority_literalising);
|
||||
strcpy(report_literalising, taskprint_status_literalising);
|
||||
strcpy(report_literalising, dest_literalising);
|
||||
/* Fault detection on status literalisation. */
|
||||
// settle(Status_LiteraliseForReport(&inst->status, status_literalising),
|
||||
// _.characteristic == STATUS_UNKNOWN, {
|
||||
// nest(_, __, {
|
||||
// /* Skip when ZERO byte were written. (failed to write) */
|
||||
// state(!__.value, apply(
|
||||
// error(value(TraditionalFunctionReturn, __.value),
|
||||
// "ZERO byte were written.")
|
||||
// ));
|
||||
// })
|
||||
// });
|
||||
|
||||
/* Traditional function returning handling. */
|
||||
settle(Status_LiteraliseForReport(&inst->content, status_literalising),
|
||||
!_.value, {
|
||||
return apply(annot(RuntimeError, "Failed to literalise status for report."));
|
||||
});
|
||||
|
||||
/* Write result to buffer. */
|
||||
/* Write the report "header". */
|
||||
/* Literalise current time and date. */
|
||||
char datetime[LITERALISATION_LENGTH_MAXIMUM];
|
||||
// settle(strftime(datetime, 64, "%c", localtime(&inst->time)), )
|
||||
|
||||
strcpy(buff, report_literalising);
|
||||
/* fin */
|
||||
// DATETIME [LEVEL] STATUS.IDENTITY (INITIATOR): STATUS.DESCRIPTION
|
||||
state(!snprintf(report_literalising, LITERALISATION_LENGTH_MAXIMUM,
|
||||
REPORT_LITERALISE_FORMAT_HEADER, datetime, inst->level,
|
||||
inst->content.identity, inst->initiator, inst->content.description),
|
||||
apply(annot(NoBytesWereWritten, "Failed to literalise date and time."))
|
||||
);
|
||||
|
||||
/* Write the report "detail". */
|
||||
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
/*
|
||||
thrd_t thread;
|
||||
Report report;
|
||||
time_t elapsed;
|
||||
ReportResult result;
|
||||
*/
|
||||
Status ReportSender_Create(ReportSender *inst, Report *report)
|
||||
{
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
fails(report, error(UnavailableParameter, "Given report was unavailable."));
|
||||
nonull(inst, apply(UnavailableInstance));
|
||||
nonull(report, error(UnavailableParameter, "Given report was unavailable."));
|
||||
|
||||
thrd_create(&inst->thread, &HANDLER, report);
|
||||
notok(Report_CopyOf(inst->report, report),
|
||||
return error(ErrorStatus, "Cannot copy to create new instance of report.");
|
||||
) // *inst->report = *report;
|
||||
notok(Report_CopyOf(&inst->report, report),
|
||||
return apply(annot(InstanceCreatingFailure,
|
||||
"Cannot copy to create new instance of report."));
|
||||
);
|
||||
inst->report = *report;
|
||||
inst->elapsed = 0;
|
||||
inst->result = REPORT_SENDER_RESULT_PENDING;
|
||||
inst->successful = false;
|
||||
inst->result = REPORT_RESULT_PENDING;
|
||||
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
Status ReportSender_Send(ReportSender *inst, ReportSendingTask task)
|
||||
Status ReportSender_Send(ReportSender *inst, ReportTask task)
|
||||
{
|
||||
// /* Skip when inst or task is unavailable. */
|
||||
// fails(inst,
|
||||
// nonull(inst,
|
||||
// error(UnavailableInstance, "Report sender was given unavailable."));
|
||||
// fails(task, InvalidReportTask);
|
||||
// nonull(task, InvalidReportTask);
|
||||
|
||||
// /* Assign for dest. */
|
||||
// const FILE *dest = (inst->report->dest == NULL ? stdout : inst->report->dest);
|
||||
@@ -284,7 +293,7 @@ Status ReportSender_Send(ReportSender *inst, ReportSendingTask task)
|
||||
// || (inst1->external_param == inst2->external_param);
|
||||
// }
|
||||
|
||||
ReportSendingTaskID THROW(Report report, Location loc)
|
||||
ReportTaskID THROW(Report report, Location loc)
|
||||
{
|
||||
// // /* Create new a instance of ReportSender. */
|
||||
// // ReportSender sender;
|
||||
|
Reference in New Issue
Block a user