Program Listing for File Cola2Session.h

Return to documentation for file (/tmp/ws/src/sick_safetyscanners_base/include/sick_safetyscanners_base/cola2/Cola2Session.h)

// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-

// -- BEGIN LICENSE BLOCK ----------------------------------------------

// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
//----------------------------------------------------------------------

#ifndef SICK_SAFETYSCANNERS_BASE_COLA2_COLA2SESSION_H
#define SICK_SAFETYSCANNERS_BASE_COLA2_COLA2SESSION_H

#include "sick_safetyscanners_base/Exceptions.h"
#include "sick_safetyscanners_base/datastructure/PacketBuffer.h"

#include "sick_safetyscanners_base/communication/TCPClient.h"

#include "sick_safetyscanners_base/cola2/CloseSession.h"
#include "sick_safetyscanners_base/cola2/Command.h"
#include "sick_safetyscanners_base/cola2/CreateSession.h"

#include "sick_safetyscanners_base/data_processing/ParseTCPPacket.h"
#include "sick_safetyscanners_base/data_processing/TCPPacketMerger.h"

#include <boost/optional.hpp>

namespace sick {
namespace cola2 {

class Command;
class CreateSession;

class Cola2Session
{
public:
  explicit Cola2Session(communication::TCPClientPtr tcp_client);

  // Deleted default, copy and copy-assignment constructors.
  Cola2Session()                    = delete;
  Cola2Session(const Cola2Session&) = delete;
  Cola2Session& operator=(const Cola2Session&) = delete;

  void sendCommand(Command& cmd,
                   sick::types::time_duration_t timeout = boost::posix_time::seconds(5));

  boost::optional<uint32_t> getSessionID() const;

  uint16_t getNextRequestID();

  void setSessionID(uint32_t session_id);

  void open();

  void close();

private:
  uint16_t m_request_id;
  boost::optional<uint32_t> m_session_id;
  communication::TCPClientPtr m_tcp_client_ptr;


  void assembleAndSendTelegram(Command& cmd);

  bool isOpen() const;

  sick::datastructure::PacketBuffer receiveAndProcessResponse(Command& cmd,
                                                              sick::types::time_duration_t timeout);
};

} // namespace cola2
} // namespace sick

#endif // SICK_SAFETYSCANNERS_BASE_COLA2_COLA2SESSION_H