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

Last change on this file since 123 was 123, checked in by Sanahuja Guillaume, 7 years ago

vision filter

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
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
135void FrameworkManager::SetupConnection(string address, uint16_t port,Time watchdogTimeout,
136 size_t rcv_buf_size) {
137 pimpl_->SetupConnection(address, port, rcv_buf_size);
138}
139
140void FrameworkManager::SetupUserInterface(string xml_file) {
141 pimpl_->SetupUserInterface(xml_file);
142}
143
144gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
145 if(pimpl_->tabwidget==NULL) Err("SetupUserInterface must be called before\n");
146 return pimpl_->tabwidget;
147}
148
149void FrameworkManager::UpdateSendData(const SendData *obj) {
150 if (getUiCom() != NULL)
151 getUiCom()->UpdateSendData(obj);
152}
153
154void FrameworkManager::BlockCom(void) {
155 if (getUiCom() != NULL)
156 getUiCom()->Block();
157}
158
159void FrameworkManager::UnBlockCom(void) {
160 if (getUiCom() != NULL)
161 getUiCom()->UnBlock();
162}
163
164bool FrameworkManager::ConnectionLost(void) const {
165 if (getUiCom() != NULL) {
166 return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
167 } else {
168 return false;
169 }
170}
171
172void FrameworkManager::SetupLogger(string log_path) {
173 pimpl_->SetupLogger(log_path);
174}
175
176string FrameworkManager::GetLogPath(void) const {
177 return pimpl_->log_path;
178}
179void FrameworkManager::AddDeviceToLog(IODevice *device) {
180 pimpl_->AddDeviceToLog(device);
181}
182
183bool FrameworkManager::IsDeviceLogged(const IODevice *device) const {
184 return pimpl_->IsDeviceLogged(device);
185}
186
187void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
188
189void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
190
191bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
192
193void FrameworkManager::DisableErrorsDisplay(bool value) {
194 pimpl_->disable_errors = value;
195}
196
197bool FrameworkManager::IsDisplayingErrors(void) const {
198 return !(pimpl_->disable_errors);
199}
200
201} // end namespace core
202} // end namespace flair
Note: See TracBrowser for help on using the repository browser.