///////////////////////////////////////////////////////////
//  IndiClient.h
//  Implementation of the Class IndiClient
//  Created on:      16-May-2017 2:43:00 PM
//  Original author: Marco De Pascale
///////////////////////////////////////////////////////////

// #if !defined(EA_667996D2_4520_4731_B41A_1A112E44B65C__INCLUDED_)
// #define EA_667996D2_4520_4731_B41A_1A112E44B65C__INCLUDED_

#ifndef _INDICLIENT_H
#define _INDICLIENT_H

#include <vector>
#include <string>
#include <iterator>
#include <algorithm>

// #include "listenerThread.h"

#include <IndiMessage.hpp>
#include <IndiXmlParser.hpp>
#include <SystemSocket.hpp>
#include <IndiElement.hpp>
#include <IndiProperty.hpp>

#include <Nice/Log.h>

//#include "shins_util.h"

#define INDI_PROTOCOL_VERSION	"1.23"
using namespace pcf;

class IndiClient//: public listenerThread
{
 private:
  std::string m_host;// = "127.0.0.1";
  /**
   * Default INDI port
   */
  int m_port;// = 7624;
  /**
   * Handler for socket connection
   */
  SystemSocket m_socketConn;
  //shins::PtrMutex m_mutexCount;
  // private:
  //   void erase_new_line(std::string &str);

public:
  IndiClient();
  IndiClient(int port);
  IndiClient(std::string host);
  IndiClient(int port, std::string host);
  virtual ~IndiClient();
  int connect();
  int close();
  int is_valid();

  inline void set_port(const int& _port) {m_port = _port;}
  inline void set_host(const std::string& _host) {m_host = _host;}

  int send_new_property(const IndiProperty &, int *_counter, IceUtil::Mutex *_mtxCount);
  int send_get_property(const IndiProperty &, int *_counter, IceUtil::Mutex *_mtxCount);

  int send_get_properties(const std::vector<IndiProperty> &);
  int get_socket_fd();
  int recv_xml(std::string &);
  int cb_recv_xml(std::string &, const int &);
  int send_new_property2(const IndiProperty &,
			 IndiClient &,
			 int (IndiClient::*)(std::string &, const int &),
			 std::string &, const int &);

  int send_new_property3(const IndiProperty &,
			 IndiClient &,
			 int (IndiClient::*)(std::string &),
			 std::string &);
  int send_get_property3(const IndiProperty &,
			 IndiClient &,
			 int (IndiClient::*)(std::string &),
			 std::string &);
};

#endif //_INDICLIENT_H

// #endif // !defined(EA_667996D2_4520_4731_B41A_1A112E44B65C__INCLUDED_)
