return m_ConfigHive;
}
-Component::RefType Application::LoadComponent(string name)
+Component::RefType Application::LoadComponent(string path, ConfigObject::RefType componentConfig)
{
Component::RefType component;
Component *(*pCreateComponent)();
- component = GetComponent(name);
-
- if (component.get() != NULL)
- return component;
-
- Log("Loading component '%s'", name.c_str());
-
- ConfigObject::RefType componentConfig = m_ConfigHive->GetObject("component", name);
-
- if (componentConfig.get() == NULL) {
- componentConfig = new_object<ConfigObject>();
- componentConfig->SetName(name);
- componentConfig->SetType("component");
- m_ConfigHive->AddObject(componentConfig);
- }
-
- string path = componentConfig->GetProperty("path", name);
+ Log("Loading component '%s'", path.c_str());
HMODULE hModule = LoadLibrary(path.c_str());
ConfigHive::RefType GetConfigHive(void);
- shared_ptr<Component> LoadComponent(string name);
+ shared_ptr<Component> LoadComponent(string path, ConfigObject::RefType componentConfig);
void UnloadComponent(string name);
shared_ptr<Component> GetComponent(string name);
};
void ConfigObject::SetProperty(const string& name, const string& value)
{
- string oldValue = GetProperty(name);
-
Properties[name] = value;
ConfigHive::RefType hive = m_Hive.lock();
ea->Source = hive;
ea->Object = static_pointer_cast<ConfigObject>(shared_from_this());
ea->Property = name;
- ea->OldValue = oldValue;
+
+ string oldValue;
+ if (GetProperty(name, &oldValue))
+ ea->OldValue = oldValue;
+
hive->OnPropertyChanged(ea);
}
}
-string ConfigObject::GetProperty(const string& name, const string& defaultValue) const
+bool ConfigObject::GetProperty(const string& name, string *value) const
{
map<string, string>::const_iterator vi = Properties.find(name);
if (vi == Properties.end())
- return defaultValue;
- return vi->second;
+ return false;
+ *value = vi->second;
+ return true;
}
-int ConfigObject::GetPropertyInteger(const string& name, int defaultValue) const
+bool ConfigObject::GetPropertyInteger(const string& name, int *value) const
{
- string value = GetProperty(name);
- if (value == string())
- return defaultValue;
- return strtol(value.c_str(), NULL, 10);
+ string stringValue;
+ if (!GetProperty(name, &stringValue))
+ return false;
+ *value = strtol(stringValue.c_str(), NULL, 10);
+ return true;
}
-double ConfigObject::GetPropertyDouble(const string& name, double defaultValue) const
+bool ConfigObject::GetPropertyDouble(const string& name, double *value) const
{
- string value = GetProperty(name);
- if (value == string())
- return defaultValue;
- return strtod(value.c_str(), NULL);
+ string stringValue;
+ if (!GetProperty(name, &stringValue))
+ return false;
+ *value = strtod(stringValue.c_str(), NULL);
+ return true;
}
void SetPropertyInteger(const string& name, int value);
void SetPropertyDouble(const string& name, double value);
- string GetProperty(const string& name, const string& defaultValue = string()) const;
- int GetPropertyInteger(const string& name, int defaultValue = 0) const;
- double GetPropertyDouble(const string& name, double defaultValue = 0.0f) const;
+ bool GetProperty(const string& name, string *value) const;
+ bool GetPropertyInteger(const string& name, int *value) const;
+ bool GetPropertyDouble(const string& name, double *value) const;
};
}
ifstream fp;
FIFO::RefType fifo = new_object<FIFO>();
- fp.open(GetConfig()->GetProperty("filename").c_str(), ifstream::in);
+ string filename;
+ if (!GetConfig()->GetProperty("filename", &filename))
+ throw exception(/*"Missing filename property"*/);
+
+ fp.open(filename.c_str(), ifstream::in);
if (fp.fail())
throw exception(/*"Could not open config file"*/);
ConnectionManager::RefType connectionManager = icingaApp->GetConnectionManager();
ConfigHive::RefType configHive = icingaApp->GetConfigHive();
- if (GetConfig()->GetPropertyInteger("configSource") != 0) {
+ int configSource;
+ if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
connectionManager->RegisterMethod("config::FetchObjects", bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
configHive->OnObjectCreated.bind(bind_weak(&ConfigRpcComponent::LocalObjectCreatedHandler, shared_from_this()));
JsonRpcMessage::RefType msg = MakeObjectMessage(ea->Object, "config::ObjectRemoved", false);
cJSON *params = msg->GetParams();
cJSON_AddStringToObject(params, "property", ea->Property.c_str());
- string value = ea->Object->GetProperty(ea->Property);
+ string value;
+ ea->Object->GetProperty(ea->Property, &value);
cJSON_AddStringToObject(params, "value", value.c_str());
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType ea)
{
if (ea->Object->GetType() == "component") {
- LoadComponent(ea->Object->GetName());
+ string path;
+
+ if (!ea->Object->GetProperty("path", &path))
+ throw exception(/*"Missing path property"*/);
+
+ LoadComponent(path, ea->Object);
}
return 0;