Пример #1
0
            bool bus_read(zmqpp::socket &sub, Content... content)
            {
                zmqpp::message msg;

                if (!sub.receive(msg))
                    return false;
                return bus_read_extract(&msg, content...);
            }
Пример #2
0
            /**
            * Check that we can read a rpleth from the socket and check that its valid.
            */
            void check_rpleth_card_msg(zmqpp::socket &source, const std::vector<uint8_t> card_binary)
            {
                zmqpp::message msg;
                std::string connection_identity, data;

                source.receive(msg);
                msg >> connection_identity;
                msg >> data; // data we would read from socket
                RplethPacket rpleth_packet = extract_packet(data);

                ASSERT_TRUE(rpleth_packet.isGood);
                ASSERT_EQ(8, +rpleth_packet.dataLen);
                ASSERT_EQ(8, +rpleth_packet.data.size());

                ASSERT_EQ(card_binary, rpleth_packet.data);
            }
Пример #3
0
void try_set(zmqpp::socket& socket, zmqpp::socket_option const& option, CheckType const& value, std::string const& option_name, std::string const& value_type)
{
    BOOST_CHECKPOINT("setting option " << option_name << " against set type '" << value_type << "'");
    try
    {
        socket.set(option, value);
        BOOST_CHECK_MESSAGE(typeid(CheckType) == typeid(WantedType), "expected exception setting option '" << option_name << "' against type '" << value_type << "'");
    }
    catch(zmqpp::zmq_internal_exception const& e)
    {
        BOOST_CHECK_MESSAGE(false, "threw internal exception " << e.zmq_error() << " '" << e.what() << "' setting option '" << option_name << "' against type '" << value_type << "'");
    }
    catch(zmqpp::exception const& e)
    {
        BOOST_CHECK_MESSAGE(typeid(CheckType) != typeid(WantedType), "threw unexpected exception '" << e.what() << "' setting option '" << option_name << "' against type '" << value_type << "'");
    }
}
Пример #4
0
void YacasKernel::Request::reply(zmqpp::socket& socket, const std::string& msg_type, const Json::Value& content) const
{
    Json::Value header;
    header["username"] = "******";
    header["version"] = "5.0";
    header["session"] = boost::uuids::to_string(_session.uuid());
    header["date"]  = now();
    header["msg_id"] = boost::uuids::to_string(_session.generate_msg_uuid());
    header["msg_type"] = msg_type;

    Json::StreamWriterBuilder builder;

    const std::string content_buf = Json::writeString(builder, content);
    // FIXME:
    const std::string metadata_buf = "{}";
    const std::string header_buf = Json::writeString(builder, header);
    const std::string parent_header_buf = Json::writeString(builder, _header);
    
    HMAC_SHA256 auth(_session.auth());
    
    auth.update(header_buf);
    auth.update(parent_header_buf);
    auth.update(metadata_buf);
    auth.update(content_buf);
    
    zmqpp::message msg;
    msg.add(_identities_buf);
    msg.add("<IDS|MSG>");
    msg.add(auth.hexdigest());
    msg.add(header_buf);
    msg.add(parent_header_buf);
    msg.add(metadata_buf);
    msg.add(content_buf);
    
    socket.send(msg);
}
Пример #5
0
void regionDataPublisher(zmqpp::socket &publisher, PATH_FIND_NODE &pathFindNode, tbb::concurrent_queue<PathEntity*> &solvedPathQueue, tbb::concurrent_vector<Entity*> entities) {
	using namespace std;

	std::chrono::steady_clock clock;

	// Initialize path.
	for (auto entity : entities) {
		pathFindNode.try_put(std::tuple<size_t, glm::vec2>(entity->id, entity->position));
	}

	while (1) {
		auto start = clock.now();

		// Grab a bunch fo path
		{
			//size_t size = entities.size();
			for (size_t i = 0; i < 200; ++i) {
				PathEntity* pathEntity;
				if (solvedPathQueue.try_pop(pathEntity)) {

					entities[pathEntity->id]->pathNodes = pathEntity->pathNodes;
					entities[pathEntity->id]->currentNode = 0;
				}
			}
		}

		// Traverse nodes
		{
			for (auto entity : entities) {
				if (entity->pathNodes != 0) {
					if (entity->currentNode < entity->pathNodes->size()) {
						size_t currentIndex = (size_t)(*entity->pathNodes)[entity->currentNode++];
						//wss::Utils::indexToXY(currentIndex, MAP_W, entity->position);
						wss::Utils::indexToXY(currentIndex, MAP_W, entity->position);
					}
					else {
						entity->pathNodes = 0;
						pathFindNode.try_put(std::tuple<size_t, glm::vec2>(entity->id, entity->position));
					}
				}
			}
		}

		{
			rapidjson::Document document;
			document.SetObject();
			serializeEntities(document, 0, entities.size(), entities);

			rapidjson::StringBuffer sb;
			rapidjson::Writer<rapidjson::StringBuffer> writer(sb);

			document.Accept(writer);

			publisher.send(sb.GetString());
		}
		std::chrono::duration<double> elapsed = clock.now() - start;
		if (elapsed.count() < 1.0/5.0) {
			std::this_thread::sleep_for(std::chrono::milliseconds(1000/5 - (size_t)(elapsed.count() * 1000.0)));
		//cout << "elpased region publisher" << endl;
		}

	}
}