#include <anna/dbos/Loader.hpp>
namespace anna {
- namespace dbms {
- class Database;
- class Connection;
- }
- namespace dbos {
- class Repository;
- }
+namespace dbms {
+class Database;
+class Connection;
+}
+namespace dbos {
+class Repository;
+}
}
namespace workdir {
namespace filesystem {
- class Directory;
+class Directory;
}
namespace storage {
class Directory : public dbos::Object, public dbos::ObjectFacade <Directory> {
public:
- const filesystem::Directory* getFilesystemDirectory () const throw () { return a_filesystemDirectory; }
- int getINode () const throw () { return a_inode; }
-
- std::string asString () const throw ();
+ const filesystem::Directory* getFilesystemDirectory() const throw() { return a_filesystemDirectory; }
+ int getINode() const throw() { return a_inode; }
+
+ std::string asString() const throw();
+
+ static void setup(dbos::Repository&, const int maxSize) throw(RuntimeException);
+ static Directory* instantiate(const filesystem::Directory*) throw(RuntimeException);
- static void setup (dbos::Repository&, const int maxSize) throw (RuntimeException);
- static Directory* instantiate (const filesystem::Directory*) throw (RuntimeException);
-
- static const char* getStorageAreaName () throw () { return "storage::Directory"; }
- static const dbos::Size getMaxSize () throw () { return st_maxSize; }
+ static const char* getStorageAreaName() throw() { return "storage::Directory"; }
+ static const dbos::Size getMaxSize() throw() { return st_maxSize; }
private:
- class Loader : public dbos::Loader {
- public:
- Loader () : dbos::Loader () {;}
-
- Loader& setKey (const filesystem::Directory* directory) throw () {
- a_filesystemDirectory = directory;
- return *this;
- }
-
- const filesystem::Directory* getDirectory () const throw () { return a_filesystemDirectory; }
- int getINode () const throw () { return a_inode; }
-
- dbos::Index getIndex () const throw ();
- std::string asString () const throw ();
-
- private:
- const filesystem::Directory* a_filesystemDirectory;
- int a_inode;
-
- // dbms::Statement is not required
- dbms::Statement* initialize (dbms::Database&) throw (RuntimeException) { return NULL; }
- bool load (dbms::Connection*, const dbos::StorageArea*) throw (RuntimeException);
- };
-
- const filesystem::Directory* a_filesystemDirectory;
- int a_inode;
-
- static Loader* st_loader;
- static ExclusiveHash <std::string> st_hash;
- static int st_maxSize;
-
- Directory () { ; }
- Directory (const Directory&);
-
- void initialize (dbos::Loader& loader) throw (RuntimeException, dbms::DatabaseException);
- void destroy () throw ();
-
- dbos_declare_object (Directory);
+ class Loader : public dbos::Loader {
+ public:
+ Loader() : dbos::Loader() {;}
+
+ Loader& setKey(const filesystem::Directory* directory) throw() {
+ a_filesystemDirectory = directory;
+ return *this;
+ }
+
+ const filesystem::Directory* getDirectory() const throw() { return a_filesystemDirectory; }
+ int getINode() const throw() { return a_inode; }
+
+ dbos::Index getIndex() const throw();
+ std::string asString() const throw();
+
+ private:
+ const filesystem::Directory* a_filesystemDirectory;
+ int a_inode;
+
+ // dbms::Statement is not required
+ dbms::Statement* initialize(dbms::Database&) throw(RuntimeException) { return NULL; }
+ bool load(dbms::Connection*, const dbos::StorageArea*) throw(RuntimeException);
+ };
+
+ const filesystem::Directory* a_filesystemDirectory;
+ int a_inode;
+
+ static Loader* st_loader;
+ static ExclusiveHash <std::string> st_hash;
+ static int st_maxSize;
+
+ Directory() { ; }
+ Directory(const Directory&);
+
+ void initialize(dbos::Loader& loader) throw(RuntimeException, dbms::DatabaseException);
+ void destroy() throw();
+
+ dbos_declare_object(Directory);
};
}
#include <anna/dbos/Loader.hpp>
namespace anna {
- namespace dbms {
- class Database;
- class Connection;
- }
- namespace dbos {
- class Repository;
- }
+namespace dbms {
+class Database;
+class Connection;
+}
+namespace dbos {
+class Repository;
+}
}
namespace workdir {
namespace filesystem {
- class File;
+class File;
}
namespace storage {
class File : public dbos::Object, public dbos::ObjectFacade <File> {
public:
- const Directory* getParent () const throw () { return a_parent; }
- const filesystem::File* getFilesystemFile () const throw () { return a_filesystemFile; }
- int getINode () const throw () { return a_inode; }
-
- std::string asString () const throw ();
-
- static void setup (dbos::Repository&, const int maxSize) throw (RuntimeException);
- static File* instantiate (const filesystem::File*) throw (RuntimeException);
-
- static const char* getStorageAreaName () throw () { return "storage::File"; }
- static const dbos::Size getMaxSize () throw () { return st_maxSize; }
+ const Directory* getParent() const throw() { return a_parent; }
+ const filesystem::File* getFilesystemFile() const throw() { return a_filesystemFile; }
+ int getINode() const throw() { return a_inode; }
+
+ std::string asString() const throw();
+
+ static void setup(dbos::Repository&, const int maxSize) throw(RuntimeException);
+ static File* instantiate(const filesystem::File*) throw(RuntimeException);
+
+ static const char* getStorageAreaName() throw() { return "storage::File"; }
+ static const dbos::Size getMaxSize() throw() { return st_maxSize; }
private:
- class Loader : public dbos::Loader {
- public:
- Loader () : dbos::Loader () {;}
-
- Loader& setKey (const filesystem::File* file) throw () {
- a_filesystemFile = file;
- return *this;
- }
-
- const filesystem::File* getFile () const throw () { return a_filesystemFile; }
- int getINode () const throw () { return a_inode; }
-
- dbos::Index getIndex () const throw ();
- std::string asString () const throw ();
-
- private:
- const filesystem::File* a_filesystemFile;
- int a_inode;
-
- // dbms::Statement is not required
- dbms::Statement* initialize (dbms::Database&) throw (RuntimeException) { return NULL; }
- bool load (dbms::Connection*, const dbos::StorageArea*) throw (RuntimeException);
- };
-
- Directory* a_parent;
- const filesystem::File* a_filesystemFile;
- int a_inode;
-
- static Loader* st_loader;
- static ExclusiveHash <std::string> st_hash;
- static int st_maxSize;
-
- File () : a_parent (NULL) { ; }
- File (const File&);
-
- void initialize (dbos::Loader& loader) throw (RuntimeException, dbms::DatabaseException);
- void destroy () throw ();
-
- dbos_declare_object (File);
+ class Loader : public dbos::Loader {
+ public:
+ Loader() : dbos::Loader() {;}
+
+ Loader& setKey(const filesystem::File* file) throw() {
+ a_filesystemFile = file;
+ return *this;
+ }
+
+ const filesystem::File* getFile() const throw() { return a_filesystemFile; }
+ int getINode() const throw() { return a_inode; }
+
+ dbos::Index getIndex() const throw();
+ std::string asString() const throw();
+
+ private:
+ const filesystem::File* a_filesystemFile;
+ int a_inode;
+
+ // dbms::Statement is not required
+ dbms::Statement* initialize(dbms::Database&) throw(RuntimeException) { return NULL; }
+ bool load(dbms::Connection*, const dbos::StorageArea*) throw(RuntimeException);
+ };
+
+ Directory* a_parent;
+ const filesystem::File* a_filesystemFile;
+ int a_inode;
+
+ static Loader* st_loader;
+ static ExclusiveHash <std::string> st_hash;
+ static int st_maxSize;
+
+ File() : a_parent(NULL) { ; }
+ File(const File&);
+
+ void initialize(dbos::Loader& loader) throw(RuntimeException, dbms::DatabaseException);
+ void destroy() throw();
+
+ dbos_declare_object(File);
};
}
/**
Constructor.
- \param device Instance for device (address).
+ \param device Instance for device (address).
\param port Port number.
*/
INetAddress(const Device* device, const int port = -1) : a_device(device), a_port(port) {;}
/**
Copy operator.
- \param right Source address to be copied.
+ \param right Source address to be copied.
*/
INetAddress& operator = (const INetAddress& right) throw() { a_device = right.a_device; a_port = right.a_port; return *this; }
/**
- Comparison operator.
+ Comparison operator.
\param right Source address to be compared.
@return \em true when address provided is equal to this \em false in other case.
*/
bool operator == (const INetAddress& right) const throw() { return a_device == right.a_device && a_port == right.a_port; }
/**
- Returns the initialized state for this network address.
- @return \em true when initialized, \em false when not.
+ Returns the initialized state for this network address.
+ @return \em true when initialized, \em false when not.
*/
bool isNull() const throw() { return (a_device == NULL || a_port == -1); }
/**
- Clear the content for this instance.
+ Clear the content for this instance.
*/
void clear() throw() { a_device = NULL; a_port = -1; }
~LiteTransport();
/**
- Returns the class name literal.
- @return class name literal.
+ Returns the class name literal.
+ @return class name literal.
*/
static const char* className() throw() { return "anna::comm::LiteTransport"; }
class ReceiverFactory : public Mutex {
public:
/**
- Returns the logical name for this receiver factory.
- @return logical name for this receiver factory.
+ Returns the logical name for this receiver factory.
+ @return logical name for this receiver factory.
*/
const std::string& getName() const throw() { return a_name; }
protected:
/**
Constructor.
- \param name Logical name for this receivers factory.
+ \param name Logical name for this receivers factory.
*/
ReceiverFactory(const char* name);
/**
Returns the transport layer manager associated to this class.
- \return transport layer manager associated to this class.
+ \return transport layer manager associated to this class.
*/
static TransportFactory& getFactory() throw() { return st_transportFactory; }
@param hostname Logical name for the server used to resolve (could be www.gopher.net i.e.).
@return First IP address returned by the system.
-
+
\see man gethostbyname.
*/
static std::string resolveIP(const char* hostname) throw(RuntimeException);
/**
Parses the environment data (all variables available) when process was started.
- @param envp Environment array passed on main function as third argument.
+ @param envp Environment array passed on main function as third argument.
Cache data is cleared if NULL passed, allowing to get current environment values for variables.
*/
void initialize(char **envp = NULL) throw();
LOGMETHOD(TraceMethod tm("Environment", "initialize", ANNA_FILE_LOCATION));
// clear data
a_vars.clear();
- if (!envp) return;
+
+ if(!envp) return;
// register data
std::string assignment, var, val;
- while (*envp) {
- assignment = *envp;
+
+ while(*envp) {
+ assignment = *envp;
std::size_t equalPos = assignment.find("=");
- if (equalPos != string::npos) { // protection
+
+ if(equalPos != string::npos) { // protection
var = assignment.substr(0, equalPos - 1);
val = assignment.substr(equalPos, assignment.size() - 1);
a_vars[var] = val;
}
+
envp++;
}
}
throw RuntimeException("Invalid NULL variable name!", ANNA_FILE_LOCATION);
std::string var = variableName;
-
return getValue(var, exceptionIfMissing);
}
std::string Environment::getValue(const std::string &variableName, bool exceptionIfMissing) throw(RuntimeException) {
std::string result = "";
-
std::map<std::string, std::string>::const_iterator it = a_vars.find(variableName);
if(it == a_vars.end()) {
- char *current = getenv (variableName.c_str());
- if (!current) {
+ char *current = getenv(variableName.c_str());
+
+ if(!current) {
std::string msg = "The variable '";
msg += variableName;
msg += "' is not defined in the environment.";
LOGDEBUG(Logger::debug(msg, ANNA_FILE_LOCATION));
if(exceptionIfMissing) throw RuntimeException(msg, ANNA_FILE_LOCATION);
- }
- else {
+ } else {
// assignment
a_vars[variableName] = current;
result = current;
}
- }
- else {
+ } else {
result = it->second;
}
void Environment::setVariable(const std::string &name, const std::string &value, bool overwrite) throw(RuntimeException) {
+ if(name == "") throw RuntimeException("Must provide non-empty variable name", ANNA_FILE_LOCATION);
- if (name == "") throw RuntimeException("Must provide non-empty variable name", ANNA_FILE_LOCATION);
-
- if(setenv(name.c_str(), value.c_str(), overwrite ? 1:0) != 0) {
+ if(setenv(name.c_str(), value.c_str(), overwrite ? 1 : 0) != 0) {
std::string msg = "Cannot set the environment variable '";
msg += name;
msg += "=\"";
msg += value;
msg += "\"'. The errno is ";
msg += anna::functions::asString(errno);
-
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
// optimization
- if (overwrite)
+ if(overwrite)
a_vars[name] = value;
}
void Environment::unsetVariable(const std::string &name) throw(RuntimeException) {
-
- if (name == "") throw RuntimeException("Must provide non-empty variable name", ANNA_FILE_LOCATION);
+ if(name == "") throw RuntimeException("Must provide non-empty variable name", ANNA_FILE_LOCATION);
if(unsetenv(name.c_str()) != 0) {
std::string msg = "Cannot unset the environment variable named '";
msg += name;
msg += "'. The errno is ";
msg += anna::functions::asString(errno);
-
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
std::map<std::string, std::string>::iterator it = a_vars.find(name);
+
if(it != a_vars.end()) a_vars.erase(it);
}
env.initialize();
BOOST_CHECK_THROW(env.getValue("WRONG_ENV_VAR", true), anna::RuntimeException); // true => exception if missing
BOOST_CHECK_THROW(env.getValue(NULL), anna::RuntimeException);
-
env.setVariable("TEST_VAR", "my test var value");
BOOST_REQUIRE_EQUAL(env.getValue("TEST_VAR"), std::string("my test var value"));
env.setVariable("TEST_VAR", "my new test var value", false /* no overwritting */);
BOOST_REQUIRE_EQUAL(env.getValue("TEST_VAR"), std::string("my test var value"));
env.unsetVariable("TEST_VAR");
BOOST_REQUIRE_EQUAL(env.getValue("TEST_VAR"), std::string(""));
-
BOOST_REQUIRE_EQUAL(env.getValue("MISSING_ENV_VAR"), std::string(""));
}