source: flair-src/trunk/lib/FlairCore/src/FrameworkManager.cpp@ 213

Last change on this file since 213 was 213, checked in by Sanahuja Guillaume, 4 years ago

thread stack size rework
add Matrix class

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