Subversion Repositories HomeAutomation

Rev

Rev 999 | Rev 1026 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 999 Rev 1024
Line 25... Line 25...
25
#include <iostream>
25
#include <iostream>
26
#include <signal.h>
26
#include <signal.h>
27
 
27
 
28
#include "version.h"
28
#include "version.h"
29
#include "Tools/tools.h"
29
#include "Tools/tools.h"
30
#include "SyslogStream/syslogstream.h"
30
#include "Logger/logger.h"
31
#include "Settings/settings.h"
31
#include "Settings/settings.h"
32
#include "Socket/server.h"
32
#include "Socket/server.h"
33
#include "CanNet/cannetmanager.h"
33
#include "CanNet/cannetmanager.h"
34
#include "Socket/asyncsocket.h"
34
#include "Socket/asyncsocket.h"
35
#include "VM/virtualmachine.h"
35
#include "VM/virtualmachine.h"
Line 44... Line 44...
44
    signal(SIGINT, handler);
44
    signal(SIGINT, handler);
45
    signal(SIGQUIT, handler);
45
    signal(SIGQUIT, handler);
46
    signal(SIGABRT, handler);
46
    signal(SIGABRT, handler);
47
    signal(SIGPIPE, handler);
47
    signal(SIGPIPE, handler);
48
 
48
 
49
    SyslogStream &slog = SyslogStream::getInstance();
49
    Logger &log = Logger::getInstance();
50
 
50
 
51
    slog << "Atom " + ftos(VERSION) + " starting...\n";
51
    log.addToSyslog("Atom " + ftos(VERSION) + " starting...\n");
52
    slog << "Written by Mattias Runge 2008-2009\n\n";
52
    log.add("Written by Mattias Runge 2008-2009\n\n");
53
 
53
 
54
    if (file_exists("/etc/atom.conf"))
54
    if (file_exists("/etc/atom.conf"))
55
    {
55
    {
56
        if (!Settings::read("/etc/atom.conf"))
56
        if (!Settings::read("/etc/atom.conf"))
57
        {
57
        {
Line 62... Line 62...
62
    {
62
    {
63
        if (!Settings::read("atom.conf"))
63
        if (!Settings::read("atom.conf"))
64
        {
64
        {
65
            return cleanUp();
65
            return cleanUp();
66
        }
66
        }
-
 
67
    }
-
 
68
 
-
 
69
    string logfile = Settings::get("Logfile");
-
 
70
    if (logfile != "")
-
 
71
    {
-
 
72
        if (!log.open(logfile))
-
 
73
        {
-
 
74
            log.addToSyslog("Could not open logfile, " + logfile + "\n");
-
 
75
        }
-
 
76
        else
-
 
77
        {
-
 
78
            log.add("Logging to " + logfile + "\n");
-
 
79
        }
-
 
80
    }
-
 
81
    else
-
 
82
    {
-
 
83
        log.add("Logfile is not defined, logging will be done to syslog and console only\n");
67
    }
84
    }
68
 
85
 
69
    VirtualMachine &vm = VirtualMachine::getInstance();
86
    VirtualMachine &vm = VirtualMachine::getInstance();
70
    vm.start();
87
    vm.start();
71
 
88
 
Line 76... Line 93...
76
        canDebug.setSettings(stoi(canDebugPort), "CanDebug");
93
        canDebug.setSettings(stoi(canDebugPort), "CanDebug");
77
        canDebug.start();
94
        canDebug.start();
78
    }
95
    }
79
    else
96
    else
80
    {
97
    {
81
        slog << "CanDebugPort is not defined, can not start CanDebug socket\n";
98
        log.add("CanDebugPort is not defined, can not start CanDebug socket\n");
82
    }
99
    }
83
 
100
 
84
    CanNetManager &canMan = CanNetManager::getInstance();
101
    CanNetManager &canMan = CanNetManager::getInstance();
85
    canMan.start();
102
    canMan.start();
86
 
103
 
87
    if (Settings::get("DaemonMode") == "yes")
104
    if (Settings::get("DaemonMode") == "yes")
88
    {
105
    {
89
        slog << "Entering daemon mode...\n";
106
        log.add("Entering daemon mode...\n");
90
        if (daemon(0, 0) == -1)
107
        if (daemon(0, 0) == -1)
91
        {
108
        {
92
            slog << "Could not enter daemon mode. Exiting...\n";
109
            log.addToSyslog("Could not enter daemon mode. Exiting...\n");
93
            return cleanUp();
110
            return cleanUp();
94
        }
111
        }
95
    }
112
    }
96
 
113
 
97
    vm.join();
114
    vm.join();
Line 99... Line 116...
99
    return cleanUp();
116
    return cleanUp();
100
}
117
}
101
 
118
 
102
int cleanUp()
119
int cleanUp()
103
{
120
{
104
    SyslogStream &slog = SyslogStream::getInstance();
121
    Logger &log = Logger::getInstance();
105
 
122
 
106
    slog << "\n";
123
    log.add("\n");
107
    slog << "Goodbye!\n";
124
    log.addToSyslog("Thank you for using Atom. Goodbye!\n");
108
 
125
 
109
    CanDebug::deleteInstance();
126
    CanDebug::deleteInstance();
110
    VirtualMachine::deleteInstance();
127
    VirtualMachine::deleteInstance();
111
    CanNetManager::deleteInstance();
128
    CanNetManager::deleteInstance();
112
    SyslogStream::deleteInstance();
129
    Logger::deleteInstance();
113
 
130
 
114
    return EXIT_SUCCESS;
131
    return EXIT_SUCCESS;
115
}
132
}
116
 
133
 
117
void handler(int status)
134
void handler(int status)