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


C++ DatagramIterator::read_channel方法代码示例

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


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

示例1: LogCategory

DistributedObject::DistributedObject(StateServer *stateserver, doid_t do_id, doid_t parent_id,
                                     zone_t zone_id, const Class *dclass, DatagramIterator &dgi,
                                     bool has_other) :
    m_stateserver(stateserver), m_do_id(do_id), m_parent_id(INVALID_DO_ID), m_zone_id(0),
    m_dclass(dclass), m_ai_channel(INVALID_CHANNEL), m_owner_channel(INVALID_CHANNEL),
    m_ai_explicitly_set(false), m_parent_synchronized(false), m_next_context(0)
{
    stringstream name;
    name << dclass->get_name() << "(" << do_id << ")";
    m_log = new LogCategory("object", name.str());
    set_con_name(name.str());

    for(unsigned int i = 0; i < m_dclass->get_num_fields(); ++i) {
        const Field *field = m_dclass->get_field(i);
        if(field->has_keyword("required") && !field->as_molecular()) {
            dgi.unpack_field(field, m_required_fields[field]);
        }
    }

    if(has_other) {
        uint16_t count = dgi.read_uint16();
        for(int i = 0; i < count; ++i) {
            uint16_t field_id = dgi.read_uint16();
            const Field *field = m_dclass->get_field_by_id(field_id);
            if(!field) {
                m_log->error() << "Received unknown field with ID " << field_id 
                               << " within an OTHER section.\n";
                break;
            }

            if(field->has_keyword("ram")) {
                dgi.unpack_field(field, m_ram_fields[field]);
            } else {
                m_log->error() << "Received non-RAM field " << field->get_name()
                               << " within an OTHER section.\n";
                dgi.skip_field(field);
            }
        }
    }

    subscribe_channel(do_id);

    m_log->debug() << "Object created..." << endl;

    dgi.seek_payload(); // Seek back to front of payload, to read sender
    handle_location_change(parent_id, zone_id, dgi.read_channel());
    wake_children();
}
开发者ID:Astron,项目名称:Astron,代码行数:48,代码来源:DistributedObject.cpp

示例2: handle_delete_ai

void StateServer::handle_delete_ai(DatagramIterator& dgi, channel_t sender)
{
    channel_t ai_channel = dgi.read_channel();
    std::set <channel_t> targets;
    for(auto it = m_objs.begin(); it != m_objs.end(); ++it) {
        if(it->second && it->second->m_ai_channel == ai_channel && it->second->m_ai_explicitly_set) {
            targets.insert(it->second->m_do_id);
        }
    }

    if(targets.size()) {
        DatagramPtr dg = Datagram::create(targets, sender, STATESERVER_DELETE_AI_OBJECTS);
        dg->add_channel(ai_channel);
        route_datagram(dg);
    }
}
开发者ID:Fantasticer,项目名称:Astron,代码行数:16,代码来源:StateServer.cpp

示例3: handle_datagram

