diff --git a/Status/include/status.h b/Status/include/status.h index dbdefa4..bac29be 100644 --- a/Status/include/status.h +++ b/Status/include/status.h @@ -113,7 +113,6 @@ typedef struct _Status { 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); void StatusUtils_Dump(Status *inst, Status *store); diff --git a/Status/src/status.c b/Status/src/status.c index a3dd965..9db4d93 100644 --- a/Status/src/status.c +++ b/Status/src/status.c @@ -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) { return (stat.prev != NULL); @@ -174,65 +159,3 @@ int StatusUtils_Depth(Status *stat) // return (inst1->argue_start == inst2->argue_start) // || (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; -} diff --git a/common.h b/common.h index 0e788fa..8b492ae 100644 --- a/common.h +++ b/common.h @@ -209,4 +209,8 @@ typedef bool _Bit; # define __ATTRIBUTABLE__ # define attr(a) +/* Useless in C, only for human to see. + Probably rewrite this in Classify. */ +# define throws(e) + #endif /* COMPOUND_COMMON_H */ diff --git a/report.c b/report.c index c9ac737..7e0f715 100644 --- a/report.c +++ b/report.c @@ -51,6 +51,17 @@ void Report_Delete(Report *inst) inst = NULL; } + + + + + + + + + + + /* Status status; char *initiator; @@ -61,47 +72,56 @@ void Report_Delete(Report *inst) */ Status Report_Literalise(Report *inst, char *buff) { - nonull(inst, apply(UnavailableInstance)); - nonull(buff, apply(UnavailableBuffer)); + // nonull(inst, apply(UnavailableInstance)); + // nonull(buff, apply(UnavailableBuffer)); - /* Report literalisation. */ - char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY; + // /* Report literalisation. */ + // char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY; - /** Status literalisation. **/ - char status_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.") - // )); - // }) - // }); + // /* 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.")); - }); + // /* 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)), ) + // 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.")) - ); + // // 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". */ + // /* Write the report "detail". */ return apply(NormalStatus); } @@ -149,3 +169,65 @@ Status ReportSender_Send(ReportSender *inst, ReportTask task) // /* 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; +} diff --git a/report.h b/report.h index 17ec409..04ab5d7 100644 --- a/report.h +++ b/report.h @@ -93,10 +93,6 @@ Status ReportSender_Send(ReportSender *inst, ReportTask task); * 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);