Exemplo n.º 1
0
int		mongoproxy_update(const google::protobuf::Message & msg, const std::string & fields, const char * cb_data, int cb_size){
    MongoOPReq requpdate;
    std::vector<string> vs;
    dcs::strsplit(fields, ",", vs);
    if (vs.empty()){
        GLOG_ERR("not found the fields define :%s", fields.c_str());
        return -1;
    }
    google::protobuf::Message * tmpmsg = msg.New();
    tmpmsg->CopyFrom(msg);
    auto reflect = tmpmsg->GetReflection();
    auto desc = tmpmsg->GetDescriptor();
    for (int i = 0; i < desc->field_count(); ++i){
        auto field = desc->field(i);
        if (std::find(vs.begin(), vs.end(), field->name()) != vs.end()){
            continue;
        }
        reflect->ClearField(tmpmsg, field);
    }
    string fieldsquery;
    pbjson::pb2json(tmpmsg, fieldsquery);
    delete tmpmsg;
    requpdate.set_q(fieldsquery);
    return _mongoproxy_cmd(MONGO_OP_UPDATE, msg, true, &requpdate, cb_data, cb_size);
}
Exemplo n.º 2
0
inline Resource Sender::PopFree() {
    if (_nfree == 0) {
        if (_nalloc == 0) {
            Resource r;
            r.response = _response;
            r.sub_done = &_sub_done0;
            _alloc_resources[_nalloc++] = r;
            return r;
        } else if (_nalloc == 1) {
            Resource r;
            r.response = _response->New();
            r.sub_done = new SubDone(this);
            _alloc_resources[_nalloc++] = r;
            return r;
        } else {
            CHECK(false) << "nalloc=" << _nalloc;
            return Resource();
        }
    } else {
        Resource r = _free_resources[--_nfree];
        r.response->Clear();
        Controller& sub_cntl = r.sub_done->_cntl;
        ExcludedServers* saved_accessed = sub_cntl._accessed;
        sub_cntl._accessed = NULL;
        sub_cntl.Reset();
        sub_cntl._accessed = saved_accessed;
        return r;
    }
}
Exemplo n.º 3
0
	void Receive(const IHost::Callback& callback, const google::protobuf::Message& message, const short port)
	{
		SCOPED_LOG(m_Log);
		m_Message.reset(message.New());
		m_Callback = callback;

		const SocketPtr socket(new Socket(m_Service, Endpoint(boost::asio::ip::udp::v4(), port)));
		const IConnection::Ptr connection(new Connection<Socket, Endpoint>(m_Log, socket, m_BufferSize, *m_Message));

		for (std::size_t i = 0 ; i < m_Threads * 2; ++i)
			connection->Receive(boost::bind(&Impl::ConnectionCallback, this, _1, connection, callback), 0);
	}
Exemplo n.º 4
0
    /// true if messages are equal
    bool make_message_diff( gpb::Message const &templ,
                            gpb::Message const &src,
                            gpb::Message &result  )
    {
        boost::scoped_ptr<gpb::Message> new_result(src.New());
        new_result->CopyFrom( src );

        typedef gpb::FieldDescriptor field_desc;
        typedef std::vector<const field_desc *> field_list;
        field_list fields;

        new_result->GetReflection( )->ListFields(*new_result, &fields);

        size_t changes(0);

        for( field_list::const_iterator b(fields.begin()), e(fields.end());
                                                                b!=e; ++b )
        {
            field_desc const *next(*b);
            if( !next->is_repeated() &&
                !templ.GetReflection( )->HasField( templ, next ) )
            {
                ++changes;
                continue;
            }

            if( next->cpp_type( ) == field_desc::CPPTYPE_MESSAGE ) {
                changes += (!messages_diff( templ, *new_result, next ));
            } else {
                changes += (!field_diff( templ, *new_result, next ));
            }
        }

        result.GetReflection()->Swap( new_result.get(), &result );
        return changes == 0;
    }