00001 /* --------------------------------------------------------------------------- 00002 Phission : 00003 Realtime Vision Processing System 00004 00005 Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu) 00006 University of Massachusetts at Lowell, 00007 Laboratory for Artificial Intelligence and Robotics 00008 00009 This file is part of Phission. 00010 00011 Phission is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU Lesser General Public License as published by 00013 the Free Software Foundation; either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 Phission is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public License 00022 along with Phission; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 ---------------------------------------------------------------------------*/ 00026 #ifdef HAVE_CONFIG_H 00027 #include <phissionconfig.h> 00028 #endif 00029 00030 #include <phStandard.h> 00031 00032 #include <phObject.h> 00033 #include <phMutex.h> 00034 #include <phSemaphore.h> 00035 #include <phCondition.h> 00036 #include <phThread.h> 00037 #include <phList.h> 00038 #include <phObjectList.h> 00039 #include <phTimeStamp.h> 00040 #include <phTimeInterval.h> 00041 #include <phRWLock.h> 00042 #include <phLiveObject.h> 00043 #include <phDataObject.h> 00044 #include <phImage.h> 00045 #include <phCaptureInterface.h> 00046 #include <phDisplayInterface.h> 00047 #include <phTimeStamp.h> 00048 #include <phPipeline.h> 00049 00050 #include <phSystem.h> 00051 00052 #include <phError.h> 00053 #include <phMemory.h> 00054 #include <phPrint.h> 00055 00056 /* ---------------------------------------------------------------------- */ 00057 phSystem::phSystem() 00058 { 00059 phFUNCTION("phSystem::phSystem()") 00060 int locked = 0; 00061 int i = 0; 00062 00063 phTHIS_LOOSE_LOCK(locked); 00064 00065 this->setName("phSystem"); 00066 00067 for (i = 0; i < phSystem_NCOMPONENTS; i++ ) 00068 { 00069 this->m_use[i] = this->m_active[i] = 0; 00070 } 00071 00072 this->m_is_active = 0; 00073 00074 this->m_autoMode = phAUTO_MODE; 00075 00076 phTHIS_LOOSE_UNLOCK(locked); 00077 } 00078 00079 /* ---------------------------------------------------------------------- */ 00080 phSystem::~phSystem() 00081 { 00082 phFUNCTION("phSystem::~phSystem()") 00083 int locked = 0; 00084 00085 phTHIS_LOOSE_LOCK(locked); 00086 00087 rc = this->removeAll(); 00088 phPRINT_RC(rc,NULL,"this->removeAll()"); 00089 } 00090 00091 /* ---------------------------------------------------------------------- */ 00092 int phSystem::setAutoMode( int mode ) 00093 { 00094 phFUNCTION("phSystem::setAutoMode") 00095 int locked = 0; 00096 00097 phTHIS_LOCK(locked); 00098 00099 this->m_autoMode = mode; 00100 00101 phTHIS_UNLOCK(locked); 00102 00103 return phSUCCESS; 00104 error: 00105 00106 phTHIS_ERROR_UNLOCK(locked); 00107 00108 return phFAIL; 00109 } 00110 00111 /* ---------------------------------------------------------------------- */ 00112 int phSystem::getAutoMode( ) 00113 { 00114 return this->m_autoMode; 00115 } 00116 00117 /* ---------------------------------------------------------------------- */ 00118 int phSystem::startDisplay( phDisplayInterface *display ) 00119 { 00120 phFUNCTION("phSystem::startDisplay") 00121 00122 /* this doesn't require locking the system object */ 00123 00124 if (display == NULL) return phFAIL; 00125 00126 /* If the display window isn't open, open it */ 00127 if ((display->isOpen() == 0) && 00128 (display->isLiveSourceSet() == 1)) 00129 { 00130 rc = display->open(); 00131 phCHECK_RC(rc,NULL, "display->open() failed"); 00132 } 00133 00134 #if 0 00135 /* Only start the live source thread if it's not on */ 00136 /* and the live source is defined */ 00137 /* This is here so that when the user wants to resume from a HALT, 00138 * The live source will be turned back on. The display thread will 00139 * turn it on automatically at first */ 00140 if ((display->isLiveSourceOn() == 0) && 00141 (display->isLiveSourceSet() == 1)) 00142 { 00143 rc = display->liveSourceOn(); 00144 phCHECK_RC(rc,NULL, "display->liveSourceOn() failed"); 00145 } 00146 #endif 00147 00148 if (display->isPaused()) display->unpause(); 00149 00150 return phSUCCESS; 00151 error: 00152 return phFAIL; 00153 } 00154 00155 /* ---------------------------------------------------------------------- */ 00156 int phSystem::startPipeline( phPipeline *pipeline ) 00157 { 00158 phFUNCTION("phSystem::startPipeline") 00159 00160 /* this doesn't require locking the system object */ 00161 00162 if (pipeline == NULL) return phFAIL; 00163 00164 if (!pipeline->isPipelineActive()) 00165 { 00166 rc = pipeline->startPipeline(); 00167 phCHECK_RC(rc,NULL, "pipeline->startPipeline()"); 00168 } 00169 00170 return phSUCCESS; 00171 error: 00172 return phFAIL; 00173 } 00174 00175 /* ---------------------------------------------------------------------- */ 00176 int phSystem::startCapture( phCaptureInterface *capture ) 00177 { 00178 phFUNCTION("phSystem::startCapture") 00179 00180 /* this doesn't require locking the system object */ 00181 00182 if (capture == NULL) return phFAIL; 00183 00184 if (!capture->isCapturing()) 00185 { 00186 rc = capture->start(); 00187 phCHECK_RC(rc,NULL, "capture->start()"); 00188 } 00189 00190 return phSUCCESS; 00191 error: 00192 return phFAIL; 00193 } 00194 00195 /* ---------------------------------------------------------------------- */ 00196 int phSystem::startThread( phThread *thread ) 00197 { 00198 phFUNCTION("phSystem::startThread") 00199 00200 /* this doesn't require locking the system object */ 00201 00202 if (thread == NULL) return phFAIL; 00203 00204 if (!thread->isRunning()) 00205 { 00206 rc = thread->start(); 00207 phCHECK_RC(rc,NULL, "thread->start()"); 00208 } 00209 00210 return phSUCCESS; 00211 error: 00212 return phFAIL; 00213 } 00214 00215 00216 /* ---------------------------------------------------------------------- */ 00217 int phSystem::haltDisplay( phDisplayInterface *display ) 00218 { 00219 phFUNCTION("phSystem::haltDisplay") 00220 00221 /* this doesn't require locking the system object */ 00222 00223 if (display == NULL) return phFAIL; 00224 00225 if (//(display->isLiveSourceOn() == 1) && 00226 (display->isPaused() == 0) && 00227 (display->isLiveSourceSet() == 1)) 00228 { 00229 rc = display->pause(); 00230 phPRINT_RC(rc,NULL,"display->pause() failed."); 00231 #if 0 00232 rc = display->liveSourceOff(); 00233 phPRINT_RC(rc,NULL,"display->liveSourceOff failed."); 00234 #endif 00235 } 00236 00237 return phSUCCESS; 00238 } 00239 00240 00241 /* ---------------------------------------------------------------------- */ 00242 int phSystem::haltPipeline( phPipeline *pipeline ) 00243 { 00244 phFUNCTION("phSystem::haltPipeline") 00245 00246 /* this doesn't require locking the system object */ 00247 00248 if (pipeline == NULL) return phFAIL; 00249 00250 if (pipeline->isPipelineActive()) 00251 { 00252 rc = pipeline->stopPipeline(); 00253 phCHECK_RC(rc,NULL, "pipeline->stopPipeline()"); 00254 } 00255 00256 return phSUCCESS; 00257 error: 00258 return phFAIL; 00259 } 00260 00261 /* ---------------------------------------------------------------------- */ 00262 int phSystem::haltCapture( phCaptureInterface *capture ) 00263 { 00264 phFUNCTION("phSystem::haltCapture") 00265 00266 /* this doesn't require locking the system object */ 00267 00268 if (capture == NULL) return phFAIL; 00269 00270 if (capture->isCapturing()) 00271 { 00272 rc = capture->stop(); 00273 phCHECK_RC(rc,NULL, "capture->stop()"); 00274 } 00275 00276 return phSUCCESS; 00277 error: 00278 return phFAIL; 00279 } 00280 00281 /* ---------------------------------------------------------------------- */ 00282 int phSystem::haltThread( phThread *thread ) 00283 { 00284 phFUNCTION("phSystem::haltThread") 00285 00286 /* this doesn't require locking the system object */ 00287 00288 if (thread == NULL) return phFAIL; 00289 00290 if (thread->isRunning()) 00291 { 00292 rc = thread->stop(); 00293 phCHECK_RC(rc,NULL, "thread->stop()"); 00294 } 00295 00296 return phSUCCESS; 00297 error: 00298 return phFAIL; 00299 } 00300 00301 00302 /* ---------------------------------------------------------------------- */ 00303 int phSystem::stopDisplay( phDisplayInterface *display ) 00304 { 00305 phFUNCTION("phSystem::stopDisplay") 00306 00307 /* this doesn't require locking the system object */ 00308 00309 if (display == NULL) return phFAIL; 00310 00311 rc = phSystem::haltDisplay(display); 00312 phPRINT_RC( rc, NULL, "phSystem::haltDisplay failed" ); 00313 00314 /* If the display window is open, close it !!! */ 00315 /* The live source was shut off haltDisplays() */ 00316 if (display->isOpen() == 1) 00317 { 00318 rc = display->close(); 00319 phPRINT_RC(rc,NULL,"display->close()"); 00320 } 00321 00322 return phSUCCESS; 00323 } 00324 00325 /* ---------------------------------------------------------------------- */ 00326 int phSystem::stopPipeline( phPipeline *pipeline ) 00327 { 00328 return phSystem::haltPipeline(pipeline); 00329 } 00330 00331 /* ---------------------------------------------------------------------- */ 00332 int phSystem::stopCapture( phCaptureInterface *capture ) 00333 { 00334 phFUNCTION("phSystem::stopCapture") 00335 00336 /* this doesn't require locking the system object */ 00337 00338 if (capture == NULL) return phFAIL; 00339 00340 rc = phSystem::haltCapture(capture); 00341 phPRINT_RC(rc,NULL,"phSystem::haltCapture failed"); 00342 00343 if (capture->isOpen()) 00344 { 00345 /* This shouldn't happen, the device should have been 00346 * closed by the call to stop() */ 00347 rc = capture->close(); 00348 phPRINT_RC(rc,NULL,"capture->close()"); 00349 } 00350 00351 return phSUCCESS; 00352 } 00353 00354 /* ---------------------------------------------------------------------- */ 00355 int phSystem::stopThread( phThread *thread ) 00356 { 00357 return phSystem::haltThread(thread); 00358 } 00359 00360 /* ---------------------------------------------------------------------- */ 00361 int32_t phSystem::displaysOpen() 00362 { 00363 phFUNCTION("phSystem::displaysOpen") 00364 int locked = 0; 00365 int displays_locked = 0; 00366 phObjectNode *node = NULL; 00367 phDisplayInterface *display = NULL; 00368 int32_t retrc = phSUCCESS; 00369 00370 phTHIS_LOCK(locked); 00371 00372 if (this->m_use[phSystem_DISPLAY] == 1) 00373 { 00374 phMUTEX_LOCK(this->m_displays,displays_locked); 00375 00376 node = this->m_displays.getHeadObject(); 00377 00378 /* Loop through all the displays in the list */ 00379 while (node != NULL) 00380 { 00381 display = (phDisplayInterface *)node->getObject(); 00382 00383 if ((display != NULL) && (display->isOpen())) 00384 retrc++; 00385 00386 node = node->getNextObject(); 00387 } 00388 00389 phMUTEX_UNLOCK(this->m_displays,displays_locked); 00390 } 00391 00392 phTHIS_UNLOCK(locked); 00393 00394 return retrc; 00395 error: 00396 phMUTEX_ERROR_UNLOCK(this->m_displays,displays_locked); 00397 00398 phTHIS_ERROR_UNLOCK(locked); 00399 00400 return phFAIL; 00401 } 00402 00403 /* ---------------------------------------------------------------------- */ 00404 int32_t phSystem::displaysActive() 00405 { 00406 phFUNCTION("phSystem::displaysActive") 00407 int locked = 0; 00408 int displays_locked = 0; 00409 phObjectNode *node = NULL; 00410 phDisplayInterface *display = NULL; 00411 int32_t retrc = phSUCCESS; 00412 00413 phTHIS_LOCK(locked); 00414 00415 if (this->m_use[phSystem_DISPLAY] == 1) 00416 { 00417 phMUTEX_LOCK(this->m_displays,displays_locked); 00418 00419 node = this->m_displays.getHeadObject(); 00420 00421 /* Loop through all the displays in the list */ 00422 while (node != NULL) 00423 { 00424 display = (phDisplayInterface *)node->getObject(); 00425 00426 if ((display != NULL) && display->isOpen()) 00427 //(display->isLiveSourceOn() == 1)) 00428 retrc++; 00429 00430 node = node->getNextObject(); 00431 } 00432 00433 phMUTEX_UNLOCK(this->m_displays,displays_locked); 00434 } 00435 00436 phTHIS_UNLOCK(locked); 00437 00438 return retrc; 00439 error: 00440 phMUTEX_ERROR_UNLOCK(this->m_displays,displays_locked); 00441 00442 phTHIS_ERROR_UNLOCK(locked); 00443 00444 return phFAIL; 00445 } 00446 00447 /* ---------------------------------------------------------------------- */ 00448 int32_t phSystem::pipelinesActive() 00449 { 00450 phFUNCTION("phSystem::pipelinesActive") 00451 int locked = 0; 00452 int pipelines_locked = 0; 00453 phObjectNode *node = NULL; 00454 phPipeline *pipeline = NULL; 00455 int32_t retrc = phSUCCESS; 00456 00457 phTHIS_LOCK(locked); 00458 00459 if (this->m_use[phSystem_PIPELINE] == 1) 00460 { 00461 phMUTEX_LOCK(this->m_pipelines,pipelines_locked); 00462 00463 node = this->m_pipelines.getHeadObject(); 00464 00465 /* Loop through all the pipelines in the list */ 00466 while (node != NULL) 00467 { 00468 pipeline = (phPipeline *)node->getObject(); 00469 00470 if ((pipeline != NULL) && (pipeline->isPipelineActive())) 00471 retrc++; 00472 00473 node = node->getNextObject(); 00474 } 00475 00476 phMUTEX_UNLOCK(this->m_pipelines,pipelines_locked); 00477 00478 if (retrc > 0) 00479 this->m_active[phSystem_PIPELINE] = 1; 00480 } 00481 00482 phTHIS_UNLOCK(locked); 00483 00484 return phSUCCESS; 00485 error: 00486 phMUTEX_ERROR_UNLOCK(this->m_pipelines,pipelines_locked); 00487 00488 phTHIS_ERROR_UNLOCK(locked); 00489 00490 return phFAIL; 00491 00492 } 00493 00494 /* ---------------------------------------------------------------------- */ 00495 int32_t phSystem::capturesActive() 00496 { 00497 phFUNCTION("phSystem::capturesActive") 00498 int locked = 0; 00499 int captures_locked = 0; 00500 phObjectNode *node = NULL; 00501 phCaptureInterface *capture = NULL; 00502 int32_t retrc = phSUCCESS; 00503 00504 phTHIS_LOCK(locked); 00505 00506 if (this->m_use[phSystem_CAPTURE] == 1) 00507 { 00508 phMUTEX_LOCK(this->m_captures,captures_locked); 00509 00510 node = this->m_captures.getHeadObject(); 00511 00512 /* Loop through all the captures in the list */ 00513 while (node != NULL) 00514 { 00515 capture = (phCaptureInterface *)node->getObject(); 00516 00517 if ((capture != NULL) && (capture->isCapturing())) 00518 retrc++; 00519 00520 node = node->getNextObject(); 00521 } 00522 00523 phMUTEX_UNLOCK(this->m_captures,captures_locked); 00524 00525 if (retrc > 0) 00526 this->m_active[phSystem_CAPTURE] = 1; 00527 } 00528 00529 phTHIS_UNLOCK(locked); 00530 00531 return retrc; 00532 error: 00533 phMUTEX_ERROR_UNLOCK(this->m_captures,captures_locked); 00534 00535 phTHIS_ERROR_UNLOCK(locked); 00536 00537 return phFAIL; 00538 00539 } 00540 00541 /* ---------------------------------------------------------------------- */ 00542 int32_t phSystem::threadsActive() 00543 { 00544 phFUNCTION("phSystem::threadsActive") 00545 int locked = 0; 00546 int threads_locked = 0; 00547 phObjectNode *node = NULL; 00548 phThread *thread = NULL; 00549 int32_t retrc = phSUCCESS; 00550 00551 phTHIS_LOCK(locked); 00552 00553 if (this->m_use[phSystem_THREAD] == 1) 00554 { 00555 phMUTEX_LOCK(this->m_threads,threads_locked); 00556 00557 node = this->m_threads.getHeadObject(); 00558 00559 /* Loop through all the threads in the list */ 00560 while (node != NULL) 00561 { 00562 thread = (phThread *)node->getObject(); 00563 00564 if ((thread != NULL) && (thread->isRunning())) 00565 retrc++; 00566 00567 node = node->getNextObject(); 00568 } 00569 00570 phMUTEX_UNLOCK(this->m_threads,threads_locked); 00571 00572 if (retrc > 0) 00573 this->m_active[phSystem_THREAD] = 1; 00574 } 00575 00576 phTHIS_UNLOCK(locked); 00577 00578 return retrc; 00579 error: 00580 phMUTEX_ERROR_UNLOCK(this->m_threads,threads_locked); 00581 00582 phTHIS_ERROR_UNLOCK(locked); 00583 00584 return phFAIL; 00585 } 00586 00587 /* ---------------------------------------------------------------------- */ 00588 int32_t phSystem::displayCount() 00589 { 00590 return this->m_displays.length(); 00591 } 00592 00593 /* ---------------------------------------------------------------------- */ 00594 int32_t phSystem::pipelineCount() 00595 { 00596 return this->m_pipelines.length(); 00597 } 00598 00599 /* ---------------------------------------------------------------------- */ 00600 int32_t phSystem::captureCount() 00601 { 00602 return this->m_captures.length(); 00603 } 00604 00605 /* ---------------------------------------------------------------------- */ 00606 int32_t phSystem::threadCount() 00607 { 00608 return this->m_threads.length(); 00609 } 00610 00611 /* ---------------------------------------------------------------------- */ 00612 int phSystem::addDisplay(phDisplayInterface *display,int autoStart) 00613 { 00614 phFUNCTION("phSystem::addDisplay") 00615 phObjectNode *objnode = NULL; 00616 int locked = 0; 00617 00618 if (display == NULL) return phFAIL; 00619 00620 phTHIS_LOCK(locked); 00621 00622 this->m_use[phSystem_DISPLAY] = 1; 00623 objnode = this->m_displays.pushObject(display); 00624 phCHECK_PTR(objnode,NULL,"m_displays.pushObject"); 00625 00626 /* TODO: Add ability to disable this feature */ 00627 /* this will start up the display if the other displays are active */ 00628 if ((this->m_active[phSystem_DISPLAY]) && 00629 (this->m_autoMode != phMANUAL_MODE) && 00630 (autoStart)) 00631 { 00632 rc = this->startDisplay(display); 00633 phPRINT_RC(rc,NULL,"this->startDisplay(%p)",display); 00634 00635 if ((rc == phSUCCESS) && (this->m_active[phSystem_DISPLAY] == 0)) 00636 { 00637 this->m_active[phSystem_DISPLAY] = 1; 00638 } 00639 } 00640 00641 phTHIS_UNLOCK(locked); 00642 00643 return phSUCCESS; 00644 error: 00645 phTHIS_ERROR_UNLOCK(locked); 00646 00647 return phFAIL; 00648 } 00649 00650 /* ---------------------------------------------------------------------- */ 00651 int phSystem::addPipeline(phPipeline *pipeline,int autoStart) 00652 { 00653 phFUNCTION("phSystem::addPipeline") 00654 phObjectNode *objnode = NULL; 00655 int locked = 0; 00656 00657 if (pipeline == NULL) return phFAIL; 00658 00659 phTHIS_LOCK(locked); 00660 00661 this->m_use[phSystem_PIPELINE] = 1; 00662 objnode = this->m_pipelines.pushObject(pipeline); 00663 phCHECK_PTR(objnode,NULL,"m_pipelines.pushObject"); 00664 00665 /* TODO: Add ability to disable this feature */ 00666 /* this will start up the pipeline if the other pipelines are active */ 00667 if ((this->m_active[phSystem_PIPELINE]) && 00668 (this->m_autoMode != phMANUAL_MODE) && 00669 (autoStart)) 00670 { 00671 rc = this->startPipeline(pipeline); 00672 phPRINT_RC(rc,NULL,"this->startPipeline(%p)",pipeline); 00673 00674 if ((rc == phSUCCESS) && (this->m_active[phSystem_PIPELINE] == 0)) 00675 { 00676 this->m_active[phSystem_PIPELINE] = 1; 00677 } 00678 } 00679 00680 phTHIS_UNLOCK(locked); 00681 00682 return phSUCCESS; 00683 error: 00684 phTHIS_ERROR_UNLOCK(locked); 00685 00686 return phFAIL; 00687 } 00688 00689 /* ---------------------------------------------------------------------- */ 00690 int phSystem::addCapture(phCaptureInterface *capture,int autoStart) 00691 { 00692 phFUNCTION("phSystem::addCapture") 00693 phObjectNode *objnode = NULL; 00694 int locked = 0; 00695 00696 if (capture == NULL) return phFAIL; 00697 00698 phTHIS_LOCK(locked); 00699 00700 this->m_use[phSystem_CAPTURE] = 1; 00701 objnode = this->m_captures.pushObject(capture); 00702 phCHECK_PTR(objnode,NULL,"m_captures.pushObject"); 00703 00704 /* TODO: Add ability to disable this feature */ 00705 /* This will start up the capture if the other captures are active */ 00706 if ((this->m_active[phSystem_CAPTURE]) && 00707 (this->m_autoMode != phMANUAL_MODE) && 00708 (autoStart)) 00709 { 00710 rc = this->startCapture(capture); 00711 phPRINT_RC(rc,NULL,"this->startCaptures(%p)",capture); 00712 00713 if ((rc == phSUCCESS) && (this->m_active[phSystem_CAPTURE] == 0)) 00714 { 00715 this->m_active[phSystem_CAPTURE] = 1; 00716 } 00717 } 00718 00719 phTHIS_UNLOCK(locked); 00720 00721 return phSUCCESS; 00722 error: 00723 phTHIS_ERROR_UNLOCK(locked); 00724 00725 return phFAIL; 00726 } 00727 00728 /* ---------------------------------------------------------------------- */ 00729 int phSystem::addThread(phThread *thread,int autoStart) 00730 { 00731 phFUNCTION("phSystem::addThread") 00732 phObjectNode *objnode = NULL; 00733 int locked = 0; 00734 00735 if (thread == NULL) return phFAIL; 00736 00737 phTHIS_LOCK(locked); 00738 00739 this->m_use[phSystem_THREAD] = 1; 00740 objnode = this->m_threads.pushObject(thread); 00741 phCHECK_PTR(objnode,NULL,"m_threads.pushObject"); 00742 00743 /* This will start up the thread if the other threads are active */ 00744 if ((this->m_active[phSystem_THREAD]) && 00745 (this->m_autoMode != phMANUAL_MODE) && 00746 (autoStart)) 00747 { 00748 rc = thread->start(); 00749 phPRINT_RC(rc,NULL,"this->start(%p)",thread); 00750 00751 if ((rc == phSUCCESS) && (this->m_active[phSystem_THREAD] == 0)) 00752 { 00753 this->m_active[phSystem_THREAD] = 1; 00754 } 00755 } 00756 00757 phTHIS_UNLOCK(locked); 00758 00759 return phSUCCESS; 00760 error: 00761 phTHIS_ERROR_UNLOCK(locked); 00762 00763 return phFAIL; 00764 } 00765 00766 /* ---------------------------------------------------------------------- */ 00767 int phSystem::add( phObject *obj, int autoStart ) 00768 { 00769 phFUNCTION("phSystem::add") 00770 int locked = 0; 00771 00772 if (obj == NULL) return phFAIL; 00773 00774 phTHIS_LOCK(locked); 00775 00776 if (obj->hasParent("phPipeline")) 00777 { 00778 rc = this->addPipeline((phPipeline *)obj,autoStart); 00779 phCHECK_RC(rc,NULL,"this->addPipeline(%p,%d)",obj,autoStart); 00780 } 00781 else if (obj->hasParent("phCaptureInterface")) 00782 { 00783 rc = this->addCapture((phCaptureInterface *)obj,autoStart); 00784 phCHECK_RC(rc,NULL,"this->addCapture(%p,%d)",obj,autoStart); 00785 } 00786 else if (obj->hasParent("phDisplayInterface")) 00787 { 00788 rc = this->addDisplay((phDisplayInterface *)obj,autoStart); 00789 phCHECK_RC(rc,NULL,"this->addDisplay(%p,%d)",obj,autoStart); 00790 } 00791 else if (obj->hasParent("phThread")) 00792 { 00793 rc = this->addThread((phThread *)obj,autoStart); 00794 phCHECK_RC(rc,NULL,"this->addThread(%p,%d)",obj,autoStart); 00795 } 00796 else 00797 { 00798 phCHECK_RC(-1,NULL,"Can't determine the object type for %p",obj); 00799 } 00800 00801 phTHIS_UNLOCK(locked); 00802 00803 return phSUCCESS; 00804 error: 00805 00806 phTHIS_ERROR_UNLOCK(locked); 00807 return phFAIL; 00808 } 00809 00810 /* ---------------------------------------------------------------------- */ 00811 int phSystem::removeDisplay( phDisplayInterface *display, int autoStop ) 00812 { 00813 phFUNCTION("phSystem::removeDisplay") 00814 phObject *obj = NULL; 00815 int locked = 0; 00816 int is_empty = 0; 00817 00818 if (display == NULL) return phFAIL; 00819 00820 phTHIS_LOOSE_LOCK(locked); 00821 00822 obj = this->m_displays.removeObject(display); 00823 phCHECK_PTR(obj,NULL,"this->m_displays.removeObject"); 00824 00825 /* if (this->m_displays.length() == 0) */ 00826 if (this->m_displays.isEmpty()) 00827 { 00828 is_empty = 1; 00829 } 00830 00831 /* this will stop the display if the other displays are active */ 00832 if ((this->m_active[phSystem_DISPLAY]) && 00833 (this->m_autoMode != phMANUAL_MODE) && 00834 (autoStop)) 00835 { 00836 rc = this->stopDisplay(display); 00837 phPRINT_RC(rc,NULL,"this->stopDisplay(%p)",display); 00838 } 00839 00840 /* if the list is empty, then we're not using the feature in the system 00841 * and it can't have any active members, even if we're in phMANUAL_MODE */ 00842 if (is_empty) 00843 { 00844 this->m_use[phSystem_DISPLAY] = 0; 00845 this->m_active[phSystem_DISPLAY] = 0; 00846 } 00847 00848 phTHIS_UNLOCK(locked); 00849 00850 return phSUCCESS; 00851 error: 00852 phTHIS_ERROR_UNLOCK(locked); 00853 00854 return phFAIL; 00855 } 00856 00857 /* ---------------------------------------------------------------------- */ 00858 int phSystem::removePipeline( phPipeline *pipeline, int autoStop ) 00859 { 00860 phFUNCTION("phSystem::removePipeline") 00861 phObject *obj = NULL; 00862 int locked = 0; 00863 int is_empty = 0; 00864 00865 if (pipeline == NULL) return phFAIL; 00866 00867 phTHIS_LOCK(locked); 00868 00869 obj = this->m_pipelines.removeObject(pipeline); 00870 phCHECK_PTR(obj,NULL,"this->m_pipelines.removeObject"); 00871 00872 /*if (this->m_pipelines.length() == 0)*/ 00873 if (this->m_pipelines.isEmpty()) 00874 { 00875 is_empty = 1; 00876 } 00877 00878 /* this will stop the pipeline if the other pipelines are active */ 00879 if ((this->m_active[phSystem_PIPELINE]) && 00880 (this->m_autoMode != phMANUAL_MODE) && 00881 (autoStop)) 00882 { 00883 rc = this->stopPipeline(pipeline); 00884 phPRINT_RC(rc,NULL,"this->stopPipeline(%p)",pipeline); 00885 } 00886 00887 /* if the list is empty, then we're not using the feature in the system 00888 * and it can't have any active members, even if we're in phMANUAL_MODE */ 00889 if (is_empty) 00890 { 00891 this->m_use[phSystem_PIPELINE] = 0; 00892 this->m_active[phSystem_PIPELINE] = 0; 00893 } 00894 00895 phTHIS_UNLOCK(locked); 00896 00897 return phSUCCESS; 00898 error: 00899 phTHIS_ERROR_UNLOCK(locked); 00900 00901 return phFAIL; 00902 } 00903 00904 /* ---------------------------------------------------------------------- */ 00905 int phSystem::removeCapture( phCaptureInterface *capture, int autoStop ) 00906 { 00907 phFUNCTION("phSystem::removeCapture") 00908 phObject *obj = NULL; 00909 int locked = 0; 00910 int is_empty = 0; 00911 00912 if (capture == NULL) return phFAIL; 00913 00914 phTHIS_LOCK(locked); 00915 00916 obj = this->m_captures.removeObject(capture); 00917 phCHECK_PTR(obj,NULL,"this->m_captures.removeObject"); 00918 00919 /*if (this->m_captures.length() == 0)*/ 00920 if (this->m_captures.isEmpty()) 00921 { 00922 is_empty = 1; 00923 } 00924 00925 /* this will stop the capture if the other captures are active */ 00926 if ((this->m_active[phSystem_CAPTURE]) && 00927 (this->m_autoMode != phMANUAL_MODE) && 00928 (autoStop)) 00929 { 00930 rc = this->stopCapture(capture); 00931 phPRINT_RC(rc,NULL,"this->stopCapture(%p)",capture); 00932 } 00933 00934 /* if the list is empty, then we're not using the feature in the system 00935 * and it can't have any active members, even if we're in phMANUAL_MODE */ 00936 if (is_empty) 00937 { 00938 this->m_use[phSystem_CAPTURE] = 0; 00939 this->m_active[phSystem_CAPTURE] = 0; 00940 } 00941 00942 phTHIS_UNLOCK(locked); 00943 00944 return phSUCCESS; 00945 error: 00946 phTHIS_ERROR_UNLOCK(locked); 00947 00948 return phFAIL; 00949 } 00950 00951 /* ---------------------------------------------------------------------- */ 00952 int phSystem::removeThread( phThread *thread, int autoStop ) 00953 { 00954 phFUNCTION("phSystem::removeThread") 00955 phObject *obj = NULL; 00956 int locked = 0; 00957 int is_empty = 0; 00958 00959 if (thread == NULL) return phFAIL; 00960 00961 phTHIS_LOCK(locked); 00962 00963 obj = this->m_threads.removeObject(thread); 00964 phCHECK_PTR(obj,NULL,"this->m_threads.removeObject"); 00965 00966 /*if (this->m_threads.length() == 0)*/ 00967 if (this->m_threads.isEmpty()) 00968 { 00969 is_empty = 1; 00970 } 00971 00972 /* this will stop the thread if the other threads are active */ 00973 if ((this->m_active[phSystem_THREAD]) && 00974 (this->m_autoMode != phMANUAL_MODE) && 00975 (autoStop)) 00976 { 00977 rc = thread->stop(); 00978 phPRINT_RC(rc,NULL,"thread->stop(%p)",thread); 00979 } 00980 00981 /* if the list is empty, then we're not using the feature in the system 00982 * and it can't have any active members, even if we're in phMANUAL_MODE */ 00983 if (is_empty) 00984 { 00985 this->m_use[phSystem_THREAD] = 0; 00986 this->m_active[phSystem_THREAD] = 0; 00987 } 00988 00989 phTHIS_UNLOCK(locked); 00990 00991 return phSUCCESS; 00992 error: 00993 phTHIS_ERROR_UNLOCK(locked); 00994 00995 return phFAIL; 00996 } 00997 00998 /* ---------------------------------------------------------------------- */ 00999 int phSystem::remove( phObject *obj, int autoStop ) 01000 { 01001 phFUNCTION("phSystem::remove") 01002 int locked = 0; 01003 01004 if (obj == NULL) return phFAIL; 01005 01006 phTHIS_LOCK(locked); 01007 01008 if (obj->hasParent("phPipeline")) 01009 { 01010 rc = this->removePipeline((phPipeline *)obj,autoStop); 01011 phCHECK_RC(rc,NULL,"this->removePipeline(%p,%d)",obj,autoStop); 01012 } 01013 else if (obj->hasParent("phCaptureInterface")) 01014 { 01015 rc = this->removeCapture((phCaptureInterface *)obj,autoStop); 01016 phCHECK_RC(rc,NULL,"this->removeCapture(%p,%d)",obj,autoStop); 01017 } 01018 else if (obj->hasParent("phDisplayInterface")) 01019 { 01020 rc = this->removeDisplay((phDisplayInterface *)obj,autoStop); 01021 phCHECK_RC(rc,NULL,"this->removeDisplay(%p,%d)",obj,autoStop); 01022 } 01023 else if (obj->hasParent("phThread")) 01024 { 01025 rc = this->removeThread((phThread *)obj,autoStop); 01026 phCHECK_RC(rc,NULL,"this->removeThread(%p,%d)",obj,autoStop); 01027 } 01028 else 01029 { 01030 phCHECK_RC(-1,NULL,"Can't determine the object type for %p",obj); 01031 } 01032 01033 phTHIS_UNLOCK(locked); 01034 01035 return phSUCCESS; 01036 error: 01037 01038 phTHIS_ERROR_UNLOCK(locked); 01039 return phFAIL; 01040 } 01041 01042 /* ---------------------------------------------------------------------- */ 01043 int phSystem::removeDisplays() 01044 { 01045 phFUNCTION("phSystem::removeDisplays") 01046 int locked = 0; 01047 01048 phTHIS_LOOSE_LOCK(locked); 01049 01050 /* Shutdown displays if active */ 01051 if (this->m_active[phSystem_DISPLAY]) 01052 { 01053 rc = this->stopDisplays(); 01054 phPRINT_RC(rc,NULL,"this->stopDisplays()"); 01055 } 01056 01057 this->m_use[phSystem_DISPLAY] = 0; 01058 01059 rc = this->m_displays.empty(); 01060 phPRINT_RC(rc,NULL,"this->m_displays.empty()"); 01061 01062 01063 phTHIS_LOOSE_UNLOCK(locked); 01064 01065 return phSUCCESS; 01066 } 01067 01068 /* ---------------------------------------------------------------------- */ 01069 int phSystem::removePipelines() 01070 { 01071 phFUNCTION("phSystem::removePipelines") 01072 int locked = 0; 01073 01074 phTHIS_LOOSE_LOCK(locked); 01075 01076 /* Shutdown pipelines if active */ 01077 if (this->m_active[phSystem_PIPELINE]) 01078 { 01079 rc = this->stopPipelines(); 01080 phPRINT_RC(rc,NULL,"this->stopPipelines()"); 01081 } 01082 01083 this->m_use[phSystem_PIPELINE] = 0; 01084 01085 rc = this->m_pipelines.empty(); 01086 phPRINT_RC(rc,NULL,"this->m_pipelines.empty()"); 01087 01088 phTHIS_LOOSE_UNLOCK(locked); 01089 01090 return phSUCCESS; 01091 } 01092 01093 /* ---------------------------------------------------------------------- */ 01094 int phSystem::removeCaptures() 01095 { 01096 phFUNCTION("phSystem::removeCaptures") 01097 int locked = 0; 01098 01099 phTHIS_LOOSE_LOCK(locked); 01100 01101 01102 /* Shutdown captures if active */ 01103 if (this->m_active[phSystem_CAPTURE]) 01104 { 01105 rc = this->stopCaptures(); 01106 phPRINT_RC(rc,NULL,"this->stopCaptures()"); 01107 } 01108 01109 this->m_use[phSystem_CAPTURE] = 0; 01110 01111 rc = this->m_captures.empty(); 01112 phPRINT_RC(rc,NULL,"this->m_captures.empty()"); 01113 01114 01115 phTHIS_LOOSE_UNLOCK(locked); 01116 01117 return phSUCCESS; 01118 } 01119 01120 /* ---------------------------------------------------------------------- */ 01121 int phSystem::removeThreads() 01122 { 01123 phFUNCTION("phSystem::removeThreads") 01124 int locked = 0; 01125 01126 phTHIS_LOOSE_LOCK(locked); 01127 01128 /* Shutdown threads if active */ 01129 if (this->m_active[phSystem_THREAD]) 01130 { 01131 rc = this->stopThreads(); 01132 phPRINT_RC(rc,NULL,"this->stopThreads()"); 01133 } 01134 01135 this->m_use[phSystem_THREAD] = 0; 01136 01137 rc = this->m_threads.empty(); 01138 phPRINT_RC(rc,NULL,"this->m_threads.empty()"); 01139 01140 01141 phTHIS_LOOSE_UNLOCK(locked); 01142 01143 return phSUCCESS; 01144 } 01145 01146 /* ---------------------------------------------------------------------- */ 01147 int phSystem::removeAll() 01148 { 01149 phFUNCTION("phSystem::removeAll") 01150 int locked = 0; 01151 01152 phTHIS_LOOSE_LOCK(locked); 01153 01154 if (this->m_is_active > 0) 01155 { 01156 rc = this->shutdown(); 01157 phPRINT_RC(rc,NULL,"this->shutdown()"); 01158 } 01159 01160 this->m_is_active = 0; 01161 01162 rc = this->removeThreads(); 01163 phPRINT_RC(rc,NULL,"this->removeThreads()"); 01164 01165 rc = this->removeCaptures(); 01166 phPRINT_RC(rc,NULL,"this->removeCaptures()"); 01167 01168 rc = this->removePipelines(); 01169 phPRINT_RC(rc,NULL,"this->removePipelines()"); 01170 01171 rc = this->removeDisplays(); 01172 phPRINT_RC(rc,NULL,"this->removeDisplays()"); 01173 01174 01175 phTHIS_LOOSE_UNLOCK(locked); 01176 01177 return phSUCCESS; 01178 } 01179 01180 /* ---------------------------------------------------------------------- */ 01181 int phSystem::startDisplays( ) 01182 { 01183 phFUNCTION("phSystem::startDisplays") 01184 int locked = 0; 01185 int displays_locked = 0; 01186 phObjectNode *node = NULL; 01187 phDisplayInterface *display = NULL; 01188 uint32_t i = 0; 01189 01190 phTHIS_LOCK(locked); 01191 01192 /* -------------------------------------------------------------------- */ 01193 /* Startup the displays */ 01194 if (this->m_use[phSystem_DISPLAY] == 1) 01195 { 01196 phMUTEX_LOCK(this->m_displays,displays_locked); 01197 01198 node = this->m_displays.getHeadObject(); 01199 01200 /* Loop through all the displays in the list */ 01201 while (node != NULL) 01202 { 01203 display = (phDisplayInterface *)node->getObject(); 01204 01205 if (display != NULL) 01206 { 01207 rc = this->startDisplay(display); 01208 phPRINT_RC(rc,NULL,"Error opening display[%d] window",i); 01209 } 01210 01211 node = node->getNextObject(); 01212 i++; 01213 } 01214 01215 phMUTEX_UNLOCK(this->m_displays,displays_locked); 01216 01217 this->m_active[phSystem_DISPLAY] = 1; 01218 } 01219 01220 phTHIS_UNLOCK(locked); 01221 01222 return phSUCCESS; 01223 error: 01224 phMUTEX_ERROR_UNLOCK(this->m_displays,displays_locked); 01225 01226 phTHIS_ERROR_UNLOCK(locked); 01227 01228 return phFAIL; 01229 } 01230 01231 /* ---------------------------------------------------------------------- */ 01232 int phSystem::startPipelines() 01233 { 01234 phFUNCTION("phSystem::startPipelines") 01235 int locked = 0; 01236 int pipelines_locked = 0; 01237 phObjectNode *node = NULL; 01238 phPipeline *pipeline = NULL; 01239 uint32_t i = 0; 01240 01241 phTHIS_LOCK(locked); 01242 01243 /* -------------------------------------------------------------------- */ 01244 /* Start the pipeline processing */ 01245 if (this->m_use[phSystem_PIPELINE] == 1) 01246 { 01247 phMUTEX_LOCK(this->m_pipelines,pipelines_locked); 01248 01249 node = this->m_pipelines.getHeadObject(); 01250 01251 /* Loop through all the pipelines in the list */ 01252 while (node != NULL) 01253 { 01254 pipeline = (phPipeline *)node->getObject(); 01255 01256 rc = this->startPipeline(pipeline); 01257 phCHECK_RC(rc,NULL, "Error starting pipeline[%d]",i); 01258 01259 node = node->getNextObject(); 01260 i++; 01261 } 01262 01263 phMUTEX_UNLOCK(this->m_pipelines,pipelines_locked); 01264 01265 this->m_active[phSystem_PIPELINE] = 1; 01266 } 01267 01268 phTHIS_UNLOCK(locked); 01269 01270 return phSUCCESS; 01271 error: 01272 phMUTEX_ERROR_UNLOCK(this->m_pipelines,pipelines_locked); 01273 01274 phTHIS_ERROR_UNLOCK(locked); 01275 01276 return phFAIL; 01277 } 01278 01279 /* ---------------------------------------------------------------------- */ 01280 int phSystem::startCaptures() 01281 { 01282 phFUNCTION("phSystem::startCaptures") 01283 int locked = 0; 01284 int captures_locked = 0; 01285 phObjectNode *node = NULL; 01286 phCaptureInterface *capture = NULL; 01287 uint32_t i = 0; 01288 01289 phTHIS_LOCK(locked); 01290 01291 /* -------------------------------------------------------------------- */ 01292 /* make sure the capture device is open */ 01293 if (this->m_use[phSystem_CAPTURE] == 1) 01294 { 01295 phMUTEX_LOCK(this->m_captures,captures_locked); 01296 01297 node = this->m_captures.getHeadObject(); 01298 01299 /* Loop through all the captures in the list */ 01300 while (node != NULL) 01301 { 01302 capture = (phCaptureInterface *)node->getObject(); 01303 01304 rc = this->startCapture(capture); 01305 phCHECK_RC(rc,NULL,"Error starting capture[%d] thread", i ); 01306 01307 node = node->getNextObject(); 01308 i++; 01309 } 01310 01311 phMUTEX_UNLOCK(this->m_captures,captures_locked); 01312 01313 this->m_active[phSystem_CAPTURE] = 1; 01314 } 01315 01316 phTHIS_UNLOCK(locked); 01317 01318 return phSUCCESS; 01319 error: 01320 phMUTEX_ERROR_UNLOCK(this->m_captures,captures_locked); 01321 01322 phTHIS_ERROR_UNLOCK(locked); 01323 01324 return phFAIL; 01325 } 01326 01327 /* ---------------------------------------------------------------------- */ 01328 int phSystem::startThreads() 01329 { 01330 phFUNCTION("phSystem::startThreads") 01331 int locked = 0; 01332 int threads_locked = 0; 01333 phObjectNode *node = NULL; 01334 phThread *thread = NULL; 01335 uint32_t i = 0; 01336 01337 phTHIS_LOCK(locked); 01338 01339 /* -------------------------------------------------------------------- */ 01340 /* make sure the thread device is running */ 01341 if (this->m_use[phSystem_THREAD] == 1) 01342 { 01343 phMUTEX_LOCK(this->m_threads,threads_locked); 01344 01345 node = this->m_threads.getHeadObject(); 01346 01347 /* Loop through all the threads in the list */ 01348 while (node != NULL) 01349 { 01350 thread = (phThread *)node->getObject(); 01351 01352 rc = this->startThread(thread); 01353 phCHECK_RC(rc,NULL,"Error starting thread[%d] thread", i ); 01354 01355 node = node->getNextObject(); 01356 i++; 01357 } 01358 01359 phMUTEX_UNLOCK(this->m_threads,threads_locked); 01360 01361 this->m_active[phSystem_THREAD] = 1; 01362 } 01363 01364 phTHIS_UNLOCK(locked); 01365 01366 return phSUCCESS; 01367 error: 01368 phMUTEX_ERROR_UNLOCK(this->m_threads,threads_locked); 01369 01370 phTHIS_ERROR_UNLOCK(locked); 01371 01372 return phFAIL; 01373 } 01374 01375 /* ---------------------------------------------------------------------- */ 01376 int phSystem::startup() 01377 { 01378 phFUNCTION("phSystem::startup") 01379 int locked = 0; 01380 01381 phTHIS_LOCK(locked); 01382 01383 rc = this->startDisplays(); 01384 phCHECK_RC(rc,NULL,"this->startDisplays()"); 01385 01386 rc = this->startPipelines(); 01387 phCHECK_RC(rc,NULL,"this->startPipelines()"); 01388 01389 rc = this->startCaptures(); 01390 phCHECK_RC(rc,NULL,"this->startCaptures()"); 01391 01392 rc = this->startThreads(); 01393 phCHECK_RC(rc,NULL,"this->startThreads()"); 01394 01395 this->m_is_active = 2; 01396 01397 phTHIS_UNLOCK(locked); 01398 01399 return phSUCCESS; 01400 error: 01401 phTHIS_ERROR_UNLOCK(locked); 01402 01403 return phFAIL; 01404 } 01405 01406 /* ---------------------------------------------------------------------- */ 01407 int phSystem::haltThreads() 01408 { 01409 phFUNCTION("phSystem::haltThreads") 01410 int locked = 0; 01411 int threads_locked = 0; 01412 phObjectNode *node = NULL; 01413 phThread *thread = NULL; 01414 01415 phTHIS_LOOSE_LOCK(locked); 01416 01417 /* -------------------------------------------------------------------- */ 01418 /* Stop capturing if there is capturing in progress */ 01419 if (this->m_use[phSystem_THREAD] == 1) 01420 { 01421 phMUTEX_LOOSE_LOCK(this->m_threads,threads_locked); 01422 01423 node = this->m_threads.getHeadObject(); 01424 01425 /* Loop through all the threads in the list */ 01426 while (node != NULL) 01427 { 01428 thread = (phThread *)node->getObject(); 01429 01430 rc = this->haltThread(thread); 01431 phPRINT_RC(rc,NULL,"this->haltThread failed."); 01432 01433 node = node->getNextObject(); 01434 } 01435 01436 phMUTEX_LOOSE_UNLOCK(this->m_threads,threads_locked); 01437 01438 this->m_active[phSystem_THREAD] = 1; 01439 } 01440 01441 phTHIS_LOOSE_UNLOCK(locked); 01442 01443 return phSUCCESS; 01444 } 01445 01446 /* ---------------------------------------------------------------------- */ 01447 int phSystem::haltCaptures() 01448 { 01449 phFUNCTION("phSystem::haltCaptures") 01450 int locked = 0; 01451 int captures_locked = 0; 01452 phObjectNode *node = NULL; 01453 phCaptureInterface *capture = NULL; 01454 01455 phTHIS_LOOSE_LOCK(locked); 01456 01457 /* -------------------------------------------------------------------- */ 01458 /* Stop capturing if there is capturing in progress */ 01459 if (this->m_use[phSystem_CAPTURE] == 1) 01460 { 01461 phMUTEX_LOOSE_LOCK(this->m_captures,captures_locked); 01462 01463 node = this->m_captures.getHeadObject(); 01464 01465 /* Loop through all the captures in the list */ 01466 while (node != NULL) 01467 { 01468 capture = (phCaptureInterface *)node->getObject(); 01469 01470 rc = this->haltCapture(capture); 01471 phPRINT_RC(rc,NULL,"this->haltCapture failed."); 01472 01473 node = node->getNextObject(); 01474 } 01475 01476 phMUTEX_LOOSE_UNLOCK(this->m_captures,captures_locked); 01477 01478 this->m_active[phSystem_CAPTURE] = 1; 01479 } 01480 01481 phTHIS_LOOSE_UNLOCK(locked); 01482 01483 return phSUCCESS; 01484 } 01485 01486 /* ---------------------------------------------------------------------- */ 01487 int phSystem::haltPipelines() 01488 { 01489 phFUNCTION("phSystem::haltPipelines") 01490 int locked = 0; 01491 int pipelines_locked = 0; 01492 phObjectNode *node = NULL; 01493 phPipeline *pipeline = NULL; 01494 01495 phTHIS_LOOSE_LOCK(locked); 01496 01497 /* -------------------------------------------------------------------- */ 01498 /* Turn off the pipelines */ 01499 if (this->m_use[phSystem_PIPELINE] == 1) 01500 { 01501 phMUTEX_LOOSE_LOCK(this->m_pipelines,pipelines_locked); 01502 01503 node = this->m_pipelines.getHeadObject(); 01504 01505 /* Loop through all the pipelines in the list */ 01506 while (node != NULL) 01507 { 01508 pipeline = (phPipeline *)node->getObject(); 01509 01510 rc = this->haltPipeline(pipeline); 01511 phPRINT_RC(rc,NULL,"this->stopPipeline failed"); 01512 01513 node = node->getNextObject(); 01514 } 01515 01516 phMUTEX_LOOSE_UNLOCK(this->m_pipelines,pipelines_locked); 01517 01518 this->m_active[phSystem_PIPELINE] = 0; 01519 } 01520 01521 phTHIS_LOOSE_UNLOCK(locked); 01522 01523 return phSUCCESS; 01524 } 01525 01526 /* ---------------------------------------------------------------------- */ 01527 int phSystem::haltDisplays() 01528 { 01529 phFUNCTION("phSystem::haltDisplays") 01530 int locked = 0; 01531 int displays_locked = 0; 01532 phObjectNode *node = NULL; 01533 phDisplayInterface *display = NULL; 01534 01535 phTHIS_LOOSE_LOCK(locked); 01536 01537 /* -------------------------------------------------------------------- */ 01538 /* Stop all the display threads */ 01539 if (this->m_use[phSystem_DISPLAY] == 1) 01540 { 01541 phMUTEX_LOOSE_LOCK(this->m_displays,displays_locked); 01542 01543 node = this->m_displays.getHeadObject(); 01544 01545 /* Loop through all the displays in the list */ 01546 while (node != NULL) 01547 { 01548 display = (phDisplayInterface *)node->getObject(); 01549 01550 rc = this->haltDisplay(display); 01551 phPRINT_RC(rc,NULL,"this->haltDisplay failed"); 01552 01553 node = node->getNextObject(); 01554 } 01555 01556 phMUTEX_LOOSE_UNLOCK(this->m_displays,displays_locked); 01557 } 01558 01559 phTHIS_LOOSE_UNLOCK(locked); 01560 01561 return phSUCCESS; 01562 } 01563 01564 /* ---------------------------------------------------------------------- */ 01565 int phSystem::halt() 01566 { 01567 phFUNCTION("phSystem::halt") 01568 int locked = 0; 01569 01570 phTHIS_LOOSE_LOCK(locked); 01571 01572 rc = this->haltThreads(); 01573 phPRINT_RC(rc,NULL,"this->haltThreads()"); 01574 01575 rc = this->haltCaptures(); 01576 phPRINT_RC(rc,NULL,"this->haltCaptures()"); 01577 01578 rc = this->haltDisplays(); 01579 phPRINT_RC(rc,NULL,"this->haltDisplays()"); 01580 01581 rc = this->haltPipelines(); 01582 phPRINT_RC(rc,NULL,"this->haltPipelines()"); 01583 01584 this->m_is_active = 1; 01585 01586 phTHIS_LOOSE_UNLOCK(locked); 01587 01588 return phSUCCESS; 01589 } 01590 01591 /* ---------------------------------------------------------------------- */ 01592 int phSystem::stopThreads() 01593 { 01594 phFUNCTION("phSystem::stopThreads") 01595 int locked = 0; 01596 int threads_locked = 0; 01597 phObjectNode *node = NULL; 01598 phThread *thread = NULL; 01599 01600 phTHIS_LOOSE_LOCK(locked); 01601 01602 /* -------------------------------------------------------------------- */ 01603 /* Stop capturing if there is capturing in progress */ 01604 if (this->m_use[phSystem_THREAD] == 1) 01605 { 01606 phMUTEX_LOOSE_LOCK(this->m_threads,threads_locked); 01607 01608 node = this->m_threads.getHeadObject(); 01609 01610 /* Loop through all the threads in the list */ 01611 while (node != NULL) 01612 { 01613 thread = (phThread *)node->getObject(); 01614 01615 rc = thread->stop(); 01616 phPRINT_RC(rc,NULL,"thread->stop()"); 01617 01618 node = node->getNextObject(); 01619 } 01620 01621 phMUTEX_LOOSE_UNLOCK(this->m_threads,threads_locked); 01622 01623 this->m_active[phSystem_THREAD] = 0; 01624 } 01625 01626 phTHIS_LOOSE_UNLOCK(locked); 01627 01628 return phSUCCESS; 01629 } 01630 01631 /* ---------------------------------------------------------------------- */ 01632 int phSystem::stopCaptures() 01633 { 01634 phFUNCTION("phSystem::stopCaptures") 01635 int locked = 0; 01636 int captures_locked = 0; 01637 phObjectNode *node = NULL; 01638 phCaptureInterface *capture = NULL; 01639 01640 phTHIS_LOOSE_LOCK(locked); 01641 01642 /* -------------------------------------------------------------------- */ 01643 /* Stop capturing if there is capturing in progress */ 01644 if (this->m_use[phSystem_CAPTURE] == 1) 01645 { 01646 phMUTEX_LOOSE_LOCK(this->m_captures,captures_locked); 01647 01648 node = this->m_captures.getHeadObject(); 01649 01650 /* Loop through all the captures in the list */ 01651 while (node != NULL) 01652 { 01653 capture = (phCaptureInterface *)node->getObject(); 01654 01655 rc = this->stopCapture(capture); 01656 phPRINT_RC(rc,NULL,"this->stopCapture failed"); 01657 01658 node = node->getNextObject(); 01659 } 01660 01661 phMUTEX_LOOSE_UNLOCK(this->m_captures,captures_locked); 01662 01663 this->m_active[phSystem_CAPTURE] = 0; 01664 } 01665 01666 phTHIS_LOOSE_UNLOCK(locked); 01667 01668 return phSUCCESS; 01669 } 01670 01671 /* ---------------------------------------------------------------------- */ 01672 int phSystem::stopPipelines() 01673 { 01674 phFUNCTION("phSystem::stopPipelines") 01675 int locked = 0; 01676 01677 phTHIS_LOOSE_LOCK(locked); 01678 01679 rc = this->haltPipelines(); 01680 phPRINT_RC(rc,NULL,"this->haltPipelines()"); 01681 01682 this->m_active[phSystem_PIPELINE] = 0; 01683 01684 phTHIS_LOOSE_UNLOCK(locked); 01685 01686 return phSUCCESS; 01687 } 01688 01689 /* ---------------------------------------------------------------------- */ 01690 int phSystem::stopDisplays() 01691 { 01692 phFUNCTION("phSystem::stopDisplays") 01693 int locked = 0; 01694 int displays_locked = 0; 01695 phObjectNode *node = NULL; 01696 phDisplayInterface *display = NULL; 01697 01698 phTHIS_LOOSE_LOCK(locked); 01699 01700 /* -------------------------------------------------------------------- */ 01701 /* Stop all the display threads */ 01702 if (this->m_use[phSystem_DISPLAY] == 1) 01703 { 01704 phMUTEX_LOOSE_LOCK(this->m_displays,displays_locked); 01705 01706 node = this->m_displays.getHeadObject(); 01707 01708 /* Loop through all the displays in the list */ 01709 while (node != NULL) 01710 { 01711 display = (phDisplayInterface *)node->getObject(); 01712 01713 rc = this->stopDisplay(display); 01714 phPRINT_RC(rc,NULL,"this->stopDisplay failed."); 01715 01716 node = node->getNextObject(); 01717 } 01718 01719 phMUTEX_LOOSE_UNLOCK(this->m_displays,displays_locked); 01720 01721 this->m_active[phSystem_DISPLAY] = 0; 01722 } 01723 01724 phTHIS_LOOSE_UNLOCK(locked); 01725 01726 return phSUCCESS; 01727 } 01728 01729 /* ---------------------------------------------------------------------- */ 01730 int phSystem::shutdown() 01731 { 01732 phFUNCTION("phSystem::shutdown") 01733 int locked = 0; 01734 01735 phTHIS_LOOSE_LOCK(locked); 01736 01737 rc = this->stopThreads(); 01738 phPRINT_RC(rc,NULL,"this->stopThreads()"); 01739 01740 rc = this->stopCaptures(); 01741 phPRINT_RC(rc,NULL,"this->stopCaptures()"); 01742 01743 rc = this->stopPipelines(); 01744 phPRINT_RC(rc,NULL,"this->stopPipelines()"); 01745 01746 rc = this->stopDisplays(); 01747 phPRINT_RC(rc,NULL,"this->stopDisplays()"); 01748 01749 this->m_is_active = 0; 01750 01751 phTHIS_LOOSE_UNLOCK(locked); 01752 01753 return phSUCCESS; 01754 }
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |