Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phCaptureInterface.cpp

Go to the documentation of this file.
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 <phStdint.h>
00031 #include <phStandard.h>
00032 
00033 #include <phObject.h>
00034 #include <phMutex.h>
00035 #include <phSemaphore.h>
00036 #include <phCondition.h>
00037 #include <phRWLock.h>
00038 #include <phThread.h>
00039 #include <phList.h>
00040 #include <phTimeStamp.h>
00041 #include <phTimeInterval.h>
00042 #include <phLiveObject.h>
00043 #include <phDataObject.h>
00044 #include <phImage.h>
00045 
00046 #include <phCaptureInterface.h>
00047 
00048 #include <phError.h>
00049 #include <phMemory.h>
00050 #include <phPrint.h>
00051 
00052 /* ---------------------------------------------------------------------- */
00053 phCaptureInterface::phCaptureInterface()
00054 {
00055     setName("phCaptureInterface");
00056     
00057     this->m_liveSourceOutput = NULL;
00058     
00059     /* initialize the path information */
00060     this->m_path = NULL;
00061     this->m_path_size = 0;
00062 }
00063 
00064 /* ---------------------------------------------------------------------- */
00065 phCaptureInterface::~phCaptureInterface()
00066 {
00067     /* Free the buffer used for the device/path information */
00068     phFree(this->m_path);
00069     this->m_path_size = 0;
00070 
00071     this->m_liveSourceOutput = NULL;
00072 }
00073 
00074 /* ---------------------------------------------------------------------- */
00075 /* setPath - This allows setting of the device name apart from passing
00076  * it as an argument of open.
00077  *
00078  * phFAIL - failed to set the path
00079  * phSUCCESS - successfully set the path
00080  * 1 - the path wasn't set because it's already set as something or
00081  * the length of the parameter was NULL/""
00082  */
00083 /* ---------------------------------------------------------------------- */
00084 int phCaptureInterface::setPath( const char *path )
00085 {
00086     phFUNCTION("phCaptureInterface::setPath")
00087     int locked = 0;
00088     int length = ((path == NULL) ? 0 : strlen(path));
00089     int retrc = phSUCCESS;
00090 
00091     if (length == 0) return 1;
00092     
00093     rc = this->m_settings_lock.lock();
00094     phCHECK_RC(rc,NULL,"this->m_settings_lock.lock() failed");
00095     locked = 1;
00096    
00097     /* Don't set the path if it's null or of 0 length...
00098      * We should never get here anyway */
00099     if ((path != NULL) && (length > 0))
00100     {
00101         int same = 1;
00102         if (this->m_path != NULL)
00103         {
00104             if (strcmp(this->m_path,path) != 0)
00105             {
00106                 same = 0;
00107             }
00108         }
00109         else
00110         {
00111             same = 0;
00112         }
00113         if (same == 0)
00114         {
00115             phDALLOC_RESIZE(this->m_path,
00116                             this->m_path_size,
00117                             length + 1, /* NULL byte */
00118                             char );
00119             
00120             sprintf(this->m_path,"%s",path);
00121         }
00122         else
00123         {
00124             retrc = 1;
00125         }
00126     }
00127     
00128     if (locked)
00129     {
00130         rc = this->m_settings_lock.unlock();
00131         locked = 0;
00132         phCHECK_RC(rc,NULL,"this->m_settings_lock.unlock() failed");
00133     }
00134     
00135     return retrc;
00136 error:
00137     if (locked == 1)
00138     {
00139         rc = this->m_settings_lock.unlock();
00140         phPRINT_RC(rc,NULL,"this->m_settings_lock.unlock() failed");
00141         locked = 0;
00142     }
00143     
00144     return phFAIL;
00145 }
00146 
00147 /* ---------------------------------------------------------------------- */
00148 const char *phCaptureInterface::getPath( )
00149 {
00150     return (const char *)this->m_path;
00151 }
00152 
00153 /* ---------------------------------------------------------------------- */
00154 /* on close, the class retains all previous knowledge
00155  * except the device capabilities. */
00156 /* ---------------------------------------------------------------------- */
00157 int phCaptureInterface::open(char *path )
00158 {
00159     phFUNCTION("phCaptureInterface::open")
00160     phCHECK_RC(-1,NULL,"This function isn't implemented.");
00161 error:
00162     return phFAIL;
00163 }
00164 
00165 /* ---------------------------------------------------------------------- */
00166 int phCaptureInterface::close()
00167 {
00168     phFUNCTION("phCaptureInterface::close")
00169     phCHECK_RC(-1,NULL,"This function isn't implemented.");
00170 error:
00171     return phFAIL;
00172 }
00173 
00174 /* ---------------------------------------------------------------------- */
00175 int phCaptureInterface::isOpen()
00176 {
00177     phFUNCTION("phCaptureInterface::isOpen")
00178     phCHECK_RC(-1,NULL,"This function isn't implemented.");
00179 error:
00180     return phFAIL;
00181 }
00182 
00183 /* ---------------------------------------------------------------------- */
00184 int phCaptureInterface::setup()
00185 {
00186     phFUNCTION("phCaptureInterface::setup")
00187     
00188     /* We have the lock here, we release it in "::run" */
00189     if (!this->isOpen())
00190     {
00191         rc = this->open();
00192         phCHECK_RC(rc,NULL,"this->open()");
00193     }
00194     
00195     return phSUCCESS;  
00196 error:
00197     return phFAIL;
00198 }
00199 
00200 /* ---------------------------------------------------------------------- */
00201 int phCaptureInterface::cleanup()
00202 {
00203     phFUNCTION("phCaptureInterface::cleanup")
00204     
00205     /* Close should obtain the lock if necessary */
00206     if (this->isOpen())
00207     {
00208         rc = this->close();
00209         phCHECK_RC(rc,NULL,"this->close()");
00210     }
00211 
00212     return phSUCCESS;
00213 error:
00214     return phFAIL;  
00215 }
00216   
00217 /* ---------------------------------------------------------------------- */
00218 int phCaptureInterface::isCapturing()
00219 {
00220     /* Changed this to just "isRunning" cause if the thread exits, then
00221      * it will call 'cleanup' which closes the capture object */
00222     /* return ((this->isRunning() || (!this->threadStopped())) ? 1 : 0); */
00223     return this->isRunning();
00224 }
00225 
00226 /* ---------------------------------------------------------------------- */
00227 int phCaptureInterface::setLiveSourceOutput( phLiveObject *liveSourceOutput )
00228 {
00229     phFUNCTION("phCaptureInterface::setLiveSourceOutput")
00230     
00231     rc = this->lock();
00232     phPRINT_RC(rc,NULL,"this->lock()");
00233     
00234     this->m_liveSourceOutput = liveSourceOutput;
00235     
00236     rc = this->unlock();
00237     phPRINT_RC(rc,NULL,"this->unlock()");
00238 
00239     return phSUCCESS;
00240 }
00241 /* ---------------------------------------------------------------------- */
00242 int phCaptureInterface::setSource( phLiveObject *source )
00243 {
00244     return this->setLiveSourceOutput(source);
00245 }
00246 /* ---------------------------------------------------------------------- */
00247 int phCaptureInterface::setOutput( phLiveObject *output )
00248 {
00249     return this->setLiveSourceOutput(output);
00250 }
00251 
00252 /* ---------------------------------------------------------------------- */
00253 phLiveObject *phCaptureInterface::getLiveSourceOutput()
00254 {
00255     return this->m_liveSourceOutput;
00256 }
00257 /* ---------------------------------------------------------------------- */
00258 phLiveObject *phCaptureInterface::getSource()
00259 {
00260     return this->getLiveSourceOutput();
00261 }
00262 /* ---------------------------------------------------------------------- */
00263 phLiveObject *phCaptureInterface::getOutput()
00264 {
00265     return this->getLiveSourceOutput();
00266 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:02 2007 for phission by  doxygen 1.4.4