Skip to content
Snippets Groups Projects
Verified Commit 65aedbfc authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'dev' into f-multi-retrieve

parents d3ac4239 d1525b52
No related branches found
No related tags found
1 merge request!5F multi retrieve
This commit is part of merge request !5. Comments created here will be created in the context of that merge request.
# GENERAL # GENERAL
* >=conan-1.37.2 (e.g. with `pip install conan`) * >=conan-1.37.2 (e.g. with `pip install conan`)
* >=cmake-3.14 * >=cmake-3.13
* >=gcc-10.2.0 | >=clang-11 * >=gcc-10.2.0 | >=clang-11
# OPTIONAL # OPTIONAL
......
...@@ -149,6 +149,9 @@ public: ...@@ -149,6 +149,9 @@ public:
return ConnectionManager::GetInstance().mGetConnection(name); return ConnectionManager::GetInstance().mGetConnection(name);
}; };
/**
* Get the connection marked by the "default" key in the configuration.
*/
inline static auto GetDefaultConnection() inline static auto GetDefaultConnection()
-> const std::shared_ptr<Connection> & { -> const std::shared_ptr<Connection> & {
return ConnectionManager::GetInstance().mGetDefaultConnection(); return ConnectionManager::GetInstance().mGetDefaultConnection();
......
...@@ -38,6 +38,12 @@ using caosdb::entity::v1alpha1::IdResponse; ...@@ -38,6 +38,12 @@ using caosdb::entity::v1alpha1::IdResponse;
using ProtoParent = caosdb::entity::v1alpha1::Parent; using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoEntity = caosdb::entity::v1alpha1::Entity; using ProtoEntity = caosdb::entity::v1alpha1::Entity;
/**
* Messages convey information about the state and result of transactions.
*
* A Message object can be thought of as kinf of a generalized error object in
* other frameworks. Please have a look at MessageCodes for more details.
*/
class Message { class Message {
public: public:
[[nodiscard]] inline auto GetCode() const -> MessageCode { [[nodiscard]] inline auto GetCode() const -> MessageCode {
...@@ -58,187 +64,187 @@ private: ...@@ -58,187 +64,187 @@ private:
}; };
/** /**
* Container for Messages. * Container for Messages.
*/ */
class Messages { class Messages {
public: public:
[[nodiscard]] inline auto Size() const -> int { return wrapped->size(); } [[nodiscard]] inline auto Size() const -> int { return wrapped->size(); }
[[nodiscard]] inline auto At(int index) const -> const Message { [[nodiscard]] inline auto At(int index) const -> const Message {
return Message(&(wrapped->at(index))); return Message(&(wrapped->at(index)));
} }
friend class Entity; friend class Entity;
private: private:
inline Messages() : wrapped(nullptr){}; inline Messages() : wrapped(nullptr){};
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Message> ::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Message>
*wrapped; *wrapped;
}; };
/** /**
* Parent of an Entity. * Parent of an Entity.
* *
* This implementation uses protobuf messages as storage backends. In other * This implementation uses protobuf messages as storage backends. In other
* words, this class wraps a protobuf message and provides getter and setter * words, this class wraps a protobuf message and provides getter and setter
* methods. * methods.
*/ */
class Parent { class Parent {
public: public:
explicit inline Parent(caosdb::entity::v1alpha1::Parent *wrapped) explicit inline Parent(caosdb::entity::v1alpha1::Parent *wrapped)
: wrapped(wrapped){}; : wrapped(wrapped){};
Parent(); Parent();
/**
* Return the id of the parent entity.
*/
[[nodiscard]] auto GetId() const -> const std::string &;
/**
* Return the name of the parent entity.
*/
[[nodiscard]] auto GetName() const -> const std::string &;
/**
* Return the description of the parent entity.
*/
[[nodiscard]] auto GetDescription() const -> const std::string &;
/**
* Set the id of the parent.
*/
auto SetId(const std::string &id) -> void;
/**
* Set the name of the parent.
*/
auto SetName(const std::string &name) -> void;
/** /**
* Return a json string representing this parent. * Return the id of the parent entity.
* */
* This is intended for debugging. [[nodiscard]] auto GetId() const -> const std::string &;
*/ /**
inline auto ToString() const -> const std::string { * Return the name of the parent entity.
google::protobuf::util::JsonOptions options; */
std::string out; [[nodiscard]] auto GetName() const -> const std::string &;
google::protobuf::util::MessageToJsonString(*(this->wrapped), &out, /**
options); * Return the description of the parent entity.
return out; */
} [[nodiscard]] auto GetDescription() const -> const std::string &;
// TODO(fspreck) These need implementations. See Entity::GetErrors for /**
// inspiration. * Set the id of the parent.
/** */
* Return the error messages of this parent. auto SetId(const std::string &id) -> void;
*/ /**
[[nodiscard]] inline auto GetErrors() const -> const Messages &; * Set the name of the parent.
/** */
* Return the warning messages of this parent. auto SetName(const std::string &name) -> void;
*/
[[nodiscard]] inline auto GetWarnings() const -> const Messages &;
/**
* Return the info messages of this parent.
*/
[[nodiscard]] inline auto GetInfos() const -> const Messages &;
friend class Entity; /**
friend class Parents; * Return a json string representing this parent.
*
* This is intended for debugging.
*/
inline auto ToString() const -> const std::string {
google::protobuf::util::JsonOptions options;
std::string out;
google::protobuf::util::MessageToJsonString(*(this->wrapped), &out,
options);
return out;
}
// TODO(fspreck) These need implementations. See Entity::GetErrors for
// inspiration.
/**
* Return the error messages of this parent.
*/
[[nodiscard]] inline auto GetErrors() const -> const Messages &;
/**
* Return the warning messages of this parent.
*/
[[nodiscard]] inline auto GetWarnings() const -> const Messages &;
/**
* Return the info messages of this parent.
*/
[[nodiscard]] inline auto GetInfos() const -> const Messages &;
private: friend class Entity;
/** friend class Parents;
* Return an empty protobuf message pointer.
*
* This function is called by the default constructor of the
* caosdb::entity::Parent class and the protobuf message is used as the
* storage-backend for the new Parent instance.
*
* An 'Arena' takes care of the the memory management. Don't try to delete
* this.
*/
static auto CreateProtoParent() -> ProtoParent *;
/**
* Message which serves as storage backend.
*/
mutable caosdb::entity::v1alpha1::Parent *wrapped;
};
private:
/** /**
* Container for parents of entities. * Return an empty protobuf message pointer.
* *
* Should only be instantiated and write-accessed by the owning entity. * This function is called by the default constructor of the
* caosdb::entity::Parent class and the protobuf message is used as the
* storage-backend for the new Parent instance.
*
* An 'Arena' takes care of the the memory management. Don't try to delete
* this.
*/
static auto CreateProtoParent() -> ProtoParent *;
/**
* Message which serves as storage backend.
*/ */
mutable caosdb::entity::v1alpha1::Parent *wrapped;
};
/**
* Container for parents of entities.
*
* Should only be instantiated and write-accessed by the owning entity.
*/
class Parents { class Parents {
public: public:
/** /**
* Return the current size of the parent container. * Return the current size of the parent container.
* *
* That is also the number of parents the owning entity currently has. * That is also the number of parents the owning entity currently has.
*/ */
[[nodiscard]] inline auto Size() const -> int { return wrapped->size(); } [[nodiscard]] inline auto Size() const -> int { return wrapped->size(); }
/** /**
* Return the parent at the given index. * Return the parent at the given index.
*/ */
[[nodiscard]] inline auto At(int index) const -> const Parent { [[nodiscard]] inline auto At(int index) const -> const Parent {
return Parent(&(wrapped->at(index))); return Parent(&(wrapped->at(index)));
} }
friend class Entity; friend class Entity;
private: private:
inline Parents(){}; inline Parents(){};
explicit inline Parents( explicit inline Parents(
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent>
*wrapped)
: wrapped(wrapped){};
/**
* Append a parent.
*
* This increases the Size() by one.
*/
auto Append(const Parent &parent) -> void;
/**
* The collection of parent messages which serves as a backend for this
* class.
*/
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent> ::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent>
*wrapped; *wrapped)
}; : wrapped(wrapped){};
/** /**
* Property of an Entity. * Append a parent.
* *
* This is a property which belongs to another entity. Don't confuse it with * This increases the Size() by one.
* an Entity with the "Property" role.
*/ */
auto Append(const Parent &parent) -> void;
/**
* The collection of parent messages which serves as a backend for this
* class.
*/
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent>
*wrapped;
};
/**
* Property of an Entity.
*
* This is a property which belongs to another entity. Don't confuse it with
* an Entity with the "Property" role.
*/
class Property { class Property {
public: public:
explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped) explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped)
: wrapped(wrapped){}; : wrapped(wrapped){};
// TODO(fspreck) All of these methods need implementations. // TODO(fspreck) All of these methods need implementations.
[[nodiscard]] auto GetId() const -> const std::string &; [[nodiscard]] auto GetId() const -> const std::string &;
[[nodiscard]] auto GetName() const -> const std::string &; [[nodiscard]] auto GetName() const -> const std::string &;
[[nodiscard]] auto GetDescription() const -> const std::string &; [[nodiscard]] auto GetDescription() const -> const std::string &;
[[nodiscard]] auto GetImportance() const -> const std::string &; [[nodiscard]] auto GetImportance() const -> const std::string &;
[[nodiscard]] auto GetValue() const -> const std::string &; [[nodiscard]] auto GetValue() const -> const std::string &;
[[nodiscard]] auto GetUnit() const -> const std::string &; [[nodiscard]] auto GetUnit() const -> const std::string &;
[[nodiscard]] auto GetDatatype() const -> const std::string &; [[nodiscard]] auto GetDatatype() const -> const std::string &;
[[nodiscard]] auto GetErrors() const -> const Messages &; [[nodiscard]] auto GetErrors() const -> const Messages &;
[[nodiscard]] auto GetWarnings() const -> const Messages &; [[nodiscard]] auto GetWarnings() const -> const Messages &;
[[nodiscard]] auto GetInfos() const -> const Messages &; [[nodiscard]] auto GetInfos() const -> const Messages &;
auto SetId(const std::string &id) -> void; auto SetId(const std::string &id) -> void;
auto SetName(const std::string &name) -> void; auto SetName(const std::string &name) -> void;
auto SetImportance(const std::string &importance) -> void; auto SetImportance(const std::string &importance) -> void;
auto SetValue(const std::string &value) -> void; auto SetValue(const std::string &value) -> void;
auto SetUnit(const std::string &unit) -> void; auto SetUnit(const std::string &unit) -> void;
auto SetDatatype(const std::string &datatype) -> void; auto SetDatatype(const std::string &datatype) -> void;
friend class Entity; friend class Entity;
friend class Properties; friend class Properties;
private: private:
caosdb::entity::v1alpha1::Property *wrapped; caosdb::entity::v1alpha1::Property *wrapped;
}; };
/** /**
...@@ -248,12 +254,12 @@ private: ...@@ -248,12 +254,12 @@ private:
*/ */
class Properties { class Properties {
public: public:
// TODO(fspreck) Implementations needed (basically everything). See Parents // TODO(fspreck) Implementations needed (basically everything). See Parents
// container for inspiration. // container for inspiration.
[[nodiscard]] auto At(int index) const -> const Property &; [[nodiscard]] auto At(int index) const -> const Property &;
auto Append(const Property &property) -> void; auto Append(const Property &property) -> void;
friend class Entity; friend class Entity;
private: private:
inline Properties(){}; inline Properties(){};
......
...@@ -32,9 +32,9 @@ using std::runtime_error; ...@@ -32,9 +32,9 @@ using std::runtime_error;
/** /**
* @brief Generic exception class of the caosdb client library. * @brief Generic exception class of the caosdb client library.
*/ */
class GenericException : public runtime_error { class Exception : public runtime_error {
public: public:
explicit GenericException(StatusCode code, const std::string &what_arg) explicit Exception(StatusCode code, const std::string &what_arg)
: runtime_error(what_arg), code(code) {} : runtime_error(what_arg), code(code) {}
[[nodiscard]] inline auto GetCode() const -> StatusCode { return this->code; } [[nodiscard]] inline auto GetCode() const -> StatusCode { return this->code; }
...@@ -45,32 +45,28 @@ private: ...@@ -45,32 +45,28 @@ private:
/** /**
* @brief Exception for authentication errors. * @brief Exception for authentication errors.
*/ */
class AuthenticationError : public GenericException { class AuthenticationError : public Exception {
public: public:
explicit AuthenticationError(const std::string &what_arg) explicit AuthenticationError(const std::string &what_arg)
: GenericException(StatusCode::AUTHENTICATION_ERROR, what_arg) {} : Exception(StatusCode::AUTHENTICATION_ERROR, what_arg) {}
}; };
/** /**
* @brief The connection to the CaosDB server is down. * @brief The connection to the CaosDB server is down.
*/ */
class ConnectionError : public GenericException { class ConnectionError : public Exception {
public: public:
explicit ConnectionError(const std::string &what_arg) explicit ConnectionError(const std::string &what_arg)
: GenericException(StatusCode::CONNECTION_ERROR, what_arg) {} : Exception(StatusCode::CONNECTION_ERROR, what_arg) {}
}; };
/** /**
* @brief The transaction terminated unsuccessfully. * @brief The transaction terminated unsuccessfully.
*/ */
class TransactionError : public GenericException { class TransactionError : public Exception {
protected:
TransactionError(StatusCode code, const std::string &what_arg)
: GenericException(code, what_arg) {}
public: public:
explicit TransactionError(const std::string &what_arg) explicit TransactionError(const std::string &what_arg)
: GenericException(StatusCode::GENERIC_TRANSACTION_ERROR, what_arg) {} : Exception(StatusCode::GENERIC_TRANSACTION_ERROR, what_arg) {}
}; };
class TransactionStatusError : public TransactionError { class TransactionStatusError : public TransactionError {
...@@ -83,19 +79,19 @@ public: ...@@ -83,19 +79,19 @@ public:
* @brief Exception for errors of the ConfigurationManager or other components * @brief Exception for errors of the ConfigurationManager or other components
* of the configuration. * of the configuration.
*/ */
class ConfigurationError : public GenericException { class ConfigurationError : public Exception {
public: public:
explicit ConfigurationError(const std::string &what_arg) explicit ConfigurationError(const std::string &what_arg)
: GenericException(StatusCode::CONFIGURATION_ERROR, what_arg) {} : Exception(StatusCode::CONFIGURATION_ERROR, what_arg) {}
}; };
/** /**
* @brief The connection isn't known to the ConnectionManager under this name. * @brief The connection isn't known to the ConnectionManager under this name.
*/ */
class UnknownConnectionError : public GenericException { class UnknownConnectionError : public Exception {
public: public:
explicit UnknownConnectionError(const std::string &what_arg) explicit UnknownConnectionError(const std::string &what_arg)
: GenericException(StatusCode::UNKNOWN_CONNECTION_ERROR, what_arg) {} : Exception(StatusCode::UNKNOWN_CONNECTION_ERROR, what_arg) {}
}; };
} // namespace caosdb::exceptions } // namespace caosdb::exceptions
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
* *
*/ */
#ifndef CAOSDB_LOG_LEVELS_H #ifndef CAOSDB_LOG_LEVEL_H
#define CAOSDB_LOG_LEVELS_H #define CAOSDB_LOG_LEVEL_H
#define CAOSDB_LOG_LEVEL_OFF 1000000 #define CAOSDB_LOG_LEVEL_OFF 1000000
#define CAOSDB_LOG_LEVEL_FATAL 700 #define CAOSDB_LOG_LEVEL_FATAL 700
......
...@@ -43,6 +43,9 @@ typedef boost::log::sources::severity_channel_logger<int, std::string> ...@@ -43,6 +43,9 @@ typedef boost::log::sources::severity_channel_logger<int, std::string>
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class) BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class)
/**
* This class stores the integer log level.
*/
class LevelConfiguration { class LevelConfiguration {
public: public:
LevelConfiguration(int level) : level(level){}; LevelConfiguration(int level) : level(level){};
...@@ -54,6 +57,11 @@ private: ...@@ -54,6 +57,11 @@ private:
class SinkConfiguration; class SinkConfiguration;
/**
* This class stores the logging level and log sinks.
*
* Sinks are represented by SinkConfiguration objects.
*/
class LoggingConfiguration : public LevelConfiguration { class LoggingConfiguration : public LevelConfiguration {
public: public:
virtual ~LoggingConfiguration() = default; virtual ~LoggingConfiguration() = default;
...@@ -69,6 +77,23 @@ private: ...@@ -69,6 +77,23 @@ private:
auto initialize_logging_defaults() -> int; auto initialize_logging_defaults() -> int;
auto initialize_logging(const LoggingConfiguration &configuration) -> void; auto initialize_logging(const LoggingConfiguration &configuration) -> void;
/**
* A logging sink is characterized by a name and destination.
*
* Typical inheriting configurations exist for console, files and syslog.
*
* When a SinkConfiguration is created from a configuration, the sink
* configuration must contain a \p destination key which matches one of the
* keywords for implemented sinks. At the moment of writing this documentation,
* valid destinations are:
*
* \li \p file
* \li \p console
* \li \p syslog
*
* A \p level keyword sets the logging level, if it exists at the sink or
* logging level of the configuration.
*/
class SinkConfiguration : public LevelConfiguration { class SinkConfiguration : public LevelConfiguration {
public: public:
virtual ~SinkConfiguration() = default; virtual ~SinkConfiguration() = default;
...@@ -104,6 +129,12 @@ private: ...@@ -104,6 +129,12 @@ private:
const std::string destination = "Console"; const std::string destination = "Console";
}; };
/**
* The file name is the destination, the directory can be set separately.
*
* If there is a `directory` key in the configuration, that will be used as a
* default, otherwise it is the current directory.
*/
class FileSinkConfiguration : public SinkConfiguration { class FileSinkConfiguration : public SinkConfiguration {
public: public:
virtual ~FileSinkConfiguration() = default; virtual ~FileSinkConfiguration() = default;
...@@ -136,27 +167,27 @@ private: ...@@ -136,27 +167,27 @@ private:
}; };
/** /**
* Convenience function for the c-interface. * Convenience function for the C interface.
*/ */
void caosdb_log_fatal(const char *channel, const char *msg); void caosdb_log_fatal(const char *channel, const char *msg);
/** /**
* Convenience function for the c-interface. * Convenience function for the C interface.
*/ */
void caosdb_log_error(const char *channel, const char *msg); void caosdb_log_error(const char *channel, const char *msg);
/** /**
* Convenience function for the c-interface. * Convenience function for the C interface.
*/ */
void caosdb_log_warn(const char *channel, const char *msg); void caosdb_log_warn(const char *channel, const char *msg);
/** /**
* Convenience function for the c-interface. * Convenience function for the C interface.
*/ */
void caosdb_log_info(const char *channel, const char *msg); void caosdb_log_info(const char *channel, const char *msg);
/** /**
* Convenience function for the c-interface. * Convenience function for the C interface.
*/ */
void caosdb_log_debug(const char *channel, const char *msg); void caosdb_log_debug(const char *channel, const char *msg);
/** /**
* Convenience function for the c-interface. * Convenience function for the C interface.
*/ */
void caosdb_log_trace(const char *channel, const char *msg); void caosdb_log_trace(const char *channel, const char *msg);
......
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
* In contrast to the status codes, the message codes are part of the CaosDB * In contrast to the status codes, the message codes are part of the CaosDB
* API. Messages (and their codes) represent the state of the entities in a * API. Messages (and their codes) represent the state of the entities in a
* transaction or the server. * transaction or the server.
*
* For a specification of the message codes, look at the protobuf documentation.
* The sources and documentation can be found at
* https://gitlab.indiscale.com/caosdb/src/caosdb-proto.
*/ */
namespace caosdb::entity { namespace caosdb::entity {
......
...@@ -25,7 +25,12 @@ ...@@ -25,7 +25,12 @@
/** /**
* TransactionStatus indicates the current status of a transaction and, when it * TransactionStatus indicates the current status of a transaction and, when it
* has already terminated, whether the transaction has been successful or not. * has already terminated, whether the transaction has been successful or not.
*
* A status code of 0 denotes a generic success state, positive values indicate
* errors, and negative values indicate other states, such as different stages
* of a transaction in process.
*/ */
#include "caosdb/status_code.h" #include "caosdb/status_code.h"
#include "caosdb/exceptions.h" #include "caosdb/exceptions.h"
#include <memory> // for shared_ptr, unique_ptr #include <memory> // for shared_ptr, unique_ptr
...@@ -35,7 +40,7 @@ namespace caosdb::transaction { ...@@ -35,7 +40,7 @@ namespace caosdb::transaction {
using caosdb::StatusCode; using caosdb::StatusCode;
using caosdb::exceptions::AuthenticationError; using caosdb::exceptions::AuthenticationError;
using caosdb::exceptions::ConnectionError; using caosdb::exceptions::ConnectionError;
using caosdb::exceptions::GenericException; using caosdb::exceptions::Exception;
using caosdb::exceptions::TransactionError; using caosdb::exceptions::TransactionError;
/** /**
...@@ -43,6 +48,8 @@ using caosdb::exceptions::TransactionError; ...@@ -43,6 +48,8 @@ using caosdb::exceptions::TransactionError;
*/ */
class TransactionStatus { class TransactionStatus {
public: public:
// REFACTORING NEEDED: When you touch this code again consider writing a
// macro, because this is a lot of redundant code here...
inline static auto INITIAL() -> const TransactionStatus & { inline static auto INITIAL() -> const TransactionStatus & {
static const TransactionStatus initial( static const TransactionStatus initial(
StatusCode::INITIAL, caosdb::get_status_description(StatusCode::INITIAL)); StatusCode::INITIAL, caosdb::get_status_description(StatusCode::INITIAL));
...@@ -61,6 +68,9 @@ public: ...@@ -61,6 +68,9 @@ public:
} }
inline static auto RPC_ERROR(const std::string &details) inline static auto RPC_ERROR(const std::string &details)
-> const TransactionStatus { -> const TransactionStatus {
// We use the GENERIC_RPC_ERROR here because we might want to add further
// RPC_ERROR states with different error codes (which stem from GRPC) here
// in the future.
return TransactionStatus( return TransactionStatus(
StatusCode::GENERIC_RPC_ERROR, StatusCode::GENERIC_RPC_ERROR,
caosdb::get_status_description(StatusCode::GENERIC_RPC_ERROR) + caosdb::get_status_description(StatusCode::GENERIC_RPC_ERROR) +
...@@ -113,7 +123,7 @@ public: ...@@ -113,7 +123,7 @@ public:
case StatusCode::GENERIC_TRANSACTION_ERROR: case StatusCode::GENERIC_TRANSACTION_ERROR:
throw TransactionError(this->description); throw TransactionError(this->description);
default: default:
throw GenericException(StatusCode::GENERIC_ERROR, this->description); throw Exception(StatusCode::GENERIC_ERROR, this->description);
} }
} }
...@@ -130,7 +140,7 @@ public: ...@@ -130,7 +140,7 @@ public:
/** /**
* Return a description of the erroneous state. * Return a description of the erroneous state.
* *
* Returns an empty string if there is no description. * No description yields an empty string.
*/ */
inline auto GetDescription() const -> const std::string & { inline auto GetDescription() const -> const std::string & {
return this->description; return this->description;
......
...@@ -43,8 +43,6 @@ using boost::json::value; ...@@ -43,8 +43,6 @@ using boost::json::value;
/** /**
* @brief Read a text file into a string and return the file's content. * @brief Read a text file into a string and return the file's content.
*
* TODO use boost-filesystem's "load_string_file"!
*/ */
inline auto load_string_file(const path &path) -> std::string { inline auto load_string_file(const path &path) -> std::string {
std::string result; std::string result;
...@@ -52,11 +50,13 @@ inline auto load_string_file(const path &path) -> std::string { ...@@ -52,11 +50,13 @@ inline auto load_string_file(const path &path) -> std::string {
return result; return result;
} }
inline auto get_env_var(const char *key, const char *fall_back) -> const /**
char * { * @brief Return the environment variable KEY, or FALLBACK if it does not exist.
*/
inline auto get_env_var(const char *key, const char *fallback) -> const char * {
const char *val = getenv(key); const char *val = getenv(key);
if (val == nullptr) { if (val == nullptr) {
return fall_back; return fallback;
} else { } else {
return val; return val;
} }
...@@ -64,11 +64,11 @@ inline auto get_env_var(const char *key, const char *fall_back) -> const ...@@ -64,11 +64,11 @@ inline auto get_env_var(const char *key, const char *fall_back) -> const
/** /**
* @brief Return the value of an environment variable or - if undefined - the * @brief Return the value of an environment variable or - if undefined - the
* fall_back value. * fallback value.
*/ */
inline auto get_env_var(const std::string &key, const std::string &fall_back) inline auto get_env_var(const std::string &key, const std::string &fallback)
-> const std::string { -> const std::string {
const char *val = get_env_var(key.c_str(), fall_back.c_str()); const char *val = get_env_var(key.c_str(), fallback.c_str());
auto const result = std::string(val); auto const result = std::string(val);
return result; return result;
......
...@@ -79,9 +79,9 @@ typedef struct { ...@@ -79,9 +79,9 @@ typedef struct {
/** /**
* Return the environment variable of the given name. * Return the environment variable of the given name.
* *
* If the environment variable is not set, return the fall_back instead. * If the environment variable is not set, return the fallback instead.
*/ */
const char *caosdb_utility_get_env_var(const char *name, const char *fall_back); const char *caosdb_utility_get_env_var(const char *name, const char *fallback);
/** /**
* Return a description of the status code. * Return a description of the status code.
......
...@@ -358,7 +358,7 @@ auto ConfigurationManager::mReset() noexcept -> int { ...@@ -358,7 +358,7 @@ auto ConfigurationManager::mReset() noexcept -> int {
mClear(); mClear();
InitializeDefaults(); InitializeDefaults();
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} catch (const caosdb::exceptions::GenericException &exc) { } catch (const caosdb::exceptions::Exception &exc) {
return exc.GetCode(); return exc.GetCode();
} catch (const std::exception &exc) { } catch (const std::exception &exc) {
CAOSDB_LOG_ERROR(logger_name) CAOSDB_LOG_ERROR(logger_name)
...@@ -373,7 +373,7 @@ auto ConfigurationManager::mClear() noexcept -> int { ...@@ -373,7 +373,7 @@ auto ConfigurationManager::mClear() noexcept -> int {
json_configuration = value(nullptr); json_configuration = value(nullptr);
ConnectionManager::Reset(); ConnectionManager::Reset();
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} catch (const caosdb::exceptions::GenericException &exc) { } catch (const caosdb::exceptions::Exception &exc) {
return exc.GetCode(); return exc.GetCode();
} catch (const std::exception &exc) { } catch (const std::exception &exc) {
CAOSDB_LOG_ERROR(logger_name) CAOSDB_LOG_ERROR(logger_name)
...@@ -508,6 +508,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { ...@@ -508,6 +508,7 @@ auto ConfigurationManager::InitializeDefaults() -> int {
mLoadSingleJSONConfiguration(*configuration_file_path); mLoadSingleJSONConfiguration(*configuration_file_path);
} }
// Logging in the configuration leads to additional content.
if (this->json_configuration.is_object() && if (this->json_configuration.is_object() &&
this->json_configuration.as_object().contains("logging")) { this->json_configuration.as_object().contains("logging")) {
LoggingConfiguration logging_configuration = LoggingConfiguration logging_configuration =
......
...@@ -59,6 +59,7 @@ auto LoggingConfiguration::GetSinks() const ...@@ -59,6 +59,7 @@ auto LoggingConfiguration::GetSinks() const
SinkConfiguration::SinkConfiguration(std::string name, int level) SinkConfiguration::SinkConfiguration(std::string name, int level)
: LevelConfiguration(level), name(std::move(name)) {} : LevelConfiguration(level), name(std::move(name)) {}
[[nodiscard]] auto SinkConfiguration::GetName() const -> const std::string & { [[nodiscard]] auto SinkConfiguration::GetName() const -> const std::string & {
return this->name; return this->name;
} }
...@@ -77,6 +78,7 @@ auto SinkConfiguration::Configure(boost::log::settings &settings) const ...@@ -77,6 +78,7 @@ auto SinkConfiguration::Configure(boost::log::settings &settings) const
ConsoleSinkConfiguration::ConsoleSinkConfiguration(const std::string &name, ConsoleSinkConfiguration::ConsoleSinkConfiguration(const std::string &name,
int level) int level)
: SinkConfiguration(name, level) {} : SinkConfiguration(name, level) {}
[[nodiscard]] auto ConsoleSinkConfiguration::GetDestination() const [[nodiscard]] auto ConsoleSinkConfiguration::GetDestination() const
-> const std::string & { -> const std::string & {
CAOSDB_LOG_TRACE(logger_name) CAOSDB_LOG_TRACE(logger_name)
...@@ -93,12 +95,14 @@ auto ConsoleSinkConfiguration::Configure(boost::log::settings &settings) const ...@@ -93,12 +95,14 @@ auto ConsoleSinkConfiguration::Configure(boost::log::settings &settings) const
FileSinkConfiguration::FileSinkConfiguration(const std::string &name, int level) FileSinkConfiguration::FileSinkConfiguration(const std::string &name, int level)
: SinkConfiguration(name, level) {} : SinkConfiguration(name, level) {}
[[nodiscard]] auto FileSinkConfiguration::GetDestination() const [[nodiscard]] auto FileSinkConfiguration::GetDestination() const
-> const std::string & { -> const std::string & {
CAOSDB_LOG_TRACE(logger_name) CAOSDB_LOG_TRACE(logger_name)
<< "Enter FileSinkConfiguration::GetDestination()"; << "Enter FileSinkConfiguration::GetDestination()";
return this->destination; return this->destination;
} }
auto FileSinkConfiguration::SetDirectory(const std::string &directory) -> void { auto FileSinkConfiguration::SetDirectory(const std::string &directory) -> void {
this->directory = std::string(directory); this->directory = std::string(directory);
} }
...@@ -114,11 +118,13 @@ auto FileSinkConfiguration::Configure(boost::log::settings &settings) const ...@@ -114,11 +118,13 @@ auto FileSinkConfiguration::Configure(boost::log::settings &settings) const
SyslogSinkConfiguration::SyslogSinkConfiguration(const std::string &name, SyslogSinkConfiguration::SyslogSinkConfiguration(const std::string &name,
int level) int level)
: SinkConfiguration(name, level) {} : SinkConfiguration(name, level) {}
[[nodiscard]] auto SyslogSinkConfiguration::GetDestination() const [[nodiscard]] auto SyslogSinkConfiguration::GetDestination() const
-> const std::string & { -> const std::string & {
return this->destination; return this->destination;
} }
// Called if no custom logging settings are specified.
auto initialize_logging_defaults() -> int { auto initialize_logging_defaults() -> int {
// first: turn everything off // first: turn everything off
boost::log::settings off_settings; boost::log::settings off_settings;
...@@ -148,6 +154,7 @@ auto initialize_logging_defaults() -> int { ...@@ -148,6 +154,7 @@ auto initialize_logging_defaults() -> int {
return 0; return 0;
} }
// Called if custom logging settings are specified.
auto initialize_logging(const LoggingConfiguration &configuration) -> void { auto initialize_logging(const LoggingConfiguration &configuration) -> void {
boost::log::settings new_settings; boost::log::settings new_settings;
......
...@@ -56,9 +56,8 @@ const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() { ...@@ -56,9 +56,8 @@ const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() {
return caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE; return caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE;
} }
const char *caosdb_utility_get_env_var(const char *name, const char *caosdb_utility_get_env_var(const char *name, const char *fallback) {
const char *fall_back) { return caosdb::utility::get_env_var(name, fallback);
return caosdb::utility::get_env_var(name, fall_back);
} }
const char *caosdb_get_status_description(int code) { const char *caosdb_get_status_description(int code) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment