本文整理汇总了C++中configobject::Ptr::SetExtension方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::SetExtension方法的具体用法?C++ Ptr::SetExtension怎么用?C++ Ptr::SetExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configobject::Ptr
的用法示例。
在下文中一共展示了Ptr::SetExtension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeleteObjectHelper
bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors)
{
std::vector<Object::Ptr> parents = DependencyGraph::GetParents(object);
Type::Ptr type = object->GetReflectionType();
if (!parents.empty() && !cascade) {
if (errors)
errors->Add("Object '" + object->GetName() + "' of type '" + type->GetName() +
"' cannot be deleted because other objects depend on it. "
"Use cascading delete to delete it anyway.");
return false;
}
for (const Object::Ptr& pobj : parents) {
ConfigObject::Ptr parentObj = dynamic_pointer_cast<ConfigObject>(pobj);
if (!parentObj)
continue;
DeleteObjectHelper(parentObj, cascade, errors);
}
ConfigItem::Ptr item = ConfigItem::GetByTypeAndName(type, object->GetName());
try {
/* mark this object for cluster delete event */
object->SetExtension("ConfigObjectDeleted", true);
/* triggers signal for DB IDO and other interfaces */
object->Deactivate(true);
if (item)
item->Unregister();
else
object->Unregister();
} catch (const std::exception& ex) {
if (errors)
errors->Add(DiagnosticInformation(ex));
return false;
}
String path = GetObjectConfigPath(object->GetReflectionType(), object->GetName());
if (Utility::PathExists(path)) {
if (unlink(path.CStr()) < 0 && errno != ENOENT) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("unlink")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(path));
}
}
return true;
}
示例2: GetOrCreateByObject
DbObject::Ptr DbObject::GetOrCreateByObject(const ConfigObject::Ptr& object)
{
boost::mutex::scoped_lock lock(GetStaticMutex());
DbObject::Ptr dbobj = object->GetExtension("DbObject");
if (dbobj)
return dbobj;
DbType::Ptr dbtype = DbType::GetByName(object->GetType()->GetName());
if (!dbtype)
return DbObject::Ptr();
Service::Ptr service;
String name1, name2;
service = dynamic_pointer_cast<Service>(object);
if (service) {
Host::Ptr host = service->GetHost();
name1 = service->GetHost()->GetName();
name2 = service->GetShortName();
} else {
if (object->GetType() == ConfigType::GetByName("CheckCommand") ||
object->GetType() == ConfigType::GetByName("EventCommand") ||
object->GetType() == ConfigType::GetByName("NotificationCommand")) {
Command::Ptr command = dynamic_pointer_cast<Command>(object);
name1 = CompatUtility::GetCommandName(command);
}
else
name1 = object->GetName();
}
dbobj = dbtype->GetOrCreateObjectByName(name1, name2);
dbobj->SetObject(object);
object->SetExtension("DbObject", dbobj);
return dbobj;
}