本文整理汇总了C++中zone::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnAllConfigLoaded
void Zone::OnAllConfigLoaded()
{
ObjectImpl<Zone>::OnAllConfigLoaded();
m_Parent = Zone::GetByName(GetParentRaw());
if (m_Parent && m_Parent->IsGlobal())
BOOST_THROW_EXCEPTION(ScriptError("Zone '" + GetName() + "' can not have a global zone as parent.", GetDebugInfo()));
Zone::Ptr zone = m_Parent;
int levels = 0;
Array::Ptr endpoints = GetEndpointsRaw();
if (endpoints) {
ObjectLock olock(endpoints);
for (const String& endpoint : endpoints) {
Endpoint::Ptr ep = Endpoint::GetByName(endpoint);
if (ep)
ep->SetCachedZone(this);
}
}
while (zone) {
m_AllParents.push_back(zone);
zone = Zone::GetByName(zone->GetParentRaw());
levels++;
if (levels > 32)
BOOST_THROW_EXCEPTION(ScriptError("Infinite recursion detected while resolving zone graph. Check your zone hierarchy.", GetDebugInfo()));
}
}
示例2: IsHACluster
bool ApiListener::IsHACluster(void)
{
Zone::Ptr zone = Zone::GetLocalZone();
if (!zone)
return false;
return zone->IsSingleInstance();
}
示例3: GetConfigFields
Dictionary::Ptr ZoneDbObject::GetConfigFields() const
{
Zone::Ptr zone = static_pointer_cast<Zone>(GetObject());
return new Dictionary({
{ "is_global", zone->IsGlobal() ? 1 : 0 },
{ "parent_zone_object_id", zone->GetParent() }
});
}
示例4: thread
BOOST_FOREACH(const Zone::Ptr& zone, ConfigType::GetObjectsByType<Zone>()) {
/* don't connect to global zones */
if (zone->GetGlobal())
continue;
/* only connect to endpoints in a) the same zone b) our parent zone c) immediate child zones */
if (my_zone != zone && my_zone != zone->GetParent() && zone != my_zone->GetParent()) {
Log(LogDebug, "ApiListener")
<< "Not connecting to Zone '" << zone->GetName()
<< "' because it's not in the same zone, a parent or a child zone.";
continue;
}
BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) {
/* don't connect to ourselves */
if (endpoint == GetLocalEndpoint()) {
Log(LogDebug, "ApiListener")
<< "Not connecting to Endpoint '" << endpoint->GetName() << "' because that's us.";
continue;
}
/* don't try to connect to endpoints which don't have a host and port */
if (endpoint->GetHost().IsEmpty() || endpoint->GetPort().IsEmpty()) {
Log(LogDebug, "ApiListener")
<< "Not connecting to Endpoint '" << endpoint->GetName()
<< "' because the host/port attributes are missing.";
continue;
}
/* don't try to connect if there's already a connection attempt */
if (endpoint->GetConnecting()) {
Log(LogDebug, "ApiListener")
<< "Not connecting to Endpoint '" << endpoint->GetName()
<< "' because we're already trying to connect to it.";
continue;
}
/* don't try to connect if we're already connected */
if (endpoint->GetConnected()) {
Log(LogDebug, "ApiListener")
<< "Not connecting to Endpoint '" << endpoint->GetName()
<< "' because we're already connected to it.";
continue;
}
boost::thread thread(boost::bind(&ApiListener::AddConnection, this, endpoint));
thread.detach();
}
}
示例5: GetFromZoneName
/* Provide a helper function for zone origin name. */
String ApiListener::GetFromZoneName(const Zone::Ptr& fromZone)
{
String fromZoneName;
if (fromZone) {
fromZoneName = fromZone->GetName();
} else {
Zone::Ptr lzone = Zone::GetLocalZone();
if (lzone)
fromZoneName = lzone->GetName();
}
return fromZoneName;
}
示例6: SendConfigUpdate
void ApiListener::SendConfigUpdate(const JsonRpcConnection::Ptr& aclient)
{
Endpoint::Ptr endpoint = aclient->GetEndpoint();
ASSERT(endpoint);
Zone::Ptr azone = endpoint->GetZone();
Zone::Ptr lzone = Zone::GetLocalZone();
/* don't try to send config updates to our master */
if (!azone->IsChildOf(lzone))
return;
Dictionary::Ptr configUpdateV1 = new Dictionary();
Dictionary::Ptr configUpdateV2 = new Dictionary();
String zonesDir = Configuration::DataDir + "/api/zones";
for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
String zoneDir = zonesDir + "/" + zone->GetName();
if (!zone->IsChildOf(azone) && !zone->IsGlobal())
continue;
if (!Utility::PathExists(zoneDir))
continue;
Log(LogInformation, "ApiListener")
<< "Syncing configuration files for " << (zone->IsGlobal() ? "global " : "")
<< "zone '" << zone->GetName() << "' to endpoint '" << endpoint->GetName() << "'.";
ConfigDirInformation config = LoadConfigDir(zonesDir + "/" + zone->GetName());
configUpdateV1->Set(zone->GetName(), config.UpdateV1);
configUpdateV2->Set(zone->GetName(), config.UpdateV2);
}
Dictionary::Ptr message = new Dictionary({
{ "jsonrpc", "2.0" },
{ "method", "config::Update" },
{ "params", new Dictionary({
{ "update", configUpdateV1 },
{ "update_v2", configUpdateV2 }
}) }
});
aclient->SendMessage(message);
}
示例7: GetStatusFields
Dictionary::Ptr ZoneDbObject::GetStatusFields() const
{
Zone::Ptr zone = static_pointer_cast<Zone>(GetObject());
Log(LogDebug, "ZoneDbObject")
<< "update status for zone '" << zone->GetName() << "'";
return new Dictionary({
{ "parent_zone_object_id", zone->GetParent() }
});
}
示例8: IsChildOf
bool Zone::IsChildOf(const Zone::Ptr& zone)
{
Zone::Ptr azone = this;
while (azone) {
if (azone == zone)
return true;
azone = azone->GetParent();
}
return false;
}
示例9: ZoneAccessor
Value EndpointsTable::ZoneAccessor(const Value& row)
{
Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
if (!endpoint)
return Empty;
Zone::Ptr zone = endpoint->GetZone();
if (!zone)
return Empty;
return zone->GetName();
}
示例10: GetMaster
Endpoint::Ptr ApiListener::GetMaster(void) const
{
Zone::Ptr zone = Zone::GetLocalZone();
if (!zone)
return Endpoint::Ptr();
std::vector<String> names;
BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints())
if (endpoint->IsConnected() || endpoint->GetName() == GetIdentity())
names.push_back(endpoint->GetName());
std::sort(names.begin(), names.end());
return Endpoint::GetByName(*names.begin());
}
示例11: SyncZoneDir
void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
{
Dictionary::Ptr newConfig = new Dictionary();
BOOST_FOREACH(const ZoneFragment& zf, ConfigCompiler::GetZoneDirs(zone->GetName())) {
Dictionary::Ptr newConfigPart = LoadConfigDir(zf.Path);
ObjectLock olock(newConfigPart);
BOOST_FOREACH(const Dictionary::Pair& kv, newConfigPart) {
newConfig->Set("/" + zf.Tag + kv.first, kv.second);
}
}
示例12: OnAllConfigLoaded
void Checkable::OnAllConfigLoaded(void)
{
ObjectImpl<Checkable>::OnAllConfigLoaded();
Endpoint::Ptr endpoint = GetCommandEndpoint();
if (endpoint) {
Zone::Ptr checkableZone = static_pointer_cast<Zone>(GetZone());
if (!checkableZone)
checkableZone = Zone::GetLocalZone();
Zone::Ptr cmdZone = endpoint->GetZone();
if (checkableZone && cmdZone != checkableZone && cmdZone->GetParent() != checkableZone) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("command_endpoint"),
"Command endpoint must be in zone '" + checkableZone->GetName() + "' or in a direct child zone thereof."));
}
}
}
示例13: SyncZoneDir
void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
{
ConfigDirInformation newConfigInfo;
newConfigInfo.UpdateV1 = new Dictionary();
newConfigInfo.UpdateV2 = new Dictionary();
for (const ZoneFragment& zf : ConfigCompiler::GetZoneDirs(zone->GetName())) {
ConfigDirInformation newConfigPart = LoadConfigDir(zf.Path);
{
ObjectLock olock(newConfigPart.UpdateV1);
for (const Dictionary::Pair& kv : newConfigPart.UpdateV1) {
newConfigInfo.UpdateV1->Set("/" + zf.Tag + kv.first, kv.second);
}
}
{
ObjectLock olock(newConfigPart.UpdateV2);
for (const Dictionary::Pair& kv : newConfigPart.UpdateV2) {
newConfigInfo.UpdateV2->Set("/" + zf.Tag + kv.first, kv.second);
}
}
}
int sumUpdates = newConfigInfo.UpdateV1->GetLength() + newConfigInfo.UpdateV2->GetLength();
if (sumUpdates == 0)
return;
String oldDir = Configuration::DataDir + "/api/zones/" + zone->GetName();
Log(LogInformation, "ApiListener")
<< "Copying " << sumUpdates << " zone configuration files for zone '" << zone->GetName() << "' to '" << oldDir << "'.";
Utility::MkDirP(oldDir, 0700);
ConfigDirInformation oldConfigInfo = LoadConfigDir(oldDir);
UpdateConfigDir(oldConfigInfo, newConfigInfo, oldDir, true);
}
示例14: OnAllConfigLoaded
void Checkable::OnAllConfigLoaded()
{
ObjectImpl<Checkable>::OnAllConfigLoaded();
Endpoint::Ptr endpoint = GetCommandEndpoint();
if (endpoint) {
Zone::Ptr checkableZone = static_pointer_cast<Zone>(GetZone());
if (checkableZone) {
Zone::Ptr cmdZone = endpoint->GetZone();
if (cmdZone != checkableZone && cmdZone->GetParent() != checkableZone) {
BOOST_THROW_EXCEPTION(ValidationError(this, { "command_endpoint" },
"Command endpoint must be in zone '" + checkableZone->GetName() + "' or in a direct child zone thereof."));
}
} else {
BOOST_THROW_EXCEPTION(ValidationError(this, { "command_endpoint" },
"Command endpoint must not be set."));
}
}
}
示例15: SyncZoneDir
void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
{
String newDir = Application::GetZonesDir() + "/" + zone->GetName();
String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName();
Log(LogInformation, "ApiListener")
<< "Copying zone configuration files from '" << newDir << "' to '" << oldDir << "'.";
if (!Utility::MkDir(oldDir, 0700)) {
Log(LogCritical, "ApiListener")
<< "mkdir() for path '" << oldDir << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("mkdir")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(oldDir));
}
Dictionary::Ptr newConfig = LoadConfigDir(newDir);
Dictionary::Ptr oldConfig = LoadConfigDir(oldDir);
UpdateConfigDir(oldConfig, newConfig, oldDir);
}