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

Last change on this file since 10 was 2, checked in by Sanahuja Guillaume, 8 years ago

flaircore

File size: 5.2 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
29{
30 flair::core::FrameworkManager* frameworkmanager=NULL;
31}
32
33
34namespace flair
35{
36namespace core
37{
38
39
40FrameworkManager* getFrameworkManager(void) {
41 return frameworkmanager;
42}
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): Object(NULL,name,XML_ROOT_TYPE)
58{
59 if(frameworkmanager!=NULL) {
60 Err("FrameworkManager should be instanced only one time\n");
61 return;
62 }
63
64 Printf(SVN_REV);
65 frameworkmanager=this;
66 pimpl_=new FrameworkManager_impl(this,name);
67}
68
69FrameworkManager::~FrameworkManager() {
70 //Printf("destruction FrameworkManager\n");
71
72 //stop ui_com thread (which sends datas for graphs), we do not need it as 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() ; it < Childs()->end(); it++ ) {
82 //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
83 if((*it)->ObjectType()=="Thread") {
84 if(*it!=pimpl_) {
85 //Printf("del\n");
86 delete (Thread*)(*it);
87 //Childs() vector has been modified, we start from beginning again
88 //it will be incremented by the loop, so in fact we start again at begin()+1
89 //it is not a problem since begin is pimpl
90 it=Childs()->begin();
91 //Printf("del ok\n");
92 }
93 }
94 }
95
96 //next we delete IODevice
97 // (before deleting objects that could be used by the IODevice)
98 //Printf("delete IODevices\n");
99 for(vector<const Object*>::iterator it=Childs()->begin() ; it < Childs()->end(); it++ ) {
100 //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
101 if((*it)->ObjectType()=="IODevice") {
102 //Printf("del\n");
103 delete (IODevice*)*it;
104 //Printf("del ok\n");
105 //Childs() vector has been modified, we start from beginning again
106 //it will be incremented by the loop, so in fact we start again at 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 %s\n",Childs()->size(),Childs()->back()->ObjectName().c_str(),Childs()->back()->ObjectType().c_str());
119 if(Childs()->back()!=NULL) delete Childs()->back();
120 }
121
122 //childs.clear();
123
124//Printf("destruction FrameworkManager ok\n");
125}
126
127void FrameworkManager::SetupConnection(string address,uint16_t port,size_t rcv_buf_size) {
128 pimpl_->SetupConnection(address,port,rcv_buf_size);
129}
130
131void FrameworkManager::SetupUserInterface(string xml_file) {
132 pimpl_->SetupUserInterface(xml_file);
133}
134
135gui::TabWidget* FrameworkManager::GetTabWidget(void) const {
136 return pimpl_->tabwidget;
137}
138
139void FrameworkManager::UpdateSendData(const SendData *obj) {
140 if(getUiCom()!=NULL) getUiCom()->UpdateSendData(obj);
141}
142
143void FrameworkManager::BlockCom(void) {
144 if(getUiCom()!=NULL) getUiCom()->Block();
145}
146
147void FrameworkManager::UnBlockCom(void) {
148 if(getUiCom()!=NULL) getUiCom()->UnBlock();
149}
150
151bool FrameworkManager::ConnectionLost(void) const {
152 if(getUiCom()!=NULL) {
153 return (getUiCom()->ConnectionLost()| pimpl_->connection_lost);
154 } else {
155 return false;
156 }
157}
158
159void FrameworkManager::SetupLogger(string log_path) {
160 pimpl_->SetupLogger(log_path);
161}
162
163void FrameworkManager::AddDeviceToLog(IODevice *device) {
164 pimpl_->AddDeviceToLog(device);
165}
166
167void FrameworkManager::StartLog(void) {
168 pimpl_->StartLog();
169}
170
171void FrameworkManager::StopLog(void) {
172 pimpl_->StopLog();
173}
174
175bool FrameworkManager::IsLogging(void) const {
176 return pimpl_->is_logging;
177}
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.