src/SocketHandler.h
branchv_0
changeset 4 8d036e5e5fcc
parent 3 e701e06ff561
child 5 e57e2a2798b2
equal deleted inserted replaced
3:e701e06ff561 4:8d036e5e5fcc
    48 		std::vector<relpipe::reader::handlers::AttributeMetadata> attributes;
    48 		std::vector<relpipe::reader::handlers::AttributeMetadata> attributes;
    49 		relpipe::common::type::Integer attributeIndex = 0;
    49 		relpipe::common::type::Integer attributeIndex = 0;
    50 		std::string currentValue;
    50 		std::string currentValue;
    51 	} currentRelation;
    51 	} currentRelation;
    52 
    52 
       
    53 	void configureSocket() {
       
    54 		if (socket) {
       
    55 			// already configured, reuse
       
    56 		} else {
       
    57 			std::vector<SocketOption> options;
       
    58 			for (auto o : configuration.options) options.push_back({convertor.to_bytes(o.name), convertor.to_bytes(o.value)});
       
    59 			const std::string connectionString = convertor.to_bytes(configuration.connectionString);
       
    60 			if (auto f = SocketFactory::find(connectionString)) socket = f->open(connectionString);
       
    61 		}
       
    62 	}
       
    63 
    53 public:
    64 public:
    54 
    65 
    55 	SocketHandler(Configuration configuration) : configuration(configuration) {
    66 	SocketHandler(Configuration configuration) : configuration(configuration) {
    56 		// TODO: do not throw exception from the constructor: Socket::open()
       
    57 		// socket = std::make_shared<TCPSocket>(); // TODO: create a TCP, UDP… socket
       
    58 		socket.reset(SocketFactory::find("tcp://TODO:connectionString")->open("tcp://TODO:connectionString2")); // TODO: connection string + check nullptr
       
    59 	}
    67 	}
    60 
    68 
    61 	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
    69 	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
       
    70 		configureSocket();
    62 		currentRelation = CurrentRelation{name, attributes};
    71 		currentRelation = CurrentRelation{name, attributes};
    63 	}
    72 	}
    64 
    73 
    65 	void attribute(const relpipe::common::type::StringX& value) override {
    74 	void attribute(const relpipe::common::type::StringX& value) override {
    66 
    75