void DBStateServer::handle_datagram(DatagramHandle, DatagramIterator &dgi)
{
    channel_t sender = dgi.read_channel();
    uint16_t msgtype = dgi.read_uint16();
    switch(msgtype) {
    case DBSS_OBJECT_ACTIVATE_WITH_DEFAULTS:
        handle_activate(dgi, false);
        break;
    case DBSS_OBJECT_ACTIVATE_WITH_DEFAULTS_OTHER:
        handle_activate(dgi, true);
        break;
    case DBSS_OBJECT_DELETE_DISK:
        handle_delete_disk(sender, dgi);
        break;
    case STATESERVER_OBJECT_SET_FIELD:
        handle_set_field(dgi);
        break;
    case STATESERVER_OBJECT_SET_FIELDS:
        handle_set_fields(dgi);
        break;
    case STATESERVER_OBJECT_GET_FIELD:
        handle_get_field(sender, dgi);
        break;
    case DBSERVER_OBJECT_GET_FIELD_RESP:
        handle_get_field_resp(dgi);
        break;
    case STATESERVER_OBJECT_GET_FIELDS:
        handle_get_fields(sender, dgi);
        break;
    case DBSERVER_OBJECT_GET_FIELDS_RESP:
        handle_get_fields_resp(dgi);
        break;
    case STATESERVER_OBJECT_GET_ALL:
        handle_get_all(sender, dgi);
        break;
    case DBSERVER_OBJECT_GET_ALL_RESP:
        handle_get_all_resp(dgi);
        break;
    case DBSS_OBJECT_GET_ACTIVATED:
        handle_get_activated(sender, dgi);
        break;
    default:
        m_log->trace() << "Ignoring message of type '" << msgtype << "'.\n";
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:45,代码来源:DBStateServer.cpp

示例4: handle_datagram

void DatabaseServer::handle_datagram(DatagramHandle, DatagramIterator &dgi)
{
    channel_t sender = dgi.read_channel();
    uint16_t msg_type = dgi.read_uint16();

    DBOperation *op;

    switch(msg_type) {
    case DBSERVER_CREATE_OBJECT: {
        op = new DBOperationCreate(this);
    }
    break;
    case DBSERVER_OBJECT_DELETE: {
        op = new DBOperationDelete(this);
    }
    break;
    case DBSERVER_OBJECT_GET_ALL:
    case DBSERVER_OBJECT_GET_FIELD:
    case DBSERVER_OBJECT_GET_FIELDS: {
        op = new DBOperationGet(this);
    }
    break;
    case DBSERVER_OBJECT_SET_FIELD:
    case DBSERVER_OBJECT_SET_FIELDS:
    case DBSERVER_OBJECT_DELETE_FIELD:
    case DBSERVER_OBJECT_DELETE_FIELDS: {
        op = new DBOperationSet(this);
    }
    break;
    case DBSERVER_OBJECT_SET_FIELD_IF_EMPTY:
    case DBSERVER_OBJECT_SET_FIELD_IF_EQUALS:
    case DBSERVER_OBJECT_SET_FIELDS_IF_EQUALS: {
        op = new DBOperationUpdate(this);
    }
    break;
    default:
        m_log->error() << "Recieved unknown MsgType: " << msg_type << endl;
        return;
    };

    if(op->initialize(sender, msg_type, dgi)) {
        handle_operation(op);
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:44,代码来源:DatabaseServer.cpp

示例5: handle_datagram

void StateServer::handle_datagram(DatagramHandle, DatagramIterator &dgi)
{
    channel_t sender = dgi.read_channel();
    uint16_t msgtype = dgi.read_uint16();
    switch(msgtype) {
    case STATESERVER_CREATE_OBJECT_WITH_REQUIRED: {
        handle_generate(dgi, false);
        break;
    }
    case STATESERVER_CREATE_OBJECT_WITH_REQUIRED_OTHER: {
        handle_generate(dgi, true);
        break;
    }
    case STATESERVER_DELETE_AI_OBJECTS: {
        handle_delete_ai(dgi, sender);
        break;
    }
    default:
        m_log->warning() << "Received unknown message: msgtype=" << msgtype << std::endl;
    }
}
开发者ID:Fantasticer,项目名称:Astron,代码行数:21,代码来源:StateServer.cpp

示例6: handle_datagram

// handle_datagram is the handler for datagrams received from the Astron cluster
void Client::handle_datagram(DatagramHandle in_dg, DatagramIterator &dgi)
{
    lock_guard<recursive_mutex> lock(m_client_lock);
    if(is_terminated()) {
        return;
    }

    channel_t sender = dgi.read_channel();
    if(sender == m_channel) {
        return;    // ignore messages from ourselves
    }

    uint16_t msgtype = dgi.read_uint16();
    switch(msgtype) {
    case CLIENTAGENT_EJECT: {
        uint16_t reason = dgi.read_uint16();
        string error_string = dgi.read_string();
        send_disconnect(reason, error_string);
        return;
    }
    break;
    case CLIENTAGENT_DROP: {
        handle_drop();
        return;
    }
    break;
    case CLIENTAGENT_SET_STATE: {
        m_state = (ClientState)dgi.read_uint16();
    }
    break;
    case CLIENTAGENT_ADD_INTEREST: {
        uint32_t context = m_next_context++;

        Interest i;
        build_interest(dgi, false, i);
        handle_add_interest(i, context);
        add_interest(i, context, sender);
    }
    break;
    case CLIENTAGENT_ADD_INTEREST_MULTIPLE: {
        uint32_t context = m_next_context++;

        Interest i;
        build_interest(dgi, true, i);
        handle_add_interest(i, context);
        add_interest(i, context, sender);
    }
    break;
    case CLIENTAGENT_REMOVE_INTEREST: {
        uint32_t context = m_next_context++;

        uint16_t id = dgi.read_uint16();
        Interest &i = m_interests[id];
        handle_remove_interest(id, context);
        remove_interest(i, context, sender);
    }
    break;
    case CLIENTAGENT_SET_CLIENT_ID: {
        if(m_channel != m_allocated_channel) {
            unsubscribe_channel(m_channel);
        }

        m_channel = dgi.read_channel();
        subscribe_channel(m_channel);
    }
    break;
    case CLIENTAGENT_SEND_DATAGRAM: {
        DatagramPtr forward = Datagram::create();
        forward->add_data(dgi.read_string());
        forward_datagram(forward);
    }
    break;
    case CLIENTAGENT_OPEN_CHANNEL: {
        subscribe_channel(dgi.read_channel());
    }
    break;
    case CLIENTAGENT_CLOSE_CHANNEL: {
        unsubscribe_channel(dgi.read_channel());
    }
    break;
    case CLIENTAGENT_ADD_POST_REMOVE: {
        add_post_remove(m_allocated_channel, dgi.read_datagram());
    }
    break;
    case CLIENTAGENT_CLEAR_POST_REMOVES: {
        clear_post_removes(m_allocated_channel);
    }
    break;
    case CLIENTAGENT_DECLARE_OBJECT: {
        doid_t do_id = dgi.read_doid();
        uint16_t dc_id = dgi.read_uint16();

        if(m_declared_objects.find(do_id) != m_declared_objects.end()) {
            m_log->warning() << "Received object declaration for previously declared object "
                             << do_id << ".\n";
            return;
        }

        DeclaredObject obj;
//.........这里部分代码省略.........
开发者ID:staticfox,项目名称:Astron,代码行数:101,代码来源:Client.cpp

示例7: handle_datagram

// handle_datagram is the handler for datagrams received from the Astron cluster
void Client::handle_datagram(DatagramHandle, DatagramIterator &dgi)
{
    std::lock_guard<std::recursive_mutex> lock(m_client_lock);
    channel_t sender = dgi.read_channel();
    uint16_t msgtype = dgi.read_uint16();
    switch(msgtype) {
    case CLIENTAGENT_EJECT: {
        uint16_t reason = dgi.read_uint16();
        std::string error_string = dgi.read_string();
        send_disconnect(reason, error_string);
        return;
    }
    break;
    case CLIENTAGENT_DROP: {
        handle_drop();
        return;
    }
    break;
    case CLIENTAGENT_SET_STATE: {
        m_state = (ClientState)dgi.read_uint16();
    }
    break;
    case CLIENTAGENT_ADD_INTEREST: {
        uint32_t context = m_next_context++;

        Interest i;
        build_interest(dgi, false, i);
        handle_add_interest(i, context);
        add_interest(i, context, sender);
    }
    break;
    case CLIENTAGENT_ADD_INTEREST_MULTIPLE: {
        uint32_t context = m_next_context++;

        Interest i;
        build_interest(dgi, true, i);
        handle_add_interest(i, context);
        add_interest(i, context, sender);
    }
    break;
    case CLIENTAGENT_REMOVE_INTEREST: {
        uint32_t context = m_next_context++;

        uint16_t id = dgi.read_uint16();
        Interest &i = m_interests[id];
        handle_remove_interest(id, context);
        remove_interest(i, context, sender);
    }
    break;
    case CLIENTAGENT_SET_CLIENT_ID: {
        if(m_channel != m_allocated_channel) {
            unsubscribe_channel(m_channel);
        }

        m_channel = dgi.read_channel();
        subscribe_channel(m_channel);
    }
    break;
    case CLIENTAGENT_SEND_DATAGRAM: {
        DatagramPtr forward = Datagram::create();
        forward->add_data(dgi.read_string());
        forward_datagram(forward);
    }
    break;
    case CLIENTAGENT_OPEN_CHANNEL: {
        subscribe_channel(dgi.read_channel());
    }
    break;
    case CLIENTAGENT_CLOSE_CHANNEL: {
        unsubscribe_channel(dgi.read_channel());
    }
    break;
    case CLIENTAGENT_ADD_POST_REMOVE: {
        add_post_remove(dgi.read_datagram());
    }
    break;
    case CLIENTAGENT_CLEAR_POST_REMOVES: {
        clear_post_removes();
    }
    break;
    case CLIENTAGENT_DECLARE_OBJECT: {
        doid_t do_id = dgi.read_doid();
        uint16_t dc_id = dgi.read_uint16();

        if(m_declared_objects.find(do_id) != m_declared_objects.end()) {
            m_log->warning() << "Received object declaration for previously declared object "
                             << do_id << ".\n";
            return;
        }

        DeclaredObject obj;
        obj.id = do_id;
        obj.dcc = g_dcf->get_class_by_id(dc_id);
        m_declared_objects[do_id] = obj;
    }
    break;
    case CLIENTAGENT_UNDECLARE_OBJECT: {
        doid_t do_id = dgi.read_doid();

//.........这里部分代码省略.........
开发者ID:Unkn0wn0ne,项目名称:Astron,代码行数:101,代码来源:Client.cpp

示例8: handle_datagram

void DistributedObject::handle_datagram(DatagramHandle, DatagramIterator &dgi)
{
    channel_t sender = dgi.read_channel();
    uint16_t msgtype = dgi.read_uint16();
    switch(msgtype) {
    case STATESERVER_DELETE_AI_OBJECTS: {
        if(m_ai_channel != dgi.read_channel()) {
            m_log->warning() << " received reset for wrong AI channel.\n";
            break; // Not my AI!
        }
        annihilate(sender);

        break;
    }
    case STATESERVER_OBJECT_DELETE_RAM: {
        if(m_do_id != dgi.read_doid()) {
            break;    // Not meant for me!
        }

        // Delete object
        annihilate(sender);

        break;
    }
    case STATESERVER_OBJECT_DELETE_CHILDREN: {
        doid_t r_do_id = dgi.read_doid();
        if(r_do_id == m_do_id) {
            delete_children(sender);
        } else if(r_do_id == m_parent_id) {
            annihilate(sender, false);
        }
        break;
    }
    case STATESERVER_OBJECT_SET_FIELD: {
        if(m_do_id != dgi.read_doid()) {
            break;    // Not meant for me!
        }
        handle_one_update(dgi, sender);

        break;
    }
    case STATESERVER_OBJECT_SET_FIELDS: {
        if(m_do_id != dgi.read_doid()) {
            break;    // Not meant for me!
        }
        uint16_t field_count = dgi.read_uint16();
        for(int16_t i = 0; i < field_count; ++i) {
            if(!handle_one_update(dgi, sender)) {
                break;
            }
        }
        break;
    }
    case STATESERVER_OBJECT_CHANGING_AI: {
        doid_t r_parent_id = dgi.read_doid();
        channel_t new_channel = dgi.read_channel();
        m_log->trace() << "Received ChangingAI notification from " << r_parent_id << ".\n";
        if(r_parent_id != m_parent_id) {
            m_log->warning() << "Received AI channel from " << r_parent_id
                             << " but my parent_id is " << m_parent_id << ".\n";
            break;
        }
        if(m_ai_explicitly_set) {
            break;
        }
        handle_ai_change(new_channel, sender, false);

        break;
    }
    case STATESERVER_OBJECT_SET_AI: {
        channel_t new_channel = dgi.read_channel();
        m_log->trace() << "Updating AI to " << new_channel << ".\n";
        handle_ai_change(new_channel, sender, true);

        break;
    }
    case STATESERVER_OBJECT_GET_AI: {
        m_log->trace() << "Received AI query from " << sender << ".\n";
        DatagramPtr dg = Datagram::create(sender, m_do_id, STATESERVER_OBJECT_GET_AI_RESP);
        dg->add_uint32(dgi.read_uint32()); // Get context
        dg->add_doid(m_do_id);
        dg->add_channel(m_ai_channel);
        route_datagram(dg);

        break;
    }
    case STATESERVER_OBJECT_GET_AI_RESP: {
        dgi.read_uint32(); // Discard context
        doid_t r_parent_id = dgi.read_doid();
        m_log->trace() << "Received AI query response from " << r_parent_id << ".\n";
        if(r_parent_id != m_parent_id) {
            m_log->warning() << "Received AI channel from " << r_parent_id
                             << " but my parent_id is " << m_parent_id << ".\n";
            break;
        }

        channel_t new_ai = dgi.read_channel();
        if(m_ai_explicitly_set) {
            break;
        }
//.........这里部分代码省略.........
开发者ID:Astron,项目名称:Astron,代码行数:101,代码来源:DistributedObject.cpp

示例9: handle_datagram

void LoadingObject::handle_datagram(DatagramHandle in_dg, DatagramIterator &dgi)
{
	/*channel_t sender =*/ dgi.read_channel(); // sender not used
	uint16_t msgtype = dgi.read_uint16();
	switch(msgtype)
	{
		case DBSERVER_OBJECT_GET_ALL_RESP:
		{
			if(m_is_loaded)
			{
				break; // Don't care about these message any more if loaded
			}

			uint32_t db_context = dgi.read_uint32();
			if(db_context != m_context &&
			   m_valid_contexts.find(db_context) == m_valid_contexts.end())
			{
				m_log->warning() << "Received get_all_resp with incorrect context '"
				                 << db_context << "'.\n";
				break;
			}

			m_log->trace() << "Received GetAllResp from database.\n";
			m_is_loaded = true;

			if(dgi.read_bool() != true)
			{
				m_log->debug() << "Object not found in database.\n";
				m_dbss->discard_loader(m_do_id);
				forward_datagrams();
				break;
			}

			uint16_t dc_id = dgi.read_uint16();
			const Class *r_dclass = g_dcf->get_class_by_id(dc_id);
			if(!r_dclass)
			{
				m_log->error() << "Received object from database with unknown dclass"
				               << " - id:" << dc_id << std::endl;
				m_dbss->discard_loader(m_do_id);
				forward_datagrams();
				break;
			}

			if(m_dclass && r_dclass != m_dclass)
			{
				m_log->error() << "Requested object of class '" << m_dclass->get_id()
				               << "', but received class " << dc_id << std::endl;
				m_dbss->discard_loader(m_do_id);
				forward_datagrams();
				break;
			}

			// Get fields from database
			if(!unpack_db_fields(dgi, r_dclass, m_required_fields, m_ram_fields))
			{
				m_log->error() << "Error while unpacking fields from database.\n";
				m_dbss->discard_loader(m_do_id);
				forward_datagrams();
				break;
			}

			// Add default values and updated values
			int dcc_field_count = r_dclass->get_num_fields();
			for(int i = 0; i < dcc_field_count; ++i)
			{
				const Field *field = r_dclass->get_field(i);
				if(!field->as_molecular())
				{
					if(field->has_keyword("required"))
					{
						if(m_field_updates.find(field) != m_field_updates.end())
						{
							m_required_fields[field] = m_field_updates[field];
						}
						else if(m_required_fields.find(field) == m_required_fields.end())
						{
							std::string val = field->get_default_value();
							m_required_fields[field] = std::vector<uint8_t>(val.begin(), val.end());
						}
					}
					else if(field->has_keyword("ram"))
					{
						if(m_field_updates.find(field) != m_field_updates.end())
						{
							m_ram_fields[field] = m_field_updates[field];
						}
					}
				}
			}

			// Create object on stateserver
			DistributedObject* obj = new DistributedObject(m_dbss, m_dbss->m_db_channel, m_do_id,
			        m_parent_id, m_zone_id, r_dclass,
			        m_required_fields, m_ram_fields);

			// Tell DBSS about object and handle datagram queue
			m_dbss->receive_object(obj);
			replay_datagrams(obj);

//.........这里部分代码省略.........
开发者ID:Echocage,项目名称:Astron,代码行数:101,代码来源:LoadingObject.cpp


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