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 | // we start by deleting threads (except pimpl which must be deleted at last)
|
---|
79 | // (before deleting objects that could be used by the threads)
|
---|
80 | // Printf("delete Threads\n");
|
---|
81 | for (vector<const Object *>::iterator it = Childs()->begin();
|
---|
82 | it < Childs()->end(); it++) {
|
---|
83 | //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
|
---|
84 | if ((*it)->ObjectType() == "Thread") {
|
---|
85 | if (*it != pimpl_) {
|
---|
86 | // Printf("del\n");
|
---|
87 | ((Thread *)(*it))->SafeStop();
|
---|
88 | ((Thread *)(*it))->Join();
|
---|
89 | delete (Thread *)(*it);
|
---|
90 | // Childs() vector has been modified, we start from beginning again
|
---|
91 | // it will be incremented by the loop, so in fact we start again at
|
---|
92 | // begin()+1
|
---|
93 | // it is not a problem since begin is pimpl
|
---|
94 | it = Childs()->begin();
|
---|
95 | // Printf("del ok\n");
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | // next we delete IODevice
|
---|
101 | // (before deleting objects that could be used by the IODevice)
|
---|
102 | // Printf("delete IODevices\n");
|
---|
103 | for (vector<const Object *>::iterator it = Childs()->begin();
|
---|
104 | it < Childs()->end(); it++) {
|
---|
105 | //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
|
---|
106 | if ((*it)->ObjectType() == "IODevice") {
|
---|
107 | // Printf("del\n");
|
---|
108 | delete (IODevice *)*it;
|
---|
109 | // Printf("del ok\n");
|
---|
110 | // Childs() vector has been modified, we start from beginning again
|
---|
111 | // it will be incremented by the loop, so in fact we start again at
|
---|
112 | // begin()+1
|
---|
113 | // it is not a problem since begin is pimpl (not an IODevice)
|
---|
114 | it = Childs()->begin();
|
---|
115 | // Printf("del ok\n");
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | // Printf("delete childs\n");
|
---|
120 | // on efface les enfants en commencant par la fin
|
---|
121 | // le ui_com puis FrameworkManager_impl est détruit en dernier
|
---|
122 | // permet de garder l'uicom pour notifer des destructions
|
---|
123 | while (Childs()->size() != 0) {
|
---|
124 | //Printf("child %i %s %s\n",Childs()->size(),Childs()->back()->ObjectName().c_str(),Childs()->back()->ObjectType().c_str());
|
---|
125 | if (Childs()->back() != NULL)
|
---|
126 | delete Childs()->back();
|
---|
127 | }
|
---|
128 |
|
---|
129 | // childs.clear();
|
---|
130 |
|
---|
131 | // Printf("destruction FrameworkManager ok\n");
|
---|
132 | }
|
---|
133 |
|
---|
134 | void FrameworkManager::SetupConnection(string address, uint16_t port,Time watchdogTimeout,
|
---|
135 | size_t rcv_buf_size) {
|
---|
136 | pimpl_->SetupConnection(address, port, watchdogTimeout,rcv_buf_size);
|
---|
137 | }
|
---|
138 |
|
---|
139 | void FrameworkManager::SetupUserInterface(string xml_file) {
|
---|
140 | pimpl_->SetupUserInterface(xml_file);
|
---|
141 | }
|
---|
142 |
|
---|
143 | gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
|
---|
144 | if(pimpl_->tabwidget==NULL) Err("SetupUserInterface must be called before\n");
|
---|
145 | return pimpl_->tabwidget;
|
---|
146 | }
|
---|
147 |
|
---|
148 | void FrameworkManager::UpdateSendData(const SendData *obj) {
|
---|
149 | if (getUiCom() != NULL)
|
---|
150 | getUiCom()->UpdateSendData(obj);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void FrameworkManager::BlockCom(void) {
|
---|
154 | if (getUiCom() != NULL)
|
---|
155 | getUiCom()->Block();
|
---|
156 | }
|
---|
157 |
|
---|
158 | void FrameworkManager::UnBlockCom(void) {
|
---|
159 | if (getUiCom() != NULL)
|
---|
160 | getUiCom()->UnBlock();
|
---|
161 | }
|
---|
162 |
|
---|
163 | bool FrameworkManager::ConnectionLost(void) const {
|
---|
164 | if (getUiCom() != NULL) {
|
---|
165 | return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
|
---|
166 | } else {
|
---|
167 | return false;
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | void FrameworkManager::SetupLogger(string log_path,uint32_t stackSize) {
|
---|
172 | pimpl_->SetupLogger(log_path,stackSize);
|
---|
173 | }
|
---|
174 |
|
---|
175 | string FrameworkManager::GetLogPath(void) const {
|
---|
176 | return pimpl_->log_path;
|
---|
177 | }
|
---|
178 | void FrameworkManager::AddDeviceToLog(IODevice *device) {
|
---|
179 | pimpl_->AddDeviceToLog(device);
|
---|
180 | }
|
---|
181 |
|
---|
182 | bool FrameworkManager::IsDeviceLogged(const IODevice *device) const {
|
---|
183 | return pimpl_->IsDeviceLogged(device);
|
---|
184 | }
|
---|
185 |
|
---|
186 | void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
|
---|
187 |
|
---|
188 | void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
|
---|
189 |
|
---|
190 | bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
|
---|
191 |
|
---|
192 | void FrameworkManager::DisableErrorsDisplay(bool value) {
|
---|
193 | pimpl_->disable_errors = value;
|
---|
194 | }
|
---|
195 |
|
---|
196 | bool FrameworkManager::IsDisplayingErrors(void) const {
|
---|
197 | return !(pimpl_->disable_errors);
|
---|
198 | }
|
---|
199 |
|
---|
200 | } // end namespace core
|
---|
201 | } // end namespace flair
|
---|