本文整理汇总了C++中configobject::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DumpModifiedAttributes
void IcingaApplication::DumpModifiedAttributes(void)
{
String path = GetModAttrPath();
std::fstream fp;
String tempFilename = Utility::CreateTempFile(path + ".XXXXXX", 0644, fp);
fp.exceptions(std::ofstream::failbit | std::ofstream::badbit);
ConfigObject::Ptr previousObject;
ConfigObject::DumpModifiedAttributes(boost::bind(&PersistModAttrHelper, boost::ref(fp), boost::ref(previousObject), _1, _2, _3));
if (previousObject) {
ConfigWriter::EmitRaw(fp, "\tobj.version = ");
ConfigWriter::EmitValue(fp, 0, previousObject->GetVersion());
ConfigWriter::EmitRaw(fp, "\n}\n");
}
fp.close();
#ifdef _WIN32
_unlink(path.CStr());
#endif /* _WIN32 */
if (rename(tempFilename.CStr(), path.CStr()) < 0) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("rename")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(tempFilename));
}
}
示例2: ConfigObjectModifyAttribute
static void ConfigObjectModifyAttribute(const String& attr, const Value& value)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
ConfigObject::Ptr self = vframe->Self;
REQUIRE_NOT_NULL(self);
return self->ModifyAttribute(attr, value);
}
示例3: PersistMessage
void ApiListener::PersistMessage(const Dictionary::Ptr& message, const ConfigObject::Ptr& secobj)
{
double ts = message->Get("ts");
ASSERT(ts != 0);
Dictionary::Ptr pmessage = new Dictionary();
pmessage->Set("timestamp", ts);
pmessage->Set("message", JsonEncode(message));
if (secobj) {
Dictionary::Ptr secname = new Dictionary();
secname->Set("type", secobj->GetReflectionType()->GetName());
secname->Set("name", secobj->GetName());
pmessage->Set("secobj", secname);
}
boost::mutex::scoped_lock lock(m_LogLock);
if (m_LogFile) {
NetString::WriteStringToStream(m_LogFile, JsonEncode(pmessage));
m_LogMessageCount++;
SetLogMessageTimestamp(ts);
if (m_LogMessageCount > 50000) {
CloseLogFile();
RotateLogFile();
OpenLogFile();
}
}
}
示例4: PersistModAttrHelper
static void PersistModAttrHelper(std::fstream& fp, ConfigObject::Ptr& previousObject, const ConfigObject::Ptr& object, const String& attr, const Value& value)
{
if (object != previousObject) {
if (previousObject) {
ConfigWriter::EmitRaw(fp, "\tobj.version = ");
ConfigWriter::EmitValue(fp, 0, previousObject->GetVersion());
ConfigWriter::EmitRaw(fp, "\n}\n\n");
}
ConfigWriter::EmitRaw(fp, "var obj = ");
Array::Ptr args1 = new Array();
args1->Add(object->GetReflectionType()->GetName());
args1->Add(object->GetName());
ConfigWriter::EmitFunctionCall(fp, "get_object", args1);
ConfigWriter::EmitRaw(fp, "\nif (obj) {\n");
}
ConfigWriter::EmitRaw(fp, "\tobj.");
Array::Ptr args2 = new Array();
args2->Add(attr);
args2->Add(value);
ConfigWriter::EmitFunctionCall(fp, "modify_attribute", args2);
ConfigWriter::EmitRaw(fp, "\n");
previousObject = object;
}
示例5: ConfigObjectRestoreAttribute
static void ConfigObjectRestoreAttribute(const String& attr)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
ConfigObject::Ptr self = vframe->Self;
REQUIRE_NOT_NULL(self);
return self->RestoreAttribute(attr);
}
示例6: ObjectHandler
void CheckerComponent::ObjectHandler(const ConfigObject::Ptr& object)
{
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
if (!checkable)
return;
Zone::Ptr zone = Zone::GetByName(checkable->GetZoneName());
bool same_zone = (!zone || Zone::GetLocalZone() == zone);
{
boost::mutex::scoped_lock lock(m_Mutex);
if (object->IsActive() && !object->IsPaused() && same_zone) {
if (m_PendingCheckables.find(checkable) != m_PendingCheckables.end())
return;
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
} else {
m_IdleCheckables.erase(checkable);
m_PendingCheckables.erase(checkable);
}
m_CV.notify_all();
}
}
示例7: Dictionary
BOOST_FOREACH(const Object::Ptr& pobj, DependencyGraph::GetParents((obj))) {
ConfigObject::Ptr configObj = dynamic_pointer_cast<ConfigObject>(pobj);
if (!configObj)
continue;
Dictionary::Ptr refInfo = new Dictionary();
refInfo->Set("type", configObj->GetType()->GetName());
refInfo->Set("name", configObj->GetName());
used_by->Add(refInfo);
}
示例8: CanAccessObject
bool Zone::CanAccessObject(const ConfigObject::Ptr& object)
{
Zone::Ptr object_zone;
if (object->GetReflectionType() == Zone::TypeInstance)
object_zone = static_pointer_cast<Zone>(object);
else
object_zone = static_pointer_cast<Zone>(object->GetZone());
if (!object_zone)
object_zone = Zone::GetLocalZone();
return object_zone->IsChildOf(this);
}
示例9: 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;
}
示例10: DeleteObject
bool ConfigObjectUtility::DeleteObject(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors)
{
if (object->GetPackage() != "_api") {
if (errors)
errors->Add("Object cannot be deleted because it was not created using the API.");
return false;
}
return DeleteObjectHelper(object, cascade, errors);
}
示例11: UnregisterObject
void ConfigType::UnregisterObject(const ConfigObject::Ptr& object)
{
String name = object->GetName();
{
boost::mutex::scoped_lock lock(m_Mutex);
m_ObjectMap.erase(name);
m_ObjectVector.erase(std::remove(m_ObjectVector.begin(), m_ObjectVector.end(), object), m_ObjectVector.end());
}
}
示例12: UnregisterObject
void ConfigType::UnregisterObject(const ConfigObject::Ptr& object)
{
String name = object->GetName();
{
ObjectLock olock(this);
m_ObjectMap.erase(name);
m_ObjectVector.erase(std::remove(m_ObjectVector.begin(), m_ObjectVector.end(), object), m_ObjectVector.end());
}
}
示例13:
ValidationError::ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message)
: m_Object(object), m_AttributePath(attributePath), m_Message(message)
{
String path;
BOOST_FOREACH(const String& attribute, attributePath) {
if (!path.IsEmpty())
path += " -> ";
path += "'" + attribute + "'";
}
Type::Ptr type = object->GetReflectionType();
m_What = "Validation failed for object '" + object->GetName() + "' of type '" + type->GetName() + "'";
if (!path.IsEmpty())
m_What += "; Attribute " + path;
m_What += ": " + message;
}
示例14: RestoreObject
void ConfigObject::RestoreObject(const String& message, int attributeTypes)
{
Dictionary::Ptr persistentObject = JsonDecode(message);
String type = persistentObject->Get("type");
String name = persistentObject->Get("name");
ConfigObject::Ptr object = GetObject(type, name);
if (!object)
return;
#ifdef I2_DEBUG
Log(LogDebug, "ConfigObject")
<< "Restoring object '" << name << "' of type '" << type << "'.";
#endif /* I2_DEBUG */
Dictionary::Ptr update = persistentObject->Get("update");
Deserialize(object, update, false, attributeTypes);
object->OnStateLoaded();
object->SetStateLoaded(true);
}
示例15: RegisterObject
void ConfigType::RegisterObject(const ConfigObject::Ptr& object)
{
String name = object->GetName();
{
ObjectLock olock(this);
ObjectMap::iterator it = m_ObjectMap.find(name);
if (it != m_ObjectMap.end()) {
if (it->second == object)
return;
BOOST_THROW_EXCEPTION(ScriptError("An object with type '" + m_Name + "' and name '" + name + "' already exists (" +
Convert::ToString(it->second->GetDebugInfo()) + "), new declaration: " + Convert::ToString(object->GetDebugInfo()),
object->GetDebugInfo()));
}
m_ObjectMap[name] = object;
m_ObjectVector.push_back(object);
}
}