SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "NetworkManager.h" 00003 #include "NetworkDaoThread.h" 00004 #include "Globals.h" 00005 using namespace spikestream; 00006 00007 //Qt includes 00008 #include <QDebug> 00009 00011 NetworkManager::NetworkManager() : SpikeStreamThread(){ 00012 } 00013 00014 00016 NetworkManager::~NetworkManager(){ 00017 } 00018 00019 00020 /*----------------------------------------------------------*/ 00021 /*----- PUBLIC METHODS -----*/ 00022 /*----------------------------------------------------------*/ 00023 00025 void NetworkManager::cancel(){ 00026 stopThread = true; 00027 } 00028 00029 00030 //Run method inherited from SpikeStreamThread 00031 void NetworkManager::run(){ 00032 stopThread = false; 00033 clearError(); 00034 00035 try{ 00036 if (currentTask == LOAD_NETWORK_TASK){ 00037 //Start task 00038 emit progress(0, 0, "Loading neuron and connection group information.", false); 00039 network->load(); 00040 00041 //Wait for network to finish task 00042 while(network->isBusy() && !stopThread){ 00043 emit progress(network->getNumberOfCompletedSteps(), network->getTotalNumberOfSteps(), network->getProgressMessage(), true); 00044 msleep(200); 00045 } 00046 00047 //Handle cancel operation 00048 if(stopThread){ 00049 network->cancel(); 00050 while(network->isBusy()){ 00051 emit progress(0, 1, "Waiting for network to finish clean up.", false); 00052 msleep(200); 00053 } 00054 } 00055 00056 //Check for errors 00057 if(network->isError()) 00058 setError(network->getErrorMessage()); 00059 } 00060 else if (currentTask == SAVE_NETWORK_TASK){ 00061 //Start task 00062 network->save(); 00063 00064 //Wait for network to finish task - this operation cannot be cancelled 00065 while(network->isBusy() && !stopThread){ 00066 emit progress(network->getNumberOfCompletedSteps(), network->getTotalNumberOfSteps(), network->getProgressMessage(), false); 00067 msleep(200); 00068 } 00069 00070 //Check for errors 00071 if(network->isError()) 00072 setError(network->getErrorMessage()); 00073 } 00074 else if (currentTask == DELETE_NETWORK_TASK){ 00075 //Start task 00076 NetworkDaoThread networkDaoThread(Globals::getNetworkDao()->getDBInfo()); 00077 networkDaoThread.startDeleteNetwork(networkID); 00078 00079 //Wait for network dao thread to finish task 00080 while(networkDaoThread.isRunning()){ 00081 emit progress(networkDaoThread.getNumberOfCompletedSteps(), networkDaoThread.getTotalNumberOfSteps(), networkDaoThread.getProgressMessage(), false); 00082 msleep(200); 00083 } 00084 00085 //Check for errors 00086 if(networkDaoThread.isError()) 00087 setError(networkDaoThread.getErrorMessage()); 00088 } 00089 else{ 00090 throw SpikeStreamException("Current task not recognized: " + QString::number(currentTask)); 00091 } 00092 } 00093 catch(SpikeStreamException& ex){ 00094 setError(ex.getMessage()); 00095 } 00096 catch(...){ 00097 setError("Unrecognized exception thrown."); 00098 } 00099 00100 emit progress(1, 1, "Complete.", false); 00101 stopThread = true; 00102 } 00103 00104 00106 void NetworkManager::startDeleteNetwork(unsigned networkID){ 00107 this->networkID = networkID; 00108 currentTask = DELETE_NETWORK_TASK; 00109 start(); 00110 } 00111 00112 00114 void NetworkManager::startLoadNetwork(Network *network){ 00115 this->network = network; 00116 currentTask = LOAD_NETWORK_TASK; 00117 start(); 00118 } 00119 00120 00121 00123 void NetworkManager::startSaveNetwork(Network *network){ 00124 this->network = network; 00125 currentTask = SAVE_NETWORK_TASK; 00126 start(); 00127 } 00128 00129 00130