separating data structure from global state

This commit is contained in:
rusefi 2018-08-31 22:19:19 -04:00
parent 61d3eb177c
commit 95117bcfdc
8 changed files with 16 additions and 11 deletions

View File

@ -102,11 +102,11 @@ static void printWarning(const char *fmt, va_list ap) {
resetLogging(&logger); // todo: is 'reset' really needed here?
appendMsgPrefix(&logger);
append(&logger, WARNING_PREFIX);
logger.append(WARNING_PREFIX);
printToStream(&warningStream, fmt, ap);
append(&logger, warningBuffer);
logger.append(warningBuffer);
append(&logger, DELIMETER);
scheduleLogging(&logger);
}

View File

@ -8,9 +8,8 @@
#ifndef PID_H_
#define PID_H_
#include "global.h"
#include "main.h"
#include "engine_configuration_generated_structures.h"
#include "datalogging.h"
#if EFI_PROD_CODE || EFI_SIMULATOR
#include "tunerstudio_configuration.h"

View File

@ -29,6 +29,7 @@ extern "C"
#ifdef __cplusplus
#include "cli_registry.h"
#include "datalogging.h"
#include "loggingcentral.h"
#include "eficonsole.h"
#endif

View File

@ -39,7 +39,6 @@
#include "memstreams.h"
#include "console_io.h"
#include "rfiutil.h"
#include "loggingcentral.h"
static MemoryStream intermediateLoggingBuffer;
static uint8_t intermediateLoggingBufferData[INTERMEDIATE_LOGGING_BUFFER_SIZE] CCM_OPTIONAL;
@ -65,18 +64,23 @@ static ALWAYS_INLINE bool validateBuffer(Logging *logging, const char *text, uin
return false;
}
void append(Logging *logging, const char *text) {
void Logging::append(const char *text) {
efiAssertVoid(CUSTOM_ERR_6602, text != NULL, "append NULL");
uint32_t extraLen = efiStrlen(text);
bool isCapacityProblem = validateBuffer(logging, text, extraLen);
bool isCapacityProblem = validateBuffer(this, text, extraLen);
if (isCapacityProblem) {
return;
}
strcpy(logging->linePointer, text);
strcpy(linePointer, text);
/**
* And now we are pointing at the zero char at the end of the buffer again
*/
logging->linePointer += extraLen;
linePointer += extraLen;
}
// todo: inline
void append(Logging *logging, const char *text) {
logging->append(text);
}
/**

View File

@ -64,8 +64,6 @@ void resetLogging(Logging *logging);
void appendMsgPrefix(Logging *logging);
void appendMsgPostfix(Logging *logging);
void scheduleMsg(Logging *logging, const char *fmt, ...);
#ifdef __cplusplus
extern "C"

View File

@ -9,5 +9,6 @@
void initLoggingCentral(void);
char * swapOutputBuffers(int *actualOutputBufferSize);
void scheduleMsg(Logging *logging, const char *fmt, ...);
#endif /* UTIL_LOGGINGCENTRAL_H_ */

View File

@ -3,6 +3,7 @@
#ifdef __cplusplus
#include "datalogging.h"
#include "loggingcentral.h"
#include "eficonsole.h"
#include "cli_registry.h"
#include "chprintf.h"

View File

@ -24,6 +24,7 @@
#ifdef __cplusplus
#include "datalogging.h"
#include "loggingcentral.h"
extern "C"
{