fixed some compiler errors. disabled qscript agent
[profile/ivi/automotive-message-broker.git] / lib / debugout.h
1 /*
2 Copyright (C) 2012 Intel Corporation
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #ifndef DEBUGOUT__H__
20 #define DEBUGOUT__H__
21
22 #include <string>
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
26 #include "timestamp.h"
27
28 using namespace std;
29
30 void debugOut(string message);
31
32 class DebugOut 
33 {
34 public:
35
36         static const int Error;
37         static const int Warning;
38
39         DebugOut(int debugLevel = 4)
40         {
41                 mDebugLevel = debugLevel;
42
43                 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
44                 {
45                         ostream out(buf);
46                         out.precision(15);
47                         out<<bufferTime(amb::currentTime())<<" | ";
48
49                         if(mDebugLevel == Error)
50                                 out<<"ERROR ";
51                         if(mDebugLevel == Warning)
52                                 out<<"WARNING ";
53                 }
54         }
55         DebugOut const& operator << (string message) const
56         {
57                 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
58                 {
59                         ostream out(buf);
60                         out.precision(15);
61                         out<<message<<" ";
62                 }
63                 return *this;
64         }
65
66         DebugOut const& operator << (ostream & (*manip)(std::ostream&)) const
67         {
68
69
70                 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
71                 {
72                         ostream out(buf);
73                         out.precision(15);
74                         out<<endl;
75                 }
76                 return *this;
77         }
78         
79         DebugOut const & operator << (double val) const
80         {
81                 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
82                 {
83                         ostream out(buf);
84                         out.precision(15);
85                         out<<val<<" ";
86                 }
87                 return *this;
88         }
89
90         static void setDebugThreshhold(int th)
91         {
92                 debugThreshhold = th;
93         }
94
95         static void setOutput(ostream &o)
96         {
97                 buf = o.rdbuf();
98         }
99
100 private:
101
102         std::string bufferTime(double time)
103         {
104                 ostringstream f;
105
106                 f.precision(15);
107
108                 f<<time;
109
110                 while(f.str().length() <= 15)
111                 {
112                         f<<" ";
113                 }
114
115                 return f.str();
116         }
117
118         static int debugThreshhold;
119         static std::streambuf *buf;
120         int mDebugLevel;
121 };
122
123
124
125
126
127 #endif