Skip to content

Commit

Permalink
libdeng2|Cleanup: Removed LegacyCore as obsolete and unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 13, 2013
1 parent aaebc29 commit d89025f
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 317 deletions.
1 change: 0 additions & 1 deletion doomsday/libdeng2/include/de/LegacyCore

This file was deleted.

41 changes: 17 additions & 24 deletions doomsday/libdeng2/include/de/c_wrapper.h
Expand Up @@ -50,31 +50,10 @@ extern "C" {
#endif

/*
* LegacyCore
* App
*/
DENG2_OPAQUE(LegacyCore)

// Log levels (see de::Log for description).
typedef enum legacycore_loglevel_e {
DE2_LOG_TRACE,
DE2_LOG_DEBUG,
DE2_LOG_VERBOSE,
DE2_LOG_MESSAGE,
DE2_LOG_INFO,
DE2_LOG_WARNING,
DE2_LOG_ERROR,
DE2_LOG_CRITICAL
} legacycore_loglevel_t;

DENG2_PUBLIC LegacyCore *LegacyCore_New();
DENG2_PUBLIC void LegacyCore_Delete(LegacyCore *lc);
DENG2_PUBLIC LegacyCore *LegacyCore_Instance();
DENG2_PUBLIC void LegacyCore_Timer(unsigned int milliseconds, void (*callback)(void));
DENG2_PUBLIC int LegacyCore_SetLogFile(char const *filePath);
DENG2_PUBLIC char const *LegacyCore_LogFile();
DENG2_PUBLIC void LegacyCore_PrintLogFragment(char const *text);
DENG2_PUBLIC void LegacyCore_PrintfLogFragmentAtLevel(legacycore_loglevel_t level, char const *format, ...);
DENG2_PUBLIC void LegacyCore_FatalError(char const *msg);
DENG2_PUBLIC void App_Timer(unsigned int milliseconds, void (*callback)(void));
DENG2_PUBLIC void App_FatalError(char const *msg);

/*
* CommandLine
Expand All @@ -94,9 +73,23 @@ DENG2_PUBLIC int CommandLine_IsMatchingAlias(char const *original, char const *o
/*
* LogBuffer
*/
// Log levels (see de::Log for description).
typedef enum legacycore_loglevel_e {
DE2_LOG_TRACE,
DE2_LOG_DEBUG,
DE2_LOG_VERBOSE,
DE2_LOG_MESSAGE,
DE2_LOG_INFO,
DE2_LOG_WARNING,
DE2_LOG_ERROR,
DE2_LOG_CRITICAL
} legacycore_loglevel_t;

DENG2_PUBLIC void LogBuffer_EnableStandardOutput(int enable);
DENG2_PUBLIC void LogBuffer_Flush(void);
DENG2_PUBLIC void LogBuffer_Clear(void);
DENG2_PUBLIC void LogBuffer_Msg(char const *text);
DENG2_PUBLIC void LogBuffer_Printf(legacycore_loglevel_t level, char const *format, ...);

/*
* Info
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/core/app.h
Expand Up @@ -228,7 +228,7 @@ class DENG2_PUBLIC App : DENG2_OBSERVES(Clock, TimeChange)
*
* This should not be called directly. From C++ code, one should throw an
* exception in unrecoverable error situations. From C code, one should
* call the LegacyCore_FatalError() function.
* call the App_FatalError() function.
*
* @param message Error message to be shown to the user.
*/
Expand Down
5 changes: 5 additions & 0 deletions doomsday/libdeng2/include/de/core/logbuffer.h
Expand Up @@ -132,6 +132,11 @@ class DENG2_PUBLIC LogBuffer : public QObject, public Lockable, DENG2_OBSERVES(F
*/
void setOutputFile(String const &path);

/**
* Returns the path of the file used for log output.
*/
String outputFile() const;

/**
* Adds a new sink where log entries will be flushed. There can be any
* number of sinks in use. The sink must not be deleted while it is
Expand Down
9 changes: 9 additions & 0 deletions doomsday/libdeng2/include/de/core/loop.h
Expand Up @@ -21,6 +21,7 @@

#include <QObject>
#include <de/Observers>
#include <de/Time>

namespace de {

Expand Down Expand Up @@ -70,6 +71,14 @@ class DENG2_PUBLIC Loop : public QObject

void resume();

/**
* Registers a new single-shot timer that will do a callback.
*
* @param delay Time to wait before calling.
* @param func Callback to call.
*/
static void timer(TimeDelta const &delay, void (*func)(void));

public slots:
void nextLoopIteration();

Expand Down
99 changes: 0 additions & 99 deletions doomsday/libdeng2/include/de/legacy/legacycore.h

This file was deleted.

8 changes: 0 additions & 8 deletions doomsday/libdeng2/legacy.pri

This file was deleted.

1 change: 0 additions & 1 deletion doomsday/libdeng2/libdeng2.pro
Expand Up @@ -57,7 +57,6 @@ INCLUDEPATH += include

include(data.pri)
include(filesys.pri)
include(legacy.pri)
include(network.pri)
include(scriptsys.pri)
include(widgets.pri)
Expand Down
116 changes: 44 additions & 72 deletions doomsday/libdeng2/src/c_wrapper.cpp
Expand Up @@ -20,7 +20,7 @@
#include "de/c_wrapper.h"
#include "de/Error"
#include "de/App"
#include "de/LegacyCore"
#include "de/Loop"
#include "de/Address"
#include "de/ByteRefArray"
#include "de/Block"
Expand All @@ -31,82 +31,14 @@
#include <cstring>
#include <stdarg.h>

#define DENG2_LEGACYCORE() de::LegacyCore::instance()
#define DENG2_LEGACYNETWORK() DENG2_LEGACYCORE().network()
#define DENG2_COMMANDLINE() DENG2_APP->commandLine()

LegacyCore *LegacyCore_New()
void App_Timer(unsigned int milliseconds, void (*callback)(void))
{
return reinterpret_cast<LegacyCore *>(new de::LegacyCore());
de::Loop::timer(de::TimeDelta::fromMilliSeconds(milliseconds), callback);
}

void LegacyCore_Delete(LegacyCore *lc)
{
if(lc)
{
// It gets stopped automatically.
DENG2_SELF(LegacyCore, lc);
delete self;
}
}

LegacyCore *LegacyCore_Instance()
{
return reinterpret_cast<LegacyCore *>(&de::LegacyCore::instance());
}

void LegacyCore_Timer(unsigned int milliseconds, void (*callback)(void))
{
DENG2_LEGACYCORE().timer(milliseconds, callback);
}

int LegacyCore_SetLogFile(char const *filePath)
{
try
{
DENG2_LEGACYCORE().setLogFileName(filePath);
return true;
}
catch(de::Error const &er)
{
LOG_AS("LegacyCore_SetLogFile");
LOG_WARNING(er.asText());
return false;
}
}

char const *LegacyCore_LogFile()
{
return DENG2_LEGACYCORE().logFileName();
}

void LegacyCore_PrintLogFragment(char const *text)
{
DENG2_LEGACYCORE().printLogFragment(text);
}

void LegacyCore_PrintfLogFragmentAtLevel(legacycore_loglevel_t level, char const *format, ...)
{
// Validate the level.
de::LogEntry::Level logLevel = de::LogEntry::Level(level);
if(level < DE2_LOG_TRACE || level > DE2_LOG_CRITICAL)
{
logLevel = de::LogEntry::MESSAGE;
}

// If this level is not enabled, just ignore.
if(!de::LogBuffer::appBuffer().isEnabled(logLevel)) return;

char buffer[2048];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args); /// @todo unsafe
va_end(args);

DENG2_LEGACYCORE().printLogFragment(buffer, logLevel);
}

void LegacyCore_FatalError(char const *msg)
void App_FatalError(char const *msg)
{
DENG2_APP->handleUncaughtException(msg);
}
Expand Down Expand Up @@ -197,6 +129,46 @@ void LogBuffer_EnableStandardOutput(int enable)
de::LogBuffer::appBuffer().enableStandardOutput(enable != 0);
}

