Example #1
0
bool DEProtoProxy::get_Image(void* image, unsigned int length)
{
	boost::lock_guard<boost::mutex>(*this->server->getTransactionMutex());

	DEPacket pkt, dataHeader;
	pkt.set_type(DEPacket::P_COMMAND);
	SingleCommand* cmd = pkt.add_command();
	cmd->set_command_id(k_GetImage);

	this->sendCommand(pkt);
	this->receiveFromServer(dataHeader);
	if (dataHeader.type() != DEPacket::P_DATA_HEADER ||
		!dataHeader.has_data_header()) 
		BOOST_THROW_EXCEPTION(ProtocolException() << errorMessage("Did not receive expected data header for image."));
	
	this->imgBuffer.resizeIfNeeded(static_cast<std::size_t>(dataHeader.data_header().bytesize()));

	if (!this->server->receive(this->imgBuffer.getBufferPtr(), static_cast<std::size_t>(dataHeader.data_header().bytesize()), this->imageTimeout))
	{
		BOOST_THROW_EXCEPTION(CommunicationException() << errorMessage("Unable to receive image from server."));
	}

	if (dataHeader.data_header().bytesize() != length)
	{
		BOOST_THROW_EXCEPTION(CommandException() << errorMessage ("Image received did not have the expected size"));
	}

	memcpy(image, this->imgBuffer.getBufferPtr(), length);

	return true;
}
Example #2
0
void PacketCreator::addSingleCommand(DEPacket& message, type cmdVal)
{
	message.set_type(DEPacket::P_COMMAND);
	SingleCommand* cmd = message.add_command();
	cmd->set_command_id(cmdVal);

	vector<Param>::iterator  it;
	for (it = this->_params.begin(); it != this->_params.end(); it++)
	{
		AnyParameter* param = cmd->add_parameter();
		this->setAnyParameter(param, *it);
	}

	if (!this->_persistent) this->clear();
}