- avoid using _tprintf

- use EnvironmentVariable as a singleton

svn path=/trunk/; revision=24586
This commit is contained in:
Johannes Anderwald 2006-10-20 20:09:29 +00:00
parent 98aa4d7f47
commit 74847bd6f5
8 changed files with 108 additions and 55 deletions

View file

@ -14,9 +14,20 @@
namespace Sysreg_
{
using std::cout;
#ifdef UNICODE
using std::wcerr;
using std::endl;
#define cerr wcerr
#else
using std::cerr;
using std::endl;
#endif
using std::ifstream;
//---------------------------------------------------------------------------------------
ConfigParser::ConfigParser()
@ -84,9 +95,7 @@ namespace Sysreg_
ConfigMap::iterator it = m_Map.find (ConfVariable);
if (it == m_Map.end ())
{
#ifdef NDEBUG
cerr << "ConfigParser::getValue failed to find " << ConfVariable << endl;
#endif
return false;
}

View file

@ -18,6 +18,7 @@
namespace Sysreg_
{
using std::map;
using std::wstring;
//---------------------------------------------------------------------------------------
///
/// class ConfigParser
@ -34,6 +35,7 @@ namespace Sysreg_
class ConfigParser
{
public:
typedef std::basic_string<TCHAR> string;
typedef std::basic_istringstream<TCHAR> istringstream;
typedef map<string, string> ConfigMap;

View file

@ -13,9 +13,22 @@
namespace System_
{
using std::cout;
#ifdef UNICODE
using std::wcerr;
using std::endl;
#define cerr wcerr
#else
using std::cerr;
using std::endl;
#endif
EnvironmentVariable::EnvironmentMap EnvironmentVariable::m_Map;
//---------------------------------------------------------------------------------------
EnvironmentVariable::EnvironmentVariable()
@ -44,17 +57,13 @@ namespace System_
if (!value)
{
#ifdef NDEBUG
cerr << "EnvironmentVariable::getValue found no value for " << EnvName << endl;
#endif
return false;
}
if (!_tcslen(value))
{
#ifdef NDEBUG
cerr << "EnvironmentVariable::getValue found no value for " << EnvName << endl;
#endif
return false;
}

View file

@ -28,16 +28,8 @@ namespace System_
class EnvironmentVariable
{
typedef map<string, string> EnvironmentMap;
public:
//---------------------------------------------------------------------------------------
///
/// EnvironmentVariable
///
/// Description: constructor of class EnvironmentVariable
EnvironmentVariable();
typedef map<string, string> EnvironmentMap;
//---------------------------------------------------------------------------------------
///
/// ~EnvironmentVariable
@ -58,11 +50,20 @@ namespace System_
/// @param EnvValue value of the environment variable
/// @return bool
bool getValue(const string & EnvName, string & EnvValue);
static bool getValue(const string & EnvName, string & EnvValue);
protected:
EnvironmentMap m_Map;
//---------------------------------------------------------------------------------------
///
/// EnvironmentVariable
///
/// Description: constructor of class EnvironmentVariable
EnvironmentVariable();
static EnvironmentMap m_Map;
}; // end of class EnvironmentVariable

View file

@ -14,9 +14,19 @@
namespace System_
{
using std::cout;
#ifdef UNICODE
using std::wcerr;
using std::endl;
#define cerr wcerr
#else
using std::cerr;
using std::endl;
#endif
//---------------------------------------------------------------------------------------
PipeReader::PipeReader() : m_File(NULL)
@ -36,24 +46,18 @@ namespace System_
{
if (m_File != NULL)
{
#ifdef NDEBUG
cerr << "PipeReader::openPipe> pipe already open" << endl;
#endif
return false;
}
//
m_File = _tpopen(PipeCmd.c_str(), AccessMode.c_str());
if (m_File)
{
#ifdef NDEBUG
cerr << "PipeReader::openPipe> successfully opened pipe" << endl;
#endif
return true;
}
#ifdef NDEBUG
cerr << "PipeReader::openPipe> failed to open pipe " << PipeCmd << endl;
#endif
return false;
}
@ -63,9 +67,7 @@ namespace System_
{
if (!m_File)
{
#ifdef NDEBUG
cerr << "PipeReader::closePipe> pipe is not open" << endl;
#endif
return false;
}
@ -73,9 +75,7 @@ namespace System_
if (res == UINT_MAX)
{
#ifdef NDEBUG
cerr << "Error: _pclose failed " <<endl;
#endif
return false;
}
@ -105,16 +105,9 @@ namespace System_
TCHAR * res = _fgetts(buf, size, m_File);
if (!res)
{
#ifdef NDEBUG
cerr << "Error: PipeReader::readPipe failed" << endl;
#endif
return 0;
}
#ifdef NDEBUG
cerr << "PipeReader::readPipe> res: " << Buffer << endl;
#endif
return _tcslen(buf);
}

View file

@ -16,9 +16,20 @@
namespace Sysreg_
{
using std::cout;
#ifdef UNICODE
using std::wcerr;
using std::endl;
#define cerr wcerr
#else
using std::cerr;
using std::endl;
#endif
using System_::PipeReader;
@ -72,7 +83,8 @@ namespace Sysreg_
}
else
{
_tprintf(_T("Error: unknown debug port %s Currently only file|pipe is supported\n"), debug_port);
cerr <<"Error: unknown debug port " << debug_port <<endl
<<" Currently only file|pipe is supported" <<endl;
return false;
}
@ -90,7 +102,7 @@ namespace Sysreg_
/// TBD the information needs to be written into an provided log object
/// which writes the info into HTML/log / sends etc ....
_tprintf(debug_data.c_str ());
cerr << debug_data << endl;
return true;
}
@ -102,7 +114,7 @@ namespace Sysreg_
if (!pipe_reader.openPipe(boot_cmd, string(_T("rt"))))
{
_tprintf(_T("Error: failed to open pipe with cmd: %s\n"), boot_cmd.c_str ());
cerr << "Error: failed to open pipe with cmd: " << boot_cmd <<endl;
return false;
}
string Buffer;
@ -130,13 +142,13 @@ namespace Sysreg_
if (!pipe_reader.openPipe(boot_cmd, string(_T("rt"))))
{
_tprintf(_T("Error: failed to open pipe with cmd: %s\n"), boot_cmd.c_str ());
cerr << "Error: failed to open pipe with cmd: " << boot_cmd << endl;
return false;
}
FILE * file = _tfopen(debug_log.c_str (), _T("rt"));
if (!file)
{
_tprintf(_T("Error: failed to open debug log %s\n", debug_log.c_str ()));
cerr << "Error: failed to open debug log " << debug_log << endl;
pipe_reader.closePipe ();
return false;
}
@ -156,6 +168,7 @@ namespace Sysreg_
}while(!pipe_reader.isEof ());
pipe_reader.closePipe ();
return true;
}
} // end of namespace Sysreg_

View file

@ -25,9 +25,22 @@
namespace System_
{
using std::cout;
#ifdef UNICODE
using std::wcerr;
using std::endl;
#define cerr wcerr
#else
using std::cerr;
using std::endl;
#endif
using std::vector;
string SymbolFile::VAR_ROS_OUTPUT = _T("ROS_OUTPUT");
@ -52,13 +65,12 @@ namespace System_
bool SymbolFile::initialize(ConfigParser & conf_parser, const System_::string &Path)
{
vector<string> vect;
EnvironmentVariable envvar;
string current_dir;
if (Path == _T(""))
{
current_dir = _T("output-i386");
envvar.getValue(SymbolFile::VAR_ROS_OUTPUT, current_dir);
EnvironmentVariable::getValue(SymbolFile::VAR_ROS_OUTPUT, current_dir);
}
else
{
@ -101,6 +113,8 @@ namespace System_
string path = current_dir;
path.insert (path.length () -1, _T("\\"));
path.insert (path.length () -1, filename);
cerr << "Module Name " << modulename << endl << "File Name " << filename << endl;
m_Map.insert(std::make_pair<string, string>(modulename, path));
@ -168,7 +182,7 @@ namespace System_
if (!pipe_reader.openPipe (pipe_cmd))
{
_tprintf(_T("SymbolFile::resolveAddress> failed to open pipe %s"), pipe_cmd);
cerr << "SymbolFile::resolveAddress> failed to open pipe" <<pipe_cmd <<endl;
return false;
}
@ -189,7 +203,7 @@ namespace System_
if (it == m_Map.end ())
{
_tprintf(_T("SymbolFile::resolveAddress> no symbol file found for module %s"), ModuleName.c_str());
cerr << "SymbolFile::resolveAddress> no symbol file found for module " << ModuleName << endl;
return false;
}

View file

@ -11,13 +11,25 @@
#include "sysreg.h"
#ifdef UNICODE
using std::wcerr;
using std::endl;
using std::wcout;
#define cerr wcerr
#define cout wcout
#else
using std::cerr;
using std::endl;
#endif
typedef std::basic_string<TCHAR> string;
using std::cout;
using std::endl;
using std::cerr;
using System_::EnvironmentVariable;
using System_::ComponentFactoryTemplate;
@ -63,7 +75,7 @@ int _tmain(int argc, TCHAR * argv[])
RegressionTest * regtest = comp_factory.createComponent (argv[2]);
if (!regtest)
{
_tprintf(_T("Error: the requested regression test does not exist"));
cerr << "Error: the requested regression test does not exist" << endl;
return -1;
}
@ -75,11 +87,11 @@ int _tmain(int argc, TCHAR * argv[])
if (regtest->execute (config))
{
_tprintf(_T("The regression test %s completed successfully\n"), regtest->getName ().c_str ());
cout << "The regression test " << regtest->getName () << " completed successfully" << endl;
}
else
{
_tprintf(_T("The regression test %s failed\n"), regtest->getName ().c_str ());
cout << "The regression test " << regtest->getName () << "failed" << endl;
}
return 0;