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

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

vision filter

File size: 5.5 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]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"
[45]22#include "compile_info.h"
[2]23
24using std::string;
25using std::vector;
26using namespace flair::gui;
27
[15]28namespace {
[45]29 flair::core::FrameworkManager *frameworkmanager = NULL;
[2]30}
31
[45]32static void constructor() __attribute__((constructor));
33
34void constructor() {
35 compile_info("FlairCore");
36}
37
38
[15]39namespace flair {
40namespace core {
[2]41
[15]42FrameworkManager *getFrameworkManager(void) { return frameworkmanager; }
[2]43
44bool IsBigEndian(void) {
[15]45 union {
46 uint32_t i;
47 char c[4];
48 } bint = {0x01020304};
[2]49
[15]50 if (bint.c[0] == 1) {
51 return true;
52 } else {
53 return false;
54 }
[2]55}
56
[15]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 }
[2]63
[15]64 frameworkmanager = this;
65 pimpl_ = new FrameworkManager_impl(this, name);
[2]66}
67
68FrameworkManager::~FrameworkManager() {
[15]69 // Printf("destruction FrameworkManager\n");
[2]70
[15]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 }
[2]77
[15]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 }
[2]96 }
[15]97 }
[2]98
[15]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");
[2]116 }
[15]117 }
[2]118
[15]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 }
[2]129
[15]130 // childs.clear();
[2]131
[15]132 // Printf("destruction FrameworkManager ok\n");
[2]133}
134
[55]135void FrameworkManager::SetupConnection(string address, uint16_t port,Time watchdogTimeout,
[15]136 size_t rcv_buf_size) {
137 pimpl_->SetupConnection(address, port, rcv_buf_size);
[2]138}
139
140void FrameworkManager::SetupUserInterface(string xml_file) {
[15]141 pimpl_->SetupUserInterface(xml_file);
[2]142}
143
[15]144gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
[55]145 if(pimpl_->tabwidget==NULL) Err("SetupUserInterface must be called before\n");
[15]146 return pimpl_->tabwidget;
[2]147}
148
149void FrameworkManager::UpdateSendData(const SendData *obj) {
[15]150 if (getUiCom() != NULL)
151 getUiCom()->UpdateSendData(obj);
[2]152}
153
154void FrameworkManager::BlockCom(void) {
[15]155 if (getUiCom() != NULL)
156 getUiCom()->Block();
[2]157}
158
159void FrameworkManager::UnBlockCom(void) {
[15]160 if (getUiCom() != NULL)
161 getUiCom()->UnBlock();
[2]162}
163
164bool FrameworkManager::ConnectionLost(void) const {
[15]165 if (getUiCom() != NULL) {
166 return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
167 } else {
168 return false;
169 }
[2]170}
171
172void FrameworkManager::SetupLogger(string log_path) {
[15]173 pimpl_->SetupLogger(log_path);
[2]174}
175
[123]176string FrameworkManager::GetLogPath(void) const {
177 return pimpl_->log_path;
178}
[2]179void FrameworkManager::AddDeviceToLog(IODevice *device) {
[15]180 pimpl_->AddDeviceToLog(device);
[2]181}
182
[122]183bool FrameworkManager::IsDeviceLogged(const IODevice *device) const {
184 return pimpl_->IsDeviceLogged(device);
185}
186
[15]187void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
[2]188
[15]189void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
[2]190
[15]191bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
[2]192
193void FrameworkManager::DisableErrorsDisplay(bool value) {
[15]194 pimpl_->disable_errors = value;
[2]195}
196
197bool FrameworkManager::IsDisplayingErrors(void) const {
[15]198 return !(pimpl_->disable_errors);
[2]199}
200
201} // end namespace core
202} // end namespace flair
Note: See TracBrowser for help on using the repository browser.