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 (3)
......@@ -107,6 +107,7 @@ trigger_inttest:
# ... or use main if possible...
- if [[ "$CI_COMMIT_REF_NAME" == "main" ]] ; then
CPPINT_REF=main ;
F_BRANCH=main ;
fi
- if echo "$CI_COMMIT_REF_NAME" | grep -c "^v" ; then
CPPINT_REF=main ;
......
......@@ -113,6 +113,7 @@ public:
friend class ConfigurationManager;
private:
auto ConvertLogLevel(const std::string &string_level) const -> int;
auto CreateConsoleSinkConfiguration(const object &from,
const std::string &name, int level) const
-> std::shared_ptr<caosdb::logging::SinkConfiguration>;
......@@ -236,7 +237,9 @@ private:
ConnectionConfigurationHelper connection_configuration_helper;
LoggingConfigurationHelper logging_configuration_helper;
inline ConfigurationManager() { InitializeDefaults(); };
inline ConfigurationManager(){
// InitializeDefaults();
};
/**
* Initialize this ConfigurationManager with the defaults.
......
......@@ -39,6 +39,7 @@ using caosdb::entity::v1alpha1::IdResponse;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoProperty = caosdb::entity::v1alpha1::Property;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoMessage = caosdb::entity::v1alpha1::Message;
/**
* Messages convey information about the state and result of transactions.
......@@ -63,10 +64,9 @@ public:
friend class Messages;
private:
explicit inline Message(caosdb::entity::v1alpha1::Message *wrapped)
: wrapped(wrapped){};
explicit inline Message(ProtoMessage *wrapped) : wrapped(wrapped){};
caosdb::entity::v1alpha1::Message *wrapped;
ProtoMessage *wrapped;
};
/**
......@@ -87,8 +87,7 @@ public:
private:
inline Messages() : wrapped(nullptr){};
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Message>
*wrapped;
::google::protobuf::RepeatedPtrField<ProtoMessage> *wrapped;
};
/**
......@@ -100,8 +99,7 @@ private:
*/
class Parent {
public:
explicit inline Parent(caosdb::entity::v1alpha1::Parent *wrapped)
: wrapped(wrapped){};
explicit inline Parent(ProtoParent *wrapped) : wrapped(wrapped){};
Parent();
/**
......@@ -185,7 +183,7 @@ private:
/**
* Message which serves as storage backend.
*/
mutable caosdb::entity::v1alpha1::Parent *wrapped;
mutable ProtoParent *wrapped;
// Messages errors;
// Messages warnings;
// Messages infos;
......@@ -216,8 +214,7 @@ public:
private:
inline Parents(){};
explicit inline Parents(
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent>
*wrapped)
::google::protobuf::RepeatedPtrField<ProtoParent> *wrapped)
: wrapped(wrapped){};
/**
......@@ -230,8 +227,7 @@ private:
* The collection of parent messages which serves as a backend for this
* class.
*/
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent>
*wrapped;
::google::protobuf::RepeatedPtrField<ProtoParent> *wrapped;
};
/**
......@@ -242,8 +238,7 @@ private:
*/
class Property {
public:
explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped)
: wrapped(wrapped){};
explicit inline Property(ProtoProperty *wrapped) : wrapped(wrapped){};
Property();
/**
......@@ -288,6 +283,10 @@ public:
* Set the name of this property.
*/
auto SetName(const std::string &name) -> void;
/**
* Set the description of this property.
*/
auto SetDescription(const std::string &description) -> void;
/**
* Set the importance of this property.
*/
......@@ -325,7 +324,7 @@ public:
private:
static auto CreateProtoProperty() -> ProtoProperty *;
mutable caosdb::entity::v1alpha1::Property *wrapped;
mutable ProtoProperty *wrapped;
};
/**
......@@ -353,8 +352,7 @@ public:
private:
inline Properties(){};
explicit inline Properties(
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Property>
*wrapped)
::google::protobuf::RepeatedPtrField<ProtoProperty> *wrapped)
: wrapped(wrapped){};
/**
......@@ -364,8 +362,7 @@ private:
*/
auto Append(const Property &property) -> void;
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Property>
*wrapped;
::google::protobuf::RepeatedPtrField<ProtoProperty> *wrapped;
};
/**
......@@ -442,6 +439,10 @@ public:
auto SetRole(const std::string &role) -> void;
auto SetName(const std::string &name) -> void;
/**
* Set the description of this entity.
*/
auto SetDescription(const std::string &description) -> void;
auto SetValue(const std::string &value) -> void;
auto SetUnit(const std::string &unit) -> void;
......
......@@ -38,10 +38,10 @@ namespace caosdb::logging {
const std::string logger_name = "caosdb::logging";
typedef boost::log::sources::severity_channel_logger<int, std::string>
typedef boost::log::sources::severity_channel_logger_mt<int, std::string>
boost_logger_class;
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class)
BOOST_LOG_GLOBAL_LOGGER(logger, boost_logger_class)
/**
* This class stores the integer log level.
......
......@@ -302,8 +302,9 @@ auto LoggingConfigurationHelper::CreateSinkConfiguration(
assert(from.contains("destination"));
const auto &destination =
std::string(from.at("destination").as_string().c_str());
int level = from.contains("level")
? static_cast<int>(from.at("level").as_int64())
? ConvertLogLevel(from.at("level").as_string().c_str())
: default_level;
if (destination == "file") {
......@@ -317,38 +318,43 @@ auto LoggingConfigurationHelper::CreateSinkConfiguration(
}
}
auto LoggingConfigurationHelper::CreateLoggingConfiguration(
const object &from) const -> LoggingConfiguration {
auto default_level_str = from.contains("level")
? std::string(from.at("level").as_string().c_str())
: "";
int default_level = 0;
auto LoggingConfigurationHelper::ConvertLogLevel(
const std::string &string_level) const -> int {
static std::map<std::string, int> log_level_names = {
{"", CAOSDB_DEFAULT_LOG_LEVEL}, {"off", CAOSDB_LOG_LEVEL_OFF},
{"fatal", CAOSDB_LOG_LEVEL_FATAL}, {"error", CAOSDB_LOG_LEVEL_ERROR},
{"warn", CAOSDB_LOG_LEVEL_WARN}, {"info", CAOSDB_LOG_LEVEL_INFO},
{"debug", CAOSDB_LOG_LEVEL_DEBUG}, {"trace", CAOSDB_LOG_LEVEL_TRACE},
{"all", CAOSDB_LOG_LEVEL_ALL}};
try {
default_level = CAOSDB_DEFAULT_LOG_LEVEL;
return log_level_names.at(string_level);
} catch (const std::out_of_range &exc) {
throw ConfigurationError("Unknown log level: " + default_level_str);
throw ConfigurationError("Unknown log level: " + string_level);
}
}
auto LoggingConfigurationHelper::CreateLoggingConfiguration(
const object &from) const -> LoggingConfiguration {
auto default_level_str = from.contains("level")
? std::string(from.at("level").as_string().c_str())
: "";
int default_level = ConvertLogLevel(default_level_str);
auto result = LoggingConfiguration(default_level);
if (default_level == CAOSDB_LOG_LEVEL_OFF) {
return result;
}
const auto &sinks = from.at("sinks").as_object();
if (!sinks.empty()) {
const auto *elem = sinks.begin();
if (from.contains("sinks")) {
const auto &sinks = from.at("sinks").as_object();
if (!sinks.empty()) {
const auto *elem = sinks.begin();
while (elem != sinks.end()) {
result.AddSink(CreateSinkConfiguration(
elem->value().as_object(), elem->key().to_string(), default_level));
elem = std::next(elem);
while (elem != sinks.end()) {
result.AddSink(CreateSinkConfiguration(
elem->value().as_object(), elem->key().to_string(), default_level));
elem = std::next(elem);
}
}
}
......
......@@ -114,6 +114,10 @@ auto Property::SetName(const std::string &name) -> void {
this->wrapped->set_name(name);
}
auto Property::SetDescription(const std::string &description) -> void {
this->wrapped->set_description(description);
}
auto Property::SetImportance(const std::string &importance) -> void {
this->wrapped->set_importance(importance);
}
......@@ -193,6 +197,10 @@ auto Entity::SetName(const std::string &name) -> void {
this->wrapped->set_name(name);
}
auto Entity::SetDescription(const std::string &description) -> void {
this->wrapped->set_description(description);
}
auto Entity::SetValue(const std::string &value) -> void {
this->wrapped->set_value(value);
}
......
......@@ -44,6 +44,10 @@
namespace caosdb::logging {
BOOST_LOG_GLOBAL_LOGGER_INIT(logger, boost_logger_class) {
boost_logger_class lg;
return lg;
}
LoggingConfiguration::LoggingConfiguration(int level)
: LevelConfiguration(level) {}
......@@ -156,6 +160,11 @@ auto initialize_logging_defaults() -> int {
// Called if custom logging settings are specified.
auto initialize_logging(const LoggingConfiguration &configuration) -> void {
// first: turn everything off
boost::log::settings off_settings;
off_settings["Core.DisableLogging"] = true;
boost::log::init_from_settings(off_settings);
boost::log::settings new_settings;
if (configuration.GetLevel() == CAOSDB_LOG_LEVEL_OFF) {
......
......@@ -35,6 +35,7 @@
namespace caosdb::entity {
using caosdb::entity::v1alpha1::IdResponse;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using caosdb::utility::get_arena;
TEST(test_entity, test_parent_setters) {
......@@ -260,4 +261,25 @@ TEST(test_entity, test_from_id_response) {
EXPECT_EQ(other_ent.GetInfos().At(0).GetDescription(), "info_desc");
EXPECT_EQ(other_ent.GetInfos().At(0).GetCode(), MessageCode::UNSPECIFIED);
}
TEST(test_entity, test_description) {
Entity entity;
Property property;
Parent parent;
EXPECT_EQ(entity.GetDescription(), "");
EXPECT_EQ(property.GetDescription(), "");
EXPECT_EQ(parent.GetDescription(), "");
entity.SetDescription("desc entity");
property.SetDescription("desc property");
// Parent has not setter
ProtoParent protoParent;
protoParent.set_description("desc parent");
parent = Parent(&protoParent);
EXPECT_EQ(entity.GetDescription(), "desc entity");
EXPECT_EQ(property.GetDescription(), "desc property");
EXPECT_EQ(parent.GetDescription(), "desc parent");
}
} // namespace caosdb::entity