1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2011/08/31
|
---|
6 | // filename: FrameworkManager.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Main class of the Framework library
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "FrameworkManager.h"
|
---|
19 | #include "FrameworkManager_impl.h"
|
---|
20 | #include "IODevice.h"
|
---|
21 | #include "config.h"
|
---|
22 | #include "compile_info.h"
|
---|
23 |
|
---|
24 | using std::string;
|
---|
25 | using std::vector;
|
---|
26 | using namespace flair::gui;
|
---|
27 |
|
---|
28 | namespace {
|
---|
29 | flair::core::FrameworkManager *frameworkmanager = NULL;
|
---|
30 | }
|
---|
31 |
|
---|
32 | static void constructor() __attribute__((constructor));
|
---|
33 |
|
---|
34 | void constructor() {
|
---|
35 | compile_info("FlairCore");
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | namespace flair {
|
---|
40 | namespace core {
|
---|
41 |
|
---|
42 | FrameworkManager *getFrameworkManager(void) { return frameworkmanager; }
|
---|
43 |
|
---|
44 | bool IsBigEndian(void) {
|
---|
45 | union {
|
---|
46 | uint32_t i;
|
---|
47 | char c[4];
|
---|
48 | } bint = {0x01020304};
|
---|
49 |
|
---|
50 | if (bint.c[0] == 1) {
|
---|
51 | return true;
|
---|
52 | } else {
|
---|
53 | return false;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | FrameworkManager::FrameworkManager(string name)
|
---|
58 | : Object(NULL, name, XML_ROOT_TYPE) {
|
---|
59 | if (frameworkmanager != NULL) {
|
---|
60 | Err("FrameworkManager should be instanced only one time\n");
|
---|
61 | return;
|
---|
62 | }
|
---|
63 |
|
---|
64 | frameworkmanager = this;
|
---|
65 | pimpl_ = new FrameworkManager_impl(this, name);
|
---|
66 | }
|
---|
67 |
|
---|
68 | FrameworkManager::~FrameworkManager() {
|
---|
69 | // Printf("destruction FrameworkManager\n");
|
---|
70 |
|
---|
71 | // stop ui_com thread (which sends datas for graphs), we do not need it as
|
---|
72 | // graphs will be destroyed
|
---|
73 | if (getUiCom() != NULL) {
|
---|
74 | getUiCom()->SafeStop();
|
---|
75 | getUiCom()->Join();
|
---|
76 | }
|
---|
77 | /*
|
---|
78 | //stop and delete each thread has been changed to stop all thread, then delete all threads
|
---|
79 | //seems ok but needs more testing
|
---|
80 | *
|
---|
81 | // we start by deleting threads (except pimpl which must be deleted at last)
|
---|
82 | // (before deleting objects that could be used by the threads)
|
---|
83 | // Printf("delete Threads\n");
|
---|
84 | for (vector<const Object *>::iterator it = Childs()->begin();
|
---|
85 | it < Childs()->end(); it++) {
|
---|
86 | //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
|
---|
87 | if ((*it)->ObjectType() == "Thread") {
|
---|
88 | if (*it != pimpl_) {
|
---|
89 | // Printf("del\n");
|
---|
90 | ((Thread *)(*it))->SafeStop();
|
---|
91 | ((Thread *)(*it))->Join();
|
---|
92 | delete (Thread *)(*it);
|
---|
93 | // Childs() vector has been modified, we start from beginning again
|
---|
94 | // it will be incremented by the loop, so in fact we start again at
|
---|
95 | // begin()+1
|
---|
96 | // it is not a problem since begin is pimpl
|
---|
97 | it = Childs()->begin();
|
---|
98 | // Printf("del ok\n");
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 | */
|
---|
103 | // we start by stopping threads (except pimpl which must be deleted at last)
|
---|
104 | // (before deleting objects that could be used by the threads)
|
---|
105 | //Printf("stop Threads\n");
|
---|
106 | for (vector<const Object *>::iterator it = Childs()->begin();it < Childs()->end(); it++) {
|
---|
107 | //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
|
---|
108 | if ((*it)->ObjectType() == "Thread") {
|
---|
109 | if (*it != pimpl_) {
|
---|
110 | //Printf("stop\n");
|
---|
111 | ((Thread *)(*it))->SafeStop();
|
---|
112 | ((Thread *)(*it))->Join();
|
---|
113 | //Printf("stop ok\n");
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|
117 | //then delete threads
|
---|
118 | //Printf("del Threads\n");
|
---|
119 | for (vector<const Object *>::iterator it = Childs()->begin();it < Childs()->end(); it++) {
|
---|
120 | //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
|
---|
121 | if ((*it)->ObjectType() == "Thread") {
|
---|
122 | if (*it != pimpl_) {
|
---|
123 | // Printf("del\n");
|
---|
124 | delete (Thread *)(*it);
|
---|
125 | // Childs() vector has been modified, we start from beginning again
|
---|
126 | // it will be incremented by the loop, so in fact we start again at
|
---|
127 | // begin()+1
|
---|
128 | // it is not a problem since begin is pimpl
|
---|
129 | it = Childs()->begin();
|
---|
130 | //Printf("del ok\n");
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | // next we delete IODevice
|
---|
136 | // (before deleting objects that could be used by the IODevice)
|
---|
137 | // Printf("delete IODevices\n");
|
---|
138 | for (vector<const Object *>::iterator it = Childs()->begin();
|
---|
139 | it < Childs()->end(); it++) {
|
---|
140 | //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
|
---|
141 | if ((*it)->ObjectType() == "IODevice") {
|
---|
142 | // Printf("del\n");
|
---|
143 | delete (IODevice *)*it;
|
---|
144 | // Printf("del ok\n");
|
---|
145 | // Childs() vector has been modified, we start from beginning again
|
---|
146 | // it will be incremented by the loop, so in fact we start again at
|
---|
147 | // begin()+1
|
---|
148 | // it is not a problem since begin is pimpl (not an IODevice)
|
---|
149 | it = Childs()->begin();
|
---|
150 | // Printf("del ok\n");
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | // Printf("delete childs\n");
|
---|
155 | // on efface les enfants en commencant par la fin
|
---|
156 | // le ui_com puis FrameworkManager_impl est détruit en dernier
|
---|
157 | // permet de garder l'uicom pour notifer des destructions
|
---|
158 | while (Childs()->size() != 0) {
|
---|
159 | //Printf("child %i %s %s\n",Childs()->size(),Childs()->back()->ObjectName().c_str(),Childs()->back()->ObjectType().c_str());
|
---|
160 | if (Childs()->back() != NULL)
|
---|
161 | delete Childs()->back();
|
---|
162 | }
|
---|
163 |
|
---|
164 | // childs.clear();
|
---|
165 |
|
---|
166 | // Printf("destruction FrameworkManager ok\n");
|
---|
167 | }
|
---|
168 |
|
---|
169 | void FrameworkManager::SetupConnection(string address, uint16_t port,Time watchdogTimeout,
|
---|
170 | size_t rcv_buf_size) {
|
---|
171 | pimpl_->SetupConnection(address, port, watchdogTimeout,rcv_buf_size);
|
---|
172 | }
|
---|
173 |
|
---|
174 | void FrameworkManager::SetupUserInterface(string xml_file) {
|
---|
175 | pimpl_->SetupUserInterface(xml_file);
|
---|
176 | }
|
---|
177 |
|
---|
178 | gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
|
---|
179 | if(pimpl_->tabwidget==NULL) Err("SetupUserInterface must be called before\n");
|
---|
180 | return pimpl_->tabwidget;
|
---|
181 | }
|
---|
182 |
|
---|
183 | void FrameworkManager::UpdateSendData(const SendData *obj) {
|
---|
184 | if (getUiCom() != NULL)
|
---|
185 | getUiCom()->UpdateSendData(obj);
|
---|
186 | }
|
---|
187 |
|
---|
188 | void FrameworkManager::BlockCom(void) {
|
---|
189 | if (getUiCom() != NULL)
|
---|
190 | getUiCom()->Block();
|
---|
191 | }
|
---|
192 |
|
---|
193 | void FrameworkManager::UnBlockCom(void) {
|
---|
194 | if (getUiCom() != NULL)
|
---|
195 | getUiCom()->UnBlock();
|
---|
196 | }
|
---|
197 |
|
---|
198 | bool FrameworkManager::ConnectionLost(void) const {
|
---|
199 | if (getUiCom() != NULL) {
|
---|
200 | return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
|
---|
201 | } else {
|
---|
202 | return false;
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | void FrameworkManager::SetupLogger(string log_path,uint32_t stackSize) {
|
---|
207 | pimpl_->SetupLogger(log_path,stackSize);
|
---|
208 | }
|
---|
209 |
|
---|
210 | string FrameworkManager::GetLogPath(void) const {
|
---|
211 | return pimpl_->log_path;
|
---|
212 | }
|
---|
213 | void FrameworkManager::AddDeviceToLog(IODevice *device) {
|
---|
214 | pimpl_->AddDeviceToLog(device);
|
---|
215 | }
|
---|
216 |
|
---|
217 | bool FrameworkManager::IsDeviceLogged(const IODevice *device) const {
|
---|
218 | return pimpl_->IsDeviceLogged(device);
|
---|
219 | }
|
---|
220 |
|
---|
221 | void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
|
---|
222 |
|
---|
223 | void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
|
---|
224 |
|
---|
225 | bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
|
---|
226 |
|
---|
227 | void FrameworkManager::DisableErrorsDisplay(bool value) {
|
---|
228 | pimpl_->disable_errors = value;
|
---|
229 | }
|
---|
230 |
|
---|
231 | bool FrameworkManager::IsDisplayingErrors(void) const {
|
---|
232 | return !(pimpl_->disable_errors);
|
---|
233 | }
|
---|
234 |
|
---|
235 | } // end namespace core
|
---|
236 | } // end namespace flair
|
---|