Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • caosdb/src/caosdb-cpplib
1 result
Show changes
Commits on Source (6)
......@@ -18,7 +18,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.13)
set(libcaosdb_VERSION 0.0.6)
set(libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR 0)
......
# GENERAL
* >=conan-1.37.2
* >=cmake-3.14
* >=cmake-3.13
* >=gcc-10.2.0 | >=clang-11
# OPTIONAL
......
......@@ -8,7 +8,8 @@
We use [cmake](https://cmake.org) as build tool.
1. `mkdir build && cd build/`
0. clone/update the subrepo `git submodule update --init proto`
1. `mkdir build && cd build`
2. `conan install .. -s "compiler.libcxx=libstdc++11"`
3. `cmake -B . ..`
4. `cmake --build .`
......@@ -38,6 +39,7 @@ variable.
We use [Visual Studio 2019](https://visualstudio.microsoft.com/de/vs/features/cplusplus/)
as compiler. We use [cmake](https://cmake.org/download/) as build tool.
0. clone/update the subrepo `git submodule update --init proto`
1. `mkdir build`
2. `cd build`
3. `conan install .. -g visual_studio -s arch=x86_64 -s build_type=Release -s compiler.toolset=v142 -s compiler.version=16 -s compiler.runtime=MD --build=missing --update`
......@@ -46,6 +48,23 @@ as compiler. We use [cmake](https://cmake.org/download/) as build tool.
and build the project. (You can open Tools/Command Line/Developer Command
Prompt and execute `msbuild libcaosdb.sln /property:Configuration=Release`)
### Creating a Local Conan Build ##
Building and installing libcaosdb with Conan is just a single command:
`conan create . -s "compiler.libcxx=libstdc++11"`
For MacOS, you probably should adjust the option as mentioned above.
### Troubleshooting
#### `conan install` Fails Due to Missing Prebuilts
When `conan install` fails during the installation of the dependencies because
a precompiled package is not available for your specific settings, try adding
the `--build=missing` option: `conan install .. [ other options
] --build=missing`. This should download and compile the sources of the
dependencies.
## Unit Tests
### Build
......
......@@ -149,6 +149,9 @@ public:
return ConnectionManager::GetInstance().mGetConnection(name);
};
/**
* Get the connection marked by the "default" key in the configuration.
*/
inline static auto GetDefaultConnection()
-> const std::shared_ptr<Connection> & {
return ConnectionManager::GetInstance().mGetDefaultConnection();
......
......@@ -111,6 +111,12 @@ private:
friend class 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 {
public:
explicit inline Message(caosdb::entity::v1alpha1::Message *wrapped)
......
......@@ -32,9 +32,9 @@ using std::runtime_error;
/**
* @brief Generic exception class of the caosdb client library.
*/
class GenericException : public runtime_error {
class Exception : public runtime_error {
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) {}
[[nodiscard]] inline auto GetCode() const -> StatusCode { return this->code; }
......@@ -45,47 +45,47 @@ private:
/**
* @brief Exception for authentication errors.
*/
class AuthenticationError : public GenericException {
class AuthenticationError : public Exception {
public:
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.
*/
class ConnectionError : public GenericException {
class ConnectionError : public Exception {
public:
explicit ConnectionError(const std::string &what_arg)
: GenericException(StatusCode::CONNECTION_ERROR, what_arg) {}
: Exception(StatusCode::CONNECTION_ERROR, what_arg) {}
};
/**
* @brief The transaction terminated unsuccessfully.
*/
class TransactionError : public GenericException {
class TransactionError : public Exception {
public:
explicit TransactionError(const std::string &what_arg)
: GenericException(StatusCode::GENERIC_TRANSACTION_ERROR, what_arg) {}
: Exception(StatusCode::GENERIC_TRANSACTION_ERROR, what_arg) {}
};
/**
* @brief Exception for errors of the ConfigurationManager or other components
* of the configuration.
*/
class ConfigurationError : public GenericException {
class ConfigurationError : public Exception {
public:
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.
*/
class UnknownConnectionError : public GenericException {
class UnknownConnectionError : public Exception {
public:
explicit UnknownConnectionError(const std::string &what_arg)
: GenericException(StatusCode::UNKNOWN_CONNECTION_ERROR, what_arg) {}
: Exception(StatusCode::UNKNOWN_CONNECTION_ERROR, what_arg) {}
};
} // namespace caosdb::exceptions
......
......@@ -19,8 +19,8 @@
*
*/
#ifndef CAOSDB_LOG_LEVELS_H
#define CAOSDB_LOG_LEVELS_H
#ifndef CAOSDB_LOG_LEVEL_H
#define CAOSDB_LOG_LEVEL_H
#define CAOSDB_LOG_LEVEL_OFF 1000000
#define CAOSDB_LOG_LEVEL_FATAL 700
......
......@@ -43,6 +43,9 @@ typedef boost::log::sources::severity_channel_logger<int, std::string>
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class)
/**
* This class stores the integer log level.
*/
class LevelConfiguration {
public:
LevelConfiguration(int level) : level(level){};
......@@ -54,6 +57,11 @@ private:
class SinkConfiguration;
/**
* This class stores the logging level and log sinks.
*
* Sinks are represented by SinkConfiguration objects.
*/
class LoggingConfiguration : public LevelConfiguration {
public:
virtual ~LoggingConfiguration() = default;
......@@ -69,6 +77,23 @@ private:
auto initialize_logging_defaults() -> int;
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 {
public:
virtual ~SinkConfiguration() = default;
......@@ -104,6 +129,12 @@ private:
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 {
public:
virtual ~FileSinkConfiguration() = default;
......@@ -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);
/**
* Convenience function for the c-interface.
* Convenience function for the C interface.
*/
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);
/**
* Convenience function for the c-interface.
* Convenience function for the C interface.
*/
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);
/**
* Convenience function for the c-interface.
* Convenience function for the C interface.
*/
void caosdb_log_trace(const char *channel, const char *msg);
......
......@@ -30,6 +30,10 @@
* 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
* 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 {
......
......@@ -25,7 +25,12 @@
/**
* TransactionStatus indicates the current status of a transaction and, when it
* 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/exceptions.h"
#include <memory> // for shared_ptr, unique_ptr
......@@ -35,7 +40,7 @@ namespace caosdb::transaction {
using caosdb::StatusCode;
using caosdb::exceptions::AuthenticationError;
using caosdb::exceptions::ConnectionError;
using caosdb::exceptions::GenericException;
using caosdb::exceptions::Exception;
using caosdb::exceptions::TransactionError;
/**
......@@ -113,7 +118,7 @@ public:
case StatusCode::GENERIC_TRANSACTION_ERROR:
throw TransactionError(this->description);
default:
throw GenericException(StatusCode::GENERIC_ERROR, this->description);
throw Exception(StatusCode::GENERIC_ERROR, this->description);
}
}
......@@ -130,7 +135,7 @@ public:
/**
* 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 & {
return this->description;
......
......@@ -43,8 +43,6 @@ using boost::json::value;
/**
* @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 {
std::string result;
......@@ -52,11 +50,13 @@ inline auto load_string_file(const path &path) -> std::string {
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);
if (val == nullptr) {
return fall_back;
return fallback;
} else {
return val;
}
......@@ -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
* 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 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);
return result;
......
......@@ -81,9 +81,9 @@ typedef struct {
/**
* 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.
......
Subproject commit 4845aa8e479b85b50a130530bbc96a0cab4f8688
Subproject commit bff5455a899a69d5988366b2f4d175029a7e2362
......@@ -357,7 +357,7 @@ auto ConfigurationManager::mReset() noexcept -> int {
mClear();
InitializeDefaults();
return StatusCode::SUCCESS;
} catch (const caosdb::exceptions::GenericException &exc) {
} catch (const caosdb::exceptions::Exception &exc) {
return exc.GetCode();
} catch (const std::exception &exc) {
CAOSDB_LOG_ERROR(logger_name)
......@@ -372,7 +372,7 @@ auto ConfigurationManager::mClear() noexcept -> int {
json_configuration = value(nullptr);
ConnectionManager::Reset();
return StatusCode::SUCCESS;
} catch (const caosdb::exceptions::GenericException &exc) {
} catch (const caosdb::exceptions::Exception &exc) {
return exc.GetCode();
} catch (const std::exception &exc) {
CAOSDB_LOG_ERROR(logger_name)
......@@ -508,6 +508,7 @@ auto ConfigurationManager::InitializeDefaults() -> int {
mLoadSingleJSONConfiguration(*configuration_file_path);
}
// Logging in the configuration leads to additional content.
if (this->json_configuration.is_object() &&
this->json_configuration.as_object().contains("logging")) {
LoggingConfiguration logging_configuration =
......
......@@ -59,6 +59,7 @@ auto LoggingConfiguration::GetSinks() const
SinkConfiguration::SinkConfiguration(std::string name, int level)
: LevelConfiguration(level), name(std::move(name)) {}
[[nodiscard]] auto SinkConfiguration::GetName() const -> const std::string & {
return this->name;
}
......@@ -77,6 +78,7 @@ auto SinkConfiguration::Configure(boost::log::settings &settings) const
ConsoleSinkConfiguration::ConsoleSinkConfiguration(const std::string &name,
int level)
: SinkConfiguration(name, level) {}
[[nodiscard]] auto ConsoleSinkConfiguration::GetDestination() const
-> const std::string & {
CAOSDB_LOG_TRACE(logger_name)
......@@ -93,12 +95,14 @@ auto ConsoleSinkConfiguration::Configure(boost::log::settings &settings) const
FileSinkConfiguration::FileSinkConfiguration(const std::string &name, int level)
: SinkConfiguration(name, level) {}
[[nodiscard]] auto FileSinkConfiguration::GetDestination() const
-> const std::string & {
CAOSDB_LOG_TRACE(logger_name)
<< "Enter FileSinkConfiguration::GetDestination()";
return this->destination;
}
auto FileSinkConfiguration::SetDirectory(const std::string &directory) -> void {
this->directory = std::string(directory);
}
......@@ -114,11 +118,13 @@ auto FileSinkConfiguration::Configure(boost::log::settings &settings) const
SyslogSinkConfiguration::SyslogSinkConfiguration(const std::string &name,
int level)
: SinkConfiguration(name, level) {}
[[nodiscard]] auto SyslogSinkConfiguration::GetDestination() const
-> const std::string & {
return this->destination;
}
// Called if no custom logging settings are specified.
auto initialize_logging_defaults() -> int {
// first: turn everything off
boost::log::settings off_settings;
......@@ -148,6 +154,7 @@ auto initialize_logging_defaults() -> int {
return 0;
}
// Called if custom logging settings are specified.
auto initialize_logging(const LoggingConfiguration &configuration) -> void {
boost::log::settings new_settings;
......
......@@ -56,9 +56,8 @@ const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() {
return caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE;
}
const char *caosdb_utility_get_env_var(const char *name,
const char *fall_back) {
return caosdb::utility::get_env_var(name, fall_back);
const char *caosdb_utility_get_env_var(const char *name, const char *fallback) {
return caosdb::utility::get_env_var(name, fallback);
}
const char *caosdb_get_status_description(int code) {
......