当前位置: 首页>>代码示例>>C++>>正文


C++ DatagramPtr::add_doid方法代码示例

本文整理汇总了C++中DatagramPtr::add_doid方法的典型用法代码示例。如果您正苦于以下问题:C++ DatagramPtr::add_doid方法的具体用法?C++ DatagramPtr::add_doid怎么用?C++ DatagramPtr::add_doid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatagramPtr的用法示例。


在下文中一共展示了DatagramPtr::add_doid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handle_ai_change

void DistributedObject::handle_ai_change(channel_t new_ai, channel_t sender,
        bool channel_is_explicit)
{
    channel_t old_ai = m_ai_channel;
    if(new_ai == old_ai) {
        return;
    }

    // Set of channels that must be notified about ai_change
    unordered_set<channel_t> targets;

    if(old_ai) {
        targets.insert(old_ai);
    }
    if(!m_zone_objects.empty()) {
        // We have at least one child, so we want to notify the children as well
        targets.insert(parent_to_children(m_do_id));
    }

    m_ai_channel = new_ai;
    m_ai_explicitly_set = channel_is_explicit;

    DatagramPtr dg = Datagram::create(targets, sender, STATESERVER_OBJECT_CHANGING_AI);
    dg->add_doid(m_do_id);
    dg->add_channel(new_ai);
    dg->add_channel(old_ai);
    route_datagram(dg);

    if(new_ai) {
        m_log->trace() << "Sending AI entry to " << new_ai << ".\n";
        send_ai_entry(new_ai);
    }

}
开发者ID:Astron,项目名称:Astron,代码行数:34,代码来源:DistributedObject.cpp

示例2: handle_get_all

void DBStateServer::handle_get_all(channel_t sender, DatagramIterator &dgi)
{
    uint32_t r_context = dgi.read_uint32();
    doid_t r_do_id = dgi.read_doid();
    if(is_activated_object(r_do_id)) {
        return;
    }

    m_log->trace() << "Received GetAll for inactive object with id " << r_do_id << std::endl;

    // Get context for db query, and remember caller with it
    uint32_t db_context = m_next_context++;

    DatagramPtr resp_dg = Datagram::create(sender, r_do_id, STATESERVER_OBJECT_GET_ALL_RESP);
    resp_dg->add_uint32(r_context);
    resp_dg->add_doid(r_do_id);
    resp_dg->add_channel(INVALID_CHANNEL); // Location
    m_context_datagrams[db_context] = resp_dg;

    // Cache the do_id --> context in case we get a dbss_activate
    m_inactive_loads[r_do_id].insert(db_context);

    // Send query to database
    DatagramPtr dg = Datagram::create(m_db_channel, r_do_id, DBSERVER_OBJECT_GET_ALL);
    dg->add_uint32(db_context);
    dg->add_doid(r_do_id);
    route_datagram(dg);
}
开发者ID:Christofosho,项目名称:Astron,代码行数:28,代码来源:DBStateServer.cpp

示例3: send_get_object

void LoadingObject::send_get_object(doid_t do_id)
{
	DatagramPtr dg = Datagram::create(m_dbss->m_db_channel, do_id, DBSERVER_OBJECT_GET_ALL);
	dg->add_uint32(m_context); // Context
	dg->add_doid(do_id);
	route_datagram(dg);
}
开发者ID:Echocage,项目名称:Astron,代码行数:7,代码来源:LoadingObject.cpp

示例4: announce_fields

