Suppress console output for none-standalone mode

libaria2
Tatsuhiro Tsujikawa 2013-05-02 11:30:42 +09:00
parent 315c05ea3c
commit d07b3ff8d9
6 changed files with 44 additions and 34 deletions

View File

@ -43,8 +43,8 @@ class NullOutputFile:public OutputFile {
public: public:
virtual ~NullOutputFile() {} virtual ~NullOutputFile() {}
virtual size_t write(const char* str) { return 0; } virtual size_t write(const char* str) { return 0; }
virtual int vprintf(const char* format, va_list va) { return 0; }
virtual int flush() { return 0; } virtual int flush() { return 0; }
virtual int vprintf(const char* format, va_list va) { return 0; }
virtual bool supportsColor() { return false; } virtual bool supportsColor() { return false; }
}; };

View File

@ -56,6 +56,7 @@
#include "BitfieldMan.h" #include "BitfieldMan.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "RpcMethodImpl.h" #include "RpcMethodImpl.h"
#include "console.h"
namespace aria2 { namespace aria2 {
@ -72,6 +73,7 @@ Platform* platform = 0;
int libraryInit() int libraryInit()
{ {
global::initConsole(true);
try { try {
platform = new Platform(); platform = new Platform();
} catch(RecoverableException& e) { } catch(RecoverableException& e) {

View File

@ -33,38 +33,47 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "console.h" #include "console.h"
#include "NullOutputFile.h"
#ifdef __MINGW32__
# include "WinConsoleFile.h"
#else // !__MINGW32__
# include "BufferedFile.h"
#endif // !__MINGW32__
namespace aria2 { namespace aria2 {
namespace global { namespace global {
#ifdef __MINGW32__ namespace {
const SharedHandle<WinConsoleFile>& cout() Console consoleCout;
{ Console consoleCerr;
static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_OUTPUT_HANDLE)); };
return f;
}
#else // !__MINGW32__
const SharedHandle<BufferedFile>& cout()
{
static SharedHandle<BufferedFile> f(new BufferedFile(stdout));
return f;
}
#endif // !__MINGW32__
void initConsole(bool suppress)
{
if(suppress) {
consoleCerr.reset(new NullOutputFile());
consoleCout.reset(new NullOutputFile());
} else {
#ifdef __MINGW32__ #ifdef __MINGW32__
const SharedHandle<WinConsoleFile>& cerr() consoleCout.reset(new WinConsoleFile(STD_OUTPUT_HANDLE));
{ consoleCerr.reset(new WinConsoleFile(STD_ERROR_HANDLE));
static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_ERROR_HANDLE));
return f;
}
#else // !__MINGW32__ #else // !__MINGW32__
const SharedHandle<BufferedFile>& cerr() consoleCout.reset(new BufferedFile(stdout));
{ consoleCerr.reset(new BufferedFile(stderr));
static SharedHandle<BufferedFile> f(new BufferedFile(stderr));
return f;
}
#endif // !__MINGW32__ #endif // !__MINGW32__
}
}
const Console& cout()
{
return consoleCout;
}
const Console& cerr()
{
return consoleCerr;
}
} // namespace global } // namespace global

View File

@ -37,22 +37,18 @@
#include "common.h" #include "common.h"
#include "SharedHandle.h" #include "SharedHandle.h"
#ifdef __MINGW32__ #include "OutputFile.h"
# include "WinConsoleFile.h"
#else // !__MINGW32__
# include "BufferedFile.h"
#endif // !__MINGW32__
namespace aria2 { namespace aria2 {
#ifdef __MINGW32__ typedef SharedHandle<OutputFile> Console;
typedef SharedHandle<WinConsoleFile> Console;
#else // !__MINGW32__
typedef SharedHandle<BufferedFile> Console;
#endif // !__MINGW32__
namespace global { namespace global {
// Initialize console output facility. If the |suppress| is true, all
// output sent to the console objects are discarded.
void initConsole(bool suppress);
const Console& cout(); const Console& cout();
const Console& cerr(); const Console& cerr();

View File

@ -62,6 +62,7 @@ error_code::Value main(int argc, char** argv)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
aria2::error_code::Value r; aria2::error_code::Value r;
aria2::global::initConsole(false);
try { try {
aria2::Platform platform; aria2::Platform platform;
r = aria2::main(argc, argv); r = aria2::main(argc, argv);

View File

@ -9,8 +9,10 @@
#include "Platform.h" #include "Platform.h"
#include "SocketCore.h" #include "SocketCore.h"
#include "util.h" #include "util.h"
#include "console.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
aria2::global::initConsole(false);
aria2::Platform platform; aria2::Platform platform;
#ifdef ENABLE_NLS #ifdef ENABLE_NLS