本文整理汇总了C++中DatagramPtr::add_bool方法的典型用法代码示例。如果您正苦于以下问题:C++ DatagramPtr::add_bool方法的具体用法?C++ DatagramPtr::add_bool怎么用?C++ DatagramPtr::add_bool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatagramPtr
的用法示例。
在下文中一共展示了DatagramPtr::add_bool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: handle_get_fields
void DBStateServer::handle_get_fields(channel_t sender, DatagramIterator &dgi)
{
uint32_t r_context = dgi.read_uint32();
doid_t r_do_id = dgi.read_doid();
uint16_t field_count = dgi.read_uint16();
if(is_activated_object(r_do_id)) {
return;
}
m_log->trace() << "Received GetFields for inactive object with id " << r_do_id << std::endl;
// Read requested fields from datagram
std::vector<const Field*> db_fields; // Ram|required db fields in request
std::vector<const Field*> ram_fields; // Ram|required but not-db fields in request
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) {
DatagramPtr dg = Datagram::create(sender, r_do_id, STATESERVER_OBJECT_GET_FIELDS_RESP);
dg->add_uint32(r_context);
dg->add_uint8(false);
route_datagram(dg);
} else if(field->has_keyword("ram") || field->has_keyword("required")) {
if(field->has_keyword("db")) {
db_fields.push_back(field);
} else {
ram_fields.push_back(field);
}
}
}
if(db_fields.size()) {
// Get context for db query
uint32_t db_context = m_next_context++;
// Prepare reponse datagram
if(m_context_datagrams.find(db_context) == m_context_datagrams.end()) {
m_context_datagrams[db_context] = Datagram::create(sender, r_do_id,
STATESERVER_OBJECT_GET_FIELDS_RESP);
}
m_context_datagrams[db_context]->add_uint32(r_context);
m_context_datagrams[db_context]->add_bool(true);
m_context_datagrams[db_context]->add_uint16(ram_fields.size() + db_fields.size());
for(const auto& it : ram_fields) {
m_context_datagrams[db_context]->add_uint16(it->get_id());
m_context_datagrams[db_context]->add_data(it->get_default_value());
}
// Send query to database
DatagramPtr dg = Datagram::create(m_db_channel, r_do_id, DBSERVER_OBJECT_GET_FIELDS);
dg->add_uint32(db_context);
dg->add_doid(r_do_id);
dg->add_uint16(db_fields.size());
for(const auto& it : db_fields) {
dg->add_uint16(it->get_id());
}
route_datagram(dg);
} else { // If no database fields exist
DatagramPtr dg = Datagram::create(sender, r_do_id, STATESERVER_OBJECT_GET_FIELDS_RESP);
dg->add_uint32(r_context);
dg->add_bool(true);
dg->add_uint16(ram_fields.size());
for(const auto& it : ram_fields) {
dg->add_uint16(it->get_id());
dg->add_data(it->get_default_value());
}
route_datagram(dg);
}
}
示例4: handle_datagram
//.........这里部分代码省略.........
zone_t r_zone = dgi.read_zone();
// Update the child count
if(r_parent == m_do_id) {
m_zone_objects[r_zone].insert(doid);
}
break;
}
case STATESERVER_OBJECT_GET_ALL: {
uint32_t context = dgi.read_uint32();
if(dgi.read_doid() != m_do_id) {
return; // Not meant for this object!
}
DatagramPtr dg = Datagram::create(sender, m_do_id, STATESERVER_OBJECT_GET_ALL_RESP);
dg->add_uint32(context);
append_required_data(dg);
append_other_data(dg);
route_datagram(dg);
break;
}
case STATESERVER_OBJECT_GET_FIELD: {
uint32_t context = dgi.read_uint32();
if(dgi.read_doid() != m_do_id) {
return; // Not meant for this object!
}
uint16_t field_id = dgi.read_uint16();
DatagramPtr raw_field = Datagram::create();
bool success = handle_one_get(raw_field, field_id);
DatagramPtr dg = Datagram::create(sender, m_do_id, STATESERVER_OBJECT_GET_FIELD_RESP);
dg->add_uint32(context);
dg->add_bool(success);
if(success) {
dg->add_data(raw_field);
}
route_datagram(dg);
break;
}
case STATESERVER_OBJECT_GET_FIELDS: {
uint32_t context = dgi.read_uint32();
if(dgi.read_doid() != m_do_id) {
return; // Not meant for this object!
}
uint16_t field_count = dgi.read_uint16();
// Read our requested fields into a sorted set
set<uint16_t> requested_fields;
for(int i = 0; i < field_count; ++i) {
uint16_t field_id = dgi.read_uint16();
if(!requested_fields.insert(field_id).second) {
const dclass::Field* field = m_dclass->get_field_by_id(field_id);
if(field != nullptr) {
// If it is null, handle_one_get will produce a warning for us later
m_log->warning() << "Received duplicate field '"
<< field->get_name() << "' in get_fields.\n";
}
}
}
// Try to get the values for all the fields
bool success = true;
uint16_t fields_found = 0;
DatagramPtr raw_fields = Datagram::create();