void DBOperation::announce_fields(const FieldValues& fields)
{
    // Calculate the fields that we are sending in our response:
    FieldValues changed_fields;
    FieldSet deleted_fields;
    for(auto it = fields.begin(); it != fields.end(); ++it) {
        if(it->second.empty())
            deleted_fields.insert(it->first);
        else
            changed_fields[it->first] = it->second;
    }

    // Send delete fields broadcast
    if(!deleted_fields.empty()) {
        bool multi = (deleted_fields.size() > 1);
        DatagramPtr update = Datagram::create();
        update->add_server_header(database_to_object(m_doid), m_sender,
                                  multi ? DBSERVER_OBJECT_DELETE_FIELDS :
                                  DBSERVER_OBJECT_DELETE_FIELD);
        update->add_doid(m_doid);
        if(multi) {
            update->add_uint16(deleted_fields.size());
        }
        for(auto it = deleted_fields.begin(); it != deleted_fields.end(); ++it) {
            update->add_uint16((*it)->get_id());
        }
        m_dbserver->route_datagram(update);
    }

    // Send update fields broadcast
    if(!changed_fields.empty()) {
        bool multi = (changed_fields.size() > 1);
        DatagramPtr update = Datagram::create();
        update->add_server_header(database_to_object(m_doid), m_sender,
                                  multi ? DBSERVER_OBJECT_SET_FIELDS :
                                  DBSERVER_OBJECT_SET_FIELD);
        update->add_doid(m_doid);
        if(multi) {
            update->add_uint16(changed_fields.size());
        }
        for(auto it = changed_fields.begin(); it != changed_fields.end(); ++it) {
            update->add_uint16(it->first->get_id());
            update->add_data(it->second);
        }
        m_dbserver->route_datagram(update);
    }
}
开发者ID:Christofosho,项目名称:Astron,代码行数:47,代码来源:DBOperation.cpp

示例5: delete_children

