src/Socket.h
author František Kučera <franta-hg@frantovo.cz>
Thu, 28 Jul 2022 02:45:11 +0200
branchv_0
changeset 3 e701e06ff561
parent 2 fb399fd4f053
child 4 8d036e5e5fcc
permissions -rw-r--r--
add some factories: generic/template version

/**
 * Relational pipes
 * Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once

#include <string>
#include <cstring>
#include <unistd.h>
#include <stdexcept>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

namespace relpipe {
namespace out {
namespace socket {

class Socket {
public:
	virtual ~Socket() = default;
	// virtual void setOption(const std::string& uri, const std::string& value) = 0;
	virtual void send(const std::string& message) = 0;
	virtual const std::string receive() = 0;
};

class SocketFactory {
public:
	virtual ~SocketFactory() = default;
	virtual bool canHandle(const std::string& connectionString) = 0;
	// virtual void setOption(const std::string& uri, const std::string& value) = 0;
	virtual Socket* open(const std::string& connectionString) = 0;
	static std::shared_ptr<SocketFactory> find(const std::string& connectionString);
};


}
}
}