src/PosixMQHandler.h
branchv_0
changeset 7 68b93b82f1cc
parent 5 5a6828cfad41
equal deleted inserted replaced
6:b0b7b6f1bc88 7:68b93b82f1cc
    51 	} currentRelation;
    51 	} currentRelation;
    52 
    52 
    53 public:
    53 public:
    54 
    54 
    55 	PosixMQHandler(Configuration configuration) : configuration(configuration) {
    55 	PosixMQHandler(Configuration configuration) : configuration(configuration) {
       
    56 		// TODO: do not throw exception from the constructor: PosixMQ::open()
    56 		mq.reset(PosixMQ::open(convertor.to_bytes(configuration.queue), configuration.unlinkOnClose));
    57 		mq.reset(PosixMQ::open(convertor.to_bytes(configuration.queue), configuration.unlinkOnClose));
    57 	}
    58 	}
    58 
    59 
    59 	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
    60 	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
    60 		currentRelation = CurrentRelation{name, attributes};
    61 		currentRelation = CurrentRelation{name, attributes};
    61 	}
    62 	}
    62 
    63 
    63 	void attribute(const relpipe::common::type::StringX& value) override {
    64 	void attribute(const relpipe::common::type::StringX& value) override {
    64 
    65 
    65 		auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName();
    66 		auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName();
    66 		if (attributeName == L"text") currentRelation.currentValue = convertor.to_bytes(value);
    67 		if (attributeName == L"text" && value.size()) currentRelation.currentValue = convertor.to_bytes(value);
    67 		else if (attributeName == L"data") currentRelation.currentValue = Hex::fromHex(value).str();
    68 		else if (attributeName == L"data" && value.size()) currentRelation.currentValue = Hex::fromHex(value).str();
       
    69 		else if (attributeName == L"text"); // keep empty or value from 'data'
       
    70 		else if (attributeName == L"data"); // keep empty or value from 'text'
    68 
    71 
    69 		currentRelation.attributeIndex++;
    72 		currentRelation.attributeIndex++;
    70 		if (currentRelation.attributeIndex == currentRelation.attributes.size()) {
    73 		if (currentRelation.attributeIndex == currentRelation.attributes.size()) {
    71 			currentRelation.attributeIndex = 0;
    74 			currentRelation.attributeIndex = 0;
    72 			mq->send(currentRelation.currentValue);
    75 			mq->send(currentRelation.currentValue);