Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef TTCPIP_H
Toshihiro Shimizu 890ddd
#define TTCPIP_H
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
#include <qthread></qthread>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef TFARMAPI
Toshihiro Shimizu 890ddd
#undef TFARMAPI
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#ifdef TFARM_EXPORTS
Toshihiro Shimizu 890ddd
#define TFARMAPI __declspec(dllexport)
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TFARMAPI __declspec(dllimport)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TFARMAPI
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TTcpIpServerImp;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TFARMAPI TTcpIpServer : public QThread {
Shinya Kitaoka 120a6e
  int m_exitCode;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TTcpIpServer(int port);
Shinya Kitaoka 120a6e
  virtual ~TTcpIpServer();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getPort() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void run();
Shinya Kitaoka 120a6e
  int shutdown();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void onReceive(int socket, const QString &data) = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void sendReply(int socket, const QString &reply);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getExitCode() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  std::shared_ptr<ttcpipserverimp> m_imp;</ttcpipserverimp>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
enum {
Shinya Kitaoka 120a6e
  OK,
Shinya Kitaoka 120a6e
  STARTUP_FAILED,
Shinya Kitaoka 120a6e
  HOST_UNKNOWN,
Shinya Kitaoka 120a6e
  SOCKET_CREATION_FAILED,
Shinya Kitaoka 120a6e
  CONNECTION_FAILED,
Shinya Kitaoka 120a6e
  CONNECTION_REFUSED,
Shinya Kitaoka 120a6e
  CONNECTION_TIMEDOUT,
Shinya Kitaoka 120a6e
  SEND_FAILED,
Shinya Kitaoka 120a6e
  RECEIVE_FAILED
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TFARMAPI TTcpIpClient {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TTcpIpClient();
Shinya Kitaoka 120a6e
  ~TTcpIpClient();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int connect(const QString &name, const QString &addr, int port, int &sock);
Shinya Kitaoka 120a6e
  int disconnect(int sock);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int send(int sock, const QString &data);
Shinya Kitaoka 120a6e
  int send(int sock, const QString &data, QString &reply);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif