tcp_monitor_client.h 1.72 KB
Newer Older
fmg005's avatar
fmg005 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#ifndef TCP_MONITOR_CLIENT_H
#define TCP_MONITOR_CLIENT_H

#include <sys/types.h>
#include <sys/socket.h> /* socket functions */
#include <sys/time.h>  /* FD_SET, FD_ISSET, FD_ZERO, timeval, fd_set */
#include <sys/select.h>/* select() */
#include <stdio.h>
#include <stdlib.h> /* exit, EXIT_FAILURE */
#include <string.h> /* memcpy */
#include <unistd.h>
#include <netdb.h> /* gethostbyname */
#include <netinet/in.h>/* sockaddr_in */
#include <iostream>
#include <memory>
#include "CLA_Logger.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"

using namespace rapidjson; /* third party library for parsing json data */
using namespace std;

namespace CLA {
  class tcp_monitor_client {
    /* impementation of a non-blocking tcp client to talk
    *  to the rosbridge udp server
    */
    private:
      struct hostent *hp; /* host information */
      struct sockaddr_in servaddr; /* server address information */
      struct timeval timeout;
      string json_message;
      string m_topic;
      string m_type;
      const char* m_host;
      int port;
      int fd, rec_value,recvlen;
      int SOCKET_TIMEOUT_SEC;
      int SOCKET_TIMEOUT_uSEC;
      socklen_t addrlen;
      Document document; /* to parse json data */
43
      Value m_patient_data;
fmg005's avatar
fmg005 committed
44
      Value _topic;
fmg005's avatar
fmg005 committed
45 46 47 48 49 50
      StringBuffer strbuf;
      fd_set set; /* descriptor read set*/
      std::shared_ptr<CLA::LOGGER> m_logger;
    public:
      tcp_monitor_client(std::shared_ptr<CLA::LOGGER>&, const string&, const string&);
      ~tcp_monitor_client();
51
      void setup_connection();
52 53
      void send_data_to_server(const string&);
      void publish_patient_data(const string&);
fmg005's avatar
fmg005 committed
54 55 56 57 58 59
      void waiting_to_send();
      void clear();
  };
}

#endif