mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-31 01:24:19 +02:00
Merge pull request #5946 from Icinga/feature/clang-tidy
Use clang-tidy to add some more C++11 features
This commit is contained in:
commit
966585f23a
@ -93,7 +93,7 @@ static std::vector<String> GlobalArgumentCompletion(const String& argument, cons
|
|||||||
return std::vector<String>();
|
return std::vector<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Main(void)
|
static int Main()
|
||||||
{
|
{
|
||||||
int argc = Application::GetArgC();
|
int argc = Application::GetArgC();
|
||||||
char **argv = Application::GetArgV();
|
char **argv = Application::GetArgV();
|
||||||
|
@ -56,7 +56,7 @@ ConnectForm::ConnectForm(wxWindow *parent, const Url::Ptr& url)
|
|||||||
SetDefaultItem(m_ButtonsOK);
|
SetDefaultItem(m_ButtonsOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
Url::Ptr ConnectForm::GetUrl(void) const
|
Url::Ptr ConnectForm::GetUrl() const
|
||||||
{
|
{
|
||||||
wxString url = "https://" + m_UserText->GetValue() + ":" + m_PasswordText->GetValue()
|
wxString url = "https://" + m_UserText->GetValue() + ":" + m_PasswordText->GetValue()
|
||||||
+ "@" + m_HostText->GetValue() + ":" + m_PortText->GetValue() + "/";
|
+ "@" + m_HostText->GetValue() + ":" + m_PortText->GetValue() + "/";
|
||||||
|
@ -31,7 +31,7 @@ class ConnectForm final : public ConnectFormBase
|
|||||||
public:
|
public:
|
||||||
ConnectForm(wxWindow *parent, const Url::Ptr& url);
|
ConnectForm(wxWindow *parent, const Url::Ptr& url);
|
||||||
|
|
||||||
Url::Ptr GetUrl(void) const;
|
Url::Ptr GetUrl() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ MainFormBase::MainFormBase( wxWindow* parent, wxWindowID id, const wxString& tit
|
|||||||
// Connect Events
|
// Connect Events
|
||||||
this->Connect( m_QuitMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnQuitClicked ) );
|
this->Connect( m_QuitMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnQuitClicked ) );
|
||||||
this->Connect( m_AboutMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnAboutClicked ) );
|
this->Connect( m_AboutMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnAboutClicked ) );
|
||||||
m_TypesTree->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( MainFormBase::OnTypeSelected ), NULL, this );
|
m_TypesTree->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( MainFormBase::OnTypeSelected ), nullptr, this );
|
||||||
m_ObjectsList->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( MainFormBase::OnObjectSelected ), NULL, this );
|
m_ObjectsList->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( MainFormBase::OnObjectSelected ), nullptr, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
MainFormBase::~MainFormBase()
|
MainFormBase::~MainFormBase()
|
||||||
@ -77,8 +77,8 @@ MainFormBase::~MainFormBase()
|
|||||||
// Disconnect Events
|
// Disconnect Events
|
||||||
this->Disconnect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnQuitClicked ) );
|
this->Disconnect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnQuitClicked ) );
|
||||||
this->Disconnect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnAboutClicked ) );
|
this->Disconnect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFormBase::OnAboutClicked ) );
|
||||||
m_TypesTree->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( MainFormBase::OnTypeSelected ), NULL, this );
|
m_TypesTree->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( MainFormBase::OnTypeSelected ), nullptr, this );
|
||||||
m_ObjectsList->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( MainFormBase::OnObjectSelected ), NULL, this );
|
m_ObjectsList->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( MainFormBase::OnObjectSelected ), nullptr, this );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class MainFormBase : public wxFrame
|
|||||||
|
|
||||||
MainFormBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Icinga Studio"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 800,569 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
|
MainFormBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Icinga Studio"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 800,569 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
|
||||||
|
|
||||||
~MainFormBase();
|
~MainFormBase() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class ConnectFormBase : public wxDialog
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ConnectFormBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Icinga Studio - Connect"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE );
|
ConnectFormBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Icinga Studio - Connect"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE );
|
||||||
~ConnectFormBase();
|
~ConnectFormBase() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ class AboutFormBase : public wxDialog
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
AboutFormBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("About Icinga Studio"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE );
|
AboutFormBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("About Icinga Studio"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE );
|
||||||
~AboutFormBase();
|
~AboutFormBase() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ using namespace icinga;
|
|||||||
class IcingaStudio final : public wxApp
|
class IcingaStudio final : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool OnInit(void) override
|
bool OnInit() override
|
||||||
{
|
{
|
||||||
Application::InitializeBase();
|
Application::InitializeBase();
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
pUrl = new Url(argv[1].ToStdString());
|
pUrl = new Url(argv[1].ToStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
MainForm *m = new MainForm(nullptr, pUrl);
|
auto *m = new MainForm(nullptr, pUrl);
|
||||||
m->Show();
|
m->Show();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -111,7 +111,7 @@ void MainForm::OnTypeSelected(wxTreeEvent& event)
|
|||||||
ApiType::Ptr type = m_Types[typeName.ToStdString()];
|
ApiType::Ptr type = m_Types[typeName.ToStdString()];
|
||||||
|
|
||||||
std::vector<String> attrs;
|
std::vector<String> attrs;
|
||||||
attrs.push_back("__name");
|
attrs.emplace_back("__name");
|
||||||
|
|
||||||
m_ApiClient->GetObjects(type->PluralName, std::bind(&MainForm::ObjectsCompletionHandler, this, _1, _2, true),
|
m_ApiClient->GetObjects(type->PluralName, std::bind(&MainForm::ObjectsCompletionHandler, this, _1, _2, true),
|
||||||
std::vector<String>(), attrs);
|
std::vector<String>(), attrs);
|
||||||
@ -170,7 +170,7 @@ void MainForm::OnObjectSelected(wxListEvent& event)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<String> names;
|
std::vector<String> names;
|
||||||
names.push_back(objectName);
|
names.emplace_back(objectName);
|
||||||
|
|
||||||
m_ApiClient->GetObjects(type->PluralName, std::bind(&MainForm::ObjectDetailsCompletionHandler, this, _1, _2, true),
|
m_ApiClient->GetObjects(type->PluralName, std::bind(&MainForm::ObjectDetailsCompletionHandler, this, _1, _2, true),
|
||||||
names, std::vector<String>(), std::vector<String>(), true);
|
names, std::vector<String>(), std::vector<String>(), true);
|
||||||
|
@ -33,10 +33,10 @@ class MainForm final : public MainFormBase
|
|||||||
public:
|
public:
|
||||||
MainForm(wxWindow *parent, const Url::Ptr& url);
|
MainForm(wxWindow *parent, const Url::Ptr& url);
|
||||||
|
|
||||||
virtual void OnQuitClicked(wxCommandEvent& event) override;
|
void OnQuitClicked(wxCommandEvent& event) override;
|
||||||
virtual void OnAboutClicked(wxCommandEvent& event) override;
|
void OnAboutClicked(wxCommandEvent& event) override;
|
||||||
virtual void OnTypeSelected(wxTreeEvent& event) override;
|
void OnTypeSelected(wxTreeEvent& event) override;
|
||||||
virtual void OnObjectSelected(wxListEvent& event) override;
|
void OnObjectSelected(wxListEvent& event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ApiClient::Ptr m_ApiClient;
|
ApiClient::Ptr m_ApiClient;
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
String Application::GetAppVersion(void)
|
String Application::GetAppVersion()
|
||||||
{
|
{
|
||||||
return VERSION;
|
return VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Application::GetAppSpecVersion(void)
|
String Application::GetAppSpecVersion()
|
||||||
{
|
{
|
||||||
return SPEC_VERSION;
|
return SPEC_VERSION;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_TYPE(Application);
|
REGISTER_TYPE(Application);
|
||||||
|
|
||||||
boost::signals2::signal<void (void)> Application::OnReopenLogs;
|
boost::signals2::signal<void ()> Application::OnReopenLogs;
|
||||||
Application::Ptr Application::m_Instance = nullptr;
|
Application::Ptr Application::m_Instance = nullptr;
|
||||||
bool Application::m_ShuttingDown = false;
|
bool Application::m_ShuttingDown = false;
|
||||||
bool Application::m_RequestRestart = false;
|
bool Application::m_RequestRestart = false;
|
||||||
@ -71,7 +71,7 @@ double Application::m_LastReloadFailed;
|
|||||||
/**
|
/**
|
||||||
* Constructor for the Application class.
|
* Constructor for the Application class.
|
||||||
*/
|
*/
|
||||||
void Application::OnConfigLoaded(void)
|
void Application::OnConfigLoaded()
|
||||||
{
|
{
|
||||||
m_PidFile = nullptr;
|
m_PidFile = nullptr;
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ void Application::Stop(bool runtimeRemoved)
|
|||||||
ObjectImpl<Application>::Stop(runtimeRemoved);
|
ObjectImpl<Application>::Stop(runtimeRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application(void)
|
Application::~Application()
|
||||||
{
|
{
|
||||||
m_Instance = nullptr;
|
m_Instance = nullptr;
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ void Application::Exit(int rc)
|
|||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::InitializeBase(void)
|
void Application::InitializeBase()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* disable GUI-based error messages for LoadLibrary() */
|
/* disable GUI-based error messages for LoadLibrary() */
|
||||||
@ -160,7 +160,7 @@ void Application::InitializeBase(void)
|
|||||||
GetTP().Start();
|
GetTP().Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::UninitializeBase(void)
|
void Application::UninitializeBase()
|
||||||
{
|
{
|
||||||
Timer::Uninitialize();
|
Timer::Uninitialize();
|
||||||
|
|
||||||
@ -172,12 +172,12 @@ void Application::UninitializeBase(void)
|
|||||||
*
|
*
|
||||||
* @returns The application object.
|
* @returns The application object.
|
||||||
*/
|
*/
|
||||||
Application::Ptr Application::GetInstance(void)
|
Application::Ptr Application::GetInstance()
|
||||||
{
|
{
|
||||||
return m_Instance;
|
return m_Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::SetResourceLimits(void)
|
void Application::SetResourceLimits()
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
rlimit rl;
|
rlimit rl;
|
||||||
@ -289,7 +289,7 @@ void Application::SetResourceLimits(void)
|
|||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::GetArgC(void)
|
int Application::GetArgC()
|
||||||
{
|
{
|
||||||
return m_ArgC;
|
return m_ArgC;
|
||||||
}
|
}
|
||||||
@ -299,7 +299,7 @@ void Application::SetArgC(int argc)
|
|||||||
m_ArgC = argc;
|
m_ArgC = argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
char **Application::GetArgV(void)
|
char **Application::GetArgV()
|
||||||
{
|
{
|
||||||
return m_ArgV;
|
return m_ArgV;
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ void Application::SetArgV(char **argv)
|
|||||||
* Processes events for registered sockets and timers and calls whatever
|
* Processes events for registered sockets and timers and calls whatever
|
||||||
* handlers have been set up for these events.
|
* handlers have been set up for these events.
|
||||||
*/
|
*/
|
||||||
void Application::RunEventLoop(void)
|
void Application::RunEventLoop()
|
||||||
{
|
{
|
||||||
double lastLoop = Utility::GetTime();
|
double lastLoop = Utility::GetTime();
|
||||||
|
|
||||||
@ -365,12 +365,12 @@ mainloop:
|
|||||||
UninitializeBase();
|
UninitializeBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::IsShuttingDown(void)
|
bool Application::IsShuttingDown()
|
||||||
{
|
{
|
||||||
return m_ShuttingDown;
|
return m_ShuttingDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::OnShutdown(void)
|
void Application::OnShutdown()
|
||||||
{
|
{
|
||||||
/* Nothing to do here. */
|
/* Nothing to do here. */
|
||||||
}
|
}
|
||||||
@ -395,7 +395,7 @@ static void ReloadProcessCallback(const ProcessResult& pr)
|
|||||||
t.detach();
|
t.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t Application::StartReloadProcess(void)
|
pid_t Application::StartReloadProcess()
|
||||||
{
|
{
|
||||||
Log(LogInformation, "Application", "Got reload command: Starting new instance.");
|
Log(LogInformation, "Application", "Got reload command: Starting new instance.");
|
||||||
|
|
||||||
@ -428,7 +428,7 @@ pid_t Application::StartReloadProcess(void)
|
|||||||
* Signals the application to shut down during the next
|
* Signals the application to shut down during the next
|
||||||
* execution of the event loop.
|
* execution of the event loop.
|
||||||
*/
|
*/
|
||||||
void Application::RequestShutdown(void)
|
void Application::RequestShutdown()
|
||||||
{
|
{
|
||||||
Log(LogInformation, "Application", "Received request to shut down.");
|
Log(LogInformation, "Application", "Received request to shut down.");
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ void Application::RequestShutdown(void)
|
|||||||
* Signals the application to restart during the next
|
* Signals the application to restart during the next
|
||||||
* execution of the event loop.
|
* execution of the event loop.
|
||||||
*/
|
*/
|
||||||
void Application::RequestRestart(void)
|
void Application::RequestRestart()
|
||||||
{
|
{
|
||||||
m_RequestRestart = true;
|
m_RequestRestart = true;
|
||||||
}
|
}
|
||||||
@ -448,7 +448,7 @@ void Application::RequestRestart(void)
|
|||||||
* Signals the application to reopen log files during the
|
* Signals the application to reopen log files during the
|
||||||
* next execution of the event loop.
|
* next execution of the event loop.
|
||||||
*/
|
*/
|
||||||
void Application::RequestReopenLogs(void)
|
void Application::RequestReopenLogs()
|
||||||
{
|
{
|
||||||
m_RequestReopenLogs = true;
|
m_RequestReopenLogs = true;
|
||||||
}
|
}
|
||||||
@ -577,7 +577,7 @@ void Application::DisplayBugMessage(std::ostream& os)
|
|||||||
<< "***" << "\n";
|
<< "***" << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
String Application::GetCrashReportFilename(void)
|
String Application::GetCrashReportFilename()
|
||||||
{
|
{
|
||||||
return GetLocalStateDir() + "/log/icinga2/crash/report." + Convert::ToString(Utility::GetTime());
|
return GetLocalStateDir() + "/log/icinga2/crash/report." + Convert::ToString(Utility::GetTime());
|
||||||
}
|
}
|
||||||
@ -787,7 +787,7 @@ BOOL WINAPI Application::CtrlHandler(DWORD type)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::IsProcessElevated(void) {
|
bool Application::IsProcessElevated() {
|
||||||
BOOL fIsElevated = FALSE;
|
BOOL fIsElevated = FALSE;
|
||||||
DWORD dwError = ERROR_SUCCESS;
|
DWORD dwError = ERROR_SUCCESS;
|
||||||
HANDLE hToken = nullptr;
|
HANDLE hToken = nullptr;
|
||||||
@ -825,7 +825,7 @@ bool Application::IsProcessElevated(void) {
|
|||||||
/**
|
/**
|
||||||
* Handler for unhandled exceptions.
|
* Handler for unhandled exceptions.
|
||||||
*/
|
*/
|
||||||
void Application::ExceptionHandler(void)
|
void Application::ExceptionHandler()
|
||||||
{
|
{
|
||||||
if (l_InExceptionHandler)
|
if (l_InExceptionHandler)
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -934,7 +934,7 @@ LONG CALLBACK Application::SEHUnhandledExceptionFilter(PEXCEPTION_POINTERS exi)
|
|||||||
/**
|
/**
|
||||||
* Installs the exception handlers.
|
* Installs the exception handlers.
|
||||||
*/
|
*/
|
||||||
void Application::InstallExceptionHandlers(void)
|
void Application::InstallExceptionHandlers()
|
||||||
{
|
{
|
||||||
std::set_terminate(&Application::ExceptionHandler);
|
std::set_terminate(&Application::ExceptionHandler);
|
||||||
|
|
||||||
@ -953,7 +953,7 @@ void Application::InstallExceptionHandlers(void)
|
|||||||
*
|
*
|
||||||
* @returns The application's exit code.
|
* @returns The application's exit code.
|
||||||
*/
|
*/
|
||||||
int Application::Run(void)
|
int Application::Run()
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
@ -1123,7 +1123,7 @@ pid_t Application::ReadPidFile(const String& filename)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetPrefixDir(void)
|
String Application::GetPrefixDir()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("PrefixDir");
|
return ScriptGlobal::Get("PrefixDir");
|
||||||
}
|
}
|
||||||
@ -1144,7 +1144,7 @@ void Application::DeclarePrefixDir(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetSysconfDir(void)
|
String Application::GetSysconfDir()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("SysconfDir");
|
return ScriptGlobal::Get("SysconfDir");
|
||||||
}
|
}
|
||||||
@ -1165,7 +1165,7 @@ void Application::DeclareSysconfDir(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetRunDir(void)
|
String Application::GetRunDir()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("RunDir");
|
return ScriptGlobal::Get("RunDir");
|
||||||
}
|
}
|
||||||
@ -1186,7 +1186,7 @@ void Application::DeclareRunDir(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetLocalStateDir(void)
|
String Application::GetLocalStateDir()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("LocalStateDir");
|
return ScriptGlobal::Get("LocalStateDir");
|
||||||
}
|
}
|
||||||
@ -1207,7 +1207,7 @@ void Application::DeclareLocalStateDir(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetZonesDir(void)
|
String Application::GetZonesDir()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("ZonesDir", &Empty);
|
return ScriptGlobal::Get("ZonesDir", &Empty);
|
||||||
}
|
}
|
||||||
@ -1228,7 +1228,7 @@ void Application::DeclareZonesDir(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetPkgDataDir(void)
|
String Application::GetPkgDataDir()
|
||||||
{
|
{
|
||||||
String defaultValue = "";
|
String defaultValue = "";
|
||||||
return ScriptGlobal::Get("PkgDataDir", &Empty);
|
return ScriptGlobal::Get("PkgDataDir", &Empty);
|
||||||
@ -1250,7 +1250,7 @@ void Application::DeclarePkgDataDir(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetIncludeConfDir(void)
|
String Application::GetIncludeConfDir()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("IncludeConfDir", &Empty);
|
return ScriptGlobal::Get("IncludeConfDir", &Empty);
|
||||||
}
|
}
|
||||||
@ -1271,7 +1271,7 @@ void Application::DeclareIncludeConfDir(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetStatePath(void)
|
String Application::GetStatePath()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("StatePath", &Empty);
|
return ScriptGlobal::Get("StatePath", &Empty);
|
||||||
}
|
}
|
||||||
@ -1292,7 +1292,7 @@ void Application::DeclareStatePath(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetModAttrPath(void)
|
String Application::GetModAttrPath()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("ModAttrPath", &Empty);
|
return ScriptGlobal::Get("ModAttrPath", &Empty);
|
||||||
}
|
}
|
||||||
@ -1313,7 +1313,7 @@ void Application::DeclareModAttrPath(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetObjectsPath(void)
|
String Application::GetObjectsPath()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("ObjectsPath", &Empty);
|
return ScriptGlobal::Get("ObjectsPath", &Empty);
|
||||||
}
|
}
|
||||||
@ -1334,7 +1334,7 @@ void Application::DeclareObjectsPath(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetVarsPath(void)
|
String Application::GetVarsPath()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("VarsPath", &Empty);
|
return ScriptGlobal::Get("VarsPath", &Empty);
|
||||||
}
|
}
|
||||||
@ -1355,7 +1355,7 @@ void Application::DeclareVarsPath(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String Application::GetPidPath(void)
|
String Application::GetPidPath()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("PidPath", &Empty);
|
return ScriptGlobal::Get("PidPath", &Empty);
|
||||||
}
|
}
|
||||||
@ -1376,7 +1376,7 @@ void Application::DeclarePidPath(const String& path)
|
|||||||
*
|
*
|
||||||
* @returns The name.
|
* @returns The name.
|
||||||
*/
|
*/
|
||||||
String Application::GetRunAsUser(void)
|
String Application::GetRunAsUser()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("RunAsUser");
|
return ScriptGlobal::Get("RunAsUser");
|
||||||
}
|
}
|
||||||
@ -1397,7 +1397,7 @@ void Application::DeclareRunAsUser(const String& user)
|
|||||||
*
|
*
|
||||||
* @returns The name.
|
* @returns The name.
|
||||||
*/
|
*/
|
||||||
String Application::GetRunAsGroup(void)
|
String Application::GetRunAsGroup()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("RunAsGroup");
|
return ScriptGlobal::Get("RunAsGroup");
|
||||||
}
|
}
|
||||||
@ -1418,12 +1418,12 @@ void Application::DeclareRunAsGroup(const String& group)
|
|||||||
*
|
*
|
||||||
* @returns The limit.
|
* @returns The limit.
|
||||||
*/
|
*/
|
||||||
int Application::GetRLimitFiles(void)
|
int Application::GetRLimitFiles()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("RLimitFiles");
|
return ScriptGlobal::Get("RLimitFiles");
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::GetDefaultRLimitFiles(void)
|
int Application::GetDefaultRLimitFiles()
|
||||||
{
|
{
|
||||||
return 16 * 1024;
|
return 16 * 1024;
|
||||||
}
|
}
|
||||||
@ -1444,12 +1444,12 @@ void Application::DeclareRLimitFiles(int limit)
|
|||||||
*
|
*
|
||||||
* @returns The limit.
|
* @returns The limit.
|
||||||
*/
|
*/
|
||||||
int Application::GetRLimitProcesses(void)
|
int Application::GetRLimitProcesses()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("RLimitProcesses");
|
return ScriptGlobal::Get("RLimitProcesses");
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::GetDefaultRLimitProcesses(void)
|
int Application::GetDefaultRLimitProcesses()
|
||||||
{
|
{
|
||||||
return 16 * 1024;
|
return 16 * 1024;
|
||||||
}
|
}
|
||||||
@ -1470,12 +1470,12 @@ void Application::DeclareRLimitProcesses(int limit)
|
|||||||
*
|
*
|
||||||
* @returns The limit.
|
* @returns The limit.
|
||||||
*/
|
*/
|
||||||
int Application::GetRLimitStack(void)
|
int Application::GetRLimitStack()
|
||||||
{
|
{
|
||||||
return ScriptGlobal::Get("RLimitStack");
|
return ScriptGlobal::Get("RLimitStack");
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::GetDefaultRLimitStack(void)
|
int Application::GetDefaultRLimitStack()
|
||||||
{
|
{
|
||||||
return 256 * 1024;
|
return 256 * 1024;
|
||||||
}
|
}
|
||||||
@ -1507,7 +1507,7 @@ void Application::DeclareConcurrency(int ncpus)
|
|||||||
*
|
*
|
||||||
* @returns The concurrency level.
|
* @returns The concurrency level.
|
||||||
*/
|
*/
|
||||||
int Application::GetConcurrency(void)
|
int Application::GetConcurrency()
|
||||||
{
|
{
|
||||||
Value defaultConcurrency = std::thread::hardware_concurrency();
|
Value defaultConcurrency = std::thread::hardware_concurrency();
|
||||||
return ScriptGlobal::Get("Concurrency", &defaultConcurrency);
|
return ScriptGlobal::Get("Concurrency", &defaultConcurrency);
|
||||||
@ -1518,13 +1518,13 @@ int Application::GetConcurrency(void)
|
|||||||
*
|
*
|
||||||
* @returns The global thread pool.
|
* @returns The global thread pool.
|
||||||
*/
|
*/
|
||||||
ThreadPool& Application::GetTP(void)
|
ThreadPool& Application::GetTP()
|
||||||
{
|
{
|
||||||
static ThreadPool tp;
|
static ThreadPool tp;
|
||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Application::GetStartTime(void)
|
double Application::GetStartTime()
|
||||||
{
|
{
|
||||||
return m_StartTime;
|
return m_StartTime;
|
||||||
}
|
}
|
||||||
@ -1534,7 +1534,7 @@ void Application::SetStartTime(double ts)
|
|||||||
m_StartTime = ts;
|
m_StartTime = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Application::GetMainTime(void)
|
double Application::GetMainTime()
|
||||||
{
|
{
|
||||||
return m_MainTime;
|
return m_MainTime;
|
||||||
}
|
}
|
||||||
@ -1544,7 +1544,7 @@ void Application::SetMainTime(double ts)
|
|||||||
m_MainTime = ts;
|
m_MainTime = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::GetScriptDebuggerEnabled(void)
|
bool Application::GetScriptDebuggerEnabled()
|
||||||
{
|
{
|
||||||
return m_ScriptDebuggerEnabled;
|
return m_ScriptDebuggerEnabled;
|
||||||
}
|
}
|
||||||
@ -1554,7 +1554,7 @@ void Application::SetScriptDebuggerEnabled(bool enabled)
|
|||||||
m_ScriptDebuggerEnabled = enabled;
|
m_ScriptDebuggerEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Application::GetLastReloadFailed(void)
|
double Application::GetLastReloadFailed()
|
||||||
{
|
{
|
||||||
return m_LastReloadFailed;
|
return m_LastReloadFailed;
|
||||||
}
|
}
|
||||||
|
@ -39,44 +39,44 @@ class Application : public ObjectImpl<Application> {
|
|||||||
public:
|
public:
|
||||||
DECLARE_OBJECT(Application);
|
DECLARE_OBJECT(Application);
|
||||||
|
|
||||||
static boost::signals2::signal<void (void)> OnReopenLogs;
|
static boost::signals2::signal<void ()> OnReopenLogs;
|
||||||
|
|
||||||
~Application(void);
|
~Application() override;
|
||||||
|
|
||||||
static void InitializeBase(void);
|
static void InitializeBase();
|
||||||
static void UninitializeBase(void);
|
static void UninitializeBase();
|
||||||
|
|
||||||
static Application::Ptr GetInstance(void);
|
static Application::Ptr GetInstance();
|
||||||
|
|
||||||
static void Exit(int rc);
|
static void Exit(int rc);
|
||||||
|
|
||||||
int Run(void);
|
int Run();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the application.
|
* Starts the application.
|
||||||
*
|
*
|
||||||
* @returns The exit code of the application.
|
* @returns The exit code of the application.
|
||||||
*/
|
*/
|
||||||
virtual int Main(void) = 0;
|
virtual int Main() = 0;
|
||||||
|
|
||||||
static void SetResourceLimits(void);
|
static void SetResourceLimits();
|
||||||
|
|
||||||
static int GetArgC(void);
|
static int GetArgC();
|
||||||
static void SetArgC(int argc);
|
static void SetArgC(int argc);
|
||||||
|
|
||||||
static char **GetArgV(void);
|
static char **GetArgV();
|
||||||
static void SetArgV(char **argv);
|
static void SetArgV(char **argv);
|
||||||
|
|
||||||
static void InstallExceptionHandlers(void);
|
static void InstallExceptionHandlers();
|
||||||
|
|
||||||
static void RequestShutdown(void);
|
static void RequestShutdown();
|
||||||
static void RequestRestart(void);
|
static void RequestRestart();
|
||||||
static void RequestReopenLogs(void);
|
static void RequestReopenLogs();
|
||||||
|
|
||||||
static bool IsShuttingDown(void);
|
static bool IsShuttingDown();
|
||||||
|
|
||||||
static void SetDebuggingSeverity(LogSeverity severity);
|
static void SetDebuggingSeverity(LogSeverity severity);
|
||||||
static LogSeverity GetDebuggingSeverity(void);
|
static LogSeverity GetDebuggingSeverity();
|
||||||
|
|
||||||
void UpdatePidFile(const String& filename, pid_t pid = Utility::GetPid());
|
void UpdatePidFile(const String& filename, pid_t pid = Utility::GetPid());
|
||||||
void ClosePidFile(bool unlink);
|
void ClosePidFile(bool unlink);
|
||||||
@ -84,97 +84,97 @@ public:
|
|||||||
|
|
||||||
static String GetExePath(const String& argv0);
|
static String GetExePath(const String& argv0);
|
||||||
|
|
||||||
static String GetPrefixDir(void);
|
static String GetPrefixDir();
|
||||||
static void DeclarePrefixDir(const String& path);
|
static void DeclarePrefixDir(const String& path);
|
||||||
|
|
||||||
static String GetSysconfDir(void);
|
static String GetSysconfDir();
|
||||||
static void DeclareSysconfDir(const String& path);
|
static void DeclareSysconfDir(const String& path);
|
||||||
|
|
||||||
static String GetZonesDir(void);
|
static String GetZonesDir();
|
||||||
static void DeclareZonesDir(const String& path);
|
static void DeclareZonesDir(const String& path);
|
||||||
|
|
||||||
static String GetRunDir(void);
|
static String GetRunDir();
|
||||||
static void DeclareRunDir(const String& path);
|
static void DeclareRunDir(const String& path);
|
||||||
|
|
||||||
static String GetLocalStateDir(void);
|
static String GetLocalStateDir();
|
||||||
static void DeclareLocalStateDir(const String& path);
|
static void DeclareLocalStateDir(const String& path);
|
||||||
|
|
||||||
static String GetPkgDataDir(void);
|
static String GetPkgDataDir();
|
||||||
static void DeclarePkgDataDir(const String& path);
|
static void DeclarePkgDataDir(const String& path);
|
||||||
|
|
||||||
static String GetIncludeConfDir(void);
|
static String GetIncludeConfDir();
|
||||||
static void DeclareIncludeConfDir(const String& path);
|
static void DeclareIncludeConfDir(const String& path);
|
||||||
|
|
||||||
static String GetStatePath(void);
|
static String GetStatePath();
|
||||||
static void DeclareStatePath(const String& path);
|
static void DeclareStatePath(const String& path);
|
||||||
|
|
||||||
static String GetModAttrPath(void);
|
static String GetModAttrPath();
|
||||||
static void DeclareModAttrPath(const String& path);
|
static void DeclareModAttrPath(const String& path);
|
||||||
|
|
||||||
static String GetObjectsPath(void);
|
static String GetObjectsPath();
|
||||||
static void DeclareObjectsPath(const String& path);
|
static void DeclareObjectsPath(const String& path);
|
||||||
|
|
||||||
static String GetVarsPath(void);
|
static String GetVarsPath();
|
||||||
static void DeclareVarsPath(const String& path);
|
static void DeclareVarsPath(const String& path);
|
||||||
|
|
||||||
static String GetPidPath(void);
|
static String GetPidPath();
|
||||||
static void DeclarePidPath(const String& path);
|
static void DeclarePidPath(const String& path);
|
||||||
|
|
||||||
static String GetRunAsUser(void);
|
static String GetRunAsUser();
|
||||||
static void DeclareRunAsUser(const String& user);
|
static void DeclareRunAsUser(const String& user);
|
||||||
|
|
||||||
static String GetRunAsGroup(void);
|
static String GetRunAsGroup();
|
||||||
static void DeclareRunAsGroup(const String& group);
|
static void DeclareRunAsGroup(const String& group);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static bool IsProcessElevated(void);
|
static bool IsProcessElevated();
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
static int GetRLimitFiles(void);
|
static int GetRLimitFiles();
|
||||||
static int GetDefaultRLimitFiles(void);
|
static int GetDefaultRLimitFiles();
|
||||||
static void DeclareRLimitFiles(int limit);
|
static void DeclareRLimitFiles(int limit);
|
||||||
|
|
||||||
static int GetRLimitProcesses(void);
|
static int GetRLimitProcesses();
|
||||||
static int GetDefaultRLimitProcesses(void);
|
static int GetDefaultRLimitProcesses();
|
||||||
static void DeclareRLimitProcesses(int limit);
|
static void DeclareRLimitProcesses(int limit);
|
||||||
|
|
||||||
static int GetRLimitStack(void);
|
static int GetRLimitStack();
|
||||||
static int GetDefaultRLimitStack(void);
|
static int GetDefaultRLimitStack();
|
||||||
static void DeclareRLimitStack(int limit);
|
static void DeclareRLimitStack(int limit);
|
||||||
|
|
||||||
static int GetConcurrency(void);
|
static int GetConcurrency();
|
||||||
static void DeclareConcurrency(int ncpus);
|
static void DeclareConcurrency(int ncpus);
|
||||||
|
|
||||||
static ThreadPool& GetTP(void);
|
static ThreadPool& GetTP();
|
||||||
|
|
||||||
static String GetAppVersion(void);
|
static String GetAppVersion();
|
||||||
static String GetAppSpecVersion(void);
|
static String GetAppSpecVersion();
|
||||||
|
|
||||||
static double GetStartTime(void);
|
static double GetStartTime();
|
||||||
static void SetStartTime(double ts);
|
static void SetStartTime(double ts);
|
||||||
|
|
||||||
static double GetMainTime(void);
|
static double GetMainTime();
|
||||||
static void SetMainTime(double ts);
|
static void SetMainTime(double ts);
|
||||||
|
|
||||||
static bool GetScriptDebuggerEnabled(void);
|
static bool GetScriptDebuggerEnabled();
|
||||||
static void SetScriptDebuggerEnabled(bool enabled);
|
static void SetScriptDebuggerEnabled(bool enabled);
|
||||||
|
|
||||||
static double GetLastReloadFailed(void);
|
static double GetLastReloadFailed();
|
||||||
static void SetLastReloadFailed(double ts);
|
static void SetLastReloadFailed(double ts);
|
||||||
|
|
||||||
static void DisplayInfoMessage(std::ostream& os, bool skipVersion = false);
|
static void DisplayInfoMessage(std::ostream& os, bool skipVersion = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnConfigLoaded(void) override;
|
void OnConfigLoaded() override;
|
||||||
virtual void Stop(bool runtimeRemoved) override;
|
void Stop(bool runtimeRemoved) override;
|
||||||
|
|
||||||
void RunEventLoop(void);
|
void RunEventLoop();
|
||||||
|
|
||||||
pid_t StartReloadProcess(void);
|
pid_t StartReloadProcess();
|
||||||
|
|
||||||
virtual void OnShutdown(void);
|
virtual void OnShutdown();
|
||||||
|
|
||||||
virtual void ValidateName(const String& value, const ValidationUtils& utils) override final;
|
void ValidateName(const String& value, const ValidationUtils& utils) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Application::Ptr m_Instance; /**< The application instance. */
|
static Application::Ptr m_Instance; /**< The application instance. */
|
||||||
@ -205,9 +205,9 @@ private:
|
|||||||
|
|
||||||
static void SigAbrtHandler(int signum);
|
static void SigAbrtHandler(int signum);
|
||||||
static void SigUsr1Handler(int signum);
|
static void SigUsr1Handler(int signum);
|
||||||
static void ExceptionHandler(void);
|
static void ExceptionHandler();
|
||||||
|
|
||||||
static String GetCrashReportFilename(void);
|
static String GetCrashReportFilename();
|
||||||
|
|
||||||
static void AttachDebugger(const String& filename, bool interactive);
|
static void AttachDebugger(const String& filename, bool interactive);
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static double ArrayLen(void)
|
static double ArrayLen()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
||||||
@ -68,7 +68,7 @@ static bool ArrayContains(const Value& value)
|
|||||||
return self->Contains(value);
|
return self->Contains(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ArrayClear(void)
|
static void ArrayClear()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
||||||
@ -103,7 +103,7 @@ static Array::Ptr ArraySort(const std::vector<Value>& args)
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Array::Ptr ArrayShallowClone(void)
|
static Array::Ptr ArrayShallowClone()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
||||||
@ -132,7 +132,7 @@ static Value ArrayJoin(const Value& separator)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Array::Ptr ArrayReverse(void)
|
static Array::Ptr ArrayReverse()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
||||||
@ -230,7 +230,7 @@ static bool ArrayAll(const Function::Ptr& function)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static Array::Ptr ArrayUnique(void)
|
static Array::Ptr ArrayUnique()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
|
||||||
@ -245,7 +245,7 @@ static Array::Ptr ArrayUnique(void)
|
|||||||
return Array::FromSet(result);
|
return Array::FromSet(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr Array::GetPrototype(void)
|
Object::Ptr Array::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -32,16 +32,10 @@ template class std::vector<Value>;
|
|||||||
|
|
||||||
REGISTER_PRIMITIVE_TYPE(Array, Object, Array::GetPrototype());
|
REGISTER_PRIMITIVE_TYPE(Array, Object, Array::GetPrototype());
|
||||||
|
|
||||||
Array::Array(void)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Array::Array(std::initializer_list<Value> init)
|
Array::Array(std::initializer_list<Value> init)
|
||||||
: m_Data(init)
|
: m_Data(init)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Array::~Array(void)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restrieves a value from an array.
|
* Restrieves a value from an array.
|
||||||
*
|
*
|
||||||
@ -86,23 +80,11 @@ void Array::Set(SizeType index, Value&& value)
|
|||||||
*
|
*
|
||||||
* @param value The value.
|
* @param value The value.
|
||||||
*/
|
*/
|
||||||
void Array::Add(const Value& value)
|
void Array::Add(Value value)
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
m_Data.push_back(value);
|
m_Data.push_back(std::move(value));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a value to the array.
|
|
||||||
*
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
void Array::Add(Value&& value)
|
|
||||||
{
|
|
||||||
ObjectLock olock(this);
|
|
||||||
|
|
||||||
m_Data.emplace_back(std::move(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +94,7 @@ void Array::Add(Value&& value)
|
|||||||
*
|
*
|
||||||
* @returns An iterator.
|
* @returns An iterator.
|
||||||
*/
|
*/
|
||||||
Array::Iterator Array::Begin(void)
|
Array::Iterator Array::Begin()
|
||||||
{
|
{
|
||||||
ASSERT(OwnsLock());
|
ASSERT(OwnsLock());
|
||||||
|
|
||||||
@ -126,7 +108,7 @@ Array::Iterator Array::Begin(void)
|
|||||||
*
|
*
|
||||||
* @returns An iterator.
|
* @returns An iterator.
|
||||||
*/
|
*/
|
||||||
Array::Iterator Array::End(void)
|
Array::Iterator Array::End()
|
||||||
{
|
{
|
||||||
ASSERT(OwnsLock());
|
ASSERT(OwnsLock());
|
||||||
|
|
||||||
@ -138,7 +120,7 @@ Array::Iterator Array::End(void)
|
|||||||
*
|
*
|
||||||
* @returns Number of elements.
|
* @returns Number of elements.
|
||||||
*/
|
*/
|
||||||
size_t Array::GetLength(void) const
|
size_t Array::GetLength() const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -164,13 +146,13 @@ bool Array::Contains(const Value& value) const
|
|||||||
* @param index The index
|
* @param index The index
|
||||||
* @param value The value to add
|
* @param value The value to add
|
||||||
*/
|
*/
|
||||||
void Array::Insert(SizeType index, const Value& value)
|
void Array::Insert(SizeType index, Value value)
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
ASSERT(index <= m_Data.size());
|
ASSERT(index <= m_Data.size());
|
||||||
|
|
||||||
m_Data.insert(m_Data.begin() + index, value);
|
m_Data.insert(m_Data.begin() + index, std::move(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,7 +186,7 @@ void Array::Resize(SizeType newSize)
|
|||||||
m_Data.resize(newSize);
|
m_Data.resize(newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::Clear(void)
|
void Array::Clear()
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -231,7 +213,7 @@ void Array::CopyTo(const Array::Ptr& dest) const
|
|||||||
*
|
*
|
||||||
* @returns a copy of the array.
|
* @returns a copy of the array.
|
||||||
*/
|
*/
|
||||||
Array::Ptr Array::ShallowClone(void) const
|
Array::Ptr Array::ShallowClone() const
|
||||||
{
|
{
|
||||||
Array::Ptr clone = new Array();
|
Array::Ptr clone = new Array();
|
||||||
CopyTo(clone);
|
CopyTo(clone);
|
||||||
@ -244,7 +226,7 @@ Array::Ptr Array::ShallowClone(void) const
|
|||||||
*
|
*
|
||||||
* @returns a copy of the array.
|
* @returns a copy of the array.
|
||||||
*/
|
*/
|
||||||
Object::Ptr Array::Clone(void) const
|
Object::Ptr Array::Clone() const
|
||||||
{
|
{
|
||||||
Array::Ptr arr = new Array();
|
Array::Ptr arr = new Array();
|
||||||
|
|
||||||
@ -256,7 +238,7 @@ Object::Ptr Array::Clone(void) const
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Ptr Array::Reverse(void) const
|
Array::Ptr Array::Reverse() const
|
||||||
{
|
{
|
||||||
Array::Ptr result = new Array();
|
Array::Ptr result = new Array();
|
||||||
|
|
||||||
@ -268,13 +250,13 @@ Array::Ptr Array::Reverse(void) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::Sort(void)
|
void Array::Sort()
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
std::sort(m_Data.begin(), m_Data.end());
|
std::sort(m_Data.begin(), m_Data.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
String Array::ToString(void) const
|
String Array::ToString() const
|
||||||
{
|
{
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
ConfigWriter::EmitArray(msgbuf, 1, const_cast<Array *>(this));
|
ConfigWriter::EmitArray(msgbuf, 1, const_cast<Array *>(this));
|
||||||
@ -314,12 +296,12 @@ void Array::SetFieldByName(const String& field, const Value& value, const DebugI
|
|||||||
Set(index, value);
|
Set(index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Iterator icinga::begin(Array::Ptr x)
|
Array::Iterator icinga::begin(const Array::Ptr& x)
|
||||||
{
|
{
|
||||||
return x->Begin();
|
return x->Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Iterator icinga::end(Array::Ptr x)
|
Array::Iterator icinga::end(const Array::Ptr& x)
|
||||||
{
|
{
|
||||||
return x->End();
|
return x->End();
|
||||||
}
|
}
|
||||||
|
@ -47,36 +47,33 @@ public:
|
|||||||
|
|
||||||
typedef std::vector<Value>::size_type SizeType;
|
typedef std::vector<Value>::size_type SizeType;
|
||||||
|
|
||||||
Array(void);
|
Array() = default;
|
||||||
Array(std::initializer_list<Value> init);
|
Array(std::initializer_list<Value> init);
|
||||||
|
|
||||||
~Array(void);
|
|
||||||
|
|
||||||
Value Get(SizeType index) const;
|
Value Get(SizeType index) const;
|
||||||
void Set(SizeType index, const Value& value);
|
void Set(SizeType index, const Value& value);
|
||||||
void Set(SizeType index, Value&& value);
|
void Set(SizeType index, Value&& value);
|
||||||
void Add(const Value& value);
|
void Add(Value value);
|
||||||
void Add(Value&& value);
|
|
||||||
|
|
||||||
Iterator Begin(void);
|
Iterator Begin();
|
||||||
Iterator End(void);
|
Iterator End();
|
||||||
|
|
||||||
size_t GetLength(void) const;
|
size_t GetLength() const;
|
||||||
bool Contains(const Value& value) const;
|
bool Contains(const Value& value) const;
|
||||||
|
|
||||||
void Insert(SizeType index, const Value& value);
|
void Insert(SizeType index, Value value);
|
||||||
void Remove(SizeType index);
|
void Remove(SizeType index);
|
||||||
void Remove(Iterator it);
|
void Remove(Iterator it);
|
||||||
|
|
||||||
void Resize(SizeType newSize);
|
void Resize(SizeType newSize);
|
||||||
void Clear(void);
|
void Clear();
|
||||||
|
|
||||||
void Reserve(SizeType newSize);
|
void Reserve(SizeType newSize);
|
||||||
|
|
||||||
void CopyTo(const Array::Ptr& dest) const;
|
void CopyTo(const Array::Ptr& dest) const;
|
||||||
Array::Ptr ShallowClone(void) const;
|
Array::Ptr ShallowClone() const;
|
||||||
|
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static Array::Ptr FromVector(const std::vector<T>& v)
|
static Array::Ptr FromVector(const std::vector<T>& v)
|
||||||
@ -88,7 +85,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::set<T> ToSet(void)
|
std::set<T> ToSet()
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
return std::set<T>(Begin(), End());
|
return std::set<T>(Begin(), End());
|
||||||
@ -103,23 +100,23 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Object::Ptr Clone(void) const override;
|
Object::Ptr Clone() const override;
|
||||||
|
|
||||||
Array::Ptr Reverse(void) const;
|
Array::Ptr Reverse() const;
|
||||||
|
|
||||||
void Sort(void);
|
void Sort();
|
||||||
|
|
||||||
virtual String ToString(void) const override;
|
String ToString() const override;
|
||||||
|
|
||||||
virtual Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
|
Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
|
||||||
virtual void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
|
void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Value> m_Data; /**< The data for the array. */
|
std::vector<Value> m_Data; /**< The data for the array. */
|
||||||
};
|
};
|
||||||
|
|
||||||
Array::Iterator begin(Array::Ptr x);
|
Array::Iterator begin(const Array::Ptr& x);
|
||||||
Array::Iterator end(Array::Ptr x);
|
Array::Iterator end(const Array::Ptr& x);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ String Base64::Decode(const String& input)
|
|||||||
BIO_push(bio64, biomem);
|
BIO_push(bio64, biomem);
|
||||||
BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
|
BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
|
||||||
|
|
||||||
char *outbuf = new char[input.GetLength()];
|
auto *outbuf = new char[input.GetLength()];
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -25,14 +25,14 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static String BooleanToString(void)
|
static String BooleanToString()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
bool self = vframe->Self;
|
bool self = vframe->Self;
|
||||||
return self ? "true" : "false";
|
return self ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr Boolean::GetPrototype(void)
|
Object::Ptr Boolean::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@ class Value;
|
|||||||
class Boolean
|
class Boolean
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Boolean(void);
|
Boolean();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ static void ConfigObjectRestoreAttribute(const String& attr)
|
|||||||
return self->RestoreAttribute(attr);
|
return self->RestoreAttribute(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr ConfigObject::GetPrototype(void)
|
Object::Ptr ConfigObject::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -46,15 +46,12 @@ REGISTER_TYPE_WITH_PROTOTYPE(ConfigObject, ConfigObject::GetPrototype());
|
|||||||
|
|
||||||
boost::signals2::signal<void (const ConfigObject::Ptr&)> ConfigObject::OnStateChanged;
|
boost::signals2::signal<void (const ConfigObject::Ptr&)> ConfigObject::OnStateChanged;
|
||||||
|
|
||||||
ConfigObject::ConfigObject(void)
|
bool ConfigObject::IsActive() const
|
||||||
{ }
|
|
||||||
|
|
||||||
bool ConfigObject::IsActive(void) const
|
|
||||||
{
|
{
|
||||||
return GetActive();
|
return GetActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigObject::IsPaused(void) const
|
bool ConfigObject::IsPaused() const
|
||||||
{
|
{
|
||||||
return GetPaused();
|
return GetPaused();
|
||||||
}
|
}
|
||||||
@ -94,10 +91,10 @@ void ConfigObject::ClearExtension(const String& key)
|
|||||||
class ModAttrValidationUtils final : public ValidationUtils
|
class ModAttrValidationUtils final : public ValidationUtils
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool ValidateName(const String& type, const String& name) const override
|
bool ValidateName(const String& type, const String& name) const override
|
||||||
{
|
{
|
||||||
Type::Ptr ptype = Type::GetByName(type);
|
Type::Ptr ptype = Type::GetByName(type);
|
||||||
ConfigType *dtype = dynamic_cast<ConfigType *>(ptype.get());
|
auto *dtype = dynamic_cast<ConfigType *>(ptype.get());
|
||||||
|
|
||||||
if (!dtype)
|
if (!dtype)
|
||||||
return false;
|
return false;
|
||||||
@ -349,7 +346,7 @@ bool ConfigObject::IsAttributeModified(const String& attr) const
|
|||||||
return original_attributes->Contains(attr);
|
return original_attributes->Contains(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::Register(void)
|
void ConfigObject::Register()
|
||||||
{
|
{
|
||||||
ASSERT(!OwnsLock());
|
ASSERT(!OwnsLock());
|
||||||
|
|
||||||
@ -357,7 +354,7 @@ void ConfigObject::Register(void)
|
|||||||
type->RegisterObject(this);
|
type->RegisterObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::Unregister(void)
|
void ConfigObject::Unregister()
|
||||||
{
|
{
|
||||||
ASSERT(!OwnsLock());
|
ASSERT(!OwnsLock());
|
||||||
|
|
||||||
@ -374,7 +371,7 @@ void ConfigObject::Start(bool runtimeCreated)
|
|||||||
SetStartCalled(true);
|
SetStartCalled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::PreActivate(void)
|
void ConfigObject::PreActivate()
|
||||||
{
|
{
|
||||||
CONTEXT("Setting 'active' to true for object '" + GetName() + "' of type '" + GetReflectionType()->GetName() + "'");
|
CONTEXT("Setting 'active' to true for object '" + GetName() + "' of type '" + GetReflectionType()->GetName() + "'");
|
||||||
|
|
||||||
@ -431,12 +428,12 @@ void ConfigObject::Deactivate(bool runtimeRemoved)
|
|||||||
NotifyActive();
|
NotifyActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::OnConfigLoaded(void)
|
void ConfigObject::OnConfigLoaded()
|
||||||
{
|
{
|
||||||
/* Nothing to do here. */
|
/* Nothing to do here. */
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::OnAllConfigLoaded(void)
|
void ConfigObject::OnAllConfigLoaded()
|
||||||
{
|
{
|
||||||
static ConfigType *ctype;
|
static ConfigType *ctype;
|
||||||
|
|
||||||
@ -456,17 +453,17 @@ void ConfigObject::CreateChildObjects(const Type::Ptr& childType)
|
|||||||
/* Nothing to do here. */
|
/* Nothing to do here. */
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::OnStateLoaded(void)
|
void ConfigObject::OnStateLoaded()
|
||||||
{
|
{
|
||||||
/* Nothing to do here. */
|
/* Nothing to do here. */
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::Pause(void)
|
void ConfigObject::Pause()
|
||||||
{
|
{
|
||||||
SetPauseCalled(true);
|
SetPauseCalled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::Resume(void)
|
void ConfigObject::Resume()
|
||||||
{
|
{
|
||||||
SetResumeCalled(true);
|
SetResumeCalled(true);
|
||||||
}
|
}
|
||||||
@ -503,7 +500,7 @@ void ConfigObject::DumpObjects(const String& filename, int attributeTypes)
|
|||||||
StdioStream::Ptr sfp = new StdioStream(&fp, false);
|
StdioStream::Ptr sfp = new StdioStream(&fp, false);
|
||||||
|
|
||||||
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
||||||
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());
|
auto *dtype = dynamic_cast<ConfigType *>(type.get());
|
||||||
|
|
||||||
if (!dtype)
|
if (!dtype)
|
||||||
continue;
|
continue;
|
||||||
@ -605,7 +602,7 @@ void ConfigObject::RestoreObjects(const String& filename, int attributeTypes)
|
|||||||
unsigned long no_state = 0;
|
unsigned long no_state = 0;
|
||||||
|
|
||||||
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
||||||
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());
|
auto *dtype = dynamic_cast<ConfigType *>(type.get());
|
||||||
|
|
||||||
if (!dtype)
|
if (!dtype)
|
||||||
continue;
|
continue;
|
||||||
@ -624,10 +621,10 @@ void ConfigObject::RestoreObjects(const String& filename, int attributeTypes)
|
|||||||
<< "Restored " << restored << " objects. Loaded " << no_state << " new objects without state.";
|
<< "Restored " << restored << " objects. Loaded " << no_state << " new objects without state.";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::StopObjects(void)
|
void ConfigObject::StopObjects()
|
||||||
{
|
{
|
||||||
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
||||||
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());
|
auto *dtype = dynamic_cast<ConfigType *>(type.get());
|
||||||
|
|
||||||
if (!dtype)
|
if (!dtype)
|
||||||
continue;
|
continue;
|
||||||
@ -641,7 +638,7 @@ void ConfigObject::StopObjects(void)
|
|||||||
void ConfigObject::DumpModifiedAttributes(const std::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback)
|
void ConfigObject::DumpModifiedAttributes(const std::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback)
|
||||||
{
|
{
|
||||||
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
||||||
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());
|
auto *dtype = dynamic_cast<ConfigType *>(type.get());
|
||||||
|
|
||||||
if (!dtype)
|
if (!dtype)
|
||||||
continue;
|
continue;
|
||||||
@ -703,7 +700,7 @@ void ConfigObject::DumpModifiedAttributes(const std::function<void(const ConfigO
|
|||||||
ConfigObject::Ptr ConfigObject::GetObject(const String& type, const String& name)
|
ConfigObject::Ptr ConfigObject::GetObject(const String& type, const String& name)
|
||||||
{
|
{
|
||||||
Type::Ptr ptype = Type::GetByName(type);
|
Type::Ptr ptype = Type::GetByName(type);
|
||||||
ConfigType *ctype = dynamic_cast<ConfigType *>(ptype.get());
|
auto *ctype = dynamic_cast<ConfigType *>(ptype.get());
|
||||||
|
|
||||||
if (!ctype)
|
if (!ctype)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -711,12 +708,12 @@ ConfigObject::Ptr ConfigObject::GetObject(const String& type, const String& name
|
|||||||
return ctype->GetObject(name);
|
return ctype->GetObject(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigObject::Ptr ConfigObject::GetZone(void) const
|
ConfigObject::Ptr ConfigObject::GetZone() const
|
||||||
{
|
{
|
||||||
return m_Zone;
|
return m_Zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr ConfigObject::GetSourceLocation(void) const
|
Dictionary::Ptr ConfigObject::GetSourceLocation() const
|
||||||
{
|
{
|
||||||
DebugInfo di = GetDebugInfo();
|
DebugInfo di = GetDebugInfo();
|
||||||
|
|
||||||
@ -729,5 +726,5 @@ Dictionary::Ptr ConfigObject::GetSourceLocation(void) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NameComposer::~NameComposer(void)
|
NameComposer::~NameComposer()
|
||||||
{ }
|
{ }
|
||||||
|
@ -44,45 +44,45 @@ public:
|
|||||||
|
|
||||||
static boost::signals2::signal<void (const ConfigObject::Ptr&)> OnStateChanged;
|
static boost::signals2::signal<void (const ConfigObject::Ptr&)> OnStateChanged;
|
||||||
|
|
||||||
bool IsActive(void) const;
|
bool IsActive() const;
|
||||||
bool IsPaused(void) const;
|
bool IsPaused() const;
|
||||||
|
|
||||||
void SetExtension(const String& key, const Value& value);
|
void SetExtension(const String& key, const Value& value);
|
||||||
Value GetExtension(const String& key);
|
Value GetExtension(const String& key);
|
||||||
void ClearExtension(const String& key);
|
void ClearExtension(const String& key);
|
||||||
|
|
||||||
ConfigObject::Ptr GetZone(void) const;
|
ConfigObject::Ptr GetZone() const;
|
||||||
|
|
||||||
void ModifyAttribute(const String& attr, const Value& value, bool updateVersion = true);
|
void ModifyAttribute(const String& attr, const Value& value, bool updateVersion = true);
|
||||||
void RestoreAttribute(const String& attr, bool updateVersion = true);
|
void RestoreAttribute(const String& attr, bool updateVersion = true);
|
||||||
bool IsAttributeModified(const String& attr) const;
|
bool IsAttributeModified(const String& attr) const;
|
||||||
|
|
||||||
void Register(void);
|
void Register();
|
||||||
void Unregister(void);
|
void Unregister();
|
||||||
|
|
||||||
void PreActivate(void);
|
void PreActivate();
|
||||||
void Activate(bool runtimeCreated = false);
|
void Activate(bool runtimeCreated = false);
|
||||||
void Deactivate(bool runtimeRemoved = false);
|
void Deactivate(bool runtimeRemoved = false);
|
||||||
void SetAuthority(bool authority);
|
void SetAuthority(bool authority);
|
||||||
|
|
||||||
virtual void Start(bool runtimeCreated = false) override;
|
void Start(bool runtimeCreated = false) override;
|
||||||
virtual void Stop(bool runtimeRemoved = false) override;
|
void Stop(bool runtimeRemoved = false) override;
|
||||||
|
|
||||||
virtual void Pause(void);
|
virtual void Pause();
|
||||||
virtual void Resume(void);
|
virtual void Resume();
|
||||||
|
|
||||||
virtual void OnConfigLoaded(void);
|
virtual void OnConfigLoaded();
|
||||||
virtual void CreateChildObjects(const Type::Ptr& childType);
|
virtual void CreateChildObjects(const Type::Ptr& childType);
|
||||||
virtual void OnAllConfigLoaded(void);
|
virtual void OnAllConfigLoaded();
|
||||||
virtual void OnStateLoaded(void);
|
virtual void OnStateLoaded();
|
||||||
|
|
||||||
virtual Dictionary::Ptr GetSourceLocation(void) const override;
|
Dictionary::Ptr GetSourceLocation() const override;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static intrusive_ptr<T> GetObject(const String& name)
|
static intrusive_ptr<T> GetObject(const String& name)
|
||||||
{
|
{
|
||||||
typedef TypeImpl<T> ObjType;
|
typedef TypeImpl<T> ObjType;
|
||||||
ObjType *ptype = static_cast<ObjType *>(T::TypeInstance.get());
|
auto *ptype = static_cast<ObjType *>(T::TypeInstance.get());
|
||||||
return static_pointer_cast<T>(ptype->GetObject(name));
|
return static_pointer_cast<T>(ptype->GetObject(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,14 +90,11 @@ public:
|
|||||||
|
|
||||||
static void DumpObjects(const String& filename, int attributeTypes = FAState);
|
static void DumpObjects(const String& filename, int attributeTypes = FAState);
|
||||||
static void RestoreObjects(const String& filename, int attributeTypes = FAState);
|
static void RestoreObjects(const String& filename, int attributeTypes = FAState);
|
||||||
static void StopObjects(void);
|
static void StopObjects();
|
||||||
|
|
||||||
static void DumpModifiedAttributes(const std::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback);
|
static void DumpModifiedAttributes(const std::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback);
|
||||||
|
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
protected:
|
|
||||||
explicit ConfigObject(void);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConfigObject::Ptr m_Zone;
|
ConfigObject::Ptr m_Zone;
|
||||||
@ -106,7 +103,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_OBJECTNAME(klass) \
|
#define DECLARE_OBJECTNAME(klass) \
|
||||||
inline static String GetTypeName(void) \
|
inline static String GetTypeName() \
|
||||||
{ \
|
{ \
|
||||||
return #klass; \
|
return #klass; \
|
||||||
} \
|
} \
|
||||||
|
@ -35,7 +35,7 @@ enum HAMode
|
|||||||
class NameComposer
|
class NameComposer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~NameComposer(void);
|
virtual ~NameComposer();
|
||||||
|
|
||||||
virtual String MakeName(const String& shortName, const Object::Ptr& context) const = 0;
|
virtual String MakeName(const String& shortName, const Object::Ptr& context) const = 0;
|
||||||
virtual Dictionary::Ptr ParseName(const String& name) const = 0;
|
virtual Dictionary::Ptr ParseName(const String& name) const = 0;
|
||||||
@ -49,7 +49,7 @@ code {{{
|
|||||||
class ConfigObjectBase : public ObjectImpl<ConfigObjectBase>
|
class ConfigObjectBase : public ObjectImpl<ConfigObjectBase>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline DebugInfo GetDebugInfo(void) const
|
inline DebugInfo GetDebugInfo() const
|
||||||
{
|
{
|
||||||
return m_DebugInfo;
|
return m_DebugInfo;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
ConfigType::~ConfigType(void)
|
ConfigType::~ConfigType()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
ConfigObject::Ptr ConfigType::GetObject(const String& name) const
|
ConfigObject::Ptr ConfigType::GetObject(const String& name) const
|
||||||
@ -51,7 +51,7 @@ void ConfigType::RegisterObject(const ConfigObject::Ptr& object)
|
|||||||
if (it->second == object)
|
if (it->second == object)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Type *type = dynamic_cast<Type *>(this);
|
auto *type = dynamic_cast<Type *>(this);
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("An object with type '" + type->GetName() + "' and name '" + name + "' already exists (" +
|
BOOST_THROW_EXCEPTION(ScriptError("An object with type '" + type->GetName() + "' and name '" + name + "' already exists (" +
|
||||||
Convert::ToString(it->second->GetDebugInfo()) + "), new declaration: " + Convert::ToString(object->GetDebugInfo()),
|
Convert::ToString(it->second->GetDebugInfo()) + "), new declaration: " + Convert::ToString(object->GetDebugInfo()),
|
||||||
@ -75,7 +75,7 @@ void ConfigType::UnregisterObject(const ConfigObject::Ptr& object)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ConfigObject::Ptr> ConfigType::GetObjects(void) const
|
std::vector<ConfigObject::Ptr> ConfigType::GetObjects() const
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
return m_ObjectVector;
|
return m_ObjectVector;
|
||||||
@ -86,7 +86,7 @@ std::vector<ConfigObject::Ptr> ConfigType::GetObjectsHelper(Type *type)
|
|||||||
return static_cast<TypeImpl<ConfigObject> *>(type)->GetObjects();
|
return static_cast<TypeImpl<ConfigObject> *>(type)->GetObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigType::GetObjectCount(void) const
|
int ConfigType::GetObjectCount() const
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
return m_ObjectVector.size();
|
return m_ObjectVector.size();
|
||||||
|
@ -33,34 +33,35 @@ class ConfigObject;
|
|||||||
class ConfigType
|
class ConfigType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~ConfigType(void);
|
virtual ~ConfigType();
|
||||||
|
|
||||||
intrusive_ptr<ConfigObject> GetObject(const String& name) const;
|
intrusive_ptr<ConfigObject> GetObject(const String& name) const;
|
||||||
|
|
||||||
void RegisterObject(const intrusive_ptr<ConfigObject>& object);
|
void RegisterObject(const intrusive_ptr<ConfigObject>& object);
|
||||||
void UnregisterObject(const intrusive_ptr<ConfigObject>& object);
|
void UnregisterObject(const intrusive_ptr<ConfigObject>& object);
|
||||||
|
|
||||||
std::vector<intrusive_ptr<ConfigObject> > GetObjects(void) const;
|
std::vector<intrusive_ptr<ConfigObject> > GetObjects() const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static TypeImpl<T> *Get(void)
|
static TypeImpl<T> *Get()
|
||||||
{
|
{
|
||||||
typedef TypeImpl<T> ObjType;
|
typedef TypeImpl<T> ObjType;
|
||||||
return static_cast<ObjType *>(T::TypeInstance.get());
|
return static_cast<ObjType *>(T::TypeInstance.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::vector<intrusive_ptr<T> > GetObjectsByType(void)
|
static std::vector<intrusive_ptr<T> > GetObjectsByType()
|
||||||
{
|
{
|
||||||
std::vector<intrusive_ptr<ConfigObject> > objects = GetObjectsHelper(T::TypeInstance.get());
|
std::vector<intrusive_ptr<ConfigObject> > objects = GetObjectsHelper(T::TypeInstance.get());
|
||||||
std::vector<intrusive_ptr<T> > result;
|
std::vector<intrusive_ptr<T> > result;
|
||||||
for (const auto& object : objects) {
|
result.reserve(objects.size());
|
||||||
|
for (const auto& object : objects) {
|
||||||
result.push_back(static_pointer_cast<T>(object));
|
result.push_back(static_pointer_cast<T>(object));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetObjectCount(void) const;
|
int GetObjectCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<String, intrusive_ptr<ConfigObject> > ObjectMap;
|
typedef std::map<String, intrusive_ptr<ConfigObject> > ObjectMap;
|
||||||
|
@ -220,60 +220,60 @@ String ConfigWriter::EscapeIcingaString(const String& str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<String>& ConfigWriter::GetKeywords(void)
|
const std::vector<String>& ConfigWriter::GetKeywords()
|
||||||
{
|
{
|
||||||
static std::vector<String> keywords;
|
static std::vector<String> keywords;
|
||||||
static boost::mutex mutex;
|
static boost::mutex mutex;
|
||||||
boost::mutex::scoped_lock lock(mutex);
|
boost::mutex::scoped_lock lock(mutex);
|
||||||
|
|
||||||
if (keywords.empty()) {
|
if (keywords.empty()) {
|
||||||
keywords.push_back("object");
|
keywords.emplace_back("object");
|
||||||
keywords.push_back("template");
|
keywords.emplace_back("template");
|
||||||
keywords.push_back("include");
|
keywords.emplace_back("include");
|
||||||
keywords.push_back("include_recursive");
|
keywords.emplace_back("include_recursive");
|
||||||
keywords.push_back("include_zones");
|
keywords.emplace_back("include_zones");
|
||||||
keywords.push_back("library");
|
keywords.emplace_back("library");
|
||||||
keywords.push_back("null");
|
keywords.emplace_back("null");
|
||||||
keywords.push_back("true");
|
keywords.emplace_back("true");
|
||||||
keywords.push_back("false");
|
keywords.emplace_back("false");
|
||||||
keywords.push_back("const");
|
keywords.emplace_back("const");
|
||||||
keywords.push_back("var");
|
keywords.emplace_back("var");
|
||||||
keywords.push_back("this");
|
keywords.emplace_back("this");
|
||||||
keywords.push_back("globals");
|
keywords.emplace_back("globals");
|
||||||
keywords.push_back("locals");
|
keywords.emplace_back("locals");
|
||||||
keywords.push_back("use");
|
keywords.emplace_back("use");
|
||||||
keywords.push_back("__using");
|
keywords.emplace_back("__using");
|
||||||
keywords.push_back("default");
|
keywords.emplace_back("default");
|
||||||
keywords.push_back("ignore_on_error");
|
keywords.emplace_back("ignore_on_error");
|
||||||
keywords.push_back("current_filename");
|
keywords.emplace_back("current_filename");
|
||||||
keywords.push_back("current_line");
|
keywords.emplace_back("current_line");
|
||||||
keywords.push_back("apply");
|
keywords.emplace_back("apply");
|
||||||
keywords.push_back("to");
|
keywords.emplace_back("to");
|
||||||
keywords.push_back("where");
|
keywords.emplace_back("where");
|
||||||
keywords.push_back("import");
|
keywords.emplace_back("import");
|
||||||
keywords.push_back("assign");
|
keywords.emplace_back("assign");
|
||||||
keywords.push_back("ignore");
|
keywords.emplace_back("ignore");
|
||||||
keywords.push_back("function");
|
keywords.emplace_back("function");
|
||||||
keywords.push_back("return");
|
keywords.emplace_back("return");
|
||||||
keywords.push_back("break");
|
keywords.emplace_back("break");
|
||||||
keywords.push_back("continue");
|
keywords.emplace_back("continue");
|
||||||
keywords.push_back("for");
|
keywords.emplace_back("for");
|
||||||
keywords.push_back("if");
|
keywords.emplace_back("if");
|
||||||
keywords.push_back("else");
|
keywords.emplace_back("else");
|
||||||
keywords.push_back("while");
|
keywords.emplace_back("while");
|
||||||
keywords.push_back("throw");
|
keywords.emplace_back("throw");
|
||||||
keywords.push_back("try");
|
keywords.emplace_back("try");
|
||||||
keywords.push_back("except");
|
keywords.emplace_back("except");
|
||||||
}
|
}
|
||||||
|
|
||||||
return keywords;
|
return keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigIdentifier::ConfigIdentifier(const String& identifier)
|
ConfigIdentifier::ConfigIdentifier(String identifier)
|
||||||
: m_Name(identifier)
|
: m_Name(std::move(identifier))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
String ConfigIdentifier::GetName(void) const
|
String ConfigIdentifier::GetName() const
|
||||||
{
|
{
|
||||||
return m_Name;
|
return m_Name;
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ class ConfigIdentifier final : public Object
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(ConfigIdentifier);
|
DECLARE_PTR_TYPEDEFS(ConfigIdentifier);
|
||||||
|
|
||||||
ConfigIdentifier(const String& name);
|
ConfigIdentifier(String name);
|
||||||
|
|
||||||
String GetName(void) const;
|
String GetName() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_Name;
|
String m_Name;
|
||||||
@ -73,10 +73,10 @@ public:
|
|||||||
static void EmitComment(std::ostream& fp, const String& text);
|
static void EmitComment(std::ostream& fp, const String& text);
|
||||||
static void EmitFunctionCall(std::ostream& fp, const String& name, const Array::Ptr& arguments);
|
static void EmitFunctionCall(std::ostream& fp, const String& name, const Array::Ptr& arguments);
|
||||||
|
|
||||||
static const std::vector<String>& GetKeywords(void);
|
static const std::vector<String>& GetKeywords();
|
||||||
private:
|
private:
|
||||||
static String EscapeIcingaString(const String& str);
|
static String EscapeIcingaString(const String& str);
|
||||||
ConfigWriter(void);
|
ConfigWriter();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ using namespace icinga;
|
|||||||
|
|
||||||
static ConsoleType l_ConsoleType = Console_Dumb;
|
static ConsoleType l_ConsoleType = Console_Dumb;
|
||||||
|
|
||||||
static void InitializeConsole(void)
|
static void InitializeConsole()
|
||||||
{
|
{
|
||||||
l_ConsoleType = Console_Dumb;
|
l_ConsoleType = Console_Dumb;
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ std::ostream& operator<<(std::ostream& fp, const ConsoleColorTag& cct);
|
|||||||
class Console
|
class Console
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void DetectType(void);
|
static void DetectType();
|
||||||
|
|
||||||
static void SetType(std::ostream& fp, ConsoleType type);
|
static void SetType(std::ostream& fp, ConsoleType type);
|
||||||
static ConsoleType GetType(std::ostream& fp);
|
static ConsoleType GetType(std::ostream& fp);
|
||||||
@ -100,7 +100,7 @@ public:
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Console(void);
|
Console();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,12 @@ ContextFrame::ContextFrame(const String& message)
|
|||||||
GetFrames().push_front(message);
|
GetFrames().push_front(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextFrame::~ContextFrame(void)
|
ContextFrame::~ContextFrame()
|
||||||
{
|
{
|
||||||
GetFrames().pop_front();
|
GetFrames().pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<String>& ContextFrame::GetFrames(void)
|
std::list<String>& ContextFrame::GetFrames()
|
||||||
{
|
{
|
||||||
if (!l_Frames.get())
|
if (!l_Frames.get())
|
||||||
l_Frames.reset(new std::list<String>());
|
l_Frames.reset(new std::list<String>());
|
||||||
@ -42,7 +42,7 @@ std::list<String>& ContextFrame::GetFrames(void)
|
|||||||
return *l_Frames;
|
return *l_Frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextTrace::ContextTrace(void)
|
ContextTrace::ContextTrace()
|
||||||
: m_Frames(ContextFrame::GetFrames())
|
: m_Frames(ContextFrame::GetFrames())
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ void ContextTrace::Print(std::ostream& fp) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ContextTrace::GetLength(void) const
|
size_t ContextTrace::GetLength() const
|
||||||
{
|
{
|
||||||
return m_Frames.size();
|
return m_Frames.size();
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,11 @@ namespace icinga
|
|||||||
class ContextTrace
|
class ContextTrace
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ContextTrace(void);
|
ContextTrace();
|
||||||
|
|
||||||
void Print(std::ostream& fp) const;
|
void Print(std::ostream& fp) const;
|
||||||
|
|
||||||
size_t GetLength(void) const;
|
size_t GetLength() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<String> m_Frames;
|
std::list<String> m_Frames;
|
||||||
@ -51,10 +51,10 @@ class ContextFrame
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ContextFrame(const String& message);
|
ContextFrame(const String& message);
|
||||||
~ContextFrame(void);
|
~ContextFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::list<String>& GetFrames(void);
|
static std::list<String>& GetFrames();
|
||||||
|
|
||||||
friend class ContextTrace;
|
friend class ContextTrace;
|
||||||
};
|
};
|
||||||
|
@ -88,7 +88,7 @@ public:
|
|||||||
static double ToDateTimeValue(const Value& val);
|
static double ToDateTimeValue(const Value& val);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Convert(void);
|
Convert();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ static String DateTimeFormat(const String& format)
|
|||||||
return self->Format(format);
|
return self->Format(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr DateTime::GetPrototype(void)
|
Object::Ptr DateTime::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ DateTime::DateTime(const std::vector<Value>& args)
|
|||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid number of arguments for the DateTime constructor."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid number of arguments for the DateTime constructor."));
|
||||||
}
|
}
|
||||||
|
|
||||||
double DateTime::GetValue(void) const
|
double DateTime::GetValue() const
|
||||||
{
|
{
|
||||||
return m_Value;
|
return m_Value;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ String DateTime::Format(const String& format) const
|
|||||||
return Utility::FormatDateTime(format.CStr(), m_Value);
|
return Utility::FormatDateTime(format.CStr(), m_Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
String DateTime::ToString(void) const
|
String DateTime::ToString() const
|
||||||
{
|
{
|
||||||
return Format("%Y-%m-%d %H:%M:%S %z");
|
return Format("%Y-%m-%d %H:%M:%S %z");
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,10 @@ public:
|
|||||||
|
|
||||||
String Format(const String& format) const;
|
String Format(const String& format) const;
|
||||||
|
|
||||||
virtual double GetValue(void) const override;
|
double GetValue() const override;
|
||||||
virtual String ToString(void) const override;
|
String ToString() const override;
|
||||||
|
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_Value;
|
double m_Value;
|
||||||
|
@ -23,10 +23,6 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
DebugInfo::DebugInfo(void)
|
|
||||||
: FirstLine(0), FirstColumn(0), LastLine(0), LastColumn(0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Outputs a DebugInfo struct to a stream.
|
* Outputs a DebugInfo struct to a stream.
|
||||||
*
|
*
|
||||||
|
@ -35,13 +35,11 @@ struct DebugInfo
|
|||||||
{
|
{
|
||||||
String Path;
|
String Path;
|
||||||
|
|
||||||
int FirstLine;
|
int FirstLine{0};
|
||||||
int FirstColumn;
|
int FirstColumn{0};
|
||||||
|
|
||||||
int LastLine;
|
int LastLine{0};
|
||||||
int LastColumn;
|
int LastColumn{0};
|
||||||
|
|
||||||
DebugInfo(void);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const DebugInfo& val);
|
std::ostream& operator<<(std::ostream& out, const DebugInfo& val);
|
||||||
|
@ -59,7 +59,7 @@ std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)
|
|||||||
if (it != m_Dependencies.end()) {
|
if (it != m_Dependencies.end()) {
|
||||||
typedef std::pair<Object *, int> kv_pair;
|
typedef std::pair<Object *, int> kv_pair;
|
||||||
for (const kv_pair& kv : it->second) {
|
for (const kv_pair& kv : it->second) {
|
||||||
objects.push_back(kv.first);
|
objects.emplace_back(kv.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
static std::vector<Object::Ptr> GetParents(const Object::Ptr& child);
|
static std::vector<Object::Ptr> GetParents(const Object::Ptr& child);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DependencyGraph(void);
|
DependencyGraph();
|
||||||
|
|
||||||
static boost::mutex m_Mutex;
|
static boost::mutex m_Mutex;
|
||||||
static std::map<Object *, std::map<Object *, int> > m_Dependencies;
|
static std::map<Object *, std::map<Object *, int> > m_Dependencies;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static double DictionaryLen(void)
|
static double DictionaryLen()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
||||||
@ -60,14 +60,14 @@ static bool DictionaryContains(const String& key)
|
|||||||
return self->Contains(key);
|
return self->Contains(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dictionary::Ptr DictionaryShallowClone(void)
|
static Dictionary::Ptr DictionaryShallowClone()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
||||||
return self->ShallowClone();
|
return self->ShallowClone();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Array::Ptr DictionaryKeys(void)
|
static Array::Ptr DictionaryKeys()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
||||||
@ -79,7 +79,7 @@ static Array::Ptr DictionaryKeys(void)
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Array::Ptr DictionaryValues(void)
|
static Array::Ptr DictionaryValues()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
|
||||||
@ -91,7 +91,7 @@ static Array::Ptr DictionaryValues(void)
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr Dictionary::GetPrototype(void)
|
Object::Ptr Dictionary::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -29,12 +29,6 @@ template class std::map<String, Value>;
|
|||||||
|
|
||||||
REGISTER_PRIMITIVE_TYPE(Dictionary, Object, Dictionary::GetPrototype());
|
REGISTER_PRIMITIVE_TYPE(Dictionary, Object, Dictionary::GetPrototype());
|
||||||
|
|
||||||
Dictionary::Dictionary(void)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Dictionary::~Dictionary(void)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a value from a dictionary.
|
* Retrieves a value from a dictionary.
|
||||||
*
|
*
|
||||||
@ -79,20 +73,7 @@ bool Dictionary::Get(const String& key, Value *result) const
|
|||||||
* @param key The key.
|
* @param key The key.
|
||||||
* @param value The value.
|
* @param value The value.
|
||||||
*/
|
*/
|
||||||
void Dictionary::Set(const String& key, const Value& value)
|
void Dictionary::Set(const String& key, Value value)
|
||||||
{
|
|
||||||
ObjectLock olock(this);
|
|
||||||
|
|
||||||
m_Data[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a value in the dictionary.
|
|
||||||
*
|
|
||||||
* @param key The key.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
void Dictionary::Set(const String& key, Value&& value)
|
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -104,7 +85,7 @@ void Dictionary::Set(const String& key, Value&& value)
|
|||||||
*
|
*
|
||||||
* @returns Number of elements.
|
* @returns Number of elements.
|
||||||
*/
|
*/
|
||||||
size_t Dictionary::GetLength(void) const
|
size_t Dictionary::GetLength() const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -131,7 +112,7 @@ bool Dictionary::Contains(const String& key) const
|
|||||||
*
|
*
|
||||||
* @returns An iterator.
|
* @returns An iterator.
|
||||||
*/
|
*/
|
||||||
Dictionary::Iterator Dictionary::Begin(void)
|
Dictionary::Iterator Dictionary::Begin()
|
||||||
{
|
{
|
||||||
ASSERT(OwnsLock());
|
ASSERT(OwnsLock());
|
||||||
|
|
||||||
@ -145,7 +126,7 @@ Dictionary::Iterator Dictionary::Begin(void)
|
|||||||
*
|
*
|
||||||
* @returns An iterator.
|
* @returns An iterator.
|
||||||
*/
|
*/
|
||||||
Dictionary::Iterator Dictionary::End(void)
|
Dictionary::Iterator Dictionary::End()
|
||||||
{
|
{
|
||||||
ASSERT(OwnsLock());
|
ASSERT(OwnsLock());
|
||||||
|
|
||||||
@ -185,7 +166,7 @@ void Dictionary::Remove(const String& key)
|
|||||||
/**
|
/**
|
||||||
* Removes all dictionary items.
|
* Removes all dictionary items.
|
||||||
*/
|
*/
|
||||||
void Dictionary::Clear(void)
|
void Dictionary::Clear()
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -206,7 +187,7 @@ void Dictionary::CopyTo(const Dictionary::Ptr& dest) const
|
|||||||
*
|
*
|
||||||
* @returns a copy of the dictionary.
|
* @returns a copy of the dictionary.
|
||||||
*/
|
*/
|
||||||
Dictionary::Ptr Dictionary::ShallowClone(void) const
|
Dictionary::Ptr Dictionary::ShallowClone() const
|
||||||
{
|
{
|
||||||
Dictionary::Ptr clone = new Dictionary();
|
Dictionary::Ptr clone = new Dictionary();
|
||||||
CopyTo(clone);
|
CopyTo(clone);
|
||||||
@ -219,7 +200,7 @@ Dictionary::Ptr Dictionary::ShallowClone(void) const
|
|||||||
*
|
*
|
||||||
* @returns a copy of the dictionary.
|
* @returns a copy of the dictionary.
|
||||||
*/
|
*/
|
||||||
Object::Ptr Dictionary::Clone(void) const
|
Object::Ptr Dictionary::Clone() const
|
||||||
{
|
{
|
||||||
Dictionary::Ptr dict = new Dictionary();
|
Dictionary::Ptr dict = new Dictionary();
|
||||||
|
|
||||||
@ -237,7 +218,7 @@ Object::Ptr Dictionary::Clone(void) const
|
|||||||
*
|
*
|
||||||
* @returns an array of key names
|
* @returns an array of key names
|
||||||
*/
|
*/
|
||||||
std::vector<String> Dictionary::GetKeys(void) const
|
std::vector<String> Dictionary::GetKeys() const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -250,7 +231,7 @@ std::vector<String> Dictionary::GetKeys(void) const
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Dictionary::ToString(void) const
|
String Dictionary::ToString() const
|
||||||
{
|
{
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
ConfigWriter::EmitScope(msgbuf, 1, const_cast<Dictionary *>(this));
|
ConfigWriter::EmitScope(msgbuf, 1, const_cast<Dictionary *>(this));
|
||||||
@ -282,12 +263,12 @@ bool Dictionary::GetOwnField(const String& field, Value *result) const
|
|||||||
return Get(field, result);
|
return Get(field, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Iterator icinga::begin(Dictionary::Ptr x)
|
Dictionary::Iterator icinga::begin(const Dictionary::Ptr& x)
|
||||||
{
|
{
|
||||||
return x->Begin();
|
return x->Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Iterator icinga::end(Dictionary::Ptr x)
|
Dictionary::Iterator icinga::end(const Dictionary::Ptr& x)
|
||||||
{
|
{
|
||||||
return x->End();
|
return x->End();
|
||||||
}
|
}
|
||||||
|
@ -49,49 +49,44 @@ public:
|
|||||||
|
|
||||||
typedef std::map<String, Value>::value_type Pair;
|
typedef std::map<String, Value>::value_type Pair;
|
||||||
|
|
||||||
Dictionary(void);
|
|
||||||
|
|
||||||
~Dictionary(void);
|
|
||||||
|
|
||||||
Value Get(const String& key) const;
|
Value Get(const String& key) const;
|
||||||
bool Get(const String& key, Value *result) const;
|
bool Get(const String& key, Value *result) const;
|
||||||
void Set(const String& key, const Value& value);
|
void Set(const String& key, Value value);
|
||||||
void Set(const String& key, Value&& value);
|
|
||||||
bool Contains(const String& key) const;
|
bool Contains(const String& key) const;
|
||||||
|
|
||||||
Iterator Begin(void);
|
Iterator Begin();
|
||||||
Iterator End(void);
|
Iterator End();
|
||||||
|
|
||||||
size_t GetLength(void) const;
|
size_t GetLength() const;
|
||||||
|
|
||||||
void Remove(const String& key);
|
void Remove(const String& key);
|
||||||
|
|
||||||
void Remove(Iterator it);
|
void Remove(Iterator it);
|
||||||
|
|
||||||
void Clear(void);
|
void Clear();
|
||||||
|
|
||||||
void CopyTo(const Dictionary::Ptr& dest) const;
|
void CopyTo(const Dictionary::Ptr& dest) const;
|
||||||
Dictionary::Ptr ShallowClone(void) const;
|
Dictionary::Ptr ShallowClone() const;
|
||||||
|
|
||||||
std::vector<String> GetKeys(void) const;
|
std::vector<String> GetKeys() const;
|
||||||
|
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
virtual Object::Ptr Clone(void) const override;
|
Object::Ptr Clone() const override;
|
||||||
|
|
||||||
virtual String ToString(void) const override;
|
String ToString() const override;
|
||||||
|
|
||||||
virtual Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
|
Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
|
||||||
virtual void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
|
void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
|
||||||
virtual bool HasOwnField(const String& field) const override;
|
bool HasOwnField(const String& field) const override;
|
||||||
virtual bool GetOwnField(const String& field, Value *result) const override;
|
bool GetOwnField(const String& field, Value *result) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<String, Value> m_Data; /**< The data for the dictionary. */
|
std::map<String, Value> m_Data; /**< The data for the dictionary. */
|
||||||
};
|
};
|
||||||
|
|
||||||
Dictionary::Iterator begin(Dictionary::Ptr x);
|
Dictionary::Iterator begin(const Dictionary::Ptr& x);
|
||||||
Dictionary::Iterator end(Dictionary::Ptr x);
|
Dictionary::Iterator end(const Dictionary::Ptr& x);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ static boost::thread_specific_ptr<ContextTrace> l_LastExceptionContext;
|
|||||||
class libcxx_type_info : public std::type_info
|
class libcxx_type_info : public std::type_info
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~libcxx_type_info();
|
~libcxx_type_info() override;
|
||||||
|
|
||||||
virtual void noop1() const;
|
virtual void noop1() const;
|
||||||
virtual void noop2() const;
|
virtual void noop2() const;
|
||||||
@ -58,8 +58,8 @@ inline void *cast_exception(void *obj, const std::type_info *src, const std::typ
|
|||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
#else /* __GLIBCXX__ */
|
#else /* __GLIBCXX__ */
|
||||||
const libcxx_type_info *srcInfo = static_cast<const libcxx_type_info *>(src);
|
const auto *srcInfo = static_cast<const libcxx_type_info *>(src);
|
||||||
const libcxx_type_info *dstInfo = static_cast<const libcxx_type_info *>(dst);
|
const auto *dstInfo = static_cast<const libcxx_type_info *>(dst);
|
||||||
|
|
||||||
void *adj = obj;
|
void *adj = obj;
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ static boost::thread_specific_ptr<DestCallback> l_LastExceptionDest;
|
|||||||
extern "C" void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *));
|
extern "C" void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *));
|
||||||
#endif /* HAVE_CXXABI_H */
|
#endif /* HAVE_CXXABI_H */
|
||||||
|
|
||||||
void icinga::RethrowUncaughtException(void)
|
void icinga::RethrowUncaughtException()
|
||||||
{
|
{
|
||||||
#if defined(__GLIBCXX__) || !defined(HAVE_CXXABI_H)
|
#if defined(__GLIBCXX__) || !defined(HAVE_CXXABI_H)
|
||||||
throw;
|
throw;
|
||||||
@ -104,7 +104,7 @@ void icinga::RethrowUncaughtException(void)
|
|||||||
extern "C"
|
extern "C"
|
||||||
void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *))
|
void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *))
|
||||||
{
|
{
|
||||||
std::type_info *tinfo = static_cast<std::type_info *>(pvtinfo);
|
auto *tinfo = static_cast<std::type_info *>(pvtinfo);
|
||||||
|
|
||||||
typedef void (*cxa_throw_fn)(void *, std::type_info *, void (*)(void *)) __attribute__((noreturn));
|
typedef void (*cxa_throw_fn)(void *, std::type_info *, void (*)(void *)) __attribute__((noreturn));
|
||||||
static cxa_throw_fn real_cxa_throw;
|
static cxa_throw_fn real_cxa_throw;
|
||||||
@ -115,12 +115,12 @@ void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *))
|
|||||||
l_LastExceptionDest.reset(new DestCallback(dest));
|
l_LastExceptionDest.reset(new DestCallback(dest));
|
||||||
#endif /* !defined(__GLIBCXX__) && !defined(_WIN32) */
|
#endif /* !defined(__GLIBCXX__) && !defined(_WIN32) */
|
||||||
|
|
||||||
if (real_cxa_throw == 0)
|
if (real_cxa_throw == nullptr)
|
||||||
real_cxa_throw = (cxa_throw_fn)dlsym(RTLD_NEXT, "__cxa_throw");
|
real_cxa_throw = (cxa_throw_fn)dlsym(RTLD_NEXT, "__cxa_throw");
|
||||||
|
|
||||||
#ifndef NO_CAST_EXCEPTION
|
#ifndef NO_CAST_EXCEPTION
|
||||||
void *uex = cast_exception(obj, tinfo, &typeid(user_error));
|
void *uex = cast_exception(obj, tinfo, &typeid(user_error));
|
||||||
boost::exception *ex = reinterpret_cast<boost::exception *>(cast_exception(obj, tinfo, &typeid(boost::exception)));
|
auto *ex = reinterpret_cast<boost::exception *>(cast_exception(obj, tinfo, &typeid(boost::exception)));
|
||||||
|
|
||||||
if (!uex) {
|
if (!uex) {
|
||||||
#endif /* NO_CAST_EXCEPTION */
|
#endif /* NO_CAST_EXCEPTION */
|
||||||
@ -145,7 +145,7 @@ void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *))
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_CXXABI_H */
|
#endif /* HAVE_CXXABI_H */
|
||||||
|
|
||||||
StackTrace *icinga::GetLastExceptionStack(void)
|
StackTrace *icinga::GetLastExceptionStack()
|
||||||
{
|
{
|
||||||
return l_LastExceptionStack.get();
|
return l_LastExceptionStack.get();
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ void icinga::SetLastExceptionStack(const StackTrace& trace)
|
|||||||
l_LastExceptionStack.reset(new StackTrace(trace));
|
l_LastExceptionStack.reset(new StackTrace(trace));
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextTrace *icinga::GetLastExceptionContext(void)
|
ContextTrace *icinga::GetLastExceptionContext()
|
||||||
{
|
{
|
||||||
return l_LastExceptionContext.get();
|
return l_LastExceptionContext.get();
|
||||||
}
|
}
|
||||||
@ -171,14 +171,14 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, Sta
|
|||||||
|
|
||||||
String message = ex.what();
|
String message = ex.what();
|
||||||
|
|
||||||
const ValidationError *vex = dynamic_cast<const ValidationError *>(&ex);
|
const auto *vex = dynamic_cast<const ValidationError *>(&ex);
|
||||||
|
|
||||||
if (message.IsEmpty())
|
if (message.IsEmpty())
|
||||||
result << boost::diagnostic_information(ex) << "\n";
|
result << boost::diagnostic_information(ex) << "\n";
|
||||||
else
|
else
|
||||||
result << "Error: " << message << "\n";
|
result << "Error: " << message << "\n";
|
||||||
|
|
||||||
const ScriptError *dex = dynamic_cast<const ScriptError *>(&ex);
|
const auto *dex = dynamic_cast<const ScriptError *>(&ex);
|
||||||
|
|
||||||
if (dex && !dex->GetDebugInfo().Path.IsEmpty())
|
if (dex && !dex->GetDebugInfo().Path.IsEmpty())
|
||||||
ShowCodeLocation(result, dex->GetDebugInfo());
|
ShowCodeLocation(result, dex->GetDebugInfo());
|
||||||
@ -223,8 +223,8 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, Sta
|
|||||||
ShowCodeLocation(result, di);
|
ShowCodeLocation(result, di);
|
||||||
}
|
}
|
||||||
|
|
||||||
const user_error *uex = dynamic_cast<const user_error *>(&ex);
|
const auto *uex = dynamic_cast<const user_error *>(&ex);
|
||||||
const posix_error *pex = dynamic_cast<const posix_error *>(&ex);
|
const auto *pex = dynamic_cast<const posix_error *>(&ex);
|
||||||
|
|
||||||
if (!uex && !pex && verbose) {
|
if (!uex && !pex && verbose) {
|
||||||
const StackTrace *st = boost::get_error_info<StackTraceErrorInfo>(ex);
|
const StackTrace *st = boost::get_error_info<StackTraceErrorInfo>(ex);
|
||||||
@ -260,7 +260,7 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, Sta
|
|||||||
return result.str();
|
return result.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
String icinga::DiagnosticInformation(boost::exception_ptr eptr, bool verbose)
|
String icinga::DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose)
|
||||||
{
|
{
|
||||||
StackTrace *pt = GetLastExceptionStack();
|
StackTrace *pt = GetLastExceptionStack();
|
||||||
StackTrace stack;
|
StackTrace stack;
|
||||||
@ -283,33 +283,30 @@ String icinga::DiagnosticInformation(boost::exception_ptr eptr, bool verbose)
|
|||||||
return boost::diagnostic_information(eptr);
|
return boost::diagnostic_information(eptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptError::ScriptError(const String& message)
|
ScriptError::ScriptError(String message)
|
||||||
: m_Message(message), m_IncompleteExpr(false)
|
: m_Message(std::move(message)), m_IncompleteExpr(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
ScriptError::ScriptError(const String& message, const DebugInfo& di, bool incompleteExpr)
|
ScriptError::ScriptError(String message, DebugInfo di, bool incompleteExpr)
|
||||||
: m_Message(message), m_DebugInfo(di), m_IncompleteExpr(incompleteExpr), m_HandledByDebugger(false)
|
: m_Message(std::move(message)), m_DebugInfo(std::move(di)), m_IncompleteExpr(incompleteExpr), m_HandledByDebugger(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
ScriptError::~ScriptError(void) throw()
|
const char *ScriptError::what() const throw()
|
||||||
{ }
|
|
||||||
|
|
||||||
const char *ScriptError::what(void) const throw()
|
|
||||||
{
|
{
|
||||||
return m_Message.CStr();
|
return m_Message.CStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugInfo ScriptError::GetDebugInfo(void) const
|
DebugInfo ScriptError::GetDebugInfo() const
|
||||||
{
|
{
|
||||||
return m_DebugInfo;
|
return m_DebugInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptError::IsIncompleteExpression(void) const
|
bool ScriptError::IsIncompleteExpression() const
|
||||||
{
|
{
|
||||||
return m_IncompleteExpr;;
|
return m_IncompleteExpr;;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptError::IsHandledByDebugger(void) const
|
bool ScriptError::IsHandledByDebugger() const
|
||||||
{
|
{
|
||||||
return m_HandledByDebugger;
|
return m_HandledByDebugger;
|
||||||
}
|
}
|
||||||
@ -319,16 +316,12 @@ void ScriptError::SetHandledByDebugger(bool handled)
|
|||||||
m_HandledByDebugger = handled;
|
m_HandledByDebugger = handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
posix_error::posix_error(void)
|
posix_error::~posix_error() throw()
|
||||||
: m_Message(nullptr)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
posix_error::~posix_error(void) throw()
|
|
||||||
{
|
{
|
||||||
free(m_Message);
|
free(m_Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *posix_error::what(void) const throw()
|
const char *posix_error::what() const throw()
|
||||||
{
|
{
|
||||||
if (!m_Message) {
|
if (!m_Message) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
@ -380,25 +373,25 @@ ValidationError::ValidationError(const ConfigObject::Ptr& object, const std::vec
|
|||||||
m_What += ": " + message;
|
m_What += ": " + message;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidationError::~ValidationError(void) throw()
|
ValidationError::~ValidationError() throw()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
const char *ValidationError::what(void) const throw()
|
const char *ValidationError::what() const throw()
|
||||||
{
|
{
|
||||||
return m_What.CStr();
|
return m_What.CStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigObject::Ptr ValidationError::GetObject(void) const
|
ConfigObject::Ptr ValidationError::GetObject() const
|
||||||
{
|
{
|
||||||
return m_Object;
|
return m_Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> ValidationError::GetAttributePath(void) const
|
std::vector<String> ValidationError::GetAttributePath() const
|
||||||
{
|
{
|
||||||
return m_AttributePath;
|
return m_AttributePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ValidationError::GetMessage(void) const
|
String ValidationError::GetMessage() const
|
||||||
{
|
{
|
||||||
return m_Message;
|
return m_Message;
|
||||||
}
|
}
|
||||||
@ -408,8 +401,39 @@ void ValidationError::SetDebugHint(const Dictionary::Ptr& dhint)
|
|||||||
m_DebugHint = dhint;
|
m_DebugHint = dhint;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr ValidationError::GetDebugHint(void) const
|
Dictionary::Ptr ValidationError::GetDebugHint() const
|
||||||
{
|
{
|
||||||
return m_DebugHint;
|
return m_DebugHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string icinga::to_string(const StackTraceErrorInfo&)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string icinga::to_string(const errinfo_win32_error& e)
|
||||||
|
{
|
||||||
|
return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n";
|
||||||
|
}
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
std::string icinga::to_string(const errinfo_getaddrinfo_error& e)
|
||||||
|
{
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
msg = gai_strerrorA(e.value());
|
||||||
|
#else /* _WIN32 */
|
||||||
|
msg = gai_strerror(e.value());
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
return "[errinfo_getaddrinfo_error] = " + String(msg) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string icinga::to_string(const ContextTraceErrorInfo& e)
|
||||||
|
{
|
||||||
|
std::ostringstream msgbuf;
|
||||||
|
msgbuf << "[Context] = " << e.value();
|
||||||
|
return msgbuf.str();
|
||||||
|
}
|
||||||
|
@ -51,16 +51,16 @@ class user_error : virtual public std::exception, virtual public boost::exceptio
|
|||||||
class ScriptError : virtual public user_error
|
class ScriptError : virtual public user_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScriptError(const String& message);
|
ScriptError(String message);
|
||||||
ScriptError(const String& message, const DebugInfo& di, bool incompleteExpr = false);
|
ScriptError(String message, DebugInfo di, bool incompleteExpr = false);
|
||||||
~ScriptError(void) throw();
|
~ScriptError() throw() = default;
|
||||||
|
|
||||||
virtual const char *what(void) const throw() override final;
|
const char *what(void) const throw() final;
|
||||||
|
|
||||||
DebugInfo GetDebugInfo(void) const;
|
DebugInfo GetDebugInfo() const;
|
||||||
bool IsIncompleteExpression(void) const;
|
bool IsIncompleteExpression() const;
|
||||||
|
|
||||||
bool IsHandledByDebugger(void) const;
|
bool IsHandledByDebugger() const;
|
||||||
void SetHandledByDebugger(bool handled);
|
void SetHandledByDebugger(bool handled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -77,16 +77,16 @@ class ValidationError : virtual public user_error
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message);
|
ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message);
|
||||||
~ValidationError(void) throw();
|
~ValidationError() throw() override;
|
||||||
|
|
||||||
virtual const char *what(void) const throw() override final;
|
const char *what() const throw() override;
|
||||||
|
|
||||||
ConfigObject::Ptr GetObject(void) const;
|
ConfigObject::Ptr GetObject() const;
|
||||||
std::vector<String> GetAttributePath(void) const;
|
std::vector<String> GetAttributePath() const;
|
||||||
String GetMessage(void) const;
|
String GetMessage() const;
|
||||||
|
|
||||||
void SetDebugHint(const Dictionary::Ptr& dhint);
|
void SetDebugHint(const Dictionary::Ptr& dhint);
|
||||||
Dictionary::Ptr GetDebugHint(void) const;
|
Dictionary::Ptr GetDebugHint() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConfigObject::Ptr m_Object;
|
ConfigObject::Ptr m_Object;
|
||||||
@ -96,42 +96,33 @@ private:
|
|||||||
Dictionary::Ptr m_DebugHint;
|
Dictionary::Ptr m_DebugHint;
|
||||||
};
|
};
|
||||||
|
|
||||||
StackTrace *GetLastExceptionStack(void);
|
StackTrace *GetLastExceptionStack();
|
||||||
void SetLastExceptionStack(const StackTrace& trace);
|
void SetLastExceptionStack(const StackTrace& trace);
|
||||||
|
|
||||||
ContextTrace *GetLastExceptionContext(void);
|
ContextTrace *GetLastExceptionContext();
|
||||||
void SetLastExceptionContext(const ContextTrace& context);
|
void SetLastExceptionContext(const ContextTrace& context);
|
||||||
|
|
||||||
void RethrowUncaughtException(void);
|
void RethrowUncaughtException();
|
||||||
|
|
||||||
typedef boost::error_info<StackTrace, StackTrace> StackTraceErrorInfo;
|
typedef boost::error_info<StackTrace, StackTrace> StackTraceErrorInfo;
|
||||||
|
|
||||||
inline std::string to_string(const StackTraceErrorInfo&)
|
std::string to_string(const StackTraceErrorInfo&);
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef boost::error_info<ContextTrace, ContextTrace> ContextTraceErrorInfo;
|
typedef boost::error_info<ContextTrace, ContextTrace> ContextTraceErrorInfo;
|
||||||
|
|
||||||
inline std::string to_string(const ContextTraceErrorInfo& e)
|
std::string to_string(const ContextTraceErrorInfo& e);
|
||||||
{
|
|
||||||
std::ostringstream msgbuf;
|
|
||||||
msgbuf << "[Context] = " << e.value();
|
|
||||||
return msgbuf.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = nullptr, ContextTrace *context = nullptr);
|
String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = nullptr, ContextTrace *context = nullptr);
|
||||||
String DiagnosticInformation(boost::exception_ptr eptr, bool verbose = true);
|
String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = true);
|
||||||
|
|
||||||
class posix_error : virtual public std::exception, virtual public boost::exception {
|
class posix_error : virtual public std::exception, virtual public boost::exception {
|
||||||
public:
|
public:
|
||||||
posix_error(void);
|
~posix_error() throw() override;
|
||||||
virtual ~posix_error(void) throw();
|
|
||||||
|
|
||||||
virtual const char *what(void) const throw() override final;
|
const char *what(void) const throw() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable char *m_Message;
|
mutable char *m_Message{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -140,27 +131,13 @@ class win32_error : virtual public std::exception, virtual public boost::excepti
|
|||||||
struct errinfo_win32_error_;
|
struct errinfo_win32_error_;
|
||||||
typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
||||||
|
|
||||||
inline std::string to_string(const errinfo_win32_error& e)
|
std::string to_string(const errinfo_win32_error& e);
|
||||||
{
|
|
||||||
return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n";
|
|
||||||
}
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
struct errinfo_getaddrinfo_error_;
|
struct errinfo_getaddrinfo_error_;
|
||||||
typedef boost::error_info<struct errinfo_getaddrinfo_error_, int> errinfo_getaddrinfo_error;
|
typedef boost::error_info<struct errinfo_getaddrinfo_error_, int> errinfo_getaddrinfo_error;
|
||||||
|
|
||||||
inline std::string to_string(const errinfo_getaddrinfo_error& e)
|
std::string to_string(const errinfo_getaddrinfo_error& e);
|
||||||
{
|
|
||||||
String msg;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
msg = gai_strerrorA(e.value());
|
|
||||||
#else /* _WIN32 */
|
|
||||||
msg = gai_strerror(e.value());
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
return "[errinfo_getaddrinfo_error] = " + String(msg) + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
struct errinfo_message_;
|
struct errinfo_message_;
|
||||||
typedef boost::error_info<struct errinfo_message_, std::string> errinfo_message;
|
typedef boost::error_info<struct errinfo_message_, std::string> errinfo_message;
|
||||||
|
@ -21,17 +21,10 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the FIFO class.
|
|
||||||
*/
|
|
||||||
FIFO::FIFO(void)
|
|
||||||
: m_Buffer(nullptr), m_DataSize(0), m_AllocSize(0), m_Offset(0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor for the FIFO class.
|
* Destructor for the FIFO class.
|
||||||
*/
|
*/
|
||||||
FIFO::~FIFO(void)
|
FIFO::~FIFO()
|
||||||
{
|
{
|
||||||
free(m_Buffer);
|
free(m_Buffer);
|
||||||
}
|
}
|
||||||
@ -51,7 +44,7 @@ void FIFO::ResizeBuffer(size_t newSize, bool decrease)
|
|||||||
if (newSize == m_AllocSize)
|
if (newSize == m_AllocSize)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char *newBuffer = static_cast<char *>(realloc(m_Buffer, newSize));
|
auto *newBuffer = static_cast<char *>(realloc(m_Buffer, newSize));
|
||||||
|
|
||||||
if (!newBuffer)
|
if (!newBuffer)
|
||||||
BOOST_THROW_EXCEPTION(std::bad_alloc());
|
BOOST_THROW_EXCEPTION(std::bad_alloc());
|
||||||
@ -65,7 +58,7 @@ void FIFO::ResizeBuffer(size_t newSize, bool decrease)
|
|||||||
* Optimizes memory usage of the FIFO buffer by reallocating
|
* Optimizes memory usage of the FIFO buffer by reallocating
|
||||||
* and moving the buffer.
|
* and moving the buffer.
|
||||||
*/
|
*/
|
||||||
void FIFO::Optimize(void)
|
void FIFO::Optimize()
|
||||||
{
|
{
|
||||||
if (m_Offset > m_DataSize / 10 && m_Offset - m_DataSize > 1024) {
|
if (m_Offset > m_DataSize / 10 && m_Offset - m_DataSize > 1024) {
|
||||||
std::memmove(m_Buffer, m_Buffer + m_Offset, m_DataSize);
|
std::memmove(m_Buffer, m_Buffer + m_Offset, m_DataSize);
|
||||||
@ -124,25 +117,25 @@ void FIFO::Write(const void *buffer, size_t count)
|
|||||||
SignalDataAvailable();
|
SignalDataAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FIFO::Close(void)
|
void FIFO::Close()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool FIFO::IsEof(void) const
|
bool FIFO::IsEof() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t FIFO::GetAvailableBytes(void) const
|
size_t FIFO::GetAvailableBytes() const
|
||||||
{
|
{
|
||||||
return m_DataSize;
|
return m_DataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FIFO::SupportsWaiting(void) const
|
bool FIFO::SupportsWaiting() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FIFO::IsDataAvailable(void) const
|
bool FIFO::IsDataAvailable() const
|
||||||
{
|
{
|
||||||
return m_DataSize > 0;
|
return m_DataSize > 0;
|
||||||
}
|
}
|
||||||
|
@ -38,27 +38,26 @@ public:
|
|||||||
|
|
||||||
static const size_t BlockSize = 512;
|
static const size_t BlockSize = 512;
|
||||||
|
|
||||||
FIFO(void);
|
~FIFO() override;
|
||||||
~FIFO(void);
|
|
||||||
|
|
||||||
virtual size_t Peek(void *buffer, size_t count, bool allow_partial = false) override;
|
size_t Peek(void *buffer, size_t count, bool allow_partial = false) override;
|
||||||
virtual size_t Read(void *buffer, size_t count, bool allow_partial = false) override;
|
size_t Read(void *buffer, size_t count, bool allow_partial = false) override;
|
||||||
virtual void Write(const void *buffer, size_t count) override;
|
void Write(const void *buffer, size_t count) override;
|
||||||
virtual void Close(void) override;
|
void Close() override;
|
||||||
virtual bool IsEof(void) const override;
|
bool IsEof() const override;
|
||||||
virtual bool SupportsWaiting(void) const override;
|
bool SupportsWaiting() const override;
|
||||||
virtual bool IsDataAvailable(void) const override;
|
bool IsDataAvailable() const override;
|
||||||
|
|
||||||
size_t GetAvailableBytes(void) const;
|
size_t GetAvailableBytes() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *m_Buffer;
|
char *m_Buffer{nullptr};
|
||||||
size_t m_DataSize;
|
size_t m_DataSize{0};
|
||||||
size_t m_AllocSize;
|
size_t m_AllocSize{0};
|
||||||
size_t m_Offset;
|
size_t m_Offset{0};
|
||||||
|
|
||||||
void ResizeBuffer(size_t newSize, bool decrease);
|
void ResizeBuffer(size_t newSize, bool decrease);
|
||||||
void Optimize(void);
|
void Optimize();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,9 +53,9 @@ void FileLogger::Start(bool runtimeCreated)
|
|||||||
ObjectImpl<FileLogger>::Start(runtimeCreated);
|
ObjectImpl<FileLogger>::Start(runtimeCreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileLogger::ReopenLogFile(void)
|
void FileLogger::ReopenLogFile()
|
||||||
{
|
{
|
||||||
std::ofstream *stream = new std::ofstream();
|
auto *stream = new std::ofstream();
|
||||||
|
|
||||||
String path = GetPath();
|
String path = GetPath();
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@ public:
|
|||||||
|
|
||||||
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
|
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
|
||||||
|
|
||||||
virtual void Start(bool runtimeCreated) override;
|
void Start(bool runtimeCreated) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReopenLogFile(void);
|
void ReopenLogFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Object::Ptr Function::GetPrototype(void)
|
Object::Ptr Function::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_TYPE_WITH_PROTOTYPE(Function, Function::GetPrototype());
|
REGISTER_TYPE_WITH_PROTOTYPE(Function, Function::GetPrototype());
|
||||||
|
|
||||||
Function::Function(const String& name, const Callback& function, const std::vector<String>& args,
|
Function::Function(const String& name, Callback function, const std::vector<String>& args,
|
||||||
bool side_effect_free, bool deprecated)
|
bool side_effect_free, bool deprecated)
|
||||||
: m_Callback(function)
|
: m_Callback(std::move(function))
|
||||||
{
|
{
|
||||||
SetName(name, true);
|
SetName(name, true);
|
||||||
SetSideEffectFree(side_effect_free, true);
|
SetSideEffectFree(side_effect_free, true);
|
||||||
@ -48,7 +48,7 @@ Value Function::InvokeThis(const Value& otherThis, const std::vector<Value>& arg
|
|||||||
return m_Callback(arguments);
|
return m_Callback(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr Function::Clone(void) const
|
Object::Ptr Function::Clone() const
|
||||||
{
|
{
|
||||||
return const_cast<Function *>(this);
|
return const_cast<Function *>(this);
|
||||||
}
|
}
|
||||||
|
@ -51,24 +51,24 @@ public:
|
|||||||
Value Invoke(const std::vector<Value>& arguments = std::vector<Value>());
|
Value Invoke(const std::vector<Value>& arguments = std::vector<Value>());
|
||||||
Value InvokeThis(const Value& otherThis, const std::vector<Value>& arguments = std::vector<Value>());
|
Value InvokeThis(const Value& otherThis, const std::vector<Value>& arguments = std::vector<Value>());
|
||||||
|
|
||||||
bool IsSideEffectFree(void) const
|
bool IsSideEffectFree() const
|
||||||
{
|
{
|
||||||
return GetSideEffectFree();
|
return GetSideEffectFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDeprecated(void) const
|
bool IsDeprecated() const
|
||||||
{
|
{
|
||||||
return GetDeprecated();
|
return GetDeprecated();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
virtual Object::Ptr Clone(void) const override;
|
Object::Ptr Clone() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Callback m_Callback;
|
Callback m_Callback;
|
||||||
|
|
||||||
Function(const String& name, const Callback& function, const std::vector<String>& args,
|
Function(const String& name, Callback function, const std::vector<String>& args,
|
||||||
bool side_effect_free, bool deprecated);
|
bool side_effect_free, bool deprecated);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
bool icinga::InitializeOnceHelper(void (*func)(void), int priority)
|
bool icinga::InitializeOnceHelper(void (*func)(), int priority)
|
||||||
{
|
{
|
||||||
Loader::AddDeferredInitializer(func, priority);
|
Loader::AddDeferredInitializer(func, priority);
|
||||||
return true;
|
return true;
|
||||||
|
@ -30,7 +30,7 @@ namespace icinga
|
|||||||
|
|
||||||
#define I2_UNIQUE_NAME(prefix) I2_TOKENPASTE2(prefix, __COUNTER__)
|
#define I2_UNIQUE_NAME(prefix) I2_TOKENPASTE2(prefix, __COUNTER__)
|
||||||
|
|
||||||
bool InitializeOnceHelper(void (*func)(void), int priority = 0);
|
bool InitializeOnceHelper(void (*func)(), int priority = 0);
|
||||||
|
|
||||||
#define INITIALIZE_ONCE(func) \
|
#define INITIALIZE_ONCE(func) \
|
||||||
namespace { namespace I2_UNIQUE_NAME(io) { \
|
namespace { namespace I2_UNIQUE_NAME(io) { \
|
||||||
|
@ -126,12 +126,8 @@ String icinga::JsonEncode(const Value& value, bool pretty_print)
|
|||||||
struct JsonElement
|
struct JsonElement
|
||||||
{
|
{
|
||||||
String Key;
|
String Key;
|
||||||
bool KeySet;
|
bool KeySet{false};
|
||||||
Value EValue;
|
Value EValue;
|
||||||
|
|
||||||
JsonElement(void)
|
|
||||||
: KeySet(false)
|
|
||||||
{ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct JsonContext
|
struct JsonContext
|
||||||
@ -145,7 +141,7 @@ public:
|
|||||||
m_Stack.push(element);
|
m_Stack.push(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement Pop(void)
|
JsonElement Pop()
|
||||||
{
|
{
|
||||||
JsonElement value = m_Stack.top();
|
JsonElement value = m_Stack.top();
|
||||||
m_Stack.pop();
|
m_Stack.pop();
|
||||||
@ -180,18 +176,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Value GetValue(void) const
|
Value GetValue() const
|
||||||
{
|
{
|
||||||
ASSERT(m_Stack.size() == 1);
|
ASSERT(m_Stack.size() == 1);
|
||||||
return m_Stack.top().EValue;
|
return m_Stack.top().EValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveException(void)
|
void SaveException()
|
||||||
{
|
{
|
||||||
m_Exception = boost::current_exception();
|
m_Exception = boost::current_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThrowException(void) const
|
void ThrowException() const
|
||||||
{
|
{
|
||||||
if (m_Exception)
|
if (m_Exception)
|
||||||
boost::rethrow_exception(m_Exception);
|
boost::rethrow_exception(m_Exception);
|
||||||
@ -205,7 +201,7 @@ private:
|
|||||||
|
|
||||||
static int DecodeNull(void *ctx)
|
static int DecodeNull(void *ctx)
|
||||||
{
|
{
|
||||||
JsonContext *context = static_cast<JsonContext *>(ctx);
|
auto *context = static_cast<JsonContext *>(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context->AddValue(Empty);
|
context->AddValue(Empty);
|
||||||
@ -219,7 +215,7 @@ static int DecodeNull(void *ctx)
|
|||||||
|
|
||||||
static int DecodeBoolean(void *ctx, int value)
|
static int DecodeBoolean(void *ctx, int value)
|
||||||
{
|
{
|
||||||
JsonContext *context = static_cast<JsonContext *>(ctx);
|
auto *context = static_cast<JsonContext *>(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context->AddValue(static_cast<bool>(value));
|
context->AddValue(static_cast<bool>(value));
|
||||||
@ -233,7 +229,7 @@ static int DecodeBoolean(void *ctx, int value)
|
|||||||
|
|
||||||
static int DecodeNumber(void *ctx, const char *str, yajl_size len)
|
static int DecodeNumber(void *ctx, const char *str, yajl_size len)
|
||||||
{
|
{
|
||||||
JsonContext *context = static_cast<JsonContext *>(ctx);
|
auto *context = static_cast<JsonContext *>(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String jstr = String(str, str + len);
|
String jstr = String(str, str + len);
|
||||||
@ -248,7 +244,7 @@ static int DecodeNumber(void *ctx, const char *str, yajl_size len)
|
|||||||
|
|
||||||
static int DecodeString(void *ctx, const unsigned char *str, yajl_size len)
|
static int DecodeString(void *ctx, const unsigned char *str, yajl_size len)
|
||||||
{
|
{
|
||||||
JsonContext *context = static_cast<JsonContext *>(ctx);
|
auto *context = static_cast<JsonContext *>(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context->AddValue(String(str, str + len));
|
context->AddValue(String(str, str + len));
|
||||||
@ -262,7 +258,7 @@ static int DecodeString(void *ctx, const unsigned char *str, yajl_size len)
|
|||||||
|
|
||||||
static int DecodeStartMap(void *ctx)
|
static int DecodeStartMap(void *ctx)
|
||||||
{
|
{
|
||||||
JsonContext *context = static_cast<JsonContext *>(ctx);
|
auto *context = static_cast<JsonContext *>(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context->Push(new Dictionary());
|
context->Push(new Dictionary());
|
||||||
@ -276,7 +272,7 @@ static int DecodeStartMap(void *ctx)
|
|||||||
|
|
||||||
static int DecodeEndMapOrArray(void *ctx)
|
static int DecodeEndMapOrArray(void *ctx)
|
||||||
{
|
{
|
||||||
JsonContext *context = static_cast<JsonContext *>(ctx);
|
auto *context = static_cast<JsonContext *>(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context->AddValue(context->Pop().EValue);
|
context->AddValue(context->Pop().EValue);
|
||||||
@ -290,7 +286,7 @@ static int DecodeEndMapOrArray(void *ctx)
|
|||||||
|
|
||||||
static int DecodeStartArray(void *ctx)
|
static int DecodeStartArray(void *ctx)
|
||||||
{
|
{
|
||||||
JsonContext *context = static_cast<JsonContext *>(ctx);
|
auto *context = static_cast<JsonContext *>(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context->Push(new Array());
|
context->Push(new Array());
|
||||||
|
@ -36,7 +36,7 @@ typedef HMODULE LibraryHandle;
|
|||||||
class Library
|
class Library
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Library(void) = default;
|
Library() = default;
|
||||||
Library(const String& name);
|
Library(const String& name);
|
||||||
|
|
||||||
void *GetSymbolAddress(const String& name) const;
|
void *GetSymbolAddress(const String& name) const;
|
||||||
|
@ -24,13 +24,13 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& Loader::GetDeferredInitializers(void)
|
boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& Loader::GetDeferredInitializers()
|
||||||
{
|
{
|
||||||
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> > initializers;
|
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> > initializers;
|
||||||
return initializers;
|
return initializers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loader::ExecuteDeferredInitializers(void)
|
void Loader::ExecuteDeferredInitializers()
|
||||||
{
|
{
|
||||||
if (!GetDeferredInitializers().get())
|
if (!GetDeferredInitializers().get())
|
||||||
return;
|
return;
|
||||||
@ -42,7 +42,7 @@ void Loader::ExecuteDeferredInitializers(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loader::AddDeferredInitializer(const std::function<void(void)>& callback, int priority)
|
void Loader::AddDeferredInitializer(const std::function<void()>& callback, int priority)
|
||||||
{
|
{
|
||||||
if (!GetDeferredInitializers().get())
|
if (!GetDeferredInitializers().get())
|
||||||
GetDeferredInitializers().reset(new std::priority_queue<DeferredInitializer>());
|
GetDeferredInitializers().reset(new std::priority_queue<DeferredInitializer>());
|
||||||
|
@ -31,8 +31,8 @@ namespace icinga
|
|||||||
struct DeferredInitializer
|
struct DeferredInitializer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeferredInitializer(const std::function<void (void)>& callback, int priority)
|
DeferredInitializer(std::function<void ()> callback, int priority)
|
||||||
: m_Callback(callback), m_Priority(priority)
|
: m_Callback(std::move(callback)), m_Priority(priority)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool operator<(const DeferredInitializer& other) const
|
bool operator<(const DeferredInitializer& other) const
|
||||||
@ -40,13 +40,13 @@ public:
|
|||||||
return m_Priority < other.m_Priority;
|
return m_Priority < other.m_Priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(void)
|
void operator()()
|
||||||
{
|
{
|
||||||
m_Callback();
|
m_Callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::function<void (void)> m_Callback;
|
std::function<void ()> m_Callback;
|
||||||
int m_Priority;
|
int m_Priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,13 +58,13 @@ private:
|
|||||||
class Loader
|
class Loader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void AddDeferredInitializer(const std::function<void(void)>& callback, int priority = 0);
|
static void AddDeferredInitializer(const std::function<void ()>& callback, int priority = 0);
|
||||||
static void ExecuteDeferredInitializers(void);
|
static void ExecuteDeferredInitializers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Loader(void);
|
Loader();
|
||||||
|
|
||||||
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& GetDeferredInitializers(void);
|
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& GetDeferredInitializers();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ void Logger::Stop(bool runtimeRemoved)
|
|||||||
ObjectImpl<Logger>::Stop(runtimeRemoved);
|
ObjectImpl<Logger>::Stop(runtimeRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<Logger::Ptr> Logger::GetLoggers(void)
|
std::set<Logger::Ptr> Logger::GetLoggers()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
return m_Loggers;
|
return m_Loggers;
|
||||||
@ -88,7 +88,7 @@ std::set<Logger::Ptr> Logger::GetLoggers(void)
|
|||||||
*
|
*
|
||||||
* @returns The minimum severity.
|
* @returns The minimum severity.
|
||||||
*/
|
*/
|
||||||
LogSeverity Logger::GetMinSeverity(void) const
|
LogSeverity Logger::GetMinSeverity() const
|
||||||
{
|
{
|
||||||
String severity = GetSeverity();
|
String severity = GetSeverity();
|
||||||
if (severity.IsEmpty())
|
if (severity.IsEmpty())
|
||||||
@ -148,17 +148,17 @@ LogSeverity Logger::StringToSeverity(const String& severity)
|
|||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::DisableConsoleLog(void)
|
void Logger::DisableConsoleLog()
|
||||||
{
|
{
|
||||||
m_ConsoleLogEnabled = false;
|
m_ConsoleLogEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::EnableConsoleLog(void)
|
void Logger::EnableConsoleLog()
|
||||||
{
|
{
|
||||||
m_ConsoleLogEnabled = true;
|
m_ConsoleLogEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Logger::IsConsoleLogEnabled(void)
|
bool Logger::IsConsoleLogEnabled()
|
||||||
{
|
{
|
||||||
return m_ConsoleLogEnabled;
|
return m_ConsoleLogEnabled;
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ void Logger::SetConsoleLogSeverity(LogSeverity logSeverity)
|
|||||||
m_ConsoleLogSeverity = logSeverity;
|
m_ConsoleLogSeverity = logSeverity;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogSeverity Logger::GetConsoleLogSeverity(void)
|
LogSeverity Logger::GetConsoleLogSeverity()
|
||||||
{
|
{
|
||||||
return m_ConsoleLogSeverity;
|
return m_ConsoleLogSeverity;
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ void Logger::DisableTimestamp(bool disable)
|
|||||||
m_TimestampEnabled = !disable;
|
m_TimestampEnabled = !disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Logger::IsTimestampEnabled(void)
|
bool Logger::IsTimestampEnabled()
|
||||||
{
|
{
|
||||||
return m_TimestampEnabled;
|
return m_TimestampEnabled;
|
||||||
}
|
}
|
||||||
@ -194,20 +194,20 @@ void Logger::ValidateSeverity(const String& value, const ValidationUtils& utils)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::Log(LogSeverity severity, const String& facility, const String& message)
|
Log::Log(LogSeverity severity, String facility, const String& message)
|
||||||
: m_Severity(severity), m_Facility(facility)
|
: m_Severity(severity), m_Facility(std::move(facility))
|
||||||
{
|
{
|
||||||
m_Buffer << message;
|
m_Buffer << message;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::Log(LogSeverity severity, const String& facility)
|
Log::Log(LogSeverity severity, String facility)
|
||||||
: m_Severity(severity), m_Facility(facility)
|
: m_Severity(severity), m_Facility(std::move(facility))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the message to the application's log.
|
* Writes the message to the application's log.
|
||||||
*/
|
*/
|
||||||
Log::~Log(void)
|
Log::~Log()
|
||||||
{
|
{
|
||||||
LogEntry entry;
|
LogEntry entry;
|
||||||
entry.Timestamp = Utility::GetTime();
|
entry.Timestamp = Utility::GetTime();
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
static String SeverityToString(LogSeverity severity);
|
static String SeverityToString(LogSeverity severity);
|
||||||
static LogSeverity StringToSeverity(const String& severity);
|
static LogSeverity StringToSeverity(const String& severity);
|
||||||
|
|
||||||
LogSeverity GetMinSeverity(void) const;
|
LogSeverity GetMinSeverity() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the log entry and writes it to the log that is
|
* Processes the log entry and writes it to the log that is
|
||||||
@ -77,24 +77,24 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void ProcessLogEntry(const LogEntry& entry) = 0;
|
virtual void ProcessLogEntry(const LogEntry& entry) = 0;
|
||||||
|
|
||||||
virtual void Flush(void) = 0;
|
virtual void Flush() = 0;
|
||||||
|
|
||||||
static std::set<Logger::Ptr> GetLoggers(void);
|
static std::set<Logger::Ptr> GetLoggers();
|
||||||
|
|
||||||
static void DisableConsoleLog(void);
|
static void DisableConsoleLog();
|
||||||
static void EnableConsoleLog(void);
|
static void EnableConsoleLog();
|
||||||
static bool IsConsoleLogEnabled(void);
|
static bool IsConsoleLogEnabled();
|
||||||
static void DisableTimestamp(bool);
|
static void DisableTimestamp(bool);
|
||||||
static bool IsTimestampEnabled(void);
|
static bool IsTimestampEnabled();
|
||||||
|
|
||||||
static void SetConsoleLogSeverity(LogSeverity logSeverity);
|
static void SetConsoleLogSeverity(LogSeverity logSeverity);
|
||||||
static LogSeverity GetConsoleLogSeverity(void);
|
static LogSeverity GetConsoleLogSeverity();
|
||||||
|
|
||||||
virtual void ValidateSeverity(const String& value, const ValidationUtils& utils) override final;
|
void ValidateSeverity(const String& value, const ValidationUtils& utils) final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Start(bool runtimeCreated) override;
|
void Start(bool runtimeCreated) override;
|
||||||
virtual void Stop(bool runtimeRemoved) override;
|
void Stop(bool runtimeRemoved) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static boost::mutex m_Mutex;
|
static boost::mutex m_Mutex;
|
||||||
@ -107,14 +107,14 @@ private:
|
|||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Log(void) = delete;
|
Log() = delete;
|
||||||
Log(const Log& other) = delete;
|
Log(const Log& other) = delete;
|
||||||
Log& operator=(const Log& rhs) = delete;
|
Log& operator=(const Log& rhs) = delete;
|
||||||
|
|
||||||
Log(LogSeverity severity, const String& facility, const String& message);
|
Log(LogSeverity severity, String facility, const String& message);
|
||||||
Log(LogSeverity severity, const String& facility);
|
Log(LogSeverity severity, String facility);
|
||||||
|
|
||||||
~Log(void);
|
~Log();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Log& operator<<(const T& val)
|
Log& operator<<(const T& val)
|
||||||
|
@ -112,7 +112,7 @@ static double MathPow(double x, double y)
|
|||||||
return std::pow(x, y);
|
return std::pow(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double MathRandom(void)
|
static double MathRandom()
|
||||||
{
|
{
|
||||||
return (double)std::rand() / RAND_MAX;
|
return (double)std::rand() / RAND_MAX;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
static void WriteStringToStream(std::ostream& stream, const String& message);
|
static void WriteStringToStream(std::ostream& stream, const String& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetString(void);
|
NetString();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
NetworkStream::NetworkStream(const Socket::Ptr& socket)
|
NetworkStream::NetworkStream(Socket::Ptr socket)
|
||||||
: m_Socket(socket), m_Eof(false)
|
: m_Socket(std::move(socket)), m_Eof(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void NetworkStream::Close(void)
|
void NetworkStream::Close()
|
||||||
{
|
{
|
||||||
Stream::Close();
|
Stream::Close();
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ void NetworkStream::Write(const void *buffer, size_t count)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkStream::IsEof(void) const
|
bool NetworkStream::IsEof() const
|
||||||
{
|
{
|
||||||
return m_Eof;
|
return m_Eof;
|
||||||
}
|
}
|
||||||
|
@ -37,14 +37,14 @@ class NetworkStream final : public Stream
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(NetworkStream);
|
DECLARE_PTR_TYPEDEFS(NetworkStream);
|
||||||
|
|
||||||
NetworkStream(const Socket::Ptr& socket);
|
NetworkStream(Socket::Ptr socket);
|
||||||
|
|
||||||
virtual size_t Read(void *buffer, size_t count, bool allow_partial = false) override;
|
size_t Read(void *buffer, size_t count, bool allow_partial = false) override;
|
||||||
virtual void Write(const void *buffer, size_t count) override;
|
void Write(const void *buffer, size_t count) override;
|
||||||
|
|
||||||
virtual void Close(void) override;
|
void Close() override;
|
||||||
|
|
||||||
virtual bool IsEof(void) const override;
|
bool IsEof() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Socket::Ptr m_Socket;
|
Socket::Ptr m_Socket;
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static String NumberToString(void)
|
static String NumberToString()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
return vframe->Self;
|
return vframe->Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr Number::GetPrototype(void)
|
Object::Ptr Number::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@ class Value;
|
|||||||
class Number
|
class Number
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Number(void);
|
Number();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static String ObjectToString(void)
|
static String ObjectToString()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
|
Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
|
||||||
@ -39,14 +39,14 @@ static void ObjectNotifyAttribute(const String& attribute)
|
|||||||
self->NotifyField(self->GetReflectionType()->GetFieldId(attribute));
|
self->NotifyField(self->GetReflectionType()->GetFieldId(attribute));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Object::Ptr ObjectClone(void)
|
static Object::Ptr ObjectClone()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
|
Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
|
||||||
return self->Clone();
|
return self->Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr Object::GetPrototype(void)
|
Object::Ptr Object::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -38,20 +38,10 @@ static std::map<String, int> l_ObjectCounts;
|
|||||||
static Timer::Ptr l_ObjectCountTimer;
|
static Timer::Ptr l_ObjectCountTimer;
|
||||||
#endif /* I2_LEAK_DEBUG */
|
#endif /* I2_LEAK_DEBUG */
|
||||||
|
|
||||||
/**
|
|
||||||
* Default constructor for the Object class.
|
|
||||||
*/
|
|
||||||
Object::Object(void)
|
|
||||||
: m_References(0), m_Mutex(0)
|
|
||||||
#ifdef I2_DEBUG
|
|
||||||
, m_LockOwner(0)
|
|
||||||
#endif /* I2_DEBUG */
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor for the Object class.
|
* Destructor for the Object class.
|
||||||
*/
|
*/
|
||||||
Object::~Object(void)
|
Object::~Object()
|
||||||
{
|
{
|
||||||
delete reinterpret_cast<boost::recursive_mutex *>(m_Mutex);
|
delete reinterpret_cast<boost::recursive_mutex *>(m_Mutex);
|
||||||
}
|
}
|
||||||
@ -59,7 +49,7 @@ Object::~Object(void)
|
|||||||
/**
|
/**
|
||||||
* Returns a string representation for the object.
|
* Returns a string representation for the object.
|
||||||
*/
|
*/
|
||||||
String Object::ToString(void) const
|
String Object::ToString() const
|
||||||
{
|
{
|
||||||
return "Object of type '" + GetReflectionType()->GetName() + "'";
|
return "Object of type '" + GetReflectionType()->GetName() + "'";
|
||||||
}
|
}
|
||||||
@ -70,7 +60,7 @@ String Object::ToString(void) const
|
|||||||
*
|
*
|
||||||
* @returns True if the calling thread owns the lock, false otherwise.
|
* @returns True if the calling thread owns the lock, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool Object::OwnsLock(void) const
|
bool Object::OwnsLock() const
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD tid = InterlockedExchangeAdd(&m_LockOwner, 0);
|
DWORD tid = InterlockedExchangeAdd(&m_LockOwner, 0);
|
||||||
@ -193,12 +183,12 @@ Object::Ptr Object::NavigateField(int id) const
|
|||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr Object::Clone(void) const
|
Object::Ptr Object::Clone() const
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Object cannot be cloned."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Object cannot be cloned."));
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr Object::GetReflectionType(void) const
|
Type::Ptr Object::GetReflectionType() const
|
||||||
{
|
{
|
||||||
return Object::TypeInstance;
|
return Object::TypeInstance;
|
||||||
}
|
}
|
||||||
@ -238,7 +228,7 @@ void icinga::TypeRemoveObject(Object *object)
|
|||||||
l_ObjectCounts[typeName]--;
|
l_ObjectCounts[typeName]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TypeInfoTimerHandler(void)
|
static void TypeInfoTimerHandler()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(l_ObjectCountLock);
|
boost::mutex::scoped_lock lock(l_ObjectCountLock);
|
||||||
|
|
||||||
@ -262,3 +252,35 @@ INITIALIZE_ONCE([]() {
|
|||||||
});
|
});
|
||||||
#endif /* I2_LEAK_DEBUG */
|
#endif /* I2_LEAK_DEBUG */
|
||||||
|
|
||||||
|
void icinga::intrusive_ptr_add_ref(Object *object)
|
||||||
|
{
|
||||||
|
#ifdef I2_LEAK_DEBUG
|
||||||
|
if (object->m_References == 0)
|
||||||
|
TypeAddObject(object);
|
||||||
|
#endif /* I2_LEAK_DEBUG */
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
InterlockedIncrement(&object->m_References);
|
||||||
|
#else /* _WIN32 */
|
||||||
|
__sync_add_and_fetch(&object->m_References, 1);
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
}
|
||||||
|
|
||||||
|
void icinga::intrusive_ptr_release(Object *object)
|
||||||
|
{
|
||||||
|
uintptr_t refs;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
refs = InterlockedDecrement(&object->m_References);
|
||||||
|
#else /* _WIN32 */
|
||||||
|
refs = __sync_sub_and_fetch(&object->m_References, 1);
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
if (unlikely(refs == 0)) {
|
||||||
|
#ifdef I2_LEAK_DEBUG
|
||||||
|
TypeRemoveObject(object);
|
||||||
|
#endif /* I2_LEAK_DEBUG */
|
||||||
|
|
||||||
|
delete object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -49,7 +49,7 @@ extern Value Empty;
|
|||||||
|
|
||||||
#define IMPL_TYPE_LOOKUP() \
|
#define IMPL_TYPE_LOOKUP() \
|
||||||
static intrusive_ptr<Type> TypeInstance; \
|
static intrusive_ptr<Type> TypeInstance; \
|
||||||
virtual intrusive_ptr<Type> GetReflectionType(void) const override \
|
virtual intrusive_ptr<Type> GetReflectionType() const override \
|
||||||
{ \
|
{ \
|
||||||
return TypeInstance; \
|
return TypeInstance; \
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ struct TypeHelper
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct TypeHelper<T, false>
|
struct TypeHelper<T, false>
|
||||||
{
|
{
|
||||||
static ObjectFactory GetFactory(void)
|
static ObjectFactory GetFactory()
|
||||||
{
|
{
|
||||||
return DefaultObjectFactory<T>;
|
return DefaultObjectFactory<T>;
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ struct TypeHelper<T, false>
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct TypeHelper<T, true>
|
struct TypeHelper<T, true>
|
||||||
{
|
{
|
||||||
static ObjectFactory GetFactory(void)
|
static ObjectFactory GetFactory()
|
||||||
{
|
{
|
||||||
return DefaultObjectFactoryVA<T>;
|
return DefaultObjectFactoryVA<T>;
|
||||||
}
|
}
|
||||||
@ -109,12 +109,12 @@ class Object
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(Object);
|
DECLARE_PTR_TYPEDEFS(Object);
|
||||||
|
|
||||||
Object(void);
|
Object() = default;
|
||||||
virtual ~Object(void);
|
virtual ~Object();
|
||||||
|
|
||||||
virtual String ToString(void) const;
|
virtual String ToString() const;
|
||||||
|
|
||||||
virtual intrusive_ptr<Type> GetReflectionType(void) const;
|
virtual intrusive_ptr<Type> GetReflectionType() const;
|
||||||
|
|
||||||
virtual void Validate(int types, const ValidationUtils& utils);
|
virtual void Validate(int types, const ValidationUtils& utils);
|
||||||
|
|
||||||
@ -129,21 +129,21 @@ public:
|
|||||||
virtual Object::Ptr NavigateField(int id) const;
|
virtual Object::Ptr NavigateField(int id) const;
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
bool OwnsLock(void) const;
|
bool OwnsLock() const;
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
static Object::Ptr GetPrototype(void);
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
virtual Object::Ptr Clone(void) const;
|
virtual Object::Ptr Clone() const;
|
||||||
|
|
||||||
static intrusive_ptr<Type> TypeInstance;
|
static intrusive_ptr<Type> TypeInstance;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Object(const Object& other);
|
Object(const Object& other) = delete;
|
||||||
Object& operator=(const Object& rhs);
|
Object& operator=(const Object& rhs) = delete;
|
||||||
|
|
||||||
uintptr_t m_References;
|
uintptr_t m_References{0};
|
||||||
mutable uintptr_t m_Mutex;
|
mutable uintptr_t m_Mutex{0};
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
# ifndef _WIN32
|
# ifndef _WIN32
|
||||||
@ -164,38 +164,8 @@ Value GetPrototypeField(const Value& context, const String& field, bool not_foun
|
|||||||
void TypeAddObject(Object *object);
|
void TypeAddObject(Object *object);
|
||||||
void TypeRemoveObject(Object *object);
|
void TypeRemoveObject(Object *object);
|
||||||
|
|
||||||
inline void intrusive_ptr_add_ref(Object *object)
|
void intrusive_ptr_add_ref(Object *object);
|
||||||
{
|
void intrusive_ptr_release(Object *object);
|
||||||
#ifdef I2_LEAK_DEBUG
|
|
||||||
if (object->m_References == 0)
|
|
||||||
TypeAddObject(object);
|
|
||||||
#endif /* I2_LEAK_DEBUG */
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
InterlockedIncrement(&object->m_References);
|
|
||||||
#else /* _WIN32 */
|
|
||||||
__sync_add_and_fetch(&object->m_References, 1);
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void intrusive_ptr_release(Object *object)
|
|
||||||
{
|
|
||||||
uintptr_t refs;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
refs = InterlockedDecrement(&object->m_References);
|
|
||||||
#else /* _WIN32 */
|
|
||||||
refs = __sync_sub_and_fetch(&object->m_References, 1);
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
if (unlikely(refs == 0)) {
|
|
||||||
#ifdef I2_LEAK_DEBUG
|
|
||||||
TypeRemoveObject(object);
|
|
||||||
#endif /* I2_LEAK_DEBUG */
|
|
||||||
|
|
||||||
delete object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ObjectImpl
|
class ObjectImpl
|
||||||
|
@ -25,11 +25,7 @@ using namespace icinga;
|
|||||||
#define I2MUTEX_UNLOCKED 0
|
#define I2MUTEX_UNLOCKED 0
|
||||||
#define I2MUTEX_LOCKED 1
|
#define I2MUTEX_LOCKED 1
|
||||||
|
|
||||||
ObjectLock::ObjectLock(void)
|
ObjectLock::~ObjectLock()
|
||||||
: m_Object(nullptr), m_Locked(false)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
ObjectLock::~ObjectLock(void)
|
|
||||||
{
|
{
|
||||||
Unlock();
|
Unlock();
|
||||||
}
|
}
|
||||||
@ -62,7 +58,7 @@ void ObjectLock::LockMutex(const Object *object)
|
|||||||
while (likely(!__sync_bool_compare_and_swap(&object->m_Mutex, I2MUTEX_UNLOCKED, I2MUTEX_LOCKED))) {
|
while (likely(!__sync_bool_compare_and_swap(&object->m_Mutex, I2MUTEX_UNLOCKED, I2MUTEX_LOCKED))) {
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
if (likely(object->m_Mutex > I2MUTEX_LOCKED)) {
|
if (likely(object->m_Mutex > I2MUTEX_LOCKED)) {
|
||||||
boost::recursive_mutex *mtx = reinterpret_cast<boost::recursive_mutex *>(object->m_Mutex);
|
auto *mtx = reinterpret_cast<boost::recursive_mutex *>(object->m_Mutex);
|
||||||
mtx->lock();
|
mtx->lock();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -72,7 +68,7 @@ void ObjectLock::LockMutex(const Object *object)
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::recursive_mutex *mtx = new boost::recursive_mutex();
|
auto *mtx = new boost::recursive_mutex();
|
||||||
mtx->lock();
|
mtx->lock();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifdef _WIN64
|
# ifdef _WIN64
|
||||||
@ -85,7 +81,7 @@ void ObjectLock::LockMutex(const Object *object)
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectLock::Lock(void)
|
void ObjectLock::Lock()
|
||||||
{
|
{
|
||||||
ASSERT(!m_Locked && m_Object);
|
ASSERT(!m_Locked && m_Object);
|
||||||
|
|
||||||
@ -121,7 +117,7 @@ void ObjectLock::Spin(unsigned int it)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectLock::Unlock(void)
|
void ObjectLock::Unlock()
|
||||||
{
|
{
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
if (m_Locked) {
|
if (m_Locked) {
|
||||||
|
@ -31,23 +31,22 @@ namespace icinga
|
|||||||
struct ObjectLock
|
struct ObjectLock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectLock(void);
|
|
||||||
ObjectLock(const Object::Ptr& object);
|
ObjectLock(const Object::Ptr& object);
|
||||||
ObjectLock(const Object *object);
|
ObjectLock(const Object *object);
|
||||||
|
|
||||||
~ObjectLock(void);
|
~ObjectLock();
|
||||||
|
|
||||||
static void LockMutex(const Object *object);
|
static void LockMutex(const Object *object);
|
||||||
|
|
||||||
void Lock(void);
|
void Lock();
|
||||||
|
|
||||||
static void Spin(unsigned int it);
|
static void Spin(unsigned int it);
|
||||||
|
|
||||||
void Unlock(void);
|
void Unlock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Object *m_Object;
|
const Object *m_Object{nullptr};
|
||||||
bool m_Locked;
|
bool m_Locked{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,20 +29,17 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
|||||||
Object::TypeInstance = type;
|
Object::TypeInstance = type;
|
||||||
}, 20);
|
}, 20);
|
||||||
|
|
||||||
ObjectType::ObjectType(void)
|
String ObjectType::GetName() const
|
||||||
{ }
|
|
||||||
|
|
||||||
String ObjectType::GetName(void) const
|
|
||||||
{
|
{
|
||||||
return "Object";
|
return "Object";
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr ObjectType::GetBaseType(void) const
|
Type::Ptr ObjectType::GetBaseType() const
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectType::GetAttributes(void) const
|
int ObjectType::GetAttributes() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -58,17 +55,17 @@ int ObjectType::GetFieldId(const String& name) const
|
|||||||
Field ObjectType::GetFieldInfo(int id) const
|
Field ObjectType::GetFieldInfo(int id) const
|
||||||
{
|
{
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
return Field(1, "String", "type", nullptr, nullptr, 0, 0);
|
return {1, "String", "type", nullptr, nullptr, 0, 0};
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectType::GetFieldCount(void) const
|
int ObjectType::GetFieldCount() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectFactory ObjectType::GetFactory(void) const
|
ObjectFactory ObjectType::GetFactory() const
|
||||||
{
|
{
|
||||||
return DefaultObjectFactory<Object>;
|
return DefaultObjectFactory<Object>;
|
||||||
}
|
}
|
||||||
|
@ -30,17 +30,15 @@ namespace icinga
|
|||||||
class ObjectType final : public Type
|
class ObjectType final : public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectType(void);
|
String GetName() const override;
|
||||||
|
Type::Ptr GetBaseType() const override;
|
||||||
virtual String GetName(void) const override;
|
int GetAttributes() const override;
|
||||||
virtual Type::Ptr GetBaseType(void) const override;
|
int GetFieldId(const String& name) const override;
|
||||||
virtual int GetAttributes(void) const override;
|
Field GetFieldInfo(int id) const override;
|
||||||
virtual int GetFieldId(const String& name) const override;
|
int GetFieldCount() const override;
|
||||||
virtual Field GetFieldInfo(int id) const override;
|
|
||||||
virtual int GetFieldCount(void) const override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ObjectFactory GetFactory(void) const override;
|
ObjectFactory GetFactory() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,7 @@ using namespace icinga;
|
|||||||
REGISTER_TYPE(PerfdataValue);
|
REGISTER_TYPE(PerfdataValue);
|
||||||
REGISTER_SCRIPTFUNCTION_NS(System, parse_performance_data, PerfdataValue::Parse, "perfdata");
|
REGISTER_SCRIPTFUNCTION_NS(System, parse_performance_data, PerfdataValue::Parse, "perfdata");
|
||||||
|
|
||||||
PerfdataValue::PerfdataValue(void)
|
PerfdataValue::PerfdataValue(const String& label, double value, bool counter,
|
||||||
{ }
|
|
||||||
|
|
||||||
PerfdataValue::PerfdataValue(String label, double value, bool counter,
|
|
||||||
const String& unit, const Value& warn, const Value& crit, const Value& min,
|
const String& unit, const Value& warn, const Value& crit, const Value& min,
|
||||||
const Value& max)
|
const Value& max)
|
||||||
{
|
{
|
||||||
@ -139,7 +136,7 @@ PerfdataValue::Ptr PerfdataValue::Parse(const String& perfdata)
|
|||||||
return new PerfdataValue(label, value, counter, unit, warn, crit, min, max);
|
return new PerfdataValue(label, value, counter, unit, warn, crit, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
String PerfdataValue::Format(void) const
|
String PerfdataValue::Format() const
|
||||||
{
|
{
|
||||||
std::ostringstream result;
|
std::ostringstream result;
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ class PerfdataValue final : public ObjectImpl<PerfdataValue>
|
|||||||
public:
|
public:
|
||||||
DECLARE_OBJECT(PerfdataValue);
|
DECLARE_OBJECT(PerfdataValue);
|
||||||
|
|
||||||
PerfdataValue(void);
|
PerfdataValue() = default;
|
||||||
|
|
||||||
PerfdataValue(String label, double value, bool counter = false, const String& unit = "",
|
PerfdataValue(const String& label, double value, bool counter = false, const String& unit = "",
|
||||||
const Value& warn = Empty, const Value& crit = Empty,
|
const Value& warn = Empty, const Value& crit = Empty,
|
||||||
const Value& min = Empty, const Value& max = Empty);
|
const Value& min = Empty, const Value& max = Empty);
|
||||||
|
|
||||||
static PerfdataValue::Ptr Parse(const String& perfdata);
|
static PerfdataValue::Ptr Parse(const String& perfdata);
|
||||||
String Format(void) const;
|
String Format() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Value ParseWarnCritMinMaxToken(const std::vector<String>& tokens,
|
static Value ParseWarnCritMinMaxToken(const std::vector<String>& tokens,
|
||||||
|
@ -22,16 +22,16 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
PrimitiveType::PrimitiveType(const String& name, const String& base, const ObjectFactory& factory)
|
PrimitiveType::PrimitiveType(String name, String base, const ObjectFactory& factory)
|
||||||
: m_Name(name), m_Base(base), m_Factory(factory)
|
: m_Name(std::move(name)), m_Base(std::move(base)), m_Factory(factory)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
String PrimitiveType::GetName(void) const
|
String PrimitiveType::GetName() const
|
||||||
{
|
{
|
||||||
return m_Name;
|
return m_Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr PrimitiveType::GetBaseType(void) const
|
Type::Ptr PrimitiveType::GetBaseType() const
|
||||||
{
|
{
|
||||||
if (m_Base == "None")
|
if (m_Base == "None")
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -39,7 +39,7 @@ Type::Ptr PrimitiveType::GetBaseType(void) const
|
|||||||
return Type::GetByName(m_Base);
|
return Type::GetByName(m_Base);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PrimitiveType::GetAttributes(void) const
|
int PrimitiveType::GetAttributes() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ Field PrimitiveType::GetFieldInfo(int id) const
|
|||||||
throw std::runtime_error("Invalid field ID.");
|
throw std::runtime_error("Invalid field ID.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int PrimitiveType::GetFieldCount(void) const
|
int PrimitiveType::GetFieldCount() const
|
||||||
{
|
{
|
||||||
Type::Ptr base = GetBaseType();
|
Type::Ptr base = GetBaseType();
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ int PrimitiveType::GetFieldCount(void) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectFactory PrimitiveType::GetFactory(void) const
|
ObjectFactory PrimitiveType::GetFactory() const
|
||||||
{
|
{
|
||||||
return m_Factory;
|
return m_Factory;
|
||||||
}
|
}
|
||||||
|
@ -30,17 +30,17 @@ namespace icinga
|
|||||||
class PrimitiveType final : public Type
|
class PrimitiveType final : public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PrimitiveType(const String& name, const String& base, const ObjectFactory& factory = ObjectFactory());
|
PrimitiveType(String name, String base, const ObjectFactory& factory = ObjectFactory());
|
||||||
|
|
||||||
virtual String GetName(void) const override;
|
String GetName() const override;
|
||||||
virtual Type::Ptr GetBaseType(void) const override;
|
Type::Ptr GetBaseType() const override;
|
||||||
virtual int GetAttributes(void) const override;
|
int GetAttributes() const override;
|
||||||
virtual int GetFieldId(const String& name) const override;
|
int GetFieldId(const String& name) const override;
|
||||||
virtual Field GetFieldInfo(int id) const override;
|
Field GetFieldInfo(int id) const override;
|
||||||
virtual int GetFieldCount(void) const override;
|
int GetFieldCount() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ObjectFactory GetFactory(void) const override;
|
ObjectFactory GetFactory() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_Name;
|
String m_Name;
|
||||||
|
@ -65,8 +65,8 @@ static pid_t l_ProcessControlPID;
|
|||||||
static boost::once_flag l_ProcessOnceFlag = BOOST_ONCE_INIT;
|
static boost::once_flag l_ProcessOnceFlag = BOOST_ONCE_INIT;
|
||||||
static boost::once_flag l_SpawnHelperOnceFlag = BOOST_ONCE_INIT;
|
static boost::once_flag l_SpawnHelperOnceFlag = BOOST_ONCE_INIT;
|
||||||
|
|
||||||
Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& extraEnvironment)
|
Process::Process(Process::Arguments arguments, Dictionary::Ptr extraEnvironment)
|
||||||
: m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment), m_Timeout(600), m_AdjustPriority(false)
|
: m_Arguments(std::move(arguments)), m_ExtraEnvironment(std::move(extraEnvironment)), m_Timeout(600), m_AdjustPriority(false)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
, m_ReadPending(false), m_ReadFailed(false), m_Overlapped()
|
, m_ReadPending(false), m_ReadFailed(false), m_Overlapped()
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
@ -76,7 +76,7 @@ Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& ext
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
Process::~Process(void)
|
Process::~Process()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
CloseHandle(m_Overlapped.hEvent);
|
CloseHandle(m_Overlapped.hEvent);
|
||||||
@ -93,14 +93,14 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques
|
|||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
int *fds = (int *)CMSG_DATA(cmsg);
|
auto *fds = (int *)CMSG_DATA(cmsg);
|
||||||
|
|
||||||
Array::Ptr arguments = request->Get("arguments");
|
Array::Ptr arguments = request->Get("arguments");
|
||||||
Dictionary::Ptr extraEnvironment = request->Get("extraEnvironment");
|
Dictionary::Ptr extraEnvironment = request->Get("extraEnvironment");
|
||||||
bool adjustPriority = request->Get("adjustPriority");
|
bool adjustPriority = request->Get("adjustPriority");
|
||||||
|
|
||||||
// build argv
|
// build argv
|
||||||
char **argv = new char *[arguments->GetLength() + 1];
|
auto **argv = new char *[arguments->GetLength() + 1];
|
||||||
|
|
||||||
for (unsigned int i = 0; i < arguments->GetLength(); i++) {
|
for (unsigned int i = 0; i < arguments->GetLength(); i++) {
|
||||||
String arg = arguments->Get(i);
|
String arg = arguments->Get(i);
|
||||||
@ -116,7 +116,7 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques
|
|||||||
while (environ[envc])
|
while (environ[envc])
|
||||||
envc++;
|
envc++;
|
||||||
|
|
||||||
char **envp = new char *[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 2];
|
auto **envp = new char *[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 2];
|
||||||
|
|
||||||
for (int i = 0; i < envc; i++)
|
for (int i = 0; i < envc; i++)
|
||||||
envp[i] = strdup(environ[i]);
|
envp[i] = strdup(environ[i]);
|
||||||
@ -237,7 +237,7 @@ static Value ProcessWaitPIDImpl(struct msghdr *msgh, const Dictionary::Ptr& requ
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessHandler(void)
|
static void ProcessHandler()
|
||||||
{
|
{
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
sigfillset(&mask);
|
sigfillset(&mask);
|
||||||
@ -281,7 +281,7 @@ static void ProcessHandler(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *mbuf = new char[length];
|
auto *mbuf = new char[length];
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
while (count < length) {
|
while (count < length) {
|
||||||
@ -333,7 +333,7 @@ static void ProcessHandler(void)
|
|||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StartSpawnProcessHelper(void)
|
static void StartSpawnProcessHelper()
|
||||||
{
|
{
|
||||||
if (l_ProcessControlFD != -1) {
|
if (l_ProcessControlFD != -1) {
|
||||||
(void)close(l_ProcessControlFD);
|
(void)close(l_ProcessControlFD);
|
||||||
@ -497,31 +497,33 @@ send_message:
|
|||||||
return response->Get("rc");
|
return response->Get("rc");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::InitializeSpawnHelper(void)
|
void Process::InitializeSpawnHelper()
|
||||||
{
|
{
|
||||||
if (l_ProcessControlFD == -1)
|
if (l_ProcessControlFD == -1)
|
||||||
StartSpawnProcessHelper();
|
StartSpawnProcessHelper();
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
static void InitializeProcess(void)
|
static void InitializeProcess()
|
||||||
{
|
{
|
||||||
for (int tid = 0; tid < IOTHREADS; tid++) {
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
l_Events[tid] = CreateEvent(nullptr, TRUE, FALSE, nullptr);
|
for (auto& event : l_Events) {
|
||||||
|
event = CreateEvent(nullptr, TRUE, FALSE, nullptr);
|
||||||
|
}
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
for (auto& eventFD : l_EventFDs) {
|
||||||
# ifdef HAVE_PIPE2
|
# ifdef HAVE_PIPE2
|
||||||
if (pipe2(l_EventFDs[tid], O_CLOEXEC) < 0) {
|
if (pipe2(eventFD, O_CLOEXEC) < 0) {
|
||||||
if (errno == ENOSYS) {
|
if (errno == ENOSYS) {
|
||||||
# endif /* HAVE_PIPE2 */
|
# endif /* HAVE_PIPE2 */
|
||||||
if (pipe(l_EventFDs[tid]) < 0) {
|
if (pipe(eventFD) < 0) {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
<< boost::errinfo_api_function("pipe")
|
<< boost::errinfo_api_function("pipe")
|
||||||
<< boost::errinfo_errno(errno));
|
<< boost::errinfo_errno(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
Utility::SetCloExec(l_EventFDs[tid][0]);
|
Utility::SetCloExec(eventFD[0]);
|
||||||
Utility::SetCloExec(l_EventFDs[tid][1]);
|
Utility::SetCloExec(eventFD[1]);
|
||||||
# ifdef HAVE_PIPE2
|
# ifdef HAVE_PIPE2
|
||||||
} else {
|
} else {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
@ -530,13 +532,13 @@ static void InitializeProcess(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif /* HAVE_PIPE2 */
|
# endif /* HAVE_PIPE2 */
|
||||||
#endif /* _WIN32 */
|
|
||||||
}
|
}
|
||||||
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
INITIALIZE_ONCE(InitializeProcess);
|
INITIALIZE_ONCE(InitializeProcess);
|
||||||
|
|
||||||
void Process::ThreadInitialize(void)
|
void Process::ThreadInitialize()
|
||||||
{
|
{
|
||||||
/* Note to self: Make sure this runs _after_ we've daemonized. */
|
/* Note to self: Make sure this runs _after_ we've daemonized. */
|
||||||
for (int tid = 0; tid < IOTHREADS; tid++) {
|
for (int tid = 0; tid < IOTHREADS; tid++) {
|
||||||
@ -583,7 +585,7 @@ void Process::SetTimeout(double timeout)
|
|||||||
m_Timeout = timeout;
|
m_Timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Process::GetTimeout(void) const
|
double Process::GetTimeout() const
|
||||||
{
|
{
|
||||||
return m_Timeout;
|
return m_Timeout;
|
||||||
}
|
}
|
||||||
@ -593,7 +595,7 @@ void Process::SetAdjustPriority(bool adjust)
|
|||||||
m_AdjustPriority = adjust;
|
m_AdjustPriority = adjust;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Process::GetAdjustPriority(void) const
|
bool Process::GetAdjustPriority() const
|
||||||
{
|
{
|
||||||
return m_AdjustPriority;
|
return m_AdjustPriority;
|
||||||
}
|
}
|
||||||
@ -1016,7 +1018,7 @@ void Process::Run(const std::function<void(const ProcessResult&)>& callback)
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Process::DoEvents(void)
|
bool Process::DoEvents()
|
||||||
{
|
{
|
||||||
bool is_timeout = false;
|
bool is_timeout = false;
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -1134,13 +1136,13 @@ bool Process::DoEvents(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t Process::GetPID(void) const
|
pid_t Process::GetPID() const
|
||||||
{
|
{
|
||||||
return m_PID;
|
return m_PID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Process::GetTID(void) const
|
int Process::GetTID() const
|
||||||
{
|
{
|
||||||
return (reinterpret_cast<uintptr_t>(this) / sizeof(void *)) % IOTHREADS;
|
return (reinterpret_cast<uintptr_t>(this) / sizeof(void *)) % IOTHREADS;
|
||||||
}
|
}
|
||||||
|
@ -66,27 +66,27 @@ public:
|
|||||||
|
|
||||||
static const std::deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
|
static const std::deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
|
||||||
|
|
||||||
Process(const Arguments& arguments, const Dictionary::Ptr& extraEnvironment = nullptr);
|
Process(Arguments arguments, Dictionary::Ptr extraEnvironment = nullptr);
|
||||||
~Process(void);
|
~Process() override;
|
||||||
|
|
||||||
void SetTimeout(double timeout);
|
void SetTimeout(double timeout);
|
||||||
double GetTimeout(void) const;
|
double GetTimeout() const;
|
||||||
|
|
||||||
void SetAdjustPriority(bool adjust);
|
void SetAdjustPriority(bool adjust);
|
||||||
bool GetAdjustPriority(void) const;
|
bool GetAdjustPriority() const;
|
||||||
|
|
||||||
void Run(const std::function<void (const ProcessResult&)>& callback = std::function<void (const ProcessResult&)>());
|
void Run(const std::function<void (const ProcessResult&)>& callback = std::function<void (const ProcessResult&)>());
|
||||||
|
|
||||||
pid_t GetPID(void) const;
|
pid_t GetPID() const;
|
||||||
|
|
||||||
static Arguments PrepareCommand(const Value& command);
|
static Arguments PrepareCommand(const Value& command);
|
||||||
|
|
||||||
static void ThreadInitialize(void);
|
static void ThreadInitialize();
|
||||||
|
|
||||||
static String PrettyPrintArguments(const Arguments& arguments);
|
static String PrettyPrintArguments(const Arguments& arguments);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static void InitializeSpawnHelper(void);
|
static void InitializeSpawnHelper();
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -112,8 +112,8 @@ private:
|
|||||||
ProcessResult m_Result;
|
ProcessResult m_Result;
|
||||||
|
|
||||||
static void IOThreadProc(int tid);
|
static void IOThreadProc(int tid);
|
||||||
bool DoEvents(void);
|
bool DoEvents();
|
||||||
int GetTID(void) const;
|
int GetTID() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
OnUnregistered(name);
|
OnUnregistered(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear(void)
|
void Clear()
|
||||||
{
|
{
|
||||||
typename Registry<U, T>::ItemMap items;
|
typename Registry<U, T>::ItemMap items;
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ public:
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMap GetItems(void) const
|
ItemMap GetItems() const
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ RingBuffer::RingBuffer(RingBuffer::SizeType slots)
|
|||||||
: Object(), m_Slots(slots, 0), m_TimeValue(0), m_InsertedValues(0)
|
: Object(), m_Slots(slots, 0), m_TimeValue(0), m_InsertedValues(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
RingBuffer::SizeType RingBuffer::GetLength(void) const
|
RingBuffer::SizeType RingBuffer::GetLength() const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
RingBuffer(SizeType slots);
|
RingBuffer(SizeType slots);
|
||||||
|
|
||||||
SizeType GetLength(void) const;
|
SizeType GetLength() const;
|
||||||
void InsertValue(SizeType tv, int num);
|
void InsertValue(SizeType tv, int num);
|
||||||
int UpdateAndGetValues(SizeType tv, SizeType span);
|
int UpdateAndGetValues(SizeType tv, SizeType span);
|
||||||
double CalculateRate(SizeType tv, SizeType span);
|
double CalculateRate(SizeType tv, SizeType span);
|
||||||
|
@ -46,13 +46,13 @@ ScriptFrame::ScriptFrame(bool allocLocals)
|
|||||||
InitializeFrame();
|
InitializeFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFrame::ScriptFrame(bool allocLocals, const Value& self)
|
ScriptFrame::ScriptFrame(bool allocLocals, Value self)
|
||||||
: Locals(allocLocals ? new Dictionary() : nullptr), Self(self), Sandboxed(false), Depth(0)
|
: Locals(allocLocals ? new Dictionary() : nullptr), Self(std::move(self)), Sandboxed(false), Depth(0)
|
||||||
{
|
{
|
||||||
InitializeFrame();
|
InitializeFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptFrame::InitializeFrame(void)
|
void ScriptFrame::InitializeFrame()
|
||||||
{
|
{
|
||||||
std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
|
std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
|
||||||
|
|
||||||
@ -65,13 +65,13 @@ void ScriptFrame::InitializeFrame(void)
|
|||||||
PushFrame(this);
|
PushFrame(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFrame::~ScriptFrame(void)
|
ScriptFrame::~ScriptFrame()
|
||||||
{
|
{
|
||||||
ScriptFrame *frame = PopFrame();
|
ScriptFrame *frame = PopFrame();
|
||||||
ASSERT(frame == this);
|
ASSERT(frame == this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptFrame::IncreaseStackDepth(void)
|
void ScriptFrame::IncreaseStackDepth()
|
||||||
{
|
{
|
||||||
if (Depth + 1 > 300)
|
if (Depth + 1 > 300)
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Stack overflow while evaluating expression: Recursion level too deep."));
|
BOOST_THROW_EXCEPTION(ScriptError("Stack overflow while evaluating expression: Recursion level too deep."));
|
||||||
@ -79,12 +79,12 @@ void ScriptFrame::IncreaseStackDepth(void)
|
|||||||
Depth++;
|
Depth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptFrame::DecreaseStackDepth(void)
|
void ScriptFrame::DecreaseStackDepth()
|
||||||
{
|
{
|
||||||
Depth--;
|
Depth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFrame *ScriptFrame::GetCurrentFrame(void)
|
ScriptFrame *ScriptFrame::GetCurrentFrame()
|
||||||
{
|
{
|
||||||
std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
|
std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ ScriptFrame *ScriptFrame::GetCurrentFrame(void)
|
|||||||
return frames->top();
|
return frames->top();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFrame *ScriptFrame::PopFrame(void)
|
ScriptFrame *ScriptFrame::PopFrame()
|
||||||
{
|
{
|
||||||
std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
|
std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ void ScriptFrame::PushFrame(ScriptFrame *frame)
|
|||||||
frames->push(frame);
|
frames->push(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Ptr ScriptFrame::GetImports(void)
|
Array::Ptr ScriptFrame::GetImports()
|
||||||
{
|
{
|
||||||
return m_Imports;
|
return m_Imports;
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,15 @@ struct ScriptFrame
|
|||||||
int Depth;
|
int Depth;
|
||||||
|
|
||||||
ScriptFrame(bool allocLocals);
|
ScriptFrame(bool allocLocals);
|
||||||
ScriptFrame(bool allocLocals, const Value& self);
|
ScriptFrame(bool allocLocals, Value self);
|
||||||
~ScriptFrame(void);
|
~ScriptFrame();
|
||||||
|
|
||||||
void IncreaseStackDepth(void);
|
void IncreaseStackDepth();
|
||||||
void DecreaseStackDepth(void);
|
void DecreaseStackDepth();
|
||||||
|
|
||||||
static ScriptFrame *GetCurrentFrame(void);
|
static ScriptFrame *GetCurrentFrame();
|
||||||
|
|
||||||
static Array::Ptr GetImports(void);
|
static Array::Ptr GetImports();
|
||||||
static void AddImport(const Object::Ptr& import);
|
static void AddImport(const Object::Ptr& import);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -53,9 +53,9 @@ private:
|
|||||||
static Array::Ptr m_Imports;
|
static Array::Ptr m_Imports;
|
||||||
|
|
||||||
static void PushFrame(ScriptFrame *frame);
|
static void PushFrame(ScriptFrame *frame);
|
||||||
static ScriptFrame *PopFrame(void);
|
static ScriptFrame *PopFrame();
|
||||||
|
|
||||||
void InitializeFrame(void);
|
void InitializeFrame();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ bool ScriptGlobal::Exists(const String& name)
|
|||||||
return m_Globals->Contains(name);
|
return m_Globals->Contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr ScriptGlobal::GetGlobals(void)
|
Dictionary::Ptr ScriptGlobal::GetGlobals()
|
||||||
{
|
{
|
||||||
return m_Globals;
|
return m_Globals;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
|
|
||||||
static void WriteToFile(const String& filename);
|
static void WriteToFile(const String& filename);
|
||||||
|
|
||||||
static Dictionary::Ptr GetGlobals(void);
|
static Dictionary::Ptr GetGlobals();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Dictionary::Ptr m_Globals;
|
static Dictionary::Ptr m_Globals;
|
||||||
|
@ -81,7 +81,7 @@ enum MatchType
|
|||||||
MatchAny
|
MatchAny
|
||||||
};
|
};
|
||||||
|
|
||||||
void ScriptUtils::StaticInitialize(void)
|
void ScriptUtils::StaticInitialize()
|
||||||
{
|
{
|
||||||
ScriptGlobal::Set("MatchAll", MatchAll);
|
ScriptGlobal::Set("MatchAll", MatchAll);
|
||||||
ScriptGlobal::Set("MatchAny", MatchAny);
|
ScriptGlobal::Set("MatchAny", MatchAny);
|
||||||
@ -310,7 +310,7 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
|
|||||||
Array::SizeType len;
|
Array::SizeType len;
|
||||||
{
|
{
|
||||||
ObjectLock olock(arr1), xlock(arr2), ylock(result);
|
ObjectLock olock(arr1), xlock(arr2), ylock(result);
|
||||||
Array::Iterator it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin());
|
auto it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin());
|
||||||
len = it - result->Begin();
|
len = it - result->Begin();
|
||||||
}
|
}
|
||||||
result->Resize(len);
|
result->Resize(len);
|
||||||
@ -334,7 +334,7 @@ void ScriptUtils::Log(const std::vector<Value>& arguments)
|
|||||||
facility = "config";
|
facility = "config";
|
||||||
message = arguments[0];
|
message = arguments[0];
|
||||||
} else {
|
} else {
|
||||||
int sval = static_cast<int>(arguments[0]);
|
auto sval = static_cast<int>(arguments[0]);
|
||||||
severity = static_cast<LogSeverity>(sval);
|
severity = static_cast<LogSeverity>(sval);
|
||||||
facility = arguments[1];
|
facility = arguments[1];
|
||||||
message = arguments[2];
|
message = arguments[2];
|
||||||
@ -410,7 +410,7 @@ ConfigObject::Ptr ScriptUtils::GetObject(const Value& vtype, const String& name)
|
|||||||
else
|
else
|
||||||
ptype = Type::GetByName(vtype);
|
ptype = Type::GetByName(vtype);
|
||||||
|
|
||||||
ConfigType *ctype = dynamic_cast<ConfigType *>(ptype.get());
|
auto *ctype = dynamic_cast<ConfigType *>(ptype.get());
|
||||||
|
|
||||||
if (!ctype)
|
if (!ctype)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -423,7 +423,7 @@ Array::Ptr ScriptUtils::GetObjects(const Type::Ptr& type)
|
|||||||
if (!type)
|
if (!type)
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: Must not be null"));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: Must not be null"));
|
||||||
|
|
||||||
ConfigType *ctype = dynamic_cast<ConfigType *>(type.get());
|
auto *ctype = dynamic_cast<ConfigType *>(type.get());
|
||||||
|
|
||||||
if (!ctype)
|
if (!ctype)
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: Type must inherit from 'ConfigObject'"));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: Type must inherit from 'ConfigObject'"));
|
||||||
|
@ -36,7 +36,7 @@ namespace icinga
|
|||||||
class ScriptUtils
|
class ScriptUtils
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void StaticInitialize(void);
|
static void StaticInitialize();
|
||||||
static String CastString(const Value& value);
|
static String CastString(const Value& value);
|
||||||
static double CastNumber(const Value& value);
|
static double CastNumber(const Value& value);
|
||||||
static bool CastBool(const Value& value);
|
static bool CastBool(const Value& value);
|
||||||
@ -60,7 +60,7 @@ public:
|
|||||||
static Value GlobRecursive(const std::vector<Value>& args);
|
static Value GlobRecursive(const std::vector<Value>& args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScriptUtils(void);
|
ScriptUtils();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ template<typename T>
|
|||||||
class Singleton
|
class Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static T *GetInstance(void)
|
static T *GetInstance()
|
||||||
{
|
{
|
||||||
/* FIXME: This relies on static initializers being atomic. */
|
/* FIXME: This relies on static initializers being atomic. */
|
||||||
static boost::mutex mutex;
|
static boost::mutex mutex;
|
||||||
|
@ -34,18 +34,10 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the Socket class.
|
|
||||||
*/
|
|
||||||
Socket::Socket(void)
|
|
||||||
: m_FD(INVALID_SOCKET)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the Socket class.
|
* Constructor for the Socket class.
|
||||||
*/
|
*/
|
||||||
Socket::Socket(SOCKET fd)
|
Socket::Socket(SOCKET fd)
|
||||||
: m_FD(INVALID_SOCKET)
|
|
||||||
{
|
{
|
||||||
SetFD(fd);
|
SetFD(fd);
|
||||||
}
|
}
|
||||||
@ -53,7 +45,7 @@ Socket::Socket(SOCKET fd)
|
|||||||
/**
|
/**
|
||||||
* Destructor for the Socket class.
|
* Destructor for the Socket class.
|
||||||
*/
|
*/
|
||||||
Socket::~Socket(void)
|
Socket::~Socket()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
@ -81,7 +73,7 @@ void Socket::SetFD(SOCKET fd)
|
|||||||
*
|
*
|
||||||
* @returns The file descriptor.
|
* @returns The file descriptor.
|
||||||
*/
|
*/
|
||||||
SOCKET Socket::GetFD(void) const
|
SOCKET Socket::GetFD() const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -91,7 +83,7 @@ SOCKET Socket::GetFD(void) const
|
|||||||
/**
|
/**
|
||||||
* Closes the socket.
|
* Closes the socket.
|
||||||
*/
|
*/
|
||||||
void Socket::Close(void)
|
void Socket::Close()
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -106,7 +98,7 @@ void Socket::Close(void)
|
|||||||
*
|
*
|
||||||
* @returns An error code.
|
* @returns An error code.
|
||||||
*/
|
*/
|
||||||
int Socket::GetError(void) const
|
int Socket::GetError() const
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
socklen_t optlen = sizeof(opt);
|
socklen_t optlen = sizeof(opt);
|
||||||
@ -158,7 +150,7 @@ String Socket::GetAddressFromSockaddr(sockaddr *address, socklen_t len)
|
|||||||
*
|
*
|
||||||
* @returns A String describing the local address.
|
* @returns A String describing the local address.
|
||||||
*/
|
*/
|
||||||
String Socket::GetClientAddress(void)
|
String Socket::GetClientAddress()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_SocketMutex);
|
boost::mutex::scoped_lock lock(m_SocketMutex);
|
||||||
|
|
||||||
@ -198,7 +190,7 @@ String Socket::GetClientAddress(void)
|
|||||||
*
|
*
|
||||||
* @returns A String describing the peer address.
|
* @returns A String describing the peer address.
|
||||||
*/
|
*/
|
||||||
String Socket::GetPeerAddress(void)
|
String Socket::GetPeerAddress()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_SocketMutex);
|
boost::mutex::scoped_lock lock(m_SocketMutex);
|
||||||
|
|
||||||
@ -236,7 +228,7 @@ String Socket::GetPeerAddress(void)
|
|||||||
/**
|
/**
|
||||||
* Starts listening for incoming client connections.
|
* Starts listening for incoming client connections.
|
||||||
*/
|
*/
|
||||||
void Socket::Listen(void)
|
void Socket::Listen()
|
||||||
{
|
{
|
||||||
if (listen(GetFD(), SOMAXCONN) < 0) {
|
if (listen(GetFD(), SOMAXCONN) < 0) {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -328,7 +320,7 @@ size_t Socket::Read(void *buffer, size_t count)
|
|||||||
/**
|
/**
|
||||||
* Accepts a new client and creates a new client object for it.
|
* Accepts a new client and creates a new client object for it.
|
||||||
*/
|
*/
|
||||||
Socket::Ptr Socket::Accept(void)
|
Socket::Ptr Socket::Accept()
|
||||||
{
|
{
|
||||||
sockaddr_storage addr;
|
sockaddr_storage addr;
|
||||||
socklen_t addrlen = sizeof(addr);
|
socklen_t addrlen = sizeof(addr);
|
||||||
@ -407,7 +399,7 @@ bool Socket::Poll(bool read, bool write, struct timeval *timeout)
|
|||||||
return (rc != 0);
|
return (rc != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::MakeNonBlocking(void)
|
void Socket::MakeNonBlocking()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Utility::SetNonBlockingSocket(GetFD());
|
Utility::SetNonBlockingSocket(GetFD());
|
||||||
|
@ -36,38 +36,38 @@ class Socket : public Object
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(Socket);
|
DECLARE_PTR_TYPEDEFS(Socket);
|
||||||
|
|
||||||
Socket(void);
|
Socket() = default;
|
||||||
Socket(SOCKET fd);
|
Socket(SOCKET fd);
|
||||||
~Socket(void);
|
~Socket() override;
|
||||||
|
|
||||||
SOCKET GetFD(void) const;
|
SOCKET GetFD() const;
|
||||||
|
|
||||||
void Close(void);
|
void Close();
|
||||||
|
|
||||||
String GetClientAddress(void);
|
String GetClientAddress();
|
||||||
String GetPeerAddress(void);
|
String GetPeerAddress();
|
||||||
|
|
||||||
size_t Read(void *buffer, size_t size);
|
size_t Read(void *buffer, size_t size);
|
||||||
size_t Write(const void *buffer, size_t size);
|
size_t Write(const void *buffer, size_t size);
|
||||||
|
|
||||||
void Listen(void);
|
void Listen();
|
||||||
Socket::Ptr Accept(void);
|
Socket::Ptr Accept();
|
||||||
|
|
||||||
bool Poll(bool read, bool write, struct timeval *timeout = nullptr);
|
bool Poll(bool read, bool write, struct timeval *timeout = nullptr);
|
||||||
|
|
||||||
void MakeNonBlocking(void);
|
void MakeNonBlocking();
|
||||||
|
|
||||||
static void SocketPair(SOCKET s[2]);
|
static void SocketPair(SOCKET s[2]);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetFD(SOCKET fd);
|
void SetFD(SOCKET fd);
|
||||||
|
|
||||||
int GetError(void) const;
|
int GetError() const;
|
||||||
|
|
||||||
mutable boost::mutex m_SocketMutex;
|
mutable boost::mutex m_SocketMutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SOCKET m_FD; /**< The socket descriptor. */
|
SOCKET m_FD{INVALID_SOCKET}; /**< The socket descriptor. */
|
||||||
|
|
||||||
static String GetAddressFromSockaddr(sockaddr *address, socklen_t len);
|
static String GetAddressFromSockaddr(sockaddr *address, socklen_t len);
|
||||||
};
|
};
|
||||||
|
@ -35,7 +35,7 @@ static SocketEventEngine *l_SocketIOEngine;
|
|||||||
|
|
||||||
int SocketEvents::m_NextID = 0;
|
int SocketEvents::m_NextID = 0;
|
||||||
|
|
||||||
void SocketEventEngine::Start(void)
|
void SocketEventEngine::Start()
|
||||||
{
|
{
|
||||||
for (int tid = 0; tid < SOCKET_IOTHREADS; tid++) {
|
for (int tid = 0; tid < SOCKET_IOTHREADS; tid++) {
|
||||||
Socket::SocketPair(m_EventFDs[tid]);
|
Socket::SocketPair(m_EventFDs[tid]);
|
||||||
@ -77,7 +77,7 @@ void SocketEventEngine::WakeUpThread(int sid, bool wait)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketEvents::InitializeEngine(void)
|
void SocketEvents::InitializeEngine()
|
||||||
{
|
{
|
||||||
String eventEngine = ScriptGlobal::Get("EventEngine", &Empty);
|
String eventEngine = ScriptGlobal::Get("EventEngine", &Empty);
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ SocketEvents::SocketEvents(const Socket::Ptr& socket, Object *lifesupportObject)
|
|||||||
Register(lifesupportObject);
|
Register(lifesupportObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketEvents::~SocketEvents(void)
|
SocketEvents::~SocketEvents()
|
||||||
{
|
{
|
||||||
VERIFY(m_FD == INVALID_SOCKET);
|
VERIFY(m_FD == INVALID_SOCKET);
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ void SocketEvents::Register(Object *lifesupportObject)
|
|||||||
l_SocketIOEngine->Register(this, lifesupportObject);
|
l_SocketIOEngine->Register(this, lifesupportObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketEvents::Unregister(void)
|
void SocketEvents::Unregister()
|
||||||
{
|
{
|
||||||
l_SocketIOEngine->Unregister(this);
|
l_SocketIOEngine->Unregister(this);
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ boost::mutex& SocketEventEngine::GetMutex(int tid)
|
|||||||
return m_EventMutex[tid];
|
return m_EventMutex[tid];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEvents::IsHandlingEvents(void) const
|
bool SocketEvents::IsHandlingEvents() const
|
||||||
{
|
{
|
||||||
int tid = m_ID % SOCKET_IOTHREADS;
|
int tid = m_ID % SOCKET_IOTHREADS;
|
||||||
boost::mutex::scoped_lock lock(l_SocketIOEngine->GetMutex(tid));
|
boost::mutex::scoped_lock lock(l_SocketIOEngine->GetMutex(tid));
|
||||||
|
@ -39,17 +39,17 @@ namespace icinga
|
|||||||
class SocketEvents
|
class SocketEvents
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~SocketEvents(void);
|
~SocketEvents();
|
||||||
|
|
||||||
virtual void OnEvent(int revents);
|
virtual void OnEvent(int revents);
|
||||||
|
|
||||||
void Unregister(void);
|
void Unregister();
|
||||||
|
|
||||||
void ChangeEvents(int events);
|
void ChangeEvents(int events);
|
||||||
|
|
||||||
bool IsHandlingEvents(void) const;
|
bool IsHandlingEvents() const;
|
||||||
|
|
||||||
void *GetEnginePrivate(void) const;
|
void *GetEnginePrivate() const;
|
||||||
void SetEnginePrivate(void *priv);
|
void SetEnginePrivate(void *priv);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -63,7 +63,7 @@ private:
|
|||||||
|
|
||||||
static int m_NextID;
|
static int m_NextID;
|
||||||
|
|
||||||
static void InitializeEngine(void);
|
static void InitializeEngine();
|
||||||
|
|
||||||
void WakeUpThread(bool wait = false);
|
void WakeUpThread(bool wait = false);
|
||||||
|
|
||||||
@ -77,13 +77,9 @@ private:
|
|||||||
|
|
||||||
struct SocketEventDescriptor
|
struct SocketEventDescriptor
|
||||||
{
|
{
|
||||||
int Events;
|
int Events{POLLIN};
|
||||||
SocketEvents *EventInterface;
|
SocketEvents *EventInterface{nullptr};
|
||||||
Object *LifesupportObject;
|
Object *LifesupportObject{nullptr};
|
||||||
|
|
||||||
SocketEventDescriptor(void)
|
|
||||||
: Events(POLLIN), EventInterface(nullptr), LifesupportObject(nullptr)
|
|
||||||
{ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EventDescription
|
struct EventDescription
|
||||||
@ -96,7 +92,7 @@ struct EventDescription
|
|||||||
class SocketEventEngine
|
class SocketEventEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Start(void);
|
void Start();
|
||||||
|
|
||||||
void WakeUpThread(int sid, bool wait);
|
void WakeUpThread(int sid, bool wait);
|
||||||
|
|
||||||
@ -122,13 +118,13 @@ protected:
|
|||||||
class SocketEventEnginePoll final : public SocketEventEngine
|
class SocketEventEnginePoll final : public SocketEventEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void Register(SocketEvents *se, Object *lifesupportObject);
|
void Register(SocketEvents *se, Object *lifesupportObject) override;
|
||||||
virtual void Unregister(SocketEvents *se);
|
void Unregister(SocketEvents *se) override;
|
||||||
virtual void ChangeEvents(SocketEvents *se, int events);
|
void ChangeEvents(SocketEvents *se, int events) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InitializeThread(int tid);
|
void InitializeThread(int tid) override;
|
||||||
virtual void ThreadProc(int tid);
|
void ThreadProc(int tid) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
@ -31,7 +31,7 @@ using namespace icinga;
|
|||||||
# pragma optimize("", off)
|
# pragma optimize("", off)
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
StackTrace::StackTrace(void)
|
StackTrace::StackTrace()
|
||||||
{
|
{
|
||||||
#ifdef HAVE_BACKTRACE_SYMBOLS
|
#ifdef HAVE_BACKTRACE_SYMBOLS
|
||||||
m_Count = backtrace(m_Frames, sizeof(m_Frames) / sizeof(m_Frames[0]));
|
m_Count = backtrace(m_Frames, sizeof(m_Frames) / sizeof(m_Frames[0]));
|
||||||
|
@ -34,14 +34,14 @@ namespace icinga
|
|||||||
class StackTrace
|
class StackTrace
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StackTrace(void);
|
StackTrace();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
explicit StackTrace(PEXCEPTION_POINTERS exi);
|
explicit StackTrace(PEXCEPTION_POINTERS exi);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
void Print(std::ostream& fp, int ignoreFrames = 0) const;
|
void Print(std::ostream& fp, int ignoreFrames = 0) const;
|
||||||
|
|
||||||
static void StaticInitialize(void);
|
static void StaticInitialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *m_Frames[64];
|
void *m_Frames[64];
|
||||||
|
@ -33,7 +33,7 @@ StdioStream::StdioStream(std::iostream *innerStream, bool ownsStream)
|
|||||||
: m_InnerStream(innerStream), m_OwnsStream(ownsStream)
|
: m_InnerStream(innerStream), m_OwnsStream(ownsStream)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
StdioStream::~StdioStream(void)
|
StdioStream::~StdioStream()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ void StdioStream::Write(const void *buffer, size_t size)
|
|||||||
m_InnerStream->write(static_cast<const char *>(buffer), size);
|
m_InnerStream->write(static_cast<const char *>(buffer), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StdioStream::Close(void)
|
void StdioStream::Close()
|
||||||
{
|
{
|
||||||
Stream::Close();
|
Stream::Close();
|
||||||
|
|
||||||
@ -63,12 +63,12 @@ void StdioStream::Close(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StdioStream::IsDataAvailable(void) const
|
bool StdioStream::IsDataAvailable() const
|
||||||
{
|
{
|
||||||
return !IsEof();
|
return !IsEof();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StdioStream::IsEof(void) const
|
bool StdioStream::IsEof() const
|
||||||
{
|
{
|
||||||
return !m_InnerStream->good();
|
return !m_InnerStream->good();
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,15 @@ public:
|
|||||||
DECLARE_PTR_TYPEDEFS(StdioStream);
|
DECLARE_PTR_TYPEDEFS(StdioStream);
|
||||||
|
|
||||||
StdioStream(std::iostream *innerStream, bool ownsStream);
|
StdioStream(std::iostream *innerStream, bool ownsStream);
|
||||||
~StdioStream(void);
|
~StdioStream() override;
|
||||||
|
|
||||||
virtual size_t Read(void *buffer, size_t size, bool allow_partial = false) override;
|
size_t Read(void *buffer, size_t size, bool allow_partial = false) override;
|
||||||
virtual void Write(const void *buffer, size_t size) override;
|
void Write(const void *buffer, size_t size) override;
|
||||||
|
|
||||||
virtual void Close(void) override;
|
void Close() override;
|
||||||
|
|
||||||
virtual bool IsDataAvailable(void) const override;
|
bool IsDataAvailable() const override;
|
||||||
virtual bool IsEof(void) const override;
|
bool IsEof() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::iostream *m_InnerStream;
|
std::iostream *m_InnerStream;
|
||||||
|
@ -30,17 +30,17 @@ void Stream::RegisterDataHandler(const std::function<void(const Stream::Ptr&)>&
|
|||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support waiting."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support waiting."));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stream::SupportsWaiting(void) const
|
bool Stream::SupportsWaiting() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stream::IsDataAvailable(void) const
|
bool Stream::IsDataAvailable() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::Shutdown(void)
|
void Stream::Shutdown()
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support Shutdown()."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support Shutdown()."));
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ size_t Stream::Peek(void *buffer, size_t count, bool allow_partial)
|
|||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support Peek()."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support Peek()."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::SignalDataAvailable(void)
|
void Stream::SignalDataAvailable()
|
||||||
{
|
{
|
||||||
OnDataAvailable(this);
|
OnDataAvailable(this);
|
||||||
|
|
||||||
@ -76,10 +76,10 @@ bool Stream::WaitForData(int timeout)
|
|||||||
return IsDataAvailable() || IsEof();
|
return IsDataAvailable() || IsEof();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StreamDummyCallback(void)
|
static void StreamDummyCallback()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void Stream::Close(void)
|
void Stream::Close()
|
||||||
{
|
{
|
||||||
OnDataAvailable.disconnect_all_slots();
|
OnDataAvailable.disconnect_all_slots();
|
||||||
|
|
||||||
|
@ -38,11 +38,7 @@ enum ConnectionRole
|
|||||||
|
|
||||||
struct StreamReadContext
|
struct StreamReadContext
|
||||||
{
|
{
|
||||||
StreamReadContext(void)
|
~StreamReadContext()
|
||||||
: Buffer(nullptr), Size(0), MustRead(true), Eof(false)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
~StreamReadContext(void)
|
|
||||||
{
|
{
|
||||||
free(Buffer);
|
free(Buffer);
|
||||||
}
|
}
|
||||||
@ -50,10 +46,10 @@ struct StreamReadContext
|
|||||||
bool FillFromStream(const intrusive_ptr<Stream>& stream, bool may_wait);
|
bool FillFromStream(const intrusive_ptr<Stream>& stream, bool may_wait);
|
||||||
void DropData(size_t count);
|
void DropData(size_t count);
|
||||||
|
|
||||||
char *Buffer;
|
char *Buffer{nullptr};
|
||||||
size_t Size;
|
size_t Size{0};
|
||||||
bool MustRead;
|
bool MustRead{true};
|
||||||
bool Eof;
|
bool Eof{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
enum StreamReadStatus
|
enum StreamReadStatus
|
||||||
@ -108,35 +104,35 @@ public:
|
|||||||
* Causes the stream to be closed (via Close()) once all pending data has been
|
* Causes the stream to be closed (via Close()) once all pending data has been
|
||||||
* written.
|
* written.
|
||||||
*/
|
*/
|
||||||
virtual void Shutdown(void);
|
virtual void Shutdown();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the stream and releases resources.
|
* Closes the stream and releases resources.
|
||||||
*/
|
*/
|
||||||
virtual void Close(void);
|
virtual void Close();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether we've reached the end-of-file condition.
|
* Checks whether we've reached the end-of-file condition.
|
||||||
*
|
*
|
||||||
* @returns true if EOF.
|
* @returns true if EOF.
|
||||||
*/
|
*/
|
||||||
virtual bool IsEof(void) const = 0;
|
virtual bool IsEof() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits until data can be read from the stream.
|
* Waits until data can be read from the stream.
|
||||||
*/
|
*/
|
||||||
bool WaitForData(int timeout = -1);
|
bool WaitForData(int timeout = -1);
|
||||||
|
|
||||||
virtual bool SupportsWaiting(void) const;
|
virtual bool SupportsWaiting() const;
|
||||||
|
|
||||||
virtual bool IsDataAvailable(void) const;
|
virtual bool IsDataAvailable() const;
|
||||||
|
|
||||||
void RegisterDataHandler(const std::function<void(const Stream::Ptr&)>& handler);
|
void RegisterDataHandler(const std::function<void(const Stream::Ptr&)>& handler);
|
||||||
|
|
||||||
StreamReadStatus ReadLine(String *line, StreamReadContext& context, bool may_wait = false);
|
StreamReadStatus ReadLine(String *line, StreamReadContext& context, bool may_wait = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SignalDataAvailable(void);
|
void SignalDataAvailable();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::signals2::signal<void(const Stream::Ptr&)> OnDataAvailable;
|
boost::signals2::signal<void(const Stream::Ptr&)> OnDataAvailable;
|
||||||
|
@ -30,13 +30,6 @@ REGISTER_TYPE(StreamLogger);
|
|||||||
|
|
||||||
boost::mutex StreamLogger::m_Mutex;
|
boost::mutex StreamLogger::m_Mutex;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the StreamLogger class.
|
|
||||||
*/
|
|
||||||
StreamLogger::StreamLogger(void)
|
|
||||||
: m_Stream(nullptr), m_OwnsStream(false)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void StreamLogger::Stop(bool runtimeRemoved)
|
void StreamLogger::Stop(bool runtimeRemoved)
|
||||||
{
|
{
|
||||||
ObjectImpl<StreamLogger>::Stop(runtimeRemoved);
|
ObjectImpl<StreamLogger>::Stop(runtimeRemoved);
|
||||||
@ -49,7 +42,7 @@ void StreamLogger::Stop(bool runtimeRemoved)
|
|||||||
/**
|
/**
|
||||||
* Destructor for the StreamLogger class.
|
* Destructor for the StreamLogger class.
|
||||||
*/
|
*/
|
||||||
StreamLogger::~StreamLogger(void)
|
StreamLogger::~StreamLogger()
|
||||||
{
|
{
|
||||||
if (m_FlushLogTimer)
|
if (m_FlushLogTimer)
|
||||||
m_FlushLogTimer->Stop();
|
m_FlushLogTimer->Stop();
|
||||||
@ -58,12 +51,12 @@ StreamLogger::~StreamLogger(void)
|
|||||||
delete m_Stream;
|
delete m_Stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamLogger::FlushLogTimerHandler(void)
|
void StreamLogger::FlushLogTimerHandler()
|
||||||
{
|
{
|
||||||
Flush();
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamLogger::Flush(void)
|
void StreamLogger::Flush()
|
||||||
{
|
{
|
||||||
if (m_Stream)
|
if (m_Stream)
|
||||||
m_Stream->flush();
|
m_Stream->flush();
|
||||||
|
@ -38,27 +38,25 @@ class StreamLogger : public ObjectImpl<StreamLogger>
|
|||||||
public:
|
public:
|
||||||
DECLARE_OBJECT(StreamLogger);
|
DECLARE_OBJECT(StreamLogger);
|
||||||
|
|
||||||
StreamLogger(void);
|
void Stop(bool runtimeRemoved) override;
|
||||||
|
~StreamLogger() override;
|
||||||
virtual void Stop(bool runtimeRemoved) override;
|
|
||||||
~StreamLogger(void);
|
|
||||||
|
|
||||||
void BindStream(std::ostream *stream, bool ownsStream);
|
void BindStream(std::ostream *stream, bool ownsStream);
|
||||||
|
|
||||||
static void ProcessLogEntry(std::ostream& stream, const LogEntry& entry);
|
static void ProcessLogEntry(std::ostream& stream, const LogEntry& entry);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void ProcessLogEntry(const LogEntry& entry) override final;
|
void ProcessLogEntry(const LogEntry& entry) final;
|
||||||
virtual void Flush(void) override final;
|
void Flush() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static boost::mutex m_Mutex;
|
static boost::mutex m_Mutex;
|
||||||
std::ostream *m_Stream;
|
std::ostream *m_Stream{nullptr};
|
||||||
bool m_OwnsStream;
|
bool m_OwnsStream{false};
|
||||||
|
|
||||||
Timer::Ptr m_FlushLogTimer;
|
Timer::Ptr m_FlushLogTimer;
|
||||||
|
|
||||||
void FlushLogTimerHandler(void);
|
void FlushLogTimerHandler();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,14 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static int StringLen(void)
|
static int StringLen()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
String self = vframe->Self;
|
String self = vframe->Self;
|
||||||
return self.GetLength();
|
return self.GetLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String StringToString(void)
|
static String StringToString()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
return vframe->Self;
|
return vframe->Self;
|
||||||
@ -57,14 +57,14 @@ static String StringSubstr(const std::vector<Value>& args)
|
|||||||
return self.SubStr(args[0]);
|
return self.SubStr(args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String StringUpper(void)
|
static String StringUpper()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
String self = vframe->Self;
|
String self = vframe->Self;
|
||||||
return boost::to_upper_copy(self);
|
return boost::to_upper_copy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String StringLower(void)
|
static String StringLower()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
String self = vframe->Self;
|
String self = vframe->Self;
|
||||||
@ -125,21 +125,21 @@ static Value StringReplace(const String& search, const String& replacement)
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String StringReverse(void)
|
static String StringReverse()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
String self = vframe->Self;
|
String self = vframe->Self;
|
||||||
return self.Reverse();
|
return self.Reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String StringTrim(void)
|
static String StringTrim()
|
||||||
{
|
{
|
||||||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||||
String self = vframe->Self;
|
String self = vframe->Self;
|
||||||
return self.Trim();
|
return self.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr String::GetPrototype(void)
|
Object::Ptr String::GetPrototype()
|
||||||
{
|
{
|
||||||
static Dictionary::Ptr prototype;
|
static Dictionary::Ptr prototype;
|
||||||
|
|
||||||
|
@ -31,19 +31,11 @@ REGISTER_BUILTIN_TYPE(String, String::GetPrototype());
|
|||||||
|
|
||||||
const String::SizeType String::NPos = std::string::npos;
|
const String::SizeType String::NPos = std::string::npos;
|
||||||
|
|
||||||
String::String(void)
|
|
||||||
: m_Data()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
String::String(const char *data)
|
String::String(const char *data)
|
||||||
: m_Data(data)
|
: m_Data(data)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
String::String(const std::string& data)
|
String::String(std::string data)
|
||||||
: m_Data(data)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
String::String(std::string&& data)
|
|
||||||
: m_Data(std::move(data))
|
: m_Data(std::move(data))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -66,9 +58,6 @@ String::String(Value&& other)
|
|||||||
}
|
}
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
String::~String(void)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
String& String::operator=(Value&& other)
|
String& String::operator=(Value&& other)
|
||||||
{
|
{
|
||||||
if (other.IsString())
|
if (other.IsString())
|
||||||
@ -137,7 +126,7 @@ String& String::operator+=(char rhs)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::IsEmpty(void) const
|
bool String::IsEmpty() const
|
||||||
{
|
{
|
||||||
return m_Data.empty();
|
return m_Data.empty();
|
||||||
}
|
}
|
||||||
@ -147,32 +136,32 @@ bool String::operator<(const String& rhs) const
|
|||||||
return m_Data < rhs.m_Data;
|
return m_Data < rhs.m_Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
String::operator const std::string&(void) const
|
String::operator const std::string&() const
|
||||||
{
|
{
|
||||||
return m_Data;
|
return m_Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *String::CStr(void) const
|
const char *String::CStr() const
|
||||||
{
|
{
|
||||||
return m_Data.c_str();
|
return m_Data.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::Clear(void)
|
void String::Clear()
|
||||||
{
|
{
|
||||||
m_Data.clear();
|
m_Data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::SizeType String::GetLength(void) const
|
String::SizeType String::GetLength() const
|
||||||
{
|
{
|
||||||
return m_Data.size();
|
return m_Data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string& String::GetData(void)
|
std::string& String::GetData()
|
||||||
{
|
{
|
||||||
return m_Data;
|
return m_Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& String::GetData(void) const
|
const std::string& String::GetData() const
|
||||||
{
|
{
|
||||||
return m_Data;
|
return m_Data;
|
||||||
}
|
}
|
||||||
@ -234,28 +223,28 @@ void String::Replace(String::SizeType first, String::SizeType second, const Stri
|
|||||||
m_Data.replace(first, second, str);
|
m_Data.replace(first, second, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::Trim(void) const
|
String String::Trim() const
|
||||||
{
|
{
|
||||||
String t = m_Data;
|
String t = m_Data;
|
||||||
boost::algorithm::trim(t);
|
boost::algorithm::trim(t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::ToLower(void) const
|
String String::ToLower() const
|
||||||
{
|
{
|
||||||
String t = m_Data;
|
String t = m_Data;
|
||||||
boost::algorithm::to_lower(t);
|
boost::algorithm::to_lower(t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::ToUpper(void) const
|
String String::ToUpper() const
|
||||||
{
|
{
|
||||||
String t = m_Data;
|
String t = m_Data;
|
||||||
boost::algorithm::to_upper(t);
|
boost::algorithm::to_upper(t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::Reverse(void) const
|
String String::Reverse() const
|
||||||
{
|
{
|
||||||
String t = m_Data;
|
String t = m_Data;
|
||||||
std::reverse(t.m_Data.begin(), t.m_Data.end());
|
std::reverse(t.m_Data.begin(), t.m_Data.end());
|
||||||
@ -282,42 +271,42 @@ String::Iterator String::erase(String::Iterator first, String::Iterator last)
|
|||||||
return m_Data.erase(first, last);
|
return m_Data.erase(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Iterator String::Begin(void)
|
String::Iterator String::Begin()
|
||||||
{
|
{
|
||||||
return m_Data.begin();
|
return m_Data.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::ConstIterator String::Begin(void) const
|
String::ConstIterator String::Begin() const
|
||||||
{
|
{
|
||||||
return m_Data.begin();
|
return m_Data.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Iterator String::End(void)
|
String::Iterator String::End()
|
||||||
{
|
{
|
||||||
return m_Data.end();
|
return m_Data.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::ConstIterator String::End(void) const
|
String::ConstIterator String::End() const
|
||||||
{
|
{
|
||||||
return m_Data.end();
|
return m_Data.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::ReverseIterator String::RBegin(void)
|
String::ReverseIterator String::RBegin()
|
||||||
{
|
{
|
||||||
return m_Data.rbegin();
|
return m_Data.rbegin();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::ConstReverseIterator String::RBegin(void) const
|
String::ConstReverseIterator String::RBegin() const
|
||||||
{
|
{
|
||||||
return m_Data.rbegin();
|
return m_Data.rbegin();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::ReverseIterator String::REnd(void)
|
String::ReverseIterator String::REnd()
|
||||||
{
|
{
|
||||||
return m_Data.rend();
|
return m_Data.rend();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::ConstReverseIterator String::REnd(void) const
|
String::ConstReverseIterator String::REnd() const
|
||||||
{
|
{
|
||||||
return m_Data.rend();
|
return m_Data.rend();
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user