// +-------------------------------- DISCLAIMER ---------------------------------+
// |                                                                             |
// | This program is provided to you free of charge "as such".                   |
// | You should not assume that this program is error-free or suitable for any   |
// | purpose whatsoever.                                                         |
// |                                                                             |
// | EURESYS does not give any representation, warranty or undertaking that this |
// | program is free of any defect or error or suitable for any purpose. EURESYS |
// | shall not be liable, in contract, in torts or otherwise, for any damages,   |
// | loss, costs, expenses or other claims for compensation, including those     |
// | asserted by third parties, arising out of or in connection with the use of  |
// | this program.                                                               |
// +-----------------------------------------------------------------------------+

#ifndef CAMERAHANDLER_H
#define CAMERAHANDLER_H

#include <atomic>
#include <condition_variable>
#include <memory>
#include <thread>
#include <vector>
#include <neoapi/neoapi.hpp>
#include <string>

#include "EasyImage.h"

using namespace Euresys::Open_eVision;

// emulates a camera by "reading" the same image ten times per second
class CameraHandler
{
public:
  CameraHandler();
  ~CameraHandler();
  void launchCamera();
  void run();

  void getImage(EImageBW8& image);
  bool isAborted();

private:
  std::mutex processImageMutex_;
  std::condition_variable canProcessImage_;

  uint8_t* data_;
  uint32_t width_;
  uint32_t height_;
  uint32_t pitch_;
  std::atomic<bool> abort_;

  std::thread cameraThread_;
  NeoAPI::Cam camera_;
  std::unique_ptr<EImageBW8> buffer_;

  // make non-copyable
  CameraHandler( const CameraHandler& );
  CameraHandler& operator=( const CameraHandler& );
};

#endif // CAMERAHANDLER_H


