void ConfigObject::OnAllConfigLoaded(void)
{
- /* Nothing to do here. */
+ m_Zone = GetObject("Zone", GetZoneName());
}
void ConfigObject::CreateChildObjects(const Type::Ptr& childType)
return ConfigObject::Ptr();
return dtype->GetObject(name);
}
+
+ConfigObject::Ptr ConfigObject::GetZone(void) const
+{
+ return m_Zone;
+}
Value GetExtension(const String& key);
void ClearExtension(const String& key);
+ ConfigObject::Ptr GetZone(void) const;
+
void ModifyAttribute(const String& attr, const Value& value, bool updateVersion = true);
void RestoreAttribute(const String& attr, bool updateVersion = true);
bool IsAttributeModified(const String& attr) const;
explicit ConfigObject(void);
private:
+ ConfigObject::Ptr m_Zone;
+
static void RestoreObject(const String& message, int attributeTypes);
};
REGISTER_TYPE(ApiListener);
boost::signals2::signal<void(bool)> ApiListener::OnMasterChanged;
+ApiListener::Ptr ApiListener::m_Instance;
REGISTER_STATSFUNCTION(ApiListener, &ApiListener::StatsFunc);
void ApiListener::OnAllConfigLoaded(void)
{
- if (!Endpoint::GetByName(GetIdentity()))
+ m_LocalEndpoint = Endpoint::GetByName(GetIdentity());
+
+ if (!m_LocalEndpoint)
BOOST_THROW_EXCEPTION(ScriptError("Endpoint object for '" + GetIdentity() + "' is missing.", GetDebugInfo()));
}
{
SyncZoneDirs();
- if (std::distance(ConfigType::GetObjectsByType<ApiListener>().first,
- ConfigType::GetObjectsByType<ApiListener>().second) > 1) {
- Log(LogCritical, "ApiListener", "Only one ApiListener object is allowed.");
- return;
- }
+ if (m_Instance)
+ BOOST_THROW_EXCEPTION(ScriptError("Only one ApiListener object is allowed.", GetDebugInfo()));
+
+ m_Instance = this;
ObjectImpl<ApiListener>::Start(runtimeCreated);
ApiListener::Ptr ApiListener::GetInstance(void)
{
- BOOST_FOREACH(const ApiListener::Ptr& listener, ConfigType::GetObjectsByType<ApiListener>())
- return listener;
-
- return ApiListener::Ptr();
+ return m_Instance;
}
boost::shared_ptr<SSL_CTX> ApiListener::GetSSLContext(void) const
if (!master)
return false;
- return master->GetName() == GetIdentity();
+ return master == GetLocalEndpoint();
}
/**
bool need = false;
BOOST_FOREACH(const Endpoint::Ptr& endpoint, ConfigType::GetObjectsByType<Endpoint>()) {
- if (endpoint->GetName() == GetIdentity())
+ if (endpoint == GetLocalEndpoint())
continue;
if (endpoint->GetLogDuration() >= 0 && ts < now - endpoint->GetLogDuration())
BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) {
/* don't connect to ourselves */
- if (endpoint->GetName() == GetIdentity()) {
+ if (endpoint == GetLocalEndpoint()) {
Log(LogDebug, "ApiListener")
<< "Not connecting to Endpoint '" << endpoint->GetName() << "' because that's us.";
continue;
BOOST_FOREACH(const Endpoint::Ptr& endpoint, ConfigType::GetObjectsByType<Endpoint>()) {
/* don't relay messages to ourselves */
- if (endpoint->GetName() == GetIdentity())
+ if (endpoint == GetLocalEndpoint())
continue;
Zone::Ptr target_zone = endpoint->GetZone();
{
return Empty;
}
+
+Endpoint::Ptr ApiListener::GetLocalEndpoint(void) const
+{
+ return m_LocalEndpoint;
+}
Endpoint::Ptr GetMaster(void) const;
bool IsMaster(void) const;
+ Endpoint::Ptr GetLocalEndpoint(void) const;
+
static String GetApiDir(void);
void SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionary::Ptr& message);
std::set<JsonRpcConnection::Ptr> m_AnonymousClients;
std::set<HttpServerConnection::Ptr> m_HttpClients;
Timer::Ptr m_Timer;
+ Endpoint::Ptr m_LocalEndpoint;
+
+ static ApiListener::Ptr m_Instance;
void ApiTimerHandler(void);
if (!listener)
return Endpoint::Ptr();
- return Endpoint::GetByName(listener->GetIdentity());
+ return listener->GetLocalEndpoint();
}
REGISTER_TYPE(Zone);
+void Zone::OnAllConfigLoaded(void)
+{
+ m_Parent = Zone::GetByName(GetParentRaw());
+}
+
Zone::Ptr Zone::GetParent(void) const
{
- return Zone::GetByName(GetParentRaw());
+ return m_Parent;
}
std::set<Endpoint::Ptr> Zone::GetEndpoints(void) const
if (dynamic_pointer_cast<Zone>(object))
object_zone = static_pointer_cast<Zone>(object);
else
- object_zone = Zone::GetByName(object->GetZoneName());
+ object_zone = static_pointer_cast<Zone>(object->GetZone());
if (!object_zone)
object_zone = Zone::GetLocalZone();
DECLARE_OBJECT(Zone);
DECLARE_OBJECTNAME(Zone);
+ virtual void OnAllConfigLoaded(void) override;
+
Zone::Ptr GetParent(void) const;
std::set<Endpoint::Ptr> GetEndpoints(void) const;
bool IsGlobal(void) const;
static Zone::Ptr GetLocalZone(void);
+
+private:
+ Zone::Ptr m_Parent;
};
}