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

Last change on this file since 34 was 15, checked in by Bayard Gildas, 8 years ago

sources reformatted with flair-format-dir script

File size: 5.1 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"
22#include "svnversion.h"
23
24using std::string;
25using std::vector;
26using namespace flair::gui;
27
[15]28namespace {
29flair::core::FrameworkManager *frameworkmanager = NULL;
[2]30}
31
[15]32namespace flair {
33namespace core {
[2]34
[15]35FrameworkManager *getFrameworkManager(void) { return frameworkmanager; }
[2]36
37bool IsBigEndian(void) {
[15]38 union {
39 uint32_t i;
40 char c[4];
41 } bint = {0x01020304};
[2]42
[15]43 if (bint.c[0] == 1) {
44 return true;
45 } else {
46 return false;
47 }
[2]48}
49
[15]50FrameworkManager::FrameworkManager(string name)
51 : Object(NULL, name, XML_ROOT_TYPE) {
52 if (frameworkmanager != NULL) {
53 Err("FrameworkManager should be instanced only one time\n");
54 return;
55 }
[2]56
[15]57 Printf(SVN_REV);
58 frameworkmanager = this;
59 pimpl_ = new FrameworkManager_impl(this, name);
[2]60}
61
62FrameworkManager::~FrameworkManager() {
[15]63 // Printf("destruction FrameworkManager\n");
[2]64
[15]65 // stop ui_com thread (which sends datas for graphs), we do not need it as
66 // graphs will be destroyed
67 if (getUiCom() != NULL) {
68 getUiCom()->SafeStop();
69 getUiCom()->Join();
70 }
[2]71
[15]72 // we start by deleting threads (except pimpl which must be deleted at last)
73 // (before deleting objects that could be used by the threads)
74 // Printf("delete Threads\n");
75 for (vector<const Object *>::iterator it = Childs()->begin();
76 it < Childs()->end(); it++) {
77 // Printf("child %i %s
78 // %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
79 if ((*it)->ObjectType() == "Thread") {
80 if (*it != pimpl_) {
81 // Printf("del\n");
82 delete (Thread *)(*it);
83 // Childs() vector has been modified, we start from beginning again
84 // it will be incremented by the loop, so in fact we start again at
85 // begin()+1
86 // it is not a problem since begin is pimpl
87 it = Childs()->begin();
88 // Printf("del ok\n");
89 }
[2]90 }
[15]91 }
[2]92
[15]93 // next we delete IODevice
94 // (before deleting objects that could be used by the IODevice)
95 // Printf("delete IODevices\n");
96 for (vector<const Object *>::iterator it = Childs()->begin();
97 it < Childs()->end(); it++) {
98 // Printf("child %i %s
99 // %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
100 if ((*it)->ObjectType() == "IODevice") {
101 // Printf("del\n");
102 delete (IODevice *)*it;
103 // Printf("del ok\n");
104 // Childs() vector has been modified, we start from beginning again
105 // it will be incremented by the loop, so in fact we start again at
106 // begin()+1
107 // it is not a problem since begin is pimpl (not an IODevice)
108 it = Childs()->begin();
109 // Printf("del ok\n");
[2]110 }
[15]111 }
[2]112
[15]113 // Printf("delete childs\n");
114 // on efface les enfants en commencant par la fin
115 // le ui_com puis FrameworkManager_impl est détruit en dernier
116 // permet de garder l'uicom pour notifer des destructions
117 while (Childs()->size() != 0) {
118 // Printf("child %i %s
119 // %s\n",Childs()->size(),Childs()->back()->ObjectName().c_str(),Childs()->back()->ObjectType().c_str());
120 if (Childs()->back() != NULL)
121 delete Childs()->back();
122 }
[2]123
[15]124 // childs.clear();
[2]125
[15]126 // Printf("destruction FrameworkManager ok\n");
[2]127}
128
[15]129void FrameworkManager::SetupConnection(string address, uint16_t port,
130 size_t rcv_buf_size) {
131 pimpl_->SetupConnection(address, port, rcv_buf_size);
[2]132}
133
134void FrameworkManager::SetupUserInterface(string xml_file) {
[15]135 pimpl_->SetupUserInterface(xml_file);
[2]136}
137
[15]138gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
139 return pimpl_->tabwidget;
[2]140}
141
142void FrameworkManager::UpdateSendData(const SendData *obj) {
[15]143 if (getUiCom() != NULL)
144 getUiCom()->UpdateSendData(obj);
[2]145}
146
147void FrameworkManager::BlockCom(void) {
[15]148 if (getUiCom() != NULL)
149 getUiCom()->Block();
[2]150}
151
152void FrameworkManager::UnBlockCom(void) {
[15]153 if (getUiCom() != NULL)
154 getUiCom()->UnBlock();
[2]155}
156
157bool FrameworkManager::ConnectionLost(void) const {
[15]158 if (getUiCom() != NULL) {
159 return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
160 } else {
161 return false;
162 }
[2]163}
164
165void FrameworkManager::SetupLogger(string log_path) {
[15]166 pimpl_->SetupLogger(log_path);
[2]167}
168
169void FrameworkManager::AddDeviceToLog(IODevice *device) {
[15]170 pimpl_->AddDeviceToLog(device);
[2]171}
172
[15]173void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
[2]174
[15]175void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
[2]176
[15]177bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
[2]178
179void FrameworkManager::DisableErrorsDisplay(bool value) {
[15]180 pimpl_->disable_errors = value;
[2]181}
182
183bool FrameworkManager::IsDisplayingErrors(void) const {
[15]184 return !(pimpl_->disable_errors);
[2]185}
186
187} // end namespace core
188} // end namespace flair
Note: See TracBrowser for help on using the repository browser.