From f7a1aa64b01af11bf0bc65741ed9e6654def0645 Mon Sep 17 00:00:00 2001 From: Stuart Mark James <stuart.james@esrf.fr> Date: Thu, 4 Jul 2019 16:46:57 +0200 Subject: [PATCH] Added hide to att_conf, renamed InsertEvent->AddEvent, added an event time for data event errors --- CMakeLists.txt | 6 +++++- db-schema/schema.sql | 1 + src/HdbppDefines.hpp | 8 ++++---- src/HdbppTimescaleDb.cpp | 14 +++++++++++--- src/HdbppTxHistoryEvent.hpp | 2 +- test/HdbppTxHistoryEventTests.cpp | 24 ++++++++++++------------ 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fe0643..7cb5a9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,10 @@ set_target_properties(pqxx_shared PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") +set_target_properties(pqxx_static + PROPERTIES + POSITION_INDEPENDENT_CODE 1) + # Code Analysis ----------------------------------- if(HDBPP_TDB_ENABLE_CLANG) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -113,7 +117,7 @@ add_subdirectory(src) add_library(libhdbpp_timescale_shared_library SHARED ${SRC_FILES}) target_link_libraries(libhdbpp_timescale_shared_library - PUBLIC ${TDB_FOUND_LIBRARIES} pqxx_shared libhdbpp_headers spdlog Threads::Threads + PUBLIC ${TDB_FOUND_LIBRARIES} pqxx_static libhdbpp_headers spdlog Threads::Threads PRIVATE TangoInterfaceLibrary) target_include_directories(libhdbpp_timescale_shared_library diff --git a/db-schema/schema.sql b/db-schema/schema.sql index 1c2cd48..4445653 100755 --- a/db-schema/schema.sql +++ b/db-schema/schema.sql @@ -85,6 +85,7 @@ CREATE TABLE IF NOT EXISTS att_conf ( member text NOT NULL DEFAULT '', name text NOT NULL DEFAULT '', ttl int, + hide boolean DEFAULT false, PRIMARY KEY (att_conf_id), FOREIGN KEY (att_conf_type_id) REFERENCES att_conf_type (att_conf_type_id), FOREIGN KEY (att_conf_format_id) REFERENCES att_conf_format (att_conf_format_id), diff --git a/src/HdbppDefines.hpp b/src/HdbppDefines.hpp index 9e4f1ad..4df8099 100644 --- a/src/HdbppDefines.hpp +++ b/src/HdbppDefines.hpp @@ -42,10 +42,10 @@ namespace libhdbpp_compatibility namespace events { // attribute history events as strings, these are used in the storage system - const std::string InsertEvent = "add"; - const std::string StartEvent = "start"; - const std::string StopEvent = "stop"; - const std::string RemoveEvent = "remove"; + const std::string AddEvent = "add"; // represents a attribute added to the system + const std::string StartEvent = "start"; // represents when the attribute starts sending data + const std::string StopEvent = "stop"; // represents when the attribute stops sending data + const std::string RemoveEvent = "remove"; // represents a attribute removed from the system const std::string InsertParamEvent = "insert_param"; const std::string UpdateTTLEvent = "update_ttl"; const std::string PauseEvent = "pause"; diff --git a/src/HdbppTimescaleDb.cpp b/src/HdbppTimescaleDb.cpp index 4d8c2d7..d4e7c2e 100644 --- a/src/HdbppTimescaleDb.cpp +++ b/src/HdbppTimescaleDb.cpp @@ -148,13 +148,21 @@ void HdbppTimescaleDb::insert_Attr(Tango::EventData *event_data, HdbEventDataTyp { spdlog::trace("Event type is error for attribute: {}", event_data->attr_name); + // now time data is passed for errors, so create some + struct timeval tv; + struct Tango::TimeVal tango_tv; + gettimeofday(&tv, NULL); + tango_tv.tv_sec = tv.tv_sec; + tango_tv.tv_usec = tv.tv_usec; + tango_tv.tv_nsec = 0; + Conn->createTx<HdbppTxDataEventError>() .withName(event_data->attr_name) .withTraits(static_cast<Tango::AttrWriteType>(event_data_type.write_type), static_cast<Tango::AttrDataFormat>(event_data_type.data_format), event_data_type.data_type) .withError(string(event_data->errors[0].desc)) - .withEventTime(event_data->attr_value->get_date()) + .withEventTime(tango_tv) .withQuality(event_data->attr_value->get_quality()) .store(); } @@ -208,8 +216,8 @@ void HdbppTimescaleDb::configure_Attr( .withTraits(static_cast<Tango::AttrWriteType>(write_type), static_cast<Tango::AttrDataFormat>(format), type) .store(); - // add a start event - Conn->createTx<HdbppTxHistoryEvent>().withName(fqdn_attr_name).withEvent(events::StartEvent).store(); + // add an add event + Conn->createTx<HdbppTxHistoryEvent>().withName(fqdn_attr_name).withEvent(events::AddEvent).store(); } //============================================================================= diff --git a/src/HdbppTxHistoryEvent.hpp b/src/HdbppTxHistoryEvent.hpp index dc499b7..96f1d75 100644 --- a/src/HdbppTxHistoryEvent.hpp +++ b/src/HdbppTxHistoryEvent.hpp @@ -72,7 +72,7 @@ HdbppTxHistoryEvent<Conn> &HdbppTxHistoryEvent<Conn>::withEvent(unsigned char ev // without the need to decode a byte into a meaningful value. switch (event) { - case libhdbpp_compatibility::HdbppInsert: _event = events::InsertEvent; break; + case libhdbpp_compatibility::HdbppInsert: _event = events::AddEvent; break; case libhdbpp_compatibility::HdbppStart: _event = events::StartEvent; break; case libhdbpp_compatibility::HdbppStop: _event = events::StopEvent; break; case libhdbpp_compatibility::HdbppRemove: _event = events::RemoveEvent; break; diff --git a/test/HdbppTxHistoryEventTests.cpp b/test/HdbppTxHistoryEventTests.cpp index 2c627f4..346a49d 100644 --- a/test/HdbppTxHistoryEventTests.cpp +++ b/test/HdbppTxHistoryEventTests.cpp @@ -82,7 +82,7 @@ SCENARIO("Construct and store HdbppTxHistoryEvent data without error", "[hdbpp-t WHEN("Passing a valid configuration with method chaining") { - tx.withName(TestAttrFQDName).withEvent(events::InsertEvent); + tx.withName(TestAttrFQDName).withEvent(events::AddEvent); THEN("Storing the transaction does not raise an exception") { @@ -96,7 +96,7 @@ SCENARIO("Construct and store HdbppTxHistoryEvent data without error", "[hdbpp-t THEN("The data is the same as that passed via method chaining") { REQUIRE(conn.att_name == TestAttrFinalName); - REQUIRE(conn.att_last_event == events::InsertEvent); + REQUIRE(conn.att_last_event == events::AddEvent); } } } @@ -126,7 +126,7 @@ SCENARIO("When attempting to store invalid HdbppTxHistoryEvent states, errors ar } AND_WHEN("Setting a valid event and trying to store again") { - tx.withEvent(events::InsertEvent); + tx.withEvent(events::AddEvent); THEN("No exception is raised") { @@ -140,7 +140,7 @@ SCENARIO("When attempting to store invalid HdbppTxHistoryEvent states, errors ar { conn.disconnect(); REQUIRE(conn.isClosed()); - REQUIRE_NOTHROW(tx.withName(TestAttrFQDName).withEvent(events::InsertEvent)); + REQUIRE_NOTHROW(tx.withName(TestAttrFQDName).withEvent(events::AddEvent)); THEN("An exception is raised") { @@ -175,7 +175,7 @@ SCENARIO("HdbppTxHistoryEvent's overloaded functions return identical results wi tx2.withName(TestAttrFQDName); REQUIRE_NOTHROW(tx1.withEvent(libhdbpp_compatibility::HdbppInsert)); - REQUIRE_NOTHROW(tx2.withEvent(events::InsertEvent)); + REQUIRE_NOTHROW(tx2.withEvent(events::AddEvent)); THEN("The events are the same after storing") { @@ -228,43 +228,43 @@ SCENARIO("All event conversions result in correct events at store time", "[hdbpp { REQUIRE_NOTHROW(tx.withEvent(libhdbpp_compatibility::HdbppInsert).store()); - THEN("InsertEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::InsertEvent); } + THEN("AddEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::AddEvent); } } WHEN("Attempting to store event libhdbpp_compatibility::HdbppStart") { REQUIRE_NOTHROW(tx.withEvent(libhdbpp_compatibility::HdbppStart).store()); - THEN("InsertEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::StartEvent); } + THEN("AddEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::StartEvent); } } WHEN("Attempting to store event libhdbpp_compatibility::HdbppStop") { REQUIRE_NOTHROW(tx.withEvent(libhdbpp_compatibility::HdbppStop).store()); - THEN("InsertEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::StopEvent); } + THEN("AddEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::StopEvent); } } WHEN("Attempting to store event libhdbpp_compatibility::HdbppRemove") { REQUIRE_NOTHROW(tx.withEvent(libhdbpp_compatibility::HdbppRemove).store()); - THEN("InsertEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::RemoveEvent); } + THEN("AddEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::RemoveEvent); } } WHEN("Attempting to store event libhdbpp_compatibility::HdbppInsertParam") { REQUIRE_NOTHROW(tx.withEvent(libhdbpp_compatibility::HdbppInsertParam).store()); - THEN("InsertEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::InsertParamEvent); } + THEN("AddEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::InsertParamEvent); } } WHEN("Attempting to store event libhdbpp_compatibility::HdbppPause") { REQUIRE_NOTHROW(tx.withEvent(libhdbpp_compatibility::HdbppPause).store()); - THEN("InsertEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::PauseEvent); } + THEN("AddEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::PauseEvent); } } WHEN("Attempting to store event libhdbpp_compatibility::HdbppUpdateTTL") { REQUIRE_NOTHROW(tx.withEvent(libhdbpp_compatibility::HdbppUpdateTTL).store()); - THEN("InsertEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::UpdateTTLEvent); } + THEN("AddEvent is recorded at store time") { REQUIRE(conn.att_last_event == events::UpdateTTLEvent); } } } } -- GitLab