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

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

maj imu

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++) {
[186]83 //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
[15]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 }
[2]95 }
[15]96 }
[2]97
[15]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++) {
[186]103 //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
[15]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");
[2]114 }
[15]115 }
[2]116
[15]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) {
[186]122 //Printf("child %i %s %s\n",Childs()->size(),Childs()->back()->ObjectName().c_str(),Childs()->back()->ObjectType().c_str());
[15]123 if (Childs()->back() != NULL)
124 delete Childs()->back();
125 }
[2]126
[15]127 // childs.clear();
[2]128
[15]129 // Printf("destruction FrameworkManager ok\n");
[2]130}
131
[55]132void FrameworkManager::SetupConnection(string address, uint16_t port,Time watchdogTimeout,
[15]133 size_t rcv_buf_size) {
[186]134 pimpl_->SetupConnection(address, port, watchdogTimeout,rcv_buf_size);
[2]135}
136
137void FrameworkManager::SetupUserInterface(string xml_file) {
[15]138 pimpl_->SetupUserInterface(xml_file);
[2]139}
140
[15]141gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
[55]142 if(pimpl_->tabwidget==NULL) Err("SetupUserInterface must be called before\n");
[15]143 return pimpl_->tabwidget;
[2]144}
145
146void FrameworkManager::UpdateSendData(const SendData *obj) {
[15]147 if (getUiCom() != NULL)
148 getUiCom()->UpdateSendData(obj);
[2]149}
150
151void FrameworkManager::BlockCom(void) {
[15]152 if (getUiCom() != NULL)
153 getUiCom()->Block();
[2]154}
155
156void FrameworkManager::UnBlockCom(void) {
[15]157 if (getUiCom() != NULL)
158 getUiCom()->UnBlock();
[2]159}
160
161bool FrameworkManager::ConnectionLost(void) const {
[15]162 if (getUiCom() != NULL) {
163 return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
164 } else {
165 return false;
166 }
[2]167}
168
169void FrameworkManager::SetupLogger(string log_path) {
[15]170 pimpl_->SetupLogger(log_path);
[2]171}
172
[123]173string FrameworkManager::GetLogPath(void) const {
174 return pimpl_->log_path;
175}
[2]176void FrameworkManager::AddDeviceToLog(IODevice *device) {
[15]177 pimpl_->AddDeviceToLog(device);
[2]178}
179
[122]180bool FrameworkManager::IsDeviceLogged(const IODevice *device) const {
181 return pimpl_->IsDeviceLogged(device);
182}
183
[15]184void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
[2]185
[15]186void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
[2]187
[15]188bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
[2]189
190void FrameworkManager::DisableErrorsDisplay(bool value) {
[15]191 pimpl_->disable_errors = value;
[2]192}
193
194bool FrameworkManager::IsDisplayingErrors(void) const {
[15]195 return !(pimpl_->disable_errors);
[2]196}
197
198} // end namespace core
199} // end namespace flair
Note: See TracBrowser for help on using the repository browser.