Skip to content

Commit

Permalink
Refactor how variable scopes work
Browse files Browse the repository at this point in the history
refs #8074
  • Loading branch information
gunnarbeutner committed Dec 14, 2014
1 parent 461cf8d commit 1cb0231
Show file tree
Hide file tree
Showing 37 changed files with 415 additions and 771 deletions.
4 changes: 2 additions & 2 deletions icinga-app/icinga.cpp
Expand Up @@ -27,7 +27,7 @@
#include "base/utility.hpp"
#include "base/exception.hpp"
#include "base/convert.hpp"
#include "base/scriptvariable.hpp"
#include "base/scriptglobal.hpp"
#include "base/context.hpp"
#include "base/console.hpp"
#include "config.h"
Expand Down Expand Up @@ -227,7 +227,7 @@ int Main(void)
key = define;
value = "1";
}
ScriptVariable::Set(key, value);
ScriptGlobal::Set(key, value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/base/CMakeLists.txt
Expand Up @@ -27,8 +27,8 @@ set(base_SOURCES
convert.cpp debuginfo.cpp dictionary.cpp dictionary-script.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
exception.cpp fifo.cpp filelogger.cpp filelogger.thpp initialize.cpp json.cpp logger.cpp logger.thpp
netstring.cpp networkstream.cpp number.cpp number-script.cpp object.cpp object-script.cpp primitivetype.cpp process.cpp
ringbuffer.cpp scripterror.cpp scriptframe.cpp scriptfunction.cpp scriptfunctionwrapper.cpp scriptsignal.cpp
scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
ringbuffer.cpp scripterror.cpp scriptframe.cpp scriptfunction.cpp scriptfunctionwrapper.cpp scriptglobal.cpp
scriptutils.cpp serializer.cpp socket.cpp stacktrace.cpp
statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp string-script.cpp
sysloglogger.cpp sysloglogger.thpp tcpsocket.cpp thinmutex.cpp threadpool.cpp timer.cpp
tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp utility.cpp value.cpp
Expand Down
77 changes: 31 additions & 46 deletions lib/base/application.cpp
Expand Up @@ -27,7 +27,7 @@
#include "base/debug.hpp"
#include "base/type.hpp"
#include "base/convert.hpp"
#include "base/scriptvariable.hpp"
#include "base/scriptglobal.hpp"
#include "base/process.hpp"
#include <sstream>
#include <boost/algorithm/string/classification.hpp>
Expand Down Expand Up @@ -846,7 +846,7 @@ pid_t Application::ReadPidFile(const String& filename)
*/
String Application::GetPrefixDir(void)
{
return ScriptVariable::Get("PrefixDir");
return ScriptGlobal::Get("PrefixDir");
}

/**
Expand All @@ -856,7 +856,7 @@ String Application::GetPrefixDir(void)
*/
void Application::DeclarePrefixDir(const String& path)
{
ScriptVariable::Set("PrefixDir", path, false);
ScriptGlobal::Set("PrefixDir", path);
}

/**
Expand All @@ -866,7 +866,7 @@ void Application::DeclarePrefixDir(const String& path)
*/
String Application::GetSysconfDir(void)
{
return ScriptVariable::Get("SysconfDir");
return ScriptGlobal::Get("SysconfDir");
}

/**
Expand All @@ -876,7 +876,7 @@ String Application::GetSysconfDir(void)
*/
void Application::DeclareSysconfDir(const String& path)
{
ScriptVariable::Set("SysconfDir", path, false);
ScriptGlobal::Set("SysconfDir", path);
}

/**
Expand All @@ -886,7 +886,7 @@ void Application::DeclareSysconfDir(const String& path)
*/
String Application::GetRunDir(void)
{
return ScriptVariable::Get("RunDir");
return ScriptGlobal::Get("RunDir");
}

/**
Expand All @@ -896,7 +896,7 @@ String Application::GetRunDir(void)
*/
void Application::DeclareRunDir(const String& path)
{
ScriptVariable::Set("RunDir", path, false);
ScriptGlobal::Set("RunDir", path);
}

/**
Expand All @@ -906,7 +906,7 @@ void Application::DeclareRunDir(const String& path)
*/
String Application::GetLocalStateDir(void)
{
return ScriptVariable::Get("LocalStateDir");
return ScriptGlobal::Get("LocalStateDir");
}

/**
Expand All @@ -916,7 +916,7 @@ String Application::GetLocalStateDir(void)
*/
void Application::DeclareLocalStateDir(const String& path)
{
ScriptVariable::Set("LocalStateDir", path, false);
ScriptGlobal::Set("LocalStateDir", path);
}

/**
Expand All @@ -926,7 +926,7 @@ void Application::DeclareLocalStateDir(const String& path)
*/
String Application::GetZonesDir(void)
{
return ScriptVariable::Get("ZonesDir", &Empty);
return ScriptGlobal::Get("ZonesDir", &Empty);
}

/**
Expand All @@ -936,7 +936,7 @@ String Application::GetZonesDir(void)
*/
void Application::DeclareZonesDir(const String& path)
{
ScriptVariable::Set("ZonesDir", path, false);
ScriptGlobal::Set("ZonesDir", path);
}

/**
Expand All @@ -947,7 +947,7 @@ void Application::DeclareZonesDir(const String& path)
String Application::GetPkgDataDir(void)
{
String defaultValue = "";
return ScriptVariable::Get("PkgDataDir", &Empty);
return ScriptGlobal::Get("PkgDataDir", &Empty);
}

/**
Expand All @@ -957,7 +957,7 @@ String Application::GetPkgDataDir(void)
*/
void Application::DeclarePkgDataDir(const String& path)
{
ScriptVariable::Set("PkgDataDir", path, false);
ScriptGlobal::Set("PkgDataDir", path);
}

/**
Expand All @@ -967,7 +967,7 @@ void Application::DeclarePkgDataDir(const String& path)
*/
String Application::GetIncludeConfDir(void)
{
return ScriptVariable::Get("IncludeConfDir", &Empty);
return ScriptGlobal::Get("IncludeConfDir", &Empty);
}

/**
Expand All @@ -977,7 +977,7 @@ String Application::GetIncludeConfDir(void)
*/
void Application::DeclareIncludeConfDir(const String& path)
{
ScriptVariable::Set("IncludeConfDir", path, false);
ScriptGlobal::Set("IncludeConfDir", path);
}

/**
Expand All @@ -987,7 +987,7 @@ void Application::DeclareIncludeConfDir(const String& path)
*/
String Application::GetStatePath(void)
{
return ScriptVariable::Get("StatePath", &Empty);
return ScriptGlobal::Get("StatePath", &Empty);
}

/**
Expand All @@ -997,7 +997,7 @@ String Application::GetStatePath(void)
*/
void Application::DeclareStatePath(const String& path)
{
ScriptVariable::Set("StatePath", path, false);
ScriptGlobal::Set("StatePath", path);
}

/**
Expand All @@ -1007,7 +1007,7 @@ void Application::DeclareStatePath(const String& path)
*/
String Application::GetObjectsPath(void)
{
return ScriptVariable::Get("ObjectsPath", &Empty);
return ScriptGlobal::Get("ObjectsPath", &Empty);
}

/**
Expand All @@ -1017,7 +1017,7 @@ String Application::GetObjectsPath(void)
*/
void Application::DeclareObjectsPath(const String& path)
{
ScriptVariable::Set("ObjectsPath", path, false);
ScriptGlobal::Set("ObjectsPath", path);
}

/**
Expand All @@ -1027,7 +1027,7 @@ void Application::DeclareObjectsPath(const String& path)
*/
String Application::GetVarsPath(void)
{
return ScriptVariable::Get("VarsPath", &Empty);
return ScriptGlobal::Get("VarsPath", &Empty);
}

/**
Expand All @@ -1037,7 +1037,7 @@ String Application::GetVarsPath(void)
*/
void Application::DeclareVarsPath(const String& path)
{
ScriptVariable::Set("VarsPath", path, false);
ScriptGlobal::Set("VarsPath", path);
}

/**
Expand All @@ -1047,7 +1047,7 @@ void Application::DeclareVarsPath(const String& path)
*/
String Application::GetPidPath(void)
{
return ScriptVariable::Get("PidPath", &Empty);
return ScriptGlobal::Get("PidPath", &Empty);
}

/**
Expand All @@ -1057,7 +1057,7 @@ String Application::GetPidPath(void)
*/
void Application::DeclarePidPath(const String& path)
{
ScriptVariable::Set("PidPath", path, false);
ScriptGlobal::Set("PidPath", path);
}

/**
Expand All @@ -1067,7 +1067,7 @@ void Application::DeclarePidPath(const String& path)
*/
String Application::GetApplicationType(void)
{
return ScriptVariable::Get("ApplicationType");
return ScriptGlobal::Get("ApplicationType");
}

/**
Expand All @@ -1077,7 +1077,7 @@ String Application::GetApplicationType(void)
*/
void Application::DeclareApplicationType(const String& type)
{
ScriptVariable::Set("ApplicationType", type, false);
ScriptGlobal::Set("ApplicationType", type);
}

/**
Expand All @@ -1087,7 +1087,7 @@ void Application::DeclareApplicationType(const String& type)
*/
String Application::GetRunAsUser(void)
{
return ScriptVariable::Get("RunAsUser");
return ScriptGlobal::Get("RunAsUser");
}

/**
Expand All @@ -1097,7 +1097,7 @@ String Application::GetRunAsUser(void)
*/
void Application::DeclareRunAsUser(const String& user)
{
ScriptVariable::Set("RunAsUser", user, false);
ScriptGlobal::Set("RunAsUser", user);
}

/**
Expand All @@ -1107,7 +1107,7 @@ void Application::DeclareRunAsUser(const String& user)
*/
String Application::GetRunAsGroup(void)
{
return ScriptVariable::Get("RunAsGroup");
return ScriptGlobal::Get("RunAsGroup");
}

/**
Expand All @@ -1117,7 +1117,7 @@ String Application::GetRunAsGroup(void)
*/
void Application::DeclareConcurrency(int ncpus)
{
ScriptVariable::Set("Concurrency", ncpus, false);
ScriptGlobal::Set("Concurrency", ncpus);
}

/**
Expand All @@ -1128,7 +1128,7 @@ void Application::DeclareConcurrency(int ncpus)
int Application::GetConcurrency(void)
{
Value defaultConcurrency = boost::thread::hardware_concurrency();
return ScriptVariable::Get("Concurrency", &defaultConcurrency);
return ScriptGlobal::Get("Concurrency", &defaultConcurrency);
}

/**
Expand All @@ -1138,22 +1138,7 @@ int Application::GetConcurrency(void)
*/
void Application::DeclareRunAsGroup(const String& group)
{
ScriptVariable::Set("RunAsGroup", group, false);
}

void Application::MakeVariablesConstant(void)
{
ScriptVariable::GetByName("PrefixDir")->SetConstant(true);
ScriptVariable::GetByName("SysconfDir")->SetConstant(true);
ScriptVariable::GetByName("LocalStateDir")->SetConstant(true);
ScriptVariable::GetByName("RunDir")->SetConstant(true);
ScriptVariable::GetByName("PkgDataDir")->SetConstant(true);
ScriptVariable::GetByName("StatePath")->SetConstant(true);
ScriptVariable::GetByName("ObjectsPath")->SetConstant(true);
ScriptVariable::GetByName("PidPath")->SetConstant(true);
ScriptVariable::GetByName("ApplicationType")->SetConstant(true);
ScriptVariable::GetByName("RunAsUser")->SetConstant(true);
ScriptVariable::GetByName("RunAsGroup")->SetConstant(true);
ScriptGlobal::Set("RunAsGroup", group);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/base/application.hpp
Expand Up @@ -126,8 +126,6 @@ class I2_BASE_API Application : public ObjectImpl<Application> {
static int GetConcurrency(void);
static void DeclareConcurrency(int ncpus);

static void MakeVariablesConstant(void);

static ThreadPool& GetTP(void);

static String GetVersion(void);
Expand Down
1 change: 0 additions & 1 deletion lib/base/dynamicobject.cpp
Expand Up @@ -29,7 +29,6 @@
#include "base/exception.hpp"
#include "base/scriptfunction.hpp"
#include "base/initialize.hpp"
#include "base/scriptvariable.hpp"
#include "base/workqueue.hpp"
#include "base/context.hpp"
#include <fstream>
Expand Down
12 changes: 6 additions & 6 deletions lib/base/logger.cpp
Expand Up @@ -24,7 +24,7 @@
#include "base/utility.hpp"
#include "base/objectlock.hpp"
#include "base/context.hpp"
#include "base/scriptvariable.hpp"
#include "base/scriptglobal.hpp"
#include <boost/foreach.hpp>
#include <iostream>

Expand All @@ -41,11 +41,11 @@ LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;

void Logger::StaticInitialize(void)
{
ScriptVariable::Set("LogDebug", LogDebug, true, true);
ScriptVariable::Set("LogNotice", LogNotice, true, true);
ScriptVariable::Set("LogInformation", LogInformation, true, true);
ScriptVariable::Set("LogWarning", LogWarning, true, true);
ScriptVariable::Set("LogCritical", LogCritical, true, true);
ScriptGlobal::Set("LogDebug", LogDebug);
ScriptGlobal::Set("LogNotice", LogNotice);
ScriptGlobal::Set("LogInformation", LogInformation);
ScriptGlobal::Set("LogWarning", LogWarning);
ScriptGlobal::Set("LogCritical", LogCritical);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/base/process.cpp
Expand Up @@ -26,7 +26,7 @@
#include "base/initialize.hpp"
#include "base/logger.hpp"
#include "base/utility.hpp"
#include "base/scriptvariable.hpp"
#include "base/scriptglobal.hpp"
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/thread/once.hpp>
Expand Down Expand Up @@ -510,7 +510,7 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
m_ExtraEnvironment.reset();

#ifdef HAVE_VFORK
Value use_vfork = ScriptVariable::Get("UseVfork");
Value use_vfork = ScriptGlobal::Get("UseVfork");

if (use_vfork.IsEmpty() || static_cast<bool>(use_vfork))
m_Process = vfork();
Expand Down

0 comments on commit 1cb0231

Please sign in to comment.