~renatofilho/buteo-syncfw/more-verbose

« back to all changes in this revision

Viewing changes to msyncd/main.cpp

  • Committer: Sergey Gerasimenko
  • Date: 2010-06-29 12:51:21 UTC
  • Revision ID: git-v1:cd8dab07b102ac96752ece4f3cde5fc62697d717
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of buteo-syncfw package
 
3
 *
 
4
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
5
 *
 
6
 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
 
7
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 * 02110-1301 USA
 
21
 *
 
22
 */
 
23
 
 
24
 
 
25
 
 
26
#include <QCoreApplication>
 
27
#include <QtDebug>
 
28
#include <QDateTime>
 
29
 
 
30
#include <signal.h>
 
31
#include <dbus/dbus.h>
 
32
 
 
33
#include "LogMacros.h"
 
34
#include "Logger.h"
 
35
#include "synchronizer.h"
 
36
 
 
37
const QString LOGGER_CONFIG_FILE( "/etc/sync/set_sync_log_level" );
 
38
const QString SYNC_LOG_FILE_PATH( "/home/user/.sync/synchronizer.log" );
 
39
 
 
40
// Linux signal handler. This application is shutdown by sending a
 
41
// SIGTERM to it
 
42
void signalHandler(int /*signal*/)
 
43
{
 
44
    QCoreApplication::exit(0);
 
45
}
 
46
 
 
47
void setLogLevelFromFile(Buteo::Logger *aLogger)
 
48
{
 
49
    if(QFile::exists(LOGGER_CONFIG_FILE)) {
 
50
        // read the config level from the file and set
 
51
        // that level
 
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" ;
 
58
                }
 
59
                file.close();
 
60
        }
 
61
    }
 
62
}
 
63
 
 
64
int main( int argc, char* argv[] )
 
65
{
 
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
 
69
 
 
70
    QCoreApplication app(argc, argv);
 
71
 
 
72
    Buteo::Logger::createInstance(SYNC_LOG_FILE_PATH);
 
73
    Buteo::Logger *logger = Buteo::Logger::instance();
 
74
    if (logger) {
 
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;
 
79
    }
 
80
 
 
81
    LOG_DEBUG("Starting Log At :"  << QDateTime::currentDateTime()  );
 
82
 
 
83
    Buteo::Synchronizer *synchronizer = new Buteo::Synchronizer(&app);
 
84
    if (synchronizer == 0) {
 
85
        LOG_FATAL("Failed to create synchronizer");
 
86
    }
 
87
 
 
88
    if(!synchronizer->initialize() ) {
 
89
        delete synchronizer;
 
90
        synchronizer = 0;
 
91
        return -1;
 
92
    }
 
93
 
 
94
    signal(SIGTERM, signalHandler);
 
95
    signal(SIGINT, signalHandler);
 
96
 
 
97
    LOG_DEBUG("Entering event loop");
 
98
    int returnValue = app.exec();
 
99
    LOG_DEBUG("Exiting event loop");
 
100
 
 
101
    synchronizer->close();
 
102
    delete synchronizer;
 
103
    synchronizer = 0;
 
104
 
 
105
    LOG_DEBUG("Stopping logger");
 
106
 
 
107
    Buteo::Logger::deleteInstance();
 
108
 
 
109
    qDebug() << "Exiting program";
 
110
 
 
111
    return returnValue;
 
112
}