giuliomoro@153: /* giuliomoro@153: * WriteMFile.h giuliomoro@153: * giuliomoro@153: * Created on: 5 Oct 2015 giuliomoro@153: * Author: giulio giuliomoro@153: */ giuliomoro@153: giuliomoro@153: #ifndef WRITEMFILE_H_ giuliomoro@153: #define WRITEMFILE_H_ giuliomoro@153: #include giuliomoro@153: #include giuliomoro@153: #include giuliomoro@153: #include giuliomoro@153: #include giuliomoro@153: #include giuliomoro@153: giuliomoro@153: class WriteFile { giuliomoro@153: private: giuliomoro@153: static AuxiliaryTask writeAllFilesTask; giuliomoro@153: bool echo; giuliomoro@153: char *header; giuliomoro@153: char *footer; giuliomoro@153: char *stringBuffer; giuliomoro@153: int stringBufferLength; giuliomoro@153: int bufferLength; giuliomoro@153: float* buffer; giuliomoro@153: int readPointer; giuliomoro@153: int writePointer; giuliomoro@153: bool variableOpen; giuliomoro@153: char* format; giuliomoro@153: int lineLength; giuliomoro@153: static int sleepTimeMs; giuliomoro@153: FILE *file; giuliomoro@153: void writeLine(); giuliomoro@153: void writeHeader(); giuliomoro@153: void writeFooter(); giuliomoro@153: void allocateAndCopyString(const char* source, char** destination); giuliomoro@153: void print(const char* string); giuliomoro@153: void setLineLength(int newLineLength); giuliomoro@153: std::vector formatTokens; giuliomoro@153: static void sanitizeString(char* string); giuliomoro@153: static void sanitizeString(char* string, int numberOfArguments); giuliomoro@153: static bool isThreadRunning(); giuliomoro@153: static bool auxiliaryTaskRunning; giuliomoro@153: static bool threadShouldExit(); giuliomoro@153: static bool threadIsExiting; giuliomoro@153: static bool threadRunning; giuliomoro@153: static bool staticConstructed; giuliomoro@153: static void staticConstructor(); giuliomoro@153: static std::vector objAddrs; giuliomoro@153: public: giuliomoro@153: WriteFile(); giuliomoro@153: void setEcho(bool newEcho); giuliomoro@153: void setFormat(const char* newFormat); giuliomoro@153: void setHeader(const char* newHeader); giuliomoro@153: void setFooter(const char* newFooter); giuliomoro@153: void log(float* array, int length); giuliomoro@153: void log(float value); giuliomoro@153: void init(const char* filename); giuliomoro@153: giuliomoro@153: /** giuliomoro@153: * Gets the distance between the write and read pointers of giuliomoro@153: * the buffer that holds data to be written to disk. giuliomoro@153: */ giuliomoro@153: int getOffset(); giuliomoro@153: giuliomoro@153: /** giuliomoro@153: * Inquiries the status of the buffer that holds data to be written to disk. giuliomoro@153: * giuliomoro@153: * @return a value between 0 and 1, with 0 being buffer full (writing to disk not fast enough) giuliomoro@153: * and 1 being buffer empty (writing to disk is fast enough). giuliomoro@153: */ giuliomoro@153: float getBufferStatus(); giuliomoro@153: void writeOutput(); giuliomoro@153: ~WriteFile(); giuliomoro@153: static int getNumInstances(); giuliomoro@153: static void writeAllHeaders(); giuliomoro@153: static void writeAllFooters(); giuliomoro@153: static void writeAllOutputs(); giuliomoro@153: static void startThread(); giuliomoro@153: static void stopThread(); giuliomoro@153: static void run(); giuliomoro@153: }; giuliomoro@153: giuliomoro@153: #endif /* WRITEMFILE_H_ */