WriteFile.h
1 /*
2  * WriteMFile.h
3  *
4  * Created on: 5 Oct 2015
5  * Author: giulio
6  */
7 
8 #ifndef WRITEMFILE_H_
9 #define WRITEMFILE_H_
10 #include <Bela.h>
11 #include <vector>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <unistd.h>
16 
17 typedef enum {
18  kBinary,
19  kText
20 } WriteFileType;
21 
22 class WriteFile {
23 private:
24  static AuxiliaryTask writeAllFilesTask;
25  bool echo;
26  int echoedLines;
27  int echoPeriod;
28  char *header;
29  char *footer;
30  char *stringBuffer;
31  int stringBufferLength;
32  int bufferLength;
33  float* buffer;
34  int textReadPointer;
35  int binaryReadPointer;
36  int writePointer;
37  bool variableOpen;
38  char* format;
39  int lineLength;
40  WriteFileType fileType;
41  static int sleepTimeMs;
42  FILE *file;
43  void writeLine();
44  void writeHeader();
45  void writeFooter();
46  void allocateAndCopyString(const char* source, char** destination);
47  void print(const char* string);
48  void printBinary(const char* string);
49  void setLineLength(int newLineLength);
50  int getOffsetFromPointer(int aPointer);
51  std::vector<char *> formatTokens;
52  static void sanitizeString(char* string);
53  static void sanitizeString(char* string, int numberOfArguments);
54  static bool isThreadRunning();
55  static bool auxiliaryTaskRunning;
56  static bool threadShouldExit();
57  static bool threadIsExiting;
58  static bool threadRunning;
59  static bool staticConstructed;
60  static void staticConstructor();
61  static std::vector<WriteFile *> objAddrs;
62  void writeOutput(bool flush);
63 public:
64  WriteFile();
71  void setFileType(WriteFileType newFileType);
72  void setEcho(bool newEcho);
73  void setEchoInterval(int newPeriod);
80  void setFormat(const char* newFormat);
86  void setHeader(const char* newHeader);
92  void setFooter(const char* newFooter);
93  void log(const float* array, int length);
94  void log(float value);
95  void init(const char* filename);
96 
101  int getOffset();
102 
109  float getBufferStatus();
110  ~WriteFile();
111  static int getNumInstances();
112  static void writeAllHeaders();
113  static void writeAllFooters();
114  static void writeAllOutputs(bool flush);
115  static void startThread();
116  static void stopThread();
117  static void run();
118 };
119 
120 #endif /* WRITEMFILE_H_ */
float getBufferStatus()
int getOffset()
void setFooter(const char *newFooter)
void setFileType(WriteFileType newFileType)
Definition: WriteFile.h:22
Main Bela public API.
void * AuxiliaryTask
Definition: Bela.h:289
void setFormat(const char *newFormat)
void setHeader(const char *newHeader)