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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/* ****************************************************************************
* eID Middleware Project.
* Copyright (C) 2008-2009 FedICT.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version
* 3.0 as published by the Free Software Foundation.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, see
* http://www.gnu.org/licenses/.
**************************************************************************** */
#ifndef __ANALYSIS_H__
#define __ANALYSIS_H__
#include <sstream>
#include <time.h>
#include "CallbackData.h"
#include "error.h"
#include "report.h"
#include "progress.h"
class ExcAnalyse : public std::exception
{
public:
ExcAnalyse(int err, std::wstring const& msg)
: m_err(err)
, m_msg(msg)
{
}
virtual ~ExcAnalyse() throw()
{
}
std::wstring const& What() const throw()
{
return m_msg;
}
int getErr()
{
return m_err;
}
private:
int m_err;
std::wstring m_msg;
};
class ExcReport : public ExcAnalyse
{
public:
ExcReport(int err, std::wstring const& msg)
: ExcAnalyse(err, msg)
{
}
};
//----------------------------------------------------
// analyze base class
// each diagnostic class should derive from this class
// and implement the function 'run'
//----------------------------------------------------
class Analysis
{
public:
Analysis(); // ctor
virtual ~Analysis(); // dtor
virtual int run()
{
m_bPassed = false;
return -1;
};
int setCallback( CallbackData* callbackData )
{
m_callbackData = callbackData;
return 0;
};
void setProgress(size_t progress)
{
m_progress = progress;
doCallback();
}
void doCallback()
{
if (m_callbackData)
{
m_callbackData->m_callback(m_callbackData->m_userData,m_testName,m_progress);
}
}
std::string getTestName( void )
{
return m_testName;
}
std::string getTestFriendlyName( void )
{
return m_friendlyName;
}
void setStartTime()
{
m_startTime = clock();
}
void setEndTime()
{
m_endTime = clock();
}
int getExecutionTime( void )
{
return m_endTime - m_startTime;
}
bool testPassed()
{
return m_bPassed;
}
void resultToReport(Report_TYPE reportType,bool bPassed)
{
std::wstring str(L"[Error] Failed");
if (bPassed)
{
str = L"[Info ] Passed";
}
resultToReport(reportType,str.c_str());
};
void resultToReport(Report_TYPE reportType,const wchar_t* text)
{
std::wstringstream streamText;
streamText << text;
resultToReport(reportType,streamText);
}
void resultToReport(Report_TYPE reportType,std::wstringstream const& text)
{
int retVal = reportPrintResult(reportType,text.str().c_str());
if (retVal != DIAGLIB_OK)
{
ExcReport exc(retVal,text.str());
throw exc;
}
}
void commentToReport(Report_TYPE reportType,std::wstring const& text)
{
std::wstringstream streamText;
streamText << text;
commentToReport(reportType,streamText);
}
void commentToReport(Report_TYPE reportType,std::wstringstream const& text)
{
int retVal = reportPrintComment(reportType,text.str().c_str());
if (retVal != DIAGLIB_OK)
{
ExcReport exc(retVal,text.str());
throw exc;
}
}
void processParamsToStop()
{
setEndTime();
setProgress(100);
}
static std::string trim_right(const std::string &source , const std::string& t = " ")
{
std::string str = source;
return str.erase( str.find_last_not_of(t) + 1);
}
static std::string trim_left( const std::string& source, const std::string& t = " ")
{
std::string str = source;
return str.erase(0 , source.find_first_not_of(t) );
}
static std::string trim(const std::string& source, const std::string& t = " ")
{
std::string str = source;
return trim_left( trim_right( str , t) , t );
}
// static void progressCallbackFn(int progressPercent)
// {
// m_progressPercent=progressPercent;
//
private:
CallbackData* m_callbackData;
protected:
std::string m_testName; // name of the analysis engine
std::string m_friendlyName; // friendly name
bool m_bPassed; // test passed/failed
// static int m_progressPercent;
private:
size_t m_progress; // progress (percentage) of the analysis
clock_t m_startTime;
clock_t m_endTime;
};
#endif //__DIAGENGINE_ANALYSIS_H__
|