Changeset 15 in flair-src for trunk/lib/FlairCore/src/FrameworkManager.cpp
- Timestamp:
- Apr 8, 2016, 3:40:57 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/FrameworkManager.cpp
r2 r15 26 26 using namespace flair::gui; 27 27 28 namespace 29 { 30 flair::core::FrameworkManager* frameworkmanager=NULL; 28 namespace { 29 flair::core::FrameworkManager *frameworkmanager = NULL; 31 30 } 32 31 32 namespace flair { 33 namespace core { 33 34 34 namespace flair 35 { 36 namespace core 37 { 35 FrameworkManager *getFrameworkManager(void) { return frameworkmanager; } 38 36 37 bool IsBigEndian(void) { 38 union { 39 uint32_t i; 40 char c[4]; 41 } bint = {0x01020304}; 39 42 40 FrameworkManager* getFrameworkManager(void) { 41 return frameworkmanager; 43 if (bint.c[0] == 1) { 44 return true; 45 } else { 46 return false; 47 } 42 48 } 43 49 44 bool IsBigEndian(void) { 45 union { 46 uint32_t i; 47 char c[4]; 48 } bint = {0x01020304}; 50 FrameworkManager::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 } 49 56 50 if(bint.c[0] == 1) { 51 return true; 52 } else { 53 return false; 54 } 55 } 56 57 FrameworkManager::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); 57 Printf(SVN_REV); 58 frameworkmanager = this; 59 pimpl_ = new FrameworkManager_impl(this, name); 67 60 } 68 61 69 62 FrameworkManager::~FrameworkManager() { 70 //Printf("destruction FrameworkManager\n");63 // Printf("destruction FrameworkManager\n"); 71 64 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(); 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 } 76 90 } 91 } 77 92 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 } 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"); 94 110 } 111 } 95 112 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 } 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 } 112 123 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 } 124 // childs.clear(); 121 125 122 //childs.clear(); 123 124 //Printf("destruction FrameworkManager ok\n"); 126 // Printf("destruction FrameworkManager ok\n"); 125 127 } 126 128 127 void FrameworkManager::SetupConnection(string address,uint16_t port,size_t rcv_buf_size) { 128 pimpl_->SetupConnection(address,port,rcv_buf_size); 129 void FrameworkManager::SetupConnection(string address, uint16_t port, 130 size_t rcv_buf_size) { 131 pimpl_->SetupConnection(address, port, rcv_buf_size); 129 132 } 130 133 131 134 void FrameworkManager::SetupUserInterface(string xml_file) { 132 135 pimpl_->SetupUserInterface(xml_file); 133 136 } 134 137 135 gui::TabWidget *FrameworkManager::GetTabWidget(void) const {136 138 gui::TabWidget *FrameworkManager::GetTabWidget(void) const { 139 return pimpl_->tabwidget; 137 140 } 138 141 139 142 void FrameworkManager::UpdateSendData(const SendData *obj) { 140 if(getUiCom()!=NULL) getUiCom()->UpdateSendData(obj); 143 if (getUiCom() != NULL) 144 getUiCom()->UpdateSendData(obj); 141 145 } 142 146 143 147 void FrameworkManager::BlockCom(void) { 144 if(getUiCom()!=NULL) getUiCom()->Block(); 148 if (getUiCom() != NULL) 149 getUiCom()->Block(); 145 150 } 146 151 147 152 void FrameworkManager::UnBlockCom(void) { 148 if(getUiCom()!=NULL) getUiCom()->UnBlock(); 153 if (getUiCom() != NULL) 154 getUiCom()->UnBlock(); 149 155 } 150 156 151 157 bool FrameworkManager::ConnectionLost(void) const { 152 if(getUiCom()!=NULL) {153 return (getUiCom()->ConnectionLost()| pimpl_->connection_lost);154 155 156 158 if (getUiCom() != NULL) { 159 return (getUiCom()->ConnectionLost() | pimpl_->connection_lost); 160 } else { 161 return false; 162 } 157 163 } 158 164 159 165 void FrameworkManager::SetupLogger(string log_path) { 160 166 pimpl_->SetupLogger(log_path); 161 167 } 162 168 163 169 void FrameworkManager::AddDeviceToLog(IODevice *device) { 164 170 pimpl_->AddDeviceToLog(device); 165 171 } 166 172 167 void FrameworkManager::StartLog(void) { 168 pimpl_->StartLog(); 169 } 173 void FrameworkManager::StartLog(void) { pimpl_->StartLog(); } 170 174 171 void FrameworkManager::StopLog(void) { 172 pimpl_->StopLog(); 173 } 175 void FrameworkManager::StopLog(void) { pimpl_->StopLog(); } 174 176 175 bool FrameworkManager::IsLogging(void) const { 176 return pimpl_->is_logging; 177 } 177 bool FrameworkManager::IsLogging(void) const { return pimpl_->is_logging; } 178 178 179 179 void FrameworkManager::DisableErrorsDisplay(bool value) { 180 pimpl_->disable_errors=value;180 pimpl_->disable_errors = value; 181 181 } 182 182 183 183 bool FrameworkManager::IsDisplayingErrors(void) const { 184 184 return !(pimpl_->disable_errors); 185 185 } 186 186
Note:
See TracChangeset
for help on using the changeset viewer.