fix error handling in Camera::getDescription()
This commit is contained in:
		
							parent
							
								
									b7352f53bb
								
							
						
					
					
						commit
						cc6bccad08
					
				
					 2 changed files with 29 additions and 12 deletions
				
			
		
							
								
								
									
										33
									
								
								uvoscam.cpp
									
										
									
									
									
								
							
							
						
						
									
										33
									
								
								uvoscam.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -284,6 +284,7 @@ std::vector<Camera::Description> Camera::getAvailableCameras(bool update)
 | 
			
		|||
{
 | 
			
		||||
	if(!scanned_ || update)
 | 
			
		||||
	{
 | 
			
		||||
		arv_enable_interface("Fake");
 | 
			
		||||
		arv_update_device_list();
 | 
			
		||||
		scanned_ = true;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -351,6 +352,7 @@ Camera::~Camera()
 | 
			
		|||
	}
 | 
			
		||||
	if(ARV_IS_CAMERA(aCamera_))
 | 
			
		||||
		g_object_unref(aCamera_);
 | 
			
		||||
	delete description;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Camera::isOpen()
 | 
			
		||||
| 
						 | 
				
			
			@ -461,17 +463,26 @@ void Camera::trigger()
 | 
			
		|||
 | 
			
		||||
Camera::Description Camera::getDescription()
 | 
			
		||||
{
 | 
			
		||||
	Description desc;
 | 
			
		||||
	if(ARV_IS_CAMERA(aCamera_))
 | 
			
		||||
	if(!description)
 | 
			
		||||
	{
 | 
			
		||||
		GError* error;
 | 
			
		||||
		desc.vendor = arv_camera_get_vendor_name(aCamera_, &error);
 | 
			
		||||
		desc.serial = arv_camera_get_device_serial_number(aCamera_, &error);
 | 
			
		||||
		desc.id     = arv_camera_get_device_id(aCamera_, &error);
 | 
			
		||||
		desc.model= arv_camera_get_model_name(aCamera_, &error);
 | 
			
		||||
		if(!error)
 | 
			
		||||
			return desc;
 | 
			
		||||
		else return Description();
 | 
			
		||||
		if(ARV_IS_CAMERA(aCamera_))
 | 
			
		||||
		{
 | 
			
		||||
			description = new Description;
 | 
			
		||||
			GError* error = nullptr;
 | 
			
		||||
			if(!error)
 | 
			
		||||
				description->vendor = arv_camera_get_vendor_name(aCamera_, &error);
 | 
			
		||||
			if(!error)
 | 
			
		||||
				description->serial = arv_camera_get_device_serial_number(aCamera_, &error);
 | 
			
		||||
			if(!error)
 | 
			
		||||
				description->id     = arv_camera_get_device_id(aCamera_, &error);
 | 
			
		||||
			if(!error)
 | 
			
		||||
				description->model  = arv_camera_get_model_name(aCamera_, &error);
 | 
			
		||||
			if(error)
 | 
			
		||||
			{
 | 
			
		||||
				delete description;
 | 
			
		||||
				description = nullptr;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return desc;
 | 
			
		||||
	return description ? *description : Description();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,6 +39,8 @@ public:
 | 
			
		|||
	
 | 
			
		||||
	class Description
 | 
			
		||||
	{
 | 
			
		||||
	private:
 | 
			
		||||
		size_t hash = 0;
 | 
			
		||||
	public:
 | 
			
		||||
		std::string vendor;
 | 
			
		||||
		std::string serial;
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +49,9 @@ public:
 | 
			
		|||
		
 | 
			
		||||
		size_t getHash() const
 | 
			
		||||
		{
 | 
			
		||||
			return std::hash<std::string>{}(vendor + serial + id + model);
 | 
			
		||||
			//if(hash == 0)
 | 
			
		||||
				return /*hash =*/ std::hash<std::string>{}(vendor + serial + id + model);
 | 
			
		||||
			//return hash;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		bool operator==(const Description& in) const
 | 
			
		||||
| 
						 | 
				
			
			@ -83,6 +87,8 @@ private:
 | 
			
		|||
	ArvStream* aStream_ = nullptr;
 | 
			
		||||
	ArvCamera* aCamera_ = nullptr;
 | 
			
		||||
	
 | 
			
		||||
	Description* description = nullptr;
 | 
			
		||||
	
 | 
			
		||||
	unsigned int width_;
 | 
			
		||||
	unsigned int height_;
 | 
			
		||||
	int64_t format = -1;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue