/** * @function logfile.flush * * ### Synopsis * * logfile.flush(handle); * * Flush contents of shared memory block to the log file, reset memory block to "empty" state. * * @param {object} handle - handle of logfile to flush. */ static JSVAL logfile_flush (JSARGS args) { STATE *state = HANDLE(args[0]); lock_logfile(state); flush_logfile(state); unlock_logfile(state); return Undefined(); }
/** * @function logfile.flush * * ### Synopsis * * logfile.flush(handle); * * Flush contents of shared memory block to the log file, reset memory block to "empty" state. * * @param {object} handle - handle of logfile to flush. */ static JSVAL logfile_flush (JSARGS args) { HandleScope scope; STATE *state = log_HANDLE(args[0]); lock_logfile(state); flush_logfile(state); unlock_logfile(state); return Undefined(); }
/** * @function logfile.write * * ### Synopsis * * logfile.write(handle, s); * logfile.write(handle, s, len); * * Write a string to the log file. * * The string is appended to the shared memory block. The memory block is first flushed to disk if there is not enough room for the string. * * @param {object} handle - handle of the log file. * @param {string} s - string to write to the log file. * @param {int} len - optional length of string to write; defaults to strlen(s). * */ static JSVAL logfile_write (JSARGS args) { STATE *state = HANDLE(args[0]); String::AsciiValue buf(args[1]); int len; if (args.Length() > 2) { len = args[2]->IntegerValue(); } else { len = strlen(*buf); } lock_logfile(state); if (*state->length + len >= LOGFILE_CHUNK_SIZE) { flush_logfile(state); } memcpy(&state->logBuffer[*state->length], *buf, len); *state->length += len; unlock_logfile(state); return Undefined(); }
static void fileWriterTask(void *params) { LoggerMessage *msg = NULL; struct logging_status ls; memset(&ls, 0, sizeof(struct logging_status)); while(1) { int rc = -1; /* Get a sample. */ xQueueReceive(g_sampleRecordQueue, &(msg), portMAX_DELAY); switch (msg->type) { case LoggerMessageType_Sample: rc = logging_sample(&ls, msg); break; case LoggerMessageType_Start: rc = logging_start(&ls); break; case LoggerMessageType_Stop: rc = logging_stop(&ls); break; default: pr_warning("Unsupported message type\r\n"); } /* Turns the LED on if things are bad, off otherwise. */ error_led(rc); if (rc) { pr_debug("Msg type "); pr_debug_int(msg->type); pr_debug_int_msg(" failed with code ", rc); } flush_logfile(&ls); } }