factory.cpp
00001 00002 /*************************************************************************** 00003 * factory.cpp - Camera control factory 00004 * 00005 * Created: Fri Jun 15 13:11:28 2007 00006 * Copyright 2005-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program 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 Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <cams/control/factory.h> 00025 #include <fvutils/system/camargp.h> 00026 #include <core/exceptions/software.h> 00027 00028 #include <cams/control/color.h> 00029 #include <cams/control/image.h> 00030 #include <cams/control/effect.h> 00031 #include <cams/control/focus.h> 00032 #include <cams/control/pantilt.h> 00033 #include <cams/control/zoom.h> 00034 #include <cams/control/source.h> 00035 #include <cams/control/dummy.h> 00036 #include <cams/cam_exceptions.h> 00037 00038 #ifdef HAVE_VISCA_CTRL 00039 #include <cams/control/visca.h> 00040 #endif 00041 #ifdef HAVE_EVID100P_CTRL 00042 #include <cams/control/sony_evid100p.h> 00043 #endif 00044 #ifdef HAVE_DPPTU_CTRL 00045 #include <cams/control/dp_ptu.h> 00046 #endif 00047 00048 #include <typeinfo> 00049 00050 using namespace std; 00051 00052 /** @class CameraControlFactory <cams/control/factory.h> 00053 * Camera control factory. 00054 * This camera control factory provides access to all camera controls in a unified way. 00055 * You just supply a camera argument string and depending on the camera ID and compile-time 00056 * support of camera control types an instance of the desired camera control is 00057 * returned or otherwise an exception is thrown. See instance() for a list of 00058 * supported camera control types. 00059 * 00060 * @author Tim Niemueller 00061 */ 00062 00063 /** Get camera control instance with parameters from given camera argument parser. 00064 * This is a convenience method and works like instace(const char *as). 00065 * @param cap camera argument parser 00066 * @return camera instance 00067 * @exception UnknownCameraControlTypeException thrown if camera type is not known or 00068 * was not available at build time. 00069 */ 00070 CameraControl * 00071 CameraControlFactory::instance(const CameraArgumentParser *cap) 00072 { 00073 CameraControl *c = NULL; 00074 00075 // ###### 00076 if ( cap->cam_type() == "evid100p" ) { 00077 #ifdef HAVE_EVID100P_CTRL 00078 c = new SonyEviD100PControl(cap); 00079 #else 00080 throw UnknownCameraControlTypeException("No EviD100P/Visca support at compile time"); 00081 #endif 00082 } 00083 00084 // ###### 00085 if ( cap->cam_type() == "dpptu" ) { 00086 #ifdef HAVE_DPPTU_CTRL 00087 c = new DPPTUControl(cap); 00088 #else 00089 throw UnknownCameraControlTypeException("No DPPTU support at compile time"); 00090 #endif 00091 } 00092 00093 // ###### 00094 if ( cap->cam_type() == "dummy" ) { 00095 c = new DummyCameraControl(); 00096 } 00097 00098 if ( c == NULL ) { 00099 throw UnknownCameraControlTypeException(); 00100 } 00101 00102 return c; 00103 } 00104 00105 00106 /** Get camera control instance. 00107 * Get an instance of a camera of the given type. The argument string determines 00108 * the type of camera to open. 00109 * Supported camera types: 00110 * - evid100p, SonyEviD100PControl, compiled if HAVE_EVID100P_CTRL is defined in fvconf.mk 00111 * - dpptu, DPPTUControl, compiled if HAVE_DPPTU_CTRL is defined in fvconf.mk 00112 * @param as camera argument string 00113 * @return camera control instance of requested type 00114 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could 00115 * not be instantiated. This could be either to a misspelled camera ID, generally 00116 * missing support or unset definition due to configuration in fvconf.mk or missing 00117 * libraries and camera support compile-time autodetection. 00118 */ 00119 CameraControl * 00120 CameraControlFactory::instance(const char *as) 00121 { 00122 CameraArgumentParser *cap = new CameraArgumentParser(as); 00123 try { 00124 return instance(cap); 00125 } catch (UnknownCameraControlTypeException &e) { 00126 throw; 00127 } 00128 } 00129 00130 00131 /** Get camera control instance. 00132 * Get an instance of a camera control from the passed camera. 00133 * It is tried to cast the camera to the appropriate camera control type. If that 00134 * succeeds the camera control is returned, otherwise an exception is thrown. 00135 * @param camera camera to cast 00136 * @return camera control instance. 00137 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could 00138 * not be instantiated. This could be either to a misspelled camera ID, generally 00139 * missing support or unset definition due to configuration in fvconf.mk or missing 00140 * libraries and camera support compile-time autodetection. 00141 */ 00142 CameraControl * 00143 CameraControlFactory::instance(Camera *camera) 00144 { 00145 CameraControl *c = dynamic_cast<CameraControl *>(camera); 00146 if (c) { 00147 return c; 00148 } else { 00149 throw fawkes::TypeMismatchException("Camera does not provide requested camera control"); 00150 } 00151 } 00152 00153 00154 /** Get camera control instance. 00155 * Get an instance of a camera of the given type based on the given camera. 00156 * It is tried to cast the camera to the appropriate camera control type. If that 00157 * succeeds the camera control is returned, otherwise an exception is thrown. 00158 * @param typeinf type info for the intended type of the camera control 00159 * @param camera camera to cast 00160 * @return camera control instance of requested type 00161 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could 00162 * not be instantiated. This could be either to a misspelled camera ID, generally 00163 * missing support or unset definition due to configuration in fvconf.mk or missing 00164 * libraries and camera support compile-time autodetection. 00165 */ 00166 CameraControl * 00167 CameraControlFactory::instance(const std::type_info &typeinf, Camera *camera) 00168 { 00169 CameraControl *c = NULL; 00170 00171 if (typeid(CameraControlColor) == typeinf) { 00172 c = dynamic_cast<CameraControlColor *>(camera); 00173 00174 } else if (typeid(CameraControlImage) == typeinf) { 00175 c = dynamic_cast<CameraControlImage *>(camera); 00176 00177 } else if (typeid(CameraControlPanTilt) == typeinf) { 00178 c = dynamic_cast<CameraControlPanTilt *>(camera); 00179 00180 } else if (typeid(CameraControlFocus) == typeinf) { 00181 c = dynamic_cast<CameraControlFocus *>(camera); 00182 00183 } else if (typeid(CameraControlZoom) == typeinf) { 00184 c = dynamic_cast<CameraControlZoom *>(camera); 00185 00186 } else if (typeid(CameraControlEffect) == typeinf) { 00187 c = dynamic_cast<CameraControlEffect *>(camera); 00188 00189 } else if (typeid(CameraControlSource) == typeinf) { 00190 c = dynamic_cast<CameraControlSource *>(camera); 00191 00192 } else { 00193 throw UnknownCameraControlTypeException(); 00194 } 00195 00196 if (c) { 00197 return c; 00198 } else { 00199 throw fawkes::TypeMismatchException("Camera does not provide requested camera control"); 00200 } 00201 }

