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

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

sources reformatted with flair-format-dir script

File size: 5.1 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 "svnversion.h"
23
24using std::string;
25using std::vector;
26using namespace flair::gui;
27
28namespace {
29flair::core::FrameworkManager *frameworkmanager = NULL;
30}
31
32namespace flair {
33namespace core {
34
35FrameworkManager *getFrameworkManager(void) { return frameworkmanager; }
36
37bool IsBigEndian(void) {
38  union {
39    uint32_t i;
40    char c[4];
41  } bint = {0x01020304};
42
43  if (bint.c[0] == 1) {
44    return true;
45  } else {
46    return false;
47  }
48}
49
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  }
56
57  Printf(SVN_REV);
58  frameworkmanager = this;
59  pimpl_ = new FrameworkManager_impl(this, name);
60}
61
62FrameworkManager::~FrameworkManager() {
63  // Printf("destruction FrameworkManager\n");
64
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  }
71
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      }
90    }
91  }
92
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");
110    }
111  }
112
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  }
123
124  // childs.clear();
125
126  // Printf("destruction FrameworkManager ok\n");
127}
128
129void FrameworkManager::SetupConnection(string address, uint16_t port,
130                                       size_t rcv_buf_size) {
131  pimpl_->SetupConnection(address, port, rcv_buf_size);
132}
133
134void FrameworkManager::SetupUserInterface(string xml_file) {
135  pimpl_->SetupUserInterface(xml_file);
136}
137
138gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
139  return pimpl_->tabwidget;
140}
141
142void FrameworkManager::UpdateSendData(const SendData *obj) {
143  if (getUiCom() != NULL)
144    getUiCom()->UpdateSendData(obj);
145}
146
147void FrameworkManager::BlockCom(void) {
148  if (getUiCom() != NULL)
149    getUiCom()->Block();
150}
151
152void FrameworkManager::UnBlockCom(void) {
153  if (getUiCom() != NULL)
154    getUiCom()->UnBlock();
155}
156
157bool FrameworkManager::ConnectionLost(void) const {
158  if (getUiCom() != NULL) {
159    return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
160  } else {
161    return false;
162  }
163}
164
165void FrameworkManager::SetupLogger(string log_path) {
166  pimpl_->SetupLogger(log_path);
167}
168
169void FrameworkManager::AddDeviceToLog(IODevice *device) {
170  pimpl_->AddDeviceToLog(device);
171}
172
173void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
174
175void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
176
177bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
178
179void FrameworkManager::DisableErrorsDisplay(bool value) {
180  pimpl_->disable_errors = value;
181}
182
183bool FrameworkManager::IsDisplayingErrors(void) const {
184  return !(pimpl_->disable_errors);
185}
186
187} // end namespace core
188} // end namespace flair
Note: See TracBrowser for help on using the repository browser.