[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 |
|
---|
| 24 | using std::string;
|
---|
| 25 | using std::vector;
|
---|
| 26 | using namespace flair::gui;
|
---|
| 27 |
|
---|
[15] | 28 | namespace {
|
---|
[45] | 29 | flair::core::FrameworkManager *frameworkmanager = NULL;
|
---|
[2] | 30 | }
|
---|
| 31 |
|
---|
[45] | 32 | static void constructor() __attribute__((constructor));
|
---|
| 33 |
|
---|
| 34 | void constructor() {
|
---|
| 35 | compile_info("FlairCore");
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
[15] | 39 | namespace flair {
|
---|
| 40 | namespace core {
|
---|
[2] | 41 |
|
---|
[15] | 42 | FrameworkManager *getFrameworkManager(void) { return frameworkmanager; }
|
---|
[2] | 43 |
|
---|
| 44 | bool 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] | 57 | FrameworkManager::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 |
|
---|
| 68 | FrameworkManager::~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");
|
---|
[217] | 87 | ((Thread *)(*it))->SafeStop();
|
---|
| 88 | ((Thread *)(*it))->Join();
|
---|
[15] | 89 | delete (Thread *)(*it);
|
---|
| 90 | // Childs() vector has been modified, we start from beginning again
|
---|
| 91 | // it will be incremented by the loop, so in fact we start again at
|
---|
| 92 | // begin()+1
|
---|
| 93 | // it is not a problem since begin is pimpl
|
---|
| 94 | it = Childs()->begin();
|
---|
| 95 | // Printf("del ok\n");
|
---|
| 96 | }
|
---|
[2] | 97 | }
|
---|
[15] | 98 | }
|
---|
[2] | 99 |
|
---|
[15] | 100 | // next we delete IODevice
|
---|
| 101 | // (before deleting objects that could be used by the IODevice)
|
---|
| 102 | // Printf("delete IODevices\n");
|
---|
| 103 | for (vector<const Object *>::iterator it = Childs()->begin();
|
---|
| 104 | it < Childs()->end(); it++) {
|
---|
[186] | 105 | //Printf("child %i %s %s\n",Childs()->size(),(*it)->ObjectName().c_str(),(*it)->ObjectType().c_str());
|
---|
[15] | 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) {
|
---|
[186] | 124 | //Printf("child %i %s %s\n",Childs()->size(),Childs()->back()->ObjectName().c_str(),Childs()->back()->ObjectType().c_str());
|
---|
[15] | 125 | if (Childs()->back() != NULL)
|
---|
| 126 | delete Childs()->back();
|
---|
| 127 | }
|
---|
[2] | 128 |
|
---|
[15] | 129 | // childs.clear();
|
---|
[2] | 130 |
|
---|
[15] | 131 | // Printf("destruction FrameworkManager ok\n");
|
---|
[2] | 132 | }
|
---|
| 133 |
|
---|
[55] | 134 | void FrameworkManager::SetupConnection(string address, uint16_t port,Time watchdogTimeout,
|
---|
[15] | 135 | size_t rcv_buf_size) {
|
---|
[186] | 136 | pimpl_->SetupConnection(address, port, watchdogTimeout,rcv_buf_size);
|
---|
[2] | 137 | }
|
---|
| 138 |
|
---|
| 139 | void FrameworkManager::SetupUserInterface(string xml_file) {
|
---|
[15] | 140 | pimpl_->SetupUserInterface(xml_file);
|
---|
[2] | 141 | }
|
---|
| 142 |
|
---|
[15] | 143 | gui::TabWidget *FrameworkManager::GetTabWidget(void) const {
|
---|
[55] | 144 | if(pimpl_->tabwidget==NULL) Err("SetupUserInterface must be called before\n");
|
---|
[15] | 145 | return pimpl_->tabwidget;
|
---|
[2] | 146 | }
|
---|
| 147 |
|
---|
| 148 | void FrameworkManager::UpdateSendData(const SendData *obj) {
|
---|
[15] | 149 | if (getUiCom() != NULL)
|
---|
| 150 | getUiCom()->UpdateSendData(obj);
|
---|
[2] | 151 | }
|
---|
| 152 |
|
---|
| 153 | void FrameworkManager::BlockCom(void) {
|
---|
[15] | 154 | if (getUiCom() != NULL)
|
---|
| 155 | getUiCom()->Block();
|
---|
[2] | 156 | }
|
---|
| 157 |
|
---|
| 158 | void FrameworkManager::UnBlockCom(void) {
|
---|
[15] | 159 | if (getUiCom() != NULL)
|
---|
| 160 | getUiCom()->UnBlock();
|
---|
[2] | 161 | }
|
---|
| 162 |
|
---|
| 163 | bool FrameworkManager::ConnectionLost(void) const {
|
---|
[15] | 164 | if (getUiCom() != NULL) {
|
---|
| 165 | return (getUiCom()->ConnectionLost() | pimpl_->connection_lost);
|
---|
| 166 | } else {
|
---|
| 167 | return false;
|
---|
| 168 | }
|
---|
[2] | 169 | }
|
---|
| 170 |
|
---|
[213] | 171 | void FrameworkManager::SetupLogger(string log_path,uint32_t stackSize) {
|
---|
| 172 | pimpl_->SetupLogger(log_path,stackSize);
|
---|
[2] | 173 | }
|
---|
| 174 |
|
---|
[123] | 175 | string FrameworkManager::GetLogPath(void) const {
|
---|
| 176 | return pimpl_->log_path;
|
---|
| 177 | }
|
---|
[2] | 178 | void FrameworkManager::AddDeviceToLog(IODevice *device) {
|
---|
[15] | 179 | pimpl_->AddDeviceToLog(device);
|
---|
[2] | 180 | }
|
---|
| 181 |
|
---|
[122] | 182 | bool FrameworkManager::IsDeviceLogged(const IODevice *device) const {
|
---|
| 183 | return pimpl_->IsDeviceLogged(device);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[15] | 186 | void FrameworkManager::StartLog(void) { pimpl_->StartLog(); }
|
---|
[2] | 187 |
|
---|
[15] | 188 | void FrameworkManager::StopLog(void) { pimpl_->StopLog(); }
|
---|
[2] | 189 |
|
---|
[15] | 190 | bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; }
|
---|
[2] | 191 |
|
---|
| 192 | void FrameworkManager::DisableErrorsDisplay(bool value) {
|
---|
[15] | 193 | pimpl_->disable_errors = value;
|
---|
[2] | 194 | }
|
---|
| 195 |
|
---|
| 196 | bool FrameworkManager::IsDisplayingErrors(void) const {
|
---|
[15] | 197 | return !(pimpl_->disable_errors);
|
---|
[2] | 198 | }
|
---|
| 199 |
|
---|
| 200 | } // end namespace core
|
---|
| 201 | } // end namespace flair
|
---|