1 /******************************************************************************
3 * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
22 using namespace icinga;
24 REGISTER_TYPE(Component, NULL);
27 * Constructor for the component class.
29 Component::Component(const Dictionary::Ptr& properties)
30 : DynamicObject(properties)
32 assert(Application::IsMainThread());
35 throw_exception(runtime_error("Component objects must be local."));
44 Logger::Write(LogInformation, "base", "Loading component '" + GetName() + "'");
46 hModule = Utility::LoadIcingaLibrary(GetName(), true);
48 CreateComponentFunction pCreateComponent;
51 pCreateComponent = reinterpret_cast<CreateComponentFunction>(GetProcAddress(hModule,
55 /* suppress compiler warning for void * cast */
58 pCreateComponent = reinterpret_cast<CreateComponentFunction>(lt_dlsym(hModule,
65 if (pCreateComponent == NULL)
66 throw_exception(runtime_error("Loadable module does not contain "
67 "CreateComponent function"));
69 /* pCreateComponent returns a raw pointer which we must wrap in a shared_ptr */
70 impl = IComponent::Ptr(pCreateComponent());
73 throw_exception(runtime_error("CreateComponent function returned NULL."));
87 * Destructor for the Component class.
89 Component::~Component(void)
96 * Starts the component. Called when the DynamicObject is fully
97 * constructed/registered.
99 void Component::Start(void)
101 m_Impl->m_Config = GetSelf();
106 * Adds a directory to the component search path.
108 * @param componentDirectory The directory.
110 void Component::AddSearchDir(const String& componentDirectory)
112 Logger::Write(LogInformation, "base", "Adding library search dir: " +
116 SetDllDirectory(componentDirectory.CStr());
118 lt_dladdsearchdir(componentDirectory.CStr());
123 * Retrieves the configuration for this component.
125 * @returns The configuration.
127 DynamicObject::Ptr IComponent::GetConfig(void) const
129 return m_Config.lock();
133 * Starts the component.
135 void IComponent::Start(void)
137 /* Nothing to do in the default implementation. */
141 * Stops the component.
143 void IComponent::Stop(void)
145 /* Nothing to do in the default implementation. */