Skip to content
Base_Protocol.h 1.15 KiB
Newer Older
Valerio Pastore's avatar
Valerio Pastore committed
/*
 *
 *  Created on: Mar 1, 2021
 *      Author: astrisw
 *
 */

#ifndef BASEPROTOCOL_H_
#define BASEPROTOCOL_H_

#include <iostream>
#include <netinet/in.h>

Valerio Pastore's avatar
Valerio Pastore committed
#include <Base_Packet.h>
Valerio Pastore's avatar
Valerio Pastore committed

namespace inaf::oasbo::ConnectionProtocols{
Valerio Pastore's avatar
Valerio Pastore committed
/*
 * class BaseSocket
 * Implementation of a socket that allows to communicate with the sender.
 * This parent class must be inherited in order to implement your own protocol,
 * methods connect() and readPacket must be overridden
 *
 * @member field host: address of the host machine
 * @member field port: listen port
 * @member field protocol: communication protocol.
 */
class BaseProtocol{
protected:
	std::string host;
public:

	virtual std::string getHost() = 0;
	virtual void setHost(std::string host) = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	virtual int connectToServer()=0;
Valerio Pastore's avatar
Valerio Pastore committed
	virtual int connectToClient()=0;
	virtual int closeConnectionToServer()=0;
	virtual int closeConnectionToClient()=0;
	virtual bool isConnectedToClient() const =0;
	virtual bool isConnectedToServer() const =0;
	virtual int receiveFromClient(PacketLib::BasePacket &) = 0;
	virtual int sendToServer(PacketLib::BasePacket &) = 0;
	virtual ~BaseProtocol() = default;
Valerio Pastore's avatar
Valerio Pastore committed
};
Valerio Pastore's avatar
Valerio Pastore committed
#endif /* BASEPROTOCOL_H_ */