#ifndef FMSERVICE_H
#define FMSERVICE_H

#include "qtservice.h"
#include "fmdefine.h"
#include "fmcontrol.h"
#include "QsLog.h"

#include "dump.h"

using namespace QsLogging;

class FmService : public QtService<QCoreApplication>
{
public:
    FmService(int argc, char **argv)
        :QtService<QCoreApplication>(argc, argv, SERVICE_NAME)
    {

        setServiceDescription(QString::fromLocal8Bit(SERVICE_DESC));
        setStartupType(QtServiceController::AutoStartup);
        SetUnhandledExceptionFilter(FMExcpHandler);
    }

protected:
    void start()
    {
        // 初始化日志
        QString logDir = QString("%1/log").arg(QCoreApplication::applicationDirPath());
        QDir().mkdir(logDir);
        Logger& logger = Logger::instance();
        logger.setLoggingLevel(TraceLevel);
        QString logPath = QString("%1/%2").arg(logDir, "log.txt");
        DestinationPtr fileDst(DestinationFactory::MakeFileDestination(
        logPath, EnableLogRotation, MaxSizeBytes(2*1024*1024), MaxOldLogCount(50)));
        logger.addDestination(fileDst);

        m_control.Start();
    }

private:
    FmControl m_control;
};

#endif // FMSERVICE_H