static void logFragmentPrinter(de::LogEntry::Level level, char const *fragment)
{
static std::string currentLogLine;

currentLogLine += fragment;

std::string::size_type pos;
while((pos = currentLogLine.find('\n')) != std::string::npos)
{
LOG().enter(level, currentLogLine.substr(0, pos).c_str());
currentLogLine.erase(0, pos + 1);
}
}

void LogBuffer_Msg(char const *text)
{
logFragmentPrinter(de::LogEntry::MESSAGE, text);
}

void LogBuffer_Printf(legacycore_loglevel_t level, char const *format, ...)
{
// Validate the level.
de::LogEntry::Level logLevel = de::LogEntry::Level(level);
if(level < DE2_LOG_TRACE || level > DE2_LOG_CRITICAL)
{
logLevel = de::LogEntry::MESSAGE;
}

// If this level is not enabled, just ignore.
if(!de::LogBuffer::appBuffer().isEnabled(logLevel)) return;

char buffer[2048];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args); /// @todo unsafe
va_end(args);

logFragmentPrinter(logLevel, buffer);
}

Info *Info_NewFromString(char const *utf8text)
{
try
Expand Down
16 changes: 12 additions & 4 deletions doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -347,13 +347,21 @@ void App::initSubsystems(SubsystemInitFlags flags)

try
{
// Set the log output file.
logBuf.setOutputFile(d->config->gets("log.file"));
// The -out option can be used to override the configured output file.
int pos = 0;
if((pos = commandLine().check("-out", 1)) > 0)
{
logBuf.setOutputFile(String("/home") / commandLine().at(pos + 1));
}
else
{
// Set the log output file.
logBuf.setOutputFile(d->config->gets("log.file"));
}
}
catch(Error const &er)
{
LOG_WARNING("Failed to use \"" + d->config->gets("log.file") +
"\" as the log output file:\n" + er.asText());
LOG_WARNING("Failed to set log output file:\n" + er.asText());
}

// The level of enabled messages.
Expand Down

0 comments on commit d89025f

Please sign in to comment.