LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
AsyncPrinter.h
1 #ifndef ASYNC_PRINTER_H_
2 #define ASYNC_PRINTER_H_
3 
4 #include <WPILib.h>
5 #include <queue>
6 #include <string>
7 
8 #include "../Process/AsyncProcess.h"
9 
10 #define ASYNC_PRINTLN(fmt, ...) \
11 AsyncPrinter::Printf(fmt ## " (%s, line %d)\n", ## __VA_ARGS__, __FILE__, __LINE__);
12 
17 class AsyncPrinter : public AsyncProcess
18 {
19 public:
20  static void Initialize();
21  static void Finalize();
22 
23  static int Printf(const char* msg, ...);
24  static int Println(const char* msg, ...);
25  static void DbgPrint(const char* msg, ...);
26 
27  static void RedirectToFile(const char* file);
28  static void RestoreToConsole();
29 
30  AsyncPrinter();
31  ~AsyncPrinter();
32 
33  static const UINT32 kMaxQueueSize = 4096;
34  static const UINT32 kMaxPrintsPerCycle = 50;
35 
36 protected:
37  void Tick();
38 
39 private:
40  static AsyncPrinter* _instance;
41 
42  SEM_ID m_queueSem;
43 
44  queue<string> _messageQueue;
45 
46  static bool filePrinting;
47  static int fd;
48  static fpos_t pos;
49 };
50 
51 #endif