void NetString::WriteStringToStream(const Stream::Ptr& stream, const String& str)
{
std::ostringstream msgbuf;
- msgbuf << str.GetLength() << ":" << str << ",";
+ WriteStringToStream(msgbuf, str);
String msg = msgbuf.str();
stream->Write(msg.CStr(), msg.GetLength());
}
+
+/**
+ * Writes data into a stream using the netstring format.
+ *
+ * @param stream The stream.
+ * @param str The String that is to be written.
+ */
+void NetString::WriteStringToStream(std::ostream& stream, const String& str)
+{
+ stream << str.GetLength() << ":" << str << ",";
+}
public:
static StreamReadStatus ReadStringFromStream(const Stream::Ptr& stream, String *message, StreamReadContext& context, bool may_wait = false);
static void WriteStringToStream(const Stream::Ptr& stream, const String& message);
+ static void WriteStringToStream(std::ostream& stream, const String& message);
private:
NetString(void);
inline std::ostream& operator<<(std::ostream& stream, const String& str)
{
- stream << static_cast<std::string>(str);
+ stream << str.GetData();
return stream;
}
inline String operator+(const String& lhs, const String& rhs)
{
- return static_cast<std::string>(lhs)+static_cast<std::string>(rhs);
+ return lhs.GetData() + rhs.GetData();
}
inline String operator+(const String& lhs, const char *rhs)
{
- return static_cast<std::string>(lhs)+rhs;
+ return lhs.GetData() + rhs;
}
inline String operator+(const char *lhs, const String& rhs)
{
- return lhs + static_cast<std::string>(rhs);
+ return lhs + rhs.GetData();
}
inline bool operator==(const String& lhs, const String& rhs)
{
- return static_cast<std::string>(lhs) == static_cast<std::string>(rhs);
+ return lhs.GetData() == rhs.GetData();
}
inline bool operator==(const String& lhs, const char *rhs)
{
- return static_cast<std::string>(lhs) == rhs;
+ return lhs.GetData() == rhs;
}
inline bool operator==(const char *lhs, const String& rhs)
{
- return lhs == static_cast<std::string>(rhs);
+ return lhs == rhs.GetData();
}
inline bool operator<(const String& lhs, const char *rhs)
{
- return static_cast<std::string>(lhs) < rhs;
+ return lhs.GetData() < rhs;
}
inline bool operator<(const char *lhs, const String& rhs)
{
- return lhs < static_cast<std::string>(rhs);
+ return lhs < rhs.GetData();
}
inline bool operator>(const String& lhs, const String& rhs)
{
- return static_cast<std::string>(lhs) > static_cast<std::string>(rhs);
+ return lhs.GetData() > rhs.GetData();
}
inline bool operator>(const String& lhs, const char *rhs)
{
- return static_cast<std::string>(lhs) > rhs;
+ return lhs.GetData() > rhs;
}
inline bool operator>(const char *lhs, const String& rhs)
{
- return lhs > static_cast<std::string>(rhs);
+ return lhs > rhs.GetData();
}
inline bool operator<=(const String& lhs, const String& rhs)
{
- return static_cast<std::string>(lhs) <= static_cast<std::string>(rhs);
+ return lhs.GetData() <= rhs.GetData();
}
inline bool operator<=(const String& lhs, const char *rhs)
{
- return static_cast<std::string>(lhs) <= rhs;
+ return lhs.GetData() <= rhs;
}
inline bool operator<=(const char *lhs, const String& rhs)
{
- return lhs <= static_cast<std::string>(rhs);
+ return lhs <= rhs.GetData();
}
inline bool operator>=(const String& lhs, const String& rhs)
{
- return static_cast<std::string>(lhs) >= static_cast<std::string>(rhs);
+ return lhs.GetData() >= rhs.GetData();
}
inline bool operator>=(const String& lhs, const char *rhs)
{
- return static_cast<std::string>(lhs) >= rhs;
+ return lhs.GetData() >= rhs;
}
inline bool operator>=(const char *lhs, const String& rhs)
{
- return lhs >= static_cast<std::string>(rhs);
+ return lhs >= rhs.GetData();
}
inline bool operator!=(const String& lhs, const String& rhs)
{
- return static_cast<std::string>(lhs) != static_cast<std::string>(rhs);
+ return lhs.GetData() != rhs.GetData();
}
inline bool operator!=(const String& lhs, const char *rhs)
{
- return static_cast<std::string>(lhs) != rhs;
+ return lhs.GetData() != rhs;
}
inline bool operator!=(const char *lhs, const String& rhs)
{
- return lhs != static_cast<std::string>(rhs);
+ return lhs != rhs.GetData();
}
inline String::Iterator range_begin(String& x)
#include "base/netstring.hpp"
#include "base/exception.hpp"
#include <boost/foreach.hpp>
-#include <fstream>
using namespace icinga;
return Singleton<ConfigCompilerContext>::GetInstance();
}
+ConfigCompilerContext::ConfigCompilerContext(void)
+ : m_ObjectsFP(NULL)
+{ }
+
void ConfigCompilerContext::OpenObjectsFile(const String& filename)
{
m_ObjectsPath = filename;
if (!*fp)
BOOST_THROW_EXCEPTION(std::runtime_error("Could not open '" + m_ObjectsTempFile + "' file"));
- m_ObjectsFP = new StdioStream(fp, true);
+ m_ObjectsFP = fp;
}
void ConfigCompilerContext::WriteObject(const Dictionary::Ptr& object)
{
boost::mutex::scoped_lock lock(m_Mutex);
- NetString::WriteStringToStream(m_ObjectsFP, json);
+ NetString::WriteStringToStream(*m_ObjectsFP, json);
}
}
void ConfigCompilerContext::CancelObjectsFile(void)
{
- m_ObjectsFP->Close();
- m_ObjectsFP.reset();
+ delete m_ObjectsFP;
+ m_ObjectsFP = NULL;
#ifdef _WIN32
_unlink(m_ObjectsTempFile.CStr());
void ConfigCompilerContext::FinishObjectsFile(void)
{
- m_ObjectsFP->Close();
- m_ObjectsFP.reset();
+ delete m_ObjectsFP;
+ m_ObjectsFP = NULL;
#ifdef _WIN32
_unlink(m_ObjectsPath.CStr());
#define CONFIGCOMPILERCONTEXT_H
#include "config/i2-config.hpp"
-#include "base/stdiostream.hpp"
#include "base/dictionary.hpp"
#include <boost/thread/mutex.hpp>
+#include <fstream>
namespace icinga
{
class I2_CONFIG_API ConfigCompilerContext
{
public:
+ ConfigCompilerContext(void);
+
void OpenObjectsFile(const String& filename);
void WriteObject(const Dictionary::Ptr& object);
void CancelObjectsFile(void);
private:
String m_ObjectsPath;
String m_ObjectsTempFile;
- StdioStream::Ptr m_ObjectsFP;
+ std::fstream *m_ObjectsFP;
mutable boost::mutex m_Mutex;
};
DebugInfo di = rule.GetDebugInfo();
+#ifdef _DEBUG
Log(LogDebug, "Dependency")
<< "Applying dependency '" << name << "' to object '" << checkable->GetName() << "' for rule " << di;
+#endif /* _DEBUG */
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
builder->SetType("Dependency");
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
Array::Ptr arr = vinstances;
- Array::Ptr arrclone = arr->ShallowClone();
- ObjectLock olock(arrclone);
- BOOST_FOREACH(const Value& instance, arrclone) {
+ ObjectLock olock(arr);
+ BOOST_FOREACH(const Value& instance, arr) {
String name = rule.GetName();
if (!rule.GetFKVar().IsEmpty()) {
Host::Ptr childHost = Host::GetByName(GetChildHostName());
if (childHost) {
- if (GetChildServiceName().IsEmpty()) {
- Log(LogDebug, "Dependency")
- << "Dependency '" << GetName() << "' child host '" << GetChildHostName() << ".";
+ if (GetChildServiceName().IsEmpty())
m_Child = childHost;
- } else {
- Log(LogDebug, "Dependency")
- << "Dependency '" << GetName() << "' child host '" << GetChildHostName() << "' service '" << GetChildServiceName() << "' .";
+ else
m_Child = childHost->GetServiceByShortName(GetChildServiceName());
- }
}
if (!m_Child)
Host::Ptr parentHost = Host::GetByName(GetParentHostName());
if (parentHost) {
- if (GetParentServiceName().IsEmpty()) {
- Log(LogDebug, "Dependency")
- << "Dependency '" << GetName() << "' parent host '" << GetParentHostName() << ".";
+ if (GetParentServiceName().IsEmpty())
m_Parent = parentHost;
- } else {
- Log(LogDebug, "Dependency")
- << "Dependency '" << GetName() << "' parent host '" << GetParentHostName() << "' service '" << GetParentServiceName() << "' .";
+ else
m_Parent = parentHost->GetServiceByShortName(GetParentServiceName());
- }
}
if (!m_Parent)
void Host::CreateChildObjects(const Type::Ptr& childType)
{
- if (childType->GetName() == "ScheduledDowntime")
+ if (childType == ScheduledDowntime::TypeInstance)
ScheduledDowntime::EvaluateApplyRules(this);
- if (childType->GetName() == "Notification")
+ if (childType == Notification::TypeInstance)
Notification::EvaluateApplyRules(this);
- if (childType->GetName() == "Dependency")
+ if (childType == Dependency::TypeInstance)
Dependency::EvaluateApplyRules(this);
- if (childType->GetName() == "Service")
+ if (childType == Service::TypeInstance)
Service::EvaluateApplyRules(this);
}
DebugInfo di = rule.GetDebugInfo();
+#ifdef _DEBUG
Log(LogDebug, "Notification")
<< "Applying notification '" << name << "' to object '" << checkable->GetName() << "' for rule " << di;
+#endif /* _DEBUG */
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
builder->SetType("Notification");
DebugInfo di = rule.GetDebugInfo();
+#ifdef _DEBUG
Log(LogDebug, "ScheduledDowntime")
<< "Applying scheduled downtime '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
+#endif /* _DEBUG */
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
builder->SetType("ScheduledDowntime");
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
Array::Ptr arr = vinstances;
- Array::Ptr arrclone = arr->ShallowClone();
- ObjectLock olock(arrclone);
- BOOST_FOREACH(const Value& instance, arrclone) {
+ ObjectLock olock(arr);
+ BOOST_FOREACH(const Value& instance, arr) {
String name = rule.GetName();
if (!rule.GetFKVar().IsEmpty()) {
DebugInfo di = rule.GetDebugInfo();
+#ifdef _DEBUG
Log(LogDebug, "Service")
<< "Applying service '" << name << "' to host '" << host->GetName() << "' for rule " << di;
+#endif /* _DEBUG */
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
builder->SetType("Service");
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
Array::Ptr arr = vinstances;
- Array::Ptr arrclone = arr->ShallowClone();
- ObjectLock olock(arrclone);
- BOOST_FOREACH(const Value& instance, arrclone) {
+ ObjectLock olock(arr);
+ BOOST_FOREACH(const Value& instance, arr) {
String name = rule.GetName();
if (!rule.GetFKVar().IsEmpty()) {
void Service::CreateChildObjects(const Type::Ptr& childType)
{
- if (childType->GetName() == "ScheduledDowntime")
+ if (childType == ScheduledDowntime::TypeInstance)
ScheduledDowntime::EvaluateApplyRules(this);
- if (childType->GetName() == "Notification")
+ if (childType == Notification::TypeInstance)
Notification::EvaluateApplyRules(this);
- if (childType->GetName() == "Dependency")
+ if (childType == Dependency::TypeInstance)
Dependency::EvaluateApplyRules(this);
}
/* Pre-fill the time period for the next 24 hours. */
double now = Utility::GetTime();
UpdateRegion(now, now + 24 * 3600, true);
+#ifdef _DEBUG
Dump();
+#endif /* _DEBUG */
}
void TimePeriod::AddSegment(double begin, double end)
SetSegments(newSegments);
+#ifdef _DEBUG
Dump();
+#endif /* _DEBUG */
}
void TimePeriod::RemoveSegment(const Dictionary::Ptr& segment)
}
tp->UpdateRegion(valid_end, now + 24 * 3600, false);
+#ifdef _DEBUG
tp->Dump();
+#endif /* _DEBUG */
}
}