forked from ahmidou/SpliceAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggingImpl.h
More file actions
122 lines (89 loc) · 3.76 KB
/
LoggingImpl.h
File metadata and controls
122 lines (89 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2010-2013 Fabric Engine Inc. All rights reserved.
#ifndef __FabricSpliceImpl__LOGGINGIMPL_H__
#define __FabricSpliceImpl__LOGGINGIMPL_H__
#include "StringUtilityImpl.h"
#include <FabricCore.h>
namespace FabricSpliceImpl
{
/// a function used to receive a single message string
typedef void(*LoggingFunc)(const char * message, unsigned int messageLength);
/// a function used to receive a compiler error
typedef void(*CompilerErrorFunc)(unsigned int row, unsigned int col, const char * file, const char * level, const char * desc);
/// a function to receive information from a KL status message
typedef void(*StatusFunc)(const char * topic, unsigned int topicLength, const char * message, unsigned int messageLength);
class LoggingImpl
{
public:
/// sets the callback for generic log messages
static void setLogFunc(LoggingFunc func);
/// sets the callback for error log messages
static void setLogErrorFunc(LoggingFunc func);
/// sets the callback for KL compiler error messages
static void setCompilerErrorFunc(CompilerErrorFunc func);
/// sets the callback for KL report statements
static void setKLReportFunc(LoggingFunc func);
/// returns the callback for KL report statements
static LoggingFunc getKLReportFunc() { return sKLReportFunc; }
/// sets the callback for KL queueStatusMessage statements
static void setKLStatusFunc(StatusFunc func);
/// gets the callback for KL queueStatusMessage statements
static StatusFunc getKLStatusFunc() { return sKLStatusFunc; }
/// logs to the logFunc callback
static void log(const std::string & message);
/// logs to the logErrorFunc callback
static void logError(const std::string & message);
/// reports an error to the logErrorFunc (or optionally to the provided string pointer)
static bool reportError(const std::string & message, std::string * errorOut = NULL);
/// reports a KL compiler error the klCompilerError callback
static bool reportCompilerError(unsigned int row, unsigned int col, const std::string & file, const std::string & level, const std::string & desc);
/// provides a callback to work with the core client directly
static void reportCallback(void * reportUserData, const char * message, unsigned int messageLength);
/// returns true if there is an error in the
static bool hasError();
/// returns the latest error
static const char * getError();
/// clears the error
static void clearError();
/// enable timers
static void enableTimers();
/// disable timers
static void disableTimers();
/// reset a timer
static void resetTimer(const std::string & name);
/// start a timer
static void startTimer(const std::string & name);
/// stop a timer and accumulate the time
static void stopTimer(const std::string & name);
/// log a given timer
static void logTimer(const std::string & name);
/// return the number of existing timers
static unsigned int getNbTimers();
/// return the number of existing timers
static char const * getTimerName(unsigned int index);
/// a timer which records time on construction and destruction
class AutoTimerImpl
{
public:
AutoTimerImpl(std::string name);
~AutoTimerImpl();
private:
std::string mName;
};
private:
static LoggingFunc sLogFunc;
static LoggingFunc sErrorLogFunc;
static CompilerErrorFunc sCompilerErrorFunc;
static LoggingFunc sKLReportFunc;
static StatusFunc sKLStatusFunc;
static std::string mErrorLog;
struct TimeInfo {
bool running;
std::string name;
long double start;
long double elapsed;
};
static bool sTimersEnabled;
static std::map<std::string, TimeInfo> sTimers;
};
}
#endif