summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/Box.h19
-rw-r--r--lib/common/BoxTime.cpp4
-rw-r--r--lib/common/Configuration.cpp208
-rw-r--r--lib/common/Configuration.h55
-rw-r--r--lib/common/DebugMemLeakFinder.cpp19
-rw-r--r--lib/common/EventWatchFilesystemObject.cpp43
-rw-r--r--lib/common/FileStream.cpp25
-rw-r--r--lib/common/FileStream.h4
-rw-r--r--lib/common/Guards.h4
-rw-r--r--lib/common/Logging.h33
-rw-r--r--lib/common/PartialReadStream.cpp3
-rw-r--r--lib/common/Utils.cpp63
-rw-r--r--lib/common/Utils.h3
13 files changed, 143 insertions, 340 deletions
diff --git a/lib/common/Box.h b/lib/common/Box.h
index dd91dfe2..d0e7ab1e 100644
--- a/lib/common/Box.h
+++ b/lib/common/Box.h
@@ -52,6 +52,15 @@
extern bool BoxDebugTraceOn;
int BoxDebug_printf(const char *format, ...);
int BoxDebugTrace(const char *format, ...);
+ #define TRACE0(msg) {BoxDebugTrace("%s", msg);}
+ #define TRACE1(msg, a0) {BoxDebugTrace(msg, a0);}
+ #define TRACE2(msg, a0, a1) {BoxDebugTrace(msg, a0, a1);}
+ #define TRACE3(msg, a0, a1, a2) {BoxDebugTrace(msg, a0, a1, a2);}
+ #define TRACE4(msg, a0, a1, a2, a3) {BoxDebugTrace(msg, a0, a1, a2, a3);}
+ #define TRACE5(msg, a0, a1, a2, a3, a4) {BoxDebugTrace(msg, a0, a1, a2, a3, a4);}
+ #define TRACE6(msg, a0, a1, a2, a3, a4, a5) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5);}
+ #define TRACE7(msg, a0, a1, a2, a3, a4, a5, a6) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5, a6);}
+ #define TRACE8(msg, a0, a1, a2, a3, a4, a5, a6, a7) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5, a6, a7);}
#ifndef PLATFORM_DISABLE_MEM_LEAK_TESTING
#define BOX_MEMORY_LEAK_TESTING
@@ -67,6 +76,16 @@
#define TRACE_TO_SYSLOG(x) {}
#define TRACE_TO_STDOUT(x) {}
+ #define TRACE0(msg)
+ #define TRACE1(msg, a0)
+ #define TRACE2(msg, a0, a1)
+ #define TRACE3(msg, a0, a1, a2)
+ #define TRACE4(msg, a0, a1, a2, a3)
+ #define TRACE5(msg, a0, a1, a2, a3, a4)
+ #define TRACE6(msg, a0, a1, a2, a3, a4, a5)
+ #define TRACE7(msg, a0, a1, a2, a3, a4, a5, a6)
+ #define TRACE8(msg, a0, a1, a2, a3, a4, a5, a6, a7)
+
// Box Backup builds release get extra information for exception logging
#define EXCEPTION_CODENAMES_EXTENDED
#define EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION
diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp
index 7d7b1b40..1ddcffd4 100644
--- a/lib/common/BoxTime.cpp
+++ b/lib/common/BoxTime.cpp
@@ -39,8 +39,8 @@ box_time_t GetCurrentBoxTime()
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
{
- BOX_LOG_SYS_ERROR("Failed to gettimeofday(), "
- "dropping precision");
+ BOX_ERROR("Failed to gettimeofday(), dropping "
+ "precision: " << strerror(errno));
}
else
{
diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp
index 10e06680..4d76e0e0 100644
--- a/lib/common/Configuration.cpp
+++ b/lib/common/Configuration.cpp
@@ -12,8 +12,6 @@
#include <stdlib.h>
#include <limits.h>
-#include <sstream>
-
#include "Configuration.h"
#include "CommonException.h"
#include "Guards.h"
@@ -31,105 +29,7 @@ inline bool iw(int c)
static const char *sValueBooleanStrings[] = {"yes", "true", "no", "false", 0};
static const bool sValueBooleanValue[] = {true, true, false, false};
-ConfigurationVerifyKey::ConfigurationVerifyKey
-(
- std::string name,
- int flags,
- void *testFunction
-)
-: mName(name),
- mHasDefaultValue(false),
- mFlags(flags),
- mTestFunction(testFunction)
-{ }
-
-// to allow passing NULL for default ListenAddresses
-
-ConfigurationVerifyKey::ConfigurationVerifyKey
-(
- std::string name,
- int flags,
- NoDefaultValue_t t,
- void *testFunction
-)
-: mName(name),
- mHasDefaultValue(false),
- mFlags(flags),
- mTestFunction(testFunction)
-{ }
-
-ConfigurationVerifyKey::ConfigurationVerifyKey
-(
- std::string name,
- int flags,
- std::string defaultValue,
- void *testFunction
-)
-: mName(name),
- mDefaultValue(defaultValue),
- mHasDefaultValue(true),
- mFlags(flags),
- mTestFunction(testFunction)
-{ }
-
-ConfigurationVerifyKey::ConfigurationVerifyKey
-(
- std::string name,
- int flags,
- const char *defaultValue,
- void *testFunction
-)
-: mName(name),
- mDefaultValue(defaultValue),
- mHasDefaultValue(true),
- mFlags(flags),
- mTestFunction(testFunction)
-{ }
-
-ConfigurationVerifyKey::ConfigurationVerifyKey
-(
- std::string name,
- int flags,
- int defaultValue,
- void *testFunction
-)
-: mName(name),
- mHasDefaultValue(true),
- mFlags(flags),
- mTestFunction(testFunction)
-{
- ASSERT(flags & ConfigTest_IsInt);
- std::ostringstream val;
- val << defaultValue;
- mDefaultValue = val.str();
-}
-ConfigurationVerifyKey::ConfigurationVerifyKey
-(
- std::string name,
- int flags,
- bool defaultValue,
- void *testFunction
-)
-: mName(name),
- mHasDefaultValue(true),
- mFlags(flags),
- mTestFunction(testFunction)
-{
- ASSERT(flags & ConfigTest_IsBool);
- mDefaultValue = defaultValue ? "yes" : "no";
-}
-
-ConfigurationVerifyKey::ConfigurationVerifyKey
-(
- const ConfigurationVerifyKey& rToCopy
-)
-: mName(rToCopy.mName),
- mDefaultValue(rToCopy.mDefaultValue),
- mHasDefaultValue(rToCopy.mHasDefaultValue),
- mFlags(rToCopy.mFlags),
- mTestFunction(rToCopy.mTestFunction)
-{ }
// --------------------------------------------------------------------------
//
@@ -208,8 +108,8 @@ std::auto_ptr<Configuration> Configuration::LoadAndVerify(
if(!rErrorMsg.empty())
{
// An error occured, return now
- BOX_ERROR("Error in Configuration::LoadInfo: " <<
- rErrorMsg);
+ //TRACE1("Error message from LoadInto: %s", rErrorMsg.c_str());
+ TRACE0("Error at Configuration::LoadInfo\n");
delete pconfig;
pconfig = 0;
return std::auto_ptr<Configuration>(0);
@@ -220,8 +120,8 @@ std::auto_ptr<Configuration> Configuration::LoadAndVerify(
{
if(!Verify(*pconfig, *pVerify, std::string(), rErrorMsg))
{
- BOX_ERROR("Error verifying configuration: " <<
- rErrorMsg);
+ //TRACE1("Error message from Verify: %s", rErrorMsg.c_str());
+ TRACE0("Error at Configuration::Verify\n");
delete pconfig;
pconfig = 0;
return std::auto_ptr<Configuration>(0);
@@ -289,8 +189,7 @@ bool Configuration::LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::s
}
else
{
- rErrorMsg += "Unexpected start block in " +
- rConfig.mName + "\n";
+ rErrorMsg += "Unexpected start block in " + rConfig.mName + "\n";
}
}
else
@@ -391,32 +290,36 @@ bool Configuration::LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::s
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::KeyExists(const std::string&)
+// Name: Configuration::KeyExists(const char *)
// Purpose: Checks to see if a key exists
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-bool Configuration::KeyExists(const std::string& rKeyName) const
+bool Configuration::KeyExists(const char *pKeyName) const
{
- return mKeys.find(rKeyName) != mKeys.end();
+ if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
+
+ return mKeys.find(pKeyName) != mKeys.end();
}
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetKeyValue(const std::string&)
+// Name: Configuration::GetKeyValue(const char *)
// Purpose: Returns the value of a configuration variable
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-const std::string &Configuration::GetKeyValue(const std::string& rKeyName) const
+const std::string &Configuration::GetKeyValue(const char *pKeyName) const
{
- std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName));
+ if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
+
+ std::map<std::string, std::string>::const_iterator i(mKeys.find(pKeyName));
if(i == mKeys.end())
{
- BOX_ERROR("Missing configuration key: " << rKeyName);
+ BOX_ERROR("Missing configuration key: " << pKeyName);
THROW_EXCEPTION(CommonException, ConfigNoKey)
}
else
@@ -429,14 +332,16 @@ const std::string &Configuration::GetKeyValue(const std::string& rKeyName) const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetKeyValueInt(const std::string& rKeyName)
+// Name: Configuration::GetKeyValueInt(const char *)
// Purpose: Gets a key value as an integer
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-int Configuration::GetKeyValueInt(const std::string& rKeyName) const
+int Configuration::GetKeyValueInt(const char *pKeyName) const
{
- std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName));
+ if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
+
+ std::map<std::string, std::string>::const_iterator i(mKeys.find(pKeyName));
if(i == mKeys.end())
{
@@ -457,14 +362,16 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetKeyValueBool(const std::string&)
+// Name: Configuration::GetKeyValueBool(const char *) const
// Purpose: Gets a key value as a boolean
// Created: 17/2/04
//
// --------------------------------------------------------------------------
-bool Configuration::GetKeyValueBool(const std::string& rKeyName) const
+bool Configuration::GetKeyValueBool(const char *pKeyName) const
{
- std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName));
+ if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
+
+ std::map<std::string, std::string>::const_iterator i(mKeys.find(pKeyName));
if(i == mKeys.end())
{
@@ -521,21 +428,22 @@ std::vector<std::string> Configuration::GetKeyNames() const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::SubConfigurationExists(const
-// std::string&)
+// Name: Configuration::SubConfigurationExists(const char *)
// Purpose: Checks to see if a sub configuration exists
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-bool Configuration::SubConfigurationExists(const std::string& rSubName) const
+bool Configuration::SubConfigurationExists(const char *pSubName) const
{
+ if(pSubName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
+
// Attempt to find it...
std::list<std::pair<std::string, Configuration> >::const_iterator i(mSubConfigurations.begin());
for(; i != mSubConfigurations.end(); ++i)
{
// This the one?
- if(i->first == rSubName)
+ if(i->first == pSubName)
{
// Yes.
return true;
@@ -550,22 +458,22 @@ bool Configuration::SubConfigurationExists(const std::string& rSubName) const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetSubConfiguration(const
-// std::string&)
+// Name: Configuration::GetSubConfiguration(const char *)
// Purpose: Gets a sub configuration
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-const Configuration &Configuration::GetSubConfiguration(const std::string&
- rSubName) const
+const Configuration &Configuration::GetSubConfiguration(const char *pSubName) const
{
+ if(pSubName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
+
// Attempt to find it...
std::list<std::pair<std::string, Configuration> >::const_iterator i(mSubConfigurations.begin());
for(; i != mSubConfigurations.end(); ++i)
{
// This the one?
- if(i->first == rSubName)
+ if(i->first == pSubName)
{
// Yes.
return i->second;
@@ -620,14 +528,15 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
do
{
// Can the key be found?
- if(rConfig.KeyExists(pvkey->Name()))
+ ASSERT(pvkey->mpName);
+ if(rConfig.KeyExists(pvkey->mpName))
{
// Get value
- const std::string &rval = rConfig.GetKeyValue(pvkey->Name());
+ const std::string &rval = rConfig.GetKeyValue(pvkey->mpName);
const char *val = rval.c_str();
// Check it's a number?
- if((pvkey->Flags() & ConfigTest_IsInt) == ConfigTest_IsInt)
+ if((pvkey->Tests & ConfigTest_IsInt) == ConfigTest_IsInt)
{
// Test it...
char *end;
@@ -636,12 +545,12 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
{
// not a good value
ok = false;
- rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is not a valid integer.\n";
+ rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) is not a valid integer.\n";
}
}
// Check it's a bool?
- if((pvkey->Flags() & ConfigTest_IsBool) == ConfigTest_IsBool)
+ if((pvkey->Tests & ConfigTest_IsBool) == ConfigTest_IsBool)
{
// See if it's one of the allowed strings.
bool found = false;
@@ -659,38 +568,37 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
if(!found)
{
ok = false;
- rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is not a valid boolean value.\n";
+ rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) is not a valid boolean value.\n";
}
}
// Check for multi valued statments where they're not allowed
- if((pvkey->Flags() & ConfigTest_MultiValueAllowed) == 0)
+ if((pvkey->Tests & ConfigTest_MultiValueAllowed) == 0)
{
// Check to see if this key is a multi-value -- it shouldn't be
if(rval.find(MultiValueSeparator) != rval.npos)
{
ok = false;
- rErrorMsg += rLevel + rConfig.mName +"." + pvkey->Name() + " (key) multi value not allowed (duplicated key?).\n";
+ rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) multi value not allowed (duplicated key?).\n";
}
}
}
else
{
// Is it required to exist?
- if((pvkey->Flags() & ConfigTest_Exists) == ConfigTest_Exists)
+ if((pvkey->Tests & ConfigTest_Exists) == ConfigTest_Exists)
{
// Should exist, but doesn't.
ok = false;
- rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is missing.\n";
+ rErrorMsg += rLevel + rConfig.mName + "." + pvkey->mpName + " (key) is missing.\n";
}
- else if(pvkey->HasDefaultValue())
+ else if(pvkey->mpDefaultValue)
{
- rConfig.mKeys[pvkey->Name()] =
- pvkey->DefaultValue();
+ rConfig.mKeys[std::string(pvkey->mpName)] = std::string(pvkey->mpDefaultValue);
}
}
- if((pvkey->Flags() & ConfigTest_LastEntry) == ConfigTest_LastEntry)
+ if((pvkey->Tests & ConfigTest_LastEntry) == ConfigTest_LastEntry)
{
// No more!
todo = false;
@@ -710,14 +618,14 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
bool found = false;
while(scan)
{
- if(scan->Name() == i->first)
+ if(scan->mpName == i->first)
{
found = true;
break;
}
// Next?
- if((scan->Flags() & ConfigTest_LastEntry) == ConfigTest_LastEntry)
+ if((scan->Tests & ConfigTest_LastEntry) == ConfigTest_LastEntry)
{
break;
}
@@ -742,7 +650,8 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
const ConfigurationVerify *scan = rVerify.mpSubConfigurations;
while(scan)
{
- if(scan->mName.length() > 0 && scan->mName[0] == '*')
+ ASSERT(scan->mpName);
+ if(scan->mpName[0] == '*')
{
wildcardverify = scan;
}
@@ -750,8 +659,7 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
// Required?
if((scan->Tests & ConfigTest_Exists) == ConfigTest_Exists)
{
- if(scan->mName.length() > 0 &&
- scan->mName[0] == '*')
+ if(scan->mpName[0] == '*')
{
// Check something exists
if(rConfig.mSubConfigurations.size() < 1)
@@ -764,11 +672,11 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
else
{
// Check real thing exists
- if(!rConfig.SubConfigurationExists(scan->mName))
+ if(!rConfig.SubConfigurationExists(scan->mpName))
{
// Should exist, but doesn't.
ok = false;
- rErrorMsg += rLevel + rConfig.mName + "." + scan->mName + " (block) is missing.\n";
+ rErrorMsg += rLevel + rConfig.mName + "." + scan->mpName + " (block) is missing.\n";
}
}
}
@@ -793,7 +701,7 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
ASSERT(name);
while(scan)
{
- if(scan->mName == name)
+ if(strcmp(scan->mpName, name) == 0)
{
// found it!
subverify = scan;
diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h
index 80b3614b..64e7568e 100644
--- a/lib/common/Configuration.h
+++ b/lib/common/Configuration.h
@@ -29,51 +29,20 @@ enum
class ConfigurationVerifyKey
{
public:
- typedef enum
- {
- NoDefaultValue = 1
- } NoDefaultValue_t;
-
- ConfigurationVerifyKey(std::string name, int flags,
- void *testFunction = NULL);
- // to allow passing ConfigurationVerifyKey::NoDefaultValue
- // for default ListenAddresses
- ConfigurationVerifyKey(std::string name, int flags,
- NoDefaultValue_t t, void *testFunction = NULL);
- ConfigurationVerifyKey(std::string name, int flags,
- std::string defaultValue, void *testFunction = NULL);
- ConfigurationVerifyKey(std::string name, int flags,
- const char* defaultValue, void *testFunction = NULL);
- ConfigurationVerifyKey(std::string name, int flags,
- int defaultValue, void *testFunction = NULL);
- ConfigurationVerifyKey(std::string name, int flags,
- bool defaultValue, void *testFunction = NULL);
- const std::string& Name() const { return mName; }
- const std::string& DefaultValue() const { return mDefaultValue; }
- const bool HasDefaultValue() const { return mHasDefaultValue; }
- const int Flags() const { return mFlags; }
- const void* TestFunction() const { return mTestFunction; }
- ConfigurationVerifyKey(const ConfigurationVerifyKey& rToCopy);
-
-private:
- ConfigurationVerifyKey& operator=(const ConfigurationVerifyKey&
- noAssign);
-
- std::string mName; // "*" for all other keys (not implemented yet)
- std::string mDefaultValue; // default for when it's not present
- bool mHasDefaultValue;
- int mFlags;
- void *mTestFunction; // set to zero for now, will implement later
+ const char *mpName; // "*" for all other keys (not implemented yet)
+ const char *mpDefaultValue; // default for when it's not present
+ int Tests;
+ void *TestFunction; // set to zero for now, will implement later
};
class ConfigurationVerify
{
public:
- std::string mName; // "*" for all other sub config names
+ const char *mpName; // "*" for all other sub config names
const ConfigurationVerify *mpSubConfigurations;
const ConfigurationVerifyKey *mpKeys;
int Tests;
- void *TestFunction; // set to zero for now, will implement later
+ void *TestFunction; // set to zero for now, will implement later
};
class FdGetLine;
@@ -110,14 +79,14 @@ public:
std::string &rErrorMsg)
{ return LoadAndVerify(rFilename, 0, rErrorMsg); }
- bool KeyExists(const std::string& rKeyName) const;
- const std::string &GetKeyValue(const std::string& rKeyName) const;
- int GetKeyValueInt(const std::string& rKeyName) const;
- bool GetKeyValueBool(const std::string& rKeyName) const;
+ bool KeyExists(const char *pKeyName) const;
+ const std::string &GetKeyValue(const char *pKeyName) const;
+ int GetKeyValueInt(const char *pKeyName) const;
+ bool GetKeyValueBool(const char *pKeyName) const;
std::vector<std::string> GetKeyNames() const;
- bool SubConfigurationExists(const std::string& rSubName) const;
- const Configuration &GetSubConfiguration(const std::string& rSubName) const;
+ bool SubConfigurationExists(const char *pSubName) const;
+ const Configuration &GetSubConfiguration(const char *pSubName) const;
std::vector<std::string> GetSubConfigurationNames() const;
std::string mName;
diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp
index 094820b3..87cdf00d 100644
--- a/lib/common/DebugMemLeakFinder.cpp
+++ b/lib/common/DebugMemLeakFinder.cpp
@@ -146,9 +146,7 @@ void *memleakfinder_realloc(void *ptr, size_t size)
std::map<void *, MallocBlockInfo>::iterator i(sMallocBlocks.find(ptr));
if(ptr && i == sMallocBlocks.end())
{
- BOX_WARNING("Block " << ptr << " realloc()ated, but not "
- "in list. Error? Or allocated in startup static "
- "objects?");
+ TRACE1("Block %x realloc(), but not in list. Error? Or allocated in startup static objects?\n", ptr);
}
void *b = ::realloc(ptr, size);
@@ -195,9 +193,7 @@ void memleakfinder_free(void *ptr)
}
else
{
- BOX_WARNING("Block " << ptr << " freed, but not "
- "known. Error? Or allocated in startup "
- "static allocation?");
+ TRACE1("Block %p freed, but not known. Error? Or allocated in startup static allocation?\n", ptr);
}
if(sTrackMallocInSection)
@@ -297,21 +293,16 @@ void memleakfinder_traceblocksinsection()
std::map<void *, MallocBlockInfo>::const_iterator i(sMallocBlocks.find(*s));
if(i == sMallocBlocks.end())
{
- BOX_WARNING("Logical error in section block finding");
+ TRACE0("Logical error in section block finding\n");
}
else
{
- BOX_TRACE("Block " << i->first << " size " <<
- i->second.size << " allocated at " <<
- i->second.file << ":" << i->second.line);
+ TRACE4("Block %p size %d allocated at %s:%d\n", i->first, i->second.size, i->second.file, i->second.line);
}
}
for(std::map<void *, ObjectInfo>::const_iterator i(sSectionObjectBlocks.begin()); i != sSectionObjectBlocks.end(); ++i)
{
- BOX_TRACE("Object" << (i->second.array?" []":"") << " " <<
- i->first << " size " << i->second.size <<
- " allocated at " << i->second.file <<
- ":" << i->second.line);
+ TRACE5("Object%s %p size %d allocated at %s:%d\n", i->second.array?" []":"", i->first, i->second.size, i->second.file, i->second.line);
}
}
diff --git a/lib/common/EventWatchFilesystemObject.cpp b/lib/common/EventWatchFilesystemObject.cpp
index 43533fc8..84781113 100644
--- a/lib/common/EventWatchFilesystemObject.cpp
+++ b/lib/common/EventWatchFilesystemObject.cpp
@@ -26,10 +26,9 @@
// --------------------------------------------------------------------------
//
// Function
-// Name: EventWatchFilesystemObject::EventWatchFilesystemObject
-// (const char *)
-// Purpose: Constructor -- opens the file object
-// Created: 12/3/04
+// Name: EventWatchFilesystemObject::EventWatchFilesystemObject(const char *)
+// Purpose: Constructor -- opens the file object
+// Created: 12/3/04
//
// --------------------------------------------------------------------------
EventWatchFilesystemObject::EventWatchFilesystemObject(const char *Filename)
@@ -40,8 +39,9 @@ EventWatchFilesystemObject::EventWatchFilesystemObject(const char *Filename)
#ifdef HAVE_KQUEUE
if(mDescriptor == -1)
{
- BOX_LOG_SYS_ERROR("EventWatchFilesystemObject: "
- "Failed to open file '" << Filename << "'");
+ BOX_ERROR("EventWatchFilesystemObject: "
+ "Failed to open file '" << Filename << "': " <<
+ strerror(errno));
THROW_EXCEPTION(CommonException, OSFileOpenError)
}
#else
@@ -53,9 +53,9 @@ EventWatchFilesystemObject::EventWatchFilesystemObject(const char *Filename)
// --------------------------------------------------------------------------
//
// Function
-// Name: EventWatchFilesystemObject::~EventWatchFilesystemObject()
-// Purpose: Destructor
-// Created: 12/3/04
+// Name: EventWatchFilesystemObject::~EventWatchFilesystemObject()
+// Purpose: Destructor
+// Created: 12/3/04
//
// --------------------------------------------------------------------------
EventWatchFilesystemObject::~EventWatchFilesystemObject()
@@ -70,14 +70,12 @@ EventWatchFilesystemObject::~EventWatchFilesystemObject()
// --------------------------------------------------------------------------
//
// Function
-// Name: EventWatchFilesystemObject::EventWatchFilesystemObject
-// (const EventWatchFilesystemObject &)
-// Purpose: Copy constructor
-// Created: 12/3/04
+// Name: EventWatchFilesystemObject::EventWatchFilesystemObject(const EventWatchFilesystemObject &)
+// Purpose: Copy constructor
+// Created: 12/3/04
//
// --------------------------------------------------------------------------
-EventWatchFilesystemObject::EventWatchFilesystemObject(
- const EventWatchFilesystemObject &rToCopy)
+EventWatchFilesystemObject::EventWatchFilesystemObject(const EventWatchFilesystemObject &rToCopy)
: mDescriptor(::dup(rToCopy.mDescriptor))
{
if(mDescriptor == -1)
@@ -91,20 +89,17 @@ EventWatchFilesystemObject::EventWatchFilesystemObject(
// --------------------------------------------------------------------------
//
// Function
-// Name: EventWatchFilesystemObject::FillInKEvent(struct kevent &, int)
-// Purpose: For WaitForEvent
-// Created: 12/3/04
+// Name: EventWatchFilesystemObject::FillInKEvent(struct kevent &, int)
+// Purpose: For WaitForEvent
+// Created: 12/3/04
//
// --------------------------------------------------------------------------
-void EventWatchFilesystemObject::FillInKEvent(struct kevent &rEvent,
- int Flags) const
+void EventWatchFilesystemObject::FillInKEvent(struct kevent &rEvent, int Flags) const
{
- EV_SET(&rEvent, mDescriptor, EVFILT_VNODE, EV_CLEAR,
- NOTE_DELETE | NOTE_WRITE, 0, (void*)this);
+ EV_SET(&rEvent, mDescriptor, EVFILT_VNODE, EV_CLEAR, NOTE_DELETE | NOTE_WRITE, 0, (void*)this);
}
#else
-void EventWatchFilesystemObject::FillInPoll(int &fd, short &events,
- int Flags) const
+void EventWatchFilesystemObject::FillInPoll(int &fd, short &events, int Flags) const
{
THROW_EXCEPTION(CommonException, KQueueNotSupportedOnThisPlatform)
}
diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp
index 57fb8274..e0806e10 100644
--- a/lib/common/FileStream.cpp
+++ b/lib/common/FileStream.cpp
@@ -30,8 +30,7 @@ FileStream::FileStream(const char *Filename, int flags, int mode)
#else
: mOSFileHandle(::open(Filename, flags, mode)),
#endif
- mIsEOF(false),
- mFileName(Filename)
+ mIsEOF(false)
{
#ifdef WIN32
if(mOSFileHandle == INVALID_HANDLE_VALUE)
@@ -50,6 +49,9 @@ FileStream::FileStream(const char *Filename, int flags, int mode)
THROW_EXCEPTION(CommonException, OSFileOpenError)
}
}
+#ifdef WIN32
+ this->fileName = Filename;
+#endif
}
@@ -63,8 +65,7 @@ FileStream::FileStream(const char *Filename, int flags, int mode)
// --------------------------------------------------------------------------
FileStream::FileStream(tOSFileHandle FileDescriptor)
: mOSFileHandle(FileDescriptor),
- mIsEOF(false),
- mFileName("HANDLE")
+ mIsEOF(false)
{
#ifdef WIN32
if(mOSFileHandle == INVALID_HANDLE_VALUE)
@@ -76,6 +77,9 @@ FileStream::FileStream(tOSFileHandle FileDescriptor)
BOX_ERROR("FileStream: called with invalid file handle");
THROW_EXCEPTION(CommonException, OSFileOpenError)
}
+#ifdef WIN32
+ this->fileName = "HANDLE";
+#endif
}
#if 0
@@ -146,32 +150,27 @@ int FileStream::Read(void *pBuffer, int NBytes, int Timeout)
NULL
);
- if(valid)
+ if ( valid )
{
r = numBytesRead;
}
- else if(GetLastError() == ERROR_BROKEN_PIPE)
+ else if (GetLastError() == ERROR_BROKEN_PIPE)
{
r = 0;
}
else
{
- BOX_LOG_WIN_ERROR("Failed to read from file: " << mFileName);
+ BOX_ERROR("Failed to read from file: " <<
+ GetErrorMessage(GetLastError()));
r = -1;
}
#else
int r = ::read(mOSFileHandle, pBuffer, NBytes);
- if(r == -1)
- {
- BOX_LOG_SYS_ERROR("Failed to read from file: " << mFileName);
- }
#endif
-
if(r == -1)
{
THROW_EXCEPTION(CommonException, OSFileReadError)
}
-
if(r == 0)
{
mIsEOF = true;
diff --git a/lib/common/FileStream.h b/lib/common/FileStream.h
index 23cc8e75..721bf3dd 100644
--- a/lib/common/FileStream.h
+++ b/lib/common/FileStream.h
@@ -57,8 +57,10 @@ private:
bool mIsEOF;
FileStream(const FileStream &rToCopy) { /* do not call */ }
+#ifdef WIN32
// for debugging..
- std::string mFileName;
+ std::string fileName;
+#endif
};
diff --git a/lib/common/Guards.h b/lib/common/Guards.h
index cd2e4628..d2fb84e0 100644
--- a/lib/common/Guards.h
+++ b/lib/common/Guards.h
@@ -37,8 +37,8 @@ public:
{
if(mOSFileHandle < 0)
{
- BOX_LOG_SYS_ERROR("FileHandleGuard: failed to open "
- "file '" << rFilename << "'");
+ BOX_ERROR("FileHandleGuard: failed to open file '" <<
+ rFilename << "': " << strerror(errno));
THROW_EXCEPTION(CommonException, OSFileOpenError)
}
}
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 2c967c89..2d726627 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -27,16 +27,16 @@
#define BOX_LOG(level, stuff) \
{ \
- std::ostringstream _box_log_line; \
- _box_log_line << stuff; \
- Logging::Log(level, __FILE__, __LINE__, _box_log_line.str()); \
+ std::ostringstream line; \
+ line << stuff; \
+ Logging::Log(level, __FILE__, __LINE__, line.str()); \
}
#define BOX_SYSLOG(level, stuff) \
{ \
- std::ostringstream _box_log_line; \
- _box_log_line << stuff; \
- Logging::LogToSyslog(level, __FILE__, __LINE__, _box_log_line.str()); \
+ std::ostringstream line; \
+ line << stuff; \
+ Logging::LogToSyslog(level, __FILE__, __LINE__, line.str()); \
}
#define BOX_FATAL(stuff) BOX_LOG(Log::FATAL, stuff)
@@ -48,32 +48,15 @@
if (Logging::IsEnabled(Log::TRACE)) \
{ BOX_LOG(Log::TRACE, stuff) }
-#define BOX_LOG_SYS_WARNING(stuff) \
- BOX_WARNING(stuff << ": " << strerror(errno) << " (" << errno << ")")
-#define BOX_LOG_SYS_ERROR(stuff) \
- BOX_ERROR(stuff << ": " << strerror(errno) << " (" << errno << ")")
-#define BOX_LOG_SYS_FATAL(stuff) \
- BOX_FATAL(stuff << ": " << strerror(errno) << " (" << errno << ")")
-
-#ifdef WIN32
- #define BOX_LOG_WIN_ERROR(stuff) \
- BOX_ERROR(stuff << ": " << GetErrorMessage(GetLastError()))
- #define BOX_LOG_WIN_ERROR_NUMBER(stuff, number) \
- BOX_ERROR(stuff << ": " << GetErrorMessage(number))
-#endif
-
-#define BOX_FORMAT_HEX32(number) \
+#define BOX_FORMAT_ACCOUNT(accno) \
std::hex << \
std::showbase << \
std::internal << \
std::setw(10) << \
std::setfill('0') << \
- (number) << \
+ (accno) << \
std::dec
-#define BOX_FORMAT_ACCOUNT(accno) \
- BOX_FORMAT_HEX32(accno)
-
#define BOX_FORMAT_OBJECTID(objectid) \
std::hex << \
std::showbase << \
diff --git a/lib/common/PartialReadStream.cpp b/lib/common/PartialReadStream.cpp
index f2f79715..76096738 100644
--- a/lib/common/PartialReadStream.cpp
+++ b/lib/common/PartialReadStream.cpp
@@ -44,8 +44,7 @@ PartialReadStream::~PartialReadStream()
// Warn in debug mode
if(mBytesLeft != 0)
{
- BOX_TRACE("PartialReadStream destroyed with " << mBytesLeft <<
- " bytes remaining");
+ TRACE1("PartialReadStream::~PartialReadStream when mBytesLeft = %d\n", mBytesLeft);
}
}
diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp
index 90421299..83a12ccf 100644
--- a/lib/common/Utils.cpp
+++ b/lib/common/Utils.cpp
@@ -53,10 +53,10 @@ void SplitString(const std::string &String, char SplitOn, std::vector<std::strin
rOutput.push_back(String.substr(b));
}
/*#ifndef NDEBUG
- BOX_TRACE("Splitting string '" << String << " on " << (char)SplitOn);
+ TRACE2("Splitting string '%s' on %c\n", String.c_str(), SplitOn);
for(unsigned int l = 0; l < rOutput.size(); ++l)
{
- BOX_TRACE(l << " = '" << rOutput[l] << "'");
+ TRACE2("%d = '%s'\n", l, rOutput[l].c_str());
}
#endif*/
}
@@ -159,65 +159,6 @@ int ObjectExists(const std::string& rFilename)
return ((st.st_mode & S_IFDIR) == 0)?ObjectExists_File:ObjectExists_Dir;
}
-std::string HumanReadableSize(int64_t Bytes)
-{
- double readableValue = Bytes;
- std::string units = " B";
- if (readableValue > 1024)
- {
- readableValue /= 1024;
- units = "kB";
- }
-
- if (readableValue > 1024)
- {
- readableValue /= 1024;
- units = "MB";
- }
-
- if (readableValue > 1024)
- {
- readableValue /= 1024;
- units = "GB";
- }
-
- std::ostringstream result;
- result << std::fixed << std::setprecision(2) << readableValue <<
- " " << units;
- return result.str();
-}
-std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max)
-{
- std::ostringstream result;
-
- // Bar graph
- char bar[17];
- unsigned int b = (int)((Bytes * (sizeof(bar)-1)) / Max);
- if(b > sizeof(bar)-1) {b = sizeof(bar)-1;}
- for(unsigned int l = 0; l < b; l++)
- {
- bar[l] = '*';
- }
- for(unsigned int l = b; l < sizeof(bar) - 1; l++)
- {
- bar[l] = ' ';
- }
- bar[sizeof(bar)-1] = '\0';
-
- result << std::fixed <<
- std::setw(10) << Blocks << " blocks, " <<
- std::setw(10) << HumanReadableSize(Bytes) << ", " <<
- std::setw(3) << std::setprecision(0) <<
- ((Bytes*100)/Max) << "% |" << bar << "|";
-
- return result.str();
-}
-std::string FormatUsageLineStart(const std::string& rName)
-{
- std::ostringstream result;
- result << std::setw(20) << std::right << rName << ": ";
- return result.str();
-}
diff --git a/lib/common/Utils.h b/lib/common/Utils.h
index 78bcbd6b..d0842b51 100644
--- a/lib/common/Utils.h
+++ b/lib/common/Utils.h
@@ -30,9 +30,6 @@ enum
ObjectExists_Dir = 2
};
int ObjectExists(const std::string& rFilename);
-std::string HumanReadableSize(int64_t Bytes);
-std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max);
-std::string FormatUsageLineStart(const std::string& rName);
#include "MemLeakFindOff.h"