void DistributedObject::delete_children(channel_t sender)
{
    if(!m_zone_objects.empty()) {
        // We have at least one child, so we want to notify the children as well
        DatagramPtr dg = Datagram::create(parent_to_children(m_do_id), sender,
                                          STATESERVER_OBJECT_DELETE_CHILDREN);
        dg->add_doid(m_do_id);
        route_datagram(dg);
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:10,代码来源:DistributedObject.cpp

示例6: handle_one_update

bool DistributedObject::handle_one_update(DatagramIterator &dgi, channel_t sender)
{
    vector<uint8_t> data;
    uint16_t field_id = dgi.read_uint16();
    const Field *field = m_dclass->get_field_by_id(field_id);
    if(!field) {
        m_log->error() << "Received set_field for field: " << field_id
                       << ", not valid for class: " << m_dclass->get_name() << ".\n";
        return false;
    }

    m_log->trace() << "Handling update for '" << field->get_name() << "'.\n";

    dgsize_t field_start = dgi.tell();

    try {
        dgi.unpack_field(field, data);
    } catch(const DatagramIteratorEOF&) {
        m_log->error() << "Received truncated update for " << field->get_name() << ".\n";
        return false;
    }

    const MolecularField *molecular = field->as_molecular();
    if(molecular) {
        dgi.seek(field_start);
        int n = molecular->get_num_fields();
        for(int i = 0; i < n; ++i) {
            vector<uint8_t> field_data;
            const Field *atomic = molecular->get_field(i);
            dgi.unpack_field(atomic, field_data);
            save_field(atomic, field_data);
        }
    } else {
        save_field(field, data);
    }

    unordered_set<channel_t> targets;
    if(field->has_keyword("broadcast")) {
        targets.insert(location_as_channel(m_parent_id, m_zone_id));
    }
    if(field->has_keyword("airecv") && m_ai_channel && m_ai_channel != sender) {
        targets.insert(m_ai_channel);
    }
    if(field->has_keyword("ownrecv") && m_owner_channel && m_owner_channel != sender) {
        targets.insert(m_owner_channel);
    }
    if(targets.size()) { // TODO: Review this for efficiency?
        DatagramPtr dg = Datagram::create(targets, sender, STATESERVER_OBJECT_SET_FIELD);
        dg->add_doid(m_do_id);
        dg->add_uint16(field_id);
        dg->add_data(data);
        route_datagram(dg);
    }
    return true;
}
开发者ID:Astron,项目名称:Astron,代码行数:55,代码来源:DistributedObject.cpp

示例7: handle_delete_disk

void DBStateServer::handle_delete_disk(channel_t sender, DatagramIterator& dgi)
{
    doid_t do_id = dgi.read_doid();
    if(m_loading.find(do_id) != m_loading.end()) {
        // Ignore this message for now, it'll be bounced back to us
        // from the loading object if it succeeds or fails at loading.
        return;
    }

    // If object exists broadcast the delete message
    auto obj_keyval = m_objs.find(do_id);
    if(obj_keyval != m_objs.end()) {
        DistributedObject* obj = obj_keyval->second;
        std::unordered_set<channel_t> targets;

        // Add location to broadcast
        if(obj->get_location()) {
            targets.insert(obj->get_location());
        }

        // Add AI to broadcast
        if(obj->get_ai()) {
            targets.insert(obj->get_ai());
        }

        // Add owner to broadcast
        if(obj->get_owner()) {
            targets.insert(obj->get_owner());
        }

        // Build and send datagram
        DatagramPtr dg = Datagram::create(targets, sender, DBSS_OBJECT_DELETE_DISK);
        dg->add_doid(do_id);
        route_datagram(dg);
    }

    // Send delete to database
    DatagramPtr dg = Datagram::create(m_db_channel, do_id, DBSERVER_OBJECT_DELETE);
    dg->add_doid(do_id);
    route_datagram(dg);

}
开发者ID:Astron,项目名称:Astron,代码行数:42,代码来源:DBStateServer.cpp

示例8: on_complete

void DBOperationCreate::on_complete(doid_t doid)
{
    DatagramPtr resp = Datagram::create();
    resp->add_server_header(m_sender, m_dbserver->m_control_channel,
                            DBSERVER_CREATE_OBJECT_RESP);
    resp->add_uint32(m_context);
    resp->add_doid(doid);
    m_dbserver->route_datagram(resp);

    cleanup();
}
开发者ID:Christofosho,项目名称:Astron,代码行数:11,代码来源:DBOperation.cpp

示例9: handle_get_field

void DBStateServer::handle_get_field(channel_t sender, DatagramIterator &dgi)
{
    uint32_t r_context = dgi.read_uint32();
    doid_t r_do_id = dgi.read_doid();
    uint16_t field_id = dgi.read_uint16();
    if(is_activated_object(r_do_id)) {
        return;
    }

    m_log->trace() << "Received GetField for field with id " << field_id
                   << " on inactive object with id " << r_do_id << "\n";

    // Check field is "ram db" or "required"
    const Field* field = g_dcf->get_field_by_id(field_id);
    if(!field || !(field->has_keyword("required") || field->has_keyword("ram"))) {
        DatagramPtr dg = Datagram::create(sender, r_do_id, STATESERVER_OBJECT_GET_FIELD_RESP);
        dg->add_uint32(r_context);
        dg->add_bool(false);
        route_datagram(dg);
        return;
    }

    if(field->has_keyword("db")) {
        // Get context for db query
        uint32_t db_context = m_next_context++;

        // Prepare reponse datagram
        DatagramPtr dg_resp = Datagram::create(sender, r_do_id, STATESERVER_OBJECT_GET_FIELD_RESP);
        dg_resp->add_uint32(r_context);
        m_context_datagrams[db_context] = dg_resp;

        // Send query to database
        DatagramPtr dg = Datagram::create(m_db_channel, r_do_id, DBSERVER_OBJECT_GET_FIELD);
        dg->add_uint32(db_context);
        dg->add_doid(r_do_id);
        dg->add_uint16(field_id);
        route_datagram(dg);
    } else if(field->has_default_value()) { // Field is required and not-db
        DatagramPtr dg = Datagram::create(sender, r_do_id, STATESERVER_OBJECT_GET_FIELD_RESP);
        dg->add_uint32(r_context);
        dg->add_bool(true);
        dg->add_uint16(field_id);
        dg->add_data(field->get_default_value());
        route_datagram(dg);
    } else {
        DatagramPtr dg = Datagram::create(sender, r_do_id, STATESERVER_OBJECT_GET_FIELD_RESP);
        dg->add_uint32(r_context);
        dg->add_bool(false);
        route_datagram(dg);
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:51,代码来源:DBStateServer.cpp

示例10: append_required_data

void DistributedObject::append_required_data(DatagramPtr dg, bool client_only, bool also_owner)
{
    dg->add_doid(m_do_id);
    dg->add_location(m_parent_id, m_zone_id);
    dg->add_uint16(m_dclass->get_id());
    size_t field_count = m_dclass->get_num_fields();
    for(size_t i = 0; i < field_count; ++i) {
        const Field *field = m_dclass->get_field(i);
        if(field->has_keyword("required") && !field->as_molecular() && (!client_only
                || field->has_keyword("broadcast") || field->has_keyword("clrecv")
                || (also_owner && field->has_keyword("ownrecv")))) {
            dg->add_data(m_required_fields[field]);
        }
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:15,代码来源:DistributedObject.cpp

示例11: while

Client::~Client()
{
    unsubscribe_all();
    m_client_agent->m_ct.free_channel(m_allocated_channel);

    // Delete all session objects
    while(m_session_objects.size() > 0) {
        doid_t do_id = *m_session_objects.begin();
        m_session_objects.erase(do_id);
        m_log->debug() << "Client exited, deleting session object with id " << do_id << ".\n";
        DatagramPtr dg = Datagram::create(do_id, m_channel, STATESERVER_OBJECT_DELETE_RAM);
        dg->add_doid(do_id);
        route_datagram(dg);
    }

    delete m_log;
}
开发者ID:Unkn0wn0ne,项目名称:Astron,代码行数:17,代码来源:Client.cpp

示例12: handle_set_fields

void DBStateServer::handle_set_fields(DatagramIterator &dgi)
{
    doid_t do_id = dgi.read_doid();
    if(m_loading.find(do_id) != m_loading.end()) {
        // Ignore this message for now, it'll be bounced back to us
        // from the loading object if it succeeds or fails at loading.
        return;
    }

    uint16_t field_count = dgi.read_uint16();

    FieldValues db_fields;
    for(uint16_t i = 0; i < field_count; ++i) {
        uint16_t field_id = dgi.read_uint16();
        const Field* field = g_dcf->get_field_by_id(field_id);
        if(!field) {
            m_log->warning() << "Received invalid field with id " << field_id << " in SetFields.\n";
            return;
        }
        if(field->has_keyword("db")) {
            dgi.unpack_field(field, db_fields[field]);
        } else {
            dgi.skip_field(field);
        }
    }

    if(db_fields.size() > 0) {
        m_log->trace() << "Forwarding SetFields on object with id " << do_id << " to database.\n";

        DatagramPtr dg = Datagram::create(m_db_channel, do_id, DBSERVER_OBJECT_SET_FIELDS);
        dg->add_doid(do_id);
        dg->add_uint16(db_fields.size());
        for(const auto& it : db_fields) {
            dg->add_uint16(it.first->get_id());
            dg->add_data(it.second);
        }
        route_datagram(dg);
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:39,代码来源:DBStateServer.cpp

示例13: handle_set_field

void DBStateServer::handle_set_field(DatagramIterator &dgi)
{
    doid_t do_id = dgi.read_doid();
    if(m_loading.find(do_id) != m_loading.end()) {
        // Ignore this message for now, it'll be bounced back to us
        // from the loading object if it succeeds or fails at loading.
        return;
    }

    uint16_t field_id = dgi.read_uint16();

    const Field* field = g_dcf->get_field_by_id(field_id);
    if(field && field->has_keyword("db")) {
        m_log->trace() << "Forwarding SetField for field \"" << field->get_name()
                       << "\" on object with id " << do_id << " to database.\n";

        DatagramPtr dg = Datagram::create(m_db_channel, do_id, DBSERVER_OBJECT_SET_FIELD);
        dg->add_doid(do_id);
        dg->add_uint16(field_id);
        dg->add_data(dgi.read_remainder());
        route_datagram(dg);
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:23,代码来源:DBStateServer.cpp

示例14: annihilate

void Client::annihilate()
{
    lock_guard<recursive_mutex> lock(m_client_lock);
    if(is_terminated()) {
        return;
    }

    // Unsubscribe from all channels first so the DELETE messages aren't sent back to us.
    unsubscribe_all();
    m_client_agent->m_ct.free_channel(m_allocated_channel);

    // Delete all session objects
    while(m_session_objects.size() > 0) {
        doid_t do_id = *m_session_objects.begin();
        m_session_objects.erase(do_id);
        m_log->debug() << "Client exited, deleting session object with id " << do_id << ".\n";
        DatagramPtr dg = Datagram::create(do_id, m_channel, STATESERVER_OBJECT_DELETE_RAM);
        dg->add_doid(do_id);
        route_datagram(dg);
    }

    // Tell the MD this client is gone
    terminate();
}
开发者ID:nate97,项目名称:Astron,代码行数:24,代码来源:Client.cpp

示例15: add_interest

// add_interest will start a new interest operation and retrieve all the objects an interest
// from the server, subscribing to each zone in the interest.  If the interest already
// exists, the interest will be updated with the new zones passed in by the argument.
void Client::add_interest(Interest &i, uint32_t context, channel_t caller)
{
    unordered_set<zone_t> new_zones;

    for(const auto& it : i.zones) {
        if(lookup_interests(i.parent, it).empty()) {
            new_zones.insert(it);
        }
    }

    if(m_interests.find(i.id) != m_interests.end()) {
        // This is an already-open interest that is actually being altered.
        // Therefore, we need to delete the objects that the client can see
        // through this interest only.

        Interest previous_interest = m_interests[i.id];
        unordered_set<zone_t> killed_zones;

        for(const auto& it : previous_interest.zones) {
            if(lookup_interests(previous_interest.parent, it).size() > 1) {
                // An interest other than the altered one can see this parent/zone,
                // so we don't care about it.
                continue;
            }

            // If we've gotten here: parent,*it is unique, so if the new interest
            // doesn't cover it, we add it to the killed zones.
            if(i.parent != previous_interest.parent || i.zones.find(it) == i.zones.end()) {
                killed_zones.insert(it);
            }
        }

        // Now that we know what zones to kill, let's get to it:
        close_zones(previous_interest.parent, killed_zones);
    }
    m_interests[i.id] = i;

    if(new_zones.empty()) {
        // We aren't requesting any new zones with this operation, so don't
        // bother firing off a State Server request. Instead, let the client
        // know we're already done:

        notify_interest_done(i.id, caller);
        handle_interest_done(i.id, context);

        return;
    }

    uint32_t request_context = m_next_context++;

    InterestOperation *iop = new InterestOperation(this, m_client_agent->m_interest_timeout,
            i.id, context, request_context, i.parent, new_zones, caller);
    m_pending_interests.emplace(request_context, iop);

    DatagramPtr resp = Datagram::create();
    resp->add_server_header(i.parent, m_channel, STATESERVER_OBJECT_GET_ZONES_OBJECTS);
    resp->add_uint32(request_context);
    resp->add_doid(i.parent);
    resp->add_uint16(new_zones.size());
    for(const auto& it : new_zones) {
        resp->add_zone(it);
        subscribe_channel(location_as_channel(i.parent, it));
    }
    route_datagram(resp);
}
开发者ID:staticfox,项目名称:Astron,代码行数:68,代码来源:Client.cpp


注:本文中的DatagramPtr::add_doid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。