factory.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <cams/factory.h>
00025 #include <fvutils/system/camargp.h>
00026
00027 #ifdef HAVE_FIREWIRE_CAM
00028 #include <cams/firewire.h>
00029 #endif
00030 #ifdef HAVE_LEUTRON_CAM
00031 #include <cams/leutron.h>
00032 #endif
00033 #ifdef HAVE_FILELOADER_CAM
00034 #include <cams/fileloader.h>
00035 #endif
00036 #ifdef HAVE_SHMEM_CAM
00037 #include <cams/shmem.h>
00038 #endif
00039 #ifdef HAVE_NETWORK_CAM
00040 #include <cams/net.h>
00041 #endif
00042 #ifdef HAVE_V4L_CAM
00043 #include <cams/v4l.h>
00044 #endif
00045 #ifdef HAVE_V4L1_CAM
00046 #include <cams/v4l1.h>
00047 #endif
00048 #ifdef HAVE_V4L2_CAM
00049 #include <cams/v4l2.h>
00050 #endif
00051 #ifdef HAVE_NAO_CAM
00052 #include <cams/nao.h>
00053 #endif
00054 #ifdef HAVE_BUMBLEBEE2_CAM
00055 #include <cams/bumblebee2.h>
00056 #endif
00057
00058 using namespace std;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 Camera *
00078 CameraFactory::instance(const CameraArgumentParser *cap)
00079 {
00080 Camera *c = NULL;
00081
00082
00083 if ( cap->cam_type() == "firewire" ) {
00084 #ifdef HAVE_FIREWIRE_CAM
00085 c = new FirewireCamera(cap);
00086 #else
00087 throw UnknownCameraTypeException("No firewire support at compile time");
00088 #endif
00089 }
00090
00091
00092 if ( cap->cam_type() == "leutron" ) {
00093 #ifdef HAVE_LEUTRON_CAM
00094 c = new LeutronCamera();
00095 #else
00096 throw UnknownCameraTypeException("No Leutron support at compile time");
00097 #endif
00098 }
00099
00100
00101 if ( cap->cam_type() == "file" ) {
00102 #ifdef HAVE_FILELOADER_CAM
00103 c = new FileLoader(cap);
00104 #else
00105 throw UnknownCameraTypeException("No file loader support at compile time");
00106 #endif
00107 }
00108
00109
00110 if ( cap->cam_type() == "shmem" ) {
00111 #ifdef HAVE_SHMEM_CAM
00112 c = new SharedMemoryCamera(cap);
00113 #else
00114 throw UnknownCameraTypeException("No shared memory support at compile time");
00115 #endif
00116 }
00117
00118
00119 if ( cap->cam_type() == "net" ) {
00120 #ifdef HAVE_NETWORK_CAM
00121 c = new NetworkCamera(cap);
00122 #else
00123 throw UnknownCameraTypeException("No network support at compile time");
00124 #endif
00125 }
00126
00127
00128 if ( cap->cam_type() == "v4l" ) {
00129 #ifdef HAVE_V4L_CAM
00130 c = new V4LCamera(cap);
00131 #else
00132 throw UnknownCameraTypeException("No video4linux support at compile time");
00133 #endif
00134 }
00135
00136
00137 if ( cap->cam_type() == "v4l1" ) {
00138 #ifdef HAVE_V4L1_CAM
00139 c = new V4L1Camera(cap);
00140 #else
00141 throw UnknownCameraTypeException("No video4linux1 support at compile time");
00142 #endif
00143 }
00144
00145
00146 if ( cap->cam_type() == "v4l2" ) {
00147 #ifdef HAVE_V4L2_CAM
00148 c = new V4L2Camera(cap);
00149 #else
00150 throw UnknownCameraTypeException("No video4linux2 support at compile time");
00151 #endif
00152 }
00153
00154
00155 if ( cap->cam_type() == "nao" ) {
00156 #ifdef HAVE_NAO_CAM
00157 c = new NaoCamera(cap);
00158 #else
00159 throw UnknownCameraTypeException("No nao camera support at compile time");
00160 #endif
00161 }
00162
00163
00164 if ( cap->cam_type() == "bumblebee2" ) {
00165 #ifdef HAVE_BUMBLEBEE2_CAM
00166 c = new Bumblebee2Camera(cap);
00167 #else
00168 throw UnknownCameraTypeException("No Bumblebee 2 support at compile time");
00169 #endif
00170 }
00171
00172 if ( c == NULL ) {
00173 throw UnknownCameraTypeException();
00174 }
00175
00176 return c;
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 Camera *
00198 CameraFactory::instance(const char *as)
00199 {
00200 CameraArgumentParser *cap = new CameraArgumentParser(as);
00201 try {
00202 Camera *cam = instance(cap);
00203 delete cap;
00204 return cam;
00205 } catch (UnknownCameraTypeException &e) {
00206 delete cap;
00207 throw;
00208 }
00209 }