Rev 1600 | Rev 1602 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1600 | Rev 1601 | ||
|---|---|---|---|
| Line 32... | Line 32... | ||
| 32 | #include "can/Protocol.h" |
32 | #include "can/Protocol.h" |
| 33 | #include "broker/Manager.h" |
33 | #include "broker/Manager.h" |
| 34 | #include "can/Manager.h" |
34 | #include "can/Manager.h" |
| 35 | #include "can/Network.h" |
35 | #include "can/Network.h" |
| 36 | #include "can/Monitor.h" |
36 | #include "can/Monitor.h" |
| - | 37 | #include "vm/Manager.h" |
|
| 37 | 38 | ||
| - | 39 | #include "vm/plugin/System.h" |
|
| - | 40 | #include "vm/plugin/Timer.h" |
|
| - | 41 | ||
| 38 | using namespace atom; |
42 | using namespace atom; |
| 39 | 43 | ||
| 40 | logging::Logger LOG("Main"); |
44 | logging::Logger LOG("Main"); |
| 41 | std::vector<broker::Subscriber::Pointer> subscribers; |
45 | std::vector<broker::Subscriber::Pointer> subscribers; |
| 42 | boost::condition on_message_condition; |
46 | boost::condition on_message_condition; |
| 43 | boost::mutex guard_mutex; |
47 | boost::mutex guard_mutex; |
| 44 | 48 | ||
| 45 | void Handler(int status); |
49 | void Handler(int status); |
| 46 | void CleanUp(); |
50 | void CleanUp(); |
| 47 | 51 | ||
| 48 | int main(int argc, char **argv) |
52 | int main(int argc, char **argv) |
| 49 | { |
53 | { |
| 50 | LOG.Info("Atom version 1.5.0 starting..."); |
54 | LOG.Info("Atom version 1.5.0 starting..."); |
| 51 | LOG.Info("Written by Mattias Runge 2010."); |
55 | LOG.Info("Written by Mattias Runge 2010."); |
| 52 | LOG.Info("Released under GPL version 2."); |
56 | LOG.Info("Released under GPL version 2."); |
| Line 61... | Line 65... | ||
| 61 | 65 | ||
| 62 | if (!config::Manager::Instance()->Set(argc, argv)) |
66 | if (!config::Manager::Instance()->Set(argc, argv)) |
| 63 | { |
67 | { |
| 64 | CleanUp(); |
68 | CleanUp(); |
| 65 | return EXIT_SUCCESS; |
69 | return EXIT_SUCCESS; |
| 66 | } |
70 | } |
| 67 | 71 | ||
| 68 | if (config::Manager::Instance()->Exist("LogFile")) |
72 | if (config::Manager::Instance()->Exist("LogFile")) |
| 69 | { |
73 | { |
| 70 | logging::Logger::OpenFile(config::Manager::Instance()->GetAsString("LogFile")); |
74 | logging::Logger::OpenFile(config::Manager::Instance()->GetAsString("LogFile")); |
| 71 | } |
75 | } |
| 72 | 76 | ||
| 73 | if (config::Manager::Instance()->Exist("LogLevel")) |
77 | if (config::Manager::Instance()->Exist("LogLevel")) |
| 74 | { |
78 | { |
| 75 | logging::Logger::SetLevel((logging::Logger::Level)config::Manager::Instance()->GetAsInt("LogLevel")); |
79 | logging::Logger::SetLevel((logging::Logger::Level)config::Manager::Instance()->GetAsInt("LogLevel")); |
| 76 | } |
80 | } |
| 77 | 81 | ||
| 78 | if (config::Manager::Instance()->Exist("daemon")) |
82 | if (config::Manager::Instance()->Exist("daemon")) |
| 79 | { |
83 | { |
| 80 | LOG.Info("Entering daemon mode..."); |
84 | LOG.Info("Entering daemon mode..."); |
| 81 | 85 | ||
| 82 | if (daemon(0, 0) == -1) |
86 | if (daemon(0, 0) == -1) |
| 83 | { |
87 | { |
| 84 | LOG.Error("Could not enter daemon mode. Exiting..."); |
88 | LOG.Error("Could not enter daemon mode. Exiting..."); |
| 85 | CleanUp(); |
89 | CleanUp(); |
| 86 | return EXIT_FAILURE; |
90 | return EXIT_FAILURE; |
| 87 | } |
91 | } |
| 88 | 92 | ||
| 89 | LOG.Info("Deamon mode entered successfully!"); |
93 | LOG.Info("Deamon mode entered successfully!"); |
| 90 | } |
94 | } |
| 91 | 95 | ||
| 92 | timer::Manager::Create(); |
96 | timer::Manager::Create(); |
| 93 | broker::Manager::Create(); |
97 | broker::Manager::Create(); |
| 94 | net::Manager::Create(); |
98 | net::Manager::Create(); |
| 95 | can::Protocol::Create(); |
99 | can::Protocol::Create(); |
| 96 | can::Manager::Create(); |
100 | can::Manager::Create(); |
| - | 101 | vm::Manager::Create(); |
|
| 97 | 102 | ||
| 98 | if (config::Manager::Instance()->Exist("ProtocolFile")) |
103 | if (config::Manager::Instance()->Exist("ProtocolFile")) |
| 99 | { |
104 | { |
| 100 | can::Protocol::Instance()->Load(config::Manager::Instance()->GetAsString("ProtocolFile")); |
105 | can::Protocol::Instance()->Load(config::Manager::Instance()->GetAsString("ProtocolFile")); |
| 101 | } |
106 | } |
| 102 | 107 | ||
| 103 | if (config::Manager::Instance()->Exist("MonitorPort")) |
108 | if (config::Manager::Instance()->Exist("MonitorPort")) |
| 104 | { |
109 | { |
| 105 | subscribers.push_back(can::Monitor::Pointer(new can::Monitor(config::Manager::Instance()->GetAsInt("MonitorPort")))); |
110 | subscribers.push_back(can::Monitor::Pointer(new can::Monitor(config::Manager::Instance()->GetAsInt("MonitorPort")))); |
| 106 | } |
111 | } |
| 107 | 112 | ||
| 108 | subscribers.push_back(can::Manager::Instance()); |
113 | subscribers.push_back(can::Manager::Instance()); |
| 109 | 114 | ||
| 110 | if (config::Manager::Instance()->Exist("CanNet")) |
115 | if (config::Manager::Instance()->Exist("CanNet")) |
| 111 | { |
116 | { |
| 112 | type::StringList cannetworks = config::Manager::Instance()->GetAsStringVector("CanNet"); |
117 | type::StringList cannetworks = config::Manager::Instance()->GetAsStringVector("CanNet"); |
| 113 | 118 | ||
| 114 | for (int n = 0; n < cannetworks.size(); n++) |
119 | for (int n = 0; n < cannetworks.size(); n++) |
| 115 | { |
120 | { |
| 116 | subscribers.push_back(can::Network::Pointer(new can::Network(cannetworks[n]))); |
121 | subscribers.push_back(can::Network::Pointer(new can::Network(cannetworks[n]))); |
| 117 | } |
122 | } |
| - | 123 | } |
|
| - | 124 | ||
| - | 125 | vm::Manager::Instance()->AddPlugin(vm::Plugin::Pointer(new vm::plugin::System())); |
|
| - | 126 | vm::Manager::Instance()->AddPlugin(vm::Plugin::Pointer(new vm::plugin::Timer())); |
|
| - | 127 | ||
| - | 128 | if (config::Manager::Instance()->Exist("ScriptPath")) |
|
| - | 129 | { |
|
| - | 130 | vm::Manager::Instance()->Start(config::Manager::Instance()->GetAsString("ScriptPath")); |
|
| 118 | } |
131 | } |
| 119 | 132 | ||
| 120 | LOG.Info("Initialization complete."); |
133 | LOG.Info("Initialization complete."); |
| 121 | 134 | ||
| 122 | boost::mutex::scoped_lock guard(guard_mutex); |
135 | boost::mutex::scoped_lock guard(guard_mutex); |
| Line 132... | Line 145... | ||
| 132 | } |
145 | } |
| 133 | 146 | ||
| 134 | void CleanUp() |
147 | void CleanUp() |
| 135 | { |
148 | { |
| 136 | subscribers.clear(); |
149 | subscribers.clear(); |
| - | 150 | vm::Manager::Delete(); |
|
| 137 | config::Manager::Delete(); |
151 | config::Manager::Delete(); |
| 138 | timer::Manager::Delete(); |
152 | timer::Manager::Delete(); |
| 139 | can::Manager::Delete(); |
153 | can::Manager::Delete(); |
| 140 | can::Protocol::Delete(); |
154 | can::Protocol::Delete(); |
| 141 | broker::Manager::Delete(); |
155 | broker::Manager::Delete(); |