Compare commits
2 Commits
75a2b14c07
...
d19256621b
Author | SHA1 | Date | |
---|---|---|---|
d19256621b | |||
8696b89c2e |
@@ -78,78 +78,6 @@ typedef struct _Status {
|
|||||||
# define STATUS_LITERALISE_FORMAT \
|
# define STATUS_LITERALISE_FORMAT \
|
||||||
"%s: \"%s\"\n\tpredecessor=<%s> value=(%d) characteristic=(%d)\n\t%s\n"
|
"%s: \"%s\"\n\tpredecessor=<%s> value=(%d) characteristic=(%d)\n\t%s\n"
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
REPORT_SENDING_PRIORITY_ALL = 0, // Highest level; least value.
|
|
||||||
REPORT_SENDING_PRIORITY_FATAL,
|
|
||||||
REPORT_SENDING_PRIORITY_EXCEPTIONAL,
|
|
||||||
REPORT_SENDING_PRIORITY_CRITICAL,
|
|
||||||
REPORT_SENDING_PRIORITY_MAJOR,
|
|
||||||
REPORT_SENDING_PRIORITY_NORMAL,
|
|
||||||
REPORT_SENDING_PRIORITY_MINOR,
|
|
||||||
REPORT_SENDING_PRIORITY_DEBUG,
|
|
||||||
REPORT_SENDING_PRIORITY_NONE, // Lowest level, greatest value.
|
|
||||||
} ReportLevel;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
REPORT_SENDING_TASK_STATUS_FINISHED = 0,
|
|
||||||
REPORT_SENDING_TASK_STATUS_PENDING,
|
|
||||||
REPORT_SENDING_TASK_STATUS_PROCEEDING,
|
|
||||||
REPORT_SENDING_TASK_STATUS_PAUSED,
|
|
||||||
REPORT_SENDING_TASK_STATUS_NOTFOUND
|
|
||||||
} ReportStatus;
|
|
||||||
|
|
||||||
/* "Report" recollects essential informations, included but not limited to
|
|
||||||
Status and others for making an report for debugging and such. */
|
|
||||||
typedef struct {
|
|
||||||
Status content;
|
|
||||||
char *initiator;
|
|
||||||
time_t time;
|
|
||||||
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
|
|
||||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
|
||||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
!!!!at /external/Documents/Projects/Compound/Array/src/array.c:16, array_create
|
|
||||||
at /external/Documents/Projects/Compound/test.c:24, main
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// 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_RESULT_SUCCEEDED,
|
|
||||||
REPORT_RESULT_FAILED,
|
|
||||||
REPORT_RESULT_PROGRESSING,
|
|
||||||
REPORT_RESULT_PENDING,
|
|
||||||
} ReportResult;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
thrd_t thread;
|
|
||||||
Report report;
|
|
||||||
time_t elapsed;
|
|
||||||
ReportResult result;
|
|
||||||
} ReportSender;
|
|
||||||
|
|
||||||
typedef int (*ReportTask)(Report *);
|
|
||||||
typedef int ReportTaskID;
|
|
||||||
|
|
||||||
// typedef thrd_start_t ArgueStart;
|
// typedef thrd_start_t ArgueStart;
|
||||||
|
|
||||||
// typedef struct {
|
// typedef struct {
|
||||||
@@ -185,7 +113,6 @@ typedef int ReportTaskID;
|
|||||||
Status Location_Literalise(Location *inst, char *buff);
|
Status Location_Literalise(Location *inst, char *buff);
|
||||||
bool Location_Equals(Location lc1, Location lc2);
|
bool Location_Equals(Location lc1, Location lc2);
|
||||||
Status Status_Literalise(Status *inst, char *buff);
|
Status Status_Literalise(Status *inst, char *buff);
|
||||||
Status Status_LiteraliseForReport(Status *inst, char *buff);
|
|
||||||
bool Status_Equal(Status *stat1, Status *stat2);
|
bool Status_Equal(Status *stat1, Status *stat2);
|
||||||
// void StatusUtils_Dump(Status *inst, Status **store, int idx);
|
// void StatusUtils_Dump(Status *inst, Status **store, int idx);
|
||||||
void StatusUtils_Dump(Status *inst, Status *store);
|
void StatusUtils_Dump(Status *inst, Status *store);
|
||||||
@@ -194,20 +121,6 @@ bool StatusUtils_IsOkay(Status inst);
|
|||||||
bool StatusUtils_IsRecursive(Status inst);
|
bool StatusUtils_IsRecursive(Status inst);
|
||||||
int StatusUtils_Depth(Status *inst);
|
int StatusUtils_Depth(Status *inst);
|
||||||
|
|
||||||
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
|
||||||
int priority);
|
|
||||||
Status Report_CopyOf(Report *inst, Report *other);
|
|
||||||
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, ReportTask task);
|
|
||||||
|
|
||||||
// ReportTaskStatus
|
|
||||||
// ReportSender_GetStatus(ReportSender *inst);
|
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
// arguestarter_create(ArgueStartParam *inst, void *external_param);
|
// arguestarter_create(ArgueStartParam *inst, void *external_param);
|
||||||
// Status
|
// Status
|
||||||
@@ -446,18 +359,4 @@ static inline void PrintStatusDump(Status s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================================
|
|
||||||
|
|
||||||
/* Add location parameter requirement in order to give proper information
|
|
||||||
* before throwing the report out. */
|
|
||||||
// # define throw(report) THROW(report, __HERE__)
|
|
||||||
|
|
||||||
/* Useless in C, only for human to see.
|
|
||||||
Probably rewrite this in Classify. */
|
|
||||||
# define throws(e)
|
|
||||||
|
|
||||||
// ReportTaskID THROW(Report report, Location loc);
|
|
||||||
// Report CATCH(ReportTaskID taskid, Status (*handler)());
|
|
||||||
int HANDLER(void *report);
|
|
||||||
|
|
||||||
#endif /* COMPOUND_STATUS_H */
|
#endif /* COMPOUND_STATUS_H */
|
||||||
|
@@ -79,21 +79,6 @@ Status Status_Literalise(Status *inst, char *buff)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
bool StatusUtils_HasPrev(Status stat)
|
||||||
{
|
{
|
||||||
return (stat.prev != NULL);
|
return (stat.prev != NULL);
|
||||||
@@ -166,156 +151,6 @@ int StatusUtils_Depth(Status *stat)
|
|||||||
// return cnt;
|
// return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
|
||||||
int priority)
|
|
||||||
{
|
|
||||||
/* Skip unavailable parameters. */
|
|
||||||
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->content = *stat;
|
|
||||||
inst->initiator = calloc(strlen(initiator), sizeof(char));
|
|
||||||
(void)strcpy(inst->initiator, initiator);
|
|
||||||
inst->time = time(NULL);
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
nonull(inst, apply(UnavailableInstance));
|
|
||||||
nonull(other, apply(error(InvalidParameter, "Given report is unavailable.")));
|
|
||||||
|
|
||||||
// Status status;
|
|
||||||
// char *initiator;
|
|
||||||
// time_t time;
|
|
||||||
// ReportLevel priority;
|
|
||||||
// ReportTaskStatus taskprint_status;
|
|
||||||
// FILE *dest;
|
|
||||||
inst->content = other->content;
|
|
||||||
|
|
||||||
return apply(NormalStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Report_Delete(Report *inst)
|
|
||||||
{
|
|
||||||
svoid(inst);
|
|
||||||
|
|
||||||
free(inst->initiator);
|
|
||||||
inst->initiator = NULL;
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
nonull(inst, apply(UnavailableInstance));
|
|
||||||
nonull(buff, apply(UnavailableBuffer));
|
|
||||||
|
|
||||||
/* Report literalisation. */
|
|
||||||
char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
|
||||||
|
|
||||||
/** Status literalisation. **/
|
|
||||||
char status_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
|
||||||
|
|
||||||
/* 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)), )
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
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 apply(annot(InstanceCreatingFailure,
|
|
||||||
"Cannot copy to create new instance of report."));
|
|
||||||
);
|
|
||||||
inst->report = *report;
|
|
||||||
inst->elapsed = 0;
|
|
||||||
inst->result = REPORT_RESULT_PENDING;
|
|
||||||
|
|
||||||
return apply(NormalStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
Status ReportSender_Send(ReportSender *inst, ReportTask task)
|
|
||||||
{
|
|
||||||
// /* Skip when inst or task is unavailable. */
|
|
||||||
// nonull(inst,
|
|
||||||
// error(UnavailableInstance, "Report sender was given unavailable."));
|
|
||||||
// nonull(task, InvalidReportTask);
|
|
||||||
|
|
||||||
// /* Assign for dest. */
|
|
||||||
// const FILE *dest = (inst->report->dest == NULL ? stdout : inst->report->dest);
|
|
||||||
// // char buff[];
|
|
||||||
// // TODO(william): HERE, Report_Literalise
|
|
||||||
|
|
||||||
// /* Write/Send data. */
|
|
||||||
// inst->report->taskprint_status = REPORT_SENDING_TASK_STATUS_PROCEEDING;
|
|
||||||
// if (!fprintf(dest, buff)) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /* Sent successfully! Mark down properties. */
|
|
||||||
return apply(NormalStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// bool arguestarter_equal(ArgueStarter *inst1, ArgueStarter *inst2)
|
// bool arguestarter_equal(ArgueStarter *inst1, ArgueStarter *inst2)
|
||||||
// {
|
// {
|
||||||
// /* Skip when either inst1 or inst2 is unavailable. */
|
// /* Skip when either inst1 or inst2 is unavailable. */
|
||||||
@@ -324,65 +159,3 @@ Status ReportSender_Send(ReportSender *inst, ReportTask task)
|
|||||||
// return (inst1->argue_start == inst2->argue_start)
|
// return (inst1->argue_start == inst2->argue_start)
|
||||||
// || (inst1->external_param == inst2->external_param);
|
// || (inst1->external_param == inst2->external_param);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
ReportTaskID THROW(Report report, Location loc)
|
|
||||||
{
|
|
||||||
// // /* Create new a instance of ReportSender. */
|
|
||||||
// // ReportSender sender;
|
|
||||||
// // ReportSender_Create(&sender, stderr);
|
|
||||||
|
|
||||||
// // /* Send message. */
|
|
||||||
// // /* Initialise sender's thread. */
|
|
||||||
// // thrd_t sending;
|
|
||||||
// // /* Skip on failing on creating thread. */
|
|
||||||
// // if (!thrd_create(&sending, starter, NULL)) {
|
|
||||||
|
|
||||||
// // /* Conclude the session of sender. */
|
|
||||||
// // report.status = REPORT_SENDING_TASK_STATUS_FINISHED,
|
|
||||||
// // report.result = (ARGUE_RESULT_FINALISED | ARGUE_RESULT_NEGATIVE);
|
|
||||||
|
|
||||||
// // sender.result = REPORT_SENDER_RESULT_FINISHED;
|
|
||||||
// // sender.successful = false;
|
|
||||||
|
|
||||||
// // return -1;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // /* Perform sending. */
|
|
||||||
// // ReportSender_Send(&sender, NULL);
|
|
||||||
|
|
||||||
// /* Initialise sender. */
|
|
||||||
// ReportSender sender;
|
|
||||||
// /* Return with -1 when initialisation failed. */
|
|
||||||
// state(!(StatusUtils_IsOkay(ReportSender_Create(&sender, &report))), -1);
|
|
||||||
|
|
||||||
// /* Inject location information. Could be more elegant, though. */
|
|
||||||
// sender.report->status.loc = loc;
|
|
||||||
|
|
||||||
// /* Send. */ /* Return -1 when failed on sending. */
|
|
||||||
// state(!StatusUtils_IsOkay(ReportSender_Send(&sender, HANDLER)), -1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int HANDLER(void *report)
|
|
||||||
{
|
|
||||||
// /* Throw UnableToThrowError when param is unavailable. */
|
|
||||||
// if (report == NULL) {
|
|
||||||
// /* Create report on this. */
|
|
||||||
// Report e;
|
|
||||||
// Report_Create(
|
|
||||||
// &e,
|
|
||||||
// &error(UnableToThrowError, "Cannot perform throwing. Aborted."),
|
|
||||||
// stderr, nameof(DEFAULT_ARGUE_STARTER),
|
|
||||||
// REPORT_SENDING_PRIORITY_FATAL);
|
|
||||||
|
|
||||||
// /* Perform throwing. */
|
|
||||||
// (void)throw(e); // Throw the report alone.
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// (void)throw(*(Report *)report); // Lonely throw, no catch will company.
|
|
||||||
// return 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
4
common.h
4
common.h
@@ -209,4 +209,8 @@ typedef bool _Bit;
|
|||||||
# define __ATTRIBUTABLE__
|
# define __ATTRIBUTABLE__
|
||||||
# define attr(a)
|
# define attr(a)
|
||||||
|
|
||||||
|
/* Useless in C, only for human to see.
|
||||||
|
Probably rewrite this in Classify. */
|
||||||
|
# define throws(e)
|
||||||
|
|
||||||
#endif /* COMPOUND_COMMON_H */
|
#endif /* COMPOUND_COMMON_H */
|
||||||
|
@@ -30,6 +30,6 @@ done
|
|||||||
# Install individual headers.
|
# Install individual headers.
|
||||||
cp -v "common.h" "const.h" "platform.h"\
|
cp -v "common.h" "const.h" "platform.h"\
|
||||||
"name.h" "namescope.h" "type.h" "catlog.h"\
|
"name.h" "namescope.h" "type.h" "catlog.h"\
|
||||||
"attr.h" "registry.h" "class.h" "function.h" "$DST"
|
"attr.h" "registry.h" "class.h" "function.h" "report.h" "$DST"
|
||||||
|
|
||||||
printf "\nDone\n"
|
printf "\nDone\n"
|
||||||
|
233
report.c
Normal file
233
report.c
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
#include <Compound/report.h>
|
||||||
|
|
||||||
|
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
||||||
|
int priority)
|
||||||
|
{
|
||||||
|
/* Skip unavailable parameters. */
|
||||||
|
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->content = *stat;
|
||||||
|
inst->initiator = calloc(strlen(initiator), sizeof(char));
|
||||||
|
(void)strcpy(inst->initiator, initiator);
|
||||||
|
inst->time = time(NULL);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
nonull(inst, apply(UnavailableInstance));
|
||||||
|
nonull(other, apply(error(InvalidParameter, "Given report is unavailable.")));
|
||||||
|
|
||||||
|
// Status status;
|
||||||
|
// char *initiator;
|
||||||
|
// time_t time;
|
||||||
|
// ReportLevel priority;
|
||||||
|
// ReportTaskStatus taskprint_status;
|
||||||
|
// FILE *dest;
|
||||||
|
inst->content = other->content;
|
||||||
|
|
||||||
|
return apply(NormalStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Report_Delete(Report *inst)
|
||||||
|
{
|
||||||
|
svoid(inst);
|
||||||
|
|
||||||
|
free(inst->initiator);
|
||||||
|
inst->initiator = NULL;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// nonull(inst, apply(UnavailableInstance));
|
||||||
|
// nonull(buff, apply(UnavailableBuffer));
|
||||||
|
|
||||||
|
// /* Report literalisation. */
|
||||||
|
// char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||||
|
|
||||||
|
// /** Status literalisation. **/
|
||||||
|
// char status_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||||
|
|
||||||
|
// /* 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."));
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// where(
|
||||||
|
// snprintf(buff, LITERALISATION_LENGTH_MAXIMUM, REPORT_LITERALISE_FORMAT_DETAIL,
|
||||||
|
// strnil(inst->content.identity), strnil(inst->content.prev->identity),
|
||||||
|
// inst->content.value, inst->content.characteristic,
|
||||||
|
// inst->content.loc.file, inst->content.loc.line,
|
||||||
|
// inst->content.loc.func), {
|
||||||
|
// return apply(value(TraditionalFunctionReturn, _));
|
||||||
|
// });
|
||||||
|
|
||||||
|
// /* 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)), )
|
||||||
|
|
||||||
|
// // 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)
|
||||||
|
{
|
||||||
|
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 apply(annot(InstanceCreatingFailure,
|
||||||
|
"Cannot copy to create new instance of report."));
|
||||||
|
);
|
||||||
|
inst->report = *report;
|
||||||
|
inst->elapsed = 0;
|
||||||
|
inst->result = REPORT_RESULT_PENDING;
|
||||||
|
|
||||||
|
return apply(NormalStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ReportSender_Send(ReportSender *inst, ReportTask task)
|
||||||
|
{
|
||||||
|
// /* Skip when inst or task is unavailable. */
|
||||||
|
// nonull(inst,
|
||||||
|
// error(UnavailableInstance, "Report sender was given unavailable."));
|
||||||
|
// nonull(task, InvalidReportTask);
|
||||||
|
|
||||||
|
// /* Assign for dest. */
|
||||||
|
// const FILE *dest = (inst->report->dest == NULL ? stdout : inst->report->dest);
|
||||||
|
// // char buff[];
|
||||||
|
// // TODO(william): HERE, Report_Literalise
|
||||||
|
|
||||||
|
// /* Write/Send data. */
|
||||||
|
// inst->report->taskprint_status = REPORT_SENDING_TASK_STATUS_PROCEEDING;
|
||||||
|
// if (!fprintf(dest, buff)) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /* Sent successfully! Mark down properties. */
|
||||||
|
return apply(NormalStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportTaskID THROW(Report report, Location loc)
|
||||||
|
{
|
||||||
|
// // /* Create new a instance of ReportSender. */
|
||||||
|
// // ReportSender sender;
|
||||||
|
// // ReportSender_Create(&sender, stderr);
|
||||||
|
|
||||||
|
// // /* Send message. */
|
||||||
|
// // /* Initialise sender's thread. */
|
||||||
|
// // thrd_t sending;
|
||||||
|
// // /* Skip on failing on creating thread. */
|
||||||
|
// // if (!thrd_create(&sending, starter, NULL)) {
|
||||||
|
|
||||||
|
// // /* Conclude the session of sender. */
|
||||||
|
// // report.status = REPORT_SENDING_TASK_STATUS_FINISHED,
|
||||||
|
// // report.result = (ARGUE_RESULT_FINALISED | ARGUE_RESULT_NEGATIVE);
|
||||||
|
|
||||||
|
// // sender.result = REPORT_SENDER_RESULT_FINISHED;
|
||||||
|
// // sender.successful = false;
|
||||||
|
|
||||||
|
// // return -1;
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // /* Perform sending. */
|
||||||
|
// // ReportSender_Send(&sender, NULL);
|
||||||
|
|
||||||
|
// /* Initialise sender. */
|
||||||
|
// ReportSender sender;
|
||||||
|
// /* Return with -1 when initialisation failed. */
|
||||||
|
// state(!(StatusUtils_IsOkay(ReportSender_Create(&sender, &report))), -1);
|
||||||
|
|
||||||
|
// /* Inject location information. Could be more elegant, though. */
|
||||||
|
// sender.report->status.loc = loc;
|
||||||
|
|
||||||
|
// /* Send. */ /* Return -1 when failed on sending. */
|
||||||
|
// state(!StatusUtils_IsOkay(ReportSender_Send(&sender, HANDLER)), -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int HANDLER(void *report)
|
||||||
|
{
|
||||||
|
// /* Throw UnableToThrowError when param is unavailable. */
|
||||||
|
// if (report == NULL) {
|
||||||
|
// /* Create report on this. */
|
||||||
|
// Report e;
|
||||||
|
// Report_Create(
|
||||||
|
// &e,
|
||||||
|
// &error(UnableToThrowError, "Cannot perform throwing. Aborted."),
|
||||||
|
// stderr, nameof(DEFAULT_ARGUE_STARTER),
|
||||||
|
// REPORT_SENDING_PRIORITY_FATAL);
|
||||||
|
|
||||||
|
// /* Perform throwing. */
|
||||||
|
// (void)throw(e); // Throw the report alone.
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// (void)throw(*(Report *)report); // Lonely throw, no catch will company.
|
||||||
|
// return 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
100
report.h
Normal file
100
report.h
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
#ifndef COMPOUND_REPORT_H
|
||||||
|
# define COMPOUND_REPORT_H
|
||||||
|
|
||||||
|
# include <Compound/status.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
REPORT_SENDING_PRIORITY_ALL = 0, // Highest level; least value.
|
||||||
|
REPORT_SENDING_PRIORITY_FATAL,
|
||||||
|
REPORT_SENDING_PRIORITY_EXCEPTIONAL,
|
||||||
|
REPORT_SENDING_PRIORITY_CRITICAL,
|
||||||
|
REPORT_SENDING_PRIORITY_MAJOR,
|
||||||
|
REPORT_SENDING_PRIORITY_NORMAL,
|
||||||
|
REPORT_SENDING_PRIORITY_MINOR,
|
||||||
|
REPORT_SENDING_PRIORITY_DEBUG,
|
||||||
|
REPORT_SENDING_PRIORITY_NONE, // Lowest level, greatest value.
|
||||||
|
} ReportLevel;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
REPORT_SENDING_TASK_STATUS_FINISHED = 0,
|
||||||
|
REPORT_SENDING_TASK_STATUS_PENDING,
|
||||||
|
REPORT_SENDING_TASK_STATUS_PROCEEDING,
|
||||||
|
REPORT_SENDING_TASK_STATUS_PAUSED,
|
||||||
|
REPORT_SENDING_TASK_STATUS_NOTFOUND
|
||||||
|
} ReportStatus;
|
||||||
|
|
||||||
|
/* "Report" recollects essential informations, included but not limited to
|
||||||
|
Status and others for making an report for debugging and such. */
|
||||||
|
typedef struct {
|
||||||
|
Status content;
|
||||||
|
char *initiator;
|
||||||
|
time_t time;
|
||||||
|
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
|
||||||
|
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||||
|
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
!!!!at /external/Documents/Projects/Compound/Array/src/array.c:16, array_create
|
||||||
|
at /external/Documents/Projects/Compound/test.c:24, main
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 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_RESULT_SUCCEEDED,
|
||||||
|
REPORT_RESULT_FAILED,
|
||||||
|
REPORT_RESULT_PROGRESSING,
|
||||||
|
REPORT_RESULT_PENDING,
|
||||||
|
} ReportResult;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
thrd_t thread;
|
||||||
|
Report report;
|
||||||
|
time_t elapsed;
|
||||||
|
ReportResult result;
|
||||||
|
} ReportSender;
|
||||||
|
|
||||||
|
typedef int (*ReportTask)(Report *);
|
||||||
|
typedef int ReportTaskID;
|
||||||
|
|
||||||
|
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
||||||
|
int priority);
|
||||||
|
Status Report_CopyOf(Report *inst, Report *other);
|
||||||
|
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, ReportTask task);
|
||||||
|
|
||||||
|
// ReportTaskStatus
|
||||||
|
// ReportSender_GetStatus(ReportSender *inst);
|
||||||
|
|
||||||
|
/* Add location parameter requirement in order to give proper information
|
||||||
|
* before throwing the report out. */
|
||||||
|
// # define throw(report) THROW(report, __HERE__)
|
||||||
|
|
||||||
|
// ReportTaskID THROW(Report report, Location loc);
|
||||||
|
// Report CATCH(ReportTaskID taskid, Status (*handler)());
|
||||||
|
int HANDLER(void *report);
|
||||||
|
|
||||||
|
#endif /* COMPOUND_REPORT_H */
|
Reference in New Issue
Block a user