/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com

Copyright (c) 2010 I-maginer

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

You may alternatively use this source under the terms of a specific version of
the OpenSpace3D Unrestricted License provided you have obtained such a license from
I-maginer.
-----------------------------------------------------------------------------
*/

/*! \class OptitrackCamera
  *  \brief Optitrack camera handling.
  *  \
  *  \version 1.0
  *  \date may 2011
  */

#ifndef __OPTITRACKCAMERA_H__
#define __OPTITRACKCAMERA_H__

#include "../lib/common.h"
#include "../core/Thread.h"

// Pre declaration (used by OptitrackCameraManager).
class OptitrackCamera;

/*!
Manager handling the list of cameras
*/
class OptitrackCameraManager
{
public:
protected:
private:
  static OptitrackCameraManager* _singleton;
  CameraManager* manager;
  OptitrackCameraMap listOfCameras;

public:
  /*!
  */
  static OptitrackCameraManager* GetInstance();
  
  /*!
  */
  static void Kill();
  
  /*!
  */
  CameraManager* GetManager();
  
  /*!
  */
  bool GetValidCamera(OptitrackCamera* camera);
  
  /*!
  */
  void RemoveCamera(OptitrackCamera* camera);
  
  /*!
  */
  OptitrackCamera* AddCamera();

  /*!
  Destructor
  */
  ~OptitrackCameraManager();
protected:
private:
  /*!
  Use GetInstance instead of this constructor.
  */
  OptitrackCameraManager();

  /*!
  */
  void AddValidCamera(OptitrackCamera* camera);
  
  /*!
  */
  void RemoveValidCamera(OptitrackCamera* camera);

  /*!
  */
  unsigned int CreateId();
};

/*!
Single camera 
*/
class OptitrackCamera : public Optitrack::Core::Thread
{
public:
protected:
private:
  unsigned int mId;
  int mExposure;
  int mIntensity;
  int mVideoMode;
  bool bConnected;
  Camera* mCamera;
  Frame* mFrame;

public:
  /*!
  Constructor
  */
  OptitrackCamera(unsigned int id);

  /*!
  Destructor
  */
  ~OptitrackCamera();

  /*!
  Get the camera's id.
  */
  unsigned int GetId();

  /*!
  Get the intensity factor of the camera
  */
  int GetIntensity();

  /*!
  Get the exposure factor of the camera
  */
  int GetExposure();

  /*!
  Is the camera connected or not?
  */
  bool IsConnected();

  /*!
  Get the current video mode of the camera.
  */
  int GetVideoMode();

  /*!
  Set the intensity factor of the camera
  */
  void SetIntensity(int intensity);

  /*!
  Set the exposure factor of the camera
  */
  void SetExposure(int exposure);

  /*!
  Set the video mode of the camera.
  */
  void SetVideoMode(int videoMode);

  /*!
  Thread loop.
  */
  void GoThread();
protected:
private:
  /*!
  */
  void OpenCamera();
  
  /*!
  */
  void CloseCamera();
  
  /*!
  Forbiden constructor.
  */
  OptitrackCamera();
};

#endif
