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 |
---|
84 | // %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str()); |
---|
85 | if ((*it)->ObjectType() == "Thread") { |
---|
86 | if (*it != pimpl_) { |
---|
87 | // Printf("del\n"); |
---|
88 | delete (Thread *)(*it); |
---|
89 | // Childs() vector has been modified, we start from beginning again |
---|
90 | // it will be incremented by the loop, so in fact we start again at |
---|
91 | // begin()+1 |
---|
92 | // it is not a problem since begin is pimpl |
---|
93 | it = Childs()->begin(); |
---|
94 | // Printf("del ok\n"); |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | // next we delete IODevice |
---|
100 | // (before deleting objects that could be used by the IODevice) |
---|
101 | // Printf("delete IODevices\n"); |
---|
102 | for (vector<const Object *>::iterator it = Childs()->begin(); |
---|
103 | it < Childs()->end(); it++) { |
---|
104 | // Printf("child %i %s |
---|
105 | // %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 |
---|
125 | // %s\n",Childs()->size(),Childs()->back()->ObjectName().c_str(),Childs()->back()->ObjectType().c_str()); |
---|
126 | if (Childs()->back() != NULL) |
---|
127 | delete Childs()->back(); |
---|
128 | } |
---|
129 | |
---|
130 | // childs.clear(); |
---|
131 | |
---|
132 | // Printf("destruction FrameworkManager ok\n"); |
---|
133 | } |
---|
134 | |
---|
135 | void FrameworkManager::SetupConnection(string address, uint16_t port, |
---|
136 | size_t rcv_buf_size) { |
---|
137 | pimpl_->SetupConnection(address, port, rcv_buf_size); |
---|
138 | } |
---|
139 | |
---|
140 | void FrameworkManager::SetupUserInterface(string xml_file) { |
---|
141 | pimpl_->SetupUserInterface(xml_file); |
---|
142 | } |
---|
143 | |
---|
144 | gui::TabWidget *FrameworkManager::GetTabWidget(void) const { |
---|
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) { |
---|
172 | pimpl_->SetupLogger(log_path); |
---|
173 | } |
---|
174 | |
---|
175 | void FrameworkManager::AddDeviceToLog(IODevice *device) { |
---|
176 | pimpl_->AddDeviceToLog(device); |
---|
177 | } |
---|
178 | |
---|
179 | void FrameworkManager::StartLog(void) { pimpl_->StartLog(); } |
---|
180 | |
---|
181 | void FrameworkManager::StopLog(void) { pimpl_->StopLog(); } |
---|
182 | |
---|
183 | bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; } |
---|
184 | |
---|
185 | void FrameworkManager::DisableErrorsDisplay(bool value) { |
---|
186 | pimpl_->disable_errors = value; |
---|
187 | } |
---|
188 | |
---|
189 | bool FrameworkManager::IsDisplayingErrors(void) const { |
---|
190 | return !(pimpl_->disable_errors); |
---|
191 | } |
---|
192 | |
---|
193 | } // end namespace core |
---|
194 | } // end namespace flair |
---|