本文整理汇总了C++中DatagramIterator类的典型用法代码示例。如果您正苦于以下问题:C++ DatagramIterator类的具体用法?C++ DatagramIterator怎么用?C++ DatagramIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatagramIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_object_entrance
void Client::handle_object_entrance(DatagramIterator &dgi, bool other)
{
doid_t do_id = dgi.read_doid();
doid_t parent = dgi.read_doid();
zone_t zone = dgi.read_zone();
uint16_t dc_id = dgi.read_uint16();
// this object is no longer pending
m_pending_objects.erase(do_id);
if(m_owned_objects.find(do_id) != m_owned_objects.end() ||
m_seen_objects.find(do_id) != m_seen_objects.end()) {
return;
}
if(m_visible_objects.find(do_id) == m_visible_objects.end()) {
VisibleObject obj;
obj.id = do_id;
obj.dcc = g_dcf->get_class_by_id(dc_id);
obj.parent = parent;
obj.zone = zone;
m_visible_objects[do_id] = obj;
}
m_seen_objects.insert(do_id);
handle_add_object(do_id, parent, zone, dc_id, dgi, other);
}
示例2: DistributedObject
void StateServer::handle_generate(DatagramIterator &dgi, bool has_other)
{
doid_t do_id = dgi.read_doid();
doid_t parent_id = dgi.read_doid();
zone_t zone_id = dgi.read_zone();
uint16_t dc_id = dgi.read_uint16();
// Make sure the object id is unique
if(m_objs.find(do_id) != m_objs.end()) {
m_log->warning() << "Received generate for already-existing object ID=" << do_id << std::endl;
return;
}
// Make sure the class exists in the file
const Class *dc_class = g_dcf->get_class_by_id(dc_id);
if(!dc_class) {
m_log->error() << "Received create for unknown dclass with class id '" << dc_id << "'\n";
return;
}
// Create the object
DistributedObject *obj;
try {
obj = new DistributedObject(this, do_id, parent_id, zone_id, dc_class, dgi, has_other);
} catch(const DatagramIteratorEOF&) {
m_log->error() << "Received truncated generate for "
<< dc_class->get_name() << "(" << do_id << ")" << std::endl;
return;
}
m_objs[do_id] = obj;
}
示例3: initialize
bool DBOperationSet::initialize(channel_t sender, uint16_t msg_type, DatagramIterator &dgi)
{
m_sender = sender;
m_type = SET_FIELDS;
m_doid = dgi.read_doid();
uint16_t field_count;
if(msg_type == DBSERVER_OBJECT_SET_FIELDS ||
msg_type == DBSERVER_OBJECT_DELETE_FIELDS) {
field_count = dgi.read_uint16();
} else {
field_count = 1;
}
bool delete_values = false;
if(msg_type == DBSERVER_OBJECT_DELETE_FIELD ||
msg_type == DBSERVER_OBJECT_DELETE_FIELDS) {
delete_values = true;
}
if(!populate_set_fields(dgi, field_count, delete_values, false)) {
on_failure();
return false;
}
return true;
}
示例4: DatagramIterator
void DBStateServer::handle_get_fields_resp(DatagramIterator& dgi)
{
uint32_t db_context = dgi.read_uint32();
if(!is_expected_context(db_context)) {
return;
}
// Get the datagram from the db_context
DatagramPtr dg = m_context_datagrams[db_context];
m_context_datagrams.erase(db_context);
// Check to make sure the datagram is appropriate
DatagramIterator check_dgi = DatagramIterator(dg);
uint16_t resp_type = check_dgi.get_msg_type();
if(resp_type != STATESERVER_OBJECT_GET_FIELDS_RESP) {
if(resp_type == STATESERVER_OBJECT_GET_FIELD_RESP) {
m_log->warning() << "Received GetFieldResp, but expecting GetFieldsResp." << std::endl;
} else if(resp_type == STATESERVER_OBJECT_GET_ALL_RESP) {
m_log->warning() << "Received GetAllResp, but expecting GetFieldsResp." << std::endl;
}
return;
}
m_log->trace() << "Received GetFieldResp from database." << std::endl;
// Add database field payload to response (don't know dclass, so must copy payload).
if(dgi.read_bool() == true) {
dgi.read_uint16(); // Discard field count
dg->add_data(dgi.read_remainder());
}
route_datagram(dg);
}
示例5: unpack_db_fields
bool unpack_db_fields(DatagramIterator &dgi, DCClass* dclass,
std::unordered_map<DCField*, std::vector<uint8_t> > &required,
std::map<DCField*, std::vector<uint8_t> > &ram)
{
// Unload ram and required fields from database resp
uint16_t db_field_count = dgi.read_uint16();
for(uint16_t i = 0; i < db_field_count; ++i)
{
uint16_t field_id = dgi.read_uint16();
DCField *field = dclass->get_field_by_index(field_id);
if(!field)
{
return false;
}
if(field->is_ram())
{
dgi.unpack_field(field, ram[field]);
}
else if(field->is_required())
{
dgi.unpack_field(field, required[field]);
}
else
{
dgi.skip_field(field);
}
}
return true;
}
示例6: 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);
}
示例7: handle_get_activated
void DBStateServer::handle_get_activated(channel_t sender, DatagramIterator& dgi)
{
uint32_t r_context = dgi.read_uint32();
doid_t r_do_id = dgi.read_doid();
if(m_loading.find(r_do_id) != m_loading.end()) {
return;
}
m_log->trace() << "Received GetActivated for id " << r_do_id << "\n";
if(m_objs.find(r_do_id) != m_objs.end()) {
// If object is active return true
DatagramPtr dg = Datagram::create(sender, r_do_id, DBSS_OBJECT_GET_ACTIVATED_RESP);
dg->add_uint32(r_context);
dg->add_doid(r_do_id);
dg->add_bool(true);
route_datagram(dg);
} else {
// If object isn't active or loading, we can return false
DatagramPtr dg = Datagram::create(sender, r_do_id, DBSS_OBJECT_GET_ACTIVATED_RESP);
dg->add_uint32(r_context);
dg->add_doid(r_do_id);
dg->add_bool(false);
route_datagram(dg);
}
}
示例8: catch
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;
}
示例9: handle_activate
void DBStateServer::handle_activate(DatagramIterator &dgi, bool has_other)
{
uint32_t do_id = dgi.read_uint32();
uint32_t parent_id = dgi.read_uint32();
uint32_t zone_id = dgi.read_uint32();
// Check object is not already active
if(m_objs.find(do_id) != m_objs.end() || m_loading.find(do_id) != m_loading.end())
{
m_log->warning() << "Received activate for already-active object"
<< " - id:" << do_id << std::endl;
return;
}
if(!has_other)
{
auto load_it = m_inactive_loads.find(do_id);
if(load_it == m_inactive_loads.end())
{
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id);
}
else
{
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id, load_it->second);
}
m_loading[do_id]->begin();
}
else
{
uint16_t dc_id = dgi.read_uint16();
// Check dclass is valid
if(dc_id >= g_dcf->get_num_classes())
{
m_log->error() << "Received activate_other with unknown dclass"
<< " - id:" << dc_id << std::endl;
return;
}
DCClass *dclass = g_dcf->get_class(dc_id);
auto load_it = m_inactive_loads.find(do_id);
if(load_it == m_inactive_loads.end())
{
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id, dclass, dgi);
}
else
{
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id, dclass, dgi, load_it->second);
}
m_loading[do_id]->begin();
}
}
示例10: 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);
}
}
示例11: populate_set_fields
bool DBOperation::populate_set_fields(DatagramIterator &dgi, uint16_t field_count,
bool delete_values, bool check_values)
{
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_dbserver->m_log->error() << "Create/modify field request included invalid field #"
<< field_id << "\n";
return false;
}
if(field->has_keyword("db")) {
// Get criteria value
if(check_values) {
dgi.unpack_field(field, m_criteria_fields[field]);
}
// Get update value
if(!delete_values) {
dgi.unpack_field(field, m_set_fields[field]);
} else if(field->has_default_value()) {
string val = field->get_default_value();
m_set_fields[field] = vector<uint8_t>(val.begin(), val.end());
} else {
m_set_fields[field]; // Force insertion of blank vector
}
} else {
m_dbserver->m_log->warning() << "Create/modify field request included non-DB field "
<< field->get_name() << "\n";
// Don't read in a non-db field
if(!delete_values) {
dgi.skip_field(field);
}
// It is not proper to expect a non-db field in criteria.
if(check_values) {
return false;
}
}
}
// A MODIFY_FIELDS request is only valid if we're actually trying to
// change fields. A CREATE_OBJECT request is valid even without fields.
return (m_type == CREATE_OBJECT) || !m_set_fields.empty();
}
示例12: 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";
}
}
示例13: 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);
}
}
示例14: handle_activate
void DBStateServer::handle_activate(DatagramIterator &dgi, bool has_other)
{
doid_t do_id = dgi.read_doid();
doid_t parent_id = dgi.read_doid();
zone_t zone_id = dgi.read_zone();
// Check object is not already active
if(m_objs.find(do_id) != m_objs.end() || m_loading.find(do_id) != m_loading.end()) {
m_log->warning() << "Received activate for already-active object with id " << do_id << "\n";
return;
}
if(!has_other) {
auto load_it = m_inactive_loads.find(do_id);
if(load_it == m_inactive_loads.end()) {
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id);
m_loading[do_id]->begin();
} else {
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id, load_it->second);
}
} else {
uint16_t dc_id = dgi.read_uint16();
// Check id is a valid type id
if(dc_id >= g_dcf->get_num_types()) {
m_log->error() << "Received activate_other with unknown dclass"
" with id " << dc_id << "\n";
return;
}
const Class *dcc = g_dcf->get_class_by_id(dc_id);
if(!dcc) {
m_log->error() << "Tried to activate_other with non-class distributed_type '"
<< g_dcf->get_class_by_id(dc_id)->get_name() << "'\n";
}
auto load_it = m_inactive_loads.find(do_id);
if(load_it == m_inactive_loads.end()) {
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id, dcc, dgi);
m_loading[do_id]->begin();
} else {
m_loading[do_id] = new LoadingObject(this, do_id, parent_id, zone_id, dcc, dgi, load_it->second);
}
}
}
示例15: 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;
}
}