2
* This file is part of buteo-syncfw package
4
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* version 2.1 as published by the Free Software Foundation.
12
* This library is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26
#include <QCoreApplication>
31
#include <dbus/dbus.h>
33
#include "LogMacros.h"
35
#include "synchronizer.h"
37
const QString LOGGER_CONFIG_FILE( "/etc/sync/set_sync_log_level" );
38
const QString SYNC_LOG_FILE_PATH( "/home/user/.sync/synchronizer.log" );
40
// Linux signal handler. This application is shutdown by sending a
42
void signalHandler(int /*signal*/)
44
QCoreApplication::exit(0);
47
void setLogLevelFromFile(Buteo::Logger *aLogger)
49
if(QFile::exists(LOGGER_CONFIG_FILE)) {
50
// read the config level from the file and set
52
QFile file(LOGGER_CONFIG_FILE);
53
if(file.open(QIODevice::ReadOnly)) {
54
int level = file.readLine().simplified().toInt();
55
qDebug() << "Setting Log Level to " << level;
56
if(!aLogger->setLogLevel(level)) {
57
qDebug() << "Invalid Log Level Read from the file" ;
64
int main( int argc, char* argv[] )
66
// remove this later on if not needed in harmattan,
67
// this IS needed for fremantle
68
dbus_threads_init_default(); // magical line making program not crash
70
QCoreApplication app(argc, argv);
72
Buteo::Logger::createInstance(SYNC_LOG_FILE_PATH);
73
Buteo::Logger *logger = Buteo::Logger::instance();
75
setLogLevelFromFile(logger);
76
qDebug() << "Current log level is " <<
77
(logger->getLogLevelArray().count(true) - 1);
78
qDebug() << "Logs will be logged to " << SYNC_LOG_FILE_PATH;
81
LOG_DEBUG("Starting Log At :" << QDateTime::currentDateTime() );
83
Buteo::Synchronizer *synchronizer = new Buteo::Synchronizer(&app);
84
if (synchronizer == 0) {
85
LOG_FATAL("Failed to create synchronizer");
88
if(!synchronizer->initialize() ) {
94
signal(SIGTERM, signalHandler);
95
signal(SIGINT, signalHandler);
97
LOG_DEBUG("Entering event loop");
98
int returnValue = app.exec();
99
LOG_DEBUG("Exiting event loop");
101
synchronizer->close();
105
LOG_DEBUG("Stopping logger");
107
Buteo::Logger::deleteInstance();
109
qDebug() << "Exiting program";