// +-------------------------------- 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 <condition_variable>
#include <thread>
#include <memory>
#include <vector>
#include <string>

struct buffer {
  void   *start;
  size_t  length;
};

namespace Euresys
{
  namespace Open_eVision
  {
    class EImageBW8;
    class EImageC24;
  }
}

class CameraHandler
{
public:
  CameraHandler(const std::string& params = "");
  ~CameraHandler();
  void launchCamera();
  void run();

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

  uint8_t* data_;
  uint32_t width_;
  uint32_t height_;
  uint32_t pitch_;
  bool abort_;

private:
  int cameraFileDescriptor_;
  std::vector<buffer> cameraBuffers_;
  std::thread cameraThread_;

  // needed because of bayerisation
  uint32_t cameraPitch_;
  std::unique_ptr<Euresys::Open_eVision::EImageBW8> tmpBayer8Bits_;
  std::unique_ptr<Euresys::Open_eVision::EImageC24> buffer_;

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

#endif // CAMERAHANDLER_H


