File: grt_reporter.cpp

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (161 lines) | stat: -rw-r--r-- 3,222 bytes parent folder | download | duplicates (2)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* 
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "grtpp.h"
#include "grt_reporter.h"

#include <gmodule.h>

using namespace grt;
using namespace bec;


Reporter::Reporter(grt::GRT *grt) 
  : Reporter_grt(grt)
{
  flush(); 
};


inline bool Reporter::is_tracking() const    
{ 
  return _tracking; 
}


inline void Reporter::start_tracking() const 
{ 
  _tracking= true; 
} 


void Reporter::flush() const
{
  _warning_count= 0; 
  _error_count= 0;
  _tracking= false;
}


void Reporter::report_warning(const char *format, ...) const
{ 
  _warning_count++;

  va_list args;
  char *tmp;

  va_start(args, format);
  tmp= g_strdup_vprintf(format, args);
  va_end(args);

  if ( tmp )
  {
    Reporter_grt->send_warning( tmp ); 
    g_free(tmp);
  }
  else if ( format )
    Reporter_grt->send_warning( format ); 
}

void Reporter::report_error(const char *format, ...) const
{ 
  _error_count++; 

  va_list args;
  char *tmp = 0;

  va_start(args, format);
  tmp= g_strdup_vprintf(format, args);
  va_end(args);
  
  if ( tmp )
  {
    Reporter_grt->send_error( tmp ); 
    g_free(tmp);
  }
  else if ( format )
    Reporter_grt->send_error( format ); 
}


void Reporter::report_info(const char *format, ...) const  
{ 
  va_list args;
  char *tmp;

  va_start(args, format);
  tmp= g_strdup_vprintf(format, args);
  va_end(args);


  if ( tmp )
  {
    Reporter_grt->send_info( tmp ); 
    g_free(tmp);
  }
  else if ( format )
    Reporter_grt->send_info( format ); 
}


void Reporter::report_summary(const char *operation_name) const 
{ 
  if (error_count() && warning_count())
    report_info("Operation '%s' finished with %d errors and %d warnings", operation_name, error_count(), warning_count()); 
  else if (error_count())
    report_info("Operation '%s' finished with %d errors", operation_name, error_count()); 
  else if (warning_count())
    report_info("Operation '%s' finished with %d warnings", operation_name, warning_count()); 
  else 
    report_info("Operation '%s' finished successfully", operation_name); 
  flush();
}


inline int Reporter::error_count() const 
{ 
  return _error_count; 
}


inline int Reporter::warning_count() const 
{ 
  return _warning_count; 
}




SummaryCentry::SummaryCentry(Reporter& parent, const std::string& operation)
    : _rep(NULL)
{
  if (!parent.is_tracking())
  {
    _rep= &parent;
    _rep->start_tracking();
    _operation= operation;
  }
}


SummaryCentry::~SummaryCentry() 
{
  if (_rep)
    _rep->report_summary(_operation.c_str());
}