00001 #include "CameraManager.H" 00002 #include "Camera.H" 00003 00004 CameraManager::CameraManager() : error(DC1394_SUCCESS), d(NULL) { 00005 error = initialize(); 00006 } 00007 00008 CameraManager::~CameraManager() { 00009 /*for (std::vector<uint64_t>::size_type i = 0; i < freeCameraList.size(); i++) { 00010 dc1394_capture_stop(freeCameraList[i]); 00011 dc1394_camera_free(freeCameraList[i]); 00012 }*/ 00013 if (d) dc1394_free(d); 00014 } 00015 00016 dc1394error_t CameraManager::initialize() { 00017 dc1394error_t err; 00018 00019 d = dc1394_new(); 00020 if (!d) { 00021 err = DC1394_FAILURE; 00022 DC1394_ERR_RTN(err, "Failed to create new dc1394"); 00023 } 00024 00025 err = dc1394_camera_enumerate(d, &list); 00026 DC1394_ERR_RTN(err, "Failed to enumerate cameras"); 00027 00028 if (list->num == 0) { 00029 err = DC1394_CAMERA_NOT_INITIALIZED; 00030 DC1394_ERR_RTN(err, "No cameras found"); 00031 } 00032 00033 return DC1394_SUCCESS; 00034 } 00035 00036 std::vector<uint64_t> CameraManager::getCameraList() { 00037 std::vector<uint64_t> tempList; 00038 for (uint32_t i = 0; i < list->num; i++) { 00039 tempList.push_back(list->ids[i].guid); 00040 } 00041 return tempList; 00042 } 00043 00044 Camera* CameraManager::getCamera(uint64_t guid) { 00045 dc1394camera_t* camera1394 = NULL; 00046 dc1394error_t err; 00047 if (!setupSuccessful()) return NULL; 00048 for (uint32_t i = 0; i < list->num; i++) { 00049 if (list->ids[i].guid == guid) { 00050 00051 camera1394 = dc1394_camera_new(d, list->ids[i].guid); 00052 if (!camera1394) { 00053 err = DC1394_CAMERA_NOT_INITIALIZED; 00054 DC1394_WRN(err, "Failed to initialize camera"); 00055 } else { 00056 err = dc1394_reset_bus(camera1394); 00057 DC1394_WRN(err, "Failed to reset bus for camera"); 00058 } 00059 break; 00060 } 00061 } 00062 00063 if (!camera1394) return NULL; 00064 else return new Camera(camera1394); 00065 } 00066 00067 bool CameraManager::setupSuccessful() { 00068 return error == DC1394_SUCCESS; 00069 } 00070