From 46549c2adf1a6371988db19004276dea59a8a66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Wed, 3 Jul 2019 23:57:44 +0200 Subject: [PATCH 01/56] Add core functionnality for the templated RPC calls Since most of the development was made in another repository all the history has been squashed in this commit. --- xhalcore/include/xhal/rpc/call.h | 60 +++++ xhalcore/include/xhal/rpc/common.h | 313 +++++++++++++++++++++++++++ xhalcore/include/xhal/rpc/compat.h | 146 +++++++++++++ xhalcore/include/xhal/rpc/helper.h | 114 ++++++++++ xhalcore/include/xhal/rpc/register.h | 69 ++++++ 5 files changed, 702 insertions(+) create mode 100644 xhalcore/include/xhal/rpc/call.h create mode 100644 xhalcore/include/xhal/rpc/common.h create mode 100644 xhalcore/include/xhal/rpc/compat.h create mode 100644 xhalcore/include/xhal/rpc/helper.h create mode 100644 xhalcore/include/xhal/rpc/register.h diff --git a/xhalcore/include/xhal/rpc/call.h b/xhalcore/include/xhal/rpc/call.h new file mode 100644 index 0000000..f54a7ba --- /dev/null +++ b/xhalcore/include/xhal/rpc/call.h @@ -0,0 +1,60 @@ +/*! + * \file + * \brief This file contains all the functions needed to call + * remotely a RPC method + * + * \author Laurent Pétré + */ + +#ifndef XHAL_RPC_CALL_H +#define XHAL_RPC_CALL_H + +#include "xhal/rpc/common.h" +#include "xhal/rpc/compat.h" +#include "xhal/rpc/helper.h" + +#include "xhal/rpc/wiscrpcsvc.h" // move the header to xhal/extern/wiscrpcsvc.h ? + +#include + +namespace xhal { namespace rpc { + + /*! + * \brief Remotely call a RPC method + * + * The remote method called is defined by the template parameter + * \c Method. The arguments to give to the function are those from + * the \c Method::operator() signature and their types \b must be deducible. + */ + template::value, int>::type = 0 + > + helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args) + { + // The wisc::RPCMsg method name is taken from the typeid + // This is implementation dependent but g++ and clang++ + // follow the same convention + wisc::RPCMsg request(std::string(abiVersion) + "." + typeid(Method).name()); + MessageSerializer query{&request}; + + // Type conversion from args to serializable types + // must be performed in the same statement in order to + // make use of lifetime extension + query << helper::get_forward_as_tuple()(args...); + + // Remote call + const wisc::RPCMsg response = connection.call_method(request); + + // The RPC method can return a void so the void_holder is required + compat::void_holder> return_v; + + MessageDeserializer reply{&response}; + reply >> return_v; + + return return_v.get(); + } + +}} + +#endif diff --git a/xhalcore/include/xhal/rpc/common.h b/xhalcore/include/xhal/rpc/common.h new file mode 100644 index 0000000..f00f410 --- /dev/null +++ b/xhalcore/include/xhal/rpc/common.h @@ -0,0 +1,313 @@ +/*! + * \file + * \brief Contains the classes required for defining remotely callable RPC methods + * + * \author Laurent Pétré + */ + +#ifndef XHAL_RPC_COMMON_H +#define XHAL_RPC_COMMON_H + +#include "xhal/rpc/compat.h" + +#include +#include +#include + +#include "xhal/rpc/wiscRPCMsg.h" // move the header to "xhal/extern/wiscRPCMsg.h" ? + +namespace xhal { namespace rpc { + + /*! + * \brief Defines the templated RPC ABI version + */ + static constexpr const char* abiVersion = "v1"; + + /*! + * \brief Class whose all remotely callable RPC method must inherit from + * + * The required inheritance is used as a compile time check so a developer + * cannot remotely call a local function by mistake. + */ + struct Method + { + /*! + * \brief The operator call must be define once and only once per + * RPC method. + * + * This templated operator declaration is only shown as an example and + * emphasizes the need of defining it in child classes. + * + * \warnng The call operator \b must be defined as \c const. + */ + template R operator()(Args...) const; + }; + + /*! + * \brief Base of the \c MessageSerializer and \c MessageDeserializer classes + * + * \c MessageBase provides the key index tracking functionnality which + * is mandatory for serialization. + */ + class MessageBase { + + /*! + * \brief Index to the next free/unread key + */ + uint32_t _keyIdx = 0; + + protected: + + /* + * \brief Returns the next free/unread key + */ + inline uint32_t dispenseKey() { return _keyIdx++; } + + }; + + /*! + * \brief This class serializes parameters into a \c wisc::RPCMsg + */ + class MessageSerializer : public MessageBase + { + + protected: + + wisc::RPCMsg *m_wiscMsg; + + /* + * \brief Supresses implicit type conversions + * + * Every type not defined hereunder is delete by this templated function. + * It aims at enforcing maximum type compatibility with the UW RPC API by + * remembering the developer that she/he can transmit defined types over the + * network. + */ + template void save(T) = delete; + + /*! + * \brief Adds a \c std::uint32_t to the message + */ + inline void save(const std::uint32_t value) { + m_wiscMsg->set_word(std::to_string(dispenseKey()), value); + } + + /*! + * \brief Adds a \c std::vector to the message + */ + inline void save(const std::vector &value) { + m_wiscMsg->set_word_array(std::to_string(dispenseKey()), value); + } + + /*! + * \brief Adds a \c std::string to the message + */ + inline void save(const std::string &value) { + m_wiscMsg->set_string(std::to_string(dispenseKey()), value); + } + + /*! + * \brief Adds a \c std::vector to the message + */ + inline void save(const std::vector &value) { + m_wiscMsg->set_string_array(std::to_string(dispenseKey()), value); + } + + /*! + * \brief Adds the content of a \c void_holder to the message + * + * It should be used when setting the result from a function call. + */ + template inline void save(const compat::void_holder &holder) { + this->save(holder.get()); + } + + /*! + * \brief Specialization for the \c void special case + */ + inline void save(compat::void_holder) {} + + /*! + * \brief Serializes the arguments from a \c std::tuple + * + * \c std::tuple content is add from left to right to the message + * via a recursive template. It should be to serialize function arguments. + */ + template::type = 0 + > + inline void save(const std::tuple &args) { + this->save(std::get(args)); + this->save(args); + } + + /*! + * \brief Terminal call + */ + template::type = 0 + > + inline void save(const std::tuple &) {} + + public: + + /*! + * \brief Constructor + * + * Data are serialized into the \c wiscMsg message. + */ + explicit MessageSerializer(wisc::RPCMsg *wiscMsg) noexcept : m_wiscMsg{wiscMsg} {} + + /*! + * \brief Allows to serialize data into the message with a natural interface + */ + template + MessageSerializer & operator<<(const T &t) { + this->save(t); + return *this; + } + + /*! + * \brief Behaves as \c operator<< + * + * Is used for providing a unifed interface between \c MessageSerializer and + * \c MessageDeserializer so custom types serialization can be defined in a single + * function. + */ + template + MessageSerializer & operator&(const T &t) { + this->save(t); + return *this; + } + + }; + + /*! + * \brief This class deserializes parameters from a \c wisc::RPCMsg + * + * While it cannot be made \c const because deserializing requires to keep + * track of the state, this class guarentees that the original \c wisc::RPCMsg + * object will remain untouched. + */ + class MessageDeserializer : public MessageBase { + + protected: + + const wisc::RPCMsg *m_wiscMsg; + + /* + * \brief Supresses implicit type conversion + * + * Every type not defined hereunder is delete by this templated function. + * It aims at enforcing maximum type compatibility with the UW RPC API by + * remembering the developer that she/he can transmit defined types over the + * network. + */ + template void load(T) = delete; + + /*! + * \brief Retrieves a \c std::uint32_t from the message + */ + inline void load(uint32_t &value) { + value = m_wiscMsg->get_word(std::to_string(dispenseKey())); + } + + /*! + * \brief Retrieves a \c std::vector from the message + */ + inline void load(std::vector &value) { + value = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); + } + + /*! + * \brief Retrieves a \c std::string from the message + */ + inline void load(std::string &value) { + value = m_wiscMsg->get_string(std::to_string(dispenseKey())); + } + + /*! + * \brief Retrieves a \c std::vector from the message + */ + inline void load(std::vector & value) { + value = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); + } + + /*! + * \brief Retrieve a \c T parameter from the message and stores it inside + * a \c void_holder. + * + * It should be used when setting the result from a function. + */ + template inline void load(compat::void_holder &value) { + this->load(value.get()); + } + + /*! + * \brief Specialization for the \c void special case + */ + inline void load(compat::void_holder) {} + + /*! + * \brief Fills in a \c std::tuple with data from the message + * + * \c std::tuple content is filled from left to right from the message + * via a recursive template. It should be use to deserialize function + * arguments. + */ + template::type = 0 + > + inline void load(std::tuple &args) { + this->load(std::get(args)); + this->load(args); + } + + /*! + * \brief Terminal call + */ + template::type = 0 + > + inline void load(const std::tuple &) { } + + public: + + /*! + * \brief Constructor + * + * Data are retrieved from the provided \c wiscMsg message. + */ + explicit MessageDeserializer(const wisc::RPCMsg *wiscMsg) noexcept : m_wiscMsg{wiscMsg} {} + + /*! + * \brief Allows to deserialiaze data from the message with a natural interface + */ + template + MessageDeserializer & operator>>(T &t) { + this->load(t); + return *this; + } + + /*! + * \brief Behaves as \c operator<< + * + * Is used for providing a unifed interface between \c MessageSerializer and + * \c MessageDeserializer so custom types serialization can be defined in a single + * function. + */ + template + MessageDeserializer & operator&(T &t) { + load(t); + return *this; + } + + }; + +} } + +#endif diff --git a/xhalcore/include/xhal/rpc/compat.h b/xhalcore/include/xhal/rpc/compat.h new file mode 100644 index 0000000..90f55d0 --- /dev/null +++ b/xhalcore/include/xhal/rpc/compat.h @@ -0,0 +1,146 @@ +/*! + * \file + * \brief Compatibility functionalities for C++11 + * + * This file includes all the functionalities that could advantageously be + * replaced with newer versions of C++, e.g. C++14 and C++17. + * + * Since the content of this file implements missing functionalties in the + * C++11 standard, the coding style follows what is found in the STL. + * + * \author Laurent Pétré + */ + +#ifndef XHAL_RPC_COMPAT_H +#define XHAL_RPC_COMPAT_H + +#include +#include + +namespace xhal { namespace rpc { namespace compat { + + /*! + * \brief This class can encapsulates any type, including \c void + * + * \c void is an incomplete type and cannot be easily used in fully generic + * templates. This class is designed to hold any type, including `void` so that + * it can be used in generic templates. + * + * The embedded object can be retrieved with the \c get() methods. + * + * In C++17 any code using this class is easily replaced with the + * constexpr if statement. + */ + template struct void_holder + { + T t; + T &get() { return t; } + const T &get() const { return t; } + }; + + /*! + * \brief Specialization for the \c void type + */ + template<> struct void_holder + { + void get() const { return; } + }; + + /*! + * \brief This template class defines an indices sequence + * + * Please look at the \c integer_sequence from C++14 to get more + * information. + */ + template struct index_sequence {}; + + /*! + * \brief Generates an indices sequence + * + * The code follows the usual O(n) implementation. + * + * You can have a look at https://blog.galowicz.de/2016/06/24/integer_sequences_at_compile_time/ + * for more information. + */ + template struct index_sequence_gen; + + /*! + * \brief Non-terminal call + */ + template struct index_sequence_gen + { + // I is the recursion index + // N... are the generated indices. + using type = typename index_sequence_gen::type; + }; + + /*! + * \brief Terminal call + */ + template struct index_sequence_gen<0, N...> + { + using type = index_sequence; + }; + + /*! + * \brief Helper making an index sequence from \c 0 to \c N-1 + * + * Remind that an index sequence is the non-type template parameter of a + * specialization of the \c index_sequence template class. + */ + template + using make_index_sequence = typename index_sequence_gen::type; + + /*! + * \brief Calls a function with arguments from a \c std::tuple + * + * This function is the implementation part of a specialized \c std::apply + * implementation. More information can be found in the C++17 standard. + * + * Please note that these functions are applied to our case and do not + * pretend to respect the C++17 standard in any way. Moreover the \c void + * return case is handled with our \c void_holder container. This imposes + * the first template argument to be explicitly set when calling \c tuple_apply + */ + template + auto tuple_apply_impl(F &&f, const std::tuple &tuple, index_sequence) + -> decltype(std::forward(f)(std::get(tuple)...)) + { + return std::forward(f)(std::get(tuple)...); + } + + /*! + * \brief Generic case + */ + template::value, int>::type = 0 + > + void_holder tuple_apply(F &&f, const std::tuple &tuple) + { + return void_holder{ + tuple_apply_impl(std::forward(f), tuple, make_index_sequence{}) + }; + } + + /*! + * \brief Specialization for the \c void type + */ + template::value, int>::type = 0 + > + void_holder tuple_apply(F &&f, const std::tuple &tuple) + { + tuple_apply_impl(std::forward(f), tuple, make_index_sequence{}); + return {}; + } + +} } } + +#endif diff --git a/xhalcore/include/xhal/rpc/helper.h b/xhalcore/include/xhal/rpc/helper.h new file mode 100644 index 0000000..c3e3901 --- /dev/null +++ b/xhalcore/include/xhal/rpc/helper.h @@ -0,0 +1,114 @@ +/*! + * \file + * \brief Centralize all the template helper tools + * + * Since the content of this file could be integrated into a C++ + * standard template metaprogramming, the coding style follows + * what is found in the STL. + * + * \author Laurent Pétré + */ + +#ifndef XHAL_RPC_HELPER_H +#define XHAL_RPC_HELPER_H + +#include + +namespace xhal { namespace rpc { namespace helper { + + /*! + * \brief Allows to extract types of a functor + * + * This templated class provides the return type and argument types + * of a functor as traits. + * + * * \c return_type is the functor return type + * * \c decay_args_type are the decayed (cv-qualifiers and reference are + * removed) argument types in a \c std::tuple + * * \c forward_as_tuple returns a function converting its arguments + * to the arguments functor types + * + * Inspired by https://stackoverflow.com/a/10400131 + */ + template struct functor_traits; + + template + struct functor_traits + { + using return_type = R; + using decay_args_type = std::tuple::type...>; + + static constexpr inline auto forward_as_tuple() { + return [](Args&&... args){ return std::forward_as_tuple(args...); }; + } + }; + + /*! + * \brief Implementation of \c functor_return_t + * + * Should not be used as a function. + */ + template, + typename R = typename Traits::return_type + > + R functor_return_t_impl(Func); + + /*! + * \brief Return type of the \c Obj functor + * + * Only works with \c const call operators since \c functor_traits is + * only defined for those. + */ + template + using functor_return_t = decltype(functor_return_t_impl(&Obj::operator())); + + /*! + * \brief Implementation of \c functor_decay_args_t + * + * Should not be used as a function. + */ + template, + typename Args = typename Traits::decay_args_type + > + Args functor_decay_args_t_impl(Func); + + /*! + * \brief \c std::tuple whose types are the functor argument types + * + * Only works with \c const call operators since \c functor_traits is + * only defined for those. + */ + template + using functor_decay_args_t = decltype(functor_decay_args_t_impl(&Obj::operator())); + + /*! + * \brief Helper function to forward as a tuple matching the functor signature + */ + template + constexpr inline auto get_forward_as_tuple() { + return functor_traits::forward_as_tuple(); + } + + /*! + * \brief Checks whether the template parameter \c T is a \c std::tuple + */ + template + struct is_tuple_impl : std::false_type {}; + + template + struct is_tuple_impl> : std::true_type {}; + + /*! + * \brief Helper alias for cv-qualified and reference types + */ + template + using is_tuple = is_tuple_impl::type>; + +} } } + +#endif diff --git a/xhalcore/include/xhal/rpc/register.h b/xhalcore/include/xhal/rpc/register.h new file mode 100644 index 0000000..15d6473 --- /dev/null +++ b/xhalcore/include/xhal/rpc/register.h @@ -0,0 +1,69 @@ +/*! + * \file + * \brief This file contains all the functions needed to register + * a remotely callable RPC method + * + * \author Laurent Pétré + */ + +#ifndef XHAL_RPC_REGSTER_H +#define XHAL_RPC_REGSTER_H + +#include "xhal/rpc/common.h" +#include "xhal/rpc/compat.h" +#include "xhal/rpc/helper.h" + +#include "moduleapi.h" // Only present in the CTP7 modules + +#include + +namespace xhal { namespace rpc { + + /*! + * \brief Locally invoke a RPC method + * + * This function is the wrapper called for every remote function call. It + * deserializes the arguments from the \c wisc::RPCMsg, calls the local functor + * and then serializes the return value to the \c wisc::RPCMsg. + */ + template::value, int>::type = 0 + > + void invoke(const wisc::RPCMsg *request, wisc::RPCMsg *response) noexcept + { + // Remove the cv-qualifiers and references since we need + // a copy of the object + helper::functor_decay_args_t args; + + MessageDeserializer query(request); + query >> args; + + // Call the Method functor with the arguments received from + // the RPC message + auto result = compat::tuple_apply>(Method{}, args); + + // Serialize the reply + MessageSerializer reply(response); + reply << result; + } + + /*! + * \brief Register a RPC method into the \c ModuleManager + * + * This helper function register a RPC method with the right parameters + * so it can be remotely called. + */ + template + void registerMethod(ModuleManager *modmgr) + { + // The method name is taken from the typeid + // This is implementation dependent but g++ and clang++ + // follow the same convention + return modmgr->register_method(abiVersion, + typeid(Method).name(), + xhal::rpc::invoke); + } + +}} + +#endif From 284010fc83b15e3b5188e28aa08db20c774dc2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Wed, 10 Jul 2019 23:33:08 +0200 Subject: [PATCH 02/56] Add support for `std::array` of integral types --- xhalcore/include/xhal/rpc/common.h | 28 ++++++++++++++++++++++++++-- xhalcore/include/xhal/rpc/helper.h | 7 +++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/xhalcore/include/xhal/rpc/common.h b/xhalcore/include/xhal/rpc/common.h index f00f410..0613ce3 100644 --- a/xhalcore/include/xhal/rpc/common.h +++ b/xhalcore/include/xhal/rpc/common.h @@ -9,7 +9,9 @@ #define XHAL_RPC_COMMON_H #include "xhal/rpc/compat.h" +#include "xhal/rpc/helper.h" +#include #include #include #include @@ -113,6 +115,17 @@ namespace xhal { namespace rpc { m_wiscMsg->set_string_array(std::to_string(dispenseKey()), value); } + /*! + * \brief Adds a \c std::array to the message where \c T is an integral type (except \c bool) + */ + template::value && !helper::is_bool::value, int>::type = 0 + > + inline void save(const std::array &value) { + m_wiscMsg->set_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); + } + /*! * \brief Adds the content of a \c void_holder to the message * @@ -231,12 +244,23 @@ namespace xhal { namespace rpc { /*! * \brief Retrieves a \c std::vector from the message */ - inline void load(std::vector & value) { + inline void load(std::vector &value) { value = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); } /*! - * \brief Retrieve a \c T parameter from the message and stores it inside + * \brief Retrieves a \c std::array from the message where \c T is an integral type (except \c bool) + */ + template::value && !helper::is_bool::value, int>::type = 0 + > + inline void load(std::array &value) { + m_wiscMsg->get_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); + } + + /*! + * \brief Retrieves a \c T parameter from the message and stores it inside * a \c void_holder. * * It should be used when setting the result from a function. diff --git a/xhalcore/include/xhal/rpc/helper.h b/xhalcore/include/xhal/rpc/helper.h index c3e3901..d23b3f7 100644 --- a/xhalcore/include/xhal/rpc/helper.h +++ b/xhalcore/include/xhal/rpc/helper.h @@ -13,6 +13,7 @@ #define XHAL_RPC_HELPER_H #include +#include namespace xhal { namespace rpc { namespace helper { @@ -94,6 +95,12 @@ namespace xhal { namespace rpc { namespace helper { return functor_traits::forward_as_tuple(); } + /*! + * \brief Checks whether the template parameter \c T is a \c bool + */ + template + using is_bool = std::is_same::type, bool>; + /*! * \brief Checks whether the template parameter \c T is a \c std::tuple */ From 4d8223badb619c84e752e4939b60407d6b523645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Thu, 11 Jul 2019 00:14:53 +0200 Subject: [PATCH 03/56] Add support of `std::map` --- xhalcore/include/xhal/rpc/common.h | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/xhalcore/include/xhal/rpc/common.h b/xhalcore/include/xhal/rpc/common.h index 0613ce3..2bd171d 100644 --- a/xhalcore/include/xhal/rpc/common.h +++ b/xhalcore/include/xhal/rpc/common.h @@ -13,7 +13,9 @@ #include #include +#include #include +#include #include #include "xhal/rpc/wiscRPCMsg.h" // move the header to "xhal/extern/wiscRPCMsg.h" ? @@ -126,6 +128,25 @@ namespace xhal { namespace rpc { m_wiscMsg->set_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); } + /*! + * \brief Adds a \c std::map to the message where \c T is a serializable type + */ + template inline void save(const std::map &value) { + // The first RPC key stores the std::map keys + // This is required to know the std::map size at deserialization + const auto keysKey = dispenseKey(); + + std::vector keys{}; + keys.reserve(value.size()); + + for (const auto & elem : value) { + keys.push_back(elem.first); + this->save(elem.second); + } + + m_wiscMsg->set_word_array(std::to_string(keysKey), keys); + } + /*! * \brief Adds the content of a \c void_holder to the message * @@ -259,6 +280,19 @@ namespace xhal { namespace rpc { m_wiscMsg->get_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); } + /*! + * \brief Retrieves a \c std::map from the message where \c T is a serializable type + */ + template inline void load(std::map &value) { + const auto keys = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); + + for (const auto & key: keys) { + T val; + this->load(val); + value.emplace(key, std::move(val)); + } + } + /*! * \brief Retrieves a \c T parameter from the message and stores it inside * a \c void_holder. From 2a96da939371fbfbe304bf0a9a2f6de64cb9b394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Thu, 11 Jul 2019 00:24:06 +0200 Subject: [PATCH 04/56] Add support for `std::map` --- xhalcore/include/xhal/rpc/common.h | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/xhalcore/include/xhal/rpc/common.h b/xhalcore/include/xhal/rpc/common.h index 2bd171d..8723294 100644 --- a/xhalcore/include/xhal/rpc/common.h +++ b/xhalcore/include/xhal/rpc/common.h @@ -147,6 +147,25 @@ namespace xhal { namespace rpc { m_wiscMsg->set_word_array(std::to_string(keysKey), keys); } + /*! + * \brief Adds a \c std::map to the message where \c T is a serializable type + */ + template inline void save(const std::map &value) { + // The first RPC key stores the std::map keys + // This is required to know the std::map size at deserialization + const auto keysKey = dispenseKey(); + + std::vector keys{}; + keys.reserve(value.size()); + + for (const auto & elem : value) { + keys.push_back(elem.first); + this->save(elem.second); + } + + m_wiscMsg->set_string_array(std::to_string(keysKey), keys); + } + /*! * \brief Adds the content of a \c void_holder to the message * @@ -293,6 +312,19 @@ namespace xhal { namespace rpc { } } + /*! + * \brief Retrieves a \c std::map from the message where \c T is a serializable type + */ + template inline void load(std::map &value) { + const auto keys = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); + + for (const auto & key: keys) { + T val; + this->load(val); + value.emplace(key, std::move(val)); + } + } + /*! * \brief Retrieves a \c T parameter from the message and stores it inside * a \c void_holder. From cb19bda4ec5cfd2aa70796b549571929fb403bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Thu, 11 Jul 2019 01:13:47 +0200 Subject: [PATCH 05/56] Add support for custom types --- xhalcore/include/xhal/rpc/common.h | 107 +++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/xhalcore/include/xhal/rpc/common.h b/xhalcore/include/xhal/rpc/common.h index 8723294..5cc76a7 100644 --- a/xhalcore/include/xhal/rpc/common.h +++ b/xhalcore/include/xhal/rpc/common.h @@ -79,15 +79,22 @@ namespace xhal { namespace rpc { wisc::RPCMsg *m_wiscMsg; - /* - * \brief Supresses implicit type conversions + /*! + * \brief Serializes custom types if possible or else supresses implicit type conversions * - * Every type not defined hereunder is delete by this templated function. - * It aims at enforcing maximum type compatibility with the UW RPC API by - * remembering the developer that she/he can transmit defined types over the - * network. - */ - template void save(T) = delete; + * Every type not defined hereunder is taken care of by this templated function. + * The function serves two purposes: + * + * 1. It delegates the serialization to a well-known function. + * 2. It aims at enforcing maximum type compatibility with the UW RPC API by + * remembering the developer that she/he can transmit defined types over the + * network. + */ + template inline void save(const T &t) { + // This const_cast is safe when the API is used as intented + // More precisely when the object t is modified only with the operator& + serialize(*this, const_cast(t)); + } /*! * \brief Adds a \c std::uint32_t to the message @@ -217,7 +224,7 @@ namespace xhal { namespace rpc { * \brief Allows to serialize data into the message with a natural interface */ template - MessageSerializer & operator<<(const T &t) { + inline MessageSerializer & operator<<(const T &t) { this->save(t); return *this; } @@ -230,7 +237,7 @@ namespace xhal { namespace rpc { * function. */ template - MessageSerializer & operator&(const T &t) { + inline MessageSerializer & operator&(const T &t) { this->save(t); return *this; } @@ -250,15 +257,20 @@ namespace xhal { namespace rpc { const wisc::RPCMsg *m_wiscMsg; - /* - * \brief Supresses implicit type conversion + /*! + * \brief Deserializes custom types if possible or else supresses implicit type conversion * - * Every type not defined hereunder is delete by this templated function. - * It aims at enforcing maximum type compatibility with the UW RPC API by - * remembering the developer that she/he can transmit defined types over the - * network. + * Every type not defined hereunder is taken care of by this templated function. + * The function serves two purposes: + * + * 1. It delegates the deserialization to a well-known function. + * 2. It aims at enforcing maximum type compatibility with the UW RPC API by + * remembering the developer that she/he can transmit defined types over the + * network. */ - template void load(T) = delete; + template inline void load(T &t) { + serialize(*this, t); + } /*! * \brief Retrieves a \c std::uint32_t from the message @@ -363,7 +375,7 @@ namespace xhal { namespace rpc { typename... Args, typename std::enable_if::type = 0 > - inline void load(const std::tuple &) { } + inline void load(std::tuple &) { } public: @@ -378,7 +390,7 @@ namespace xhal { namespace rpc { * \brief Allows to deserialiaze data from the message with a natural interface */ template - MessageDeserializer & operator>>(T &t) { + inline MessageDeserializer & operator>>(T &t) { this->load(t); return *this; } @@ -391,13 +403,66 @@ namespace xhal { namespace rpc { * function. */ template - MessageDeserializer & operator&(T &t) { - load(t); + inline MessageDeserializer & operator&(T &t) { + this->load(t); return *this; } }; + /*! + * \brief Provides a default (de)serialiazer in case the intrusive method is used + */ + template + inline void serialize(Message &msg, T &t) { + t.serialize(msg); + } + + /*! + * \brief Serializer for \c std::array where \c is a serializable type + * + * This a simple example of custom type serialization. + * + * The library provides two custom type serialization methods: + * + * 1. The intrusive method + * 2. The non-intrusive method + * + * Let's take an example : + * + * \code{.cpp} + * struct Point + * { + * std::uint32_t x, y; + * + * // The intrusive version is implemented as a new member function + * // which takes a message as parameter (i.e. the serializer or deserializer) + * template inline void serialize(Message & msg) { + * msg & x & y; + * } + * }; + * + * // The non-intrusive version allows to serialize objects defined in a library + * // Simply define the serialize function in the xhal::rpc namespace with two parameters + * // (1) A message (i.e. the serializer or deserializer) and (2) the custom type + * namespace xhal { namspace rpc { + * template inline void serialize(Message &msg, Point &point) { + * msq & point.x & point.y; + * } + * } } + * \endcode + * + * \warning In order to work as intended the \c serialize functions \b MUST modify + * the object only with the \c operator& + * + */ + template + inline void serialize(Message &msg, std::array &value) { + for (auto & elem: value) { + msg & elem; + } + } + } } #endif From cdb1f63f9e4c866e79cd1547d731dedd42b4e924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Mon, 22 Jul 2019 23:11:13 +0200 Subject: [PATCH 06/56] Relax namespace constraints for custom type serializers Allow ADL usage in the documentation wording. --- xhalcore/include/xhal/rpc/common.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xhalcore/include/xhal/rpc/common.h b/xhalcore/include/xhal/rpc/common.h index 5cc76a7..b2582ca 100644 --- a/xhalcore/include/xhal/rpc/common.h +++ b/xhalcore/include/xhal/rpc/common.h @@ -443,8 +443,9 @@ namespace xhal { namespace rpc { * }; * * // The non-intrusive version allows to serialize objects defined in a library - * // Simply define the serialize function in the xhal::rpc namespace with two parameters - * // (1) A message (i.e. the serializer or deserializer) and (2) the custom type + * // Simply define the serialize function in the xhal::rpc namespace or the namespace + * // where the type is defined with two parameters (1) A message (i.e. the serializer + * // or deserializer) and (2) the custom type * namespace xhal { namspace rpc { * template inline void serialize(Message &msg, Point &point) { * msq & point.x & point.y; @@ -454,10 +455,11 @@ namespace xhal { namespace rpc { * * \warning In order to work as intended the \c serialize functions \b MUST modify * the object only with the \c operator& - * */ template inline void serialize(Message &msg, std::array &value) { + // The std::array size is known at compile time (and part of + // the signature), so we don't need to serialize it for (auto & elem: value) { msg & elem; } From a7e82c0e2c399023b65e083e0a1e4e56b4d2d543 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 20 Jul 2019 18:06:41 +0200 Subject: [PATCH 07/56] Catch exceptions thrown by RPC methods All exceptions thrown by RPC methods are caught, and an error message is sent via the "error" key. In order to help debugging, the type of the exception is also sent back to the client. Build system support is left for later. --- xhalcore/include/xhal/rpc/exceptions.h | 62 ++++++++++++++++++++++++ xhalcore/include/xhal/rpc/register.h | 67 +++++++++++++++++++++----- xhalcore/src/common/rpc/exceptions.cpp | 52 ++++++++++++++++++++ 3 files changed, 170 insertions(+), 11 deletions(-) create mode 100644 xhalcore/include/xhal/rpc/exceptions.h create mode 100644 xhalcore/src/common/rpc/exceptions.cpp diff --git a/xhalcore/include/xhal/rpc/exceptions.h b/xhalcore/include/xhal/rpc/exceptions.h new file mode 100644 index 0000000..786f7f6 --- /dev/null +++ b/xhalcore/include/xhal/rpc/exceptions.h @@ -0,0 +1,62 @@ +/*! + * \file + * \brief This file contains helpers for exception handling. + * + * \author Louis Moureaux + */ + +#ifndef XHAL_RPC_EXCEPTIONS_H +#define XHAL_RPC_EXCEPTIONS_H + +#include "xhal/rpc/wiscRPCMsg.h" + +namespace xhal { namespace rpc { namespace helper { + + /** + * \brief Retrieves a user-friendly message for the given exception. + * + * Specialization for \c std::exception. + */ + std::string getExceptionMessage(const std::exception &e); + + /** + * \brief Retrieves a user-friendly message for the given exception. + * + * Specialization for \c wisc::RPCMsg::BadKeyException. + * + * \note This function is never called because the constructor of \c BadKeyException calls + * \c std::abort. It is kept in case the issue is corrected in the future. + */ + std::string getExceptionMessage(const wisc::RPCMsg::BadKeyException &e); + + /** + * \brief Retrieves a user-friendly message for the given exception. + * + * Specialization for \c wisc::RPCMsg::TypeException. + */ + std::string getExceptionMessage(const wisc::RPCMsg::TypeException &e); + + /** + * \brief Retrieves a user-friendly message for the given exception. + * + * Specialization for \c wisc::RPCMsg::BufferTooSmallException. + */ + std::string getExceptionMessage(const wisc::RPCMsg::BufferTooSmallException &e); + + /** + * \brief Retrieves a user-friendly message for the given exception. + * + * Specialization for \c wisc::RPCMsg::CorruptMessageException. + */ + std::string getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e); + + /** + * \brief Sets the type of the current exception in \c response. + * \internal This function makes use of low-level functions of the Itanium C++ ABI to + * retrieve the type name of the current exception. + */ + void setExceptionType(wisc::RPCMsg *response); + +}}} // namespace xhal::rpc::helper + +#endif // XHAL_RPC_EXCEPTIONS_H diff --git a/xhalcore/include/xhal/rpc/register.h b/xhalcore/include/xhal/rpc/register.h index 15d6473..6fc31ba 100644 --- a/xhalcore/include/xhal/rpc/register.h +++ b/xhalcore/include/xhal/rpc/register.h @@ -4,6 +4,7 @@ * a remotely callable RPC method * * \author Laurent Pétré + * \author Louis Moureaux */ #ifndef XHAL_RPC_REGSTER_H @@ -11,6 +12,7 @@ #include "xhal/rpc/common.h" #include "xhal/rpc/compat.h" +#include "xhal/rpc/exceptions.h" #include "xhal/rpc/helper.h" #include "moduleapi.h" // Only present in the CTP7 modules @@ -19,6 +21,35 @@ namespace xhal { namespace rpc { + namespace helper { + + /** + * \brief Handles an exception, setting the error key on the response. + * + * In case a second exception occurs when setting the error key, \c std::terminate is called. + */ + template + void handleException(const Exception &e, wisc::RPCMsg *response) noexcept + { + // Log exception here? + response->set_string(std::string(abiVersion) + ".error", getExceptionMessage(e)); + setExceptionType(response); + } + + /* + * Handles an unknown exception, setting the error key on the response. + * + * In case an exception occurs when setting the error key, \c std::terminate is called. + */ + void handleException(wisc::RPCMsg *response) noexcept + { + // Log exception here? + response->set_string(std::string(abiVersion) + ".error", "unknown exception type"); + setExceptionType(response); + } + + } // namespace helper + /*! * \brief Locally invoke a RPC method * @@ -31,20 +62,34 @@ namespace xhal { namespace rpc { > void invoke(const wisc::RPCMsg *request, wisc::RPCMsg *response) noexcept { - // Remove the cv-qualifiers and references since we need - // a copy of the object - helper::functor_decay_args_t args; + try { + // Remove the cv-qualifiers and references since we need + // a copy of the object + helper::functor_decay_args_t args; - MessageDeserializer query(request); - query >> args; + MessageDeserializer query(request); + query >> args; - // Call the Method functor with the arguments received from - // the RPC message - auto result = compat::tuple_apply>(Method{}, args); + // Call the Method functor with the arguments received from + // the RPC message + auto result = compat::tuple_apply>(Method{}, args); - // Serialize the reply - MessageSerializer reply(response); - reply << result; + // Serialize the reply + MessageSerializer reply(response); + reply << result; + } catch (const std::exception &e) { + helper::handleException(e, response); + } catch (const wisc::RPCMsg::BadKeyException &e) { + helper::handleException(e, response); + } catch (const wisc::RPCMsg::TypeException &e) { + helper::handleException(e, response); + } catch (const wisc::RPCMsg::BufferTooSmallException &e) { + helper::handleException(e, response); + } catch (const wisc::RPCMsg::CorruptMessageException &e) { + helper::handleException(e, response); + } catch (...) { + helper::handleException(response); + } } /*! diff --git a/xhalcore/src/common/rpc/exceptions.cpp b/xhalcore/src/common/rpc/exceptions.cpp new file mode 100644 index 0000000..c91fb9e --- /dev/null +++ b/xhalcore/src/common/rpc/exceptions.cpp @@ -0,0 +1,52 @@ +#include "xhal/rpc/exceptions.h" + +#include "xhal/rpc/common.h" // abiVersion + +#include "cxxabi.h" // C++ Itanium ABI + +namespace xhal { namespace rpc { namespace helper { + + std::string getExceptionMessage(const std::exception &e) + { + return e.what(); + } + + std::string getExceptionMessage(const wisc::RPCMsg::BadKeyException &e) + { + return "bad RPC key: " + e.key; + } + + std::string getExceptionMessage(const wisc::RPCMsg::TypeException &e) + { + return "RPC type error"; + } + + std::string getExceptionMessage(const wisc::RPCMsg::BufferTooSmallException &e) + { + return "buffer too small"; + } + + std::string getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e) + { + return "corrupt RPC message: " + e.reason; + } + + void setExceptionType(wisc::RPCMsg *response) + { + // Fetch the type of the current exception + const std::type_info *exceptionType = abi::__cxa_current_exception_type(); + if (exceptionType != nullptr) { + // Try to demangle it + char *demangled = abi::__cxa_demangle(exceptionType->name(), + nullptr, nullptr, nullptr); + if (demangled != nullptr) { + response->set_string(std::string(abiVersion) + ".type", demangled); + std::free(demangled); + } else { + // Could not demangle, use raw name + response->set_string(std::string(abiVersion) + ".type", exceptionType->name()); + } + } + } + +}}} // namespace xhal::rpc::helper From 9f878c8494a976059434b4827240f48cccc34bf5 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 20 Jul 2019 18:51:56 +0200 Subject: [PATCH 08/56] Handle the error key in call() The error key is set on the message when an exception is thrown by the RPC method. Throw an exception on the calling side when it is present. --- xhalcore/include/xhal/rpc/call.h | 53 ++++++++++++++++++++++++++ xhalcore/include/xhal/rpc/exceptions.h | 7 ++++ xhalcore/src/common/rpc/exceptions.cpp | 10 +++++ 3 files changed, 70 insertions(+) diff --git a/xhalcore/include/xhal/rpc/call.h b/xhalcore/include/xhal/rpc/call.h index f54a7ba..955a00a 100644 --- a/xhalcore/include/xhal/rpc/call.h +++ b/xhalcore/include/xhal/rpc/call.h @@ -4,6 +4,7 @@ * remotely a RPC method * * \author Laurent Pétré + * \author Louis Moureaux */ #ifndef XHAL_RPC_CALL_H @@ -11,6 +12,7 @@ #include "xhal/rpc/common.h" #include "xhal/rpc/compat.h" +#include "xhal/rpc/exceptions.h" #include "xhal/rpc/helper.h" #include "xhal/rpc/wiscrpcsvc.h" // move the header to xhal/extern/wiscrpcsvc.h ? @@ -30,6 +32,53 @@ namespace xhal { namespace rpc { typename... Args, typename std::enable_if::value, int>::type = 0 > + helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args); + + /** + * \brief Thrown by \ref call when an exception is thrown on the remote host. + */ + class RemoteException : public std::runtime_error + { + std::string m_type; + + /** + * \brief \ref call is the only function that can throw this exception. + */ + template::value, int>::type + > + friend helper::functor_return_t call(wisc::RPCSvc &connection, + Args&&... args); + + /** + * \brief Constructor. + * \param response An RPC response to extract error information from. + */ + explicit RemoteException(const wisc::RPCMsg &response) : + std::runtime_error(helper::readExceptionMessage(response)), + m_type(response.get_key_exists(std::string(abiVersion) + ".type") ? + response.get_string(std::string(abiVersion) + ".type") : "") + { + } + + public: + /** + * \brief Returns \c true if the type of the exception is available. + */ + bool hasType() const { return !m_type.empty(); } + + /** + * \brief Returns the exception type name if available, an empty string otherwise. + */ + std::string type() const { return m_type; } + }; + + /* Implementation */ + template::value, int>::type + > helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args) { // The wisc::RPCMsg method name is taken from the typeid @@ -46,6 +95,10 @@ namespace xhal { namespace rpc { // Remote call const wisc::RPCMsg response = connection.call_method(request); + if (response.get_key_exists(std::string(abiVersion) + ".error")) { + throw RemoteException(response); + } + // The RPC method can return a void so the void_holder is required compat::void_holder> return_v; diff --git a/xhalcore/include/xhal/rpc/exceptions.h b/xhalcore/include/xhal/rpc/exceptions.h index 786f7f6..a6ec759 100644 --- a/xhalcore/include/xhal/rpc/exceptions.h +++ b/xhalcore/include/xhal/rpc/exceptions.h @@ -57,6 +57,13 @@ namespace xhal { namespace rpc { namespace helper { */ void setExceptionType(wisc::RPCMsg *response); + /** + * \brief Fetches an error message from \c response. + * + * The \c error key must be set and to a string. + */ + std::string readExceptionMessage(const wisc::RPCMsg &response); + }}} // namespace xhal::rpc::helper #endif // XHAL_RPC_EXCEPTIONS_H diff --git a/xhalcore/src/common/rpc/exceptions.cpp b/xhalcore/src/common/rpc/exceptions.cpp index c91fb9e..35ca052 100644 --- a/xhalcore/src/common/rpc/exceptions.cpp +++ b/xhalcore/src/common/rpc/exceptions.cpp @@ -49,4 +49,14 @@ namespace xhal { namespace rpc { namespace helper { } } + std::string readExceptionMessage(const wisc::RPCMsg &response) + { + std::string msg = "remote error: "; + if (response.get_key_exists(std::string(abiVersion) + ".type")) { + msg += response.get_string(std::string(abiVersion) + ".type") + ": "; + } + msg += response.get_string(std::string(abiVersion) + ".error"); + return msg; + } + }}} // namespace xhal::rpc::helper From 3c50086e5c8629d9a8e8d45984dbb76c14141e4f Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Tue, 6 Aug 2019 11:26:37 +0200 Subject: [PATCH 09/56] Handle RPCMsg and RPCSvc exceptions in call() The Wisconsin RPC messaging layer can throw a family of exceptions that need to be enumerated in catch() statements. Replace them with a common type deriving from std::runtime_error. --- xhalcore/include/xhal/rpc/call.h | 93 +++++++++++++++++++------- xhalcore/include/xhal/rpc/exceptions.h | 9 ++- xhalcore/src/common/rpc/exceptions.cpp | 5 ++ 3 files changed, 82 insertions(+), 25 deletions(-) diff --git a/xhalcore/include/xhal/rpc/call.h b/xhalcore/include/xhal/rpc/call.h index 955a00a..ab1223c 100644 --- a/xhalcore/include/xhal/rpc/call.h +++ b/xhalcore/include/xhal/rpc/call.h @@ -74,6 +74,35 @@ namespace xhal { namespace rpc { std::string type() const { return m_type; } }; + /** + * \brief Thrown by \c call when there is a problem calling the remote method. + * + * This can be either because the Wisconsin messaging layer throws an exception or because + * the method can't be found. + */ + class MessageException : public std::runtime_error + { + /** + * \brief \ref call is the only function that can throw this exception. + */ + template::value, int>::type + > + friend helper::functor_return_t call(wisc::RPCSvc &connection, + Args&&... args); + + /** + * \brief Constructor. + */ + explicit MessageException(const std::string &message) : + std::runtime_error(message) + {} + + public: + // Use what() + }; + /* Implementation */ template helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args) { - // The wisc::RPCMsg method name is taken from the typeid - // This is implementation dependent but g++ and clang++ - // follow the same convention - wisc::RPCMsg request(std::string(abiVersion) + "." + typeid(Method).name()); - MessageSerializer query{&request}; - - // Type conversion from args to serializable types - // must be performed in the same statement in order to - // make use of lifetime extension - query << helper::get_forward_as_tuple()(args...); - - // Remote call - const wisc::RPCMsg response = connection.call_method(request); - - if (response.get_key_exists(std::string(abiVersion) + ".error")) { - throw RemoteException(response); + try { + // The wisc::RPCMsg method name is taken from the typeid + // This is implementation dependent but g++ and clang++ + // follow the same convention + wisc::RPCMsg request(std::string(abiVersion) + "." + typeid(Method).name()); + MessageSerializer query{&request}; + + // Type conversion from args to serializable types + // must be performed in the same statement in order to + // make use of lifetime extension + query << helper::get_forward_as_tuple()(args...); + + // Remote call + const wisc::RPCMsg response = connection.call_method(request); + + // Check for errors + if (response.get_key_exists("rpcerror")) { + throw MessageException(response.get_string("rpcerror")); + } else if (response.get_key_exists(std::string(abiVersion) + ".error")) { + throw RemoteException(response); + } + + // The RPC method can return a void so the void_holder is required + compat::void_holder> return_v; + + MessageDeserializer reply{&response}; + reply >> return_v; + + return return_v.get(); + + } catch (const wisc::RPCMsg::BadKeyException &e) { + throw MessageException(helper::getExceptionMessage(e)); + } catch (const wisc::RPCMsg::TypeException &e) { + throw MessageException(helper::getExceptionMessage(e)); + } catch (const wisc::RPCMsg::BufferTooSmallException &e) { + throw MessageException(helper::getExceptionMessage(e)); + } catch (const wisc::RPCMsg::CorruptMessageException &e) { + throw MessageException(helper::getExceptionMessage(e)); + } catch (const wisc::RPCSvc::RPCException &e) { + throw MessageException(helper::getExceptionMessage(e)); } - - // The RPC method can return a void so the void_holder is required - compat::void_holder> return_v; - - MessageDeserializer reply{&response}; - reply >> return_v; - - return return_v.get(); } }} diff --git a/xhalcore/include/xhal/rpc/exceptions.h b/xhalcore/include/xhal/rpc/exceptions.h index a6ec759..42906eb 100644 --- a/xhalcore/include/xhal/rpc/exceptions.h +++ b/xhalcore/include/xhal/rpc/exceptions.h @@ -8,7 +8,7 @@ #ifndef XHAL_RPC_EXCEPTIONS_H #define XHAL_RPC_EXCEPTIONS_H -#include "xhal/rpc/wiscRPCMsg.h" +#include "xhal/rpc/wiscrpcsvc.h" namespace xhal { namespace rpc { namespace helper { @@ -50,6 +50,13 @@ namespace xhal { namespace rpc { namespace helper { */ std::string getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e); + /** + * \brief Retrieves a user-friendly message for the given exception. + * + * Specialization for \c wisc::RPCSvc::RPCException and derived types. + */ + std::string getExceptionMessage(const wisc::RPCSvc::RPCException &e); + /** * \brief Sets the type of the current exception in \c response. * \internal This function makes use of low-level functions of the Itanium C++ ABI to diff --git a/xhalcore/src/common/rpc/exceptions.cpp b/xhalcore/src/common/rpc/exceptions.cpp index 35ca052..88833ae 100644 --- a/xhalcore/src/common/rpc/exceptions.cpp +++ b/xhalcore/src/common/rpc/exceptions.cpp @@ -31,6 +31,11 @@ namespace xhal { namespace rpc { namespace helper { return "corrupt RPC message: " + e.reason; } + std::string getExceptionMessage(const wisc::RPCSvc::RPCException &e) + { + return e.message; + } + void setExceptionType(wisc::RPCMsg *response) { // Fetch the type of the current exception From 19dac69c44727a657052052ec239674017ed95ef Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Thu, 8 Aug 2019 16:51:36 +0200 Subject: [PATCH 10/56] Clean up Makefiles -- Fixes #128 * `config` submodule updated to pick up `XHAL_ROOT` and default `INSTALL_PATH` * `xhalarm` and `xhalcore` `Makefile`s are simplified for reliable, reproducible builds * `xhalarm` as dependency of `xhalcore` is moved to dependency of `xhalcore.RPM` --- Makefile | 50 +++++++--- config | 2 +- python/Makefile | 50 +++++++--- python/reg_interface_gem/Makefile | 30 +++--- xhalarm/Makefile | 102 +++++++++++++------- xhalcore/Makefile | 152 +++++++++++++++++------------- 6 files changed, 237 insertions(+), 149 deletions(-) diff --git a/Makefile b/Makefile index 731778d..eefe368 100644 --- a/Makefile +++ b/Makefile @@ -3,28 +3,42 @@ SUBPACKAGES := \ xhalcore \ xhalarm +SUBPACKAGES.CLEAN := $(patsubst %,%.clean, $(SUBPACKAGES)) SUBPACKAGES.DEBUG := $(patsubst %,%.debug, $(SUBPACKAGES)) +SUBPACKAGES.INSTALL := $(patsubst %,%.install, $(SUBPACKAGES)) +SUBPACKAGES.UNINSTALL:= $(patsubst %,%.uninstall,$(SUBPACKAGES)) SUBPACKAGES.RPM := $(patsubst %,%.rpm, $(SUBPACKAGES)) -SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) +SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) -SUBPACKAGES.CLEAN := $(patsubst %,%.clean, $(SUBPACKAGES)) -.PHONY: build clean cleanall cleandoc cleanrpm +.PHONY: $(SUBPACKAGES) \ + $(SUBPACKAGES.CLEAN) \ + $(SUBPACKAGES.INSTALL) \ + $(SUBPACKAGES.UNINSTALL) \ + $(SUBPACKAGES.RPM) \ + $(SUBPACKAGES.CLEANRPM) \ + $(SUBPACKAGES.DOC) \ + $(SUBPACKAGES.CLEANDOC) +.PHONY: all build clean cleanall cleandoc cleanrpm build: $(SUBPACKAGES) -all: $(SUBPACKAGES) $(SUBPACKAGES.RPM) $(SUBPACKAGES.DOC) +all: $(SUBPACKAGES) $(SUBPACKAGES.DOC) + +doc: $(SUBPACKAGES.DOC) rpm: $(SUBPACKAGES) $(SUBPACKAGES.RPM) -doc: $(SUBPACKAGES.DOC) +clean: $(SUBPACKAGES.CLEAN) cleanrpm: $(SUBPACKAGES.CLEANRPM) cleandoc: $(SUBPACKAGES.CLEANDOC) -clean: $(SUBPACKAGES.CLEAN) +install: $(SUBPACKAGES) $(SUBPACKAGES.INSTALL) + +uninstall: $(SUBPACKAGES.UNINSTALL) cleanall: clean cleandoc cleanrpm @@ -34,22 +48,30 @@ $(SUBPACKAGES): $(SUBPACKAGES.RPM): $(SUBPACKAGES) $(MAKE) -C $(patsubst %.rpm,%, $@) rpm -$(SUBPACKAGES.DOC): - $(MAKE) -C $(patsubst %.doc,%, $@) doc +$(SUBPACKAGES.CLEAN): + $(MAKE) -C $(patsubst %.clean,%, $@) clean + +$(SUBPACKAGES.CLEANDOC): + $(MAKE) -C $(patsubst %.cleandoc,%, $@) cleandoc $(SUBPACKAGES.CLEANRPM): $(MAKE) -C $(patsubst %.cleanrpm,%, $@) cleanrpm -$(SUBPACKAGES.CLEANDOC): - $(MAKE) -C $(patsubst %.cleandoc,%, $@) cleandoc +$(SUBPACKAGES.DOC): + $(MAKE) -C $(patsubst %.doc,%, $@) doc -$(SUBPACKAGES.CLEAN): - $(MAKE) -C $(patsubst %.clean,%, $@) clean +$(SUBPACKAGES.INSTALL): $(SUBPACKAGES) + $(MAKE) -C $(patsubst %.install,%, $@) install -.PHONY: $(SUBPACKAGES) $(SUBPACKAGES.INSTALL) $(SUBPACKAGES.CLEAN) $(SUBPACKAGES.DOC) $(SUBPACKAGES.RPM) $(SUBPACKAGES.CLEANRPM) $(SUBPACKAGES.CLEANDOC) +$(SUBPACKAGES.UNINSTALL): $(SUBPACKAGES) + $(MAKE) -C $(patsubst %.uninstall,%, $@) uninstall python: xhalarm: -xhalcore: xhalarm +xhalcore: + +xhalcore.install: xhalarm + +xhalcore.rpm: xhalarm diff --git a/config b/config index a0c94ec..2b443a8 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit a0c94eca89363574014d1d7e6cbe310474b0ffdc +Subproject commit 2b443a880b5090bdd85d49c2044f4d42f8612ea7 diff --git a/python/Makefile b/python/Makefile index a7aefd8..4156039 100644 --- a/python/Makefile +++ b/python/Makefile @@ -1,39 +1,65 @@ SUBPACKAGES := \ - reg_interface_gem \ + reg_interface_gem +SUBPACKAGES.CLEAN := $(patsubst %,%.clean, $(SUBPACKAGES)) SUBPACKAGES.DEBUG := $(patsubst %,%.debug, $(SUBPACKAGES)) -SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) +SUBPACKAGES.INSTALL := $(patsubst %,%.install, $(SUBPACKAGES)) +SUBPACKAGES.UNINSTALL:= $(patsubst %,%.uninstall,$(SUBPACKAGES)) SUBPACKAGES.RPM := $(patsubst %,%.rpm, $(SUBPACKAGES)) SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) +SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) -SUBPACKAGES.CLEAN := $(patsubst %,%.clean, $(SUBPACKAGES)) -.PHONY: $(SUBPACKAGES) $(SUBPACKAGES.INSTALL) $(SUBPACKAGES.CLEAN) $(SUBPACKAGES.DOC) $(SUBPACKAGES.RPM) $(SUBPACKAGES.CLEANRPM) $(SUBPACKAGES.CLEANDOC) +.PHONY: $(SUBPACKAGES) \ + $(SUBPACKAGES.CLEAN) \ + $(SUBPACKAGES.INSTALL) \ + $(SUBPACKAGES.UNINSTALL) \ + $(SUBPACKAGES.RPM) \ + $(SUBPACKAGES.CLEANRPM) \ + $(SUBPACKAGES.DOC) \ + $(SUBPACKAGES.CLEANDOC) + +.PHONY: all build clean cleanall cleandoc cleanrpm doc install uninstall rpm +build: $(SUBPACKAGES) + +all: $(SUBPACKAGES) $(SUBPACKAGES.DOC) rpm: $(SUBPACKAGES) $(SUBPACKAGES.RPM) doc: $(SUBPACKAGES.DOC) -cleanrpm: $(SUBPACKAGES.CLEANRPM) - clean: $(SUBPACKAGES.CLEAN) cleandoc: $(SUBPACKAGES.CLEANDOC) +cleanrpm: $(SUBPACKAGES.CLEANRPM) + +install: $(SUBPACKAGES.INSTALL) + +uninstall: $(SUBPACKAGES.UNINSTALL) + +cleanall: clean cleandoc cleanrpm + $(SUBPACKAGES): $(MAKE) -C $@ $(SUBPACKAGES.RPM): $(MAKE) -C $(patsubst %.rpm,%, $@) rpm -$(SUBPACKAGES.DOC): - $(MAKE) -C $(patsubst %.doc,%, $@) html +$(SUBPACKAGES.CLEAN): + $(MAKE) -C $(patsubst %.clean,%, $@) clean + +$(SUBPACKAGES.CLEANDOC): + $(MAKE) -C $(patsubst %.cleandoc,%, $@) cleandoc $(SUBPACKAGES.CLEANRPM): $(MAKE) -C $(patsubst %.cleanrpm,%, $@) cleanrpm -$(SUBPACKAGES.CLEANDOC): - $(MAKE) -C $(patsubst %.cleandoc,%, $@) cleandoc +$(SUBPACKAGES.DOC): + $(MAKE) -C $(patsubst %.doc,%, $@) html -$(SUBPACKAGES.CLEAN): - $(MAKE) -C $(patsubst %.clean,%, $@) clean +$(SUBPACKAGES.INSTALL): + $(MAKE) -C $(patsubst %.install,%, $@) install-site + +$(SUBPACKAGES.UNINSTALL): + $(MAKE) -C $(patsubst %.uninstall,%, $@) uninstall-site diff --git a/python/reg_interface_gem/Makefile b/python/reg_interface_gem/Makefile index 7263280..5998852 100644 --- a/python/reg_interface_gem/Makefile +++ b/python/reg_interface_gem/Makefile @@ -15,22 +15,22 @@ PackagePath := $(shell pwd) PackageDir := pkg/$(Namespace)/$(ShortPackage) ScriptDir := pkg/$(Namespace)/scripts +ProjectBase = $(BUILD_HOME)/$(Project) +ConfigDir = $(ProjectBase)/config + +include $(ConfigDir)/mfCommonDefs.mk +include $(ConfigDir)/mfPythonDefs.mk # Explicitly define the modules that are being exported (for PEP420 compliance) PythonModules = ["$(Namespace).$(ShortPackage)"] $(info PythonModules=${PythonModules}) -REG_INTERFACE_GEM_VER_MAJOR:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') -REG_INTERFACE_GEM_VER_MINOR:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') -REG_INTERFACE_GEM_VER_PATCH:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') - -include $(BUILD_HOME)/$(Project)/config/mfCommonDefs.mk -include $(BUILD_HOME)/$(Project)/config/mfPythonDefs.mk +include $(ConfigDir)/mfPythonRPM.mk +include $(ConfigDir)/mfSphinx.mk -# include $(BUILD_HOME)/$(Project)/config/mfDefs.mk - -include $(BUILD_HOME)/$(Project)/config/mfPythonRPM.mk -include $(BUILD_HOME)/$(Project)/config/mfSphinx.mk +REG_INTERFACE_GEM_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') +REG_INTERFACE_GEM_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') +REG_INTERFACE_GEM_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') default: @echo "Running default target" @@ -39,10 +39,7 @@ default: @cp -rf __init__.py $(PackageDir) # need to ensure that the python only stuff is packaged into RPMs -.PHONY: clean preprpm -_rpmprep: preprpm - @echo "Running _rpmprep target" -preprpm: default +rpmprep: default @echo "Running preprpm target" $(MakeDir) $(ScriptDir) @cp -rf scripts/* $(ScriptDir) @@ -61,11 +58,6 @@ clean: -rm -f pkg/CHANGELOG.md -rm -f pkg/requirements.txt -rpm: _rpmall _rpmarm _harvest - @echo "Running xhal reg_interface_gem rpm target" - find $(RPMBUILD_DIR)/dist -iname "*.rpm" -print0 -exec mv -t $(RPMBUILD_DIR) {} \+ - find $(RPMBUILD_DIR)/arm -iname "*.rpm" -print0 -exec mv -t $(RPMBUILD_DIR) {} \+ - print-env: @echo BUILD_HOME $(BUILD_HOME) @echo PackagePath $(PackagePath) diff --git a/xhalarm/Makefile b/xhalarm/Makefile index 078592e..3a1709e 100644 --- a/xhalarm/Makefile +++ b/xhalarm/Makefile @@ -9,72 +9,104 @@ PackageDir := pkg/$(ShortPackage) Packager := Mykhailo Dalchenko Arch := arm -XHAL_VER_MAJOR:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_MINOR:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_PATCH:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') +ProjectPath:= $(BUILD_HOME)/$(Project) +ConfigDir := $(ProjectPath)/config -INSTALL_PREFIX=/mnt/persistent/xhal +include $(ConfigDir)/mfCommonDefs.mk +include $(ConfigDir)/mfZynq.mk +include $(ConfigDir)/mfRPMRules.mk -include $(BUILD_HOME)/$(Project)/config/mfCommonDefs.mk -include $(BUILD_HOME)/$(Project)/config/mfZynq.mk -include $(BUILD_HOME)/$(Project)/config/mfRPMRules.mk +PackageSourceDir:=$(ProjectPath)/xhalcore/src/common +PackageIncludeDir:=$(ProjectPath)/xhalcore/include -ADDFLAGS=-std=gnu++14 +XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') +XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') +XHAL_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') -IncludeDirs = $(BUILD_HOME)/$(Project)/xhalcore/include +ADDFLAGS=-g -std=gnu++14 + +IncludeDirs+=$(PackageIncludeDir) INC=$(IncludeDirs:%=-I%) -Libraries+= -llog4cplus -lxerces-c -lstdc++ +Libraries+=-llog4cplus -lxerces-c -lstdc++ LDFLAGS+=-shared $(LibraryDirs) -SrcLocation =$(BUILD_HOME)/$(Project)/xhalcore/src/common -SRCS_XHAL = $(shell echo $(SrcLocation)/utils/*.cpp) +SRCS_XHAL = $(shell echo $(PackageSourceDir)/utils/*.cpp) + +AUTODEPS_XHAL = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHAL)) + +OBJS_XHAL = $(patsubst %.d,%.o,$(AUTODEPS_XHAL)) -## Place object files in lib/linux? -ObjLocation = src/linux/$(Arch) -OBJS_XHAL = $(patsubst $(SrcLocation)/%,$(ObjLocation)/%, $(SRCS_XHAL:.cpp=.o)) +XHAL_LIB = $(PackageLibraryDir)/libxhal.so -XHAL_LIB=$(BUILD_HOME)/$(Project)/$(LongPackage)/lib/libxhal.so +TargetLibraries:= xhal -.PHONY: clean rpc prerpm +# destination path macro we'll use below +df = $(PackageObjectDir)/$(*F) default: build @echo "Running default target" +# @cp -rfp $(ProjectPath)/xhalcore/src/common $(PackagePath)/src/ $(MakeDir) $(PackageDir) -_rpmprep: preprpm - @echo "Running _rpmprep target" - -preprpm: default +rpmprep: default @echo "Running preprpm target" - @cp -rf lib $(PackageDir) + $(MakeDir) $(PackageDir)/$(Package) + @cp -rfp lib include src Makefile $(PackageDir)/$(Package) + @cp -rfp $(ProjectPath)/config $(PackageDir) + $(MakeDir) $(RPMBUILD_DIR)/SOURCES + cd $(PackageDir)/..; \ + ls -l; \ + tar cjf $(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION).tbz2 $(PackageName); \ + ls -l; \ + mv $(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION).tbz2 $(RPMBUILD_DIR)/SOURCES; -build: clean $(XHAL_LIB) +all: build -_all: clean $(XHAL_LIB) +xhal: $(XHAL_LIB) doc: @echo "TO DO" +## adapted from http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ +## Generic object creation rule, generate dependencies and use them later +$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp + $(MakeDir) $(@D) + $(CC) $(CFLAGS) $(ADDFLAGS) $(INC) -c -MT $@ -MMD -MP -MF $(@D)/$(*F).Td -o $@ $< + mv $(@D)/$(*F).Td $(@D)/$(*F).d + touch $@ + +## dummy rule for dependencies +$(PackageObjectDir)/%.d: + +## mark dependencies and objects as not auto-removed +.PRECIOUS: $(PackageObjectDir)/%.d +.PRECIOUS: $(PackageObjectDir)/%.o + +## Force rule for all target library names +$(TargetLibraries): + $(XHAL_LIB): $(OBJS_XHAL) - @mkdir -p $(BUILD_HOME)/$(Project)/$(LongPackage)/lib - $(CC) $(ADDFLAGS) $(LDFLAGS) -o $@ $^ $(Libraries) + $(MakeDir) -p $(@D) + $(CC) $(ADDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) -$(OBJS_XHAL): $(SRCS_XHAL) - $(MakeDir) -p $(shell dirname $@) - $(CC) $(CFLAGS) $(ADDFLAGS) $(INC) -c -o $@ $< +## FIXME obsolete? only for xcompiled things? +# %.o: %.c +# $(CC) -std=gnu99 -c $(CFLAGS) -o $@ $< +# %.o: %.cc +# $(CXX) -std=c++0x -c $(CFLAGS) -o $@ $< -%.o: %.c - $(CC) -std=gnu99 -c $(CFLAGS) -o $@ $< -%.o: %.cc - $(CXX) -std=c++0x -c $(CFLAGS) -o $@ $< +build: $(TargetLibraries) clean: -rm -rf $(OBJS_XHAL) - -rm -rf $(XHAL_LIB) - -rm -rf $(BUILD_HOME)/$(Project)/$(LongPackage)/lib + -rm -rf $(PackageLibraryDir) + -rm -rf $(PackageExecDir) -rm -rf $(PackageDir) cleandoc: @echo "TO DO" + +cleanall: + -rm -rf $(PackageObjectDir) diff --git a/xhalcore/Makefile b/xhalcore/Makefile index 3038308..f6b2508 100644 --- a/xhalcore/Makefile +++ b/xhalcore/Makefile @@ -9,111 +9,127 @@ PackageDir := pkg/$(ShortPackage) Packager := Mykhailo Dalchenko Arch := x86_64 -XHAL_VER_MAJOR:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_MINOR:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_PATCH:=$(shell $(BUILD_HOME)/$(Project)/config/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') +ProjectPath:= $(BUILD_HOME)/$(Project) +ConfigDir := $(ProjectPath)/config -INSTALL_PREFIX=/opt/xhal +include $(ConfigDir)/mfCommonDefs.mk +include $(ConfigDir)/mfPythonDefs.mk +include $(ConfigDir)/mfRPMRules.mk -include $(BUILD_HOME)/$(Project)/config/mfCommonDefs.mk -include $(BUILD_HOME)/$(Project)/config/mfPythonDefs.mk -include $(BUILD_HOME)/$(Project)/config/mfRPMRules.mk +PackageSourceDir:=$(PackagePath)/src/common -CCFLAGS=-O0 -g3 -fno-inline -Wall -pthread -ADDFLAGS=-fPIC -std=c++11 -m64 +XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') +XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') +XHAL_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') -IncludeDirs+= /opt/xdaq/include -IncludeDirs+= $(BUILD_HOME)/$(Project)/$(LongPackage)/include +CCFLAGS=-fno-inline -Wall -pthread +ADDFLAGS=-g -fPIC -std=c++11 -m64 + +IncludeDirs+= $(XDAQ_ROOT)/include +IncludeDirs+= $(PackageIncludeDir) INC=$(IncludeDirs:%=-I%) -Libraries+= -llog4cplus -lxerces-c -lwiscrpcsvc -lstdc++ +Libraries+=-llog4cplus -lxerces-c -lwiscrpcsvc -lstdc++ -LibraryDirs+=-L/opt/xdaq/lib +LibraryDirs+=-L$(XDAQ_ROOT)/lib +LibraryDirs+=-L$(PackageLibraryDir) LibraryDirs+=-L/opt/wiscrpcsvc/lib LDFLAGS = -shared $(LibraryDirs) -SrcLocation = src/common -SRCS_UTILS = $(shell echo $(SrcLocation)/utils/*.cpp) -SRCS_XHAL = $(shell echo $(SrcLocation)/*.cpp) -SRCS_XHALPY = $(shell echo $(SrcLocation)/python_wrappers/*.cpp) -SRCS_RPC_MAN = $(shell echo $(SrcLocation)/rpc_manager/*.cpp) +SRCS_XHAL = $(wildcard $(PackageSourceDir)/*.cpp) +SRCS_UTILS = $(wildcard $(PackageSourceDir)/utils/*.cpp) +SRCS_XHALPY = $(wildcard $(PackageSourceDir)/python_wrappers/*.cpp) +SRCS_RPCMAN = $(wildcard $(PackageSourceDir)/rpc_manager/*.cpp) +# SRCS_EXES = $(wildcard $(PackageSourceDir)/*.cxx) +# SRCS_TEST_EXES= $(wildcard $(PackageTestSourceDir)/*.cxx) + +AUTODEPS_XHAL = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHAL)) +AUTODEPS_UTILS = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_UTILS)) +AUTODEPS_XHALPY = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHALPY)) +AUTODEPS_RPCMAN = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_RPCMAN)) + +OBJS_XHAL = $(patsubst %.d,%.o,$(AUTODEPS_XHAL)) +OBJS_UTILS = $(patsubst %.d,%.o,$(AUTODEPS_UTILS)) +OBJS_XHALPY = $(patsubst %.d,%.o,$(AUTODEPS_XHALPY)) +OBJS_RPCMAN = $(patsubst %.d,%.o,$(AUTODEPS_RPCMAN)) -## Place object files in src/linux/$(Arch) -ObjLocation = src/linux/$(Arch) -OBJS_UTILS = $(patsubst $(SrcLocation)/%,$(ObjLocation)/%, $(SRCS_UTILS:.cpp=.o)) -OBJS_XHAL = $(patsubst $(SrcLocation)/%,$(ObjLocation)/%, $(SRCS_XHAL:.cpp=.o)) -OBJS_XHALPY = $(patsubst $(SrcLocation)/%,$(ObjLocation)/%, $(SRCS_XHALPY:.cpp=.o)) -OBJS_RPC_MAN = $(patsubst $(SrcLocation)/%,$(ObjLocation)/%, $(SRCS_RPC_MAN:.cpp=.o)) +XHAL_LIB = $(PackageLibraryDir)/libxhal.so +XHALPY_LIB = $(PackageLibraryDir)/xhalpy.so +RPCMAN_LIB = $(PackageLibraryDir)/librpcman.so -XHALCORE_LIB = $(BUILD_HOME)/$(Project)/$(LongPackage)/lib/libxhal.so -RPC_MAN_LIB = $(BUILD_HOME)/$(Project)/$(LongPackage)/lib/librpcman.so -XHALPY_LIB = $(BUILD_HOME)/$(Project)/$(LongPackage)/lib/xhalpy.so +TargetLibraries:= xhal xhalpy rpcman -.PHONY: clean xhalcore rpc prerpm +# destination path macro we'll use below +df = $(PackageObjectDir)/$(*F) + +.PHONY: xhal rpc default: build @echo "Running default target" $(MakeDir) $(PackageDir) -_rpmprep: preprpm - @echo "Running _rpmprep target" - -preprpm: default +rpmprep: default @echo "Running preprpm target" $(MakeDir) lib/arm - @cp -rfp $(BUILD_HOME)/$(Project)/xhalarm/lib/*.so lib/arm - @cp -rfp lib $(PackageDir) - -build: xhalcore rpc + $(MakeDir) $(PackageDir)/$(Package) + @cp -rfp $(ProjectPath)/xhalarm/lib/*.so lib/arm + @cp -rfp lib include src Makefile $(PackageDir)/$(Package) + @cp -rfp $(ProjectPath)/config $(PackageDir) + $(MakeDir) $(RPMBUILD_DIR)/SOURCES + cd $(PackageDir)/..; \ + tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION).tbz2 $(PackageName); -_all: $(XHALCORE_LIB) $(RPC_MAN_LIB) $(XHALPY_LIB) +rpc: xhal $(RPCMAN_LIB) -rpc: xhalcore $(RPC_MAN_LIB) +xhal: $(XHAL_LIB) -xhalcore: $(XHALCORE_LIB) - -xhalpy: xhalcore rpc $(XHALPY_LIB) +xhalpy: xhal rpc $(XHALPY_LIB) doc: @echo "TO DO" -$(OBJS_UTILS): $(SRCS_UTILS) - @rm -rf $(OBJS_UTILS) - $(MakeDir) $(shell dirname $@) - $(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) -c $< -o $@ - -$(OBJS_XHAL): $(SRCS_XHAL) - $(MakeDir) $(shell dirname $@) -# $(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) $(Libraries) -c $(@:%.o=%.cpp) -o $@ - $(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) -c -o $@ $(patsubst $(ObjLocation)/%,$(SrcLocation)/%, $(@:%.o=%.cpp)) +## adapted from http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ +## Generic object creation rule, generate dependencies and use them later +$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp + $(MakeDir) $(@D) + $(CXX) $(CCFLAGS) $(ADDFLAGS) $(INC) -c -MT $@ -MMD -MP -MF $(@D)/$(*F).Td -o $@ $< + mv $(@D)/$(*F).Td $(@D)/$(*F).d + touch $@ -$(OBJS_RPC_MAN): $(SRCS_RPC_MAN) - $(MakeDir) $(shell dirname $@) -# $(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) $(Libraries) -c $(@:%.o=%.cpp) -o $@ - $(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) -c -o $@ $(patsubst $(ObjLocation)/%,$(SrcLocation)/%, $(@:%.o=%.cpp)) +## dummy rule for dependencies +$(PackageObjectDir)/%.d: -$(OBJS_XHALPY):$(SRCS_XHALPY) - $(MakeDir) $(shell dirname $@) - $(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) -I$(PYTHON_INCLUDE_PREFIX) -c $< -o $@ +## mark dependencies and objects as not auto-removed +.PRECIOUS: $(PackageObjectDir)/%.d +.PRECIOUS: $(PackageObjectDir)/%.o -$(XHALCORE_LIB): $(OBJS_UTILS) $(OBJS_XHAL) - $(MakeDir) $(BUILD_HOME)/$(Project)/$(LongPackage)/lib - $(CC) $(ADDFLAGS) $(LDFLAGS) -o $@ $^ $(Libraries) +## Force rule for all target library names +$(TargetLibraries): -$(RPC_MAN_LIB): $(OBJS_RPC_MAN) - $(MakeDir) $(BUILD_HOME)/$(Project)/$(LongPackage)/lib - $(CC) $(ADDFLAGS) $(LDFLAGS) -o $@ $^ $(Libraries) +$(XHAL_LIB): $(OBJS_XHAL) $(OBJS_UTILS) + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) $(XHALPY_LIB): $(OBJS_XHALPY) - $(MakeDir) $(BUILD_HOME)/$(Project)/$(LongPackage)/lib - $(CC) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -Llib -o $@ $< $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal -lrpcman + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal -lrpcman + +$(RPCMAN_LIB): $(OBJS_RPCMAN) + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) + +## xhalcore Compile $(TargetLibraries) +build: $(TargetLibraries) clean: - -rm -rf $(OBJS_UTILS) $(OBJS_XHAL) $(OBJS_RPC_MAN) $(OBJS_XHALPY) - -rm -rf $(XHALCORE_LIB) $(XHALPY_LIB) $(RPC_MAN_LIB) - -rm -rf $(BUILD_HOME)/$(Project)/$(LongPackage)/lib + -rm -rf $(OBJS_UTILS) $(OBJS_XHAL) $(OBJS_RPCMAN) $(OBJS_XHALPY) + -rm -rf $(PackageLibraryDir) + -rm -rf $(PackageExecDir) -rm -rf $(PackageDir) cleandoc: @echo "TO DO" + +cleanall: + -rm -rf $(PackageObjectDir) From 7c6cbe13e00fa360ac4459acce8867b7d95881da Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 10 Aug 2019 23:37:18 +0200 Subject: [PATCH 11/56] Compile rpc/exceptions.cpp into libxhal.so --- xhalarm/Makefile | 1 + xhalcore/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/xhalarm/Makefile b/xhalarm/Makefile index 3a1709e..33bbfc6 100644 --- a/xhalarm/Makefile +++ b/xhalarm/Makefile @@ -33,6 +33,7 @@ Libraries+=-llog4cplus -lxerces-c -lstdc++ LDFLAGS+=-shared $(LibraryDirs) SRCS_XHAL = $(shell echo $(PackageSourceDir)/utils/*.cpp) +SRCS_XHAL+= $(shell echo $(PackageSourceDir)/rpc/*.cpp) AUTODEPS_XHAL = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHAL)) diff --git a/xhalcore/Makefile b/xhalcore/Makefile index f6b2508..b614499 100644 --- a/xhalcore/Makefile +++ b/xhalcore/Makefile @@ -39,6 +39,7 @@ LDFLAGS = -shared $(LibraryDirs) SRCS_XHAL = $(wildcard $(PackageSourceDir)/*.cpp) SRCS_UTILS = $(wildcard $(PackageSourceDir)/utils/*.cpp) +SRCS_UTILS += $(wildcard $(PackageSourceDir)/rpc/*.cpp) SRCS_XHALPY = $(wildcard $(PackageSourceDir)/python_wrappers/*.cpp) SRCS_RPCMAN = $(wildcard $(PackageSourceDir)/rpc_manager/*.cpp) # SRCS_EXES = $(wildcard $(PackageSourceDir)/*.cxx) From b68124ce8e20e2550f141fd400367a9e31b21b85 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 10 Aug 2019 23:59:11 +0200 Subject: [PATCH 12/56] Fix typo in rpc/register.h header guard --- xhalcore/include/xhal/rpc/register.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xhalcore/include/xhal/rpc/register.h b/xhalcore/include/xhal/rpc/register.h index 6fc31ba..a406139 100644 --- a/xhalcore/include/xhal/rpc/register.h +++ b/xhalcore/include/xhal/rpc/register.h @@ -7,8 +7,8 @@ * \author Louis Moureaux */ -#ifndef XHAL_RPC_REGSTER_H -#define XHAL_RPC_REGSTER_H +#ifndef XHAL_RPC_REGISTER_H +#define XHAL_RPC_REGISTER_H #include "xhal/rpc/common.h" #include "xhal/rpc/compat.h" From 6257c5ecb3317ff74c0bc4e606e95196017fd307 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 25 Aug 2019 10:49:52 +0300 Subject: [PATCH 13/56] Add lmdb++.h to xhalcore This library is used by the RPC modules for the address table database. Since it is more of a support library, move it to this repository. Also use the original file name lmdb++.h instead of lmdb_cpp_wrapper.h. --- xhalcore/include/lmdb++.h | 1927 +++++++++++++++++++++++++++++++++++++ 1 file changed, 1927 insertions(+) create mode 100644 xhalcore/include/lmdb++.h diff --git a/xhalcore/include/lmdb++.h b/xhalcore/include/lmdb++.h new file mode 100644 index 0000000..4cdcdcb --- /dev/null +++ b/xhalcore/include/lmdb++.h @@ -0,0 +1,1927 @@ +/* This is free and unencumbered software released into the public domain. */ + +#ifndef LMDBXX_H +#define LMDBXX_H + +/** + * - C++11 wrapper for LMDB. + * + * @author Arto Bendiken + * @see https://sourceforge.net/projects/lmdbxx/ + */ + +#ifndef __cplusplus +#error " requires a C++ compiler" +#endif + +#if __cplusplus < 201103L +#if !defined(_MSC_VER) || _MSC_VER < 1900 +#error " requires a C++11 compiler (CXXFLAGS='-std=c++11')" +#endif // _MSC_VER check +#endif + +//////////////////////////////////////////////////////////////////////////////// + +#include /* for MDB_*, mdb_*() */ + +#ifdef LMDBXX_DEBUG +#include /* for assert() */ +#endif +#include /* for std::size_t */ +#include /* for std::snprintf() */ +#include /* for std::strlen() */ +#include /* for std::runtime_error */ +#include /* for std::string */ +#include /* for std::is_pod<> */ + +namespace lmdb { + using mode = mdb_mode_t; +} + +//////////////////////////////////////////////////////////////////////////////// +/* Error Handling */ + +namespace lmdb { + class error; + class logic_error; + class fatal_error; + class runtime_error; + class key_exist_error; + class not_found_error; + class corrupted_error; + class panic_error; + class version_mismatch_error; + class map_full_error; + class bad_dbi_error; +} + +/** + * Base class for LMDB exception conditions. + * + * @see http://symas.com/mdb/doc/group__errors.html + */ +class lmdb::error : public std::runtime_error { +protected: + const int _code; + +public: + /** + * Throws an error based on the given LMDB return code. + */ + [[noreturn]] static inline void raise(const char* origin, int rc); + + /** + * Constructor. + */ + error(const char* const origin, + const int rc) noexcept + : runtime_error{origin}, + _code{rc} {} + + /** + * Returns the underlying LMDB error code. + */ + int code() const noexcept { + return _code; + } + + /** + * Returns the origin of the LMDB error. + */ + const char* origin() const noexcept { + return runtime_error::what(); + } + + /** + * Returns the underlying LMDB error code. + */ + virtual const char* what() const noexcept { + static thread_local char buffer[1024]; + std::snprintf(buffer, sizeof(buffer), + "%s: %s", origin(), ::mdb_strerror(code())); + return buffer; + } +}; + +/** + * Base class for logic error conditions. + */ +class lmdb::logic_error : public lmdb::error { +public: + using error::error; +}; + +/** + * Base class for fatal error conditions. + */ +class lmdb::fatal_error : public lmdb::error { +public: + using error::error; +}; + +/** + * Base class for runtime error conditions. + */ +class lmdb::runtime_error : public lmdb::error { +public: + using error::error; +}; + +/** + * Exception class for `MDB_KEYEXIST` errors. + * + * @see http://symas.com/mdb/doc/group__errors.html#ga05dc5bbcc7da81a7345bd8676e8e0e3b + */ +class lmdb::key_exist_error final : public lmdb::runtime_error { +public: + using runtime_error::runtime_error; +}; + +/** + * Exception class for `MDB_NOTFOUND` errors. + * + * @see http://symas.com/mdb/doc/group__errors.html#gabeb52e4c4be21b329e31c4add1b71926 + */ +class lmdb::not_found_error final : public lmdb::runtime_error { +public: + using runtime_error::runtime_error; +}; + +/** + * Exception class for `MDB_CORRUPTED` errors. + * + * @see http://symas.com/mdb/doc/group__errors.html#gaf8148bf1b85f58e264e57194bafb03ef + */ +class lmdb::corrupted_error final : public lmdb::fatal_error { +public: + using fatal_error::fatal_error; +}; + +/** + * Exception class for `MDB_PANIC` errors. + * + * @see http://symas.com/mdb/doc/group__errors.html#gae37b9aedcb3767faba3de8c1cf6d3473 + */ +class lmdb::panic_error final : public lmdb::fatal_error { +public: + using fatal_error::fatal_error; +}; + +/** + * Exception class for `MDB_VERSION_MISMATCH` errors. + * + * @see http://symas.com/mdb/doc/group__errors.html#ga909b2db047fa90fb0d37a78f86a6f99b + */ +class lmdb::version_mismatch_error final : public lmdb::fatal_error { +public: + using fatal_error::fatal_error; +}; + +/** + * Exception class for `MDB_MAP_FULL` errors. + * + * @see http://symas.com/mdb/doc/group__errors.html#ga0a83370402a060c9175100d4bbfb9f25 + */ +class lmdb::map_full_error final : public lmdb::runtime_error { +public: + using runtime_error::runtime_error; +}; + +/** + * Exception class for `MDB_BAD_DBI` errors. + * + * @since 0.9.14 (2014/09/20) + * @see http://symas.com/mdb/doc/group__errors.html#gab4c82e050391b60a18a5df08d22a7083 + */ +class lmdb::bad_dbi_error final : public lmdb::runtime_error { +public: + using runtime_error::runtime_error; +}; + +inline void +lmdb::error::raise(const char* const origin, + const int rc) { + switch (rc) { + case MDB_KEYEXIST: throw key_exist_error{origin, rc}; + case MDB_NOTFOUND: throw not_found_error{origin, rc}; + case MDB_CORRUPTED: throw corrupted_error{origin, rc}; + case MDB_PANIC: throw panic_error{origin, rc}; + case MDB_VERSION_MISMATCH: throw version_mismatch_error{origin, rc}; + case MDB_MAP_FULL: throw map_full_error{origin, rc}; +#ifdef MDB_BAD_DBI + case MDB_BAD_DBI: throw bad_dbi_error{origin, rc}; +#endif + default: throw lmdb::runtime_error{origin, rc}; + } +} + +//////////////////////////////////////////////////////////////////////////////// +/* Procedural Interface: Metadata */ + +namespace lmdb { + // TODO: mdb_version() + // TODO: mdb_strerror() +} + +//////////////////////////////////////////////////////////////////////////////// +/* Procedural Interface: Environment */ + +namespace lmdb { + static inline void env_create(MDB_env** env); + static inline void env_open(MDB_env* env, + const char* path, unsigned int flags, mode mode); +#if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14) + static inline void env_copy(MDB_env* env, const char* path, unsigned int flags); + static inline void env_copy_fd(MDB_env* env, mdb_filehandle_t fd, unsigned int flags); +#else + static inline void env_copy(MDB_env* env, const char* path); + static inline void env_copy_fd(MDB_env* env, mdb_filehandle_t fd); +#endif + static inline void env_stat(MDB_env* env, MDB_stat* stat); + static inline void env_info(MDB_env* env, MDB_envinfo* stat); + static inline void env_sync(MDB_env* env, bool force); + static inline void env_close(MDB_env* env) noexcept; + static inline void env_set_flags(MDB_env* env, unsigned int flags, bool onoff); + static inline void env_get_flags(MDB_env* env, unsigned int* flags); + static inline void env_get_path(MDB_env* env, const char** path); + static inline void env_get_fd(MDB_env* env, mdb_filehandle_t* fd); + static inline void env_set_mapsize(MDB_env* env, std::size_t size); + static inline void env_set_max_readers(MDB_env* env, unsigned int count); + static inline void env_get_max_readers(MDB_env* env, unsigned int* count); + static inline void env_set_max_dbs(MDB_env* env, MDB_dbi count); + static inline unsigned int env_get_max_keysize(MDB_env* env); +#if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11) + static inline void env_set_userctx(MDB_env* env, void* ctx); + static inline void* env_get_userctx(MDB_env* env); +#endif + // TODO: mdb_env_set_assert() + // TODO: mdb_reader_list() + // TODO: mdb_reader_check() +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gaad6be3d8dcd4ea01f8df436f41d158d4 + */ +static inline void +lmdb::env_create(MDB_env** env) { + const int rc = ::mdb_env_create(env); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_create", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga32a193c6bf4d7d5c5d579e71f22e9340 + */ +static inline void +lmdb::env_open(MDB_env* const env, + const char* const path, + const unsigned int flags, + const mode mode) { + const int rc = ::mdb_env_open(env, path, flags, mode); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_open", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga3bf50d7793b36aaddf6b481a44e24244 + * @see http://symas.com/mdb/doc/group__mdb.html#ga5d51d6130325f7353db0955dbedbc378 + */ +static inline void +lmdb::env_copy(MDB_env* const env, +#if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14) + const char* const path, + const unsigned int flags = 0) { + const int rc = ::mdb_env_copy2(env, path, flags); +#else + const char* const path) { + const int rc = ::mdb_env_copy(env, path); +#endif + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_copy2", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga5040d0de1f14000fa01fc0b522ff1f86 + * @see http://symas.com/mdb/doc/group__mdb.html#ga470b0bcc64ac417de5de5930f20b1a28 + */ +static inline void +lmdb::env_copy_fd(MDB_env* const env, +#if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14) + const mdb_filehandle_t fd, + const unsigned int flags = 0) { + const int rc = ::mdb_env_copyfd2(env, fd, flags); +#else + const mdb_filehandle_t fd) { + const int rc = ::mdb_env_copyfd(env, fd); +#endif + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_copyfd2", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gaf881dca452050efbd434cd16e4bae255 + */ +static inline void +lmdb::env_stat(MDB_env* const env, + MDB_stat* const stat) { + const int rc = ::mdb_env_stat(env, stat); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_stat", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga18769362c7e7d6cf91889a028a5c5947 + */ +static inline void +lmdb::env_info(MDB_env* const env, + MDB_envinfo* const stat) { + const int rc = ::mdb_env_info(env, stat); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_info", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga85e61f05aa68b520cc6c3b981dba5037 + */ +static inline void +lmdb::env_sync(MDB_env* const env, + const bool force = true) { + const int rc = ::mdb_env_sync(env, force); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_sync", rc); + } +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#ga4366c43ada8874588b6a62fbda2d1e95 + */ +static inline void +lmdb::env_close(MDB_env* const env) noexcept { + ::mdb_env_close(env); +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga83f66cf02bfd42119451e9468dc58445 + */ +static inline void +lmdb::env_set_flags(MDB_env* const env, + const unsigned int flags, + const bool onoff = true) { + const int rc = ::mdb_env_set_flags(env, flags, onoff ? 1 : 0); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_set_flags", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga2733aefc6f50beb49dd0c6eb19b067d9 + */ +static inline void +lmdb::env_get_flags(MDB_env* const env, + unsigned int* const flags) { + const int rc = ::mdb_env_get_flags(env, flags); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_get_flags", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gac699fdd8c4f8013577cb933fb6a757fe + */ +static inline void +lmdb::env_get_path(MDB_env* const env, + const char** path) { + const int rc = ::mdb_env_get_path(env, path); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_get_path", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gaf1570e7c0e5a5d860fef1032cec7d5f2 + */ +static inline void +lmdb::env_get_fd(MDB_env* const env, + mdb_filehandle_t* const fd) { + const int rc = ::mdb_env_get_fd(env, fd); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_get_fd", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gaa2506ec8dab3d969b0e609cd82e619e5 + */ +static inline void +lmdb::env_set_mapsize(MDB_env* const env, + const std::size_t size) { + const int rc = ::mdb_env_set_mapsize(env, size); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_set_mapsize", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gae687966c24b790630be2a41573fe40e2 + */ +static inline void +lmdb::env_set_max_readers(MDB_env* const env, + const unsigned int count) { + const int rc = ::mdb_env_set_maxreaders(env, count); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_set_maxreaders", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga70e143cf11760d869f754c9c9956e6cc + */ +static inline void +lmdb::env_get_max_readers(MDB_env* const env, + unsigned int* const count) { + const int rc = ::mdb_env_get_maxreaders(env, count); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_get_maxreaders", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gaa2fc2f1f37cb1115e733b62cab2fcdbc + */ +static inline void +lmdb::env_set_max_dbs(MDB_env* const env, + const MDB_dbi count) { + const int rc = ::mdb_env_set_maxdbs(env, count); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_set_maxdbs", rc); + } +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#gaaf0be004f33828bf2fb09d77eb3cef94 + */ +static inline unsigned int +lmdb::env_get_max_keysize(MDB_env* const env) { + const int rc = ::mdb_env_get_maxkeysize(env); +#ifdef LMDBXX_DEBUG + assert(rc >= 0); +#endif + return static_cast(rc); +} + +#if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11) +/** + * @throws lmdb::error on failure + * @since 0.9.11 (2014/01/15) + * @see http://symas.com/mdb/doc/group__mdb.html#gaf2fe09eb9c96eeb915a76bf713eecc46 + */ +static inline void +lmdb::env_set_userctx(MDB_env* const env, + void* const ctx) { + const int rc = ::mdb_env_set_userctx(env, ctx); + if (rc != MDB_SUCCESS) { + error::raise("mdb_env_set_userctx", rc); + } +} +#endif + +#if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11) +/** + * @since 0.9.11 (2014/01/15) + * @see http://symas.com/mdb/doc/group__mdb.html#ga45df6a4fb150cda2316b5ae224ba52f1 + */ +static inline void* +lmdb::env_get_userctx(MDB_env* const env) { + return ::mdb_env_get_userctx(env); +} +#endif + +//////////////////////////////////////////////////////////////////////////////// +/* Procedural Interface: Transactions */ + +namespace lmdb { + static inline void txn_begin( + MDB_env* env, MDB_txn* parent, unsigned int flags, MDB_txn** txn); + static inline MDB_env* txn_env(MDB_txn* txn) noexcept; +#ifdef LMDBXX_TXN_ID + static inline std::size_t txn_id(MDB_txn* txn) noexcept; +#endif + static inline void txn_commit(MDB_txn* txn); + static inline void txn_abort(MDB_txn* txn) noexcept; + static inline void txn_reset(MDB_txn* txn) noexcept; + static inline void txn_renew(MDB_txn* txn); +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gad7ea55da06b77513609efebd44b26920 + */ +static inline void +lmdb::txn_begin(MDB_env* const env, + MDB_txn* const parent, + const unsigned int flags, + MDB_txn** txn) { + const int rc = ::mdb_txn_begin(env, parent, flags, txn); + if (rc != MDB_SUCCESS) { + error::raise("mdb_txn_begin", rc); + } +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#gaeb17735b8aaa2938a78a45cab85c06a0 + */ +static inline MDB_env* +lmdb::txn_env(MDB_txn* const txn) noexcept { + return ::mdb_txn_env(txn); +} + +#ifdef LMDBXX_TXN_ID +/** + * @note Only available in HEAD, not yet in any 0.9.x release (as of 0.9.16). + */ +static inline std::size_t +lmdb::txn_id(MDB_txn* const txn) noexcept { + return ::mdb_txn_id(txn); +} +#endif + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga846fbd6f46105617ac9f4d76476f6597 + */ +static inline void +lmdb::txn_commit(MDB_txn* const txn) { + const int rc = ::mdb_txn_commit(txn); + if (rc != MDB_SUCCESS) { + error::raise("mdb_txn_commit", rc); + } +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#ga73a5938ae4c3239ee11efa07eb22b882 + */ +static inline void +lmdb::txn_abort(MDB_txn* const txn) noexcept { + ::mdb_txn_abort(txn); +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#ga02b06706f8a66249769503c4e88c56cd + */ +static inline void +lmdb::txn_reset(MDB_txn* const txn) noexcept { + ::mdb_txn_reset(txn); +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga6c6f917959517ede1c504cf7c720ce6d + */ +static inline void +lmdb::txn_renew(MDB_txn* const txn) { + const int rc = ::mdb_txn_renew(txn); + if (rc != MDB_SUCCESS) { + error::raise("mdb_txn_renew", rc); + } +} + +//////////////////////////////////////////////////////////////////////////////// +/* Procedural Interface: Databases */ + +namespace lmdb { + static inline void dbi_open( + MDB_txn* txn, const char* name, unsigned int flags, MDB_dbi* dbi); + static inline void dbi_stat(MDB_txn* txn, MDB_dbi dbi, MDB_stat* stat); + static inline void dbi_flags(MDB_txn* txn, MDB_dbi dbi, unsigned int* flags); + static inline void dbi_close(MDB_env* env, MDB_dbi dbi) noexcept; + static inline void dbi_drop(MDB_txn* txn, MDB_dbi dbi, bool del); + static inline void dbi_set_compare(MDB_txn* txn, MDB_dbi dbi, MDB_cmp_func* cmp); + static inline void dbi_set_dupsort(MDB_txn* txn, MDB_dbi dbi, MDB_cmp_func* cmp); + static inline void dbi_set_relfunc(MDB_txn* txn, MDB_dbi dbi, MDB_rel_func* rel); + static inline void dbi_set_relctx(MDB_txn* txn, MDB_dbi dbi, void* ctx); + static inline bool dbi_get(MDB_txn* txn, MDB_dbi dbi, const MDB_val* key, MDB_val* data); + static inline bool dbi_put(MDB_txn* txn, MDB_dbi dbi, const MDB_val* key, MDB_val* data, unsigned int flags); + static inline bool dbi_del(MDB_txn* txn, MDB_dbi dbi, const MDB_val* key, const MDB_val* data); + // TODO: mdb_cmp() + // TODO: mdb_dcmp() +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gac08cad5b096925642ca359a6d6f0562a + */ +static inline void +lmdb::dbi_open(MDB_txn* const txn, + const char* const name, + const unsigned int flags, + MDB_dbi* const dbi) { + const int rc = ::mdb_dbi_open(txn, name, flags, dbi); + if (rc != MDB_SUCCESS) { + error::raise("mdb_dbi_open", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gae6c1069febe94299769dbdd032fadef6 + */ +static inline void +lmdb::dbi_stat(MDB_txn* const txn, + const MDB_dbi dbi, + MDB_stat* const result) { + const int rc = ::mdb_stat(txn, dbi, result); + if (rc != MDB_SUCCESS) { + error::raise("mdb_stat", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga95ba4cb721035478a8705e57b91ae4d4 + */ +static inline void +lmdb::dbi_flags(MDB_txn* const txn, + const MDB_dbi dbi, + unsigned int* const flags) { + const int rc = ::mdb_dbi_flags(txn, dbi, flags); + if (rc != MDB_SUCCESS) { + error::raise("mdb_dbi_flags", rc); + } +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#ga52dd98d0c542378370cd6b712ff961b5 + */ +static inline void +lmdb::dbi_close(MDB_env* const env, + const MDB_dbi dbi) noexcept { + ::mdb_dbi_close(env, dbi); +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#gab966fab3840fc54a6571dfb32b00f2db + */ +static inline void +lmdb::dbi_drop(MDB_txn* const txn, + const MDB_dbi dbi, + const bool del = false) { + const int rc = ::mdb_drop(txn, dbi, del ? 1 : 0); + if (rc != MDB_SUCCESS) { + error::raise("mdb_drop", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga68e47ffcf72eceec553c72b1784ee0fe + */ +static inline void +lmdb::dbi_set_compare(MDB_txn* const txn, + const MDB_dbi dbi, + MDB_cmp_func* const cmp = nullptr) { + const int rc = ::mdb_set_compare(txn, dbi, cmp); + if (rc != MDB_SUCCESS) { + error::raise("mdb_set_compare", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gacef4ec3dab0bbd9bc978b73c19c879ae + */ +static inline void +lmdb::dbi_set_dupsort(MDB_txn* const txn, + const MDB_dbi dbi, + MDB_cmp_func* const cmp = nullptr) { + const int rc = ::mdb_set_dupsort(txn, dbi, cmp); + if (rc != MDB_SUCCESS) { + error::raise("mdb_set_dupsort", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga697d82c7afe79f142207ad5adcdebfeb + */ +static inline void +lmdb::dbi_set_relfunc(MDB_txn* const txn, + const MDB_dbi dbi, + MDB_rel_func* const rel) { + const int rc = ::mdb_set_relfunc(txn, dbi, rel); + if (rc != MDB_SUCCESS) { + error::raise("mdb_set_relfunc", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga7c34246308cee01724a1839a8f5cc594 + */ +static inline void +lmdb::dbi_set_relctx(MDB_txn* const txn, + const MDB_dbi dbi, + void* const ctx) { + const int rc = ::mdb_set_relctx(txn, dbi, ctx); + if (rc != MDB_SUCCESS) { + error::raise("mdb_set_relctx", rc); + } +} + +/** + * @retval true if the key/value pair was retrieved + * @retval false if the key wasn't found + * @see http://symas.com/mdb/doc/group__mdb.html#ga8bf10cd91d3f3a83a34d04ce6b07992d + */ +static inline bool +lmdb::dbi_get(MDB_txn* const txn, + const MDB_dbi dbi, + const MDB_val* const key, + MDB_val* const data) { + const int rc = ::mdb_get(txn, dbi, const_cast(key), data); + if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) { + error::raise("mdb_get", rc); + } + return (rc == MDB_SUCCESS); +} + +/** + * @retval true if the key/value pair was inserted + * @retval false if the key already existed + * @see http://symas.com/mdb/doc/group__mdb.html#ga4fa8573d9236d54687c61827ebf8cac0 + */ +static inline bool +lmdb::dbi_put(MDB_txn* const txn, + const MDB_dbi dbi, + const MDB_val* const key, + MDB_val* const data, + const unsigned int flags = 0) { + const int rc = ::mdb_put(txn, dbi, const_cast(key), data, flags); + if (rc != MDB_SUCCESS && rc != MDB_KEYEXIST) { + error::raise("mdb_put", rc); + } + return (rc == MDB_SUCCESS); +} + +/** + * @retval true if the key/value pair was removed + * @retval false if the key wasn't found + * @see http://symas.com/mdb/doc/group__mdb.html#gab8182f9360ea69ac0afd4a4eaab1ddb0 + */ +static inline bool +lmdb::dbi_del(MDB_txn* const txn, + const MDB_dbi dbi, + const MDB_val* const key, + const MDB_val* const data = nullptr) { + const int rc = ::mdb_del(txn, dbi, const_cast(key), const_cast(data)); + if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) { + error::raise("mdb_del", rc); + } + return (rc == MDB_SUCCESS); +} + +//////////////////////////////////////////////////////////////////////////////// +/* Procedural Interface: Cursors */ + +namespace lmdb { + static inline void cursor_open(MDB_txn* txn, MDB_dbi dbi, MDB_cursor** cursor); + static inline void cursor_close(MDB_cursor* cursor) noexcept; + static inline void cursor_renew(MDB_txn* txn, MDB_cursor* cursor); + static inline MDB_txn* cursor_txn(MDB_cursor* cursor) noexcept; + static inline MDB_dbi cursor_dbi(MDB_cursor* cursor) noexcept; + static inline bool cursor_get(MDB_cursor* cursor, MDB_val* key, MDB_val* data, MDB_cursor_op op); + static inline void cursor_put(MDB_cursor* cursor, MDB_val* key, MDB_val* data, unsigned int flags); + static inline void cursor_del(MDB_cursor* cursor, unsigned int flags); + static inline void cursor_count(MDB_cursor* cursor, std::size_t& count); +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga9ff5d7bd42557fd5ee235dc1d62613aa + */ +static inline void +lmdb::cursor_open(MDB_txn* const txn, + const MDB_dbi dbi, + MDB_cursor** const cursor) { + const int rc = ::mdb_cursor_open(txn, dbi, cursor); + if (rc != MDB_SUCCESS) { + error::raise("mdb_cursor_open", rc); + } +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#gad685f5d73c052715c7bd859cc4c05188 + */ +static inline void +lmdb::cursor_close(MDB_cursor* const cursor) noexcept { + ::mdb_cursor_close(cursor); +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#gac8b57befb68793070c85ea813df481af + */ +static inline void +lmdb::cursor_renew(MDB_txn* const txn, + MDB_cursor* const cursor) { + const int rc = ::mdb_cursor_renew(txn, cursor); + if (rc != MDB_SUCCESS) { + error::raise("mdb_cursor_renew", rc); + } +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#ga7bf0d458f7f36b5232fcb368ebda79e0 + */ +static inline MDB_txn* +lmdb::cursor_txn(MDB_cursor* const cursor) noexcept { + return ::mdb_cursor_txn(cursor); +} + +/** + * @see http://symas.com/mdb/doc/group__mdb.html#ga2f7092cf70ee816fb3d2c3267a732372 + */ +static inline MDB_dbi +lmdb::cursor_dbi(MDB_cursor* const cursor) noexcept { + return ::mdb_cursor_dbi(cursor); +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga48df35fb102536b32dfbb801a47b4cb0 + */ +static inline bool +lmdb::cursor_get(MDB_cursor* const cursor, + MDB_val* const key, + MDB_val* const data, + const MDB_cursor_op op) { + const int rc = ::mdb_cursor_get(cursor, key, data, op); + if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) { + error::raise("mdb_cursor_get", rc); + } + return (rc == MDB_SUCCESS); +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga1f83ccb40011837ff37cc32be01ad91e + */ +static inline void +lmdb::cursor_put(MDB_cursor* const cursor, + MDB_val* const key, + MDB_val* const data, + const unsigned int flags = 0) { + const int rc = ::mdb_cursor_put(cursor, key, data, flags); + if (rc != MDB_SUCCESS) { + error::raise("mdb_cursor_put", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga26a52d3efcfd72e5bf6bd6960bf75f95 + */ +static inline void +lmdb::cursor_del(MDB_cursor* const cursor, + const unsigned int flags = 0) { + const int rc = ::mdb_cursor_del(cursor, flags); + if (rc != MDB_SUCCESS) { + error::raise("mdb_cursor_del", rc); + } +} + +/** + * @throws lmdb::error on failure + * @see http://symas.com/mdb/doc/group__mdb.html#ga4041fd1e1862c6b7d5f10590b86ffbe2 + */ +static inline void +lmdb::cursor_count(MDB_cursor* const cursor, + std::size_t& count) { + const int rc = ::mdb_cursor_count(cursor, &count); + if (rc != MDB_SUCCESS) { + error::raise("mdb_cursor_count", rc); + } +} + +//////////////////////////////////////////////////////////////////////////////// +/* Resource Interface: Values */ + +namespace lmdb { + class val; +} + +/** + * Wrapper class for `MDB_val` structures. + * + * @note Instances of this class are movable and copyable both. + * @see http://symas.com/mdb/doc/group__mdb.html#structMDB__val + */ +class lmdb::val { +protected: + MDB_val _val; + +public: + /** + * Default constructor. + */ + val() noexcept = default; + + /** + * Constructor. + */ + val(const std::string& data) noexcept + : val{data.data(), data.size()} {} + + /** + * Constructor. + */ + val(const char* const data) noexcept + : val{data, std::strlen(data)} {} + + /** + * Constructor. + */ + val(const void* const data, + const std::size_t size) noexcept + : _val{size, const_cast(data)} {} + + /** + * Move constructor. + */ + val(val&& other) noexcept = default; + + /** + * Move assignment operator. + */ + val& operator=(val&& other) noexcept = default; + + /** + * Destructor. + */ + ~val() noexcept = default; + + /** + * Returns an `MDB_val*` pointer. + */ + operator MDB_val*() noexcept { + return &_val; + } + + /** + * Returns an `MDB_val*` pointer. + */ + operator const MDB_val*() const noexcept { + return &_val; + } + + /** + * Determines whether this value is empty. + */ + bool empty() const noexcept { + return size() == 0; + } + + /** + * Returns the size of the data. + */ + std::size_t size() const noexcept { + return _val.mv_size; + } + + /** + * Returns a pointer to the data. + */ + template + T* data() noexcept { + return reinterpret_cast(_val.mv_data); + } + + /** + * Returns a pointer to the data. + */ + template + const T* data() const noexcept { + return reinterpret_cast(_val.mv_data); + } + + /** + * Returns a pointer to the data. + */ + char* data() noexcept { + return reinterpret_cast(_val.mv_data); + } + + /** + * Returns a pointer to the data. + */ + const char* data() const noexcept { + return reinterpret_cast(_val.mv_data); + } + + /** + * Assigns the value. + */ + template + val& assign(const T* const data, + const std::size_t size) noexcept { + _val.mv_size = size; + _val.mv_data = const_cast(reinterpret_cast(data)); + return *this; + } + + /** + * Assigns the value. + */ + val& assign(const char* const data) noexcept { + return assign(data, std::strlen(data)); + } + + /** + * Assigns the value. + */ + val& assign(const std::string& data) noexcept { + return assign(data.data(), data.size()); + } +}; + +#if !(defined(__COVERITY__) || defined(_MSC_VER)) +static_assert(std::is_pod::value, "lmdb::val must be a POD type"); +static_assert(sizeof(lmdb::val) == sizeof(MDB_val), "sizeof(lmdb::val) != sizeof(MDB_val)"); +#endif + +//////////////////////////////////////////////////////////////////////////////// +/* Resource Interface: Environment */ + +namespace lmdb { + class env; +} + +/** + * Resource class for `MDB_env*` handles. + * + * @note Instances of this class are movable, but not copyable. + * @see http://symas.com/mdb/doc/group__internal.html#structMDB__env + */ +class lmdb::env { +protected: + MDB_env* _handle{nullptr}; + +public: + static constexpr unsigned int default_flags = 0; + static constexpr mode default_mode = 0644; /* -rw-r--r-- */ + + /** + * Creates a new LMDB environment. + * + * @param flags + * @throws lmdb::error on failure + */ + static env create(const unsigned int flags = default_flags) { + MDB_env* handle{nullptr}; + lmdb::env_create(&handle); +#ifdef LMDBXX_DEBUG + assert(handle != nullptr); +#endif + if (flags) { + try { + lmdb::env_set_flags(handle, flags); + } + catch (const lmdb::error&) { + lmdb::env_close(handle); + throw; + } + } + return env{handle}; + } + + /** + * Constructor. + * + * @param handle a valid `MDB_env*` handle + */ + env(MDB_env* const handle) noexcept + : _handle{handle} {} + + /** + * Move constructor. + */ + env(env&& other) noexcept { + std::swap(_handle, other._handle); + } + + /** + * Move assignment operator. + */ + env& operator=(env&& other) noexcept { + if (this != &other) { + std::swap(_handle, other._handle); + } + return *this; + } + + /** + * Destructor. + */ + ~env() noexcept { + try { close(); } catch (...) {} + } + + /** + * Returns the underlying `MDB_env*` handle. + */ + operator MDB_env*() const noexcept { + return _handle; + } + + /** + * Returns the underlying `MDB_env*` handle. + */ + MDB_env* handle() const noexcept { + return _handle; + } + + /** + * Flushes data buffers to disk. + * + * @param force + * @throws lmdb::error on failure + */ + void sync(const bool force = true) { + lmdb::env_sync(handle(), force); + } + + /** + * Closes this environment, releasing the memory map. + * + * @note this method is idempotent + * @post `handle() == nullptr` + */ + void close() noexcept { + if (handle()) { + lmdb::env_close(handle()); + _handle = nullptr; + } + } + + /** + * Opens this environment. + * + * @param path + * @param flags + * @param mode + * @throws lmdb::error on failure + */ + env& open(const char* const path, + const unsigned int flags = default_flags, + const mode mode = default_mode) { + lmdb::env_open(handle(), path, flags, mode); + return *this; + } + + /** + * @param flags + * @param onoff + * @throws lmdb::error on failure + */ + env& set_flags(const unsigned int flags, + const bool onoff = true) { + lmdb::env_set_flags(handle(), flags, onoff); + return *this; + } + + /** + * @param size + * @throws lmdb::error on failure + */ + env& set_mapsize(const std::size_t size) { + lmdb::env_set_mapsize(handle(), size); + return *this; + } + + /** + * @param count + * @throws lmdb::error on failure + */ + env& set_max_readers(const unsigned int count) { + lmdb::env_set_max_readers(handle(), count); + return *this; + } + + /** + * @param count + * @throws lmdb::error on failure + */ + env& set_max_dbs(const MDB_dbi count) { + lmdb::env_set_max_dbs(handle(), count); + return *this; + } +}; + +//////////////////////////////////////////////////////////////////////////////// +/* Resource Interface: Transactions */ + +namespace lmdb { + class txn; +} + +/** + * Resource class for `MDB_txn*` handles. + * + * @note Instances of this class are movable, but not copyable. + * @see http://symas.com/mdb/doc/group__internal.html#structMDB__txn + */ +class lmdb::txn { +protected: + MDB_txn* _handle{nullptr}; + +public: + static constexpr unsigned int default_flags = 0; + + /** + * Creates a new LMDB transaction. + * + * @param env the environment handle + * @param parent + * @param flags + * @throws lmdb::error on failure + */ + static txn begin(MDB_env* const env, + MDB_txn* const parent = nullptr, + const unsigned int flags = default_flags) { + MDB_txn* handle{nullptr}; + lmdb::txn_begin(env, parent, flags, &handle); +#ifdef LMDBXX_DEBUG + assert(handle != nullptr); +#endif + return txn{handle}; + } + + /** + * Constructor. + * + * @param handle a valid `MDB_txn*` handle + */ + txn(MDB_txn* const handle) noexcept + : _handle{handle} {} + + /** + * Move constructor. + */ + txn(txn&& other) noexcept { + std::swap(_handle, other._handle); + } + + /** + * Move assignment operator. + */ + txn& operator=(txn&& other) noexcept { + if (this != &other) { + std::swap(_handle, other._handle); + } + return *this; + } + + /** + * Destructor. + */ + ~txn() noexcept { + if (_handle) { + try { abort(); } catch (...) {} + _handle = nullptr; + } + } + + /** + * Returns the underlying `MDB_txn*` handle. + */ + operator MDB_txn*() const noexcept { + return _handle; + } + + /** + * Returns the underlying `MDB_txn*` handle. + */ + MDB_txn* handle() const noexcept { + return _handle; + } + + /** + * Returns the transaction's `MDB_env*` handle. + */ + MDB_env* env() const noexcept { + return lmdb::txn_env(handle()); + } + + /** + * Commits this transaction. + * + * @throws lmdb::error on failure + * @post `handle() == nullptr` + */ + void commit() { + lmdb::txn_commit(_handle); + _handle = nullptr; + } + + /** + * Aborts this transaction. + * + * @post `handle() == nullptr` + */ + void abort() noexcept { + lmdb::txn_abort(_handle); + _handle = nullptr; + } + + /** + * Resets this read-only transaction. + */ + void reset() noexcept { + lmdb::txn_reset(_handle); + } + + /** + * Renews this read-only transaction. + * + * @throws lmdb::error on failure + */ + void renew() { + lmdb::txn_renew(_handle); + } +}; + +//////////////////////////////////////////////////////////////////////////////// +/* Resource Interface: Databases */ + +namespace lmdb { + class dbi; +} + +/** + * Resource class for `MDB_dbi` handles. + * + * @note Instances of this class are movable, but not copyable. + * @see http://symas.com/mdb/doc/group__mdb.html#gadbe68a06c448dfb62da16443d251a78b + */ +class lmdb::dbi { +protected: + MDB_dbi _handle{0}; + +public: + static constexpr unsigned int default_flags = 0; + static constexpr unsigned int default_put_flags = 0; + + /** + * Opens a database handle. + * + * @param txn the transaction handle + * @param name + * @param flags + * @throws lmdb::error on failure + */ + static dbi + open(MDB_txn* const txn, + const char* const name = nullptr, + const unsigned int flags = default_flags) { + MDB_dbi handle{}; + lmdb::dbi_open(txn, name, flags, &handle); + return dbi{handle}; + } + + /** + * Constructor. + * + * @param handle a valid `MDB_dbi` handle + */ + dbi(const MDB_dbi handle) noexcept + : _handle{handle} {} + + /** + * Move constructor. + */ + dbi(dbi&& other) noexcept { + std::swap(_handle, other._handle); + } + + /** + * Move assignment operator. + */ + dbi& operator=(dbi&& other) noexcept { + if (this != &other) { + std::swap(_handle, other._handle); + } + return *this; + } + + /** + * Destructor. + */ + ~dbi() noexcept { + if (_handle) { + /* No need to call close() here. */ + } + } + + /** + * Returns the underlying `MDB_dbi` handle. + */ + operator MDB_dbi() const noexcept { + return _handle; + } + + /** + * Returns the underlying `MDB_dbi` handle. + */ + MDB_dbi handle() const noexcept { + return _handle; + } + + /** + * Returns statistics for this database. + * + * @param txn a transaction handle + * @throws lmdb::error on failure + */ + MDB_stat stat(MDB_txn* const txn) const { + MDB_stat result; + lmdb::dbi_stat(txn, handle(), &result); + return result; + } + + /** + * Retrieves the flags for this database handle. + * + * @param txn a transaction handle + * @throws lmdb::error on failure + */ + unsigned int flags(MDB_txn* const txn) const { + unsigned int result{}; + lmdb::dbi_flags(txn, handle(), &result); + return result; + } + + /** + * Returns the number of records in this database. + * + * @param txn a transaction handle + * @throws lmdb::error on failure + */ + std::size_t size(MDB_txn* const txn) const { + return stat(txn).ms_entries; + } + + /** + * @param txn a transaction handle + * @param del + * @throws lmdb::error on failure + */ + void drop(MDB_txn* const txn, + const bool del = false) { + lmdb::dbi_drop(txn, handle(), del); + } + + /** + * Sets a custom key comparison function for this database. + * + * @param txn a transaction handle + * @param cmp the comparison function + * @throws lmdb::error on failure + */ + dbi& set_compare(MDB_txn* const txn, + MDB_cmp_func* const cmp = nullptr) { + lmdb::dbi_set_compare(txn, handle(), cmp); + return *this; + } + + /** + * Retrieves a key/value pair from this database. + * + * @param txn a transaction handle + * @param key + * @param data + * @throws lmdb::error on failure + */ + bool get(MDB_txn* const txn, + const val& key, + val& data) { + return lmdb::dbi_get(txn, handle(), key, data); + } + + /** + * Retrieves a key from this database. + * + * @param txn a transaction handle + * @param key + * @throws lmdb::error on failure + */ + bool get(MDB_txn* const txn, + const std::string& key) const { + const lmdb::val k{key}; + lmdb::val v{}; + return lmdb::dbi_get(txn, handle(), k, v); + } + + /** + * Retrieves a key from this database. + * + * @param txn a transaction handle + * @param key + * @throws lmdb::error on failure + */ + template + bool get(MDB_txn* const txn, + const K& key) const { + const lmdb::val k{&key, sizeof(K)}; + lmdb::val v{}; + return lmdb::dbi_get(txn, handle(), k, v); + } + + /** + * Retrieves a key/value pair from this database. + * + * @param txn a transaction handle + * @param key + * @param val + * @throws lmdb::error on failure + */ + template + bool get(MDB_txn* const txn, + const K& key, + V& val) const { + const lmdb::val k{&key, sizeof(K)}; + lmdb::val v{}; + const bool result = lmdb::dbi_get(txn, handle(), k, v); + if (result) { + val = *v.data(); + } + return result; + } + + /** + * Retrieves a key/value pair from this database. + * + * @param txn a transaction handle + * @param key a NUL-terminated string key + * @param val + * @throws lmdb::error on failure + */ + template + bool get(MDB_txn* const txn, + const char* const key, + V& val) const { + const lmdb::val k{key, std::strlen(key)}; + lmdb::val v{}; + const bool result = lmdb::dbi_get(txn, handle(), k, v); + if (result) { + val = *v.data(); + } + return result; + } + + /** + * Stores a key/value pair into this database. + * + * @param txn a transaction handle + * @param key + * @param data + * @param flags + * @throws lmdb::error on failure + */ + bool put(MDB_txn* const txn, + const val& key, + val& data, + const unsigned int flags = default_put_flags) { + return lmdb::dbi_put(txn, handle(), key, data, flags); + } + + /** + * Stores a key into this database. + * + * @param txn a transaction handle + * @param key + * @param flags + * @throws lmdb::error on failure + */ + template + bool put(MDB_txn* const txn, + const K& key, + const unsigned int flags = default_put_flags) { + const lmdb::val k{&key, sizeof(K)}; + lmdb::val v{}; + return lmdb::dbi_put(txn, handle(), k, v, flags); + } + + /** + * Stores a key/value pair into this database. + * + * @param txn a transaction handle + * @param key + * @param val + * @param flags + * @throws lmdb::error on failure + */ + template + bool put(MDB_txn* const txn, + const K& key, + const V& val, + const unsigned int flags = default_put_flags) { + const lmdb::val k{&key, sizeof(K)}; + lmdb::val v{&val, sizeof(V)}; + return lmdb::dbi_put(txn, handle(), k, v, flags); + } + + /** + * Stores a key/value pair into this database. + * + * @param txn a transaction handle + * @param key a NUL-terminated string key + * @param val + * @param flags + * @throws lmdb::error on failure + */ + template + bool put(MDB_txn* const txn, + const char* const key, + const V& val, + const unsigned int flags = default_put_flags) { + const lmdb::val k{key, std::strlen(key)}; + lmdb::val v{&val, sizeof(V)}; + return lmdb::dbi_put(txn, handle(), k, v, flags); + } + + /** + * Stores a key/value pair into this database. + * + * @param txn a transaction handle + * @param key a NUL-terminated string key + * @param val a NUL-terminated string key + * @param flags + * @throws lmdb::error on failure + */ + bool put(MDB_txn* const txn, + const char* const key, + const char* const val, + const unsigned int flags = default_put_flags) { + const lmdb::val k{key, std::strlen(key)}; + lmdb::val v{val, std::strlen(val)}; + return lmdb::dbi_put(txn, handle(), k, v, flags); + } + + /** + * Removes a key/value pair from this database. + * + * @param txn a transaction handle + * @param key + * @throws lmdb::error on failure + */ + bool del(MDB_txn* const txn, + const val& key) { + return lmdb::dbi_del(txn, handle(), key); + } + + /** + * Removes a key/value pair from this database. + * + * @param txn a transaction handle + * @param key + * @throws lmdb::error on failure + */ + template + bool del(MDB_txn* const txn, + const K& key) { + const lmdb::val k{&key, sizeof(K)}; + return lmdb::dbi_del(txn, handle(), k); + } +}; + +//////////////////////////////////////////////////////////////////////////////// +/* Resource Interface: Cursors */ + +namespace lmdb { + class cursor; +} + +/** + * Resource class for `MDB_cursor*` handles. + * + * @note Instances of this class are movable, but not copyable. + * @see http://symas.com/mdb/doc/group__internal.html#structMDB__cursor + */ +class lmdb::cursor { +protected: + MDB_cursor* _handle{nullptr}; + +public: + static constexpr unsigned int default_flags = 0; + + /** + * Creates an LMDB cursor. + * + * @param txn the transaction handle + * @param dbi the database handle + * @throws lmdb::error on failure + */ + static cursor + open(MDB_txn* const txn, + const MDB_dbi dbi) { + MDB_cursor* handle{}; + lmdb::cursor_open(txn, dbi, &handle); +#ifdef LMDBXX_DEBUG + assert(handle != nullptr); +#endif + return cursor{handle}; + } + + /** + * Constructor. + * + * @param handle a valid `MDB_cursor*` handle + */ + cursor(MDB_cursor* const handle) noexcept + : _handle{handle} {} + + /** + * Move constructor. + */ + cursor(cursor&& other) noexcept { + std::swap(_handle, other._handle); + } + + /** + * Move assignment operator. + */ + cursor& operator=(cursor&& other) noexcept { + if (this != &other) { + std::swap(_handle, other._handle); + } + return *this; + } + + /** + * Destructor. + */ + ~cursor() noexcept { + try { close(); } catch (...) {} + } + + /** + * Returns the underlying `MDB_cursor*` handle. + */ + operator MDB_cursor*() const noexcept { + return _handle; + } + + /** + * Returns the underlying `MDB_cursor*` handle. + */ + MDB_cursor* handle() const noexcept { + return _handle; + } + + /** + * Closes this cursor. + * + * @note this method is idempotent + * @post `handle() == nullptr` + */ + void close() noexcept { + if (_handle) { + lmdb::cursor_close(_handle); + _handle = nullptr; + } + } + + /** + * Renews this cursor. + * + * @param txn the transaction scope + * @throws lmdb::error on failure + */ + void renew(MDB_txn* const txn) { + lmdb::cursor_renew(txn, handle()); + } + + /** + * Returns the cursor's transaction handle. + */ + MDB_txn* txn() const noexcept { + return lmdb::cursor_txn(handle()); + } + + /** + * Returns the cursor's database handle. + */ + MDB_dbi dbi() const noexcept { + return lmdb::cursor_dbi(handle()); + } + + /** + * Retrieves a key from the database. + * + * @param key + * @param op + * @throws lmdb::error on failure + */ + bool get(MDB_val* const key, + const MDB_cursor_op op) { + return get(key, nullptr, op); + } + + /** + * Retrieves a key from the database. + * + * @param key + * @param op + * @throws lmdb::error on failure + */ + bool get(lmdb::val& key, + const MDB_cursor_op op) { + return get(key, nullptr, op); + } + + /** + * Retrieves a key/value pair from the database. + * + * @param key + * @param val (may be `nullptr`) + * @param op + * @throws lmdb::error on failure + */ + bool get(MDB_val* const key, + MDB_val* const val, + const MDB_cursor_op op) { + return lmdb::cursor_get(handle(), key, val, op); + } + + /** + * Retrieves a key/value pair from the database. + * + * @param key + * @param val + * @param op + * @throws lmdb::error on failure + */ + bool get(lmdb::val& key, + lmdb::val& val, + const MDB_cursor_op op) { + return lmdb::cursor_get(handle(), key, val, op); + } + + /** + * Retrieves a key/value pair from the database. + * + * @param key + * @param val + * @param op + * @throws lmdb::error on failure + */ + bool get(std::string& key, + std::string& val, + const MDB_cursor_op op) { + lmdb::val k{}, v{}; + const bool found = get(k, v, op); + if (found) { + key.assign(k.data(), k.size()); + val.assign(v.data(), v.size()); + } + return found; + } + + /** + * Positions this cursor at the given key. + * + * @param key + * @param op + * @throws lmdb::error on failure + */ + template + bool find(const K& key, + const MDB_cursor_op op = MDB_SET) { + lmdb::val k{&key, sizeof(K)}; + return get(k, nullptr, op); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* LMDBXX_H */ From 8f7459db23d6c82021dc4af3321304dc4c53db4c Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 25 Aug 2019 10:54:48 +0300 Subject: [PATCH 14/56] Add a class to guard access to the LMDB database The new class will be used to avoid passing the LMDB handle as an argument to every function. The implementation isn't very smart so far, but this can be improved without breaking the existing API. The new code is located in xhalarm because it is not usable on the client side. --- xhalcore/include/xhal/LMDB.h | 101 +++++++++++++++++++++++++++++ xhalcore/src/common/LMDB.cpp | 120 +++++++++++++++++++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 xhalcore/include/xhal/LMDB.h create mode 100644 xhalcore/src/common/LMDB.cpp diff --git a/xhalcore/include/xhal/LMDB.h b/xhalcore/include/xhal/LMDB.h new file mode 100644 index 0000000..475441f --- /dev/null +++ b/xhalcore/include/xhal/LMDB.h @@ -0,0 +1,101 @@ +/*! + * \file + * \brief This file contains utilities dealing with the LMDB register database. + * + * \author Louis Moureaux + */ + +#ifndef XHAL_LMDB_H +#define XHAL_LMDB_H + +#include + +namespace xhal { + + /** + * \brief Provides access to shared LMDB data structures. + * + * This class uses the "guard" pattern to provide access to LMDB data structures: an + * environment, a database handle and a read-only transaction. These objects are + * guaranteed to be accessible for the lifetime of the guard. + * + * This guard is recursive: several instances of it can safely be nested. The recommended + * usage patterns are as follows: + * + * * If the guard should be kept alive for the lifetime of an object, use private + * inheritance on the corresponding class. + * * If the guard is only required within a function, declare an instance of it. + * + * When the first guard is created, it sets up the objects required to read from the + * database. These objects are released automatically when the last guard is deleted. + * + * \warning This class is not thread-safe. + */ + class LMDBGuard + { + public: + /** + * \brief Constructs a guard. + */ + LMDBGuard(); + + /** + * \brief Copy constructor. + */ + LMDBGuard(const LMDBGuard &) = default; + + /** + * \brief Assignment operator. + */ + LMDBGuard &operator=(const LMDBGuard &) = default; + + /** + * \brief Move constructor. + */ + constexpr LMDBGuard(LMDBGuard &&) = default; + + /** + * \brief Move operator. + */ + // Can't be made constexpr in GCC 4.9 + LMDBGuard &operator=(LMDBGuard &&) = default; + + /** + * \brief Destructor. Resources are freed when the last guard is deleted. + */ + ~LMDBGuard() noexcept; + + /** + * \brief Retrieves the LMDB environment. + */ + lmdb::env &env() noexcept; + + /** + * \brief Retrieves the LMDB environment (\c const version). + */ + const lmdb::env &env() const noexcept; + + /** + * \brief Retrieves the LMDB database handle. + */ + lmdb::dbi &dbi() noexcept; + + /** + * \brief Retrieves the LMDB database handle (\c const version). + */ + const lmdb::dbi &dbi() const noexcept; + + /** + * \brief Retrieves a read-only LMDB transaction. + */ + lmdb::txn &rtxn() noexcept; + + /** + * \brief Retrieves a read-only LMDB transaction (\c const version). + */ + const lmdb::txn &rtxn() const noexcept; + }; + +} // namespace xhal + +#endif // XHAL_LMDB_H diff --git a/xhalcore/src/common/LMDB.cpp b/xhalcore/src/common/LMDB.cpp new file mode 100644 index 0000000..f8bec7d --- /dev/null +++ b/xhalcore/src/common/LMDB.cpp @@ -0,0 +1,120 @@ +#include "xhal/LMDB.h" + +#include +#include + +#define PATH_VAR "GEM_PATH" +#define DB_NAME "/address_table.mdb" + +namespace xhal { + namespace /* anonymous */ { + /// \brief Maximum size of the LMDB object, currently 50 MiB; + static const std::size_t MAP_SIZE = 50UL * 1024UL * 1024UL; + + /** + * \brief Creates the environment. + * + * Required as a separate function for the Singleton constructor. + */ + lmdb::env create_env() + { + auto env = lmdb::env::create(); + env.set_mapsize(MAP_SIZE); + + const char * path = std::getenv(PATH_VAR); + if (path == nullptr) { + throw std::runtime_error("Environment variable " PATH_VAR " is not defined"); + } + std::string fullPath = path; + fullPath += DB_NAME;; + env.open(fullPath.c_str(), 0, 0664); + + return env; + } + + /** + * \brief Shared data managed by the guards. + */ + struct Singleton + { + // NOTE: Order is important! + lmdb::env env; ///< \brief Environment + lmdb::txn rtxn; ///< \brief Read-only transaction + lmdb::dbi dbi; ///< \brief Database handle + + /** + * \brief Constructor. + * + * A constructor is required because LMDB objects don't have default constructors. + */ + Singleton() : // NOTE: Order is important! + env(create_env()), + rtxn(lmdb::txn::begin(env, nullptr, MDB_RDONLY)), + dbi(lmdb::dbi::open(rtxn, nullptr)) + { + } + }; + + /** + * \brief Points to the data managed by the guards. + */ + std::unique_ptr SINGLETON = nullptr; + + /** + * \brief The number of guards currently active. + */ + int GUARD_COUNT = 0; + } // anonymous namespace + + LMDBGuard::LMDBGuard() + { + if (GUARD_COUNT <= 0 || SINGLETON == nullptr) { + SINGLETON = std::unique_ptr(); // Initialize + GUARD_COUNT = 1; + } else if (GUARD_COUNT == std::numeric_limits::max()) { + throw std::runtime_error("Out of LMDB guard handles"); + } else { + ++GUARD_COUNT; // Add a reference + } + } + + LMDBGuard::~LMDBGuard() noexcept + { + --GUARD_COUNT; + if (GUARD_COUNT <= 0) { + // Free shared resources + SINGLETON = nullptr; + } + } + + lmdb::env &LMDBGuard::env() noexcept + { + return SINGLETON->env; + } + + const lmdb::env &LMDBGuard::env() const noexcept + { + return SINGLETON->env; + } + + lmdb::dbi &LMDBGuard::dbi() noexcept + { + return SINGLETON->dbi; + } + + const lmdb::dbi &LMDBGuard::dbi() const noexcept + { + return SINGLETON->dbi; + } + + lmdb::txn &LMDBGuard::rtxn() noexcept + { + return SINGLETON->rtxn; + } + + const lmdb::txn &LMDBGuard::rtxn() const noexcept + { + return SINGLETON->rtxn; + } + +} // namespace xhal From a390dbd835250ab0a6c3318d9e5a919b66b2889f Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 12 Aug 2019 16:40:09 +0200 Subject: [PATCH 15/56] add CI templates * fix bug in arm makefile for packaging --- .gitlab-ci.yml | 394 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 18 ++- config | 2 +- python/Makefile | 10 +- xhalarm/Makefile | 25 ++- xhalcore/Makefile | 20 ++- 6 files changed, 446 insertions(+), 23 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..70769c5 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,394 @@ +## GitLab Continuous Integration YAML file + +## ------------------- used variables: ------------------- ## + # https://gitlab.cern.ch/help/ci/variables/README.md + # CI_COMMIT_TAG + # CI_COMMIT_REF_NAME + # CI_COMMIT_SHA + # CI_MERGE_REQUEST_TARGET_BRANCH_NAME + # CI_MERGE_REQUEST_TARGET_BRANCH_SHA + # GITLAB_USER_EMAIL + # GITLAB_USER_ID + # GITLAB_USER_LOGIN + # GITLAB_USER_NAME + +## ------------------- used secure variables: ------------------- ## + # EOS_ACCOUNT_USERNAME: Username of to write in the EOS folder whose path is EOS_PATH + # EOS_ACCOUNT_PASSWORD: Account password + # KRB_PASSWORD + # KRB_USERNAME + # CI_DEPLOY_USER + # CI_DEPLOY_PASSWORD + +## ------------------- Stage definitions ------------------- ## +stages: + - compile # compile the sources, make the docs (if requested) + - docs # compile the docs (if requested) + - package # build the RPMs + - test # test the packages (install, run basic tests) + - publish # publish the RPMs and docs + - deploy # deploy the RPMs and docs + +## ------------------- Define up anchors for various tasks, shared across all jobs utilizing them ------------------- ## +.common_variables: &common_variables + EOS_SITE_URL: http://cmsgemdaq.cern.ch + BUILD_HOME: /builds/${CI_PROJECT_NAMESPACE} + XDAQ_OS: linux + XDAQ_ROOT: /opt/xdaq + LD_LIBRARY_PATH: /opt/xdaq/lib:/opt/reedmuller/lib:/opt/wiscrpcsvc/lib + PACKAGE_NAME: ${CI_PROJECT_NAME} + ARTIFACTS_DIR: artifacts + GIT_SUBMODULE_STRATEGY: normal + PETA_STAGE: /data/bigdisk/sw/peta-stage + # REPO_NAME: ${${CI_REPOSITORY_URL##?*/}%%.*} + +variables: *common_variables + +## ------------------- Set up images for specified job types ------------------- # +.slc6setup: &slc6setup + image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:slc6 + +.cc7setup: &cc7setup + image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7 + # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7:xdaq14-6 + # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7:xdaq15 + +.cc8setup: &cc8setup + image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc8 + # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc8:python2 + # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc8:python3 + +### ------------------- Shared setup between stages ------------------- ### +.common_setup: &common_setup + - mkdir -p ${ARTIFACTS_DIR} + ## need to pull in all dependencies, based on some requirements, preferably the spec file? + ## cache this stuff between builds? + ## should be in the Docker image + - | + pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" + sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* + sudo yum install -y reedmuller\* --enablerepo=gemos* + +.retry_settings: &retry_settings + retry: + max: 2 + when: + - runner_system_failure + - stuck_or_timeout_failure + +.common_cache: &common_cache + # key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" + # key: "$BUILD_ARCH" + untracked: true + paths: + - ~/.cache/pip + # - /opt/ctp7_modules + # - /opt/reedmuller + # - /opt/reg_utils + # - /opt/rwreg + # - /opt/wiscrpcsvc + # - /opt/xhal + +.common_artifacts: &common_artifacts + name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" + expire_in: 1d + paths: + - ${ARTIFACTS_DIR} + +##### ------------------- Run compilation ------------------- ##### +.compile_artifacts: &compile_artifacts + untracked: true + <<: *common_artifacts + # paths: + # - ${ARTIFACTS_DIR} + +.before_compile: &before_compile + - mkdir -p ${ARTIFACTS_DIR} + ## these are set in the Dockerfile, but don't work in the gitlab CI by default? + - export BUILD_HOME=/builds/$CI_PROJECT_NAMESPACE + - export ARTIFACTS_DIR=$BUILD_HOME/artifacts + ## need to pull in all cmsgemos dependencies, based on some requirements, preferably the spec file? + ## cache this stuff between builds? + ## set up Xilinx peta/Zynq compiler + - source /data/bigdisk/sw/Xilinx/SDK/2016.2/settings64.sh + +.compile_common: &compile_common + only: + - /^issue.*$/ + - /^hotfix.*$/ + - /^release.*$/ + - /^feature.*$/ + - /^citest.*$/ + - develop + - master + - tags + tags: + stage: compile + before_script: + *before_compile + script: + - make all -j8 + # - mkdir ${ARTIFACTS_DIR}/${XDAQ_PLATFORM} + # - find . -iname '*.so' -print0 -exec mv -t ${ARTIFACTS_DIR}/${XDAQ_PLATFORM} {} \+ + after_script: + - ls -la ${ARTIFACTS_DIR} + artifacts: + name: ${CI_JOB_STAGE} + <<: *compile_artifacts + +compile:cc7: + <<: *cc7setup + <<: *compile_common + environment: + variables: + cache: + +# compile:cc8: +# <<: *cc8setup +# <<: *compile_common +# environment: +# variables: +# cache: + +##### ------------------- Generate docs ------------------- ##### +.docs_artifacts: &docs_artifacts + untracked: true + <<: *common_artifacts + # paths: + # - ${ARTIFACTS_DIR} + # - doc/build/html + +# generate docs +docs: + <<: *cc7setup + stage: compile + only: + - /^feature.*ci-cd*$/ + - /^citest.*$/ + - /^develop$/ + - /^release.*$/ + - tags + - master + dependencies: + before_script: + - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` + - eval `set | egrep '^(BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` + script: + - make doc + # - doxygen -s ${BUILD_HOME}/doc/cmsgemos.cfg >& /dev/null + after_script: + - | + mkdir -p ${ARTIFACTS_DIR}/api + mv -t ${ARTIFACTS_DIR}/api/ doc/build/html/* + artifacts: + name: ${CI_JOB_STAGE} + <<: *docs_artifacts + coverage: '/Documentation coverage: \d+\.\d+/' + +##### ------------------- Run tests using the compiled binaries ------------------- ##### +.before_test: &before_test + - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` + - eval `set | egrep '^(BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` + - | + sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* + sudo yum install -y reedmuller\* --enablerepo=gemos* + +# run tests using the binary built before +test:cc7: + <<: *cc7setup + stage: test + dependencies: + - compile:cc7 + before_script: + *before_test + script: + - echo ./runmytests.sh + after_script: + - 'echo "FIXME: parse-abi-changes.sh"' + - 'echo "FIXME: test summary"' + coverage: '/Test coverage: \d+\.\d+/' + +# test:cc8: +# <<: *cc8setup +# stage: test +# dependencies: +# - compile:cc8 +# before_script: +# *before_test +# script: +# - echo ./runmytests.sh +# after_script: +# - 'echo "FIXME: parse-abi-changes.sh"' +# - 'echo "FIXME: test summary"' +# coverage: '/Test coverage: \d+\.\d+/' + +##### ------------------- Package generated files into RPMs and tarballs ------------------- ##### +.package_artifacts: &package_artifacts + untracked: true + <<: *common_artifacts + # paths: + # - ${ARTIFACTS_DIR} + +.before_package: &before_package + - mkdir -p ${ARTIFACTS_DIR} + - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` + - eval `set | egrep '^(BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` + - | + pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" + sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* + sudo yum install -y reedmuller\* --enablerepo=gemos* + +.package_common: &package_common + stage: package + before_script: + *before_package + script: + ## Ensure compile artifacts are more recent than the checkout + - | + find ./ -type f -name '*.d' -print0 -exec touch {} \; + find ./ -type f -name '*.o' -print0 -exec touch {} \; + find ./ -type f -name '*.so' -print0 -exec touch {} \; + - make release + ## Move packaged files to deployment staging area + - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` + - eval `set | egrep '^(EOS|BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` + - mv repos ${ARTIFACTS_DIR} + after_script: + - ls -la ${ARTIFACTS_DIR} + - ls -la ${ARTIFACTS_DIR}/repos + artifacts: + name: ${CI_JOB_STAGE} + <<: *package_artifacts + +# generate RPMs +package:cc7:unstable: + <<: *cc7setup + only: + - /^develop$/ + - /^feature.*ci-cd*$/ + - /^citest.*$/ + # - triggers ## should go into releases/'testing' or unstable? + # - chat ## should go into releases/'testing' or unstable? + # - api ## should go into releases/'testing' or unstable? + tags: + variables: + COMPILER: 'gcc' + PYEXE: 'python2.7' + PACKAGE_TYPE: 'unstable' + dependencies: + - compile:cc7 + - docs + <<: *package_common + +package:cc7:testing: + <<: *cc7setup + only: + - /^release.*$/ + tags: + variables: + COMPILER: 'gcc' + PYEXE: 'python2.7' + PACKAGE_TYPE: 'testing' + dependencies: + - compile:cc7 + - docs + <<: *package_common + +package:cc7:base: + <<: *cc7setup + only: + - tags + tags: + variables: + COMPILER: 'gcc' + PYEXE: 'python2.7' + PACKAGE_TYPE: 'base' + dependencies: + - compile:cc7 + - docs + <<: *package_common + +# package:cc8: +# <<: *cc8setup +# dependencies: +# - compile:cc8 +# - docs +# <<: *package_common + +##### ------------------- Publish RPMs, docs, and tarballs ------------------- ##### +.publish_variables: &publish_variables + EOS_BASE_WEB_DIR: "/eos/project/c/cmsgemdaq/www" + EOS_COMMON_WEB_DIR: "cmsgemdaq" + EOS_DOC_NAME: "api" + EOS_REPO_NAME: "repos" + EOS_SITE_WEB_DIR: "${EOS_BASE_WEB_DIR}/${CI_PROJECT_NAME}" + EOS_SW_DIR: "${EOS_BASE_WEB_DIR}/sw/${CI_PROJECT_NAME}" + EOS_DOCS_DIR: "${EOS_BASE_WEB_DIR}/docs/${CI_PROJECT_NAME}" + EOS_UNSTABLE_DIR: "${EOS_BASE_WEB_DIR}/sw/${CI_PROJECT_NAME}/unstable" + EOS_RELEASE_DIR: "${EOS_BASE_WEB_DIR}/sw/${CI_PROJECT_NAME}/releases" + +.publish_common: &publish_common + <<: *cc7setup + stage: publish + variables: *publish_variables + before_script: + - eval `set | egrep '^(KRB|CI|GIT)' | awk -F= '{ print "export " $1 }'` + - eval `set | egrep '^(EOS|BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` + script: + # - push python packages to pypi/conda + # - push RPMs to packagecloud.io + # - push RPMs to gitlab yum repo, a la xDAQ? + # - push sphinx/rst/md/rtd docs to readthedocs.io + # - push sphinx/rst/md/rtd docs to $EOS_WEB_DIR/docs/${fulltag}, update doc main page index + - 'echo "FIXME: github_changelog_generator"' + - 'echo "FIXME: cp CHANGELOG.md ${ARTIFACTS_DIR}"' + - ${BUILD_HOME}/${CI_PROJECT_NAME}/config/ci/publish_eos.sh + - if [ -n "${DEBUG_CI}" ]; then sleep 500; fi + +# publish:debug: +# variables: +# EOS_BASE_WEB_DIR: /tmp/ +# <<: *publish_common +# variables: +# DEBUG_CI: 'yes' +# only: +# - /^citest.*$/ +# when: manual +# after_script: + +publish:unstable: + variables: + EOS_BASE_WEB_DIR: /tmp/ + <<: *publish_common + only: + - /^feature.*ci-cd*$/ + - /^citest.*$/ + - /^develop$/ + dependencies: + - package:cc7:unstable + after_script: + - ls -la ${ARTIFACTS_DIR} + +publish:testing: + <<: *publish_common + only: + - /^release.*$/ + dependencies: + - package:cc7:testing + after_script: + # - notify mattermost + # - send email + # - generate_release.sh pre + +publish:base: + <<: *publish_common + only: + - tags + dependencies: + - package:cc7:base + after_script: + - 'echo "FIXME: github_changelog_generator"' + - 'echo "FIXME: generate_release_notes.sh"' + # - notify mattermost + # - send email + # - generate_release.sh rel diff --git a/Makefile b/Makefile index eefe368..b7faa4f 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ SUBPACKAGES := \ SUBPACKAGES.CLEAN := $(patsubst %,%.clean, $(SUBPACKAGES)) SUBPACKAGES.DEBUG := $(patsubst %,%.debug, $(SUBPACKAGES)) SUBPACKAGES.INSTALL := $(patsubst %,%.install, $(SUBPACKAGES)) +SUBPACKAGES.RELEASE := $(patsubst %,%.release, $(SUBPACKAGES)) SUBPACKAGES.UNINSTALL:= $(patsubst %,%.uninstall,$(SUBPACKAGES)) SUBPACKAGES.RPM := $(patsubst %,%.rpm, $(SUBPACKAGES)) SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) @@ -16,17 +17,20 @@ SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) $(SUBPACKAGES.CLEAN) \ $(SUBPACKAGES.INSTALL) \ $(SUBPACKAGES.UNINSTALL) \ + $(SUBPACKAGES.RELEASE) \ $(SUBPACKAGES.RPM) \ $(SUBPACKAGES.CLEANRPM) \ $(SUBPACKAGES.DOC) \ $(SUBPACKAGES.CLEANDOC) -.PHONY: all build clean cleanall cleandoc cleanrpm +.PHONY: all build doc install uninstall rpm release +.PHONY: clean cleanall cleandoc cleanrpm cleanrelease build: $(SUBPACKAGES) all: $(SUBPACKAGES) $(SUBPACKAGES.DOC) doc: $(SUBPACKAGES.DOC) +# copy generated docs to common location? rpm: $(SUBPACKAGES) $(SUBPACKAGES.RPM) @@ -35,12 +39,19 @@ clean: $(SUBPACKAGES.CLEAN) cleanrpm: $(SUBPACKAGES.CLEANRPM) cleandoc: $(SUBPACKAGES.CLEANDOC) +# remove generated common docs install: $(SUBPACKAGES) $(SUBPACKAGES.INSTALL) uninstall: $(SUBPACKAGES.UNINSTALL) -cleanall: clean cleandoc cleanrpm +release: $(SUBPACKAGES.RELEASE) +# put generated files into release tree + +cleanrelease: + rm -rf repos + +cleanall: clean cleandoc cleanrpm cleanrelease $(SUBPACKAGES): $(MAKE) -C $@ @@ -66,6 +77,9 @@ $(SUBPACKAGES.INSTALL): $(SUBPACKAGES) $(SUBPACKAGES.UNINSTALL): $(SUBPACKAGES) $(MAKE) -C $(patsubst %.uninstall,%, $@) uninstall +$(SUBPACKAGES.RELEASE): $(SUBPACKAGES) + $(MAKE) -C $(patsubst %.release,%, $@) release + python: xhalarm: diff --git a/config b/config index 2b443a8..1a7cccf 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 2b443a880b5090bdd85d49c2044f4d42f8612ea7 +Subproject commit 1a7cccfb4fb87790305a85fb9a90803d44eaf717 diff --git a/python/Makefile b/python/Makefile index 4156039..9e94e22 100644 --- a/python/Makefile +++ b/python/Makefile @@ -4,6 +4,7 @@ SUBPACKAGES := \ SUBPACKAGES.CLEAN := $(patsubst %,%.clean, $(SUBPACKAGES)) SUBPACKAGES.DEBUG := $(patsubst %,%.debug, $(SUBPACKAGES)) SUBPACKAGES.INSTALL := $(patsubst %,%.install, $(SUBPACKAGES)) +SUBPACKAGES.RELEASE := $(patsubst %,%.release, $(SUBPACKAGES)) SUBPACKAGES.UNINSTALL:= $(patsubst %,%.uninstall,$(SUBPACKAGES)) SUBPACKAGES.RPM := $(patsubst %,%.rpm, $(SUBPACKAGES)) SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) @@ -14,12 +15,14 @@ SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) $(SUBPACKAGES.CLEAN) \ $(SUBPACKAGES.INSTALL) \ $(SUBPACKAGES.UNINSTALL) \ + $(SUBPACKAGES.RELEASE) \ $(SUBPACKAGES.RPM) \ $(SUBPACKAGES.CLEANRPM) \ $(SUBPACKAGES.DOC) \ $(SUBPACKAGES.CLEANDOC) -.PHONY: all build clean cleanall cleandoc cleanrpm doc install uninstall rpm +.PHONY: all build doc install uninstall rpm release +.PHONY: clean cleanall cleandoc cleanrpm build: $(SUBPACKAGES) all: $(SUBPACKAGES) $(SUBPACKAGES.DOC) @@ -38,6 +41,8 @@ install: $(SUBPACKAGES.INSTALL) uninstall: $(SUBPACKAGES.UNINSTALL) +release: $(SUBPACKAGES.RELEASE) + cleanall: clean cleandoc cleanrpm $(SUBPACKAGES): @@ -63,3 +68,6 @@ $(SUBPACKAGES.INSTALL): $(SUBPACKAGES.UNINSTALL): $(MAKE) -C $(patsubst %.uninstall,%, $@) uninstall-site + +$(SUBPACKAGES.RELEASE): $(SUBPACKAGES) + $(MAKE) -C $(patsubst %.release,%, $@) release diff --git a/xhalarm/Makefile b/xhalarm/Makefile index 33bbfc6..b066776 100644 --- a/xhalarm/Makefile +++ b/xhalarm/Makefile @@ -18,6 +18,7 @@ include $(ConfigDir)/mfRPMRules.mk PackageSourceDir:=$(ProjectPath)/xhalcore/src/common PackageIncludeDir:=$(ProjectPath)/xhalcore/include +PackageObjectDir:=$(PackagePath)/src/linux/$(Arch) XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') @@ -46,25 +47,25 @@ TargetLibraries:= xhal # destination path macro we'll use below df = $(PackageObjectDir)/$(*F) +## @xhalarm Compile all target libraries +build: $(TargetLibraries) + +all: build + default: build - @echo "Running default target" -# @cp -rfp $(ProjectPath)/xhalcore/src/common $(PackagePath)/src/ - $(MakeDir) $(PackageDir) -rpmprep: default +## @xhalarm Prepare the package for building the RPM +rpmprep: build @echo "Running preprpm target" $(MakeDir) $(PackageDir)/$(Package) - @cp -rfp lib include src Makefile $(PackageDir)/$(Package) + @cp -rfp lib include Makefile $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/config $(PackageDir) + cd $(ProjectPath); cp -rfp --parents xhalcore/{include,src/common} $(PackagePath)/$(PackageDir) $(MakeDir) $(RPMBUILD_DIR)/SOURCES cd $(PackageDir)/..; \ - ls -l; \ - tar cjf $(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION).tbz2 $(PackageName); \ - ls -l; \ - mv $(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION).tbz2 $(RPMBUILD_DIR)/SOURCES; - -all: build + tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION)-$(PACKAGE_NOARCH_RELEASE).tbz2 $(PackageName); +## @xhalarm Compile the xhal library xhal: $(XHAL_LIB) doc: @@ -98,8 +99,6 @@ $(XHAL_LIB): $(OBJS_XHAL) # %.o: %.cc # $(CXX) -std=c++0x -c $(CFLAGS) -o $@ $< -build: $(TargetLibraries) - clean: -rm -rf $(OBJS_XHAL) -rm -rf $(PackageLibraryDir) diff --git a/xhalcore/Makefile b/xhalcore/Makefile index b614499..d8aa326 100644 --- a/xhalcore/Makefile +++ b/xhalcore/Makefile @@ -17,6 +17,7 @@ include $(ConfigDir)/mfPythonDefs.mk include $(ConfigDir)/mfRPMRules.mk PackageSourceDir:=$(PackagePath)/src/common +PackageObjectDir:=$(PackagePath)/src/linux/$(Arch) XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') @@ -66,25 +67,35 @@ df = $(PackageObjectDir)/$(*F) .PHONY: xhal rpc +## @xhalcore Compile all target libraries +build: $(TargetLibraries) + +all: build + default: build @echo "Running default target" $(MakeDir) $(PackageDir) -rpmprep: default +## @xhalcore Prepare the package for building the RPM +rpmprep: build @echo "Running preprpm target" $(MakeDir) lib/arm $(MakeDir) $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/xhalarm/lib/*.so lib/arm - @cp -rfp lib include src Makefile $(PackageDir)/$(Package) + @cp -rfp lib include Makefile $(PackageDir)/$(Package) + @cp -rfp --parents src/common $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/config $(PackageDir) $(MakeDir) $(RPMBUILD_DIR)/SOURCES cd $(PackageDir)/..; \ - tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION).tbz2 $(PackageName); + tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION)-$(PACKAGE_NOARCH_RELEASE).tbz2 $(PackageName); +## @xhalcore Compile the xhal RPC manager library rpc: xhal $(RPCMAN_LIB) +## @xhalcore Compile the xhal library xhal: $(XHAL_LIB) +## @xhalcore Compile the xhal python bindings xhalpy: xhal rpc $(XHALPY_LIB) doc: @@ -120,9 +131,6 @@ $(RPCMAN_LIB): $(OBJS_RPCMAN) $(MakeDir) -p $(@D) $(CXX) $(ADDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) -## xhalcore Compile $(TargetLibraries) -build: $(TargetLibraries) - clean: -rm -rf $(OBJS_UTILS) $(OBJS_XHAL) $(OBJS_RPCMAN) $(OBJS_XHALPY) -rm -rf $(PackageLibraryDir) From 6ea7306e1000ca432bc4c546a9a07d4f9f0a31f1 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Sun, 18 Aug 2019 16:28:59 +0200 Subject: [PATCH 16/56] Compiling with SONAMEs --- Makefile | 7 ++++++- config | 2 +- xhalarm/Makefile | 18 ++++++++++-------- xhalcore/Makefile | 29 +++++++++++++++++------------ 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index b7faa4f..ceef551 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,12 @@ build: $(SUBPACKAGES) all: $(SUBPACKAGES) $(SUBPACKAGES.DOC) doc: $(SUBPACKAGES.DOC) -# copy generated docs to common location? + @echo "Generating project doxygen" + @echo "TO DO" +# @mkdir ./doc/build +# @rm -fr ./doc/build/* 2> /dev/null +# @doxygen -s ./doc/doxygen_conf +# copy generated docs to common location for release? rpm: $(SUBPACKAGES) $(SUBPACKAGES.RPM) diff --git a/config b/config index 1a7cccf..f9384d4 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 1a7cccfb4fb87790305a85fb9a90803d44eaf717 +Subproject commit f9384d4738c6d4b243d45673444b7d60433da0f6 diff --git a/xhalarm/Makefile b/xhalarm/Makefile index b066776..d714b84 100644 --- a/xhalarm/Makefile +++ b/xhalarm/Makefile @@ -58,9 +58,10 @@ default: build rpmprep: build @echo "Running preprpm target" $(MakeDir) $(PackageDir)/$(Package) - @cp -rfp lib include Makefile $(PackageDir)/$(Package) + @cp -rfp lib include src Makefile $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/config $(PackageDir) - cd $(ProjectPath); cp -rfp --parents xhalcore/{include,src/common} $(PackagePath)/$(PackageDir) + cd $(ProjectPath); cp -rfp xhalcore/{include,src} $(PackagePath)/$(PackageDir) +# cd $(ProjectPath); cp -rfp --parents xhalcore/{include,src/common} $(PackagePath)/$(PackageDir) $(MakeDir) $(RPMBUILD_DIR)/SOURCES cd $(PackageDir)/..; \ tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION)-$(PACKAGE_NOARCH_RELEASE).tbz2 $(PackageName); @@ -91,7 +92,8 @@ $(TargetLibraries): $(XHAL_LIB): $(OBJS_XHAL) $(MakeDir) -p $(@D) - $(CC) $(ADDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) + $(CC) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(link-sonames) ## FIXME obsolete? only for xcompiled things? # %.o: %.c @@ -100,13 +102,13 @@ $(XHAL_LIB): $(OBJS_XHAL) # $(CXX) -std=c++0x -c $(CFLAGS) -o $@ $< clean: - -rm -rf $(OBJS_XHAL) - -rm -rf $(PackageLibraryDir) - -rm -rf $(PackageExecDir) - -rm -rf $(PackageDir) + $(RM) $(OBJS_XHAL) + $(RM) $(PackageLibraryDir) + $(RM) $(PackageExecDir) + $(RM) $(PackageDir) cleandoc: @echo "TO DO" cleanall: - -rm -rf $(PackageObjectDir) + $(RM) $(PackageObjectDir) diff --git a/xhalcore/Makefile b/xhalcore/Makefile index d8aa326..59f5252 100644 --- a/xhalcore/Makefile +++ b/xhalcore/Makefile @@ -36,7 +36,7 @@ LibraryDirs+=-L$(XDAQ_ROOT)/lib LibraryDirs+=-L$(PackageLibraryDir) LibraryDirs+=-L/opt/wiscrpcsvc/lib -LDFLAGS = -shared $(LibraryDirs) +LDFLAGS+= -shared $(LibraryDirs) SRCS_XHAL = $(wildcard $(PackageSourceDir)/*.cpp) SRCS_UTILS = $(wildcard $(PackageSourceDir)/utils/*.cpp) @@ -77,17 +77,19 @@ default: build $(MakeDir) $(PackageDir) ## @xhalcore Prepare the package for building the RPM -rpmprep: build +rpmprep: build doc @echo "Running preprpm target" $(MakeDir) lib/arm $(MakeDir) $(PackageDir)/$(Package) - @cp -rfp $(ProjectPath)/xhalarm/lib/*.so lib/arm + @cp -rfp $(ProjectPath)/xhalarm/lib/* lib/arm @cp -rfp lib include Makefile $(PackageDir)/$(Package) - @cp -rfp --parents src/common $(PackageDir)/$(Package) + @cp -rfp src $(PackageDir)/$(Package) +# @cp -rfp --parents src/common $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/config $(PackageDir) $(MakeDir) $(RPMBUILD_DIR)/SOURCES cd $(PackageDir)/..; \ tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION)-$(PACKAGE_NOARCH_RELEASE).tbz2 $(PackageName); + $(RM) $(PackageDir)/$(Package) ## @xhalcore Compile the xhal RPC manager library rpc: xhal $(RPCMAN_LIB) @@ -121,24 +123,27 @@ $(TargetLibraries): $(XHAL_LIB): $(OBJS_XHAL) $(OBJS_UTILS) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(link-sonames) $(XHALPY_LIB): $(OBJS_XHALPY) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal -lrpcman + $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal -lrpcman + $(link-sonames) $(RPCMAN_LIB): $(OBJS_RPCMAN) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(@F) -o $@ $^ $(Libraries) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(link-sonames) clean: - -rm -rf $(OBJS_UTILS) $(OBJS_XHAL) $(OBJS_RPCMAN) $(OBJS_XHALPY) - -rm -rf $(PackageLibraryDir) - -rm -rf $(PackageExecDir) - -rm -rf $(PackageDir) + $(RM) $(OBJS_UTILS) $(OBJS_XHAL) $(OBJS_RPCMAN) $(OBJS_XHALPY) + $(RM) $(PackageLibraryDir) + $(RM) $(PackageExecDir) + $(RM) $(PackageDir) cleandoc: @echo "TO DO" cleanall: - -rm -rf $(PackageObjectDir) + $(RM) $(PackageObjectDir) From 672cf00e535a18112b9d1984bc898f3441e20761 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 19 Aug 2019 17:34:28 +0200 Subject: [PATCH 17/56] Only rebuild packages when required --- Makefile | 2 +- config | 2 +- python/reg_interface_gem/Makefile | 17 ++++++++++------- xhalarm/Makefile | 16 ++++++++++------ xhalcore/Makefile | 23 +++++++++++++---------- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index ceef551..127528a 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ release: $(SUBPACKAGES.RELEASE) # put generated files into release tree cleanrelease: - rm -rf repos + -rm -rf release cleanall: clean cleandoc cleanrpm cleanrelease diff --git a/config b/config index f9384d4..c5adc01 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit f9384d4738c6d4b243d45673444b7d60433da0f6 +Subproject commit c5adc018e2de8b21b6a132c558d4014b86c7b0d5 diff --git a/python/reg_interface_gem/Makefile b/python/reg_interface_gem/Makefile index 5998852..b38d5e4 100644 --- a/python/reg_interface_gem/Makefile +++ b/python/reg_interface_gem/Makefile @@ -25,27 +25,30 @@ include $(ConfigDir)/mfPythonDefs.mk PythonModules = ["$(Namespace).$(ShortPackage)"] $(info PythonModules=${PythonModules}) -include $(ConfigDir)/mfPythonRPM.mk -include $(ConfigDir)/mfSphinx.mk - REG_INTERFACE_GEM_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') REG_INTERFACE_GEM_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') REG_INTERFACE_GEM_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') +include $(ConfigDir)/mfPythonRPM.mk +include $(ConfigDir)/mfSphinx.mk + +PythonSources=$(wildcard core/*.py) +PythonSources+=$(wildcard scripts/*.py) + default: - @echo "Running default target" $(MakeDir) $(PackageDir) @echo "__path__ = __import__('pkgutil').extend_path(__path__, __name__)" > pkg/$(Namespace)/__init__.py @cp -rf __init__.py $(PackageDir) -# need to ensure that the python only stuff is packaged into RPMs -rpmprep: default - @echo "Running preprpm target" +# Override, as this package uses pkg/setup.py as the template file +$(PackageSetupFile): pkg/setup.py +$(PackagePrepFile): $(PythonSources) Makefile | default $(MakeDir) $(ScriptDir) @cp -rf scripts/* $(ScriptDir) @cp -rf core $(PackageDir) -cp -rf README.md LICENSE CHANGELOG.md MANIFEST.in requirements.txt $(PackageDir) -cp -rf README.md LICENSE CHANGELOG.md MANIFEST.in requirements.txt pkg + touch $@ clean: @echo "Running clean target" diff --git a/xhalarm/Makefile b/xhalarm/Makefile index d714b84..bc28714 100644 --- a/xhalarm/Makefile +++ b/xhalarm/Makefile @@ -14,7 +14,6 @@ ConfigDir := $(ProjectPath)/config include $(ConfigDir)/mfCommonDefs.mk include $(ConfigDir)/mfZynq.mk -include $(ConfigDir)/mfRPMRules.mk PackageSourceDir:=$(ProjectPath)/xhalcore/src/common PackageIncludeDir:=$(ProjectPath)/xhalcore/include @@ -44,6 +43,8 @@ XHAL_LIB = $(PackageLibraryDir)/libxhal.so TargetLibraries:= xhal +include $(ConfigDir)/mfRPMRules.mk + # destination path macro we'll use below df = $(PackageObjectDir)/$(*F) @@ -55,16 +56,19 @@ all: build default: build ## @xhalarm Prepare the package for building the RPM -rpmprep: build - @echo "Running preprpm target" +## @xhalcore Prepare the package for building the RPM +rpmprep: build doc + +$(PackageSourceTarball): $(XHAL_LIB) Makefile + $(MakeDir) $(RPM_DIR) $(MakeDir) $(PackageDir)/$(Package) @cp -rfp lib include src Makefile $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/config $(PackageDir) cd $(ProjectPath); cp -rfp xhalcore/{include,src} $(PackagePath)/$(PackageDir) # cd $(ProjectPath); cp -rfp --parents xhalcore/{include,src/common} $(PackagePath)/$(PackageDir) - $(MakeDir) $(RPMBUILD_DIR)/SOURCES cd $(PackageDir)/..; \ - tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION)-$(PACKAGE_NOARCH_RELEASE).tbz2 $(PackageName); + tar cjf $(PackageSourceTarball) $(PackageName); + $(RM) $(PackageDir)/$(Package) ## @xhalarm Compile the xhal library xhal: $(XHAL_LIB) @@ -74,7 +78,7 @@ doc: ## adapted from http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ ## Generic object creation rule, generate dependencies and use them later -$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp +$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp Makefile $(MakeDir) $(@D) $(CC) $(CFLAGS) $(ADDFLAGS) $(INC) -c -MT $@ -MMD -MP -MF $(@D)/$(*F).Td -o $@ $< mv $(@D)/$(*F).Td $(@D)/$(*F).d diff --git a/xhalcore/Makefile b/xhalcore/Makefile index 59f5252..ca7c930 100644 --- a/xhalcore/Makefile +++ b/xhalcore/Makefile @@ -14,10 +14,10 @@ ConfigDir := $(ProjectPath)/config include $(ConfigDir)/mfCommonDefs.mk include $(ConfigDir)/mfPythonDefs.mk -include $(ConfigDir)/mfRPMRules.mk PackageSourceDir:=$(PackagePath)/src/common PackageObjectDir:=$(PackagePath)/src/linux/$(Arch) +PackageDocsDir:=$(PackagePath)/doc/_build/html XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') @@ -62,6 +62,8 @@ RPCMAN_LIB = $(PackageLibraryDir)/librpcman.so TargetLibraries:= xhal xhalpy rpcman +include $(ConfigDir)/mfRPMRules.mk + # destination path macro we'll use below df = $(PackageObjectDir)/$(*F) @@ -73,12 +75,14 @@ build: $(TargetLibraries) all: build default: build - @echo "Running default target" $(MakeDir) $(PackageDir) ## @xhalcore Prepare the package for building the RPM rpmprep: build doc - @echo "Running preprpm target" + +# Define as dependency everything that should cause a rebuild +$(PackageSourceTarball): $(XHAL_LIB) $(XHALPY_LIB) $(RPCMAN_LIB) Makefile $(ProjectPath)/xhalarm/lib/libxhal* + $(MakeDir) $(RPM_DIR) $(MakeDir) lib/arm $(MakeDir) $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/xhalarm/lib/* lib/arm @@ -86,9 +90,8 @@ rpmprep: build doc @cp -rfp src $(PackageDir)/$(Package) # @cp -rfp --parents src/common $(PackageDir)/$(Package) @cp -rfp $(ProjectPath)/config $(PackageDir) - $(MakeDir) $(RPMBUILD_DIR)/SOURCES cd $(PackageDir)/..; \ - tar cjf $(RPMBUILD_DIR)/SOURCES/$(Project)-$(LongPackage)-$(PACKAGE_FULL_VERSION)-$(PACKAGE_NOARCH_RELEASE).tbz2 $(PackageName); + tar cjf $(PackageSourceTarball) $(PackageName); $(RM) $(PackageDir)/$(Package) ## @xhalcore Compile the xhal RPC manager library @@ -105,7 +108,7 @@ doc: ## adapted from http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ ## Generic object creation rule, generate dependencies and use them later -$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp +$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp Makefile $(MakeDir) $(@D) $(CXX) $(CCFLAGS) $(ADDFLAGS) $(INC) -c -MT $@ -MMD -MP -MF $(@D)/$(*F).Td -o $@ $< mv $(@D)/$(*F).Td $(@D)/$(*F).d @@ -126,14 +129,14 @@ $(XHAL_LIB): $(OBJS_XHAL) $(OBJS_UTILS) $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) $(link-sonames) -$(XHALPY_LIB): $(OBJS_XHALPY) +$(RPCMAN_LIB): $(OBJS_RPCMAN) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal -lrpcman + $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) $(link-sonames) -$(RPCMAN_LIB): $(OBJS_RPCMAN) +$(XHALPY_LIB): $(OBJS_XHALPY) $(XHAL_LIB) $(RPCMAN_LIB) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal -lrpcman $(link-sonames) clean: From a876ae182ec5567669b2966e8a47ba29ece2f363 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 19 Aug 2019 17:41:22 +0200 Subject: [PATCH 18/56] Fixup in gitlab-ci --- .gitlab-ci.yml | 112 ++++++++++++++++++++++++++++-------------------- Makefile | 9 +++- config | 2 +- python/Makefile | 9 +++- 4 files changed, 81 insertions(+), 51 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 70769c5..6b8ba69 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,8 +15,10 @@ ## ------------------- used secure variables: ------------------- ## # EOS_ACCOUNT_USERNAME: Username of to write in the EOS folder whose path is EOS_PATH # EOS_ACCOUNT_PASSWORD: Account password - # KRB_PASSWORD - # KRB_USERNAME + # KRB_PASSWORD base64 hased value + # KRB_USERNAME base64 hased value + # GPG_SIGNING_KEY_PRIV base64 hased value + # GPG_PASSPHRASE base64 hased value # CI_DEPLOY_USER # CI_DEPLOY_PASSWORD @@ -31,7 +33,7 @@ stages: ## ------------------- Define up anchors for various tasks, shared across all jobs utilizing them ------------------- ## .common_variables: &common_variables - EOS_SITE_URL: http://cmsgemdaq.cern.ch + EOS_SITE_URL: https://cmsgemdaq.cern.ch/cmsgemdaq BUILD_HOME: /builds/${CI_PROJECT_NAMESPACE} XDAQ_OS: linux XDAQ_ROOT: /opt/xdaq @@ -59,15 +61,12 @@ variables: *common_variables # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc8:python3 ### ------------------- Shared setup between stages ------------------- ### -.common_setup: &common_setup - - mkdir -p ${ARTIFACTS_DIR} - ## need to pull in all dependencies, based on some requirements, preferably the spec file? - ## cache this stuff between builds? - ## should be in the Docker image - - | - pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" - sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* - sudo yum install -y reedmuller\* --enablerepo=gemos* +.common_setup: &common_setup |- + mkdir -p ${ARTIFACTS_DIR} + pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" + sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* + sudo yum install -y reedmuller\* --enablerepo=gemos* + source /data/bigdisk/sw/Xilinx/SDK/2016.2/settings64.sh .retry_settings: &retry_settings retry: @@ -75,7 +74,7 @@ variables: *common_variables when: - runner_system_failure - stuck_or_timeout_failure - + .common_cache: &common_cache # key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" # key: "$BUILD_ARCH" @@ -88,7 +87,7 @@ variables: *common_variables # - /opt/rwreg # - /opt/wiscrpcsvc # - /opt/xhal - + .common_artifacts: &common_artifacts name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" expire_in: 1d @@ -102,16 +101,19 @@ variables: *common_variables # paths: # - ${ARTIFACTS_DIR} +.touch_compile_artifacts: &touch_compile_artifacts |- + find ./ -type f -name '*.d' -print0 -exec touch {} \; + find ./ -type f -name '*.o' -print0 -exec touch {} \; + find ./ -type f -name 'lib*' -print0 -exec touch {} \; + find ./ -type f -name 'xhalpy*' -print0 -exec touch {} \; + # find ./python/reg_interface_gem/pkg/xhal -type f -print0 -exec touch {} \; + .before_compile: &before_compile - - mkdir -p ${ARTIFACTS_DIR} ## these are set in the Dockerfile, but don't work in the gitlab CI by default? - export BUILD_HOME=/builds/$CI_PROJECT_NAMESPACE - export ARTIFACTS_DIR=$BUILD_HOME/artifacts - ## need to pull in all cmsgemos dependencies, based on some requirements, preferably the spec file? - ## cache this stuff between builds? - ## set up Xilinx peta/Zynq compiler - - source /data/bigdisk/sw/Xilinx/SDK/2016.2/settings64.sh - + - *common_setup + .compile_common: &compile_common only: - /^issue.*$/ @@ -149,7 +151,7 @@ compile:cc7: # environment: # variables: # cache: - + ##### ------------------- Generate docs ------------------- ##### .docs_artifacts: &docs_artifacts untracked: true @@ -158,6 +160,11 @@ compile:cc7: # - ${ARTIFACTS_DIR} # - doc/build/html +.touch_docs_artifacts: &touch_docs_artifacts |- + find ./python/reg_interface_gem/doc/_build -type f -print0 -exec touch {} \; + # find ./doc/html -type f -print0 -exec touch {} \; + # find ./doc/latex -type f -print0 -exec touch {} \; + # generate docs docs: <<: *cc7setup @@ -192,7 +199,7 @@ docs: - | sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* sudo yum install -y reedmuller\* --enablerepo=gemos* - + # run tests using the binary built before test:cc7: <<: *cc7setup @@ -228,38 +235,44 @@ test:cc7: <<: *common_artifacts # paths: # - ${ARTIFACTS_DIR} - -.before_package: &before_package - - mkdir -p ${ARTIFACTS_DIR} - - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` - - eval `set | egrep '^(BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` - - | - pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" - sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* - sudo yum install -y reedmuller\* --enablerepo=gemos* + +.touch_package_artifacts: &touch_package_artifacts |- + find ./python/reg_interface_gem/pkg/xhal -type f -print0 -exec touch {} \; + find ./python/reg_interface_gem/rpm -type f -iname 'setup.py' -print0 -exec touch {} \; + find ./python/reg_interface_gem/rpm -type f -iname 'reg_interface_gem.src.rpm' -print0 -exec touch {} \; + find ./python/reg_interface_gem/rpm -type f -iname 'reg_interface_gem.x86_64.rpm' -print0 -exec touch {} \; + find ./python/reg_interface_gem/rpm -type f -iname 'reg_interface_gem.zip' -print0 -exec touch {} \; + find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.tbz2' -print0 -exec touch {} \; + find ./xhal*/rpm -type f -wholename '*/rpm/xhal.spec' -print0 -exec touch {} \; + find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.src.rpm' -print0 -exec touch {} \; + find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.arm*.rpm' -print0 -exec touch {} \; + find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.x86_64.rpm' -print0 -exec touch {} \; + +.before_package: &before_package |- + eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` + eval `set | egrep '^(BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` .package_common: &package_common stage: package before_script: - *before_package + - *common_setup + - *before_package script: ## Ensure compile artifacts are more recent than the checkout - - | - find ./ -type f -name '*.d' -print0 -exec touch {} \; - find ./ -type f -name '*.o' -print0 -exec touch {} \; - find ./ -type f -name '*.so' -print0 -exec touch {} \; - - make release + - *touch_compile_artifacts + - *touch_docs_artifacts + - make rpm ## Move packaged files to deployment staging area - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` - eval `set | egrep '^(EOS|BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` - - mv repos ${ARTIFACTS_DIR} after_script: +# - mv repos ${ARTIFACTS_DIR} - ls -la ${ARTIFACTS_DIR} - ls -la ${ARTIFACTS_DIR}/repos artifacts: name: ${CI_JOB_STAGE} <<: *package_artifacts - + # generate RPMs package:cc7:unstable: <<: *cc7setup @@ -317,16 +330,16 @@ package:cc7:base: ##### ------------------- Publish RPMs, docs, and tarballs ------------------- ##### .publish_variables: &publish_variables - EOS_BASE_WEB_DIR: "/eos/project/c/cmsgemdaq/www" + EOS_BASE_WEB_DIR: "/eos/project/c/cmsgemdaq/www/ci-test" EOS_COMMON_WEB_DIR: "cmsgemdaq" EOS_DOC_NAME: "api" EOS_REPO_NAME: "repos" EOS_SITE_WEB_DIR: "${EOS_BASE_WEB_DIR}/${CI_PROJECT_NAME}" - EOS_SW_DIR: "${EOS_BASE_WEB_DIR}/sw/${CI_PROJECT_NAME}" - EOS_DOCS_DIR: "${EOS_BASE_WEB_DIR}/docs/${CI_PROJECT_NAME}" - EOS_UNSTABLE_DIR: "${EOS_BASE_WEB_DIR}/sw/${CI_PROJECT_NAME}/unstable" - EOS_RELEASE_DIR: "${EOS_BASE_WEB_DIR}/sw/${CI_PROJECT_NAME}/releases" - + EOS_SW_DIR: "sw/${CI_PROJECT_NAME}" + EOS_DOCS_DIR: "docs/${CI_PROJECT_NAME}" + EOS_UNSTABLE_DIR: "unstable" + EOS_RELEASE_DIR: "releases" + .publish_common: &publish_common <<: *cc7setup stage: publish @@ -334,6 +347,8 @@ package:cc7:base: before_script: - eval `set | egrep '^(KRB|CI|GIT)' | awk -F= '{ print "export " $1 }'` - eval `set | egrep '^(EOS|BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` + - *common_setup + - sudo yum install -y rpm-sign script: # - push python packages to pypi/conda # - push RPMs to packagecloud.io @@ -342,9 +357,14 @@ package:cc7:base: # - push sphinx/rst/md/rtd docs to $EOS_WEB_DIR/docs/${fulltag}, update doc main page index - 'echo "FIXME: github_changelog_generator"' - 'echo "FIXME: cp CHANGELOG.md ${ARTIFACTS_DIR}"' + - *touch_compile_artifacts + - *touch_docs_artifacts + - *touch_package_artifacts + - make release + - cp -rfp release/* ${ARTIFACTS_DIR} - ${BUILD_HOME}/${CI_PROJECT_NAME}/config/ci/publish_eos.sh - if [ -n "${DEBUG_CI}" ]; then sleep 500; fi - + # publish:debug: # variables: # EOS_BASE_WEB_DIR: /tmp/ diff --git a/Makefile b/Makefile index 127528a..a0bd062 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ SUBPACKAGES.RPM := $(patsubst %,%.rpm, $(SUBPACKAGES)) SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) +SUBPACKAGES.CLEANALL := $(patsubst %,%.cleanall, $(SUBPACKAGES)) .PHONY: $(SUBPACKAGES) \ $(SUBPACKAGES.CLEAN) \ @@ -21,7 +22,8 @@ SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) $(SUBPACKAGES.RPM) \ $(SUBPACKAGES.CLEANRPM) \ $(SUBPACKAGES.DOC) \ - $(SUBPACKAGES.CLEANDOC) + $(SUBPACKAGES.CLEANDOC) \ + $(SUBPACKAGES.CLEANALL) .PHONY: all build doc install uninstall rpm release .PHONY: clean cleanall cleandoc cleanrpm cleanrelease @@ -56,7 +58,7 @@ release: $(SUBPACKAGES.RELEASE) cleanrelease: -rm -rf release -cleanall: clean cleandoc cleanrpm cleanrelease +cleanall: $(SUBPACKAGES.CLEANALL) cleanrelease $(SUBPACKAGES): $(MAKE) -C $@ @@ -73,6 +75,9 @@ $(SUBPACKAGES.CLEANDOC): $(SUBPACKAGES.CLEANRPM): $(MAKE) -C $(patsubst %.cleanrpm,%, $@) cleanrpm +$(SUBPACKAGES.CLEANALL): + $(MAKE) -C $(patsubst %.cleanall,%, $@) cleanall + $(SUBPACKAGES.DOC): $(MAKE) -C $(patsubst %.doc,%, $@) doc diff --git a/config b/config index c5adc01..38f4b5a 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit c5adc018e2de8b21b6a132c558d4014b86c7b0d5 +Subproject commit 38f4b5ac3f91bd04790e4f592a5e91ecac884b57 diff --git a/python/Makefile b/python/Makefile index 9e94e22..c940948 100644 --- a/python/Makefile +++ b/python/Makefile @@ -10,6 +10,7 @@ SUBPACKAGES.RPM := $(patsubst %,%.rpm, $(SUBPACKAGES)) SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) +SUBPACKAGES.CLEANALL := $(patsubst %,%.cleanall, $(SUBPACKAGES)) .PHONY: $(SUBPACKAGES) \ $(SUBPACKAGES.CLEAN) \ @@ -19,7 +20,8 @@ SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) $(SUBPACKAGES.RPM) \ $(SUBPACKAGES.CLEANRPM) \ $(SUBPACKAGES.DOC) \ - $(SUBPACKAGES.CLEANDOC) + $(SUBPACKAGES.CLEANDOC) \ + $(SUBPACKAGES.CLEANALL) .PHONY: all build doc install uninstall rpm release .PHONY: clean cleanall cleandoc cleanrpm @@ -43,7 +45,7 @@ uninstall: $(SUBPACKAGES.UNINSTALL) release: $(SUBPACKAGES.RELEASE) -cleanall: clean cleandoc cleanrpm +cleanall: $(SUBPACKAGES.CLEANALL) $(SUBPACKAGES): $(MAKE) -C $@ @@ -60,6 +62,9 @@ $(SUBPACKAGES.CLEANDOC): $(SUBPACKAGES.CLEANRPM): $(MAKE) -C $(patsubst %.cleanrpm,%, $@) cleanrpm +$(SUBPACKAGES.CLEANALL): + $(MAKE) -C $(patsubst %.cleanall,%, $@) cleanall + $(SUBPACKAGES.DOC): $(MAKE) -C $(patsubst %.doc,%, $@) html From 114a65b4c92a8b052f1038a855dd5b55ab767c6a Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 9 Sep 2019 09:32:16 +0200 Subject: [PATCH 19/56] Update CI process * add lmdb to CI install step * add gem-peta-stage-ctp7 to install steps --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6b8ba69..43d8178 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -66,7 +66,10 @@ variables: *common_variables pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* sudo yum install -y reedmuller\* --enablerepo=gemos* + sudo yum install -y gem-peta-stage-ctp7 --enablerepo=gemos* + sudo yum install -y lmdb\* source /data/bigdisk/sw/Xilinx/SDK/2016.2/settings64.sh + env | egrep CI .retry_settings: &retry_settings retry: From 162081b1988a5799f544633bc8a1d912ad51b7ad Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:30:53 +0200 Subject: [PATCH 20/56] [refactor] Move `xhalcore` to `xhal` --- {xhalcore => xhal}/Makefile | 0 {xhalcore => xhal}/include/lmdb++.h | 0 {xhalcore => xhal}/include/packageinfo.h | 0 {xhalcore => xhal}/include/xhal/LMDB.h | 0 {xhalcore => xhal}/include/xhal/XHALDevice.h | 0 {xhalcore => xhal}/include/xhal/XHALInterface.h | 0 {xhalcore => xhal}/include/xhal/rpc/calibration_routines.h | 0 {xhalcore => xhal}/include/xhal/rpc/call.h | 0 {xhalcore => xhal}/include/xhal/rpc/common.h | 0 {xhalcore => xhal}/include/xhal/rpc/compat.h | 0 {xhalcore => xhal}/include/xhal/rpc/daq_monitor.h | 0 {xhalcore => xhal}/include/xhal/rpc/exceptions.h | 0 {xhalcore => xhal}/include/xhal/rpc/helper.h | 0 {xhalcore => xhal}/include/xhal/rpc/optohybrid.h | 0 {xhalcore => xhal}/include/xhal/rpc/register.h | 0 {xhalcore => xhal}/include/xhal/rpc/utils.h | 0 {xhalcore => xhal}/include/xhal/rpc/vfat3.h | 0 {xhalcore => xhal}/include/xhal/rpc/wiscRPCMsg.h | 0 {xhalcore => xhal}/include/xhal/rpc/wiscrpcsvc.h | 0 {xhalcore => xhal}/include/xhal/utils/Exception.h | 0 {xhalcore => xhal}/include/xhal/utils/PyTypes.h | 0 {xhalcore => xhal}/include/xhal/utils/XHALXMLNode.h | 0 {xhalcore => xhal}/include/xhal/utils/XHALXMLParser.h | 0 {xhalcore => xhal}/src/common/LMDB.cpp | 0 {xhalcore => xhal}/src/common/XHALDevice.cpp | 0 {xhalcore => xhal}/src/common/XHALInterface.cpp | 0 .../src/common/python_wrappers/XHALInterface_python.cpp | 0 {xhalcore => xhal}/src/common/rpc/exceptions.cpp | 0 .../src/common/rpc_manager/calibration_routines.cpp | 0 {xhalcore => xhal}/src/common/rpc_manager/daq_monitor.cpp | 0 {xhalcore => xhal}/src/common/rpc_manager/optohybrid.cpp | 0 {xhalcore => xhal}/src/common/rpc_manager/utils.cpp | 0 {xhalcore => xhal}/src/common/rpc_manager/vfat3.cpp | 0 {xhalcore => xhal}/src/common/utils/XHALXMLParser.cpp | 0 {xhalcore => xhal}/test/test.py | 0 35 files changed, 0 insertions(+), 0 deletions(-) rename {xhalcore => xhal}/Makefile (100%) rename {xhalcore => xhal}/include/lmdb++.h (100%) rename {xhalcore => xhal}/include/packageinfo.h (100%) rename {xhalcore => xhal}/include/xhal/LMDB.h (100%) rename {xhalcore => xhal}/include/xhal/XHALDevice.h (100%) rename {xhalcore => xhal}/include/xhal/XHALInterface.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/calibration_routines.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/call.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/common.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/compat.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/daq_monitor.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/exceptions.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/helper.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/optohybrid.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/register.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/utils.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/vfat3.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/wiscRPCMsg.h (100%) rename {xhalcore => xhal}/include/xhal/rpc/wiscrpcsvc.h (100%) rename {xhalcore => xhal}/include/xhal/utils/Exception.h (100%) rename {xhalcore => xhal}/include/xhal/utils/PyTypes.h (100%) rename {xhalcore => xhal}/include/xhal/utils/XHALXMLNode.h (100%) rename {xhalcore => xhal}/include/xhal/utils/XHALXMLParser.h (100%) rename {xhalcore => xhal}/src/common/LMDB.cpp (100%) rename {xhalcore => xhal}/src/common/XHALDevice.cpp (100%) rename {xhalcore => xhal}/src/common/XHALInterface.cpp (100%) rename {xhalcore => xhal}/src/common/python_wrappers/XHALInterface_python.cpp (100%) rename {xhalcore => xhal}/src/common/rpc/exceptions.cpp (100%) rename {xhalcore => xhal}/src/common/rpc_manager/calibration_routines.cpp (100%) rename {xhalcore => xhal}/src/common/rpc_manager/daq_monitor.cpp (100%) rename {xhalcore => xhal}/src/common/rpc_manager/optohybrid.cpp (100%) rename {xhalcore => xhal}/src/common/rpc_manager/utils.cpp (100%) rename {xhalcore => xhal}/src/common/rpc_manager/vfat3.cpp (100%) rename {xhalcore => xhal}/src/common/utils/XHALXMLParser.cpp (100%) rename {xhalcore => xhal}/test/test.py (100%) diff --git a/xhalcore/Makefile b/xhal/Makefile similarity index 100% rename from xhalcore/Makefile rename to xhal/Makefile diff --git a/xhalcore/include/lmdb++.h b/xhal/include/lmdb++.h similarity index 100% rename from xhalcore/include/lmdb++.h rename to xhal/include/lmdb++.h diff --git a/xhalcore/include/packageinfo.h b/xhal/include/packageinfo.h similarity index 100% rename from xhalcore/include/packageinfo.h rename to xhal/include/packageinfo.h diff --git a/xhalcore/include/xhal/LMDB.h b/xhal/include/xhal/LMDB.h similarity index 100% rename from xhalcore/include/xhal/LMDB.h rename to xhal/include/xhal/LMDB.h diff --git a/xhalcore/include/xhal/XHALDevice.h b/xhal/include/xhal/XHALDevice.h similarity index 100% rename from xhalcore/include/xhal/XHALDevice.h rename to xhal/include/xhal/XHALDevice.h diff --git a/xhalcore/include/xhal/XHALInterface.h b/xhal/include/xhal/XHALInterface.h similarity index 100% rename from xhalcore/include/xhal/XHALInterface.h rename to xhal/include/xhal/XHALInterface.h diff --git a/xhalcore/include/xhal/rpc/calibration_routines.h b/xhal/include/xhal/rpc/calibration_routines.h similarity index 100% rename from xhalcore/include/xhal/rpc/calibration_routines.h rename to xhal/include/xhal/rpc/calibration_routines.h diff --git a/xhalcore/include/xhal/rpc/call.h b/xhal/include/xhal/rpc/call.h similarity index 100% rename from xhalcore/include/xhal/rpc/call.h rename to xhal/include/xhal/rpc/call.h diff --git a/xhalcore/include/xhal/rpc/common.h b/xhal/include/xhal/rpc/common.h similarity index 100% rename from xhalcore/include/xhal/rpc/common.h rename to xhal/include/xhal/rpc/common.h diff --git a/xhalcore/include/xhal/rpc/compat.h b/xhal/include/xhal/rpc/compat.h similarity index 100% rename from xhalcore/include/xhal/rpc/compat.h rename to xhal/include/xhal/rpc/compat.h diff --git a/xhalcore/include/xhal/rpc/daq_monitor.h b/xhal/include/xhal/rpc/daq_monitor.h similarity index 100% rename from xhalcore/include/xhal/rpc/daq_monitor.h rename to xhal/include/xhal/rpc/daq_monitor.h diff --git a/xhalcore/include/xhal/rpc/exceptions.h b/xhal/include/xhal/rpc/exceptions.h similarity index 100% rename from xhalcore/include/xhal/rpc/exceptions.h rename to xhal/include/xhal/rpc/exceptions.h diff --git a/xhalcore/include/xhal/rpc/helper.h b/xhal/include/xhal/rpc/helper.h similarity index 100% rename from xhalcore/include/xhal/rpc/helper.h rename to xhal/include/xhal/rpc/helper.h diff --git a/xhalcore/include/xhal/rpc/optohybrid.h b/xhal/include/xhal/rpc/optohybrid.h similarity index 100% rename from xhalcore/include/xhal/rpc/optohybrid.h rename to xhal/include/xhal/rpc/optohybrid.h diff --git a/xhalcore/include/xhal/rpc/register.h b/xhal/include/xhal/rpc/register.h similarity index 100% rename from xhalcore/include/xhal/rpc/register.h rename to xhal/include/xhal/rpc/register.h diff --git a/xhalcore/include/xhal/rpc/utils.h b/xhal/include/xhal/rpc/utils.h similarity index 100% rename from xhalcore/include/xhal/rpc/utils.h rename to xhal/include/xhal/rpc/utils.h diff --git a/xhalcore/include/xhal/rpc/vfat3.h b/xhal/include/xhal/rpc/vfat3.h similarity index 100% rename from xhalcore/include/xhal/rpc/vfat3.h rename to xhal/include/xhal/rpc/vfat3.h diff --git a/xhalcore/include/xhal/rpc/wiscRPCMsg.h b/xhal/include/xhal/rpc/wiscRPCMsg.h similarity index 100% rename from xhalcore/include/xhal/rpc/wiscRPCMsg.h rename to xhal/include/xhal/rpc/wiscRPCMsg.h diff --git a/xhalcore/include/xhal/rpc/wiscrpcsvc.h b/xhal/include/xhal/rpc/wiscrpcsvc.h similarity index 100% rename from xhalcore/include/xhal/rpc/wiscrpcsvc.h rename to xhal/include/xhal/rpc/wiscrpcsvc.h diff --git a/xhalcore/include/xhal/utils/Exception.h b/xhal/include/xhal/utils/Exception.h similarity index 100% rename from xhalcore/include/xhal/utils/Exception.h rename to xhal/include/xhal/utils/Exception.h diff --git a/xhalcore/include/xhal/utils/PyTypes.h b/xhal/include/xhal/utils/PyTypes.h similarity index 100% rename from xhalcore/include/xhal/utils/PyTypes.h rename to xhal/include/xhal/utils/PyTypes.h diff --git a/xhalcore/include/xhal/utils/XHALXMLNode.h b/xhal/include/xhal/utils/XHALXMLNode.h similarity index 100% rename from xhalcore/include/xhal/utils/XHALXMLNode.h rename to xhal/include/xhal/utils/XHALXMLNode.h diff --git a/xhalcore/include/xhal/utils/XHALXMLParser.h b/xhal/include/xhal/utils/XHALXMLParser.h similarity index 100% rename from xhalcore/include/xhal/utils/XHALXMLParser.h rename to xhal/include/xhal/utils/XHALXMLParser.h diff --git a/xhalcore/src/common/LMDB.cpp b/xhal/src/common/LMDB.cpp similarity index 100% rename from xhalcore/src/common/LMDB.cpp rename to xhal/src/common/LMDB.cpp diff --git a/xhalcore/src/common/XHALDevice.cpp b/xhal/src/common/XHALDevice.cpp similarity index 100% rename from xhalcore/src/common/XHALDevice.cpp rename to xhal/src/common/XHALDevice.cpp diff --git a/xhalcore/src/common/XHALInterface.cpp b/xhal/src/common/XHALInterface.cpp similarity index 100% rename from xhalcore/src/common/XHALInterface.cpp rename to xhal/src/common/XHALInterface.cpp diff --git a/xhalcore/src/common/python_wrappers/XHALInterface_python.cpp b/xhal/src/common/python_wrappers/XHALInterface_python.cpp similarity index 100% rename from xhalcore/src/common/python_wrappers/XHALInterface_python.cpp rename to xhal/src/common/python_wrappers/XHALInterface_python.cpp diff --git a/xhalcore/src/common/rpc/exceptions.cpp b/xhal/src/common/rpc/exceptions.cpp similarity index 100% rename from xhalcore/src/common/rpc/exceptions.cpp rename to xhal/src/common/rpc/exceptions.cpp diff --git a/xhalcore/src/common/rpc_manager/calibration_routines.cpp b/xhal/src/common/rpc_manager/calibration_routines.cpp similarity index 100% rename from xhalcore/src/common/rpc_manager/calibration_routines.cpp rename to xhal/src/common/rpc_manager/calibration_routines.cpp diff --git a/xhalcore/src/common/rpc_manager/daq_monitor.cpp b/xhal/src/common/rpc_manager/daq_monitor.cpp similarity index 100% rename from xhalcore/src/common/rpc_manager/daq_monitor.cpp rename to xhal/src/common/rpc_manager/daq_monitor.cpp diff --git a/xhalcore/src/common/rpc_manager/optohybrid.cpp b/xhal/src/common/rpc_manager/optohybrid.cpp similarity index 100% rename from xhalcore/src/common/rpc_manager/optohybrid.cpp rename to xhal/src/common/rpc_manager/optohybrid.cpp diff --git a/xhalcore/src/common/rpc_manager/utils.cpp b/xhal/src/common/rpc_manager/utils.cpp similarity index 100% rename from xhalcore/src/common/rpc_manager/utils.cpp rename to xhal/src/common/rpc_manager/utils.cpp diff --git a/xhalcore/src/common/rpc_manager/vfat3.cpp b/xhal/src/common/rpc_manager/vfat3.cpp similarity index 100% rename from xhalcore/src/common/rpc_manager/vfat3.cpp rename to xhal/src/common/rpc_manager/vfat3.cpp diff --git a/xhalcore/src/common/utils/XHALXMLParser.cpp b/xhal/src/common/utils/XHALXMLParser.cpp similarity index 100% rename from xhalcore/src/common/utils/XHALXMLParser.cpp rename to xhal/src/common/utils/XHALXMLParser.cpp diff --git a/xhalcore/test/test.py b/xhal/test/test.py similarity index 100% rename from xhalcore/test/test.py rename to xhal/test/test.py From dc0624b9d8d00c3e7c6a21ba00183a0658f3c24d Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:32:40 +0200 Subject: [PATCH 21/56] [refactor] Move `xhalarm` `postinstall.sh` script to `xhal`, and remove `xhalarm` --- {xhalarm => xhal}/scripts/postinstall.sh | 0 xhalarm/Makefile | 118 ----------------------- xhalarm/include/packageinfo.h | 11 --- 3 files changed, 129 deletions(-) rename {xhalarm => xhal}/scripts/postinstall.sh (100%) delete mode 100644 xhalarm/Makefile delete mode 100644 xhalarm/include/packageinfo.h diff --git a/xhalarm/scripts/postinstall.sh b/xhal/scripts/postinstall.sh similarity index 100% rename from xhalarm/scripts/postinstall.sh rename to xhal/scripts/postinstall.sh diff --git a/xhalarm/Makefile b/xhalarm/Makefile deleted file mode 100644 index bc28714..0000000 --- a/xhalarm/Makefile +++ /dev/null @@ -1,118 +0,0 @@ -BUILD_HOME := $(shell dirname `cd ../; pwd`) -Project := xhal -Package := xhal -ShortPackage := xhal -LongPackage := xhalarm -PackageName := $(ShortPackage) -PackagePath := $(shell pwd) -PackageDir := pkg/$(ShortPackage) -Packager := Mykhailo Dalchenko -Arch := arm - -ProjectPath:= $(BUILD_HOME)/$(Project) -ConfigDir := $(ProjectPath)/config - -include $(ConfigDir)/mfCommonDefs.mk -include $(ConfigDir)/mfZynq.mk - -PackageSourceDir:=$(ProjectPath)/xhalcore/src/common -PackageIncludeDir:=$(ProjectPath)/xhalcore/include -PackageObjectDir:=$(PackagePath)/src/linux/$(Arch) - -XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') - -ADDFLAGS=-g -std=gnu++14 - -IncludeDirs+=$(PackageIncludeDir) -INC=$(IncludeDirs:%=-I%) - -Libraries+=-llog4cplus -lxerces-c -lstdc++ - -LDFLAGS+=-shared $(LibraryDirs) - -SRCS_XHAL = $(shell echo $(PackageSourceDir)/utils/*.cpp) -SRCS_XHAL+= $(shell echo $(PackageSourceDir)/rpc/*.cpp) - -AUTODEPS_XHAL = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHAL)) - -OBJS_XHAL = $(patsubst %.d,%.o,$(AUTODEPS_XHAL)) - -XHAL_LIB = $(PackageLibraryDir)/libxhal.so - -TargetLibraries:= xhal - -include $(ConfigDir)/mfRPMRules.mk - -# destination path macro we'll use below -df = $(PackageObjectDir)/$(*F) - -## @xhalarm Compile all target libraries -build: $(TargetLibraries) - -all: build - -default: build - -## @xhalarm Prepare the package for building the RPM -## @xhalcore Prepare the package for building the RPM -rpmprep: build doc - -$(PackageSourceTarball): $(XHAL_LIB) Makefile - $(MakeDir) $(RPM_DIR) - $(MakeDir) $(PackageDir)/$(Package) - @cp -rfp lib include src Makefile $(PackageDir)/$(Package) - @cp -rfp $(ProjectPath)/config $(PackageDir) - cd $(ProjectPath); cp -rfp xhalcore/{include,src} $(PackagePath)/$(PackageDir) -# cd $(ProjectPath); cp -rfp --parents xhalcore/{include,src/common} $(PackagePath)/$(PackageDir) - cd $(PackageDir)/..; \ - tar cjf $(PackageSourceTarball) $(PackageName); - $(RM) $(PackageDir)/$(Package) - -## @xhalarm Compile the xhal library -xhal: $(XHAL_LIB) - -doc: - @echo "TO DO" - -## adapted from http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ -## Generic object creation rule, generate dependencies and use them later -$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp Makefile - $(MakeDir) $(@D) - $(CC) $(CFLAGS) $(ADDFLAGS) $(INC) -c -MT $@ -MMD -MP -MF $(@D)/$(*F).Td -o $@ $< - mv $(@D)/$(*F).Td $(@D)/$(*F).d - touch $@ - -## dummy rule for dependencies -$(PackageObjectDir)/%.d: - -## mark dependencies and objects as not auto-removed -.PRECIOUS: $(PackageObjectDir)/%.d -.PRECIOUS: $(PackageObjectDir)/%.o - -## Force rule for all target library names -$(TargetLibraries): - -$(XHAL_LIB): $(OBJS_XHAL) - $(MakeDir) -p $(@D) - $(CC) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) - $(link-sonames) - -## FIXME obsolete? only for xcompiled things? -# %.o: %.c -# $(CC) -std=gnu99 -c $(CFLAGS) -o $@ $< -# %.o: %.cc -# $(CXX) -std=c++0x -c $(CFLAGS) -o $@ $< - -clean: - $(RM) $(OBJS_XHAL) - $(RM) $(PackageLibraryDir) - $(RM) $(PackageExecDir) - $(RM) $(PackageDir) - -cleandoc: - @echo "TO DO" - -cleanall: - $(RM) $(PackageObjectDir) diff --git a/xhalarm/include/packageinfo.h b/xhalarm/include/packageinfo.h deleted file mode 100644 index f8d4a73..0000000 --- a/xhalarm/include/packageinfo.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef XHAL_PACKAGEINFO_H -#define XHAL_PACKAGEINFO_H - -#ifndef DOXYGEN_IGNORE_THIS - -#define XHAL_REQUIRED_PACKAGE_LIST reedmuller -#define XHAL_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel - -#endif - -#endif From 271c614524c4339d3724a869241cf2622a5a80d6 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:39:47 +0200 Subject: [PATCH 22/56] [refactor] Move `extern` headers to `xhal/extern` --- xhal/include/{ => xhal/extern}/lmdb++.h | 0 xhal/include/xhal/{rpc => extern}/wiscRPCMsg.h | 0 xhal/include/xhal/{rpc => extern}/wiscrpcsvc.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename xhal/include/{ => xhal/extern}/lmdb++.h (100%) rename xhal/include/xhal/{rpc => extern}/wiscRPCMsg.h (100%) rename xhal/include/xhal/{rpc => extern}/wiscrpcsvc.h (100%) diff --git a/xhal/include/lmdb++.h b/xhal/include/xhal/extern/lmdb++.h similarity index 100% rename from xhal/include/lmdb++.h rename to xhal/include/xhal/extern/lmdb++.h diff --git a/xhal/include/xhal/rpc/wiscRPCMsg.h b/xhal/include/xhal/extern/wiscRPCMsg.h similarity index 100% rename from xhal/include/xhal/rpc/wiscRPCMsg.h rename to xhal/include/xhal/extern/wiscRPCMsg.h diff --git a/xhal/include/xhal/rpc/wiscrpcsvc.h b/xhal/include/xhal/extern/wiscrpcsvc.h similarity index 100% rename from xhal/include/xhal/rpc/wiscrpcsvc.h rename to xhal/include/xhal/extern/wiscrpcsvc.h From 1798accbb918300760a387b673f596327b72de93 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:43:31 +0200 Subject: [PATCH 23/56] [refactor] Migrate headers for `client` package --- xhal/include/xhal/{ => client}/XHALDevice.h | 0 xhal/include/xhal/{ => client}/XHALInterface.h | 0 xhal/include/xhal/{rpc => client/rpcman}/calibration_routines.h | 0 xhal/include/xhal/{rpc => client/rpcman}/daq_monitor.h | 0 xhal/include/xhal/{rpc => client/rpcman}/optohybrid.h | 0 xhal/include/xhal/{rpc => client/rpcman}/utils.h | 0 xhal/include/xhal/{rpc => client/rpcman}/vfat3.h | 0 xhal/include/xhal/{ => client}/utils/PyTypes.h | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename xhal/include/xhal/{ => client}/XHALDevice.h (100%) rename xhal/include/xhal/{ => client}/XHALInterface.h (100%) rename xhal/include/xhal/{rpc => client/rpcman}/calibration_routines.h (100%) rename xhal/include/xhal/{rpc => client/rpcman}/daq_monitor.h (100%) rename xhal/include/xhal/{rpc => client/rpcman}/optohybrid.h (100%) rename xhal/include/xhal/{rpc => client/rpcman}/utils.h (100%) rename xhal/include/xhal/{rpc => client/rpcman}/vfat3.h (100%) rename xhal/include/xhal/{ => client}/utils/PyTypes.h (100%) diff --git a/xhal/include/xhal/XHALDevice.h b/xhal/include/xhal/client/XHALDevice.h similarity index 100% rename from xhal/include/xhal/XHALDevice.h rename to xhal/include/xhal/client/XHALDevice.h diff --git a/xhal/include/xhal/XHALInterface.h b/xhal/include/xhal/client/XHALInterface.h similarity index 100% rename from xhal/include/xhal/XHALInterface.h rename to xhal/include/xhal/client/XHALInterface.h diff --git a/xhal/include/xhal/rpc/calibration_routines.h b/xhal/include/xhal/client/rpcman/calibration_routines.h similarity index 100% rename from xhal/include/xhal/rpc/calibration_routines.h rename to xhal/include/xhal/client/rpcman/calibration_routines.h diff --git a/xhal/include/xhal/rpc/daq_monitor.h b/xhal/include/xhal/client/rpcman/daq_monitor.h similarity index 100% rename from xhal/include/xhal/rpc/daq_monitor.h rename to xhal/include/xhal/client/rpcman/daq_monitor.h diff --git a/xhal/include/xhal/rpc/optohybrid.h b/xhal/include/xhal/client/rpcman/optohybrid.h similarity index 100% rename from xhal/include/xhal/rpc/optohybrid.h rename to xhal/include/xhal/client/rpcman/optohybrid.h diff --git a/xhal/include/xhal/rpc/utils.h b/xhal/include/xhal/client/rpcman/utils.h similarity index 100% rename from xhal/include/xhal/rpc/utils.h rename to xhal/include/xhal/client/rpcman/utils.h diff --git a/xhal/include/xhal/rpc/vfat3.h b/xhal/include/xhal/client/rpcman/vfat3.h similarity index 100% rename from xhal/include/xhal/rpc/vfat3.h rename to xhal/include/xhal/client/rpcman/vfat3.h diff --git a/xhal/include/xhal/utils/PyTypes.h b/xhal/include/xhal/client/utils/PyTypes.h similarity index 100% rename from xhal/include/xhal/utils/PyTypes.h rename to xhal/include/xhal/client/utils/PyTypes.h From 0b83821af719f4a7fd60a4b669d795d6d0c32a6a Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:48:56 +0200 Subject: [PATCH 24/56] [refactor] Migrate sources for `client/rpc_manager` package --- xhal/src/{common => client}/rpc_manager/calibration_routines.cpp | 0 xhal/src/{common => client}/rpc_manager/daq_monitor.cpp | 0 xhal/src/{common => client}/rpc_manager/optohybrid.cpp | 0 xhal/src/{common => client}/rpc_manager/utils.cpp | 0 xhal/src/{common => client}/rpc_manager/vfat3.cpp | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename xhal/src/{common => client}/rpc_manager/calibration_routines.cpp (100%) rename xhal/src/{common => client}/rpc_manager/daq_monitor.cpp (100%) rename xhal/src/{common => client}/rpc_manager/optohybrid.cpp (100%) rename xhal/src/{common => client}/rpc_manager/utils.cpp (100%) rename xhal/src/{common => client}/rpc_manager/vfat3.cpp (100%) diff --git a/xhal/src/common/rpc_manager/calibration_routines.cpp b/xhal/src/client/rpc_manager/calibration_routines.cpp similarity index 100% rename from xhal/src/common/rpc_manager/calibration_routines.cpp rename to xhal/src/client/rpc_manager/calibration_routines.cpp diff --git a/xhal/src/common/rpc_manager/daq_monitor.cpp b/xhal/src/client/rpc_manager/daq_monitor.cpp similarity index 100% rename from xhal/src/common/rpc_manager/daq_monitor.cpp rename to xhal/src/client/rpc_manager/daq_monitor.cpp diff --git a/xhal/src/common/rpc_manager/optohybrid.cpp b/xhal/src/client/rpc_manager/optohybrid.cpp similarity index 100% rename from xhal/src/common/rpc_manager/optohybrid.cpp rename to xhal/src/client/rpc_manager/optohybrid.cpp diff --git a/xhal/src/common/rpc_manager/utils.cpp b/xhal/src/client/rpc_manager/utils.cpp similarity index 100% rename from xhal/src/common/rpc_manager/utils.cpp rename to xhal/src/client/rpc_manager/utils.cpp diff --git a/xhal/src/common/rpc_manager/vfat3.cpp b/xhal/src/client/rpc_manager/vfat3.cpp similarity index 100% rename from xhal/src/common/rpc_manager/vfat3.cpp rename to xhal/src/client/rpc_manager/vfat3.cpp From 9dac42116d4a3d3ea4d39d7a8fb8be1bd426d2b8 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:49:30 +0200 Subject: [PATCH 25/56] [refactor] Migrate sources for `client/python_wrappers` package --- .../{common => client}/python_wrappers/XHALInterface_python.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xhal/src/{common => client}/python_wrappers/XHALInterface_python.cpp (100%) diff --git a/xhal/src/common/python_wrappers/XHALInterface_python.cpp b/xhal/src/client/python_wrappers/XHALInterface_python.cpp similarity index 100% rename from xhal/src/common/python_wrappers/XHALInterface_python.cpp rename to xhal/src/client/python_wrappers/XHALInterface_python.cpp From c9218c22e89c3535d5aeb4794ba108e3b201658a Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:50:15 +0200 Subject: [PATCH 26/56] [refactor] Migrate sources for `client` interfaces --- xhal/src/{common => client}/XHALDevice.cpp | 0 xhal/src/{common => client}/XHALInterface.cpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename xhal/src/{common => client}/XHALDevice.cpp (100%) rename xhal/src/{common => client}/XHALInterface.cpp (100%) diff --git a/xhal/src/common/XHALDevice.cpp b/xhal/src/client/XHALDevice.cpp similarity index 100% rename from xhal/src/common/XHALDevice.cpp rename to xhal/src/client/XHALDevice.cpp diff --git a/xhal/src/common/XHALInterface.cpp b/xhal/src/client/XHALInterface.cpp similarity index 100% rename from xhal/src/common/XHALInterface.cpp rename to xhal/src/client/XHALInterface.cpp From 0a78beaada62af40b7fa1e65fdf5ca79355fccd6 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:45:24 +0200 Subject: [PATCH 27/56] [refactor] Migrate headers for `common/rpc` package --- xhal/include/xhal/{ => common}/rpc/call.h | 0 xhal/include/xhal/{ => common}/rpc/common.h | 0 xhal/include/xhal/{ => common}/rpc/compat.h | 0 xhal/include/xhal/{ => common}/rpc/exceptions.h | 0 xhal/include/xhal/{ => common}/rpc/helper.h | 0 xhal/include/xhal/{ => common}/rpc/register.h | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename xhal/include/xhal/{ => common}/rpc/call.h (100%) rename xhal/include/xhal/{ => common}/rpc/common.h (100%) rename xhal/include/xhal/{ => common}/rpc/compat.h (100%) rename xhal/include/xhal/{ => common}/rpc/exceptions.h (100%) rename xhal/include/xhal/{ => common}/rpc/helper.h (100%) rename xhal/include/xhal/{ => common}/rpc/register.h (100%) diff --git a/xhal/include/xhal/rpc/call.h b/xhal/include/xhal/common/rpc/call.h similarity index 100% rename from xhal/include/xhal/rpc/call.h rename to xhal/include/xhal/common/rpc/call.h diff --git a/xhal/include/xhal/rpc/common.h b/xhal/include/xhal/common/rpc/common.h similarity index 100% rename from xhal/include/xhal/rpc/common.h rename to xhal/include/xhal/common/rpc/common.h diff --git a/xhal/include/xhal/rpc/compat.h b/xhal/include/xhal/common/rpc/compat.h similarity index 100% rename from xhal/include/xhal/rpc/compat.h rename to xhal/include/xhal/common/rpc/compat.h diff --git a/xhal/include/xhal/rpc/exceptions.h b/xhal/include/xhal/common/rpc/exceptions.h similarity index 100% rename from xhal/include/xhal/rpc/exceptions.h rename to xhal/include/xhal/common/rpc/exceptions.h diff --git a/xhal/include/xhal/rpc/helper.h b/xhal/include/xhal/common/rpc/helper.h similarity index 100% rename from xhal/include/xhal/rpc/helper.h rename to xhal/include/xhal/common/rpc/helper.h diff --git a/xhal/include/xhal/rpc/register.h b/xhal/include/xhal/common/rpc/register.h similarity index 100% rename from xhal/include/xhal/rpc/register.h rename to xhal/include/xhal/common/rpc/register.h From cda8aae38806bef431b1ba8df8b31826e1ea837c Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:46:09 +0200 Subject: [PATCH 28/56] [refactor] Migrate headers for `common/utils` package --- xhal/include/xhal/{ => common}/utils/Exception.h | 0 xhal/include/xhal/{ => common}/utils/XHALXMLNode.h | 0 xhal/include/xhal/{ => common}/utils/XHALXMLParser.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename xhal/include/xhal/{ => common}/utils/Exception.h (100%) rename xhal/include/xhal/{ => common}/utils/XHALXMLNode.h (100%) rename xhal/include/xhal/{ => common}/utils/XHALXMLParser.h (100%) diff --git a/xhal/include/xhal/utils/Exception.h b/xhal/include/xhal/common/utils/Exception.h similarity index 100% rename from xhal/include/xhal/utils/Exception.h rename to xhal/include/xhal/common/utils/Exception.h diff --git a/xhal/include/xhal/utils/XHALXMLNode.h b/xhal/include/xhal/common/utils/XHALXMLNode.h similarity index 100% rename from xhal/include/xhal/utils/XHALXMLNode.h rename to xhal/include/xhal/common/utils/XHALXMLNode.h diff --git a/xhal/include/xhal/utils/XHALXMLParser.h b/xhal/include/xhal/common/utils/XHALXMLParser.h similarity index 100% rename from xhal/include/xhal/utils/XHALXMLParser.h rename to xhal/include/xhal/common/utils/XHALXMLParser.h From d731769d25117fbc5093ef64206be7fb63534341 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:46:51 +0200 Subject: [PATCH 29/56] [refactor] Migrate headers for `server` package --- xhal/include/xhal/{ => server}/LMDB.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xhal/include/xhal/{ => server}/LMDB.h (100%) diff --git a/xhal/include/xhal/LMDB.h b/xhal/include/xhal/server/LMDB.h similarity index 100% rename from xhal/include/xhal/LMDB.h rename to xhal/include/xhal/server/LMDB.h From 1f35f8127d0b925a95e5184e152dceb73282ee81 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:48:08 +0200 Subject: [PATCH 30/56] [refactor] Migrate sources for `server` package --- xhal/src/{common => server}/LMDB.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xhal/src/{common => server}/LMDB.cpp (100%) diff --git a/xhal/src/common/LMDB.cpp b/xhal/src/server/LMDB.cpp similarity index 100% rename from xhal/src/common/LMDB.cpp rename to xhal/src/server/LMDB.cpp From 1cc4148356698ac6d3d3d2743edf7f33cce722d0 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 17:52:27 +0200 Subject: [PATCH 31/56] [refactor] Update bolierplate for new structure --- .gitlab-ci.yml | 10 +- Makefile | 11 +- xhal/Makefile | 180 +++++++--------------- xhal/spec.template | 361 +++++++++++++++++++++++++++++++++++++++++++++ xhal/xhal.mk | 244 ++++++++++++++++++++++++++++++ 5 files changed, 668 insertions(+), 138 deletions(-) create mode 100644 xhal/spec.template create mode 100644 xhal/xhal.mk diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43d8178..2fe0799 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -245,11 +245,11 @@ test:cc7: find ./python/reg_interface_gem/rpm -type f -iname 'reg_interface_gem.src.rpm' -print0 -exec touch {} \; find ./python/reg_interface_gem/rpm -type f -iname 'reg_interface_gem.x86_64.rpm' -print0 -exec touch {} \; find ./python/reg_interface_gem/rpm -type f -iname 'reg_interface_gem.zip' -print0 -exec touch {} \; - find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.tbz2' -print0 -exec touch {} \; - find ./xhal*/rpm -type f -wholename '*/rpm/xhal.spec' -print0 -exec touch {} \; - find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.src.rpm' -print0 -exec touch {} \; - find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.arm*.rpm' -print0 -exec touch {} \; - find ./xhal*/rpm -type f -wholename '*/rpm/xhal*.x86_64.rpm' -print0 -exec touch {} \; + find ./xhal -type f -wholename '*/rpm/xhal*.tbz2' -print0 -exec touch {} \; + find ./xhal -type f -wholename '*/rpm/xhal.spec' -print0 -exec touch {} \; + find ./xhal -type f -wholename '*/rpm/xhal*.src.rpm' -print0 -exec touch {} \; + find ./xhal -type f -wholename '*/rpm/xhal*.arm*.rpm' -print0 -exec touch {} \; + find ./xhal -type f -wholename '*/rpm/xhal*.x86_64.rpm' -print0 -exec touch {} \; .before_package: &before_package |- eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` diff --git a/Makefile b/Makefile index a0bd062..5dd3ae7 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ SUBPACKAGES := \ python \ - xhalcore \ - xhalarm + xhal SUBPACKAGES.CLEAN := $(patsubst %,%.clean, $(SUBPACKAGES)) SUBPACKAGES.DEBUG := $(patsubst %,%.debug, $(SUBPACKAGES)) @@ -91,11 +90,3 @@ $(SUBPACKAGES.RELEASE): $(SUBPACKAGES) $(MAKE) -C $(patsubst %.release,%, $@) release python: - -xhalarm: - -xhalcore: - -xhalcore.install: xhalarm - -xhalcore.rpm: xhalarm diff --git a/xhal/Makefile b/xhal/Makefile index ca7c930..2d79f2a 100644 --- a/xhal/Makefile +++ b/xhal/Makefile @@ -1,152 +1,86 @@ -BUILD_HOME := $(shell dirname `cd ../; pwd`) -Project := xhal -Package := xhal -ShortPackage := xhal -LongPackage := xhalcore -PackageName := $(ShortPackage) -PackagePath := $(shell pwd) -PackageDir := pkg/$(ShortPackage) -Packager := Mykhailo Dalchenko -Arch := x86_64 +TARGETS := arm x86_64 -ProjectPath:= $(BUILD_HOME)/$(Project) -ConfigDir := $(ProjectPath)/config +TARGETS.RPM := $(patsubst %,%.rpm, $(TARGETS)) +TARGETS.CLEAN := $(patsubst %,%.clean, $(TARGETS)) +TARGETS.CLEANRPM := $(patsubst %,%.cleanrpm, $(TARGETS)) +TARGETS.CLEANALLRPM:= $(patsubst %,%.cleanallrpm, $(TARGETS)) +TARGETS.CLEANALL := $(patsubst %,%.cleanall, $(TARGETS)) +TARGETS.INSTALL := $(patsubst %,%.install, $(TARGETS)) +TARGETS.UNINSTALL := $(patsubst %,%.uninstall, $(TARGETS)) +TARGETS.RELEASE := $(patsubst %,%.release, $(TARGETS)) -include $(ConfigDir)/mfCommonDefs.mk -include $(ConfigDir)/mfPythonDefs.mk +.PHONY: $(TARGETS) \ + $(TARGETS.CLEAN) \ + $(TARGETS.INSTALL) \ + $(TARGETS.UNINSTALL) \ + $(TARGETS.RELEASE) \ + $(TARGETS.RPM) \ + $(TARGETS.CLEANRPM) \ + $(TARGETS.CLEANALLRPM) \ + $(TARGETS.CLEANALL) -PackageSourceDir:=$(PackagePath)/src/common -PackageObjectDir:=$(PackagePath)/src/linux/$(Arch) -PackageDocsDir:=$(PackagePath)/doc/_build/html +.PHONY: all default install uninstall rpm release +.PHONY: clean cleanall cleanrpm cleanallrpm -XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') -XHAL_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') +default: all -CCFLAGS=-fno-inline -Wall -pthread -ADDFLAGS=-g -fPIC -std=c++11 -m64 +all: $(TARGETS) doc -IncludeDirs+= $(XDAQ_ROOT)/include -IncludeDirs+= $(PackageIncludeDir) -INC=$(IncludeDirs:%=-I%) +rpm: $(TARGETS) $(TARGETS.RPM) -Libraries+=-llog4cplus -lxerces-c -lwiscrpcsvc -lstdc++ +clean: $(TARGETS.CLEAN) -LibraryDirs+=-L$(XDAQ_ROOT)/lib -LibraryDirs+=-L$(PackageLibraryDir) -LibraryDirs+=-L/opt/wiscrpcsvc/lib +cleanall: $(TARGETS.CLEANALL) cleandoc -LDFLAGS+= -shared $(LibraryDirs) +cleanrpm: $(TARGETS.CLEANRPM) -SRCS_XHAL = $(wildcard $(PackageSourceDir)/*.cpp) -SRCS_UTILS = $(wildcard $(PackageSourceDir)/utils/*.cpp) -SRCS_UTILS += $(wildcard $(PackageSourceDir)/rpc/*.cpp) -SRCS_XHALPY = $(wildcard $(PackageSourceDir)/python_wrappers/*.cpp) -SRCS_RPCMAN = $(wildcard $(PackageSourceDir)/rpc_manager/*.cpp) -# SRCS_EXES = $(wildcard $(PackageSourceDir)/*.cxx) -# SRCS_TEST_EXES= $(wildcard $(PackageTestSourceDir)/*.cxx) +cleanallrpm: $(TARGETS.CLEANALLRPM) -AUTODEPS_XHAL = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHAL)) -AUTODEPS_UTILS = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_UTILS)) -AUTODEPS_XHALPY = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHALPY)) -AUTODEPS_RPCMAN = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_RPCMAN)) +install: $(TARGETS.INSTALL) -OBJS_XHAL = $(patsubst %.d,%.o,$(AUTODEPS_XHAL)) -OBJS_UTILS = $(patsubst %.d,%.o,$(AUTODEPS_UTILS)) -OBJS_XHALPY = $(patsubst %.d,%.o,$(AUTODEPS_XHALPY)) -OBJS_RPCMAN = $(patsubst %.d,%.o,$(AUTODEPS_RPCMAN)) +uninstall: $(TARGETS.UNINSTALL) -XHAL_LIB = $(PackageLibraryDir)/libxhal.so -XHALPY_LIB = $(PackageLibraryDir)/xhalpy.so -RPCMAN_LIB = $(PackageLibraryDir)/librpcman.so +release: $(TARGETS.RELEASE) -TargetLibraries:= xhal xhalpy rpcman +$(TARGETS): + TargetArch=$@ $(MAKE) -f xhal.mk build -include $(ConfigDir)/mfRPMRules.mk +$(TARGETS.RPM): + TargetArch=$(patsubst %.rpm,%,$@) $(MAKE) -f xhal.mk rpm -# destination path macro we'll use below -df = $(PackageObjectDir)/$(*F) +$(TARGETS.CLEAN): + TargetArch=$(patsubst %.clean,%,$@) $(MAKE) -f xhal.mk clean -.PHONY: xhal rpc +$(TARGETS.CLEANRPM): + TargetArch=$(patsubst %.cleanrpm,%,$@) $(MAKE) -f xhal.mk cleanrpm -## @xhalcore Compile all target libraries -build: $(TargetLibraries) +$(TARGETS.CLEANALLRPM): + TargetArch=$(patsubst %.cleanallrpm,%,$@) $(MAKE) -f xhal.mk cleanallrpm -all: build +$(TARGETS.CLEANALL): + TargetArch=$(patsubst %.cleanall,%,$@) $(MAKE) -f xhal.mk cleanall -default: build - $(MakeDir) $(PackageDir) +$(TARGETS.INSTALL): + TargetArch=$(patsubst %.install,%,$@) $(MAKE) -f xhal.mk install -## @xhalcore Prepare the package for building the RPM -rpmprep: build doc +$(TARGETS.UNINSTALL): + TargetArch=$(patsubst %.uninstall,%,$@) $(MAKE) -f xhal.mk uninstall -# Define as dependency everything that should cause a rebuild -$(PackageSourceTarball): $(XHAL_LIB) $(XHALPY_LIB) $(RPCMAN_LIB) Makefile $(ProjectPath)/xhalarm/lib/libxhal* - $(MakeDir) $(RPM_DIR) - $(MakeDir) lib/arm - $(MakeDir) $(PackageDir)/$(Package) - @cp -rfp $(ProjectPath)/xhalarm/lib/* lib/arm - @cp -rfp lib include Makefile $(PackageDir)/$(Package) - @cp -rfp src $(PackageDir)/$(Package) -# @cp -rfp --parents src/common $(PackageDir)/$(Package) - @cp -rfp $(ProjectPath)/config $(PackageDir) - cd $(PackageDir)/..; \ - tar cjf $(PackageSourceTarball) $(PackageName); - $(RM) $(PackageDir)/$(Package) - -## @xhalcore Compile the xhal RPC manager library -rpc: xhal $(RPCMAN_LIB) - -## @xhalcore Compile the xhal library -xhal: $(XHAL_LIB) - -## @xhalcore Compile the xhal python bindings -xhalpy: xhal rpc $(XHALPY_LIB) +$(TARGETS.RELEASE): + TargetArch=$(patsubst %.release,%,$@) $(MAKE) -f xhal.mk release doc: @echo "TO DO" -## adapted from http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ -## Generic object creation rule, generate dependencies and use them later -$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp Makefile - $(MakeDir) $(@D) - $(CXX) $(CCFLAGS) $(ADDFLAGS) $(INC) -c -MT $@ -MMD -MP -MF $(@D)/$(*F).Td -o $@ $< - mv $(@D)/$(*F).Td $(@D)/$(*F).d - touch $@ - -## dummy rule for dependencies -$(PackageObjectDir)/%.d: - -## mark dependencies and objects as not auto-removed -.PRECIOUS: $(PackageObjectDir)/%.d -.PRECIOUS: $(PackageObjectDir)/%.o - -## Force rule for all target library names -$(TargetLibraries): - -$(XHAL_LIB): $(OBJS_XHAL) $(OBJS_UTILS) - $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) - $(link-sonames) - -$(RPCMAN_LIB): $(OBJS_RPCMAN) - $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) - $(link-sonames) - -$(XHALPY_LIB): $(OBJS_XHALPY) $(XHAL_LIB) $(RPCMAN_LIB) - $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal -lrpcman - $(link-sonames) - -clean: - $(RM) $(OBJS_UTILS) $(OBJS_XHAL) $(OBJS_RPCMAN) $(OBJS_XHALPY) - $(RM) $(PackageLibraryDir) - $(RM) $(PackageExecDir) - $(RM) $(PackageDir) - cleandoc: @echo "TO DO" -cleanall: - $(RM) $(PackageObjectDir) +arm: + +x86_64: + +ctp7: + +bcp: + +apx: diff --git a/xhal/spec.template b/xhal/spec.template new file mode 100644 index 0000000..b6af8b7 --- /dev/null +++ b/xhal/spec.template @@ -0,0 +1,361 @@ +%define _package __package__ +%define _longpackage __longpackage__ +%define _packagename __packagename__ +%define _version __version__ +%define _short_release __short_release__ +%define _prefix __prefix__ +#%%define _sources_dir __sources_dir__ +%define _tmppath /tmp +#%%define _packagedir __packagedir__ +%define _os __os__ +%define _platform __platform__ +%define _project __project__ +%define _author __author__ +%define _summary __summary__ +%define _url __url__ +%define _buildarch __buildarch__ +#%%define _includedirs __includedirs__ + +%global _binaries_in_noarch_packages_terminate_build 0 +%global _unpackaged_files_terminate_build 0 + +### find . -type d -wholename '*/lib/arm' +#%%global add_arm_libs %( if [ -d '%{_packagedir}/lib/arm' ]; then echo "1" ; else echo "0"; fi ) +%global is_arm %( if [[ '__buildarch__' =~ "arm" ]]; then echo "1" ; else echo "0"; fi ) +%global not_arm %( if [[ ! '__buildarch__' =~ "arm" ]]; then echo "1" ; else echo "0"; fi ) + +%global _find_debuginfo_opts -g + +# +# Binary RPM specified attributed (lib and bin) +# +Name: %{_packagename} +Summary: %{_summary} +Version: %{_version} +Release: %{_release} +Packager: %{_author} +# BuildArch: %{_buildarch} +License: __license__ +URL: %{_url} +# Source: %{_source_url}/%{_project}-%{_longpackage}-%{_version}-%{_short_release}.tbz2 +BuildRoot: %{_tmppath}/%{_packagename}-%{_version}-%{_release}-buildroot +Prefix: %{_prefix} +%if 0%{?_requires} +Requires: __requires_list__ +%endif + +%if 0%{?_build_requires} +BuildRequires: __build_requires_list__ +%endif + +%if %{is_arm} +AutoReq: no +%endif + +%description +__description__ + +%if %not_arm +## xhal-client subpackage +%package client +Summary: Client package for %{_packagename} +Requires: __client_requires_list__ +BuildRequires: __client_build_requires_list__ + +%description client +Client libraries of the xhal package +%endif + +%if %is_arm +%package -n ctp7-xhal-libs +Summary: Libraries for cross-compiling %{_packagename} dependent applications for CTP7 +Prefix: /opt/gem-peta-stage/ctp7/%{_prefix} +Requires: gem-peta-stage-ctp7 +BuildRequires: __build_requires_list__,__server_build_requires_list__ +BuildArch: noarch +AutoReq: no + +%description -n ctp7-xhal-libs +Provides the %{_packagename} libraries for the CTP7. +These libraries are used when cross-compiling CTP7 applications. + +%endif + +## xhal-server subpackage +%package server +Summary: Server package for %{_packagename} +Requires: __server_requires_list__ +BuildRequires: __server_build_requires_list__ + +%description server +Server libraries of the xhal package + +## Only build devel RPMs for non-ARM +%if %not_arm +%package -n %{_packagename}-devel +Summary: Development files for %{_packagename} +Requires: %{_packagename} + +%description -n %{_packagename}-devel +Development headers for the %{_packagename} package + +%package -n %{_packagename}-server-devel +Summary: Development files for %{_packagename}-server +Requires: %{_packagename}-server + +%description -n %{_packagename}-server-devel +Development package for the server libraries of the xhal package + +%package -n %{_packagename}-client-devel +Summary: Development package for %{_packagename}-client +Requires: %{_packagename}-client + +%description -n %{_packagename}-client-devel +Development package for the client libraries of the xhal package + +%endif + +## Only build debuginfo RPMs for non-ARM? +#%%%if %not_arm +%package -n %{_packagename}-debuginfo +Summary: Debuginfos for %{_packagename} +Requires: %{_packagename} + +%description -n %{_packagename}-debuginfo +Debuginfos for the %{_packagename} package + +#%%##%%%package -n %{_packagename}-server-debuginfo +#%%##%%Summary: Debuginfos for %{_packagename}-server +#%%##%%Requires: %{_packagename}-server +#%%##%% +#%%##%%%description -n %{_packagename}-server-debuginfo +#%%##%%Debuginfos for the server libraries of the xhal package + +## xhal-client is not for ARM +## xhal-client package and subpackages +#%%##%%%package -n %{_packagename}-client-debuginfo +#%%##%%Summary: Debuginfo for %{_packagename}-client +#%%##%%Requires: %{_packagename}-client +#%%##%% +#%%##%%%description -n %{_packagename}-client-debuginfo +#%%##%%Debuginfos for the client libraries of the xhal package +#%%%endif + +# %pre + +%prep +## if there is a Source tag that points to the tarball +#%%setup -q +mv %{_sourcedir}/%{_project}-%{_longpackage}-%{_version}-%{_short_release}.tbz2 ./ +tar xjf %{_project}-%{_longpackage}-%{_version}-%{_short_release}.tbz2 + +## update extracted timestamps if doing a git build +find %{_project}/%{_packagename} -type f -iname '*.h' -print0 -exec touch {} \+ +find %{_project}/%{_packagename} -type f -iname '*.cpp' -print0 -exec touch {} \+ +find %{_project}/%{_packagename} -type f -iname '*.d' -print0 -exec touch {} \+ +find %{_project}/%{_packagename} -type f -iname '*.o' -print0 -exec touch {} \+ +find %{_project}/%{_packagename} -type f -iname '*.so*' -print0 -exec touch {} \+ +find %{_project}/%{_packagename} -type l -iname '*.so*' -print0 -exec touch -h {} \+ + +%build +pushd %{_project}/%{_packagename} +TargetArch=%{_longpackage} make build -j4 +popd + +# +# Prepare the list of files that are the input to the binary and devel RPMs +# +%install +rm -rf %{buildroot} +pushd %{_project}/%{_packagename} +echo TargetArch=%{_longpackage} INSTALL_PREFIX=%{buildroot} make install +TargetArch=%{_longpackage} INSTALL_PREFIX=%{buildroot} make install +touch ChangeLog README.md LICENSE MAINTAINER.md CHANGELOG.md +popd + +%if %is_arm +pushd %{_project} +mkdir -p %{buildroot}/opt/ +cp -rfp --parents gem-peta-stage %{buildroot}/opt/ +popd +%endif + +## Manually run find-debuginfo because...? +## maybe only on x86_64? +/usr/lib/rpm/find-debuginfo.sh -g -m -r --strict-build-id + +%clean +##rm -rf %{buildroot} + +# +# Files that go in the binary RPM +# +%files +%defattr(-,root,root,0755) +%{_prefix}/lib/libxhal-base.so* + +%dir + +%doc %{_project}/%{_packagename}/MAINTAINER.md +%doc %{_project}/%{_packagename}/README.md +%doc %{_project}/%{_packagename}/CHANGELOG.md +%license %{_project}/%{_packagename}/LICENSE + +##### Server subpackage ##### +# +# Files that go in the binary RPM +# +%files server +%defattr(-,root,root,0755) +%{_prefix}/lib/libxhal-server.so* + +%dir + +%doc %{_project}/%{_packagename}/MAINTAINER.md +%doc %{_project}/%{_packagename}/README.md +%doc %{_project}/%{_packagename}/CHANGELOG.md +%license %{_project}/%{_packagename}/LICENSE + +%if %not_arm +#### Client subpackage #### +# +# Files that go in the binary RPM +# +%files client +%defattr(-,root,root,0755) +%{_prefix}/lib/libxhal-client.so* +%{_prefix}/lib/libxhal-rpcman.so* +%{_prefix}/lib/xhalpy.so* + +%dir + +%doc %{_project}/%{_packagename}/MAINTAINER.md +%doc %{_project}/%{_packagename}/README.md +%doc %{_project}/%{_packagename}/CHANGELOG.md +%license %{_project}/%{_packagename}/LICENSE + +%endif + +%if %is_arm + +#### CTP7 libs #### +# +# Files that go in the binary RPM +# +%files -n ctp7-xhal-libs +%defattr(-,root,root,0755) +%attr(0755,root,root) %{prefix}/lib/libxhal-*.so* + +## Tries to put in the /mnt/persistent tree +## %%%dir +## %%%docdir /opt/xhal +## %%%doc %{_project}/%{_packagename}/MAINTAINER.md +## %%%doc %{_project}/%{_packagename}/README.md +## %%%doc %{_project}/%{_packagename}/CHANGELOG.md +## %%%license %{_project}/%{_packagename}/LICENSE +%endif + +#### Only build devel RPMs for non-ARM #### +%if %not_arm + +# +# Files that go in the devel RPM +# +%files -n %{_packagename}-devel +%defattr(-,root,root,0755) +%attr(0644,root,root) %{_prefix}/include/xhal/extern/wisc*.h + +%dir +%{_prefix}/include/xhal/common + +%doc %{_project}/%{_packagename}/MAINTAINER.md +%doc %{_project}/%{_packagename}/README.md +%doc %{_project}/%{_packagename}/CHANGELOG.md +%license %{_project}/%{_packagename}/LICENSE + +# +# Files that go in the server-devel RPM +# +%files -n %{_packagename}-server-devel +%defattr(-,root,root,0755) +%attr(0644,root,root) %{_prefix}/include/xhal/extern/lmdb++.h + +%dir +%{_prefix}/include/xhal/server + +%doc %{_project}/%{_packagename}/MAINTAINER.md +%doc %{_project}/%{_packagename}/README.md +%doc %{_project}/%{_packagename}/CHANGELOG.md +%license %{_project}/%{_packagename}/LICENSE + +# +# Files that go in the client-devel RPM +# +%files -n %{_packagename}-client-devel +%defattr(-,root,root,0755) + +%dir +%{_prefix}/include/xhal/client + +%doc %{_project}/%{_packagename}/MAINTAINER.md +%doc %{_project}/%{_packagename}/README.md +%doc %{_project}/%{_packagename}/CHANGELOG.md +%license %{_project}/%{_packagename}/LICENSE + +%endif + +#### Only build debuginfo RPMs for non-ARM? #### +#%%%if %not_arm +# +# Files that go in the debuginfo RPM +# +%files -n %{_packagename}-debuginfo +%defattr(-,root,root,0755) + +%dir +/usr/lib/debug/%{_prefix} +/usr/src/debug/%{_packagename}-%{_version} + +%doc %{_project}/%{_packagename}/MAINTAINER.md +%doc %{_project}/%{_packagename}/README.md +%doc %{_project}/%{_packagename}/CHANGELOG.md +%license %{_project}/%{_packagename}/LICENSE + +##### Server subpackage ##### +#%%##%%# +#%%##%%# Files that go in the server-debuginfo RPM +#%%##%%# +#%%##%%%files -n %{_packagename}-server-debuginfo +#%%##%%%defattr(-,root,root,0755) +#%%##%% +#%%##%%%dir +#%%##%%/usr/lib/debug/%{_prefix} +#%%##%%/usr/src/debug/%{_packagename}-server-%{_version} +#%%##%% +#%%##%%%doc %{_project}/%{_packagename}/MAINTAINER.md %{_project}/%{_packagename}/README.md %{_project}/%{_packagename}/CHANGELOG.md +#%%##%%%license %{_project}/%{_packagename}/LICENSE + +#%%%if %not_arm +##### Client subpackage ##### +#%%##%%# +#%%##%%# Files that go in the client-debuginfo RPM +#%%##%%# +#%%##%%%files -n %{_packagename}-client-debuginfo +#%%##%%%defattr(-,root,root,0755) +#%%##%% +#%%##%%%dir +#%%##%%/usr/lib/debug/%{_prefix} +#%%##%%/usr/src/debug/%{_packagename}-client-%{_version} +#%%##%% +#%%##%%%doc %{_project}/%{_packagename}/MAINTAINER.md %{_project}/%{_packagename}/README.md %{_project}/%{_packagename}/CHANGELOG.md +#%%##%%%license %{_project}/%{_packagename}/LICENSE + +#%%##%%%endif + +%post + +%preun + +%postun + +%changelog diff --git a/xhal/xhal.mk b/xhal/xhal.mk new file mode 100644 index 0000000..a564ddf --- /dev/null +++ b/xhal/xhal.mk @@ -0,0 +1,244 @@ +BUILD_HOME := $(shell dirname `cd ../; pwd`) +Project := xhal +Package := xhal +ShortPackage := xhal +LongPackage := $(TargetArch) +PackageName := $(ShortPackage) +PackagePath := $(TargetArch) +PackageDir := pkg/$(ShortPackage) +Packager := Mykhailo Dalchenko +Arch := $(TargetArch) + +ProjectPath:=$(BUILD_HOME)/$(Project) + +ConfigDir:=$(ProjectPath)/config + +include $(ConfigDir)/mfCommonDefs.mk + +ifeq ($(Arch),x86_64) +include $(ConfigDir)/mfPythonDefs.mk +CFLAGS=-fno-inline -Wall -pthread +ADDFLAGS=-g -fPIC -std=c++11 -std=gnu++11 -m64 +else +include $(ConfigDir)/mfZynq.mk +ADDFLAGS=-g -std=gnu++14 +endif + +PackageSourceDir:=src +PackageIncludeDir:=include +PackageObjectDir:=$(PackagePath)/src/linux/$(Arch) +PackageLibraryDir:=$(PackagePath)/lib +PackageExecDir:=$(PackagePath)/bin +PackageDocsDir:=$(PackagePath)/doc/_build/html + +XHAL_VER_MAJOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[1];}' | awk '{split($$0,b,":"); print b[2];}') +XHAL_VER_MINOR:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[2];}' | awk '{split($$0,b,":"); print b[2];}') +XHAL_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print a[3];}' | awk '{split($$0,b,":"); print b[2];}') + +IncludeDirs+= $(XDAQ_ROOT)/include +IncludeDirs+= $(PackageIncludeDir) +IncludeDirs+= $(PackageIncludeDir)/xhal/extern +# IncludeDirs+= $(PackageIncludeDir)/server +# IncludeDirs+= $(PackageIncludeDir)/client +INC=$(IncludeDirs:%=-I%) + +ifeq ($(Arch),x86_64) +Libraries+=-llog4cplus -lxerces-c -lwiscrpcsvc -lstdc++ +LibraryDirs+=-L$(XDAQ_ROOT)/lib +LibraryDirs+=-L/opt/wiscrpcsvc/lib +else +Libraries+=-llog4cplus -lxerces-c -lstdc++ +endif + +LibraryDirs+=-L$(PackageLibraryDir) + +LDFLAGS+= -shared $(LibraryDirs) + +SRCS_XHAL = $(wildcard $(PackageSourceDir)/common/utils/*.cpp) +SRCS_XHAL += $(wildcard $(PackageSourceDir)/common/rpc/*.cpp) +SRCS_CLIENT = $(wildcard $(PackageSourceDir)/client/*.cpp) +SRCS_SERVER = $(wildcard $(PackageSourceDir)/server/*.cpp) +SRCS_XHALPY = $(wildcard $(PackageSourceDir)/client/python_wrappers/*.cpp) +SRCS_RPCMAN = $(wildcard $(PackageSourceDir)/client/rpc_manager/*.cpp) +# SRCS_EXES = $(wildcard $(PackageSourceDir)/*.cxx) +# SRCS_TEST_EXES= $(wildcard $(PackageTestSourceDir)/*.cxx) + +AUTODEPS_XHAL = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHAL)) +AUTODEPS_CLIENT = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_CLIENT)) +AUTODEPS_SERVER = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_SERVER)) +AUTODEPS_XHALPY = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_XHALPY)) +AUTODEPS_RPCMAN = $(patsubst $(PackageSourceDir)/%.cpp,$(PackageObjectDir)/%.d,$(SRCS_RPCMAN)) + +OBJS_XHAL = $(patsubst %.d,%.o,$(AUTODEPS_XHAL)) +OBJS_CLIENT = $(patsubst %.d,%.o,$(AUTODEPS_CLIENT)) +OBJS_SERVER = $(patsubst %.d,%.o,$(AUTODEPS_SERVER)) +OBJS_XHALPY = $(patsubst %.d,%.o,$(AUTODEPS_XHALPY)) +OBJS_RPCMAN = $(patsubst %.d,%.o,$(AUTODEPS_RPCMAN)) + +XHAL_LIB = $(PackageLibraryDir)/libxhal-base.so +CLIENT_LIB = $(PackageLibraryDir)/libxhal-client.so +SERVER_LIB = $(PackageLibraryDir)/libxhal-server.so +XHALPY_LIB = $(PackageLibraryDir)/xhalpy.so +RPCMAN_LIB = $(PackageLibraryDir)/libxhal-rpcman.so + +ifeq ($(Arch),x86_64) +TargetLibraries:= xhal-base xhal-server xhal-client xhalpy xhal-rpcman +else +TargetLibraries:= xhal-base xhal-server +endif + +## Update spec file for subpackage specific requirements +ifndef BASE_REQUIRED_PACKAGE_LIST +BASE_REQUIRED_PACKAGE_LIST=$(shell awk 'BEGIN{IGNORECASE=1} /define XHAL_BASE_REQUIRED_PACKAGE_LIST/ {print $$3;}' $(PackageIncludeDir)/packageinfo.h) +endif + +ifndef CLIENT_REQUIRED_PACKAGE_LIST +CLIENT_REQUIRED_PACKAGE_LIST=$(shell awk 'BEGIN{IGNORECASE=1} /define XHAL_CLIENT_REQUIRED_PACKAGE_LIST/ {print $$3;}' $(PackageIncludeDir)/packageinfo.h) +endif + +ifndef SERVER_REQUIRED_PACKAGE_LIST +SERVER_REQUIRED_PACKAGE_LIST=$(shell awk 'BEGIN{IGNORECASE=1} /define XHAL_SERVER_REQUIRED_PACKAGE_LIST/ {print $$3;}' $(PackageIncludeDir)/packageinfo.h) +endif + +ifndef BASE_BUILD_REQUIRED_PACKAGE_LIST +BASE_BUILD_REQUIRED_PACKAGE_LIST=$(shell awk 'BEGIN{IGNORECASE=1} /define XHAL_BASE_BUILD_REQUIRED_PACKAGE_LIST/ {print $$3;}' $(PackageIncludeDir)/packageinfo.h) +endif + +ifndef CLIENT_BUILD_REQUIRED_PACKAGE_LIST +CLIENT_BUILD_REQUIRED_PACKAGE_LIST=$(shell awk 'BEGIN{IGNORECASE=1} /define XHAL_CLIENT_BUILD_REQUIRED_PACKAGE_LIST/ {print $$3;}' $(PackageIncludeDir)/packageinfo.h) +endif + +ifndef SERVER_BUILD_REQUIRED_PACKAGE_LIST +SERVER_BUILD_REQUIRED_PACKAGE_LIST=$(shell awk 'BEGIN{IGNORECASE=1} /define XHAL_SERVER_BUILD_REQUIRED_PACKAGE_LIST/ {print $$3;}' $(PackageIncludeDir)/packageinfo.h) +endif + +## Override the RPM_DIR variable because we're a special case +RPM_DIR:=$(ProjectPath)/$(PackageName)/$(LongPackage)/rpm +include $(ConfigDir)/mfRPMRules.mk + +$(PackageSpecFile): $(ProjectPath)/$(PackageName)/spec.template + +specificspecupdate: $(PackageSpecFile) + echo Running specific spec update + sed -i 's#__base_requires_list__#$(BASE_REQUIRED_PACKAGE_LIST)#' $< + sed -i 's#__base_build_requires_list__#$(BASE_BUILD_REQUIRED_PACKAGE_LIST)#' $< + sed -i 's#__client_requires_list__#$(CLIENT_REQUIRED_PACKAGE_LIST)#' $< + sed -i 's#__client_build_requires_list__#$(CLIENT_BUILD_REQUIRED_PACKAGE_LIST)#' $< + sed -i 's#__server_requires_list__#$(SERVER_REQUIRED_PACKAGE_LIST)#' $< + sed -i 's#__server_build_requires_list__#$(SERVER_BUILD_REQUIRED_PACKAGE_LIST)#' $< + +# destination path macro we'll use below +df = $(PackageObjectDir)/$(*F) + +.PHONY: xhal-base xhal-client xhal-server xhal-rpcman + +## @xhal Compile all target libraries +build: $(TargetLibraries) + +all: + +default: $(TARGETS) + +## @xhal Prepare the package for building the RPM +rpmprep: build doc + +# Define as dependency everything that should cause a rebuild +TarballDependencies = $(XHAL_LIB) $(SERVER_LIB) Makefile xhal.mk spec.template +ifeq ($(Arch),x86_64) +TarballDependencies+= $(CLIENT_LIB) $(XHALPY_LIB) $(RPCMAN_LIB) +else +endif + +## this needs to reproduce the compiled tree because... wrong headed +## either do the make in the spec file, or don't make up your mind! +$(PackageSourceTarball): $(TarballDependencies) + $(MakeDir) $(PackagePath)/$(PackageDir) +ifeq ($(Arch),x86_64) + echo nothing to do +else + $(MakeDir) $(PackagePath)/$(PackageDir)/gem-peta-stage/ctp7/$(INSTALL_PATH)/lib + @cp -rfp $(PackageLibraryDir)/* $(PackagePath)/$(PackageDir)/gem-peta-stage/ctp7/$(INSTALL_PATH)/lib +endif + $(MakeDir) $(RPM_DIR) + @cp -rfp spec.template $(PackagePath) + $(MakeDir) $(PackagePath)/$(PackageDir)/$(PackageName)/$(LongPackage) + @cp -rfp --parents $(PackageObjectDir) $(PackagePath)/$(PackageDir)/$(PackageName) + @cp -rfp --parents $(PackageLibraryDir) $(PackagePath)/$(PackageDir)/$(PackageName) + -cp -rfp --parents $(PackageExecDir) $(PackagePath)/$(PackageDir)/$(PackageName) + @cp -rfp $(PackageSourceDir) $(PackagePath)/$(PackageDir)/$(PackageName) + @cp -rfp $(PackageIncludeDir) $(PackagePath)/$(PackageDir)/$(PackageName) + @cp -rfp xhal.mk $(PackagePath)/$(PackageDir)/$(PackageName)/Makefile + @cp -rfp $(ProjectPath)/config $(PackagePath)/$(PackageDir) +# cd $(ProjectPath); cp -rfp --parents xhal/Makefile $(PackagePath)/$(PackageDir) +# cd $(ProjectPath); cp -rfp --parents xhal/{include,src} $(PackagePath)/$(PackageDir) + cd $(PackagePath)/$(PackageDir)/..; \ + tar cjf $(PackageSourceTarball) . ; +# $(RM) $(PackagePath)/$(PackageDir) + +## @xhal Compile the xhal library +xhal-base: $(XHAL_LIB) + +## @xhal Compile the xhal-client library +xhal-client: $(CLIENT_LIB) + +## @xhal Compile the xhal-server library +xhal-server: $(SERVER_LIB) + +## @xhal Compile the xhal RPC manager library +xhal-rpcman: xhal-base $(RPCMAN_LIB) + +## @xhal Compile the xhal python bindings +xhalpy: xhal-base xhal-rpcman $(XHALPY_LIB) + +## adapted from http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ +## Generic object creation rule, generate dependencies and use them later +$(PackageObjectDir)/%.o: $(PackageSourceDir)/%.cpp Makefile + $(MakeDir) $(@D) + $(CXX) $(CFLAGS) $(ADDFLAGS) $(INC) -c -MT $@ -MMD -MP -MF $(@D)/$(*F).Td -o $@ $< + mv $(@D)/$(*F).Td $(@D)/$(*F).d + touch $@ + +## dummy rule for dependencies +$(PackageObjectDir)/%.d: + +## mark dependencies and objects as not auto-removed +.PRECIOUS: $(PackageObjectDir)/%.d +.PRECIOUS: $(PackageObjectDir)/%.o + +## Force rule for all target library names +$(TargetLibraries): + +$(XHAL_LIB): $(OBJS_XHAL) + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(link-sonames) + +$(CLIENT_LIB): $(OBJS_CLIENT) + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(link-sonames) + +$(SERVER_LIB): $(OBJS_SERVER) + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(link-sonames) + +$(RPCMAN_LIB): $(OBJS_RPCMAN) + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(link-sonames) + +$(XHALPY_LIB): $(OBJS_XHALPY) $(XHAL_LIB) $(RPCMAN_LIB) + $(MakeDir) -p $(@D) + $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal-base -lxhal-rpcman + $(link-sonames) + +clean: + $(RM) $(OBJS_XHAL) $(OBJS_CLIENT) $(OBJS_SERVER) $(OBJS_RPCMAN) $(OBJS_XHALPY) + $(RM) $(PackageLibraryDir) + $(RM) $(PackageExecDir) + $(RM) $(PackagePath)/$(PackageDir) + +cleanall: + $(RM) $(PackageObjectDir) + $(RM) $(PackagePath) From 31dad8370cc3ab7f753d7418465c6c8a73671b5f Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 20:11:54 +0200 Subject: [PATCH 32/56] [refactor] Adapt `common/rpc` for new structure --- xhal/include/xhal/common/rpc/call.h | 24 +++++++++++---------- xhal/include/xhal/common/rpc/common.h | 21 ++++++++++-------- xhal/include/xhal/common/rpc/compat.h | 14 ++++++++---- xhal/include/xhal/common/rpc/exceptions.h | 18 ++++++++++------ xhal/include/xhal/common/rpc/helper.h | 16 +++++++++----- xhal/include/xhal/common/rpc/register.h | 26 ++++++++++++----------- xhal/src/common/rpc/exceptions.cpp | 14 ++++++++---- 7 files changed, 82 insertions(+), 51 deletions(-) diff --git a/xhal/include/xhal/common/rpc/call.h b/xhal/include/xhal/common/rpc/call.h index ab1223c..91ff6bd 100644 --- a/xhal/include/xhal/common/rpc/call.h +++ b/xhal/include/xhal/common/rpc/call.h @@ -7,19 +7,21 @@ * \author Louis Moureaux */ -#ifndef XHAL_RPC_CALL_H -#define XHAL_RPC_CALL_H +#ifndef XHAL_COMMON_RPC_CALL_H +#define XHAL_COMMON_RPC_CALL_H -#include "xhal/rpc/common.h" -#include "xhal/rpc/compat.h" -#include "xhal/rpc/exceptions.h" -#include "xhal/rpc/helper.h" +#include "xhal/common/rpc/common.h" +#include "xhal/common/rpc/compat.h" +#include "xhal/common/rpc/exceptions.h" +#include "xhal/common/rpc/helper.h" -#include "xhal/rpc/wiscrpcsvc.h" // move the header to xhal/extern/wiscrpcsvc.h ? +#include "xhal/extern/wiscrpcsvc.h" #include -namespace xhal { namespace rpc { +namespace xhal { + namespace common { + namespace rpc { /*! * \brief Remotely call a RPC method @@ -152,7 +154,7 @@ namespace xhal { namespace rpc { throw MessageException(helper::getExceptionMessage(e)); } } + } +} -}} - -#endif +#endif // XHAL_COMMON_RPC_CALL_H diff --git a/xhal/include/xhal/common/rpc/common.h b/xhal/include/xhal/common/rpc/common.h index b2582ca..36a817f 100644 --- a/xhal/include/xhal/common/rpc/common.h +++ b/xhal/include/xhal/common/rpc/common.h @@ -5,11 +5,11 @@ * \author Laurent Pétré */ -#ifndef XHAL_RPC_COMMON_H -#define XHAL_RPC_COMMON_H +#ifndef XHAL_COMMON_RPC_COMMON_H +#define XHAL_COMMON_RPC_COMMON_H -#include "xhal/rpc/compat.h" -#include "xhal/rpc/helper.h" +#include "xhal/common/rpc/compat.h" +#include "xhal/common/rpc/helper.h" #include #include @@ -18,9 +18,11 @@ #include #include -#include "xhal/rpc/wiscRPCMsg.h" // move the header to "xhal/extern/wiscRPCMsg.h" ? +#include "xhal/extern/wiscRPCMsg.h" -namespace xhal { namespace rpc { +namespace xhal { + namespace common { + namespace rpc { /*! * \brief Defines the templated RPC ABI version @@ -463,8 +465,9 @@ namespace xhal { namespace rpc { for (auto & elem: value) { msg & elem; } + } } + } +} -} } - -#endif +#endif // XHAL_COMMON_RPC_COMMON_H diff --git a/xhal/include/xhal/common/rpc/compat.h b/xhal/include/xhal/common/rpc/compat.h index 90f55d0..9eec8b1 100644 --- a/xhal/include/xhal/common/rpc/compat.h +++ b/xhal/include/xhal/common/rpc/compat.h @@ -11,13 +11,16 @@ * \author Laurent Pétré */ -#ifndef XHAL_RPC_COMPAT_H -#define XHAL_RPC_COMPAT_H +#ifndef XHAL_COMMON_RPC_COMPAT_H +#define XHAL_COMMON_RPC_COMPAT_H #include #include -namespace xhal { namespace rpc { namespace compat { +namespace xhal { + namespace common { + namespace rpc { + namespace compat { /*! * \brief This class can encapsulates any type, including \c void @@ -141,6 +144,9 @@ namespace xhal { namespace rpc { namespace compat { return {}; } -} } } + } + } + } +} #endif diff --git a/xhal/include/xhal/common/rpc/exceptions.h b/xhal/include/xhal/common/rpc/exceptions.h index 42906eb..54667ba 100644 --- a/xhal/include/xhal/common/rpc/exceptions.h +++ b/xhal/include/xhal/common/rpc/exceptions.h @@ -5,12 +5,15 @@ * \author Louis Moureaux */ -#ifndef XHAL_RPC_EXCEPTIONS_H -#define XHAL_RPC_EXCEPTIONS_H +#ifndef XHAL_COMMON_RPC_EXCEPTIONS_H +#define XHAL_COMMON_RPC_EXCEPTIONS_H -#include "xhal/rpc/wiscrpcsvc.h" +#include "xhal/extern/wiscrpcsvc.h" -namespace xhal { namespace rpc { namespace helper { +namespace xhal { + namespace common { + namespace rpc { + namespace helper { /** * \brief Retrieves a user-friendly message for the given exception. @@ -71,6 +74,9 @@ namespace xhal { namespace rpc { namespace helper { */ std::string readExceptionMessage(const wisc::RPCMsg &response); -}}} // namespace xhal::rpc::helper + } + } + } +} -#endif // XHAL_RPC_EXCEPTIONS_H +#endif // XHAL_COMMON_RPC_EXCEPTIONS_H diff --git a/xhal/include/xhal/common/rpc/helper.h b/xhal/include/xhal/common/rpc/helper.h index d23b3f7..c14202b 100644 --- a/xhal/include/xhal/common/rpc/helper.h +++ b/xhal/include/xhal/common/rpc/helper.h @@ -9,13 +9,16 @@ * \author Laurent Pétré */ -#ifndef XHAL_RPC_HELPER_H -#define XHAL_RPC_HELPER_H +#ifndef XHAL_COMMON_RPC_HELPER_H +#define XHAL_COMMON_RPC_HELPER_H #include #include -namespace xhal { namespace rpc { namespace helper { +namespace xhal { + namespace common { + namespace rpc { + namespace helper { /*! * \brief Allows to extract types of a functor @@ -116,6 +119,9 @@ namespace xhal { namespace rpc { namespace helper { template using is_tuple = is_tuple_impl::type>; -} } } + } + } + } +} -#endif +#endif // XHAL_COMMON_RPC_HELPER_H diff --git a/xhal/include/xhal/common/rpc/register.h b/xhal/include/xhal/common/rpc/register.h index a406139..056b653 100644 --- a/xhal/include/xhal/common/rpc/register.h +++ b/xhal/include/xhal/common/rpc/register.h @@ -7,21 +7,22 @@ * \author Louis Moureaux */ -#ifndef XHAL_RPC_REGISTER_H -#define XHAL_RPC_REGISTER_H +#ifndef XHAL_COMMON_RPC_REGISTER_H +#define XHAL_COMMON_RPC_REGISTER_H -#include "xhal/rpc/common.h" -#include "xhal/rpc/compat.h" -#include "xhal/rpc/exceptions.h" -#include "xhal/rpc/helper.h" +#include "xhal/common/rpc/common.h" +#include "xhal/common/rpc/compat.h" +#include "xhal/common/rpc/exceptions.h" +#include "xhal/common/rpc/helper.h" #include "moduleapi.h" // Only present in the CTP7 modules #include -namespace xhal { namespace rpc { - - namespace helper { +namespace xhal { + namespace common { + namespace rpc { + namespace helper { /** * \brief Handles an exception, setting the error key on the response. @@ -108,7 +109,8 @@ namespace xhal { namespace rpc { typeid(Method).name(), xhal::rpc::invoke); } + } + } +} -}} - -#endif +#endif // XHAL_COMMON_RPC_REGISTER_H diff --git a/xhal/src/common/rpc/exceptions.cpp b/xhal/src/common/rpc/exceptions.cpp index 88833ae..75df1a8 100644 --- a/xhal/src/common/rpc/exceptions.cpp +++ b/xhal/src/common/rpc/exceptions.cpp @@ -1,10 +1,13 @@ -#include "xhal/rpc/exceptions.h" +#include "xhal/common/rpc/exceptions.h" -#include "xhal/rpc/common.h" // abiVersion +#include "xhal/common/rpc/common.h" // abiVersion #include "cxxabi.h" // C++ Itanium ABI -namespace xhal { namespace rpc { namespace helper { +namespace xhal { + namespace common { + namespace rpc { + namespace helper { std::string getExceptionMessage(const std::exception &e) { @@ -64,4 +67,7 @@ namespace xhal { namespace rpc { namespace helper { return msg; } -}}} // namespace xhal::rpc::helper + } + } + } +} From aff3201cee71c8b33fc8887c0dff505fd0ef7636 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 20:14:26 +0200 Subject: [PATCH 33/56] [refactor] Adapt `common` for new structure --- xhal/include/xhal/common/utils/Exception.h | 66 +++---- xhal/include/xhal/common/utils/XHALXMLNode.h | 182 +++++++++--------- .../include/xhal/common/utils/XHALXMLParser.h | 180 ++++++++--------- xhal/src/common/utils/XHALXMLParser.cpp | 38 ++-- 4 files changed, 236 insertions(+), 230 deletions(-) diff --git a/xhal/include/xhal/common/utils/Exception.h b/xhal/include/xhal/common/utils/Exception.h index 5b7f0ae..9dc6fdd 100644 --- a/xhal/include/xhal/common/utils/Exception.h +++ b/xhal/include/xhal/common/utils/Exception.h @@ -6,43 +6,43 @@ * @version 1.0 */ -#ifndef XHAL_UTILS_EXCEPTION_H -#define XHAL_UTILS_EXCEPTION_H +#ifndef XHAL_COMMON_UTILS_EXCEPTION_H +#define XHAL_COMMON_UTILS_EXCEPTION_H #include #include #include -#define XHAL_UTILS_DEFINE_EXCEPTION(EXCEPTION_NAME) \ -namespace xhal { \ - namespace utils { \ - class EXCEPTION_NAME : public std::exception { \ - public: \ - EXCEPTION_NAME(std::string message) : msg(message) { \ - \ - } \ - \ - virtual ~EXCEPTION_NAME() { \ - \ - } \ - \ - virtual const char* what() const noexcept (true) override { \ - return msg.c_str(); \ - } \ - \ - std::string msg; \ - \ - private: \ - EXCEPTION_NAME(); \ - }; \ - } /* namespace xhal::utils */ \ -} /* namespace xhal */ +#define XHAL_COMMON_UTILS_DEFINE_EXCEPTION(EXCEPTION_NAME) \ +namespace xhal { \ + namespace common { \ + namespace utils { \ + class EXCEPTION_NAME : public std::exception { \ + public: \ + EXCEPTION_NAME(std::string message) : msg(message) { \ + \ + } \ + \ + virtual ~EXCEPTION_NAME() { \ + \ + } \ + \ + virtual const char* what() const noexcept (true) override { \ + return msg.c_str(); \ + } \ + \ + std::string msg; \ + \ + private: \ + EXCEPTION_NAME(); \ + }; \ + } \ + } \ +} +XHAL_COMMON_UTILS_DEFINE_EXCEPTION(XHALException) +XHAL_COMMON_UTILS_DEFINE_EXCEPTION(XHALXMLParserException) +XHAL_COMMON_UTILS_DEFINE_EXCEPTION(XHALRPCException) +XHAL_COMMON_UTILS_DEFINE_EXCEPTION(XHALRPCNotConnectedException) - -XHAL_UTILS_DEFINE_EXCEPTION(XHALException) -XHAL_UTILS_DEFINE_EXCEPTION(XHALXMLParserException) -XHAL_UTILS_DEFINE_EXCEPTION(XHALRPCException) -XHAL_UTILS_DEFINE_EXCEPTION(XHALRPCNotConnectedException) - -#endif //XHAL_UTILS_EXCEPTION_H +#endif // XHAL_COMMON_UTILS_EXCEPTION_H diff --git a/xhal/include/xhal/common/utils/XHALXMLNode.h b/xhal/include/xhal/common/utils/XHALXMLNode.h index c026828..967ecce 100644 --- a/xhal/include/xhal/common/utils/XHALXMLNode.h +++ b/xhal/include/xhal/common/utils/XHALXMLNode.h @@ -6,102 +6,106 @@ * @version 1.0 */ -#ifndef XHAL_UTILS_NODE_H -#define XHAL_UTILS_NODE_H +#ifndef XHAL_COMMON_UTILS_NODE_H +#define XHAL_COMMON_UTILS_NODE_H + #include #include namespace xhal { - namespace utils { - /** - * @class Node - * @brief stores single XML node with its attributes - * - * Note that all the class members are public in order to avoid extra ambiguitization of the code with getters and setters - */ - class Node - { - public: - /** - * @brief Default constructor. Creates empty Node. - */ - Node() - { - name=""; - description=""; - vhdlname = ""; - address = 0x0; - real_address = 0x0; - permission = ""; - mode = "single"; - size = 1; - mask = 0xFFFFFFFF; - isModule = false; - parent = nullptr; - level = 0; - warn_min_value = -1; - error_min_value = -1; - } - ~Node(){} - /** - * @brief Adds child node - */ - void addChild(Node child) {children.push_back(child);} - /** - * @brief Returns VHDL node name - */ - std::string getVhdlName(){return vhdlname;} - /** - * @brief Not implemented - */ - void output() - { - //!TODO - //print 'Name:',self.name - //print 'Description:',self.description - //print 'Address:','{0:#010x}'.format(self.address) - //print 'Permission:',self.permission - //print 'Mode:',self.mode - //print 'Size:',self.size - //print 'Mask:','{0:#010x}'.format(self.mask) - //print 'Module:',self.isModule - //print 'Parent:',self.parent.name - } - - /** - * @brief Returns all hierarchy of chlid nodes - * @param node parent node - * @param kids vector of nodes, must be empty when function called and will be updated with node childrem - */ - void getAllChildren(Node node, std::vector kids) - { - if (node.children.empty()) + namespace common { + namespace utils { + /** + * @class Node + * @brief stores single XML node with its attributes + * + * Note that all the class members are public in order to avoid extra ambiguitization of the code with getters and setters + */ + class Node + { + public: + /** + * @brief Default constructor. Creates empty Node. + */ + Node() + { + name=""; + description=""; + vhdlname = ""; + address = 0x0; + real_address = 0x0; + permission = ""; + mode = "single"; + size = 1; + mask = 0xFFFFFFFF; + isModule = false; + parent = nullptr; + level = 0; + warn_min_value = -1; + error_min_value = -1; + } + ~Node(){} + /** + * @brief Adds child node + */ + void addChild(Node child) {children.push_back(child);} + /** + * @brief Returns VHDL node name + */ + std::string getVhdlName(){return vhdlname;} + /** + * @brief Not implemented + */ + void output() { - kids.push_back(node); - } else { - for (auto const& child: node.children) + //!TODO + //print 'Name:',self.name + //print 'Description:',self.description + //print 'Address:','{0:#010x}'.format(self.address) + //print 'Permission:',self.permission + //print 'Mode:',self.mode + //print 'Size:',self.size + //print 'Mask:','{0:#010x}'.format(self.mask) + //print 'Module:',self.isModule + //print 'Parent:',self.parent.name + } + + /** + * @brief Returns all hierarchy of chlid nodes + * @param node parent node + * @param kids vector of nodes, must be empty when function called and will be updated with node childrem + */ + void getAllChildren(Node node, std::vector kids) + { + if (node.children.empty()) { - getAllChildren(child, kids); + kids.push_back(node); + } else { + for (auto const& child: node.children) + { + getAllChildren(child, kids); + } } } - } - - std::string name; - std::string description; - std::string vhdlname; - uint32_t address; - uint32_t real_address; - std::string permission; - std::string mode; - uint32_t size; - uint32_t mask; - bool isModule; - Node *parent; - std::vector children; - int level; - int warn_min_value; - int error_min_value; - }; + + std::string name; + std::string description; + std::string vhdlname; + uint32_t address; + uint32_t real_address; + std::string permission; + std::string mode; + uint32_t size; + uint32_t mask; + bool isModule; + Node *parent; + std::vector children; + int level; + int warn_min_value; + int error_min_value; + }; + } } } -#endif + +#endif // XHAL_COMMON_UTILS_NODE_H diff --git a/xhal/include/xhal/common/utils/XHALXMLParser.h b/xhal/include/xhal/common/utils/XHALXMLParser.h index feddf5d..53a059e 100644 --- a/xhal/include/xhal/common/utils/XHALXMLParser.h +++ b/xhal/include/xhal/common/utils/XHALXMLParser.h @@ -8,8 +8,8 @@ -#ifndef XHALXMLPARSER_H -#define XHALXMLPARSER_H +#ifndef XHAL_COMMON_UTILS_XHALXMLPARSER_H +#define XHAL_COMMON_UTILS_XHALXMLPARSER_H #include #include @@ -48,97 +48,99 @@ #define XHAL_ERROR(MSG) LOG4CPLUS_ERROR(m_logger, MSG) #define XHAL_FATAL(MSG) LOG4CPLUS_FATAL(m_logger, MSG) -#include "xhal/utils/XHALXMLNode.h" -#include "xhal/utils/Exception.h" +#include "xhal/common/utils/XHALXMLNode.h" +#include "xhal/common/utils/Exception.h" namespace xhal { - namespace utils { - /** - * @class XHALXMLParser - * @brief provide parsing interface and search through flattened node tree - */ - class XHALXMLParser - { - public: - /** - * @brief Default constructor - * @param xmlFile address table file name - */ - XHALXMLParser(const std::string& xmlFile); + namespace common { + namespace utils { + /** + * @class XHALXMLParser + * @brief provide parsing interface and search through flattened node tree + */ + class XHALXMLParser + { + public: + /** + * @brief Default constructor + * @param xmlFile address table file name + */ + XHALXMLParser(const std::string& xmlFile); + + ~XHALXMLParser(); + + /** + * @brief sets amount of logging/debugging information to display + * @param loglevel: + * 0 - ERROR + * 1 - WARN + * 2 - INFO + * 3 - DEBUG + * 4 - TRACE + */ + void setLogLevel(int loglevel); + /** + * @brief parses XML file and creates flattened nodes tree + */ + void parseXML(); + /** + * @brief returns node object by its name or nothing if name is not found + */ + #ifdef __ARM_ARCH_7A__ + std::experimental::optional getNode(const char* nodeName); + #else + boost::optional getNode(const char* nodeName); + #endif + /** + * @brief not implemented + */ + #ifdef __ARM_ARCH_7A__ + std::experimental::optional getNodeFromAddress(const uint32_t nodeAddress); + #else + boost::optional getNodeFromAddress(const uint32_t nodeAddress); + #endif + /** + * @brief return all nodes + */ + std::unordered_map getAllNodes(); - ~XHALXMLParser(); + private: + std::string m_xmlFile; + log4cplus::Logger m_logger; + std::unordered_map m_vars; + std::unordered_map* m_nodes; + xercesc::DOMNode* m_root; + xercesc::DOMNode* m_node; + xercesc::DOMNodeList* children; + static int index; - /** - * @brief sets amount of logging/debugging information to display - * @param loglevel: - * 0 - ERROR - * 1 - WARN - * 2 - INFO - * 3 - DEBUG - * 4 - TRACE - */ - void setLogLevel(int loglevel); - /** - * @brief parses XML file and creates flattened nodes tree - */ - void parseXML(); - /** - * @brief returns node object by its name or nothing if name is not found - */ -#ifdef __ARM_ARCH_7A__ - std::experimental::optional getNode(const char* nodeName); -#else - boost::optional getNode(const char* nodeName); -#endif - /** - * @brief not implemented - */ -#ifdef __ARM_ARCH_7A__ - std::experimental::optional getNodeFromAddress(const uint32_t nodeAddress); -#else - boost::optional getNodeFromAddress(const uint32_t nodeAddress); -#endif - /** - * @brief return all nodes - */ - std::unordered_map getAllNodes(); - - private: - std::string m_xmlFile; - log4cplus::Logger m_logger; - std::unordered_map m_vars; - std::unordered_map* m_nodes; - xercesc::DOMNode* m_root; - xercesc::DOMNode* m_node; - xercesc::DOMNodeList* children; - static int index; - - /** - * @brief fills custom node object - */ - void makeTree(xercesc::DOMNode * node, std::string basename, uint32_t baseAddress, std::unordered_map * nodes, xhal::utils::Node * parentNode, std::unordered_map vars, bool isGenerated); - /** - * @brief returns node attribute value by its name if found - */ -#ifdef __ARM_ARCH_7A__ - std::experimental::optional getAttVal(xercesc::DOMNode * t_node, const char * attname); -#else - boost::optional getAttVal(xercesc::DOMNode * t_node, const char * attname); -#endif - /** - * @brief converts string representation of hex, binary or decimal number to an integer - */ - unsigned int parseInt(std::string & s); - /** - * @brief returns cleaned from automatic generation symbols node name - */ - std::string substituteVars(std::string & s, std::unordered_map dict); - /** - * @brief returns a copy of original string with all occurences of first substring replaced with second substring - */ - std::string replaceAll( std::string const& original, std::string const& from, std::string const& to ); - }; + /** + * @brief fills custom node object + */ + void makeTree(xercesc::DOMNode * node, std::string basename, uint32_t baseAddress, std::unordered_map * nodes, xhal::common::utils::Node * parentNode, std::unordered_map vars, bool isGenerated); + /** + * @brief returns node attribute value by its name if found + */ + #ifdef __ARM_ARCH_7A__ + std::experimental::optional getAttVal(xercesc::DOMNode * t_node, const char * attname); + #else + boost::optional getAttVal(xercesc::DOMNode * t_node, const char * attname); + #endif + /** + * @brief converts string representation of hex, binary or decimal number to an integer + */ + unsigned int parseInt(std::string & s); + /** + * @brief returns cleaned from automatic generation symbols node name + */ + std::string substituteVars(std::string & s, std::unordered_map dict); + /** + * @brief returns a copy of original string with all occurences of first substring replaced with second substring + */ + std::string replaceAll( std::string const& original, std::string const& from, std::string const& to ); + }; + } } } -#endif // XHALXMLPARSER_H +#endif // XHAL_COMMON_UTILS_XHALXMLPARSER_H diff --git a/xhal/src/common/utils/XHALXMLParser.cpp b/xhal/src/common/utils/XHALXMLParser.cpp index 5ab5c35..8f4d845 100644 --- a/xhal/src/common/utils/XHALXMLParser.cpp +++ b/xhal/src/common/utils/XHALXMLParser.cpp @@ -1,10 +1,10 @@ -#include "xhal/utils/XHALXMLParser.h" +#include "xhal/common/utils/XHALXMLParser.h" #include -int xhal::utils::XHALXMLParser::index = 0; +int xhal::common::utils::XHALXMLParser::index = 0; -xhal::utils::XHALXMLParser::XHALXMLParser(const std::string& xmlFile) +xhal::common::utils::XHALXMLParser::XHALXMLParser(const std::string& xmlFile) { m_xmlFile = xmlFile; log4cplus::SharedAppenderPtr myAppender(new log4cplus::ConsoleAppender()); @@ -21,13 +21,13 @@ xhal::utils::XHALXMLParser::XHALXMLParser(const std::string& xmlFile) m_nodes = new std::unordered_map(); } -xhal::utils::XHALXMLParser::~XHALXMLParser() +xhal::common::utils::XHALXMLParser::~XHALXMLParser() { if (m_nodes) delete m_nodes; m_logger.shutdown(); } -void xhal::utils::XHALXMLParser::setLogLevel(int loglevel) +void xhal::common::utils::XHALXMLParser::setLogLevel(int loglevel) { switch(loglevel) { @@ -49,7 +49,7 @@ void xhal::utils::XHALXMLParser::setLogLevel(int loglevel) } } -void xhal::utils::XHALXMLParser::parseXML() +void xhal::common::utils::XHALXMLParser::parseXML() { // /// Initialize XML4C system @@ -60,7 +60,7 @@ void xhal::utils::XHALXMLParser::parseXML() XHAL_ERROR("Error during Xerces-c Initialization." << std::endl << " Exception message:" << xercesc::XMLString::transcode(toCatch.getMessage())); - throw xhal::utils::XHALXMLParserException("XHALParser: initialization failed"); + throw xhal::common::utils::XHALXMLParserException("XHALParser: initialization failed"); return; } @@ -129,14 +129,14 @@ void xhal::utils::XHALXMLParser::parseXML() makeTree(m_root,"",0x0,m_nodes,NULL,m_vars,false); XHAL_DEBUG("Number of nodes: " << m_nodes->size()); } else{ - throw xhal::utils::XHALXMLParserException("XHALParser: an error occured during parsing"); + throw xhal::common::utils::XHALXMLParserException("XHALParser: an error occured during parsing"); } XHAL_DEBUG("Parsing done!"); if (parser) parser->release(); xercesc::XMLPlatformUtils::Terminate(); } -void xhal::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std::string baseName, uint32_t baseAddress, std::unordered_map * nodes, Node * parentNode, std::unordered_map vars, bool isGenerated) +void xhal::common::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std::string baseName, uint32_t baseAddress, std::unordered_map * nodes, Node * parentNode, std::unordered_map vars, bool isGenerated) { XHAL_DEBUG("Call makeTree"); unsigned int generateSize; @@ -245,9 +245,9 @@ void xhal::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std::string b } #ifdef __ARM_ARCH_7A__ -std::experimental::optional xhal::utils::XHALXMLParser::getAttVal(xercesc::DOMNode * t_node_, const char * attname) +std::experimental::optional xhal::common::utils::XHALXMLParser::getAttVal(xercesc::DOMNode * t_node_, const char * attname) #else -boost::optional xhal::utils::XHALXMLParser::getAttVal(xercesc::DOMNode * t_node_, const char * attname) +boost::optional xhal::common::utils::XHALXMLParser::getAttVal(xercesc::DOMNode * t_node_, const char * attname) #endif { XHAL_TRACE("Call getAttVal for attribute " << attname); @@ -273,7 +273,7 @@ boost::optional xhal::utils::XHALXMLParser::getAttVal(xercesc::DOMN } } -unsigned int xhal::utils::XHALXMLParser::parseInt(std::string & s) +unsigned int xhal::common::utils::XHALXMLParser::parseInt(std::string & s) { XHAL_TRACE("Call parseInt for argument " << s); std::stringstream converter(s); @@ -292,7 +292,7 @@ unsigned int xhal::utils::XHALXMLParser::parseInt(std::string & s) } } -std::string xhal::utils::XHALXMLParser::substituteVars(std::string & s, std::unordered_map dict) +std::string xhal::common::utils::XHALXMLParser::substituteVars(std::string & s, std::unordered_map dict) { if (s == "") {return s;} std::string ret; @@ -304,7 +304,7 @@ std::string xhal::utils::XHALXMLParser::substituteVars(std::string & s, std::uno return ret; } -std::string xhal::utils::XHALXMLParser::replaceAll( std::string const& original, std::string const& from, std::string const& to ) +std::string xhal::common::utils::XHALXMLParser::replaceAll( std::string const& original, std::string const& from, std::string const& to ) { std::string results; std::string::const_iterator end = original.end(); @@ -321,9 +321,9 @@ std::string xhal::utils::XHALXMLParser::replaceAll( std::string const& original, } #ifdef __ARM_ARCH_7A__ -std::experimental::optional xhal::utils::XHALXMLParser::getNode(const char* nodeName) +std::experimental::optional xhal::common::utils::XHALXMLParser::getNode(const char* nodeName) #else -boost::optional xhal::utils::XHALXMLParser::getNode(const char* nodeName) +boost::optional xhal::common::utils::XHALXMLParser::getNode(const char* nodeName) #endif { XHAL_DEBUG("Call getNode for argument " << nodeName); @@ -340,9 +340,9 @@ boost::optional xhal::utils::XHALXMLParser::getNode(const cha // Not used a.t.m. Do we need it? FIXME #ifdef __ARM_ARCH_7A__ -std::experimental::optional xhal::utils::XHALXMLParser::getNodeFromAddress(const uint32_t nodeAddress) +std::experimental::optional xhal::common::utils::XHALXMLParser::getNodeFromAddress(const uint32_t nodeAddress) #else -boost::optional xhal::utils::XHALXMLParser::getNodeFromAddress(const uint32_t nodeAddress) +boost::optional xhal::common::utils::XHALXMLParser::getNodeFromAddress(const uint32_t nodeAddress) #endif { //Node * res = NULL; @@ -363,7 +363,7 @@ boost::optional xhal::utils::XHALXMLParser::getNodeFromAddres } -std::unordered_map xhal::utils::XHALXMLParser::getAllNodes() +std::unordered_map xhal::common::utils::XHALXMLParser::getAllNodes() { return *m_nodes; } From d9a128cc217d009f36e75b6c6475a9edb75c384c Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 20:15:25 +0200 Subject: [PATCH 34/56] [refactor] Adapt `server` for new structure --- xhal/include/xhal/server/LMDB.h | 8 +++++--- xhal/src/server/LMDB.cpp | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/xhal/include/xhal/server/LMDB.h b/xhal/include/xhal/server/LMDB.h index 475441f..57e0f77 100644 --- a/xhal/include/xhal/server/LMDB.h +++ b/xhal/include/xhal/server/LMDB.h @@ -5,12 +5,13 @@ * \author Louis Moureaux */ -#ifndef XHAL_LMDB_H -#define XHAL_LMDB_H +#ifndef XHAL_SERVER_LMDB_H +#define XHAL_SERVER_LMDB_H #include namespace xhal { + namespace server { /** * \brief Provides access to shared LMDB data structures. @@ -96,6 +97,7 @@ namespace xhal { const lmdb::txn &rtxn() const noexcept; }; + } // namespace xhal::server } // namespace xhal -#endif // XHAL_LMDB_H +#endif // XHAL_SERVER_LMDBXS_H diff --git a/xhal/src/server/LMDB.cpp b/xhal/src/server/LMDB.cpp index f8bec7d..6168ae1 100644 --- a/xhal/src/server/LMDB.cpp +++ b/xhal/src/server/LMDB.cpp @@ -1,4 +1,4 @@ -#include "xhal/LMDB.h" +#include "xhal/server/LMDB.h" #include #include @@ -7,6 +7,7 @@ #define DB_NAME "/address_table.mdb" namespace xhal { + namespace server { namespace /* anonymous */ { /// \brief Maximum size of the LMDB object, currently 50 MiB; static const std::size_t MAP_SIZE = 50UL * 1024UL * 1024UL; @@ -116,5 +117,5 @@ namespace xhal { { return SINGLETON->rtxn; } - + } // namespace xhal::server } // namespace xhal From 151976291fb11763e1f2c90489cdab87a1879300 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 20:15:57 +0200 Subject: [PATCH 35/56] [refactor] Adapt `client` interfaces for new structure --- xhal/include/xhal/client/XHALDevice.h | 138 +++++++++++----------- xhal/include/xhal/client/XHALInterface.h | 141 ++++++++++++----------- xhal/src/client/XHALDevice.cpp | 34 +++--- xhal/src/client/XHALInterface.cpp | 30 ++--- 4 files changed, 174 insertions(+), 169 deletions(-) diff --git a/xhal/include/xhal/client/XHALDevice.h b/xhal/include/xhal/client/XHALDevice.h index c33af81..805d178 100644 --- a/xhal/include/xhal/client/XHALDevice.h +++ b/xhal/include/xhal/client/XHALDevice.h @@ -6,77 +6,79 @@ * @version 1.0 */ -#ifndef XHALDEVICE_H -#define XHALDEVICE_H +#ifndef XHAL_CLIENT_XHALDEVICE_H +#define XHAL_CLIENT_XHALDEVICE_H -#include "xhal/utils/XHALXMLParser.h" -#include "xhal/XHALInterface.h" +#include "xhal/common/utils/XHALXMLParser.h" +#include "xhal/client/XHALInterface.h" #include namespace xhal { - /** - * @class XHALDevice - * @brief provide interface to call remote procedures at Zynq CPU and basic FW registers manipulation - */ - class XHALDevice : public XHALInterface - { - public: - /** - * @brief Default constructor - * - * Parses XML file - * @param board_domain_name domain name of CTP7 - * @param address_table_filename XML address table file name - */ - XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename); - virtual ~XHALDevice(){} - - /** - * @brief Reconnect to RPC service and reload required modules - */ - virtual void reconnect(); - - /** - * @brief read FW register by its name - * applies reading mask if any - */ - uint32_t readReg(std::string regName); - /** - * @brief read FW register by its address - * reg mask is ignored!! - */ - uint32_t readReg(uint32_t address); - /** - * @brief write FW register by its name - * applies read/write mask if any - */ - void writeReg(std::string regName, uint32_t value); - //void writeReg(uint32_t address, uint32_t value); - - /** - * @brief Read list of FW registers by their addresses - * FIXME reg mask is ignored?? - * - * @param addresses An array of register addresses - * @param result An array of register values - * @param size Size of the above arrays - */ - uint32_t getList(uint32_t* addresses, uint32_t* result, ssize_t size); - - /** - * @brief Read block of 32-bit registers starting from a given address - * - * @param address Starting address - * @param result An array of register values - * @param size Size of the above array - */ - uint32_t getBlock(uint32_t address, uint32_t* result, ssize_t size); - - private: - std::string m_address_table_filename; - xhal::utils::XHALXMLParser * m_parser; - xhal::utils::Node m_node; - }; + namespace client { + /** + * @class XHALDevice + * @brief provide interface to call remote procedures at Zynq CPU and basic FW registers manipulation + */ + class XHALDevice : public XHALInterface + { + public: + /** + * @brief Default constructor + * + * Parses XML file + * @param board_domain_name domain name of CTP7 + * @param address_table_filename XML address table file name + */ + XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename); + virtual ~XHALDevice(){} + + /** + * @brief Reconnect to RPC service and reload required modules + */ + virtual void reconnect(); + + /** + * @brief read FW register by its name + * applies reading mask if any + */ + uint32_t readReg(std::string regName); + /** + * @brief read FW register by its address + * reg mask is ignored!! + */ + uint32_t readReg(uint32_t address); + /** + * @brief write FW register by its name + * applies read/write mask if any + */ + void writeReg(std::string regName, uint32_t value); + //void writeReg(uint32_t address, uint32_t value); + + /** + * @brief Read list of FW registers by their addresses + * FIXME reg mask is ignored?? + * + * @param addresses An array of register addresses + * @param result An array of register values + * @param size Size of the above arrays + */ + uint32_t getList(uint32_t* addresses, uint32_t* result, ssize_t size); + + /** + * @brief Read block of 32-bit registers starting from a given address + * + * @param address Starting address + * @param result An array of register values + * @param size Size of the above array + */ + uint32_t getBlock(uint32_t address, uint32_t* result, ssize_t size); + + private: + std::string m_address_table_filename; + xhal::common::utils::XHALXMLParser * m_parser; + xhal::common::utils::Node m_node; + }; + } } -#endif // XHALDEVICE_H +#endif // XHAL_CLIENT_XHALDEVICE_H diff --git a/xhal/include/xhal/client/XHALInterface.h b/xhal/include/xhal/client/XHALInterface.h index d14646d..c2d6324 100644 --- a/xhal/include/xhal/client/XHALInterface.h +++ b/xhal/include/xhal/client/XHALInterface.h @@ -6,13 +6,13 @@ * @version 1.0 */ -#ifndef XHALINTERFACE_H -#define XHALINTERFACE_H +#ifndef XHAL_CLIENT_XHALINTERFACE_H +#define XHAL_CLIENT_XHALINTERFACE_H #include #include -#include "xhal/rpc/wiscrpcsvc.h" -#include "xhal/utils/Exception.h" +#include "xhal/extern/wiscrpcsvc.h" +#include "xhal/common/utils/Exception.h" #include "log4cplus/logger.h" #include "log4cplus/loglevel.h" @@ -29,87 +29,90 @@ #define STANDARD_CATCH \ catch (wisc::RPCSvc::NotConnectedException &e) { \ XHAL_ERROR("Caught NotConnectedException: " << e.message.c_str()); \ - throw xhal::utils::XHALRPCNotConnectedException("RPC NotConnectedException: " + e.message);\ + throw xhal::common::utils::XHALRPCNotConnectedException("RPC NotConnectedException: " + e.message);\ } \ catch (wisc::RPCSvc::RPCErrorException &e) { \ XHAL_ERROR("Caught RPCErrorException: " << e.message.c_str()); \ - throw xhal::utils::XHALRPCException("RPC ErrorException: " + e.message);\ + throw xhal::common::utils::XHALRPCException("RPC ErrorException: " + e.message);\ } \ catch (wisc::RPCSvc::RPCException &e) { \ XHAL_ERROR("Caught exception: " << e.message.c_str()); \ - throw xhal::utils::XHALRPCException("RPC exception: " + e.message);\ + throw xhal::common::utils::XHALRPCException("RPC exception: " + e.message);\ } \ catch (wisc::RPCMsg::BadKeyException &e) { \ XHAL_ERROR("Caught exception: " << e.key.c_str()); \ - throw xhal::utils::XHALRPCException("RPC BadKeyException (most probably remote register not accessible): " + e.key);\ + throw xhal::common::utils::XHALRPCException("RPC BadKeyException (most probably remote register not accessible): " + e.key);\ } #define ASSERT(x) do { \ if (!(x)) { \ printf("Assertion Failed on line %u: %s\n", __LINE__, #x); \ - throw xhal::utils::XHALException("ASSERT failure");\ + throw xhal::common::utils::XHALException("ASSERT failure");\ } \ } while (0) namespace xhal { - /** - * @class XHALInterface - * @brief Provides interface to call remote procedures at Zynq CPU - */ - class XHALInterface - { - public: - /** - * @brief Default constructor - * @param board_domain_name domain name of CTP7 - */ - XHALInterface(const std::string& board_domain_name); - /** - * @brief Constructor, taking also the external logger - * @param board_domain_name domain name of CTP7 - */ - XHALInterface(const std::string& board_domain_name, log4cplus::Logger& logger); - - virtual ~XHALInterface(); - - /** - * @brief Initialize interface and establish RPC service connection with CTP7 - */ - void connect(); - - /** - * @brief Reconnect to RPC service and reload required modules - */ - virtual void reconnect(); - - /** - * @brief Initialize interface and establish RPC service connection with CTP7 - */ - void disconnect(); - - /** - * @brief load remote module - */ - void loadModule(const std::string& module_name, const std::string& module_version); - - /** - * @brief sets amount of logging/debugging information to display - * @param loglevel: - * 0 - ERROR - * 1 - WARN - * 2 - INFO - * 3 - DEBUG - * 4 - TRACE - */ - void setLogLevel(int loglevel); - - protected: - std::string m_board_domain_name; - log4cplus::Logger m_logger; - wisc::RPCSvc rpc; - wisc::RPCMsg req, rsp; - bool isConnected; - static int index; - }; + namespace client { + /** + * @class XHALInterface + * @brief Provides interface to call remote procedures at Zynq CPU + */ + class XHALInterface + { + public: + /** + * @brief Default constructor + * @param board_domain_name domain name of CTP7 + */ + XHALInterface(const std::string& board_domain_name); + /** + * @brief Constructor, taking also the external logger + * @param board_domain_name domain name of CTP7 + */ + XHALInterface(const std::string& board_domain_name, log4cplus::Logger& logger); + + virtual ~XHALInterface(); + + /** + * @brief Initialize interface and establish RPC service connection with CTP7 + */ + void connect(); + + /** + * @brief Reconnect to RPC service and reload required modules + */ + virtual void reconnect(); + + /** + * @brief Initialize interface and establish RPC service connection with CTP7 + */ + void disconnect(); + + /** + * @brief load remote module + */ + void loadModule(const std::string& module_name, const std::string& module_version); + + /** + * @brief sets amount of logging/debugging information to display + * @param loglevel: + * 0 - ERROR + * 1 - WARN + * 2 - INFO + * 3 - DEBUG + * 4 - TRACE + */ + void setLogLevel(int loglevel); + + protected: + std::string m_board_domain_name; + log4cplus::Logger m_logger; + wisc::RPCSvc rpc; + wisc::RPCMsg req, rsp; + bool isConnected; + static int index; + }; + } } -#endif // XHALINTERFACE_H + +#endif // XHAL_CLIENT_XHALINTERFACE_H diff --git a/xhal/src/client/XHALDevice.cpp b/xhal/src/client/XHALDevice.cpp index 1d87bc9..0c41e83 100644 --- a/xhal/src/client/XHALDevice.cpp +++ b/xhal/src/client/XHALDevice.cpp @@ -1,12 +1,12 @@ -#include "xhal/XHALDevice.h" +#include "xhal/client/XHALDevice.h" -xhal::XHALDevice::XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename): - xhal::XHALInterface(board_domain_name), +xhal::client::XHALDevice::XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename): + xhal::client::XHALInterface(board_domain_name), m_address_table_filename(address_table_filename) { //FIXME Implement try-catch XHAL_DEBUG("Address table name " << m_address_table_filename); - m_parser = new xhal::utils::XHALXMLParser(m_address_table_filename); + m_parser = new xhal::common::utils::XHALXMLParser(m_address_table_filename); XHAL_DEBUG("XHALXML parser created"); m_parser->setLogLevel(2); m_parser->parseXML(); @@ -14,7 +14,7 @@ xhal::XHALDevice::XHALDevice(const std::string& board_domain_name, const std::st this->loadModule("extras","extras v1.0.1"); } -void xhal::XHALDevice::reconnect() +void xhal::client::XHALDevice::reconnect() { if (!isConnected){ this->connect(); @@ -22,11 +22,11 @@ void xhal::XHALDevice::reconnect() this->loadModule("extras","extras v1.0.1"); } else { XHAL_ERROR("Interface already connected. Reconnection failed"); - throw xhal::utils::XHALRPCException("RPC exception: Interface already connected. Reconnection failed"); + throw xhal::common::utils::XHALRPCException("RPC exception: Interface already connected. Reconnection failed"); } } -uint32_t xhal::XHALDevice::readReg(std::string regName) +uint32_t xhal::client::XHALDevice::readReg(std::string regName) { if (auto t_node = m_parser->getNode(regName.c_str())) { @@ -42,7 +42,7 @@ uint32_t xhal::XHALDevice::readReg(std::string regName) if (rsp.get_key_exists("error")) { XHAL_ERROR("RPC response returned error, readReg failed"); - throw xhal::utils::XHALException("Error during register access"); + throw xhal::common::utils::XHALException("Error during register access"); } else { try{ ASSERT(rsp.get_word_array_size("data") == 1); @@ -68,12 +68,12 @@ uint32_t xhal::XHALDevice::readReg(std::string regName) return result; } else { XHAL_ERROR("Register not found in address table!"); - throw xhal::utils::XHALXMLParserException(strcat("XHAL XML exception: can't find node", regName.c_str())); + throw xhal::common::utils::XHALXMLParserException(strcat("XHAL XML exception: can't find node", regName.c_str())); } } // In current shape implements raw address reading... Should the signature be update? FIXME -uint32_t xhal::XHALDevice::readReg(uint32_t address) +uint32_t xhal::client::XHALDevice::readReg(uint32_t address) { req = wisc::RPCMsg("memory.read"); req.set_word("address", address); @@ -86,7 +86,7 @@ uint32_t xhal::XHALDevice::readReg(uint32_t address) if (rsp.get_key_exists("error")) { XHAL_ERROR("RPC response returned error, readReg failed"); - throw xhal::utils::XHALException("Error during register access"); + throw xhal::common::utils::XHALException("Error during register access"); } else { try{ ASSERT(rsp.get_word_array_size("data") == 1); @@ -108,7 +108,7 @@ uint32_t xhal::XHALDevice::readReg(uint32_t address) return result; } -void xhal::XHALDevice::writeReg(std::string regName, uint32_t value) +void xhal::client::XHALDevice::writeReg(std::string regName, uint32_t value) { if (auto t_node = m_parser->getNode(regName.c_str())) { @@ -126,7 +126,7 @@ void xhal::XHALDevice::writeReg(std::string regName, uint32_t value) if (rsp.get_key_exists("error")) { XHAL_ERROR("RPC response returned error, writeReg failed"); - throw xhal::utils::XHALException("Error during register access"); + throw xhal::common::utils::XHALException("Error during register access"); } } else { uint32_t current_val = this->readReg(m_node.real_address); @@ -154,16 +154,16 @@ void xhal::XHALDevice::writeReg(std::string regName, uint32_t value) if (rsp.get_key_exists("error")) { XHAL_ERROR("RPC response returned error, writeReg failed"); - throw xhal::utils::XHALException("Error during register access"); + throw xhal::common::utils::XHALException("Error during register access"); } } } else { XHAL_ERROR("Register not found in address table!"); - throw xhal::utils::XHALXMLParserException(strcat("XHAL XML exception: can't find node", regName.c_str())); + throw xhal::common::utils::XHALXMLParserException(strcat("XHAL XML exception: can't find node", regName.c_str())); } } -uint32_t xhal::XHALDevice::getList(uint32_t* addresses, uint32_t* result, ssize_t size) +uint32_t xhal::client::XHALDevice::getList(uint32_t* addresses, uint32_t* result, ssize_t size) { req = wisc::RPCMsg("extras.listread"); req.set_word_array("addresses", addresses,size); @@ -185,7 +185,7 @@ uint32_t xhal::XHALDevice::getList(uint32_t* addresses, uint32_t* result, ssize_ return 0; } -uint32_t xhal::XHALDevice::getBlock(uint32_t address, uint32_t* result, ssize_t size) +uint32_t xhal::client::XHALDevice::getBlock(uint32_t address, uint32_t* result, ssize_t size) { req = wisc::RPCMsg("extras.blockread"); req.set_word("address", address); diff --git a/xhal/src/client/XHALInterface.cpp b/xhal/src/client/XHALInterface.cpp index bddfaf9..28e3506 100644 --- a/xhal/src/client/XHALInterface.cpp +++ b/xhal/src/client/XHALInterface.cpp @@ -1,10 +1,10 @@ -#include "xhal/XHALInterface.h" +#include "xhal/client/XHALInterface.h" #include -int xhal::XHALInterface::index = 0; +int xhal::client::XHALInterface::index = 0; -xhal::XHALInterface::XHALInterface(const std::string& board_domain_name): +xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name): m_board_domain_name(board_domain_name), isConnected(false) { @@ -26,12 +26,12 @@ xhal::XHALInterface::XHALInterface(const std::string& board_domain_name): this->connect(); XHAL_INFO("XHAL Interface connected"); } - catch (xhal::utils::XHALRPCException &e) { + catch (xhal::common::utils::XHALRPCException &e) { XHAL_INFO("XHAL Interface failed to connect"); } } -xhal::XHALInterface::XHALInterface(const std::string& board_domain_name, log4cplus::Logger& logger): +xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name, log4cplus::Logger& logger): m_board_domain_name(board_domain_name), m_logger(logger), isConnected(false) @@ -43,20 +43,20 @@ xhal::XHALInterface::XHALInterface(const std::string& board_domain_name, log4cpl this->connect(); XHAL_INFO("XHAL Interface connected"); } - catch (xhal::utils::XHALRPCException &e) { + catch (xhal::common::utils::XHALRPCException &e) { XHAL_INFO("XHAL Interface failed to connect"); isConnected = false; } } -xhal::XHALInterface::~XHALInterface() +xhal::client::XHALInterface::~XHALInterface() { XHAL_DEBUG("XHAL destructor called"); this->disconnect(); //m_logger.shutdown(); } -void xhal::XHALInterface::connect() +void xhal::client::XHALInterface::connect() { try { rpc.connect(m_board_domain_name); @@ -65,20 +65,20 @@ void xhal::XHALInterface::connect() } catch (wisc::RPCSvc::ConnectionFailedException &e) { XHAL_ERROR("Caught RPCErrorException: " << e.message.c_str()); - throw xhal::utils::XHALRPCException("RPC ConnectionFailedException: " + e.message); + throw xhal::common::utils::XHALRPCException("RPC ConnectionFailedException: " + e.message); } catch (wisc::RPCSvc::RPCException &e) { XHAL_ERROR("Caught exception: " << e.message.c_str()); - throw xhal::utils::XHALRPCException("RPC exception: " + e.message); + throw xhal::common::utils::XHALRPCException("RPC exception: " + e.message); } } -void xhal::XHALInterface::reconnect() +void xhal::client::XHALInterface::reconnect() { this->connect(); } -void xhal::XHALInterface::disconnect() +void xhal::client::XHALInterface::disconnect() { try { rpc.disconnect(); @@ -90,11 +90,11 @@ void xhal::XHALInterface::disconnect() } catch (wisc::RPCSvc::RPCException &e) { XHAL_ERROR("Caught exception: " << e.message.c_str()); - throw xhal::utils::XHALRPCException("RPC exception: " + e.message); + throw xhal::common::utils::XHALRPCException("RPC exception: " + e.message); } } -void xhal::XHALInterface::loadModule(const std::string& module_name, const std::string& module_version) +void xhal::client::XHALInterface::loadModule(const std::string& module_name, const std::string& module_version) { try { ASSERT(rpc.load_module(module_name, module_version)); @@ -102,7 +102,7 @@ void xhal::XHALInterface::loadModule(const std::string& module_name, const std:: STANDARD_CATCH; } -void xhal::XHALInterface::setLogLevel(int loglevel) +void xhal::client::XHALInterface::setLogLevel(int loglevel) { switch(loglevel) { From 26460ff499b38203d5d21ef7724ddb158a0d0a4f Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 20:17:57 +0200 Subject: [PATCH 36/56] [refactor] Adapt `client/rpcman` for new structure --- .../xhal/client/rpcman/calibration_routines.h | 208 +++++++++--------- xhal/include/xhal/client/rpcman/daq_monitor.h | 142 ++++++------ xhal/include/xhal/client/rpcman/optohybrid.h | 57 ++--- xhal/include/xhal/client/rpcman/utils.h | 50 +++-- xhal/include/xhal/client/rpcman/vfat3.h | 108 ++++----- .../rpc_manager/calibration_routines.cpp | 26 +-- xhal/src/client/rpc_manager/daq_monitor.cpp | 14 +- xhal/src/client/rpc_manager/optohybrid.cpp | 30 +-- xhal/src/client/rpc_manager/utils.cpp | 8 +- xhal/src/client/rpc_manager/vfat3.cpp | 14 +- 10 files changed, 334 insertions(+), 323 deletions(-) diff --git a/xhal/include/xhal/client/rpcman/calibration_routines.h b/xhal/include/xhal/client/rpcman/calibration_routines.h index 60d2d51..cb3a52c 100644 --- a/xhal/include/xhal/client/rpcman/calibration_routines.h +++ b/xhal/include/xhal/client/rpcman/calibration_routines.h @@ -1,108 +1,110 @@ -#ifndef CALIBRATION_ROUTINES_H -#define CALIBRATION_ROUTINES_H +#ifndef XHAL_CLIENT_RPCMAN_CALIBRATION_ROUTINES_H +#define XHAL_CLIENT_RPCMAN_CALIBRATION_ROUTINES_H -#include "xhal/XHALInterface.h" +#include "xhal/client/XHALInterface.h" namespace xhal { - namespace rpc { - /** - * @class CalRoutines - * @brief Provides interface to call remote utility methods - */ - class CalRoutines : public XHALInterface - { - public: - /** - * @brief Default constructor - * - * Loads the neccessary remote modules - * @param board_domain_name domain name of CTP7 - */ - CalRoutines(const std::string& board_domain_name):xhal::XHALInterface(board_domain_name){this->loadModule("calibration_routines", "calibration_routines v1.0.1");} - - ~CalRoutines(){} - - //FIXME Add documentation - uint32_t checkSbitMappingWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t nevts, uint32_t L1Ainterval, uint32_t pulseDelay, uint32_t *data); - - //FIXME Add documentation - uint32_t checkSbitRateWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t waitTime, uint32_t pulseRate, uint32_t pulseDelay, uint32_t *outDataCTP7Rate, uint32_t *outDataFPGAClusterCntRate, uint32_t *outDataVFATSBits); - - /** - * @brief Runs a generic scan routine for a specific channel of a VFAT chip - * - * @param nevts Number of events per scan point - * @param ohN Optical link - * @param dacMin Min value of scanned variable - * @param dacMax Max value of scanned variable - * @param dacStep Step parameter - * @param ch VFAT channel - * @param useCalPulse Indicates whether to use internal calibration pulses - * @param currentPulse Indicates whether to use current or voltage internal calibration pulse - * @param calScaleFactor FIXME - * @param mask FIXME - * @param scanReg Register to scan FIXME: add possible values - * @param useUltra Indicates whether to use FW-implemented ultraScan - * @param useExtTrig FIXME: do we need both this and useCalPulse? - * @param result An array carrying scan results - */ - uint32_t genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t mask, char * scanReg, bool useUltra, bool useExtTrig, uint32_t * result); - - /** - * @brief Runs a generic scan routine on all channels of a VFAT chip - * - * @param nevts Number of events per scan point - * @param ohN Optical link - * @param dacMin Min value of scanned variable - * @param dacMax Max value of scanned variable - * @param dacStep Step parameter - * @param useCalPulse Indicates whether to use internal calibration pulses - * @param currentPulse Indicates whether to use current or voltage internal calibration pulse - * @param calScaleFactor FIXME - * @param mask FIXME - * @param scanReg Register to scan FIXME: add possible values - * @param useUltra Indicates whether to use FW-implemented ultraScan - * @param useExtTrig FIXME: do we need both this and useCalPulse? - * @param result An array carrying scan results - */ - //FIXME Should we rearrange parameters so they are in the same order as in genScan? - uint32_t genChannelScan(uint32_t nevts, uint32_t ohN, uint32_t mask, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, bool useExtTrig, char * scanReg, bool useUltra, uint32_t * result); - - //FIXME Add documentation - uint32_t sbitRateScan(uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t maskOh, bool invertVFATPos, char * scanReg, uint32_t waitTime, uint32_t * resultDacVal, uint32_t * resultTrigRate, uint32_t * resultTrigRatePerVFAT, bool isParallel); - - /** - * @brief configure TTC generator - * - * v3 electronics Behavior: - * pulseDelay (only for enable = true), delay between CalPulse and L1A - * L1Ainterval (only for enable = true), how often to repeat signals - * enable = true (false) ignore (take) ttc commands from backplane for this AMC (affects all links) - * v2b electronics behavior: - * Configure the T1 controller - * mode: 0 (Single T1 signal), - * 1 (CalPulse followed by L1A), - * 2 (pattern) - * type (only for mode 0, type of T1 signal to send): - * 0 L1A - * 1 CalPulse - * 2 Resync - * 3 BC0 - * pulseDelay (only for mode 1), delay between CalPulse and L1A - * L1Ainterval (only for mode 0,1), how often to repeat signals - * nPulses how many signals to send (0 is continuous) - * enable = true (false) start (stop) the T1Controller for link ohN - */ - uint32_t ttcGenConf(uint32_t ohN, uint32_t mode, uint32_t type, uint32_t pulseDelay, uint32_t L1Ainterval, uint32_t nPulses, bool enable); - - /** - * @brief Toggles TTC behavior - * - * v3 electronics: enable = true (false) ignore (take) ttc commands from backplane for this AMC - * v2b electronics: enable = true (false) start (stop) the T1Controller for link ohN - */ - uint32_t ttcGenToggle(uint32_t ohN, bool enable); - }; + namespace client { + namespace rpcman { + /** + * @class CalRoutines + * @brief Provides interface to call remote utility methods + */ + class CalRoutines : public xhal::client::XHALInterface + { + public: + /** + * @brief Default constructor + * + * Loads the neccessary remote modules + * @param board_domain_name domain name of CTP7 + */ + CalRoutines(const std::string& board_domain_name):xhal::client::XHALInterface(board_domain_name){this->loadModule("calibration_routines", "calibration_routines v1.0.1");} + + ~CalRoutines(){} + + //FIXME Add documentation + uint32_t checkSbitMappingWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t nevts, uint32_t L1Ainterval, uint32_t pulseDelay, uint32_t *data); + + //FIXME Add documentation + uint32_t checkSbitRateWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t waitTime, uint32_t pulseRate, uint32_t pulseDelay, uint32_t *outDataCTP7Rate, uint32_t *outDataFPGAClusterCntRate, uint32_t *outDataVFATSBits); + + /** + * @brief Runs a generic scan routine for a specific channel of a VFAT chip + * + * @param nevts Number of events per scan point + * @param ohN Optical link + * @param dacMin Min value of scanned variable + * @param dacMax Max value of scanned variable + * @param dacStep Step parameter + * @param ch VFAT channel + * @param useCalPulse Indicates whether to use internal calibration pulses + * @param currentPulse Indicates whether to use current or voltage internal calibration pulse + * @param calScaleFactor FIXME + * @param mask FIXME + * @param scanReg Register to scan FIXME: add possible values + * @param useUltra Indicates whether to use FW-implemented ultraScan + * @param useExtTrig FIXME: do we need both this and useCalPulse? + * @param result An array carrying scan results + */ + uint32_t genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t mask, char * scanReg, bool useUltra, bool useExtTrig, uint32_t * result); + + /** + * @brief Runs a generic scan routine on all channels of a VFAT chip + * + * @param nevts Number of events per scan point + * @param ohN Optical link + * @param dacMin Min value of scanned variable + * @param dacMax Max value of scanned variable + * @param dacStep Step parameter + * @param useCalPulse Indicates whether to use internal calibration pulses + * @param currentPulse Indicates whether to use current or voltage internal calibration pulse + * @param calScaleFactor FIXME + * @param mask FIXME + * @param scanReg Register to scan FIXME: add possible values + * @param useUltra Indicates whether to use FW-implemented ultraScan + * @param useExtTrig FIXME: do we need both this and useCalPulse? + * @param result An array carrying scan results + */ + //FIXME Should we rearrange parameters so they are in the same order as in genScan? + uint32_t genChannelScan(uint32_t nevts, uint32_t ohN, uint32_t mask, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, bool useExtTrig, char * scanReg, bool useUltra, uint32_t * result); + + //FIXME Add documentation + uint32_t sbitRateScan(uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t maskOh, bool invertVFATPos, char * scanReg, uint32_t waitTime, uint32_t * resultDacVal, uint32_t * resultTrigRate, uint32_t * resultTrigRatePerVFAT, bool isParallel); + + /** + * @brief configure TTC generator + * + * v3 electronics Behavior: + * pulseDelay (only for enable = true), delay between CalPulse and L1A + * L1Ainterval (only for enable = true), how often to repeat signals + * enable = true (false) ignore (take) ttc commands from backplane for this AMC (affects all links) + * v2b electronics behavior: + * Configure the T1 controller + * mode: 0 (Single T1 signal), + * 1 (CalPulse followed by L1A), + * 2 (pattern) + * type (only for mode 0, type of T1 signal to send): + * 0 L1A + * 1 CalPulse + * 2 Resync + * 3 BC0 + * pulseDelay (only for mode 1), delay between CalPulse and L1A + * L1Ainterval (only for mode 0,1), how often to repeat signals + * nPulses how many signals to send (0 is continuous) + * enable = true (false) start (stop) the T1Controller for link ohN + */ + uint32_t ttcGenConf(uint32_t ohN, uint32_t mode, uint32_t type, uint32_t pulseDelay, uint32_t L1Ainterval, uint32_t nPulses, bool enable); + + /** + * @brief Toggles TTC behavior + * + * v3 electronics: enable = true (false) ignore (take) ttc commands from backplane for this AMC + * v2b electronics: enable = true (false) start (stop) the T1Controller for link ohN + */ + uint32_t ttcGenToggle(uint32_t ohN, bool enable); + }; + } } } -#endif +#endif // XHAL_CLIENT_RPCMAN_CALIBRATION_ROUTINES_H diff --git a/xhal/include/xhal/client/rpcman/daq_monitor.h b/xhal/include/xhal/client/rpcman/daq_monitor.h index 0ac7fca..f94b676 100644 --- a/xhal/include/xhal/client/rpcman/daq_monitor.h +++ b/xhal/include/xhal/client/rpcman/daq_monitor.h @@ -1,76 +1,78 @@ -#ifndef DAQ_MONITOR_H -#define DAQ_MONITOR_H +#ifndef XHAL_CLIENT_RPCMAN_DAQ_MONITOR_H +#define XHAL_CLIENT_RPCMAN_DAQ_MONITOR_H -#include "xhal/XHALInterface.h" -#include "xhal/utils/PyTypes.h" +#include "xhal/client/XHALInterface.h" +#include "xhal/client/utils/PyTypes.h" namespace xhal { - namespace rpc { - /** - * @class DaqMonitor - * @brief Provides interface to call remote utility methods - */ - class DaqMonitor : public XHALInterface - { - public: - /** - * @brief Default constructor - * - * Loads the neccessary remote modules - * @param board_domain_name domain name of CTP7 - */ - DaqMonitor(const std::string& board_domain_name):xhal::XHALInterface(board_domain_name){this->loadModule("amc", "amc v1.0.1");} - - ~DaqMonitor(){} - - /** - * @brief get an array of values for TTC main monitoring table - * - * @return an array of monitoring values - */ - //uint32_t getmonTTCmain(uint32_t* result); - PyListUint32 getmonTTCmain(); - - /** - * @brief get an array of values for TRIGGER main monitoring table - * - * @param noh Number of expected optical links, default value 12 - * @return an array of monitoring values - */ - PyListUint32 getmonTRIGGERmain(uint32_t noh = 12); - - /** - * @brief get an array of values for TRIGGER OH main monitoring table - * - * @param noh Number of expected optical links, default value 12 - * @return an array of monitoring values - */ - PyListUint32 getmonTRIGGEROHmain(uint32_t noh = 12); - - /** - * @brief get an array of values for DAQ main monitoring table - * - * @return an array of monitoring values - */ - PyListUint32 getmonDAQmain(); - - /** - * @brief get an array of values for DAQ OH main monitoring table - * - * @param noh Number of expected optical links, default value 12 - * @return an array of monitoring values - */ - PyListUint32 getmonDAQOHmain(uint32_t noh = 12); - - /** - * @brief get an array of values for OH main monitoring table - * - * @param noh Number of expected optical links, default value 12 - * @return an array of monitoring values - */ - PyListUint32 getmonOHmain(uint32_t noh = 12); - }; + namespace client { + namespace rpcman { + /** + * @class DaqMonitor + * @brief Provides interface to call remote utility methods + */ + class DaqMonitor : public xhal::client::XHALInterface + { + public: + /** + * @brief Default constructor + * + * Loads the neccessary remote modules + * @param board_domain_name domain name of CTP7 + */ + DaqMonitor(const std::string& board_domain_name):xhal::client::XHALInterface(board_domain_name){this->loadModule("amc", "amc v1.0.1");} + + ~DaqMonitor(){} + + /** + * @brief get an array of values for TTC main monitoring table + * + * @return an array of monitoring values + */ + //uint32_t getmonTTCmain(uint32_t* result); + PyListUint32 getmonTTCmain(); + + /** + * @brief get an array of values for TRIGGER main monitoring table + * + * @param noh Number of expected optical links, default value 12 + * @return an array of monitoring values + */ + PyListUint32 getmonTRIGGERmain(uint32_t noh = 12); + + /** + * @brief get an array of values for TRIGGER OH main monitoring table + * + * @param noh Number of expected optical links, default value 12 + * @return an array of monitoring values + */ + PyListUint32 getmonTRIGGEROHmain(uint32_t noh = 12); + + /** + * @brief get an array of values for DAQ main monitoring table + * + * @return an array of monitoring values + */ + PyListUint32 getmonDAQmain(); + + /** + * @brief get an array of values for DAQ OH main monitoring table + * + * @param noh Number of expected optical links, default value 12 + * @return an array of monitoring values + */ + PyListUint32 getmonDAQOHmain(uint32_t noh = 12); + + /** + * @brief get an array of values for OH main monitoring table + * + * @param noh Number of expected optical links, default value 12 + * @return an array of monitoring values + */ + PyListUint32 getmonOHmain(uint32_t noh = 12); + }; + } } } -#endif +#endif // XHAL_CLIENT_RPCMAN_DAQ_MONITOR_H diff --git a/xhal/include/xhal/client/rpcman/optohybrid.h b/xhal/include/xhal/client/rpcman/optohybrid.h index e2cf7c9..9bb1bbe 100644 --- a/xhal/include/xhal/client/rpcman/optohybrid.h +++ b/xhal/include/xhal/client/rpcman/optohybrid.h @@ -1,30 +1,33 @@ -#ifndef OPTOHYBRID_H -#define OPTOHYBRID_H +#ifndef XHAL_CLIENT_RPCMAN_OPTOHYBRID_H +#define XHAL_CLIENT_RPCMAN_OPTOHYBRID_H -#include "xhal/XHALDevice.h" -namespace xhal { - namespace rpc { - class Optohybrid : public xhal::XHALDevice { - public: - /** - * @brief Default constructor - * - * Parses XML file and loads required modules - * @param board_domain_name domain name of CTP7 - * @param address_table_filename XML address table file name - */ - Optohybrid(const std::string& board_domain_name, const std::string& address_table_filename); +#include "xhal/client/XHALDevice.h" - //FIXME provide documentation - uint32_t broadcastRead(uint32_t ohN, char * regName, uint32_t vfatMask, uint32_t * result); - uint32_t broadcastWrite(uint32_t ohN, char * regName, uint32_t value, uint32_t vfatMask); - uint32_t configureScanModule(uint32_t ohN, uint32_t vfatN, uint32_t scanmode, bool useUltra, uint32_t vfatMask, uint32_t ch, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep); - uint32_t printScanConfiguration(uint32_t ohN, bool useUltra); - uint32_t startScanModule(uint32_t ohN, bool useUltra); - uint32_t getUltraScanResults(uint32_t ohN, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t * result); - uint32_t stopCalPulse2AllChannels(uint32_t ohN, uint32_t mask, uint32_t ch_min, uint32_t ch_max); - };//end class Optohybrid - }//end namespace rpc -}//end namespace xhal +namespace xhal { + namespace client { + namespace rpcman { + class Optohybrid : public xhal::client::XHALDevice { + public: + /** + * @brief Default constructor + * + * Parses XML file and loads required modules + * @param board_domain_name domain name of CTP7 + * @param address_table_filename XML address table file name + */ + Optohybrid(const std::string& board_domain_name, const std::string& address_table_filename); + + //FIXME provide documentation + uint32_t broadcastRead(uint32_t ohN, char * regName, uint32_t vfatMask, uint32_t * result); + uint32_t broadcastWrite(uint32_t ohN, char * regName, uint32_t value, uint32_t vfatMask); + uint32_t configureScanModule(uint32_t ohN, uint32_t vfatN, uint32_t scanmode, bool useUltra, uint32_t vfatMask, uint32_t ch, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep); + uint32_t printScanConfiguration(uint32_t ohN, bool useUltra); + uint32_t startScanModule(uint32_t ohN, bool useUltra); + uint32_t getUltraScanResults(uint32_t ohN, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t * result); + uint32_t stopCalPulse2AllChannels(uint32_t ohN, uint32_t mask, uint32_t ch_min, uint32_t ch_max); + }; + } + } +} -#endif +#endif // XHAL_CLIENT_RPCMAN_OPTOHYBRID_H diff --git a/xhal/include/xhal/client/rpcman/utils.h b/xhal/include/xhal/client/rpcman/utils.h index 72f4a5b..1e10ab9 100644 --- a/xhal/include/xhal/client/rpcman/utils.h +++ b/xhal/include/xhal/client/rpcman/utils.h @@ -1,33 +1,35 @@ -#ifndef UTILS_H -#define UTILS_H +#ifndef XHAL_CLIENT_RPCMAN_UTILS_H +#define XHAL_CLIENT_RPCMAN_UTILS_H #include #include #include #include -#include "xhal/XHALInterface.h" +#include "xhal/client/XHALInterface.h" namespace xhal { - namespace rpc { - /** - * @class Utils - * @brief Provides interface to call remote utility methods - */ - class Utils : public XHALInterface - { - public: - /** - * @brief Default constructor - * - * Loads the neccessary remote modules - * @param board_domain_name domain name of CTP7 - */ - Utils(const std::string& board_domain_name):xhal::XHALInterface(board_domain_name){this->loadModule("utils", "utils v1.0.1");} - ~Utils(){} - uint32_t update_atdb(char * xmlfilename); - uint32_t getRegInfoDB(char * regName); - }; - + namespace client { + namespace rpcman { + /** + * @class Utils + * @brief Provides interface to call remote utility methods + */ + class Utils : public xhal::client::XHALInterface + { + public: + /** + * @brief Default constructor + * + * Loads the neccessary remote modules + * @param board_domain_name domain name of CTP7 + */ + Utils(const std::string& board_domain_name):xhal::client::XHALInterface(board_domain_name){this->loadModule("utils", "utils v1.0.1");} + ~Utils(){} + uint32_t update_atdb(char * xmlfilename); + uint32_t getRegInfoDB(char * regName); + }; + + } } } -#endif +#endif // XHAL_CLIENT_RPCMAN_UTILS_H diff --git a/xhal/include/xhal/client/rpcman/vfat3.h b/xhal/include/xhal/client/rpcman/vfat3.h index 2ba3217..2e89e82 100644 --- a/xhal/include/xhal/client/rpcman/vfat3.h +++ b/xhal/include/xhal/client/rpcman/vfat3.h @@ -1,57 +1,59 @@ -#ifndef VFAT3_H -#define VFAT3_H +#ifndef XHAL_CLIENT_RPCMAN_VFAT3_H +#define XHAL_CLIENT_RPCMAN_VFAT3_H -#include "xhal/XHALDevice.h" +#include "xhal/client/XHALDevice.h" namespace xhal { - namespace rpc { - class VFAT3 : public xhal::XHALDevice { - public: - /** - * @brief Default constructor - * - * Parses XML file and loads required modules - * @param board_domain_name domain name of CTP7 - * @param address_table_filename XML address table file name - */ - VFAT3(const std::string& board_domain_name, const std::string& address_table_filename); - - //FIXME provide docs - /** - * @brief load configuration parameters to VFAT3 chips - */ - uint32_t configureVFAT3s(uint32_t ohN, uint32_t vfatMask); + namespace client { + namespace rpcman { + class VFAT3 : public xhal::client::XHALDevice { + public: + /** + * @brief Default constructor + * + * Parses XML file and loads required modules + * @param board_domain_name domain name of CTP7 + * @param address_table_filename XML address table file name + */ + VFAT3(const std::string& board_domain_name, const std::string& address_table_filename); + + //FIXME provide docs + /** + * @brief load configuration parameters to VFAT3 chips + */ + uint32_t configureVFAT3s(uint32_t ohN, uint32_t vfatMask); + + /** + * @brief reads channel registers of all unmasked vfats on ohN + * @param ohN Optohybrid optical link number + * @param vfatMask Bitmask of chip positions determining which chips to use + * @param chanRegData array pointer for channel register data with 3072 entries, the (vfat,chan) pairing determines the array index via: idx = vfat*128 + chan + */ + uint32_t getChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData); + + /** + * @brief sets all vfat3 channel registers + * @param ohN Optohybrid optical link number + * @param vfatMask Bitmask of chip positions determining which chips to use + * @param calEnable array pointer for calEnable with 3072 entries, the (vfat,chan) pairing determines the array index via: idx = vfat*128 + chan + * @param masks as calEnable but for channel masks + * @param trimARM as calEnable but for arming comparator trim value + * @param trimARMPol as calEnable but for arming comparator trim polarity + * @param trimZCC as calEnable but for zero crossing comparator trim value + * @param trimZCCPol as calEnable but for zero crossing comparator trim polarity + */ + uint32_t setChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *calEnable, uint32_t *masks, uint32_t *trimARM, uint32_t *trimARMPol, uint32_t *trimZCC, uint32_t *trimZCCPol); + + /** + * @brief sets all vfat3 channel registers using a single channel register array + * @param ohN Optohybrid optical link number + * @param vfatMask Bitmask of chip positions determining which chips to use + * @param chanRegData array pointer for channel register data with 3072 entries, the (vfat,chan) pairing determines the array index via: idx = vfat*128 + chan + */ + uint32_t setChannelRegistersVFAT3Simple(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData); + }; + } + } +} - /** - * @brief reads channel registers of all unmasked vfats on ohN - * @param ohN Optohybrid optical link number - * @param vfatMask Bitmask of chip positions determining which chips to use - * @param chanRegData array pointer for channel register data with 3072 entries, the (vfat,chan) pairing determines the array index via: idx = vfat*128 + chan - */ - uint32_t getChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData); - - /** - * @brief sets all vfat3 channel registers - * @param ohN Optohybrid optical link number - * @param vfatMask Bitmask of chip positions determining which chips to use - * @param calEnable array pointer for calEnable with 3072 entries, the (vfat,chan) pairing determines the array index via: idx = vfat*128 + chan - * @param masks as calEnable but for channel masks - * @param trimARM as calEnable but for arming comparator trim value - * @param trimARMPol as calEnable but for arming comparator trim polarity - * @param trimZCC as calEnable but for zero crossing comparator trim value - * @param trimZCCPol as calEnable but for zero crossing comparator trim polarity - */ - uint32_t setChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *calEnable, uint32_t *masks, uint32_t *trimARM, uint32_t *trimARMPol, uint32_t *trimZCC, uint32_t *trimZCCPol); - - /** - * @brief sets all vfat3 channel registers using a single channel register array - * @param ohN Optohybrid optical link number - * @param vfatMask Bitmask of chip positions determining which chips to use - * @param chanRegData array pointer for channel register data with 3072 entries, the (vfat,chan) pairing determines the array index via: idx = vfat*128 + chan - */ - uint32_t setChannelRegistersVFAT3Simple(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData); - };//end class VFAT3 - }//end namespace rpc -}//end namespace xhal - -#endif +#endif // XHAL_CLIENT_RPCMAN_VFAT3_H diff --git a/xhal/src/client/rpc_manager/calibration_routines.cpp b/xhal/src/client/rpc_manager/calibration_routines.cpp index c824a6c..1c81e16 100644 --- a/xhal/src/client/rpc_manager/calibration_routines.cpp +++ b/xhal/src/client/rpc_manager/calibration_routines.cpp @@ -1,6 +1,6 @@ -#include "xhal/rpc/calibration_routines.h" +#include "xhal/client/rpcman/calibration_routines.h" -uint32_t xhal::rpc::CalRoutines::checkSbitMappingWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t nevts, uint32_t L1Ainterval, uint32_t pulseDelay, uint32_t *data) +uint32_t xhal::client::rpcman::CalRoutines::checkSbitMappingWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t nevts, uint32_t L1Ainterval, uint32_t pulseDelay, uint32_t *data) { req = wisc::RPCMsg("calibration_routines.checkSbitMappingWithCalPulse"); @@ -35,9 +35,9 @@ uint32_t xhal::rpc::CalRoutines::checkSbitMappingWithCalPulse(uint32_t ohN, uint } return 0; -} //End checkSbitMappingWithCalPulse() +} -uint32_t xhal::rpc::CalRoutines::checkSbitRateWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t waitTime, uint32_t pulseRate, uint32_t pulseDelay, uint32_t *outDataCTP7Rate, uint32_t *outDataFPGAClusterCntRate, uint32_t *outDataVFATSBits) +uint32_t xhal::client::rpcman::CalRoutines::checkSbitRateWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t waitTime, uint32_t pulseRate, uint32_t pulseDelay, uint32_t *outDataCTP7Rate, uint32_t *outDataFPGAClusterCntRate, uint32_t *outDataVFATSBits) { req = wisc::RPCMsg("calibration_routines.checkSbitRateWithCalPulse"); @@ -90,9 +90,9 @@ uint32_t xhal::rpc::CalRoutines::checkSbitRateWithCalPulse(uint32_t ohN, uint32_ } return 0; -} //End checkSbitRateWithCalPulse() +} -uint32_t xhal::rpc::CalRoutines::genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t mask, char * scanReg, bool useUltra, bool useExtTrig, uint32_t * result) +uint32_t xhal::client::rpcman::CalRoutines::genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t mask, char * scanReg, bool useUltra, bool useExtTrig, uint32_t * result) { req = wisc::RPCMsg("calibration_routines.genScan"); @@ -133,7 +133,7 @@ uint32_t xhal::rpc::CalRoutines::genScan(uint32_t nevts, uint32_t ohN, uint32_t return 0; } -uint32_t xhal::rpc::CalRoutines::genChannelScan(uint32_t nevts, uint32_t ohN, uint32_t mask, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, bool useExtTrig, char * scanReg, bool useUltra, uint32_t * result) +uint32_t xhal::client::rpcman::CalRoutines::genChannelScan(uint32_t nevts, uint32_t ohN, uint32_t mask, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, bool useExtTrig, char * scanReg, bool useUltra, uint32_t * result) { req = wisc::RPCMsg("calibration_routines.genChannelScan"); @@ -171,9 +171,9 @@ uint32_t xhal::rpc::CalRoutines::genChannelScan(uint32_t nevts, uint32_t ohN, ui } return 0; -} //End genChannelScan() +} -uint32_t xhal::rpc::CalRoutines::sbitRateScan(uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t maskOh, bool invertVFATPos, char * scanReg, uint32_t waitTime, uint32_t * resultDacVal, uint32_t * resultTrigRate, uint32_t * resultTrigRatePerVFAT, bool isParallel) +uint32_t xhal::client::rpcman::CalRoutines::sbitRateScan(uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t maskOh, bool invertVFATPos, char * scanReg, uint32_t waitTime, uint32_t * resultDacVal, uint32_t * resultTrigRate, uint32_t * resultTrigRatePerVFAT, bool isParallel) { req = wisc::RPCMsg("calibration_routines.sbitRateScan"); @@ -234,9 +234,9 @@ uint32_t xhal::rpc::CalRoutines::sbitRateScan(uint32_t ohN, uint32_t dacMin, uin } return 0; -} //End sbitRateScan(...) +} -uint32_t xhal::rpc::CalRoutines::ttcGenConf(uint32_t ohN, uint32_t mode, uint32_t type, uint32_t pulseDelay, uint32_t L1Ainterval, uint32_t nPulses, bool enable) +uint32_t xhal::client::rpcman::CalRoutines::ttcGenConf(uint32_t ohN, uint32_t mode, uint32_t type, uint32_t pulseDelay, uint32_t L1Ainterval, uint32_t nPulses, bool enable) { req = wisc::RPCMsg("calibration_routines.ttcGenConf"); @@ -258,7 +258,7 @@ uint32_t xhal::rpc::CalRoutines::ttcGenConf(uint32_t ohN, uint32_t mode, uint32_ return 0; } -uint32_t xhal::rpc::CalRoutines::ttcGenToggle(uint32_t ohN, bool enable) +uint32_t xhal::client::rpcman::CalRoutines::ttcGenToggle(uint32_t ohN, bool enable) { req = wisc::RPCMsg("calibration_routines.ttcGenToggle"); req.set_word("ohN", ohN); @@ -272,4 +272,4 @@ uint32_t xhal::rpc::CalRoutines::ttcGenToggle(uint32_t ohN, bool enable) return 1; } return 0; -} //End ttcGenToggle(...) +} diff --git a/xhal/src/client/rpc_manager/daq_monitor.cpp b/xhal/src/client/rpc_manager/daq_monitor.cpp index 5045c9c..b866cd6 100644 --- a/xhal/src/client/rpc_manager/daq_monitor.cpp +++ b/xhal/src/client/rpc_manager/daq_monitor.cpp @@ -1,6 +1,6 @@ -#include "xhal/rpc/daq_monitor.h" +#include "xhal/client/rpcman/daq_monitor.h" -PyListUint32 xhal::rpc::DaqMonitor::getmonTTCmain() +PyListUint32 xhal::client::rpcman::DaqMonitor::getmonTTCmain() { PyListUint32 result; req = wisc::RPCMsg("amc.getmonTTCmain"); @@ -26,7 +26,7 @@ PyListUint32 xhal::rpc::DaqMonitor::getmonTTCmain() return result; } -PyListUint32 xhal::rpc::DaqMonitor::getmonTRIGGERmain(uint32_t noh) +PyListUint32 xhal::client::rpcman::DaqMonitor::getmonTRIGGERmain(uint32_t noh) { PyListUint32 result; req = wisc::RPCMsg("amc.getmonTRIGGERmain"); @@ -53,7 +53,7 @@ PyListUint32 xhal::rpc::DaqMonitor::getmonTRIGGERmain(uint32_t noh) return result; } -PyListUint32 xhal::rpc::DaqMonitor::getmonTRIGGEROHmain(uint32_t noh) +PyListUint32 xhal::client::rpcman::DaqMonitor::getmonTRIGGEROHmain(uint32_t noh) { PyListUint32 result(8*noh,0); req = wisc::RPCMsg("amc.getmonTRIGGEROHmain"); @@ -93,7 +93,7 @@ PyListUint32 xhal::rpc::DaqMonitor::getmonTRIGGEROHmain(uint32_t noh) return result; } -PyListUint32 xhal::rpc::DaqMonitor::getmonDAQmain() +PyListUint32 xhal::client::rpcman::DaqMonitor::getmonDAQmain() { PyListUint32 result; req = wisc::RPCMsg("amc.getmonDAQmain"); @@ -122,7 +122,7 @@ PyListUint32 xhal::rpc::DaqMonitor::getmonDAQmain() return result; } -PyListUint32 xhal::rpc::DaqMonitor::getmonDAQOHmain(uint32_t noh) +PyListUint32 xhal::client::rpcman::DaqMonitor::getmonDAQOHmain(uint32_t noh) { PyListUint32 result(6*noh,0); req = wisc::RPCMsg("amc.getmonDAQOHmain"); @@ -158,7 +158,7 @@ PyListUint32 xhal::rpc::DaqMonitor::getmonDAQOHmain(uint32_t noh) return result; } -PyListUint32 xhal::rpc::DaqMonitor::getmonOHmain(uint32_t noh) +PyListUint32 xhal::client::rpcman::DaqMonitor::getmonOHmain(uint32_t noh) { PyListUint32 result(7*noh,0); req = wisc::RPCMsg("amc.getmonOHmain"); diff --git a/xhal/src/client/rpc_manager/optohybrid.cpp b/xhal/src/client/rpc_manager/optohybrid.cpp index 04b4c6f..b21c0bb 100644 --- a/xhal/src/client/rpc_manager/optohybrid.cpp +++ b/xhal/src/client/rpc_manager/optohybrid.cpp @@ -1,12 +1,12 @@ -#include "xhal/rpc/optohybrid.h" +#include "xhal/client/rpcman/optohybrid.h" -xhal::rpc::Optohybrid::Optohybrid(const std::string& board_domain_name, const std::string& address_table_filename): - xhal::XHALDevice(board_domain_name, address_table_filename) +xhal::client::rpcman::Optohybrid::Optohybrid(const std::string& board_domain_name, const std::string& address_table_filename) : + xhal::client::XHALDevice(board_domain_name, address_table_filename) { this->loadModule("optohybrid","optohybrid v1.0.1"); } -uint32_t xhal::rpc::Optohybrid::broadcastRead(uint32_t ohN, char * regName, uint32_t vfatMask, uint32_t * result) +uint32_t xhal::client::rpcman::Optohybrid::broadcastRead(uint32_t ohN, char * regName, uint32_t vfatMask, uint32_t * result) { /* User supplies the VFAT node name as reg_name, examples: * @@ -40,9 +40,9 @@ uint32_t xhal::rpc::Optohybrid::broadcastRead(uint32_t ohN, char * regName, uint return 1; } return 0; -} //End broadcastRead +} -uint32_t xhal::rpc::Optohybrid::broadcastWrite(uint32_t ohN, char * regName, uint32_t value, uint32_t vfatMask) +uint32_t xhal::client::rpcman::Optohybrid::broadcastWrite(uint32_t ohN, char * regName, uint32_t value, uint32_t vfatMask) { /* User supplies the VFAT node name as reg_name, examples: * @@ -71,7 +71,7 @@ uint32_t xhal::rpc::Optohybrid::broadcastWrite(uint32_t ohN, char * regName, uin return 0; } -uint32_t xhal::rpc::Optohybrid::configureScanModule(uint32_t ohN, uint32_t vfatN, uint32_t scanmode, bool useUltra, uint32_t vfatMask, uint32_t ch, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep) +uint32_t xhal::client::rpcman::Optohybrid::configureScanModule(uint32_t ohN, uint32_t vfatN, uint32_t scanmode, bool useUltra, uint32_t vfatMask, uint32_t ch, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep) { req = wisc::RPCMsg("optohybrid.configureScanModule"); @@ -101,9 +101,9 @@ uint32_t xhal::rpc::Optohybrid::configureScanModule(uint32_t ohN, uint32_t vfatN } return 0; -} //End configureScanModule(...) +} -uint32_t xhal::rpc::Optohybrid::printScanConfiguration(uint32_t ohN, bool useUltra) +uint32_t xhal::client::rpcman::Optohybrid::printScanConfiguration(uint32_t ohN, bool useUltra) { req = wisc::RPCMsg("optohybrid.printScanConfiguration"); @@ -123,9 +123,9 @@ uint32_t xhal::rpc::Optohybrid::printScanConfiguration(uint32_t ohN, bool useUlt } return 0; -} //End printScanConfiguration(...) +} -uint32_t xhal::rpc::Optohybrid::startScanModule(uint32_t ohN, bool useUltra) +uint32_t xhal::client::rpcman::Optohybrid::startScanModule(uint32_t ohN, bool useUltra) { req = wisc::RPCMsg("optohybrid.startScanModule"); @@ -145,9 +145,9 @@ uint32_t xhal::rpc::Optohybrid::startScanModule(uint32_t ohN, bool useUltra) } return 0; -} //End startScanModule(...) +} -uint32_t xhal::rpc::Optohybrid::getUltraScanResults(uint32_t ohN, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t * result) +uint32_t xhal::client::rpcman::Optohybrid::getUltraScanResults(uint32_t ohN, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t * result) { req = wisc::RPCMsg("optohybrid.getUltraScanResults"); @@ -176,9 +176,9 @@ uint32_t xhal::rpc::Optohybrid::getUltraScanResults(uint32_t ohN, uint32_t nevts } return 0; -} //End getUltraScanResults(...) +} -uint32_t xhal::rpc::Optohybrid::stopCalPulse2AllChannels(uint32_t ohN, uint32_t mask, uint32_t ch_min, uint32_t ch_max) +uint32_t xhal::client::rpcman::Optohybrid::stopCalPulse2AllChannels(uint32_t ohN, uint32_t mask, uint32_t ch_min, uint32_t ch_max) { req = wisc::RPCMsg("optohybrid.stopCalPulse2AllChannels"); diff --git a/xhal/src/client/rpc_manager/utils.cpp b/xhal/src/client/rpc_manager/utils.cpp index d909e6f..2fdc290 100644 --- a/xhal/src/client/rpc_manager/utils.cpp +++ b/xhal/src/client/rpc_manager/utils.cpp @@ -1,6 +1,6 @@ -#include "xhal/rpc/utils.h" +#include "xhal/client/rpcman/utils.h" -uint32_t xhal::rpc::Utils::update_atdb(char * xmlfilename) +uint32_t xhal::client::rpcman::Utils::update_atdb(char * xmlfilename) { req = wisc::RPCMsg("utils.update_address_table"); req.set_string("at_xml", xmlfilename); @@ -11,12 +11,12 @@ uint32_t xhal::rpc::Utils::update_atdb(char * xmlfilename) if (rsp.get_key_exists("error")) { XHAL_ERROR("Address table update failed!"); - throw xhal::utils::XHALException("Error during address table update"); + throw xhal::common::utils::XHALException("Error during address table update"); } return 0; } -uint32_t xhal::rpc::Utils::getRegInfoDB(char * regName) +uint32_t xhal::client::rpcman::Utils::getRegInfoDB(char * regName) { uint32_t address, mask; std::string permissions; diff --git a/xhal/src/client/rpc_manager/vfat3.cpp b/xhal/src/client/rpc_manager/vfat3.cpp index 43e3f78..59caf5c 100644 --- a/xhal/src/client/rpc_manager/vfat3.cpp +++ b/xhal/src/client/rpc_manager/vfat3.cpp @@ -1,13 +1,13 @@ #include -#include "xhal/rpc/vfat3.h" +#include "xhal/client/rpcman/vfat3.h" -xhal::rpc::VFAT3::VFAT3(const std::string& board_domain_name, const std::string& address_table_filename): - xhal::XHALDevice(board_domain_name, address_table_filename) +xhal::client::rpcman::VFAT3::VFAT3(const std::string& board_domain_name, const std::string& address_table_filename) : + xhal::client::XHALDevice(board_domain_name, address_table_filename) { this->loadModule("vfat3","vfat3 v1.0.1"); } -uint32_t xhal::rpc::VFAT3::configureVFAT3s(uint32_t ohN, uint32_t vfatMask) +uint32_t xhal::client::rpcman::VFAT3::configureVFAT3s(uint32_t ohN, uint32_t vfatMask) { req = wisc::RPCMsg("vfat3.configureVFAT3s"); req.set_word("vfatMask",vfatMask); @@ -25,7 +25,7 @@ uint32_t xhal::rpc::VFAT3::configureVFAT3s(uint32_t ohN, uint32_t vfatMask) return 0; } -uint32_t xhal::rpc::VFAT3::getChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData) +uint32_t xhal::client::rpcman::VFAT3::getChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData) { req = wisc::RPCMsg("vfat3.getChannelRegistersVFAT3"); req.set_word("ohN",ohN); @@ -53,7 +53,7 @@ uint32_t xhal::rpc::VFAT3::getChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatM return 0; } -uint32_t xhal::rpc::VFAT3::setChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *calEnable, uint32_t *masks, uint32_t *trimARM, uint32_t *trimARMPol, uint32_t *trimZCC, uint32_t *trimZCCPol) +uint32_t xhal::client::rpcman::VFAT3::setChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *calEnable, uint32_t *masks, uint32_t *trimARM, uint32_t *trimARMPol, uint32_t *trimZCC, uint32_t *trimZCCPol) { req = wisc::RPCMsg("vfat3.setChannelRegistersVFAT3"); req.set_word("ohN",ohN); @@ -78,7 +78,7 @@ uint32_t xhal::rpc::VFAT3::setChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatM return 0; } -uint32_t xhal::rpc::VFAT3::setChannelRegistersVFAT3Simple(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData) +uint32_t xhal::client::rpcman::VFAT3::setChannelRegistersVFAT3Simple(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData) { req = wisc::RPCMsg("vfat3.setChannelRegistersVFAT3"); req.set_word("ohN",ohN); From 699da3d0f7ade0204401575030ab5e5c270856b2 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 20:18:14 +0200 Subject: [PATCH 37/56] [refactor] Adapt `client/python_wrappers` for new structure --- .../python_wrappers/XHALInterface_python.cpp | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/xhal/src/client/python_wrappers/XHALInterface_python.cpp b/xhal/src/client/python_wrappers/XHALInterface_python.cpp index d847d8d..b5c20ed 100644 --- a/xhal/src/client/python_wrappers/XHALInterface_python.cpp +++ b/xhal/src/client/python_wrappers/XHALInterface_python.cpp @@ -1,9 +1,9 @@ #include -#include "xhal/utils/Exception.h" -#include "xhal/XHALDevice.h" -#include "xhal/utils/PyTypes.h" -#include "xhal/rpc/daq_monitor.h" -#include "xhal/rpc/utils.h" +#include "xhal/common/utils/Exception.h" +#include "xhal/client/XHALDevice.h" +#include "xhal/client/utils/PyTypes.h" +#include "xhal/client/rpcman/daq_monitor.h" +#include "xhal/client/rpcman/utils.h" #include #include @@ -37,14 +37,14 @@ inline void TRANSLATOR_NAME(EXCEPTION_NAME const& e) } #endif -PY_EXCEPTION_TRANSLATOR(translate_XHALException,xhal::utils::XHALException, obj_XHALException) -PY_EXCEPTION_TRANSLATOR(translate_XHALXMLParserException,xhal::utils::XHALXMLParserException, obj_XHALXMLParserException) -PY_EXCEPTION_TRANSLATOR(translate_XHALRPCException,xhal::utils::XHALRPCException, obj_XHALRPCException) -PY_EXCEPTION_TRANSLATOR(translate_XHALRPCNotConnectedException,xhal::utils::XHALRPCNotConnectedException, obj_XHALRPCNotConnectedException) +PY_EXCEPTION_TRANSLATOR(translate_XHALException,xhal::common::utils::XHALException, obj_XHALException) +PY_EXCEPTION_TRANSLATOR(translate_XHALXMLParserException,xhal::common::utils::XHALXMLParserException, obj_XHALXMLParserException) +PY_EXCEPTION_TRANSLATOR(translate_XHALRPCException,xhal::common::utils::XHALRPCException, obj_XHALRPCException) +PY_EXCEPTION_TRANSLATOR(translate_XHALRPCNotConnectedException,xhal::common::utils::XHALRPCNotConnectedException, obj_XHALRPCNotConnectedException) // https://stackoverflow.com/questions/7577410/boost-python-select-between-overloaded-methods -uint32_t (xhal::XHALDevice::*readReg_byname)(std::string regName) = &xhal::XHALDevice::readReg; -uint32_t (xhal::XHALDevice::*readReg_byaddress)(uint32_t address) = &xhal::XHALDevice::readReg; +uint32_t (xhal::client::XHALDevice::*readReg_byname)(std::string regName) = &xhal::client::XHALDevice::readReg; +uint32_t (xhal::client::XHALDevice::*readReg_byaddress)(uint32_t address) = &xhal::client::XHALDevice::readReg; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getmonTRIGGERmain_overloads, getmonTRIGGERmain, 0, 1) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getmonTRIGGEROHmain_overloads, getmonTRIGGEROHmain, 0, 1) @@ -52,43 +52,43 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getmonDAQOHmain_overloads, getmonDAQOHmai BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getmonOHmain_overloads, getmonOHmain, 0, 1) BOOST_PYTHON_MODULE(xhalpy){ - using namespace boost::python; - - obj_XHALException = createExceptionClass("XHALException"); - obj_XHALXMLParserException = createExceptionClass("XHALXMLParserException"); - obj_XHALRPCException = createExceptionClass("XHALRPCException"); - obj_XHALRPCNotConnectedException = createExceptionClass("XHALRPCNotConnectedException"); - - register_exception_translator(&translate_XHALException); - register_exception_translator(&translate_XHALXMLParserException); - register_exception_translator(&translate_XHALRPCException); - register_exception_translator(&translate_XHALRPCNotConnectedException); - - class_("XHALDevice", init()) - .def("connect",&xhal::XHALDevice::connect) - .def("reconnect",&xhal::XHALDevice::reconnect) - .def("disconnect",&xhal::XHALDevice::disconnect) - .def("loadModule",&xhal::XHALDevice::loadModule) - .def("setLogLevel",&xhal::XHALDevice::setLogLevel) - .def("readReg",readReg_byname) - .def("readReg",readReg_byaddress) - .def("writeReg",&xhal::XHALDevice::writeReg); - - class_("PyListUint32") - .def(vector_indexing_suite() ); - - class_("PyDictVecUint32") - .def(map_indexing_suite() ); - - class_("Utils", init()) - .def("update_atdb",&xhal::rpc::Utils::update_atdb) - .def("getRegInfoDB",&xhal::rpc::Utils::getRegInfoDB); - - class_("DaqMonitor", init()) - .def("getmonTTCmain",&xhal::rpc::DaqMonitor::getmonTTCmain) - .def("getmonTRIGGERmain",&xhal::rpc::DaqMonitor::getmonTRIGGERmain,getmonTRIGGERmain_overloads()) - .def("getmonTRIGGEROHmain",&xhal::rpc::DaqMonitor::getmonTRIGGEROHmain,getmonTRIGGEROHmain_overloads()) - .def("getmonDAQOHmain",&xhal::rpc::DaqMonitor::getmonDAQOHmain,getmonDAQOHmain_overloads()) - .def("getmonOHmain",&xhal::rpc::DaqMonitor::getmonOHmain,getmonOHmain_overloads()) - .def("getmonDAQmain",&xhal::rpc::DaqMonitor::getmonDAQmain); + using namespace boost::python; + + obj_XHALException = createExceptionClass("XHALException"); + obj_XHALXMLParserException = createExceptionClass("XHALXMLParserException"); + obj_XHALRPCException = createExceptionClass("XHALRPCException"); + obj_XHALRPCNotConnectedException = createExceptionClass("XHALRPCNotConnectedException"); + + register_exception_translator(&translate_XHALException); + register_exception_translator(&translate_XHALXMLParserException); + register_exception_translator(&translate_XHALRPCException); + register_exception_translator(&translate_XHALRPCNotConnectedException); + + class_("XHALDevice", init()) + .def("connect",&xhal::client::XHALDevice::connect) + .def("reconnect",&xhal::client::XHALDevice::reconnect) + .def("disconnect",&xhal::client::XHALDevice::disconnect) + .def("loadModule",&xhal::client::XHALDevice::loadModule) + .def("setLogLevel",&xhal::client::XHALDevice::setLogLevel) + .def("readReg",readReg_byname) + .def("readReg",readReg_byaddress) + .def("writeReg",&xhal::client::XHALDevice::writeReg); + + class_("PyListUint32") + .def(vector_indexing_suite() ); + + class_("PyDictVecUint32") + .def(map_indexing_suite() ); + + class_("Utils", init()) + .def("update_atdb",&xhal::client::rpcman::Utils::update_atdb) + .def("getRegInfoDB",&xhal::client::rpcman::Utils::getRegInfoDB); + + class_("DaqMonitor", init()) + .def("getmonTTCmain",&xhal::client::rpcman::DaqMonitor::getmonTTCmain) + .def("getmonTRIGGERmain",&xhal::client::rpcman::DaqMonitor::getmonTRIGGERmain,getmonTRIGGERmain_overloads()) + .def("getmonTRIGGEROHmain",&xhal::client::rpcman::DaqMonitor::getmonTRIGGEROHmain,getmonTRIGGEROHmain_overloads()) + .def("getmonDAQOHmain",&xhal::client::rpcman::DaqMonitor::getmonDAQOHmain,getmonDAQOHmain_overloads()) + .def("getmonOHmain",&xhal::client::rpcman::DaqMonitor::getmonOHmain,getmonOHmain_overloads()) + .def("getmonDAQmain",&xhal::client::rpcman::DaqMonitor::getmonDAQmain); } From 42b6b9b36c8f38f92e04df0f78f1ad828ca84f10 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 22:16:34 +0200 Subject: [PATCH 38/56] [style] Standardize Doxygen comment style --- xhal/include/xhal/client/XHALInterface.h | 20 +-- xhal/include/xhal/common/rpc/call.h | 36 ++-- xhal/include/xhal/common/rpc/common.h | 202 +++++++++++----------- xhal/include/xhal/common/rpc/compat.h | 64 +++---- xhal/include/xhal/common/rpc/exceptions.h | 44 ++--- xhal/include/xhal/common/rpc/helper.h | 56 +++--- xhal/include/xhal/common/rpc/register.h | 32 ++-- xhal/include/xhal/server/LMDB.h | 36 ++-- xhal/src/common/rpc/exceptions.cpp | 104 +++++------ 9 files changed, 292 insertions(+), 302 deletions(-) diff --git a/xhal/include/xhal/client/XHALInterface.h b/xhal/include/xhal/client/XHALInterface.h index c2d6324..ccc0e54 100644 --- a/xhal/include/xhal/client/XHALInterface.h +++ b/xhal/include/xhal/client/XHALInterface.h @@ -3,7 +3,7 @@ * Hardware interface for XHAL * * @author Mykhailo Dalchenko - * @version 1.0 + * @version 1.0 */ #ifndef XHAL_CLIENT_XHALINTERFACE_H @@ -42,7 +42,7 @@ catch (wisc::RPCMsg::BadKeyException &e) { \ XHAL_ERROR("Caught exception: " << e.key.c_str()); \ throw xhal::common::utils::XHALRPCException("RPC BadKeyException (most probably remote register not accessible): " + e.key);\ - } + } #define ASSERT(x) do { \ if (!(x)) { \ @@ -55,7 +55,7 @@ namespace xhal { namespace client { /** * @class XHALInterface - * @brief Provides interface to call remote procedures at Zynq CPU + * @brief Provides interface to call remote procedures at Zynq CPU */ class XHALInterface { @@ -70,29 +70,29 @@ namespace xhal { * @param board_domain_name domain name of CTP7 */ XHALInterface(const std::string& board_domain_name, log4cplus::Logger& logger); - + virtual ~XHALInterface(); - + /** * @brief Initialize interface and establish RPC service connection with CTP7 */ void connect(); - + /** * @brief Reconnect to RPC service and reload required modules */ virtual void reconnect(); - + /** * @brief Initialize interface and establish RPC service connection with CTP7 */ void disconnect(); - + /** * @brief load remote module */ void loadModule(const std::string& module_name, const std::string& module_version); - + /** * @brief sets amount of logging/debugging information to display * @param loglevel: @@ -103,7 +103,7 @@ namespace xhal { * 4 - TRACE */ void setLogLevel(int loglevel); - + protected: std::string m_board_domain_name; log4cplus::Logger m_logger; diff --git a/xhal/include/xhal/common/rpc/call.h b/xhal/include/xhal/common/rpc/call.h index 91ff6bd..35018ed 100644 --- a/xhal/include/xhal/common/rpc/call.h +++ b/xhal/include/xhal/common/rpc/call.h @@ -1,10 +1,10 @@ -/*! - * \file - * \brief This file contains all the functions needed to call +/** + * @file + * @brief This file contains all the functions needed to call * remotely a RPC method * - * \author Laurent Pétré - * \author Louis Moureaux + * @author Laurent Pétré + * @author Louis Moureaux */ #ifndef XHAL_COMMON_RPC_CALL_H @@ -23,12 +23,12 @@ namespace xhal { namespace common { namespace rpc { - /*! - * \brief Remotely call a RPC method + /** + * @brief Remotely call a RPC method * * The remote method called is defined by the template parameter - * \c Method. The arguments to give to the function are those from - * the \c Method::operator() signature and their types \b must be deducible. + * @c Method. The arguments to give to the function are those from + * the @c Method::operator() signature and their types @b must be deducible. */ template call(wisc::RPCSvc &connection, Args&&... args); /** - * \brief Thrown by \ref call when an exception is thrown on the remote host. + * @brief Thrown by @ref call when an exception is thrown on the remote host. */ class RemoteException : public std::runtime_error { std::string m_type; /** - * \brief \ref call is the only function that can throw this exception. + * @brief @ref call is the only function that can throw this exception. */ template + * @author Laurent Pétré */ #ifndef XHAL_COMMON_RPC_COMMON_H @@ -24,55 +24,55 @@ namespace xhal { namespace common { namespace rpc { - /*! - * \brief Defines the templated RPC ABI version + /** + * @brief Defines the templated RPC ABI version */ static constexpr const char* abiVersion = "v1"; - /*! - * \brief Class whose all remotely callable RPC method must inherit from + /** + * @brief Class whose all remotely callable RPC method must inherit from * * The required inheritance is used as a compile time check so a developer * cannot remotely call a local function by mistake. */ struct Method { - /*! - * \brief The operator call must be define once and only once per + /** + * @brief The operator call must be define once and only once per * RPC method. * * This templated operator declaration is only shown as an example and * emphasizes the need of defining it in child classes. * - * \warnng The call operator \b must be defined as \c const. + * @warnng The call operator @b must be defined as @c const. */ template R operator()(Args...) const; }; - /*! - * \brief Base of the \c MessageSerializer and \c MessageDeserializer classes + /** + * @brief Base of the @c MessageSerializer and @c MessageDeserializer classes * - * \c MessageBase provides the key index tracking functionnality which + * @c MessageBase provides the key index tracking functionnality which * is mandatory for serialization. */ class MessageBase { - /*! - * \brief Index to the next free/unread key + /** + * @brief Index to the next free/unread key */ uint32_t _keyIdx = 0; protected: - /* - * \brief Returns the next free/unread key + /** + * @brief Returns the next free/unread key */ inline uint32_t dispenseKey() { return _keyIdx++; } }; - /*! - * \brief This class serializes parameters into a \c wisc::RPCMsg + /** + * @brief This class serializes parameters into a @c wisc::RPCMsg */ class MessageSerializer : public MessageBase { @@ -81,8 +81,8 @@ namespace xhal { wisc::RPCMsg *m_wiscMsg; - /*! - * \brief Serializes custom types if possible or else supresses implicit type conversions + /** + * @brief Serializes custom types if possible or else supresses implicit type conversions * * Every type not defined hereunder is taken care of by this templated function. * The function serves two purposes: @@ -98,36 +98,36 @@ namespace xhal { serialize(*this, const_cast(t)); } - /*! - * \brief Adds a \c std::uint32_t to the message + /** + * @brief Adds a @c std::uint32_t to the message */ inline void save(const std::uint32_t value) { m_wiscMsg->set_word(std::to_string(dispenseKey()), value); } - /*! - * \brief Adds a \c std::vector to the message + /** + * @brief Adds a @c std::vector to the message */ inline void save(const std::vector &value) { m_wiscMsg->set_word_array(std::to_string(dispenseKey()), value); } - /*! - * \brief Adds a \c std::string to the message + /** + * @brief Adds a @c std::string to the message */ inline void save(const std::string &value) { m_wiscMsg->set_string(std::to_string(dispenseKey()), value); } - /*! - * \brief Adds a \c std::vector to the message + /** + * @brief Adds a @c std::vector to the message */ inline void save(const std::vector &value) { m_wiscMsg->set_string_array(std::to_string(dispenseKey()), value); } - /*! - * \brief Adds a \c std::array to the message where \c T is an integral type (except \c bool) + /** + * @brief Adds a @c std::array to the message where @c T is an integral type (except @c bool) */ templateset_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); } - /*! - * \brief Adds a \c std::map to the message where \c T is a serializable type + /** + * @brief Adds a @c std::map to the message where @c T is a serializable type */ template inline void save(const std::map &value) { // The first RPC key stores the std::map keys @@ -156,8 +156,8 @@ namespace xhal { m_wiscMsg->set_word_array(std::to_string(keysKey), keys); } - /*! - * \brief Adds a \c std::map to the message where \c T is a serializable type + /** + * @brief Adds a @c std::map to the message where @c T is a serializable type */ template inline void save(const std::map &value) { // The first RPC key stores the std::map keys @@ -175,8 +175,8 @@ namespace xhal { m_wiscMsg->set_string_array(std::to_string(keysKey), keys); } - /*! - * \brief Adds the content of a \c void_holder to the message + /** + * @brief Adds the content of a @c void_holder to the message * * It should be used when setting the result from a function call. */ @@ -184,15 +184,15 @@ namespace xhal { this->save(holder.get()); } - /*! - * \brief Specialization for the \c void special case + /** + * @brief Specialization for the @c void special case */ inline void save(compat::void_holder) {} - /*! - * \brief Serializes the arguments from a \c std::tuple + /** + * @brief Serializes the arguments from a @c std::tuple * - * \c std::tuple content is add from left to right to the message + * @c std::tuple content is add from left to right to the message * via a recursive template. It should be to serialize function arguments. */ templatesave(args); } - /*! - * \brief Terminal call + /** + * @brief Terminal call */ template inline MessageSerializer & operator<<(const T &t) { @@ -231,11 +231,11 @@ namespace xhal { return *this; } - /*! - * \brief Behaves as \c operator<< + /** + * @brief Behaves as @c operator<< * - * Is used for providing a unifed interface between \c MessageSerializer and - * \c MessageDeserializer so custom types serialization can be defined in a single + * Is used for providing a unifed interface between @c MessageSerializer and + * @c MessageDeserializer so custom types serialization can be defined in a single * function. */ template @@ -246,11 +246,11 @@ namespace xhal { }; - /*! - * \brief This class deserializes parameters from a \c wisc::RPCMsg + /** + * @brief This class deserializes parameters from a @c wisc::RPCMsg * - * While it cannot be made \c const because deserializing requires to keep - * track of the state, this class guarentees that the original \c wisc::RPCMsg + * While it cannot be made @c const because deserializing requires to keep + * track of the state, this class guarentees that the original @c wisc::RPCMsg * object will remain untouched. */ class MessageDeserializer : public MessageBase { @@ -259,8 +259,8 @@ namespace xhal { const wisc::RPCMsg *m_wiscMsg; - /*! - * \brief Deserializes custom types if possible or else supresses implicit type conversion + /** + * @brief Deserializes custom types if possible or else supresses implicit type conversion * * Every type not defined hereunder is taken care of by this templated function. * The function serves two purposes: @@ -274,36 +274,36 @@ namespace xhal { serialize(*this, t); } - /*! - * \brief Retrieves a \c std::uint32_t from the message + /** + * @brief Retrieves a @c std::uint32_t from the message */ inline void load(uint32_t &value) { value = m_wiscMsg->get_word(std::to_string(dispenseKey())); } - /*! - * \brief Retrieves a \c std::vector from the message + /** + * @brief Retrieves a @c std::vector from the message */ inline void load(std::vector &value) { value = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); } - /*! - * \brief Retrieves a \c std::string from the message + /** + * @brief Retrieves a @c std::string from the message */ inline void load(std::string &value) { value = m_wiscMsg->get_string(std::to_string(dispenseKey())); } - /*! - * \brief Retrieves a \c std::vector from the message + /** + * @brief Retrieves a @c std::vector from the message */ inline void load(std::vector &value) { value = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); } - /*! - * \brief Retrieves a \c std::array from the message where \c T is an integral type (except \c bool) + /** + * @brief Retrieves a @c std::array from the message where @c T is an integral type (except @c bool) */ templateget_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); } - /*! - * \brief Retrieves a \c std::map from the message where \c T is a serializable type + /** + * @brief Retrieves a @c std::map from the message where @c T is a serializable type */ template inline void load(std::map &value) { const auto keys = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); @@ -326,8 +326,8 @@ namespace xhal { } } - /*! - * \brief Retrieves a \c std::map from the message where \c T is a serializable type + /** + * @brief Retrieves a @c std::map from the message where @c T is a serializable type */ template inline void load(std::map &value) { const auto keys = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); @@ -339,9 +339,9 @@ namespace xhal { } } - /*! - * \brief Retrieves a \c T parameter from the message and stores it inside - * a \c void_holder. + /** + * @brief Retrieves a @c T parameter from the message and stores it inside + * a @c void_holder. * * It should be used when setting the result from a function. */ @@ -349,15 +349,15 @@ namespace xhal { this->load(value.get()); } - /*! - * \brief Specialization for the \c void special case + /** + * @brief Specialization for the @c void special case */ inline void load(compat::void_holder) {} - /*! - * \brief Fills in a \c std::tuple with data from the message + /** + * @brief Fills in a @c std::tuple with data from the message * - * \c std::tuple content is filled from left to right from the message + * @c std::tuple content is filled from left to right from the message * via a recursive template. It should be use to deserialize function * arguments. */ @@ -370,8 +370,8 @@ namespace xhal { this->load(args); } - /*! - * \brief Terminal call + /** + * @brief Terminal call */ template inline MessageDeserializer & operator>>(T &t) { @@ -397,11 +397,11 @@ namespace xhal { return *this; } - /*! - * \brief Behaves as \c operator<< + /** + * @brief Behaves as @c operator<< * - * Is used for providing a unifed interface between \c MessageSerializer and - * \c MessageDeserializer so custom types serialization can be defined in a single + * Is used for providing a unifed interface between @c MessageSerializer and + * @c MessageDeserializer so custom types serialization can be defined in a single * function. */ template @@ -412,16 +412,16 @@ namespace xhal { }; - /*! - * \brief Provides a default (de)serialiazer in case the intrusive method is used + /** + * @brief Provides a default (de)serialiazer in case the intrusive method is used */ template inline void serialize(Message &msg, T &t) { t.serialize(msg); } - /*! - * \brief Serializer for \c std::array where \c is a serializable type + /** + * @brief Serializer for @c std::array where @c is a serializable type * * This a simple example of custom type serialization. * @@ -432,7 +432,7 @@ namespace xhal { * * Let's take an example : * - * \code{.cpp} + * @code{.cpp} * struct Point * { * std::uint32_t x, y; @@ -453,10 +453,10 @@ namespace xhal { * msq & point.x & point.y; * } * } } - * \endcode + * @endcode * - * \warning In order to work as intended the \c serialize functions \b MUST modify - * the object only with the \c operator& + * @warning In order to work as intended the @c serialize functions @b MUST modify + * the object only with the @c operator& */ template inline void serialize(Message &msg, std::array &value) { diff --git a/xhal/include/xhal/common/rpc/compat.h b/xhal/include/xhal/common/rpc/compat.h index 9eec8b1..7163941 100644 --- a/xhal/include/xhal/common/rpc/compat.h +++ b/xhal/include/xhal/common/rpc/compat.h @@ -1,6 +1,6 @@ -/*! - * \file - * \brief Compatibility functionalities for C++11 +/** + * @file + * @brief Compatibility functionalities for C++11 * * This file includes all the functionalities that could advantageously be * replaced with newer versions of C++, e.g. C++14 and C++17. @@ -8,7 +8,7 @@ * Since the content of this file implements missing functionalties in the * C++11 standard, the coding style follows what is found in the STL. * - * \author Laurent Pétré + * @author Laurent Pétré */ #ifndef XHAL_COMMON_RPC_COMPAT_H @@ -22,14 +22,14 @@ namespace xhal { namespace rpc { namespace compat { - /*! - * \brief This class can encapsulates any type, including \c void + /** + * @brief This class can encapsulates any type, including @c void * - * \c void is an incomplete type and cannot be easily used in fully generic + * @c void is an incomplete type and cannot be easily used in fully generic * templates. This class is designed to hold any type, including `void` so that * it can be used in generic templates. * - * The embedded object can be retrieved with the \c get() methods. + * The embedded object can be retrieved with the @c get() methods. * * In C++17 any code using this class is easily replaced with the * constexpr if statement. @@ -41,24 +41,24 @@ namespace xhal { const T &get() const { return t; } }; - /*! - * \brief Specialization for the \c void type + /** + * @brief Specialization for the @c void type */ template<> struct void_holder { void get() const { return; } }; - /*! - * \brief This template class defines an indices sequence + /** + * @brief This template class defines an indices sequence * - * Please look at the \c integer_sequence from C++14 to get more + * Please look at the @c integer_sequence from C++14 to get more * information. */ template struct index_sequence {}; - /*! - * \brief Generates an indices sequence + /** + * @brief Generates an indices sequence * * The code follows the usual O(n) implementation. * @@ -67,8 +67,8 @@ namespace xhal { */ template struct index_sequence_gen; - /*! - * \brief Non-terminal call + /** + * @brief Non-terminal call */ template struct index_sequence_gen { @@ -77,33 +77,33 @@ namespace xhal { using type = typename index_sequence_gen::type; }; - /*! - * \brief Terminal call + /** + * @brief Terminal call */ template struct index_sequence_gen<0, N...> { using type = index_sequence; }; - /*! - * \brief Helper making an index sequence from \c 0 to \c N-1 + /** + * @brief Helper making an index sequence from @c 0 to @c N-1 * * Remind that an index sequence is the non-type template parameter of a - * specialization of the \c index_sequence template class. + * specialization of the @c index_sequence template class. */ template using make_index_sequence = typename index_sequence_gen::type; - /*! - * \brief Calls a function with arguments from a \c std::tuple + /** + * @brief Calls a function with arguments from a @c std::tuple * - * This function is the implementation part of a specialized \c std::apply + * This function is the implementation part of a specialized @c std::apply * implementation. More information can be found in the C++17 standard. * * Please note that these functions are applied to our case and do not - * pretend to respect the C++17 standard in any way. Moreover the \c void - * return case is handled with our \c void_holder container. This imposes - * the first template argument to be explicitly set when calling \c tuple_apply + * pretend to respect the C++17 standard in any way. Moreover the @c void + * return case is handled with our @c void_holder container. This imposes + * the first template argument to be explicitly set when calling @c tuple_apply */ template(f)(std::get(tuple)...); } - /*! - * \brief Generic case + /** + * @brief Generic case */ template + * @author Louis Moureaux */ #ifndef XHAL_COMMON_RPC_EXCEPTIONS_H @@ -16,61 +16,61 @@ namespace xhal { namespace helper { /** - * \brief Retrieves a user-friendly message for the given exception. + * @brief Retrieves a user-friendly message for the given exception. * - * Specialization for \c std::exception. + * Specialization for @c std::exception. */ std::string getExceptionMessage(const std::exception &e); /** - * \brief Retrieves a user-friendly message for the given exception. + * @brief Retrieves a user-friendly message for the given exception. * - * Specialization for \c wisc::RPCMsg::BadKeyException. + * Specialization for @c wisc::RPCMsg::BadKeyException. * - * \note This function is never called because the constructor of \c BadKeyException calls - * \c std::abort. It is kept in case the issue is corrected in the future. + * @note This function is never called because the constructor of @c BadKeyException calls + * @c std::abort. It is kept in case the issue is corrected in the future. */ std::string getExceptionMessage(const wisc::RPCMsg::BadKeyException &e); /** - * \brief Retrieves a user-friendly message for the given exception. + * @brief Retrieves a user-friendly message for the given exception. * - * Specialization for \c wisc::RPCMsg::TypeException. + * Specialization for @c wisc::RPCMsg::TypeException. */ std::string getExceptionMessage(const wisc::RPCMsg::TypeException &e); /** - * \brief Retrieves a user-friendly message for the given exception. + * @brief Retrieves a user-friendly message for the given exception. * - * Specialization for \c wisc::RPCMsg::BufferTooSmallException. + * Specialization for @c wisc::RPCMsg::BufferTooSmallException. */ std::string getExceptionMessage(const wisc::RPCMsg::BufferTooSmallException &e); /** - * \brief Retrieves a user-friendly message for the given exception. + * @brief Retrieves a user-friendly message for the given exception. * - * Specialization for \c wisc::RPCMsg::CorruptMessageException. + * Specialization for @c wisc::RPCMsg::CorruptMessageException. */ std::string getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e); /** - * \brief Retrieves a user-friendly message for the given exception. + * @brief Retrieves a user-friendly message for the given exception. * - * Specialization for \c wisc::RPCSvc::RPCException and derived types. + * Specialization for @c wisc::RPCSvc::RPCException and derived types. */ std::string getExceptionMessage(const wisc::RPCSvc::RPCException &e); /** - * \brief Sets the type of the current exception in \c response. - * \internal This function makes use of low-level functions of the Itanium C++ ABI to + * @brief Sets the type of the current exception in @c response. + * @internal This function makes use of low-level functions of the Itanium C++ ABI to * retrieve the type name of the current exception. */ void setExceptionType(wisc::RPCMsg *response); /** - * \brief Fetches an error message from \c response. + * @brief Fetches an error message from @c response. * - * The \c error key must be set and to a string. + * The @c error key must be set and to a string. */ std::string readExceptionMessage(const wisc::RPCMsg &response); diff --git a/xhal/include/xhal/common/rpc/helper.h b/xhal/include/xhal/common/rpc/helper.h index c14202b..3c6f6b0 100644 --- a/xhal/include/xhal/common/rpc/helper.h +++ b/xhal/include/xhal/common/rpc/helper.h @@ -1,12 +1,12 @@ -/*! - * \file - * \brief Centralize all the template helper tools +/** + * @file + * @brief Centralize all the template helper tools * * Since the content of this file could be integrated into a C++ * standard template metaprogramming, the coding style follows * what is found in the STL. * - * \author Laurent Pétré + * @author Laurent Pétré */ #ifndef XHAL_COMMON_RPC_HELPER_H @@ -20,16 +20,16 @@ namespace xhal { namespace rpc { namespace helper { - /*! - * \brief Allows to extract types of a functor + /** + * @brief Allows to extract types of a functor * * This templated class provides the return type and argument types * of a functor as traits. * - * * \c return_type is the functor return type - * * \c decay_args_type are the decayed (cv-qualifiers and reference are - * removed) argument types in a \c std::tuple - * * \c forward_as_tuple returns a function converting its arguments + * * @c return_type is the functor return type + * * @c decay_args_type are the decayed (cv-qualifiers and reference are + * removed) argument types in a @c std::tuple + * * @c forward_as_tuple returns a function converting its arguments * to the arguments functor types * * Inspired by https://stackoverflow.com/a/10400131 @@ -50,8 +50,8 @@ namespace xhal { } }; - /*! - * \brief Implementation of \c functor_return_t + /** + * @brief Implementation of @c functor_return_t * * Should not be used as a function. */ @@ -61,17 +61,17 @@ namespace xhal { > R functor_return_t_impl(Func); - /*! - * \brief Return type of the \c Obj functor + /** + * @brief Return type of the @c Obj functor * - * Only works with \c const call operators since \c functor_traits is + * Only works with @c const call operators since @c functor_traits is * only defined for those. */ template using functor_return_t = decltype(functor_return_t_impl(&Obj::operator())); - /*! - * \brief Implementation of \c functor_decay_args_t + /** + * @brief Implementation of @c functor_decay_args_t * * Should not be used as a function. */ @@ -81,31 +81,31 @@ namespace xhal { > Args functor_decay_args_t_impl(Func); - /*! - * \brief \c std::tuple whose types are the functor argument types + /** + * @brief @c std::tuple whose types are the functor argument types * - * Only works with \c const call operators since \c functor_traits is + * Only works with @c const call operators since @c functor_traits is * only defined for those. */ template using functor_decay_args_t = decltype(functor_decay_args_t_impl(&Obj::operator())); - /*! - * \brief Helper function to forward as a tuple matching the functor signature + /** + * @brief Helper function to forward as a tuple matching the functor signature */ template constexpr inline auto get_forward_as_tuple() { return functor_traits::forward_as_tuple(); } - /*! - * \brief Checks whether the template parameter \c T is a \c bool + /** + * @brief Checks whether the template parameter @c T is a @c bool */ template using is_bool = std::is_same::type, bool>; - /*! - * \brief Checks whether the template parameter \c T is a \c std::tuple + /** + * @brief Checks whether the template parameter @c T is a @c std::tuple */ template struct is_tuple_impl : std::false_type {}; @@ -113,8 +113,8 @@ namespace xhal { template struct is_tuple_impl> : std::true_type {}; - /*! - * \brief Helper alias for cv-qualified and reference types + /** + * @brief Helper alias for cv-qualified and reference types */ template using is_tuple = is_tuple_impl::type>; diff --git a/xhal/include/xhal/common/rpc/register.h b/xhal/include/xhal/common/rpc/register.h index 056b653..3224e8b 100644 --- a/xhal/include/xhal/common/rpc/register.h +++ b/xhal/include/xhal/common/rpc/register.h @@ -1,10 +1,10 @@ -/*! - * \file - * \brief This file contains all the functions needed to register +/** + * @file + * @brief This file contains all the functions needed to register * a remotely callable RPC method * - * \author Laurent Pétré - * \author Louis Moureaux + * @author Laurent Pétré + * @author Louis Moureaux */ #ifndef XHAL_COMMON_RPC_REGISTER_H @@ -25,9 +25,9 @@ namespace xhal { namespace helper { /** - * \brief Handles an exception, setting the error key on the response. + * @brief Handles an exception, setting the error key on the response. * - * In case a second exception occurs when setting the error key, \c std::terminate is called. + * In case a second exception occurs when setting the error key, @c std::terminate is called. */ template void handleException(const Exception &e, wisc::RPCMsg *response) noexcept @@ -37,10 +37,10 @@ namespace xhal { setExceptionType(response); } - /* - * Handles an unknown exception, setting the error key on the response. + /** + * @brief Handles an unknown exception, setting the error key on the response. * - * In case an exception occurs when setting the error key, \c std::terminate is called. + * In case an exception occurs when setting the error key, @c std::terminate is called. */ void handleException(wisc::RPCMsg *response) noexcept { @@ -51,12 +51,12 @@ namespace xhal { } // namespace helper - /*! - * \brief Locally invoke a RPC method + /** + * @brief Locally invoke a RPC method * * This function is the wrapper called for every remote function call. It - * deserializes the arguments from the \c wisc::RPCMsg, calls the local functor - * and then serializes the return value to the \c wisc::RPCMsg. + * deserializes the arguments from the @c wisc::RPCMsg, calls the local functor + * and then serializes the return value to the @c wisc::RPCMsg. */ template::value, int>::type = 0 @@ -93,8 +93,8 @@ namespace xhal { } } - /*! - * \brief Register a RPC method into the \c ModuleManager + /** + * @brief Register a RPC method into the @c ModuleManager * * This helper function register a RPC method with the right parameters * so it can be remotely called. diff --git a/xhal/include/xhal/server/LMDB.h b/xhal/include/xhal/server/LMDB.h index 57e0f77..cfe73f9 100644 --- a/xhal/include/xhal/server/LMDB.h +++ b/xhal/include/xhal/server/LMDB.h @@ -1,8 +1,8 @@ -/*! - * \file - * \brief This file contains utilities dealing with the LMDB register database. +/** + * @file + * @brief This file contains utilities dealing with the LMDB register database. * - * \author Louis Moureaux + * @author Louis Moureaux */ #ifndef XHAL_SERVER_LMDB_H @@ -14,7 +14,7 @@ namespace xhal { namespace server { /** - * \brief Provides access to shared LMDB data structures. + * @brief Provides access to shared LMDB data structures. * * This class uses the "guard" pattern to provide access to LMDB data structures: an * environment, a database handle and a read-only transaction. These objects are @@ -30,69 +30,69 @@ namespace xhal { * When the first guard is created, it sets up the objects required to read from the * database. These objects are released automatically when the last guard is deleted. * - * \warning This class is not thread-safe. + * @warning This class is not thread-safe. */ class LMDBGuard { public: /** - * \brief Constructs a guard. + * @brief Constructs a guard. */ LMDBGuard(); /** - * \brief Copy constructor. + * @brief Copy constructor. */ LMDBGuard(const LMDBGuard &) = default; /** - * \brief Assignment operator. + * @brief Assignment operator. */ LMDBGuard &operator=(const LMDBGuard &) = default; /** - * \brief Move constructor. + * @brief Move constructor. */ constexpr LMDBGuard(LMDBGuard &&) = default; /** - * \brief Move operator. + * @brief Move operator. */ // Can't be made constexpr in GCC 4.9 LMDBGuard &operator=(LMDBGuard &&) = default; /** - * \brief Destructor. Resources are freed when the last guard is deleted. + * @brief Destructor. Resources are freed when the last guard is deleted. */ ~LMDBGuard() noexcept; /** - * \brief Retrieves the LMDB environment. + * @brief Retrieves the LMDB environment. */ lmdb::env &env() noexcept; /** - * \brief Retrieves the LMDB environment (\c const version). + * @brief Retrieves the LMDB environment (@c const version). */ const lmdb::env &env() const noexcept; /** - * \brief Retrieves the LMDB database handle. + * @brief Retrieves the LMDB database handle. */ lmdb::dbi &dbi() noexcept; /** - * \brief Retrieves the LMDB database handle (\c const version). + * @brief Retrieves the LMDB database handle (@c const version). */ const lmdb::dbi &dbi() const noexcept; /** - * \brief Retrieves a read-only LMDB transaction. + * @brief Retrieves a read-only LMDB transaction. */ lmdb::txn &rtxn() noexcept; /** - * \brief Retrieves a read-only LMDB transaction (\c const version). + * @brief Retrieves a read-only LMDB transaction (@c const version). */ const lmdb::txn &rtxn() const noexcept; }; diff --git a/xhal/src/common/rpc/exceptions.cpp b/xhal/src/common/rpc/exceptions.cpp index 75df1a8..44e2fdb 100644 --- a/xhal/src/common/rpc/exceptions.cpp +++ b/xhal/src/common/rpc/exceptions.cpp @@ -4,70 +4,60 @@ #include "cxxabi.h" // C++ Itanium ABI -namespace xhal { - namespace common { - namespace rpc { - namespace helper { - - std::string getExceptionMessage(const std::exception &e) - { - return e.what(); - } - - std::string getExceptionMessage(const wisc::RPCMsg::BadKeyException &e) - { - return "bad RPC key: " + e.key; - } +std::string xhal::common::rpc::helper::getExceptionMessage(const std::exception &e) +{ + return e.what(); +} - std::string getExceptionMessage(const wisc::RPCMsg::TypeException &e) - { - return "RPC type error"; - } +std::string xhal::common::rpc::helper::getExceptionMessage(const wisc::RPCMsg::BadKeyException &e) +{ + return "bad RPC key: " + e.key; +} - std::string getExceptionMessage(const wisc::RPCMsg::BufferTooSmallException &e) - { - return "buffer too small"; - } +std::string xhal::common::rpc::helper::getExceptionMessage(const wisc::RPCMsg::TypeException &e) +{ + return "RPC type error"; +} - std::string getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e) - { - return "corrupt RPC message: " + e.reason; - } +std::string xhal::common::rpc::helper::getExceptionMessage(const wisc::RPCMsg::BufferTooSmallException &e) +{ + return "buffer too small"; +} - std::string getExceptionMessage(const wisc::RPCSvc::RPCException &e) - { - return e.message; - } +std::string xhal::common::rpc::helper::getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e) +{ + return "corrupt RPC message: " + e.reason; +} - void setExceptionType(wisc::RPCMsg *response) - { - // Fetch the type of the current exception - const std::type_info *exceptionType = abi::__cxa_current_exception_type(); - if (exceptionType != nullptr) { - // Try to demangle it - char *demangled = abi::__cxa_demangle(exceptionType->name(), - nullptr, nullptr, nullptr); - if (demangled != nullptr) { - response->set_string(std::string(abiVersion) + ".type", demangled); - std::free(demangled); - } else { - // Could not demangle, use raw name - response->set_string(std::string(abiVersion) + ".type", exceptionType->name()); - } - } - } +std::string xhal::common::rpc::helper::getExceptionMessage(const wisc::RPCSvc::RPCException &e) +{ + return e.message; +} - std::string readExceptionMessage(const wisc::RPCMsg &response) - { - std::string msg = "remote error: "; - if (response.get_key_exists(std::string(abiVersion) + ".type")) { - msg += response.get_string(std::string(abiVersion) + ".type") + ": "; - } - msg += response.get_string(std::string(abiVersion) + ".error"); - return msg; +void xhal::common::rpc::helper::setExceptionType(wisc::RPCMsg *response) +{ + // Fetch the type of the current exception + const std::type_info *exceptionType = abi::__cxa_current_exception_type(); + if (exceptionType != nullptr) { + // Try to demangle it + char *demangled = abi::__cxa_demangle(exceptionType->name(), + nullptr, nullptr, nullptr); + if (demangled != nullptr) { + response->set_string(std::string(abiVersion) + ".type", demangled); + std::free(demangled); + } else { + // Could not demangle, use raw name + response->set_string(std::string(abiVersion) + ".type", exceptionType->name()); } + } +} - } - } +std::string xhal::common::rpc::helper::readExceptionMessage(const wisc::RPCMsg &response) +{ + std::string msg = "remote error: "; + if (response.get_key_exists(std::string(abiVersion) + ".type")) { + msg += response.get_string(std::string(abiVersion) + ".type") + ": "; } + msg += response.get_string(std::string(abiVersion) + ".error"); + return msg; } From dc5c2ad9982e311aa145e586a215e142cd52663e Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 22:17:11 +0200 Subject: [PATCH 39/56] [style] Standardize source file namespace style --- xhal/src/server/LMDB.cpp | 216 +++++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 110 deletions(-) diff --git a/xhal/src/server/LMDB.cpp b/xhal/src/server/LMDB.cpp index 6168ae1..f235eb7 100644 --- a/xhal/src/server/LMDB.cpp +++ b/xhal/src/server/LMDB.cpp @@ -6,116 +6,112 @@ #define PATH_VAR "GEM_PATH" #define DB_NAME "/address_table.mdb" -namespace xhal { - namespace server { - namespace /* anonymous */ { - /// \brief Maximum size of the LMDB object, currently 50 MiB; - static const std::size_t MAP_SIZE = 50UL * 1024UL * 1024UL; - - /** - * \brief Creates the environment. - * - * Required as a separate function for the Singleton constructor. - */ - lmdb::env create_env() - { - auto env = lmdb::env::create(); - env.set_mapsize(MAP_SIZE); - - const char * path = std::getenv(PATH_VAR); - if (path == nullptr) { - throw std::runtime_error("Environment variable " PATH_VAR " is not defined"); - } - std::string fullPath = path; - fullPath += DB_NAME;; - env.open(fullPath.c_str(), 0, 0664); - - return env; - } - - /** - * \brief Shared data managed by the guards. - */ - struct Singleton - { - // NOTE: Order is important! - lmdb::env env; ///< \brief Environment - lmdb::txn rtxn; ///< \brief Read-only transaction - lmdb::dbi dbi; ///< \brief Database handle - - /** - * \brief Constructor. - * - * A constructor is required because LMDB objects don't have default constructors. - */ - Singleton() : // NOTE: Order is important! - env(create_env()), - rtxn(lmdb::txn::begin(env, nullptr, MDB_RDONLY)), - dbi(lmdb::dbi::open(rtxn, nullptr)) - { - } - }; - - /** - * \brief Points to the data managed by the guards. - */ - std::unique_ptr SINGLETON = nullptr; - - /** - * \brief The number of guards currently active. - */ - int GUARD_COUNT = 0; - } // anonymous namespace - - LMDBGuard::LMDBGuard() - { - if (GUARD_COUNT <= 0 || SINGLETON == nullptr) { - SINGLETON = std::unique_ptr(); // Initialize - GUARD_COUNT = 1; - } else if (GUARD_COUNT == std::numeric_limits::max()) { - throw std::runtime_error("Out of LMDB guard handles"); - } else { - ++GUARD_COUNT; // Add a reference - } - } - - LMDBGuard::~LMDBGuard() noexcept - { - --GUARD_COUNT; - if (GUARD_COUNT <= 0) { - // Free shared resources - SINGLETON = nullptr; - } - } - - lmdb::env &LMDBGuard::env() noexcept - { - return SINGLETON->env; - } - - const lmdb::env &LMDBGuard::env() const noexcept - { - return SINGLETON->env; +namespace /* anonymous */ { + /// \brief Maximum size of the LMDB object, currently 50 MiB; + static const std::size_t MAP_SIZE = 50UL * 1024UL * 1024UL; + + /** + * \brief Creates the environment. + * + * Required as a separate function for the Singleton constructor. + */ + lmdb::env create_env() + { + auto env = lmdb::env::create(); + env.set_mapsize(MAP_SIZE); + + const char * path = std::getenv(PATH_VAR); + if (path == nullptr) { + throw std::runtime_error("Environment variable " PATH_VAR " is not defined"); } - - lmdb::dbi &LMDBGuard::dbi() noexcept - { - return SINGLETON->dbi; - } - - const lmdb::dbi &LMDBGuard::dbi() const noexcept - { - return SINGLETON->dbi; - } - - lmdb::txn &LMDBGuard::rtxn() noexcept - { - return SINGLETON->rtxn; - } - - const lmdb::txn &LMDBGuard::rtxn() const noexcept + std::string fullPath = path; + fullPath += DB_NAME;; + env.open(fullPath.c_str(), 0, 0664); + + return env; + } + + /** + * \brief Shared data managed by the guards. + */ + struct Singleton + { + // NOTE: Order is important! + lmdb::env env; ///< \brief Environment + lmdb::txn rtxn; ///< \brief Read-only transaction + lmdb::dbi dbi; ///< \brief Database handle + + /** + * \brief Constructor. + * + * A constructor is required because LMDB objects don't have default constructors. + */ + Singleton() : // NOTE: Order is important! + env(create_env()), + rtxn(lmdb::txn::begin(env, nullptr, MDB_RDONLY)), + dbi(lmdb::dbi::open(rtxn, nullptr)) { - return SINGLETON->rtxn; } - } // namespace xhal::server -} // namespace xhal + }; + + /** + * \brief Points to the data managed by the guards. + */ + std::unique_ptr SINGLETON = nullptr; + + /** + * \brief The number of guards currently active. + */ + int GUARD_COUNT = 0; +} // anonymous namespace + +xhal::server::LMDBGuard::LMDBGuard() +{ + if (GUARD_COUNT <= 0 || SINGLETON == nullptr) { + SINGLETON = std::unique_ptr(); // Initialize + GUARD_COUNT = 1; + } else if (GUARD_COUNT == std::numeric_limits::max()) { + throw std::runtime_error("Out of LMDB guard handles"); + } else { + ++GUARD_COUNT; // Add a reference + } +} + +xhal::server::LMDBGuard::~LMDBGuard() noexcept +{ + --GUARD_COUNT; + if (GUARD_COUNT <= 0) { + // Free shared resources + SINGLETON = nullptr; + } +} + +lmdb::env &xhal::server::LMDBGuard::env() noexcept +{ + return SINGLETON->env; +} + +const lmdb::env &xhal::server::LMDBGuard::env() const noexcept +{ + return SINGLETON->env; +} + +lmdb::dbi &xhal::server::LMDBGuard::dbi() noexcept +{ + return SINGLETON->dbi; +} + +const lmdb::dbi &xhal::server::LMDBGuard::dbi() const noexcept +{ + return SINGLETON->dbi; +} + +lmdb::txn &xhal::server::LMDBGuard::rtxn() noexcept +{ + return SINGLETON->rtxn; +} + +const lmdb::txn &xhal::server::LMDBGuard::rtxn() const noexcept +{ + return SINGLETON->rtxn; +} From 27fab7b734123725670ee94ed247fe56d51955cd Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 22:18:05 +0200 Subject: [PATCH 40/56] [style] Standardize Doxygen comment style --- xhal/src/server/LMDB.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/xhal/src/server/LMDB.cpp b/xhal/src/server/LMDB.cpp index f235eb7..7e06aff 100644 --- a/xhal/src/server/LMDB.cpp +++ b/xhal/src/server/LMDB.cpp @@ -7,11 +7,11 @@ #define DB_NAME "/address_table.mdb" namespace /* anonymous */ { - /// \brief Maximum size of the LMDB object, currently 50 MiB; + /// @brief Maximum size of the LMDB object, currently 50 MiB; static const std::size_t MAP_SIZE = 50UL * 1024UL * 1024UL; /** - * \brief Creates the environment. + * @brief Creates the environment. * * Required as a separate function for the Singleton constructor. */ @@ -32,17 +32,17 @@ namespace /* anonymous */ { } /** - * \brief Shared data managed by the guards. + * @brief Shared data managed by the guards. */ struct Singleton { // NOTE: Order is important! - lmdb::env env; ///< \brief Environment - lmdb::txn rtxn; ///< \brief Read-only transaction - lmdb::dbi dbi; ///< \brief Database handle + lmdb::env env; ///< @brief Environment + lmdb::txn rtxn; ///< @brief Read-only transaction + lmdb::dbi dbi; ///< @brief Database handle /** - * \brief Constructor. + * @brief Constructor. * * A constructor is required because LMDB objects don't have default constructors. */ @@ -55,12 +55,12 @@ namespace /* anonymous */ { }; /** - * \brief Points to the data managed by the guards. + * @brief Points to the data managed by the guards. */ std::unique_ptr SINGLETON = nullptr; /** - * \brief The number of guards currently active. + * @brief The number of guards currently active. */ int GUARD_COUNT = 0; } // anonymous namespace From 323da320c6e9b64e4d8cfb281f02f3d73ca52b77 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 22:40:41 +0200 Subject: [PATCH 41/56] [style] Standardize whitespace and brace style in `client` header files --- xhal/include/xhal/client/XHALDevice.h | 16 +++--- xhal/include/xhal/client/XHALInterface.h | 51 +++++++++---------- .../xhal/client/rpcman/calibration_routines.h | 28 +++++----- xhal/include/xhal/client/rpcman/daq_monitor.h | 24 +++++---- xhal/include/xhal/client/rpcman/optohybrid.h | 9 +++- xhal/include/xhal/client/rpcman/utils.h | 16 ++++-- xhal/include/xhal/client/rpcman/vfat3.h | 15 ++++-- 7 files changed, 92 insertions(+), 67 deletions(-) diff --git a/xhal/include/xhal/client/XHALDevice.h b/xhal/include/xhal/client/XHALDevice.h index 805d178..5326a89 100644 --- a/xhal/include/xhal/client/XHALDevice.h +++ b/xhal/include/xhal/client/XHALDevice.h @@ -3,7 +3,7 @@ * Hardware device for XHAL * * @author Mykhailo Dalchenko - * @version 1.0 + * @version 1.0 */ #ifndef XHAL_CLIENT_XHALDEVICE_H @@ -31,13 +31,14 @@ namespace xhal { * @param address_table_filename XML address table file name */ XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename); - virtual ~XHALDevice(){} - + + virtual ~XHALDevice() {} + /** * @brief Reconnect to RPC service and reload required modules */ virtual void reconnect(); - + /** * @brief read FW register by its name * applies reading mask if any @@ -54,7 +55,7 @@ namespace xhal { */ void writeReg(std::string regName, uint32_t value); //void writeReg(uint32_t address, uint32_t value); - + /** * @brief Read list of FW registers by their addresses * FIXME reg mask is ignored?? @@ -64,7 +65,7 @@ namespace xhal { * @param size Size of the above arrays */ uint32_t getList(uint32_t* addresses, uint32_t* result, ssize_t size); - + /** * @brief Read block of 32-bit registers starting from a given address * @@ -73,7 +74,7 @@ namespace xhal { * @param size Size of the above array */ uint32_t getBlock(uint32_t address, uint32_t* result, ssize_t size); - + private: std::string m_address_table_filename; xhal::common::utils::XHALXMLParser * m_parser; @@ -81,4 +82,5 @@ namespace xhal { }; } } + #endif // XHAL_CLIENT_XHALDEVICE_H diff --git a/xhal/include/xhal/client/XHALInterface.h b/xhal/include/xhal/client/XHALInterface.h index ccc0e54..b671bee 100644 --- a/xhal/include/xhal/client/XHALInterface.h +++ b/xhal/include/xhal/client/XHALInterface.h @@ -21,35 +21,33 @@ #define XHAL_TRACE(MSG) LOG4CPLUS_TRACE(m_logger, MSG) #define XHAL_DEBUG(MSG) LOG4CPLUS_DEBUG(m_logger, MSG) -#define XHAL_INFO(MSG) LOG4CPLUS_INFO(m_logger, MSG) -#define XHAL_WARN(MSG) LOG4CPLUS_WARN(m_logger, MSG) +#define XHAL_INFO(MSG) LOG4CPLUS_INFO(m_logger, MSG) +#define XHAL_WARN(MSG) LOG4CPLUS_WARN(m_logger, MSG) #define XHAL_ERROR(MSG) LOG4CPLUS_ERROR(m_logger, MSG) #define XHAL_FATAL(MSG) LOG4CPLUS_FATAL(m_logger, MSG) -#define STANDARD_CATCH \ - catch (wisc::RPCSvc::NotConnectedException &e) { \ - XHAL_ERROR("Caught NotConnectedException: " << e.message.c_str()); \ - throw xhal::common::utils::XHALRPCNotConnectedException("RPC NotConnectedException: " + e.message);\ - } \ - catch (wisc::RPCSvc::RPCErrorException &e) { \ - XHAL_ERROR("Caught RPCErrorException: " << e.message.c_str()); \ - throw xhal::common::utils::XHALRPCException("RPC ErrorException: " + e.message);\ - } \ - catch (wisc::RPCSvc::RPCException &e) { \ - XHAL_ERROR("Caught exception: " << e.message.c_str()); \ - throw xhal::common::utils::XHALRPCException("RPC exception: " + e.message);\ - } \ - catch (wisc::RPCMsg::BadKeyException &e) { \ - XHAL_ERROR("Caught exception: " << e.key.c_str()); \ - throw xhal::common::utils::XHALRPCException("RPC BadKeyException (most probably remote register not accessible): " + e.key);\ - } - -#define ASSERT(x) do { \ - if (!(x)) { \ - printf("Assertion Failed on line %u: %s\n", __LINE__, #x); \ - throw xhal::common::utils::XHALException("ASSERT failure");\ - } \ - } while (0) +#define STANDARD_CATCH \ + catch (wisc::RPCSvc::NotConnectedException &e) { \ + XHAL_ERROR("Caught NotConnectedException: " << e.message.c_str()); \ + throw xhal::common::utils::XHALRPCNotConnectedException("RPC NotConnectedException: " + e.message); \ + } catch (wisc::RPCSvc::RPCErrorException &e) { \ + XHAL_ERROR("Caught RPCErrorException: " << e.message.c_str()); \ + throw xhal::common::utils::XHALRPCException("RPC ErrorException: " + e.message); \ + } catch (wisc::RPCSvc::RPCException &e) { \ + XHAL_ERROR("Caught exception: " << e.message.c_str()); \ + throw xhal::common::utils::XHALRPCException("RPC exception: " + e.message); \ + } catch (wisc::RPCMsg::BadKeyException &e) { \ + XHAL_ERROR("Caught exception: " << e.key.c_str()); \ + throw xhal::common::utils::XHALRPCException("RPC BadKeyException (most probably remote register not accessible): " + e.key); \ + } + +#define ASSERT(x) \ + do { \ + if (!(x)) { \ + printf("Assertion Failed on line %u: %s\n", __LINE__, #x); \ + throw xhal::common::utils::XHALException("ASSERT failure"); \ + } \ + } while (0) namespace xhal { namespace client { @@ -65,6 +63,7 @@ namespace xhal { * @param board_domain_name domain name of CTP7 */ XHALInterface(const std::string& board_domain_name); + /** * @brief Constructor, taking also the external logger * @param board_domain_name domain name of CTP7 diff --git a/xhal/include/xhal/client/rpcman/calibration_routines.h b/xhal/include/xhal/client/rpcman/calibration_routines.h index cb3a52c..58a6d52 100644 --- a/xhal/include/xhal/client/rpcman/calibration_routines.h +++ b/xhal/include/xhal/client/rpcman/calibration_routines.h @@ -8,7 +8,7 @@ namespace xhal { namespace rpcman { /** * @class CalRoutines - * @brief Provides interface to call remote utility methods + * @brief Provides interface to call remote calibration_routines methods */ class CalRoutines : public xhal::client::XHALInterface { @@ -19,16 +19,20 @@ namespace xhal { * Loads the neccessary remote modules * @param board_domain_name domain name of CTP7 */ - CalRoutines(const std::string& board_domain_name):xhal::client::XHALInterface(board_domain_name){this->loadModule("calibration_routines", "calibration_routines v1.0.1");} - - ~CalRoutines(){} - + CalRoutines(const std::string& board_domain_name) : + xhal::client::XHALInterface(board_domain_name) + { + this->loadModule("calibration_routines", "calibration_routines v1.0.1"); + } + + ~CalRoutines() {} + //FIXME Add documentation uint32_t checkSbitMappingWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t nevts, uint32_t L1Ainterval, uint32_t pulseDelay, uint32_t *data); - + //FIXME Add documentation uint32_t checkSbitRateWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t waitTime, uint32_t pulseRate, uint32_t pulseDelay, uint32_t *outDataCTP7Rate, uint32_t *outDataFPGAClusterCntRate, uint32_t *outDataVFATSBits); - + /** * @brief Runs a generic scan routine for a specific channel of a VFAT chip * @@ -37,7 +41,7 @@ namespace xhal { * @param dacMin Min value of scanned variable * @param dacMax Max value of scanned variable * @param dacStep Step parameter - * @param ch VFAT channel + * @param ch VFAT channel * @param useCalPulse Indicates whether to use internal calibration pulses * @param currentPulse Indicates whether to use current or voltage internal calibration pulse * @param calScaleFactor FIXME @@ -48,7 +52,7 @@ namespace xhal { * @param result An array carrying scan results */ uint32_t genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t mask, char * scanReg, bool useUltra, bool useExtTrig, uint32_t * result); - + /** * @brief Runs a generic scan routine on all channels of a VFAT chip * @@ -68,10 +72,10 @@ namespace xhal { */ //FIXME Should we rearrange parameters so they are in the same order as in genScan? uint32_t genChannelScan(uint32_t nevts, uint32_t ohN, uint32_t mask, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, bool useExtTrig, char * scanReg, bool useUltra, uint32_t * result); - + //FIXME Add documentation uint32_t sbitRateScan(uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t maskOh, bool invertVFATPos, char * scanReg, uint32_t waitTime, uint32_t * resultDacVal, uint32_t * resultTrigRate, uint32_t * resultTrigRatePerVFAT, bool isParallel); - + /** * @brief configure TTC generator * @@ -95,7 +99,7 @@ namespace xhal { * enable = true (false) start (stop) the T1Controller for link ohN */ uint32_t ttcGenConf(uint32_t ohN, uint32_t mode, uint32_t type, uint32_t pulseDelay, uint32_t L1Ainterval, uint32_t nPulses, bool enable); - + /** * @brief Toggles TTC behavior * diff --git a/xhal/include/xhal/client/rpcman/daq_monitor.h b/xhal/include/xhal/client/rpcman/daq_monitor.h index f94b676..71b4c16 100644 --- a/xhal/include/xhal/client/rpcman/daq_monitor.h +++ b/xhal/include/xhal/client/rpcman/daq_monitor.h @@ -9,7 +9,7 @@ namespace xhal { namespace rpcman { /** * @class DaqMonitor - * @brief Provides interface to call remote utility methods + * @brief Provides interface to call remote daq_monitor methods */ class DaqMonitor : public xhal::client::XHALInterface { @@ -20,10 +20,14 @@ namespace xhal { * Loads the neccessary remote modules * @param board_domain_name domain name of CTP7 */ - DaqMonitor(const std::string& board_domain_name):xhal::client::XHALInterface(board_domain_name){this->loadModule("amc", "amc v1.0.1");} - - ~DaqMonitor(){} - + DaqMonitor(const std::string& board_domain_name) : + xhal::client::XHALInterface(board_domain_name) + { + this->loadModule("amc", "amc v1.0.1"); + } + + ~DaqMonitor() {} + /** * @brief get an array of values for TTC main monitoring table * @@ -31,7 +35,7 @@ namespace xhal { */ //uint32_t getmonTTCmain(uint32_t* result); PyListUint32 getmonTTCmain(); - + /** * @brief get an array of values for TRIGGER main monitoring table * @@ -39,7 +43,7 @@ namespace xhal { * @return an array of monitoring values */ PyListUint32 getmonTRIGGERmain(uint32_t noh = 12); - + /** * @brief get an array of values for TRIGGER OH main monitoring table * @@ -47,14 +51,14 @@ namespace xhal { * @return an array of monitoring values */ PyListUint32 getmonTRIGGEROHmain(uint32_t noh = 12); - + /** * @brief get an array of values for DAQ main monitoring table * * @return an array of monitoring values */ PyListUint32 getmonDAQmain(); - + /** * @brief get an array of values for DAQ OH main monitoring table * @@ -62,7 +66,7 @@ namespace xhal { * @return an array of monitoring values */ PyListUint32 getmonDAQOHmain(uint32_t noh = 12); - + /** * @brief get an array of values for OH main monitoring table * diff --git a/xhal/include/xhal/client/rpcman/optohybrid.h b/xhal/include/xhal/client/rpcman/optohybrid.h index 9bb1bbe..7f32a60 100644 --- a/xhal/include/xhal/client/rpcman/optohybrid.h +++ b/xhal/include/xhal/client/rpcman/optohybrid.h @@ -6,7 +6,12 @@ namespace xhal { namespace client { namespace rpcman { - class Optohybrid : public xhal::client::XHALDevice { + /** + * @class Optohybrid + * @brief Provides interface to call remote optohybrid methods + */ + class Optohybrid : public xhal::client::XHALDevice + { public: /** * @brief Default constructor @@ -16,7 +21,7 @@ namespace xhal { * @param address_table_filename XML address table file name */ Optohybrid(const std::string& board_domain_name, const std::string& address_table_filename); - + //FIXME provide documentation uint32_t broadcastRead(uint32_t ohN, char * regName, uint32_t vfatMask, uint32_t * result); uint32_t broadcastWrite(uint32_t ohN, char * regName, uint32_t value, uint32_t vfatMask); diff --git a/xhal/include/xhal/client/rpcman/utils.h b/xhal/include/xhal/client/rpcman/utils.h index 1e10ab9..23a4b18 100644 --- a/xhal/include/xhal/client/rpcman/utils.h +++ b/xhal/include/xhal/client/rpcman/utils.h @@ -12,7 +12,7 @@ namespace xhal { namespace rpcman { /** * @class Utils - * @brief Provides interface to call remote utility methods + * @brief Provides interface to call remote utility methods */ class Utils : public xhal::client::XHALInterface { @@ -23,12 +23,18 @@ namespace xhal { * Loads the neccessary remote modules * @param board_domain_name domain name of CTP7 */ - Utils(const std::string& board_domain_name):xhal::client::XHALInterface(board_domain_name){this->loadModule("utils", "utils v1.0.1");} - ~Utils(){} + Utils(const std::string& board_domain_name) : + xhal::client::XHALInterface(board_domain_name) + { + this->loadModule("utils", "utils v1.0.1"); + } + + ~Utils() {} + uint32_t update_atdb(char * xmlfilename); uint32_t getRegInfoDB(char * regName); - }; - + }; + } } } diff --git a/xhal/include/xhal/client/rpcman/vfat3.h b/xhal/include/xhal/client/rpcman/vfat3.h index 2e89e82..2417c6d 100644 --- a/xhal/include/xhal/client/rpcman/vfat3.h +++ b/xhal/include/xhal/client/rpcman/vfat3.h @@ -6,7 +6,12 @@ namespace xhal { namespace client { namespace rpcman { - class VFAT3 : public xhal::client::XHALDevice { + /** + * @class VFAT3 + * @brief Provides interface to call remote vfat3 methods + */ + class VFAT3 : public xhal::client::XHALDevice + { public: /** * @brief Default constructor @@ -16,13 +21,13 @@ namespace xhal { * @param address_table_filename XML address table file name */ VFAT3(const std::string& board_domain_name, const std::string& address_table_filename); - + //FIXME provide docs /** * @brief load configuration parameters to VFAT3 chips */ uint32_t configureVFAT3s(uint32_t ohN, uint32_t vfatMask); - + /** * @brief reads channel registers of all unmasked vfats on ohN * @param ohN Optohybrid optical link number @@ -30,7 +35,7 @@ namespace xhal { * @param chanRegData array pointer for channel register data with 3072 entries, the (vfat,chan) pairing determines the array index via: idx = vfat*128 + chan */ uint32_t getChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData); - + /** * @brief sets all vfat3 channel registers * @param ohN Optohybrid optical link number @@ -43,7 +48,7 @@ namespace xhal { * @param trimZCCPol as calEnable but for zero crossing comparator trim polarity */ uint32_t setChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *calEnable, uint32_t *masks, uint32_t *trimARM, uint32_t *trimARMPol, uint32_t *trimZCC, uint32_t *trimZCCPol); - + /** * @brief sets all vfat3 channel registers using a single channel register array * @param ohN Optohybrid optical link number From a1079b0297ae077233966f7899511ed82af613f9 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 22:49:55 +0200 Subject: [PATCH 42/56] [style] Standardize whitespace and brace style in `client` source files --- xhal/src/client/XHALDevice.cpp | 137 +++-- xhal/src/client/XHALInterface.cpp | 58 +-- .../python_wrappers/XHALInterface_python.cpp | 4 +- .../rpc_manager/calibration_routines.cpp | 473 +++++++++--------- xhal/src/client/rpc_manager/daq_monitor.cpp | 310 ++++++------ xhal/src/client/rpc_manager/optohybrid.cpp | 301 ++++++----- xhal/src/client/rpc_manager/utils.cpp | 59 ++- xhal/src/client/rpc_manager/vfat3.cpp | 150 +++--- 8 files changed, 711 insertions(+), 781 deletions(-) diff --git a/xhal/src/client/XHALDevice.cpp b/xhal/src/client/XHALDevice.cpp index 0c41e83..c3f4c60 100644 --- a/xhal/src/client/XHALDevice.cpp +++ b/xhal/src/client/XHALDevice.cpp @@ -1,6 +1,6 @@ #include "xhal/client/XHALDevice.h" -xhal::client::XHALDevice::XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename): +xhal::client::XHALDevice::XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename) : xhal::client::XHALInterface(board_domain_name), m_address_table_filename(address_table_filename) { @@ -16,7 +16,7 @@ xhal::client::XHALDevice::XHALDevice(const std::string& board_domain_name, const void xhal::client::XHALDevice::reconnect() { - if (!isConnected){ + if (!isConnected) { this->connect(); this->loadModule("memory","memory v1.0.1"); this->loadModule("extras","extras v1.0.1"); @@ -28,39 +28,33 @@ void xhal::client::XHALDevice::reconnect() uint32_t xhal::client::XHALDevice::readReg(std::string regName) { - if (auto t_node = m_parser->getNode(regName.c_str())) - { + if (auto t_node = m_parser->getNode(regName.c_str())) { m_node = t_node.get(); req = wisc::RPCMsg("memory.read"); req.set_word("address", m_node.real_address); req.set_word("count", 1); try { rsp = rpc.call_method(req); - } - STANDARD_CATCH; + } STANDARD_CATCH; uint32_t result; - if (rsp.get_key_exists("error")) - { - XHAL_ERROR("RPC response returned error, readReg failed"); + if (rsp.get_key_exists("error")) { + XHAL_ERROR("RPC response returned error, readReg failed"); throw xhal::common::utils::XHALException("Error during register access"); } else { - try{ + try { ASSERT(rsp.get_word_array_size("data") == 1); rsp.get_word_array("data", &result); - } - STANDARD_CATCH; + } STANDARD_CATCH; } XHAL_DEBUG("RESULT: " << std::hex << result); XHAL_DEBUG("Node mask: " << std::hex << m_node.mask); uint32_t mask = m_node.mask; result = result & mask; XHAL_DEBUG("RESULT after applying mask: " << std::hex << result); - for (int i = 0; i < 32; i++) - { - if (mask & 1) - { + for (int i = 0; i < 32; i++) { + if (mask & 1) { break; - }else { + } else { mask = mask >> 1; result = result >> 1; } @@ -79,27 +73,22 @@ uint32_t xhal::client::XHALDevice::readReg(uint32_t address) req.set_word("address", address); req.set_word("count", 1); try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + rsp = rpc.call_method(req); + } STANDARD_CATCH; uint32_t result; - if (rsp.get_key_exists("error")) - { - XHAL_ERROR("RPC response returned error, readReg failed"); + if (rsp.get_key_exists("error")) { + XHAL_ERROR("RPC response returned error, readReg failed"); throw xhal::common::utils::XHALException("Error during register access"); } else { - try{ + try { ASSERT(rsp.get_word_array_size("data") == 1); rsp.get_word_array("data", &result); - } - STANDARD_CATCH; + } STANDARD_CATCH; } //uint32_t mask = m_node.mask; //result = result & mask; - //for (int i = 0; i < 32; i++) - //{ - // if (result & 0x01) - // { + //for (int i = 0; i < 32; i++) { + // if (result & 0x01) { // break; // }else { // result = result >> 1; @@ -110,32 +99,26 @@ uint32_t xhal::client::XHALDevice::readReg(uint32_t address) void xhal::client::XHALDevice::writeReg(std::string regName, uint32_t value) { - if (auto t_node = m_parser->getNode(regName.c_str())) - { + if (auto t_node = m_parser->getNode(regName.c_str())) { m_node = t_node.get(); - if (m_node.mask == 0xFFFFFFFF) - { + if (m_node.mask == 0xFFFFFFFF) { req = wisc::RPCMsg("memory.write"); req.set_word("address", m_node.real_address); req.set_word("count", 1); req.set_word("data", value); try { rsp = rpc.call_method(req); - } - STANDARD_CATCH; - if (rsp.get_key_exists("error")) - { - XHAL_ERROR("RPC response returned error, writeReg failed"); + } STANDARD_CATCH; + if (rsp.get_key_exists("error")) { + XHAL_ERROR("RPC response returned error, writeReg failed"); throw xhal::common::utils::XHALException("Error during register access"); } } else { uint32_t current_val = this->readReg(m_node.real_address); int shift_amount = 0; uint32_t mask = m_node.mask; - for (int i = 0; i < 32; i++) - { - if (mask & 1) - { + for (int i = 0; i < 32; i++) { + if (mask & 1) { break; } else { shift_amount +=1; @@ -149,11 +132,9 @@ void xhal::client::XHALDevice::writeReg(std::string regName, uint32_t value) req.set_word_array("data", &val_to_write,1); try { rsp = rpc.call_method(req); - } - STANDARD_CATCH; - if (rsp.get_key_exists("error")) - { - XHAL_ERROR("RPC response returned error, writeReg failed"); + } STANDARD_CATCH; + if (rsp.get_key_exists("error")) { + XHAL_ERROR("RPC response returned error, writeReg failed"); throw xhal::common::utils::XHALException("Error during register access"); } } @@ -165,44 +146,40 @@ void xhal::client::XHALDevice::writeReg(std::string regName, uint32_t value) uint32_t xhal::client::XHALDevice::getList(uint32_t* addresses, uint32_t* result, ssize_t size) { - req = wisc::RPCMsg("extras.listread"); - req.set_word_array("addresses", addresses,size); - req.set_word("count", size); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + req = wisc::RPCMsg("extras.listread"); + req.set_word_array("addresses", addresses,size); + req.set_word("count", size); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - try{ - if (rsp.get_key_exists("error")) { - return 1; - } else { - ASSERT(rsp.get_word_array_size("data") == size); - rsp.get_word_array("data", result); - } + try { + if (rsp.get_key_exists("error")) { + return 1; + } else { + ASSERT(rsp.get_word_array_size("data") == size); + rsp.get_word_array("data", result); } - STANDARD_CATCH; - return 0; + } STANDARD_CATCH; + return 0; } uint32_t xhal::client::XHALDevice::getBlock(uint32_t address, uint32_t* result, ssize_t size) { - req = wisc::RPCMsg("extras.blockread"); - req.set_word("address", address); - req.set_word("count", size); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + req = wisc::RPCMsg("extras.blockread"); + req.set_word("address", address); + req.set_word("count", size); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - try{ - if (rsp.get_key_exists("error")) { - return 1;//FIXME throw an exception - } else { - ASSERT(rsp.get_word_array_size("data") == size); - rsp.get_word_array("data", result); - } + try { + if (rsp.get_key_exists("error")) { + return 1;//FIXME throw an exception + } else { + ASSERT(rsp.get_word_array_size("data") == size); + rsp.get_word_array("data", result); } - STANDARD_CATCH; - return 0; + } STANDARD_CATCH; + return 0; } diff --git a/xhal/src/client/XHALInterface.cpp b/xhal/src/client/XHALInterface.cpp index 28e3506..605b5a3 100644 --- a/xhal/src/client/XHALInterface.cpp +++ b/xhal/src/client/XHALInterface.cpp @@ -4,7 +4,7 @@ int xhal::client::XHALInterface::index = 0; -xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name): +xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name) : m_board_domain_name(board_domain_name), isConnected(false) { @@ -25,13 +25,12 @@ xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name) try { this->connect(); XHAL_INFO("XHAL Interface connected"); - } - catch (xhal::common::utils::XHALRPCException &e) { + } catch (xhal::common::utils::XHALRPCException &e) { XHAL_INFO("XHAL Interface failed to connect"); } } -xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name, log4cplus::Logger& logger): +xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name, log4cplus::Logger& logger) : m_board_domain_name(board_domain_name), m_logger(logger), isConnected(false) @@ -42,8 +41,7 @@ xhal::client::XHALInterface::XHALInterface(const std::string& board_domain_name, try { this->connect(); XHAL_INFO("XHAL Interface connected"); - } - catch (xhal::common::utils::XHALRPCException &e) { + } catch (xhal::common::utils::XHALRPCException &e) { XHAL_INFO("XHAL Interface failed to connect"); isConnected = false; } @@ -62,12 +60,10 @@ void xhal::client::XHALInterface::connect() rpc.connect(m_board_domain_name); isConnected = true; XHAL_INFO("RPC connected"); - } - catch (wisc::RPCSvc::ConnectionFailedException &e) { + } catch (wisc::RPCSvc::ConnectionFailedException &e) { XHAL_ERROR("Caught RPCErrorException: " << e.message.c_str()); throw xhal::common::utils::XHALRPCException("RPC ConnectionFailedException: " + e.message); - } - catch (wisc::RPCSvc::RPCException &e) { + } catch (wisc::RPCSvc::RPCException &e) { XHAL_ERROR("Caught exception: " << e.message.c_str()); throw xhal::common::utils::XHALRPCException("RPC exception: " + e.message); } @@ -84,11 +80,9 @@ void xhal::client::XHALInterface::disconnect() rpc.disconnect(); XHAL_INFO("RPC disconnected"); isConnected = false; - } - catch (wisc::RPCSvc::NotConnectedException &e) { + } catch (wisc::RPCSvc::NotConnectedException &e) { XHAL_INFO("Caught RPCNotConnectedException: " << e.message.c_str()); - } - catch (wisc::RPCSvc::RPCException &e) { + } catch (wisc::RPCSvc::RPCException &e) { XHAL_ERROR("Caught exception: " << e.message.c_str()); throw xhal::common::utils::XHALRPCException("RPC exception: " + e.message); } @@ -98,28 +92,26 @@ void xhal::client::XHALInterface::loadModule(const std::string& module_name, con { try { ASSERT(rpc.load_module(module_name, module_version)); - } - STANDARD_CATCH; + } STANDARD_CATCH; } void xhal::client::XHALInterface::setLogLevel(int loglevel) { - switch(loglevel) - { - case 0: - m_logger.setLogLevel(log4cplus::ERROR_LOG_LEVEL); - break; - case 1: - m_logger.setLogLevel(log4cplus::WARN_LOG_LEVEL); - break; - case 2: - m_logger.setLogLevel(log4cplus::INFO_LOG_LEVEL); - break; - case 3: - m_logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL); - break; - case 4: - m_logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL); - break; + switch (loglevel) { + case 0: + m_logger.setLogLevel(log4cplus::ERROR_LOG_LEVEL); + break; + case 1: + m_logger.setLogLevel(log4cplus::WARN_LOG_LEVEL); + break; + case 2: + m_logger.setLogLevel(log4cplus::INFO_LOG_LEVEL); + break; + case 3: + m_logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL); + break; + case 4: + m_logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL); + break; } } diff --git a/xhal/src/client/python_wrappers/XHALInterface_python.cpp b/xhal/src/client/python_wrappers/XHALInterface_python.cpp index b5c20ed..634ae48 100644 --- a/xhal/src/client/python_wrappers/XHALInterface_python.cpp +++ b/xhal/src/client/python_wrappers/XHALInterface_python.cpp @@ -20,7 +20,7 @@ PyObject* createExceptionClass(const char* name, PyObject* baseTypeObj = PyExc_E char* qualifiedName1 = const_cast(qualifiedName0.c_str()); PyObject* typeObj = PyErr_NewException(qualifiedName1, baseTypeObj, 0); - if(!typeObj) bp::throw_error_already_set(); + if (!typeObj) bp::throw_error_already_set(); bp::scope().attr(name) = bp::handle<>(bp::borrowed(typeObj)); return typeObj; } @@ -34,7 +34,7 @@ inline void TRANSLATOR_NAME(EXCEPTION_NAME const& e) assert(EXCEPTION_OBJ != NULL); \ /* Use the Python 'C' API to set up an exception object*/ \ PyErr_SetString(EXCEPTION_OBJ, e.msg.c_str()); \ -} +} #endif PY_EXCEPTION_TRANSLATOR(translate_XHALException,xhal::common::utils::XHALException, obj_XHALException) diff --git a/xhal/src/client/rpc_manager/calibration_routines.cpp b/xhal/src/client/rpc_manager/calibration_routines.cpp index 1c81e16..3e50294 100644 --- a/xhal/src/client/rpc_manager/calibration_routines.cpp +++ b/xhal/src/client/rpc_manager/calibration_routines.cpp @@ -2,274 +2,263 @@ uint32_t xhal::client::rpcman::CalRoutines::checkSbitMappingWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t nevts, uint32_t L1Ainterval, uint32_t pulseDelay, uint32_t *data) { - req = wisc::RPCMsg("calibration_routines.checkSbitMappingWithCalPulse"); - - req.set_word("ohN", ohN); - req.set_word("vfatN", vfatN); - req.set_word("mask", mask); - req.set_word("useCalPulse", useCalPulse); - req.set_word("currentPulse", currentPulse); - req.set_word("calScaleFactor", calScaleFactor); - req.set_word("nevts", nevts); - req.set_word("L1Ainterval", L1Ainterval); - req.set_word("pulseDelay", pulseDelay); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - - const uint32_t size = 128*8*nevts; - if (rsp.get_key_exists("data")){ - ASSERT(rsp.get_word_array_size("data") == size); - rsp.get_word_array("data",data); - } - else{ - printf("No key found for data"); - return 1; - } - - return 0; + req = wisc::RPCMsg("calibration_routines.checkSbitMappingWithCalPulse"); + + req.set_word("ohN", ohN); + req.set_word("vfatN", vfatN); + req.set_word("mask", mask); + req.set_word("useCalPulse", useCalPulse); + req.set_word("currentPulse", currentPulse); + req.set_word("calScaleFactor", calScaleFactor); + req.set_word("nevts", nevts); + req.set_word("L1Ainterval", L1Ainterval); + req.set_word("pulseDelay", pulseDelay); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + + const uint32_t size = 128*8*nevts; + if (rsp.get_key_exists("data")){ + ASSERT(rsp.get_word_array_size("data") == size); + rsp.get_word_array("data",data); + } else { + printf("No key found for data"); + return 1; + } + + return 0; } uint32_t xhal::client::rpcman::CalRoutines::checkSbitRateWithCalPulse(uint32_t ohN, uint32_t vfatN, uint32_t mask, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t waitTime, uint32_t pulseRate, uint32_t pulseDelay, uint32_t *outDataCTP7Rate, uint32_t *outDataFPGAClusterCntRate, uint32_t *outDataVFATSBits) { - req = wisc::RPCMsg("calibration_routines.checkSbitRateWithCalPulse"); - - req.set_word("ohN", ohN); - req.set_word("vfatN", vfatN); - req.set_word("mask", mask); - req.set_word("useCalPulse", useCalPulse); - req.set_word("currentPulse", currentPulse); - req.set_word("calScaleFactor", calScaleFactor); - req.set_word("waitTime", waitTime); - req.set_word("pulseRate", pulseRate); - req.set_word("pulseDelay", pulseDelay); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - - const uint32_t size = 128; - if (rsp.get_key_exists("outDataCTP7Rate")) { - ASSERT(rsp.get_word_array_size("outDataCTP7Rate") == size); - rsp.get_word_array("outDataCTP7Rate", outDataCTP7Rate); - } - else{ - printf("No key found for outDataCTP7Rate"); - return 1; - } - - if (rsp.get_key_exists("outDataFPGAClusterCntRate")) { - ASSERT(rsp.get_word_array_size("outDataFPGAClusterCntRate") == size); - rsp.get_word_array("outDataFPGAClusterCntRate", outDataFPGAClusterCntRate); - } - else{ - printf("No key found for outDataFPGAClusterCntRate"); - return 1; - } - - if (rsp.get_key_exists("outDataVFATSBits")) { - ASSERT(rsp.get_word_array_size("outDataVFATSBits") == size); - rsp.get_word_array("outDataVFATSBits", outDataVFATSBits); - } - else{ - printf("No key found for outDataVFATSBits"); - return 1; - } - - return 0; + req = wisc::RPCMsg("calibration_routines.checkSbitRateWithCalPulse"); + + req.set_word("ohN", ohN); + req.set_word("vfatN", vfatN); + req.set_word("mask", mask); + req.set_word("useCalPulse", useCalPulse); + req.set_word("currentPulse", currentPulse); + req.set_word("calScaleFactor", calScaleFactor); + req.set_word("waitTime", waitTime); + req.set_word("pulseRate", pulseRate); + req.set_word("pulseDelay", pulseDelay); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + + const uint32_t size = 128; + if (rsp.get_key_exists("outDataCTP7Rate")) { + ASSERT(rsp.get_word_array_size("outDataCTP7Rate") == size); + rsp.get_word_array("outDataCTP7Rate", outDataCTP7Rate); + } else { + printf("No key found for outDataCTP7Rate"); + return 1; + } + + if (rsp.get_key_exists("outDataFPGAClusterCntRate")) { + ASSERT(rsp.get_word_array_size("outDataFPGAClusterCntRate") == size); + rsp.get_word_array("outDataFPGAClusterCntRate", outDataFPGAClusterCntRate); + } else { + printf("No key found for outDataFPGAClusterCntRate"); + return 1; + } + + if (rsp.get_key_exists("outDataVFATSBits")) { + ASSERT(rsp.get_word_array_size("outDataVFATSBits") == size); + rsp.get_word_array("outDataVFATSBits", outDataVFATSBits); + } else { + printf("No key found for outDataVFATSBits"); + return 1; + } + + return 0; } uint32_t xhal::client::rpcman::CalRoutines::genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, uint32_t mask, char * scanReg, bool useUltra, bool useExtTrig, uint32_t * result) { - req = wisc::RPCMsg("calibration_routines.genScan"); - - req.set_word("nevts", nevts); - req.set_word("ohN", ohN); - req.set_word("dacMin", dacMin); - req.set_word("dacMax", dacMax); - req.set_word("dacStep", dacStep); - req.set_word("ch", ch); - req.set_word("useCalPulse", useCalPulse); - req.set_word("currentPulse", currentPulse); - req.set_word("calScaleFactor", calScaleFactor); - req.set_word("mask", mask); - if(useUltra){ - req.set_word("useUltra", useUltra); - } - req.set_word("useExtTrig", useExtTrig); - req.set_string("scanReg", std::string(scanReg)); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - const uint32_t size = (dacMax - dacMin+1)*24/dacStep; - if (rsp.get_key_exists("data")) { - ASSERT(rsp.get_word_array_size("data") == size); - rsp.get_word_array("data", result); - } else { - printf("No data key found"); - return 1; - } - - return 0; + req = wisc::RPCMsg("calibration_routines.genScan"); + + req.set_word("nevts", nevts); + req.set_word("ohN", ohN); + req.set_word("dacMin", dacMin); + req.set_word("dacMax", dacMax); + req.set_word("dacStep", dacStep); + req.set_word("ch", ch); + req.set_word("useCalPulse", useCalPulse); + req.set_word("currentPulse", currentPulse); + req.set_word("calScaleFactor", calScaleFactor); + req.set_word("mask", mask); + if (useUltra) { + req.set_word("useUltra", useUltra); + } + req.set_word("useExtTrig", useExtTrig); + req.set_string("scanReg", std::string(scanReg)); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + const uint32_t size = (dacMax - dacMin+1)*24/dacStep; + if (rsp.get_key_exists("data")) { + ASSERT(rsp.get_word_array_size("data") == size); + rsp.get_word_array("data", result); + } else { + printf("No data key found"); + return 1; + } + + return 0; } uint32_t xhal::client::rpcman::CalRoutines::genChannelScan(uint32_t nevts, uint32_t ohN, uint32_t mask, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, bool useCalPulse, bool currentPulse, uint32_t calScaleFactor, bool useExtTrig, char * scanReg, bool useUltra, uint32_t * result) { - req = wisc::RPCMsg("calibration_routines.genChannelScan"); - - req.set_word("nevts", nevts); - req.set_word("ohN", ohN); - req.set_word("mask", mask); - req.set_word("dacMin", dacMin); - req.set_word("dacMax", dacMax); - req.set_word("dacStep", dacStep); - req.set_word("useCalPulse", useCalPulse); - req.set_word("currentPulse", currentPulse); - req.set_word("calScaleFactor", calScaleFactor); - req.set_word("useExtTrig", useExtTrig); - if(useUltra){ - req.set_word("useUltra", useUltra); - } - req.set_string("scanReg", std::string(scanReg)); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - const uint32_t size = 24*128*(dacMax-dacMin+1)/dacStep; - if (rsp.get_key_exists("data")) { - ASSERT(rsp.get_word_array_size("data") == size); - rsp.get_word_array("data", result); - } else { - printf("No data key found"); - return 1; - } - - return 0; + req = wisc::RPCMsg("calibration_routines.genChannelScan"); + + req.set_word("nevts", nevts); + req.set_word("ohN", ohN); + req.set_word("mask", mask); + req.set_word("dacMin", dacMin); + req.set_word("dacMax", dacMax); + req.set_word("dacStep", dacStep); + req.set_word("useCalPulse", useCalPulse); + req.set_word("currentPulse", currentPulse); + req.set_word("calScaleFactor", calScaleFactor); + req.set_word("useExtTrig", useExtTrig); + if (useUltra) { + req.set_word("useUltra", useUltra); + } + req.set_string("scanReg", std::string(scanReg)); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + const uint32_t size = 24*128*(dacMax-dacMin+1)/dacStep; + if (rsp.get_key_exists("data")) { + ASSERT(rsp.get_word_array_size("data") == size); + rsp.get_word_array("data", result); + } else { + printf("No data key found"); + return 1; + } + + return 0; } uint32_t xhal::client::rpcman::CalRoutines::sbitRateScan(uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t maskOh, bool invertVFATPos, char * scanReg, uint32_t waitTime, uint32_t * resultDacVal, uint32_t * resultTrigRate, uint32_t * resultTrigRatePerVFAT, bool isParallel) { - req = wisc::RPCMsg("calibration_routines.sbitRateScan"); - - - req.set_word("ohN", ohN); - req.set_word("maskOh", maskOh); - req.set_word("invertVFATPos", invertVFATPos); - req.set_word("isParallel", isParallel); - req.set_word("dacMin", dacMin); - req.set_word("dacMax", dacMax); - req.set_word("dacStep", dacStep); - req.set_word("ch", ch); - req.set_string("scanReg", std::string(scanReg)); - req.set_word("waitTime", waitTime); - - //Check to make sure (dacMax-dacMin+1)/dacStep is an integer! - if( 0 != ((dacMax - dacMin + 1) % dacStep) ){ - printf("Caught an error: (dacMax - dacMin + 1)/dacStep must be an integer!\n"); - return 1; - } - const uint32_t size = (dacMax - dacMin+1)/dacStep; - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - - if (rsp.get_key_exists("data_dacVal")) { - ASSERT(rsp.get_word_array_size("data_dacVal") == size); - rsp.get_word_array("data_dacVal", resultDacVal); - } else { - printf("No key found for data dac values"); - return 1; + req = wisc::RPCMsg("calibration_routines.sbitRateScan"); + + + req.set_word("ohN", ohN); + req.set_word("maskOh", maskOh); + req.set_word("invertVFATPos", invertVFATPos); + req.set_word("isParallel", isParallel); + req.set_word("dacMin", dacMin); + req.set_word("dacMax", dacMax); + req.set_word("dacStep", dacStep); + req.set_word("ch", ch); + req.set_string("scanReg", std::string(scanReg)); + req.set_word("waitTime", waitTime); + + //Check to make sure (dacMax-dacMin+1)/dacStep is an integer! + if (0 != ((dacMax - dacMin + 1) % dacStep)) { + printf("Caught an error: (dacMax - dacMin + 1)/dacStep must be an integer!\n"); + return 1; + } + const uint32_t size = (dacMax - dacMin+1)/dacStep; + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + + if (rsp.get_key_exists("data_dacVal")) { + ASSERT(rsp.get_word_array_size("data_dacVal") == size); + rsp.get_word_array("data_dacVal", resultDacVal); + } else { + printf("No key found for data dac values"); + return 1; + } + + if (rsp.get_key_exists("data_trigRate")) { + ASSERT(rsp.get_word_array_size("data_trigRate") == size); + rsp.get_word_array("data_trigRate", resultTrigRate); + } else { + printf("No key found for data trigger rate values"); + return 1; + } + + if (isParallel) { + if (rsp.get_key_exists("data_trigRatePerVFAT")) { + ASSERT(rsp.get_word_array_size("data_trigRatePerVFAT") == (size*24)); + rsp.get_word_array("data_trigRatePerVFAT", resultTrigRatePerVFAT); } - - if (rsp.get_key_exists("data_trigRate")) { - ASSERT(rsp.get_word_array_size("data_trigRate") == size); - rsp.get_word_array("data_trigRate", resultTrigRate); - } else { - printf("No key found for data trigger rate values"); - return 1; - } - - if(isParallel){ - if (rsp.get_key_exists("data_trigRatePerVFAT")) { - ASSERT(rsp.get_word_array_size("data_trigRatePerVFAT") == (size*24)); - rsp.get_word_array("data_trigRatePerVFAT", resultTrigRatePerVFAT); - } - else{ - printf("No key found for data trigger rate per vfat values"); - return 1; - } + else { + printf("No key found for data trigger rate per vfat values"); + return 1; } + } - return 0; + return 0; } uint32_t xhal::client::rpcman::CalRoutines::ttcGenConf(uint32_t ohN, uint32_t mode, uint32_t type, uint32_t pulseDelay, uint32_t L1Ainterval, uint32_t nPulses, bool enable) { - req = wisc::RPCMsg("calibration_routines.ttcGenConf"); - req.set_word("ohN", ohN); - req.set_word("mode", mode); - req.set_word("type", type); - req.set_word("pulseDelay", pulseDelay); - req.set_word("L1Ainterval", L1Ainterval); - req.set_word("nPulses", nPulses); - req.set_word("enable", enable); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - return 1; - } - return 0; + req = wisc::RPCMsg("calibration_routines.ttcGenConf"); + req.set_word("ohN", ohN); + req.set_word("mode", mode); + req.set_word("type", type); + req.set_word("pulseDelay", pulseDelay); + req.set_word("L1Ainterval", L1Ainterval); + req.set_word("nPulses", nPulses); + req.set_word("enable", enable); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + return 1; + } + return 0; } uint32_t xhal::client::rpcman::CalRoutines::ttcGenToggle(uint32_t ohN, bool enable) { - req = wisc::RPCMsg("calibration_routines.ttcGenToggle"); - req.set_word("ohN", ohN); - req.set_word("enable", enable); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - return 1; - } - return 0; + req = wisc::RPCMsg("calibration_routines.ttcGenToggle"); + req.set_word("ohN", ohN); + req.set_word("enable", enable); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + return 1; + } + return 0; } diff --git a/xhal/src/client/rpc_manager/daq_monitor.cpp b/xhal/src/client/rpc_manager/daq_monitor.cpp index b866cd6..3ef9b99 100644 --- a/xhal/src/client/rpc_manager/daq_monitor.cpp +++ b/xhal/src/client/rpc_manager/daq_monitor.cpp @@ -2,196 +2,184 @@ PyListUint32 xhal::client::rpcman::DaqMonitor::getmonTTCmain() { - PyListUint32 result; - req = wisc::RPCMsg("amc.getmonTTCmain"); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - try{ - if (rsp.get_key_exists("error")) { - printf("Error: %s",rsp.get_string("error").c_str()); - //FIXME raise an exception - } else { - result.clear(); - result.push_back(rsp.get_word("MMCM_LOCKED")); - result.push_back(rsp.get_word("TTC_SINGLE_ERROR_CNT")); - result.push_back(rsp.get_word("BC0_LOCKED")); - result.push_back(rsp.get_word("L1A_ID")); - result.push_back(rsp.get_word("L1A_RATE")); - } + PyListUint32 result; + req = wisc::RPCMsg("amc.getmonTTCmain"); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + try { + if (rsp.get_key_exists("error")) { + printf("Error: %s",rsp.get_string("error").c_str()); + //FIXME raise an exception + } else { + result.clear(); + result.push_back(rsp.get_word("MMCM_LOCKED")); + result.push_back(rsp.get_word("TTC_SINGLE_ERROR_CNT")); + result.push_back(rsp.get_word("BC0_LOCKED")); + result.push_back(rsp.get_word("L1A_ID")); + result.push_back(rsp.get_word("L1A_RATE")); } - STANDARD_CATCH; - return result; + } STANDARD_CATCH; + return result; } PyListUint32 xhal::client::rpcman::DaqMonitor::getmonTRIGGERmain(uint32_t noh) { - PyListUint32 result; - req = wisc::RPCMsg("amc.getmonTRIGGERmain"); - req.set_word("NOH",noh); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + PyListUint32 result; + req = wisc::RPCMsg("amc.getmonTRIGGERmain"); + req.set_word("NOH",noh); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - try{ - if (rsp.get_key_exists("error")) { - printf("Error: %s",rsp.get_string("error").c_str()); - // FIXME raise an exception - } else { - std::string t; - result.push_back(rsp.get_word("OR_TRIGGER_RATE")); - for (unsigned int i = 0; i < noh; i++) { - t = "OH"+std::to_string(i)+".TRIGGER_RATE"; - result.push_back(rsp.get_word(t)); - } - } + try { + if (rsp.get_key_exists("error")) { + printf("Error: %s",rsp.get_string("error").c_str()); + // FIXME raise an exception + } else { + std::string t; + result.push_back(rsp.get_word("OR_TRIGGER_RATE")); + for (unsigned int i = 0; i < noh; i++) { + t = "OH"+std::to_string(i)+".TRIGGER_RATE"; + result.push_back(rsp.get_word(t)); + } } - STANDARD_CATCH; - return result; + } STANDARD_CATCH; + return result; } PyListUint32 xhal::client::rpcman::DaqMonitor::getmonTRIGGEROHmain(uint32_t noh) { - PyListUint32 result(8*noh,0); - req = wisc::RPCMsg("amc.getmonTRIGGEROHmain"); - req.set_word("NOH",noh); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + PyListUint32 result(8*noh,0); + req = wisc::RPCMsg("amc.getmonTRIGGEROHmain"); + req.set_word("NOH",noh); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - try{ - if (rsp.get_key_exists("error")) { - printf("Error: %s",rsp.get_string("error").c_str()); - // FIXME raise an exception - }else { - std::string t; - for (unsigned int i = 0; i < noh; i++) { - t = "OH"+std::to_string(i)+".LINK0_MISSED_COMMA_CNT"; - result[i] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".LINK1_MISSED_COMMA_CNT"; - result[i+noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".LINK0_OVERFLOW_CNT"; - result[i+2*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".LINK1_OVERFLOW_CNT"; - result[i+3*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".LINK0_UNDERFLOW_CNT"; - result[i+4*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".LINK1_UNDERFLOW_CNT"; - result[i+5*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".LINK0_SBIT_OVERFLOW_CNT"; - result[i+6*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".LINK1_SBIT_OVERFLOW_CNT"; - result[i+7*noh] = rsp.get_word(t); - } - } + try { + if (rsp.get_key_exists("error")) { + printf("Error: %s",rsp.get_string("error").c_str()); + // FIXME raise an exception + }else { + std::string t; + for (unsigned int i = 0; i < noh; i++) { + t = "OH"+std::to_string(i)+".LINK0_MISSED_COMMA_CNT"; + result[i] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".LINK1_MISSED_COMMA_CNT"; + result[i+noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".LINK0_OVERFLOW_CNT"; + result[i+2*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".LINK1_OVERFLOW_CNT"; + result[i+3*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".LINK0_UNDERFLOW_CNT"; + result[i+4*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".LINK1_UNDERFLOW_CNT"; + result[i+5*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".LINK0_SBIT_OVERFLOW_CNT"; + result[i+6*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".LINK1_SBIT_OVERFLOW_CNT"; + result[i+7*noh] = rsp.get_word(t); + } } - STANDARD_CATCH; - return result; + } STANDARD_CATCH; + return result; } PyListUint32 xhal::client::rpcman::DaqMonitor::getmonDAQmain() { - PyListUint32 result; - req = wisc::RPCMsg("amc.getmonDAQmain"); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + PyListUint32 result; + req = wisc::RPCMsg("amc.getmonDAQmain"); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - try{ - if (rsp.get_key_exists("error")) { - printf("Error: %s",rsp.get_string("error").c_str()); - // FIXME raise an exception - } else { - result.push_back(rsp.get_word("DAQ_ENABLE")); - result.push_back(rsp.get_word("DAQ_LINK_READY")); - result.push_back(rsp.get_word("DAQ_LINK_AFULL")); - result.push_back(rsp.get_word("DAQ_OFIFO_HAD_OFLOW")); - result.push_back(rsp.get_word("L1A_FIFO_HAD_OFLOW")); - result.push_back(rsp.get_word("L1A_FIFO_DATA_COUNT")); - result.push_back(rsp.get_word("DAQ_FIFO_DATA_COUNT")); - result.push_back(rsp.get_word("EVENT_SENT")); - result.push_back(rsp.get_word("TTS_STATE")); - } + try { + if (rsp.get_key_exists("error")) { + printf("Error: %s",rsp.get_string("error").c_str()); + // FIXME raise an exception + } else { + result.push_back(rsp.get_word("DAQ_ENABLE")); + result.push_back(rsp.get_word("DAQ_LINK_READY")); + result.push_back(rsp.get_word("DAQ_LINK_AFULL")); + result.push_back(rsp.get_word("DAQ_OFIFO_HAD_OFLOW")); + result.push_back(rsp.get_word("L1A_FIFO_HAD_OFLOW")); + result.push_back(rsp.get_word("L1A_FIFO_DATA_COUNT")); + result.push_back(rsp.get_word("DAQ_FIFO_DATA_COUNT")); + result.push_back(rsp.get_word("EVENT_SENT")); + result.push_back(rsp.get_word("TTS_STATE")); } - STANDARD_CATCH; - return result; + } STANDARD_CATCH; + return result; } PyListUint32 xhal::client::rpcman::DaqMonitor::getmonDAQOHmain(uint32_t noh) { - PyListUint32 result(6*noh,0); - req = wisc::RPCMsg("amc.getmonDAQOHmain"); - req.set_word("NOH",noh); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + PyListUint32 result(6*noh,0); + req = wisc::RPCMsg("amc.getmonDAQOHmain"); + req.set_word("NOH",noh); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - try{ - if (rsp.get_key_exists("error")) { - printf("Error: %s",rsp.get_string("error").c_str()); - // FIXME raise an exception - }else { - std::string t; - for (unsigned int i = 0; i < noh; i++) { - t = "OH"+std::to_string(i)+".STATUS.EVT_SIZE_ERR"; - result[i] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".STATUS.EVENT_FIFO_HAD_OFLOW"; - result[i+noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".STATUS.INPUT_FIFO_HAD_OFLOW"; - result[i+2*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".STATUS.INPUT_FIFO_HAD_UFLOW"; - result[i+3*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".STATUS.VFAT_TOO_MANY"; - result[i+4*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".STATUS.VFAT_NO_MARKER"; - result[i+5*noh] = rsp.get_word(t); - } - } + try { + if (rsp.get_key_exists("error")) { + printf("Error: %s",rsp.get_string("error").c_str()); + // FIXME raise an exception + }else { + std::string t; + for (unsigned int i = 0; i < noh; i++) { + t = "OH"+std::to_string(i)+".STATUS.EVT_SIZE_ERR"; + result[i] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".STATUS.EVENT_FIFO_HAD_OFLOW"; + result[i+noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".STATUS.INPUT_FIFO_HAD_OFLOW"; + result[i+2*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".STATUS.INPUT_FIFO_HAD_UFLOW"; + result[i+3*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".STATUS.VFAT_TOO_MANY"; + result[i+4*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".STATUS.VFAT_NO_MARKER"; + result[i+5*noh] = rsp.get_word(t); + } } - STANDARD_CATCH; - return result; + } STANDARD_CATCH; + return result; } PyListUint32 xhal::client::rpcman::DaqMonitor::getmonOHmain(uint32_t noh) { - PyListUint32 result(7*noh,0); - req = wisc::RPCMsg("amc.getmonOHmain"); - req.set_word("NOH",noh); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + PyListUint32 result(7*noh,0); + req = wisc::RPCMsg("amc.getmonOHmain"); + req.set_word("NOH",noh); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - try{ - if (rsp.get_key_exists("error")) { - printf("Error: %s",rsp.get_string("error").c_str()); - // FIXME raise an exception - } else { - std::string t; - for (unsigned int i = 0; i < noh; i++) { - t = "OH"+std::to_string(i)+".FW_VERSION"; - result[i] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".EVENT_COUNTER"; - result[i+noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".EVENT_RATE"; - result[i+2*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".GTX.TRK_ERR"; - result[i+3*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".GTX.TRG_ERR"; - result[i+4*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".GBT.TRK_ERR"; - result[i+5*noh] = rsp.get_word(t); - t = "OH"+std::to_string(i)+".CORR_VFAT_BLK_CNT"; - result[i+6*noh] = rsp.get_word(t); - } - } + try { + if (rsp.get_key_exists("error")) { + printf("Error: %s",rsp.get_string("error").c_str()); + // FIXME raise an exception + } else { + std::string t; + for (unsigned int i = 0; i < noh; i++) { + t = "OH"+std::to_string(i)+".FW_VERSION"; + result[i] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".EVENT_COUNTER"; + result[i+noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".EVENT_RATE"; + result[i+2*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".GTX.TRK_ERR"; + result[i+3*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".GTX.TRG_ERR"; + result[i+4*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".GBT.TRK_ERR"; + result[i+5*noh] = rsp.get_word(t); + t = "OH"+std::to_string(i)+".CORR_VFAT_BLK_CNT"; + result[i+6*noh] = rsp.get_word(t); + } } - STANDARD_CATCH; - return result; + } STANDARD_CATCH; + return result; } diff --git a/xhal/src/client/rpc_manager/optohybrid.cpp b/xhal/src/client/rpc_manager/optohybrid.cpp index b21c0bb..490338a 100644 --- a/xhal/src/client/rpc_manager/optohybrid.cpp +++ b/xhal/src/client/rpc_manager/optohybrid.cpp @@ -1,201 +1,192 @@ #include "xhal/client/rpcman/optohybrid.h" xhal::client::rpcman::Optohybrid::Optohybrid(const std::string& board_domain_name, const std::string& address_table_filename) : - xhal::client::XHALDevice(board_domain_name, address_table_filename) + xhal::client::XHALDevice(board_domain_name, address_table_filename) { this->loadModule("optohybrid","optohybrid v1.0.1"); } uint32_t xhal::client::rpcman::Optohybrid::broadcastRead(uint32_t ohN, char * regName, uint32_t vfatMask, uint32_t * result) { - /* User supplies the VFAT node name as reg_name, examples: - * - * v2b electronics: reg_name = "VThreshold1" to get VT1 - * v3 electronics: reg_name = "CFG_THR_ARM_DAC" - * - * Supplying only a substr of VFAT Node name will crash - */ - - req = wisc::RPCMsg("optohybrid.broadcastRead"); - - req.set_string("reg_name",std::string(regName)); - req.set_word("ohN",ohN); - req.set_word("mask",vfatMask); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - else if (rsp.get_key_exists("data")) { - const uint32_t size = 24; - ASSERT(rsp.get_word_array_size("data") == size); - rsp.get_word_array("data", result); - } else { - printf("No data key found"); - return 1; - } - return 0; + /* User supplies the VFAT node name as reg_name, examples: + * + * v2b electronics: reg_name = "VThreshold1" to get VT1 + * v3 electronics: reg_name = "CFG_THR_ARM_DAC" + * + * Supplying only a substr of VFAT Node name will crash + */ + + req = wisc::RPCMsg("optohybrid.broadcastRead"); + + req.set_string("reg_name",std::string(regName)); + req.set_word("ohN",ohN); + req.set_word("mask",vfatMask); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } else if (rsp.get_key_exists("data")) { + const uint32_t size = 24; + ASSERT(rsp.get_word_array_size("data") == size); + rsp.get_word_array("data", result); + } else { + printf("No data key found"); + return 1; + } + return 0; } uint32_t xhal::client::rpcman::Optohybrid::broadcastWrite(uint32_t ohN, char * regName, uint32_t value, uint32_t vfatMask) { - /* User supplies the VFAT node name as reg_name, examples: - * - * v2b electronics: reg_name = "VThreshold1" to get VT1 - * v3 electronics: reg_name = "CFG_THR_ARM_DAC" - * - * Supplying only a substr of VFAT Node name will crash - */ - - req = wisc::RPCMsg("optohybrid.broadcastWrite"); - - req.set_string("reg_name",std::string(regName)); - req.set_word("ohN",ohN); - req.set_word("value",value); - req.set_word("mask",vfatMask); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - return 0; + /* User supplies the VFAT node name as reg_name, examples: + * + * v2b electronics: reg_name = "VThreshold1" to get VT1 + * v3 electronics: reg_name = "CFG_THR_ARM_DAC" + * + * Supplying only a substr of VFAT Node name will crash + */ + + req = wisc::RPCMsg("optohybrid.broadcastWrite"); + + req.set_string("reg_name",std::string(regName)); + req.set_word("ohN",ohN); + req.set_word("value",value); + req.set_word("mask",vfatMask); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + return 0; } uint32_t xhal::client::rpcman::Optohybrid::configureScanModule(uint32_t ohN, uint32_t vfatN, uint32_t scanmode, bool useUltra, uint32_t vfatMask, uint32_t ch, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep) { - req = wisc::RPCMsg("optohybrid.configureScanModule"); - - req.set_word("ohN",ohN); - req.set_word("scanmode",scanmode); - if (useUltra){ - req.set_word("useUltra",useUltra); - req.set_word("mask",vfatMask); - } - else{ - req.set_word("vfatN",vfatN); - } - req.set_word("ch", ch); //channel - req.set_word("nevts",nevts); - req.set_word("dacMin",dacMin); - req.set_word("dacMax",dacMax); - req.set_word("dacStep",dacStep); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - - return 0; + req = wisc::RPCMsg("optohybrid.configureScanModule"); + + req.set_word("ohN",ohN); + req.set_word("scanmode",scanmode); + if (useUltra) { + req.set_word("useUltra",useUltra); + req.set_word("mask",vfatMask); + } else { + req.set_word("vfatN",vfatN); + } + req.set_word("ch", ch); //channel + req.set_word("nevts",nevts); + req.set_word("dacMin",dacMin); + req.set_word("dacMax",dacMax); + req.set_word("dacStep",dacStep); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + + return 0; } uint32_t xhal::client::rpcman::Optohybrid::printScanConfiguration(uint32_t ohN, bool useUltra) { - req = wisc::RPCMsg("optohybrid.printScanConfiguration"); + req = wisc::RPCMsg("optohybrid.printScanConfiguration"); - req.set_word("ohN",ohN); - if (useUltra){ - req.set_word("useUltra",useUltra); - } + req.set_word("ohN",ohN); + if (useUltra) { + req.set_word("useUltra",useUltra); + } - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } - return 0; + return 0; } uint32_t xhal::client::rpcman::Optohybrid::startScanModule(uint32_t ohN, bool useUltra) { - req = wisc::RPCMsg("optohybrid.startScanModule"); + req = wisc::RPCMsg("optohybrid.startScanModule"); - req.set_word("ohN",ohN); - if (useUltra){ - req.set_word("useUltra",useUltra); - } + req.set_word("ohN",ohN); + if (useUltra) { + req.set_word("useUltra",useUltra); + } - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } - return 0; + return 0; } uint32_t xhal::client::rpcman::Optohybrid::getUltraScanResults(uint32_t ohN, uint32_t nevts, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t * result) { - req = wisc::RPCMsg("optohybrid.getUltraScanResults"); - - req.set_word("ohN",ohN); - req.set_word("nevts",nevts); - req.set_word("dacMin",dacMin); - req.set_word("dacMax",dacMax); - req.set_word("dacStep",dacStep); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - const uint32_t size = (dacMax - dacMin+1)*24/dacStep; - if (rsp.get_key_exists("data")) { - ASSERT(rsp.get_word_array_size("data") == size); - rsp.get_word_array("data", result); - } else { - printf("No data key found"); - return 1; - } - - return 0; + req = wisc::RPCMsg("optohybrid.getUltraScanResults"); + + req.set_word("ohN",ohN); + req.set_word("nevts",nevts); + req.set_word("dacMin",dacMin); + req.set_word("dacMax",dacMax); + req.set_word("dacStep",dacStep); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + const uint32_t size = (dacMax - dacMin+1)*24/dacStep; + if (rsp.get_key_exists("data")) { + ASSERT(rsp.get_word_array_size("data") == size); + rsp.get_word_array("data", result); + } else { + printf("No data key found"); + return 1; + } + + return 0; } uint32_t xhal::client::rpcman::Optohybrid::stopCalPulse2AllChannels(uint32_t ohN, uint32_t mask, uint32_t ch_min, uint32_t ch_max) { - req = wisc::RPCMsg("optohybrid.stopCalPulse2AllChannels"); + req = wisc::RPCMsg("optohybrid.stopCalPulse2AllChannels"); - req.set_word("ohN",ohN); - req.set_word("mask",mask); - req.set_word("ch_min",ch_min); - req.set_word("ch_max",ch_max); + req.set_word("ohN",ohN); + req.set_word("mask",mask); + req.set_word("ch_min",ch_min); + req.set_word("ch_max",ch_max); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } - return 0; + return 0; } diff --git a/xhal/src/client/rpc_manager/utils.cpp b/xhal/src/client/rpc_manager/utils.cpp index 2fdc290..471713c 100644 --- a/xhal/src/client/rpc_manager/utils.cpp +++ b/xhal/src/client/rpc_manager/utils.cpp @@ -2,42 +2,39 @@ uint32_t xhal::client::rpcman::Utils::update_atdb(char * xmlfilename) { - req = wisc::RPCMsg("utils.update_address_table"); - req.set_string("at_xml", xmlfilename); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + req = wisc::RPCMsg("utils.update_address_table"); + req.set_string("at_xml", xmlfilename); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - if (rsp.get_key_exists("error")) { - XHAL_ERROR("Address table update failed!"); - throw xhal::common::utils::XHALException("Error during address table update"); - } - return 0; + if (rsp.get_key_exists("error")) { + XHAL_ERROR("Address table update failed!"); + throw xhal::common::utils::XHALException("Error during address table update"); + } + return 0; } uint32_t xhal::client::rpcman::Utils::getRegInfoDB(char * regName) { - uint32_t address, mask; - std::string permissions; - req = wisc::RPCMsg("utils.readRegFromDB"); - req.set_string("reg_name", regName); - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; + uint32_t address, mask; + std::string permissions; + req = wisc::RPCMsg("utils.readRegFromDB"); + req.set_string("reg_name", regName); + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; - if (rsp.get_key_exists("error")) { - return 1; - } - printf("Register %s is found \n",regName); - try { - address = rsp.get_word("address"); - mask = rsp.get_word("mask"); - permissions = rsp.get_string("permissions"); + if (rsp.get_key_exists("error")) { + return 1; + } + printf("Register %s is found \n",regName); + try { + address = rsp.get_word("address"); + mask = rsp.get_word("mask"); + permissions = rsp.get_string("permissions"); - printf("Address: 0x%8x, permissions: %s, mask: 0x%8x \n", address, permissions.c_str(), mask); - } - STANDARD_CATCH; - return 0; + printf("Address: 0x%8x, permissions: %s, mask: 0x%8x \n", address, permissions.c_str(), mask); + } STANDARD_CATCH; + return 0; } diff --git a/xhal/src/client/rpc_manager/vfat3.cpp b/xhal/src/client/rpc_manager/vfat3.cpp index 59caf5c..0d1506b 100644 --- a/xhal/src/client/rpc_manager/vfat3.cpp +++ b/xhal/src/client/rpc_manager/vfat3.cpp @@ -2,99 +2,95 @@ #include "xhal/client/rpcman/vfat3.h" xhal::client::rpcman::VFAT3::VFAT3(const std::string& board_domain_name, const std::string& address_table_filename) : - xhal::client::XHALDevice(board_domain_name, address_table_filename) + xhal::client::XHALDevice(board_domain_name, address_table_filename) { this->loadModule("vfat3","vfat3 v1.0.1"); } uint32_t xhal::client::rpcman::VFAT3::configureVFAT3s(uint32_t ohN, uint32_t vfatMask) { - req = wisc::RPCMsg("vfat3.configureVFAT3s"); - req.set_word("vfatMask",vfatMask); - req.set_word("ohN",ohN); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - return 0; + req = wisc::RPCMsg("vfat3.configureVFAT3s"); + req.set_word("vfatMask",vfatMask); + req.set_word("ohN",ohN); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + return 0; } uint32_t xhal::client::rpcman::VFAT3::getChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData) { - req = wisc::RPCMsg("vfat3.getChannelRegistersVFAT3"); - req.set_word("ohN",ohN); - req.set_word("vfatMask",vfatMask); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - - const uint32_t size = 3072; - if (rsp.get_key_exists("chanRegData")) { - ASSERT(rsp.get_word_array_size("chanRegData") == size); - rsp.get_word_array("chanRegData", chanRegData); - } else { - printf("No channel register data found"); - return 1; - } - - return 0; + req = wisc::RPCMsg("vfat3.getChannelRegistersVFAT3"); + req.set_word("ohN",ohN); + req.set_word("vfatMask",vfatMask); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + + const uint32_t size = 3072; + if (rsp.get_key_exists("chanRegData")) { + ASSERT(rsp.get_word_array_size("chanRegData") == size); + rsp.get_word_array("chanRegData", chanRegData); + } else { + printf("No channel register data found"); + return 1; + } + + return 0; } uint32_t xhal::client::rpcman::VFAT3::setChannelRegistersVFAT3(uint32_t ohN, uint32_t vfatMask, uint32_t *calEnable, uint32_t *masks, uint32_t *trimARM, uint32_t *trimARMPol, uint32_t *trimZCC, uint32_t *trimZCCPol) { - req = wisc::RPCMsg("vfat3.setChannelRegistersVFAT3"); - req.set_word("ohN",ohN); - req.set_word("vfatMask",vfatMask); - - req.set_word_array("calEnable",calEnable,3072); - req.set_word_array("masks",masks,3072); - req.set_word_array("trimARM",trimARM,3072); - req.set_word_array("trimARMPol",trimARMPol,3072); - req.set_word_array("trimZCC",trimZCC,3072); - req.set_word_array("trimZCCPol",trimZCCPol,3072); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - return 0; + req = wisc::RPCMsg("vfat3.setChannelRegistersVFAT3"); + req.set_word("ohN",ohN); + req.set_word("vfatMask",vfatMask); + + req.set_word_array("calEnable",calEnable,3072); + req.set_word_array("masks",masks,3072); + req.set_word_array("trimARM",trimARM,3072); + req.set_word_array("trimARMPol",trimARMPol,3072); + req.set_word_array("trimZCC",trimZCC,3072); + req.set_word_array("trimZCCPol",trimZCCPol,3072); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + return 0; } uint32_t xhal::client::rpcman::VFAT3::setChannelRegistersVFAT3Simple(uint32_t ohN, uint32_t vfatMask, uint32_t *chanRegData) { - req = wisc::RPCMsg("vfat3.setChannelRegistersVFAT3"); - req.set_word("ohN",ohN); - req.set_word("vfatMask",vfatMask); - req.set_word("simple",true); - - req.set_word_array("chanRegData",chanRegData,3072); - - try { - rsp = rpc.call_method(req); - } - STANDARD_CATCH; - - if (rsp.get_key_exists("error")) { - printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); - return 1; - } - return 0; + req = wisc::RPCMsg("vfat3.setChannelRegistersVFAT3"); + req.set_word("ohN",ohN); + req.set_word("vfatMask",vfatMask); + req.set_word("simple",true); + + req.set_word_array("chanRegData",chanRegData,3072); + + try { + rsp = rpc.call_method(req); + } STANDARD_CATCH; + + if (rsp.get_key_exists("error")) { + printf("Caught an error: %s\n", (rsp.get_string("error")).c_str()); + return 1; + } + return 0; } From 68aaa655a0063981d51f5fd9722563ee12861e61 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Mon, 16 Sep 2019 23:24:51 +0200 Subject: [PATCH 43/56] [style] Standardize whitespace and brace style in `common/utils` files --- xhal/include/xhal/common/utils/Exception.h | 14 +- xhal/include/xhal/common/utils/XHALXMLNode.h | 18 +- .../include/xhal/common/utils/XHALXMLParser.h | 45 ++--- xhal/src/common/utils/XHALXMLParser.cpp | 158 ++++++++---------- 4 files changed, 110 insertions(+), 125 deletions(-) diff --git a/xhal/include/xhal/common/utils/Exception.h b/xhal/include/xhal/common/utils/Exception.h index 9dc6fdd..09bc8d4 100644 --- a/xhal/include/xhal/common/utils/Exception.h +++ b/xhal/include/xhal/common/utils/Exception.h @@ -3,7 +3,7 @@ * XHAL exception base class * * @author Mykhailo Dalchenko - * @version 1.0 + * @version 1.0 */ #ifndef XHAL_COMMON_UTILS_EXCEPTION_H @@ -19,15 +19,13 @@ namespace xhal { \ namespace utils { \ class EXCEPTION_NAME : public std::exception { \ public: \ - EXCEPTION_NAME(std::string message) : msg(message) { \ + EXCEPTION_NAME(std::string message) : \ + msg(message) {} \ \ - } \ - \ - virtual ~EXCEPTION_NAME() { \ - \ - } \ + virtual ~EXCEPTION_NAME() {} \ \ - virtual const char* what() const noexcept (true) override { \ + virtual const char* what() const noexcept (true) override \ + { \ return msg.c_str(); \ } \ \ diff --git a/xhal/include/xhal/common/utils/XHALXMLNode.h b/xhal/include/xhal/common/utils/XHALXMLNode.h index 967ecce..3ac128a 100644 --- a/xhal/include/xhal/common/utils/XHALXMLNode.h +++ b/xhal/include/xhal/common/utils/XHALXMLNode.h @@ -44,15 +44,19 @@ namespace xhal { warn_min_value = -1; error_min_value = -1; } - ~Node(){} + + ~Node() {} + /** * @brief Adds child node */ void addChild(Node child) {children.push_back(child);} + /** * @brief Returns VHDL node name */ - std::string getVhdlName(){return vhdlname;} + std::string getVhdlName() {return vhdlname;} + /** * @brief Not implemented */ @@ -69,7 +73,7 @@ namespace xhal { //print 'Module:',self.isModule //print 'Parent:',self.parent.name } - + /** * @brief Returns all hierarchy of chlid nodes * @param node parent node @@ -77,17 +81,15 @@ namespace xhal { */ void getAllChildren(Node node, std::vector kids) { - if (node.children.empty()) - { + if (node.children.empty()) { kids.push_back(node); } else { - for (auto const& child: node.children) - { + for (auto const& child: node.children) { getAllChildren(child, kids); } } } - + std::string name; std::string description; std::string vhdlname; diff --git a/xhal/include/xhal/common/utils/XHALXMLParser.h b/xhal/include/xhal/common/utils/XHALXMLParser.h index 53a059e..c3d3bde 100644 --- a/xhal/include/xhal/common/utils/XHALXMLParser.h +++ b/xhal/include/xhal/common/utils/XHALXMLParser.h @@ -3,7 +3,7 @@ * XML parser for XHAL library. Parses the XML address table and store results in unordered map of (regName, Node) * * @author Mykhailo Dalchenko - * @version 1.0 + * @version 1.0 */ @@ -43,8 +43,8 @@ #define XHAL_TRACE(MSG) LOG4CPLUS_TRACE(m_logger, MSG) #define XHAL_DEBUG(MSG) LOG4CPLUS_DEBUG(m_logger, MSG) -#define XHAL_INFO(MSG) LOG4CPLUS_INFO(m_logger, MSG) -#define XHAL_WARN(MSG) LOG4CPLUS_WARN(m_logger, MSG) +#define XHAL_INFO(MSG) LOG4CPLUS_INFO(m_logger, MSG) +#define XHAL_WARN(MSG) LOG4CPLUS_WARN(m_logger, MSG) #define XHAL_ERROR(MSG) LOG4CPLUS_ERROR(m_logger, MSG) #define XHAL_FATAL(MSG) LOG4CPLUS_FATAL(m_logger, MSG) @@ -66,9 +66,9 @@ namespace xhal { * @param xmlFile address table file name */ XHALXMLParser(const std::string& xmlFile); - + ~XHALXMLParser(); - + /** * @brief sets amount of logging/debugging information to display * @param loglevel: @@ -79,31 +79,33 @@ namespace xhal { * 4 - TRACE */ void setLogLevel(int loglevel); + /** * @brief parses XML file and creates flattened nodes tree */ void parseXML(); + /** * @brief returns node object by its name or nothing if name is not found */ - #ifdef __ARM_ARCH_7A__ - std::experimental::optional getNode(const char* nodeName); - #else - boost::optional getNode(const char* nodeName); - #endif +#ifdef __ARM_ARCH_7A__ + std::experimental::optional getNode(const char* nodeName); +#else + boost::optional getNode(const char* nodeName); +#endif /** * @brief not implemented */ - #ifdef __ARM_ARCH_7A__ - std::experimental::optional getNodeFromAddress(const uint32_t nodeAddress); - #else - boost::optional getNodeFromAddress(const uint32_t nodeAddress); - #endif +#ifdef __ARM_ARCH_7A__ + std::experimental::optional getNodeFromAddress(const uint32_t nodeAddress); +#else + boost::optional getNodeFromAddress(const uint32_t nodeAddress); +#endif /** * @brief return all nodes */ std::unordered_map getAllNodes(); - + private: std::string m_xmlFile; log4cplus::Logger m_logger; @@ -113,27 +115,30 @@ namespace xhal { xercesc::DOMNode* m_node; xercesc::DOMNodeList* children; static int index; - + /** * @brief fills custom node object */ void makeTree(xercesc::DOMNode * node, std::string basename, uint32_t baseAddress, std::unordered_map * nodes, xhal::common::utils::Node * parentNode, std::unordered_map vars, bool isGenerated); + /** * @brief returns node attribute value by its name if found */ - #ifdef __ARM_ARCH_7A__ +#ifdef __ARM_ARCH_7A__ std::experimental::optional getAttVal(xercesc::DOMNode * t_node, const char * attname); - #else +#else boost::optional getAttVal(xercesc::DOMNode * t_node, const char * attname); - #endif +#endif /** * @brief converts string representation of hex, binary or decimal number to an integer */ unsigned int parseInt(std::string & s); + /** * @brief returns cleaned from automatic generation symbols node name */ std::string substituteVars(std::string & s, std::unordered_map dict); + /** * @brief returns a copy of original string with all occurences of first substring replaced with second substring */ diff --git a/xhal/src/common/utils/XHALXMLParser.cpp b/xhal/src/common/utils/XHALXMLParser.cpp index 8f4d845..b3f081b 100644 --- a/xhal/src/common/utils/XHALXMLParser.cpp +++ b/xhal/src/common/utils/XHALXMLParser.cpp @@ -23,29 +23,29 @@ xhal::common::utils::XHALXMLParser::XHALXMLParser(const std::string& xmlFile) xhal::common::utils::XHALXMLParser::~XHALXMLParser() { - if (m_nodes) delete m_nodes; + if (m_nodes) + delete m_nodes; m_logger.shutdown(); } void xhal::common::utils::XHALXMLParser::setLogLevel(int loglevel) { - switch(loglevel) - { - case 0: - m_logger.setLogLevel(log4cplus::ERROR_LOG_LEVEL); - break; - case 1: - m_logger.setLogLevel(log4cplus::WARN_LOG_LEVEL); - break; - case 2: - m_logger.setLogLevel(log4cplus::INFO_LOG_LEVEL); - break; - case 3: - m_logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL); - break; - case 4: - m_logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL); - break; + switch (loglevel) { + case 0: + m_logger.setLogLevel(log4cplus::ERROR_LOG_LEVEL); + break; + case 1: + m_logger.setLogLevel(log4cplus::WARN_LOG_LEVEL); + break; + case 2: + m_logger.setLogLevel(log4cplus::INFO_LOG_LEVEL); + break; + case 3: + m_logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL); + break; + case 4: + m_logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL); + break; } } @@ -56,10 +56,10 @@ void xhal::common::utils::XHALXMLParser::parseXML() try { xercesc::XMLPlatformUtils::Initialize(); XHAL_INFO("Successfully initialized XML4C system"); - } catch(const xercesc::XMLException& toCatch) { + } catch (const xercesc::XMLException& toCatch) { XHAL_ERROR("Error during Xerces-c Initialization." << std::endl - << " Exception message:" - << xercesc::XMLString::transcode(toCatch.getMessage())); + << " Exception message:" + << xercesc::XMLString::transcode(toCatch.getMessage())); throw xhal::common::utils::XHALXMLParserException("XHALParser: initialization failed"); return; } @@ -87,7 +87,7 @@ void xhal::common::utils::XHALXMLParser::parseXML() config->setParameter(xercesc::XMLUni::fgXercesHandleMultipleImports, true); config->setParameter(xercesc::XMLUni::fgXercesSchemaFullChecking, false); - if(config->canSetParameter(xercesc::XMLUni::fgXercesDoXInclude, true)){ + if (config->canSetParameter(xercesc::XMLUni::fgXercesDoXInclude, true)) { config->setParameter(xercesc::XMLUni::fgXercesDoXInclude, true); XHAL_DEBUG("Xerces parser set to do XInclude "); } @@ -104,14 +104,14 @@ void xhal::common::utils::XHALXMLParser::parseXML() } catch (const xercesc::XMLException& e) { XHAL_ERROR("An error occured during parsing" << std::endl - << " Message: " - << xercesc::XMLString::transcode(e.getMessage())); + << " Message: " + << xercesc::XMLString::transcode(e.getMessage())); errorsOccured = true; // fileError = "An error occured during parsing of selected file. Please select another configuration file."; } catch (const xercesc::DOMException& e) { XHAL_ERROR("An error occured during parsing" << std::endl - << " Message: " - << xercesc::XMLString::transcode(e.msg)); + << " Message: " + << xercesc::XMLString::transcode(e.msg)); errorsOccured = true; // fileError = "An error occured during parsing of selected file. Please select another configuration file."; } catch (...) { @@ -122,13 +122,13 @@ void xhal::common::utils::XHALXMLParser::parseXML() if (!errorsOccured) { XHAL_DEBUG("DOM tree created succesfully"); - if (doc->getDocumentElement()!=NULL){ + if (doc->getDocumentElement()!=NULL) { m_root = doc->getDocumentElement(); } XHAL_DEBUG("Root node (getDocumentElement) obtained"); makeTree(m_root,"",0x0,m_nodes,NULL,m_vars,false); XHAL_DEBUG("Number of nodes: " << m_nodes->size()); - } else{ + } else { throw xhal::common::utils::XHALXMLParserException("XHALParser: an error occured during parsing"); } XHAL_DEBUG("Parsing done!"); @@ -143,20 +143,17 @@ void xhal::common::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std:: unsigned int generateAddressStep; std::string generateIdxVar; XHAL_DEBUG("Declare some local variables"); - if (isGenerated == false) - { + if (isGenerated == false) { XHAL_DEBUG("Node is not _generated_"); - if (auto tmp = getAttVal(node, "generate")) - { - if (*tmp == "true"){ + if (auto tmp = getAttVal(node, "generate")) { + if (*tmp == "true") { XHAL_DEBUG("Generate nodes"); tmp = getAttVal(node, "generate_size"); generateSize = parseInt(*tmp); tmp = getAttVal(node, "generate_address_step"); generateAddressStep = parseInt(*tmp); auto generateIdxVar = getAttVal(node, "generate_idx_var"); - for (unsigned int i = 0; i < generateSize; i++)// in range(0, generateSize): - { + for (unsigned int i = 0; i < generateSize; i++) {// in range(0, generateSize): vars[*generateIdxVar] = i; makeTree(node, baseName, baseAddress + generateAddressStep * i, nodes, parentNode, vars, true); } @@ -172,9 +169,8 @@ void xhal::common::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std:: uint32_t address; name = baseName; address = baseAddress; - if (baseName != "") {name += ".";} - if (auto tmp = getAttVal(node, "id")) - { + if (baseName != "") name += "."; + if (auto tmp = getAttVal(node, "id")) { name.append(*tmp); } else { XHAL_ERROR("getAttVal returned NONE, node has no id attribute"); @@ -183,48 +179,39 @@ void xhal::common::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std:: name = substituteVars(name, vars); XHAL_DEBUG("Node name: " << name); newNode.name = name; - if (auto tmp = getAttVal(node, "description")) - { + if (auto tmp = getAttVal(node, "description")) { newNode.description = *tmp; } - if (auto tmp = getAttVal(node, "address")) - { + if (auto tmp = getAttVal(node, "address")) { address = baseAddress + parseInt(*tmp); newNode.address = address; newNode.real_address = (address<<2)+0x64000000; } else { XHAL_TRACE("getAttVal returned NONE"); } - if (auto tmp = getAttVal(node, "permission")) - { + if (auto tmp = getAttVal(node, "permission")) { newNode.permission = *tmp; } - if (auto tmp = getAttVal(node, "mode")) - { + if (auto tmp = getAttVal(node, "mode")) { newNode.mode = *tmp; } - if (auto tmp = getAttVal(node, "size")) - { + if (auto tmp = getAttVal(node, "size")) { newNode.size = parseInt(*tmp); } - if (auto tmp = getAttVal(node, "mask")) - { + if (auto tmp = getAttVal(node, "mask")) { newNode.mask = parseInt(*tmp); } newNode.isModule = (getAttVal(node, "fw_is_module")) && (*getAttVal(node, "fw_is_module") == "true"); - if (auto tmp = getAttVal(node, "sw_monitor_warn_min_threshold")) - { + if (auto tmp = getAttVal(node, "sw_monitor_warn_min_threshold")) { newNode.warn_min_value = parseInt(*tmp); } - if (auto tmp = getAttVal(node, "sw_monitor_error_min_threshold")) - { + if (auto tmp = getAttVal(node, "sw_monitor_error_min_threshold")) { newNode.warn_min_value = parseInt(*tmp); } nodes->insert(std::make_pair(newNode.name,newNode)); XHAL_TRACE("Node map size after insert " << nodes->size()); - if (parentNode) - { + if (parentNode) { parentNode->addChild(newNode); newNode.parent = parentNode; newNode.level = parentNode->level+1; @@ -233,10 +220,8 @@ void xhal::common::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std:: const XMLSize_t nodeCount = children_->getLength(); XHAL_DEBUG("Node children length: " << nodeCount); - for( XMLSize_t ix = 0 ; ix < nodeCount ; ++ix ) - { - if (children_->item(ix)->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) - { + for (XMLSize_t ix = 0 ; ix < nodeCount ; ++ix) { + if (children_->item(ix)->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) { makeTree(children_->item(ix),name,address,nodes,&newNode,vars,false); } else { continue; @@ -247,7 +232,7 @@ void xhal::common::utils::XHALXMLParser::makeTree(xercesc::DOMNode * node, std:: #ifdef __ARM_ARCH_7A__ std::experimental::optional xhal::common::utils::XHALXMLParser::getAttVal(xercesc::DOMNode * t_node_, const char * attname) #else -boost::optional xhal::common::utils::XHALXMLParser::getAttVal(xercesc::DOMNode * t_node_, const char * attname) + boost::optional xhal::common::utils::XHALXMLParser::getAttVal(xercesc::DOMNode * t_node_, const char * attname) #endif { XHAL_TRACE("Call getAttVal for attribute " << attname); @@ -257,15 +242,13 @@ boost::optional xhal::common::utils::XHALXMLParser::getAttVal(xerce XHAL_TRACE("successfull call of getAttribute: " << t_node->getAttribute(tmp)); char * tmp2 = xercesc::XMLString::transcode(t_node->getAttribute(tmp)); XHAL_TRACE("tmp2: " << tmp2); - if (tmp2[0]!='\0') - { + if (tmp2[0]!='\0') { std::string value = tmp2; xercesc::XMLString::release(&tmp); xercesc::XMLString::release(&tmp2); XHAL_TRACE("result " << value); return value; - } else - { + } else { XHAL_TRACE("Attribute not found"); xercesc::XMLString::release(&tmp); xercesc::XMLString::release(&tmp2); @@ -294,11 +277,12 @@ unsigned int xhal::common::utils::XHALXMLParser::parseInt(std::string & s) std::string xhal::common::utils::XHALXMLParser::substituteVars(std::string & s, std::unordered_map dict) { - if (s == "") {return s;} + if (s == "") + return s; + std::string ret; ret = s; - for (auto& p: dict) - { + for (auto& p: dict) { ret = replaceAll(ret,"${" + p.first + "}",std::to_string(p.second)); } return ret; @@ -306,32 +290,31 @@ std::string xhal::common::utils::XHALXMLParser::substituteVars(std::string & s, std::string xhal::common::utils::XHALXMLParser::replaceAll( std::string const& original, std::string const& from, std::string const& to ) { - std::string results; - std::string::const_iterator end = original.end(); - std::string::const_iterator current = original.begin(); - std::string::const_iterator next = std::search( current, end, from.begin(), from.end() ); - while ( next != end ) { - results.append( current, next ); - results.append( to ); - current = next + from.size(); - next = std::search( current, end, from.begin(), from.end() ); - } + std::string results; + std::string::const_iterator end = original.end(); + std::string::const_iterator current = original.begin(); + std::string::const_iterator next = std::search( current, end, from.begin(), from.end() ); + while ( next != end ) { results.append( current, next ); - return results; + results.append( to ); + current = next + from.size(); + next = std::search( current, end, from.begin(), from.end() ); + } + results.append( current, next ); + return results; } #ifdef __ARM_ARCH_7A__ std::experimental::optional xhal::common::utils::XHALXMLParser::getNode(const char* nodeName) #else -boost::optional xhal::common::utils::XHALXMLParser::getNode(const char* nodeName) + boost::optional xhal::common::utils::XHALXMLParser::getNode(const char* nodeName) #endif { XHAL_DEBUG("Call getNode for argument " << nodeName); //Node * res = NULL; XHAL_TRACE("Searching unordered map"); auto search = m_nodes->find(nodeName); - if (search!=m_nodes->end()) - { + if (search!=m_nodes->end()) { return search->second; } else { return {}; @@ -342,20 +325,17 @@ boost::optional xhal::common::utils::XHALXMLParser::g #ifdef __ARM_ARCH_7A__ std::experimental::optional xhal::common::utils::XHALXMLParser::getNodeFromAddress(const uint32_t nodeAddress) #else -boost::optional xhal::common::utils::XHALXMLParser::getNodeFromAddress(const uint32_t nodeAddress) + boost::optional xhal::common::utils::XHALXMLParser::getNodeFromAddress(const uint32_t nodeAddress) #endif { //Node * res = NULL; - //for (auto & n: *m_nodes) - //{ - // if (nodeAddress == n.real_address) - // { + //for (auto & n: *m_nodes) { + // if (nodeAddress == n.real_address) { // res = &n; // break; // } //} - //if (res) - //{ + //if (res) { // return *res; //} else { // return {}; From 510d5f6a3d71f08d1fadcdcf3f7b165daf3e0fb2 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Tue, 17 Sep 2019 00:40:28 +0200 Subject: [PATCH 44/56] [style] Standardize whitespace and brace style in `common/rpc` files --- xhal/include/xhal/common/rpc/call.h | 146 +++++----- xhal/include/xhal/common/rpc/common.h | 331 +++++++++++----------- xhal/include/xhal/common/rpc/compat.h | 228 ++++++++------- xhal/include/xhal/common/rpc/exceptions.h | 102 +++---- xhal/include/xhal/common/rpc/helper.h | 186 ++++++------ xhal/include/xhal/common/rpc/register.h | 98 +++---- 6 files changed, 556 insertions(+), 535 deletions(-) diff --git a/xhal/include/xhal/common/rpc/call.h b/xhal/include/xhal/common/rpc/call.h index 35018ed..9b3f188 100644 --- a/xhal/include/xhal/common/rpc/call.h +++ b/xhal/include/xhal/common/rpc/call.h @@ -23,24 +23,24 @@ namespace xhal { namespace common { namespace rpc { - /** - * @brief Remotely call a RPC method - * - * The remote method called is defined by the template parameter - * @c Method. The arguments to give to the function are those from - * the @c Method::operator() signature and their types @b must be deducible. - */ - template::value, int>::type = 0 - > - helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args); - - /** - * @brief Thrown by @ref call when an exception is thrown on the remote host. - */ - class RemoteException : public std::runtime_error - { + /** + * @brief Remotely call a RPC method + * + * The remote method called is defined by the template parameter + * @c Method. The arguments to give to the function are those from + * the @c Method::operator() signature and their types @b must be deducible. + */ + template::value, int>::type = 0 + > + helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args); + + /** + * @brief Thrown by @ref call when an exception is thrown on the remote host. + */ + class RemoteException : public std::runtime_error + { std::string m_type; /** @@ -58,13 +58,12 @@ namespace xhal { * @param response An RPC response to extract error information from. */ explicit RemoteException(const wisc::RPCMsg &response) : - std::runtime_error(helper::readExceptionMessage(response)), - m_type(response.get_key_exists(std::string(abiVersion) + ".type") ? - response.get_string(std::string(abiVersion) + ".type") : "") - { - } + std::runtime_error(helper::readExceptionMessage(response)), + m_type(response.get_key_exists(std::string(abiVersion) + ".type") ? + response.get_string(std::string(abiVersion) + ".type") : "") + {} - public: + public: /** * @brief Returns @c true if the type of the exception is available. */ @@ -74,16 +73,16 @@ namespace xhal { * @brief Returns the exception type name if available, an empty string otherwise. */ std::string type() const { return m_type; } - }; - - /** - * @brief Thrown by @c call when there is a problem calling the remote method. - * - * This can be either because the Wisconsin messaging layer throws an exception or because - * the method can't be found. - */ - class MessageException : public std::runtime_error - { + }; + + /** + * @brief Thrown by @c call when there is a problem calling the remote method. + * + * This can be either because the Wisconsin messaging layer throws an exception or because + * the method can't be found. + */ + class MessageException : public std::runtime_error + { /** * @brief @ref call is the only function that can throw this exception. */ @@ -98,61 +97,62 @@ namespace xhal { * @brief Constructor. */ explicit MessageException(const std::string &message) : - std::runtime_error(message) + std::runtime_error(message) {} - public: - // Use what() - }; - - /* Implementation */ - template::value, int>::type - > - helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args) - { + public: + // Use what() + }; + + /* Implementation */ + template::value, int>::type + > + helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args) + { try { - // The wisc::RPCMsg method name is taken from the typeid - // This is implementation dependent but g++ and clang++ - // follow the same convention - wisc::RPCMsg request(std::string(abiVersion) + "." + typeid(Method).name()); - MessageSerializer query{&request}; + // The wisc::RPCMsg method name is taken from the typeid + // This is implementation dependent but g++ and clang++ + // follow the same convention + wisc::RPCMsg request(std::string(abiVersion) + "." + typeid(Method).name()); + MessageSerializer query{&request}; - // Type conversion from args to serializable types - // must be performed in the same statement in order to - // make use of lifetime extension - query << helper::get_forward_as_tuple()(args...); + // Type conversion from args to serializable types + // must be performed in the same statement in order to + // make use of lifetime extension + query << helper::get_forward_as_tuple()(args...); - // Remote call - const wisc::RPCMsg response = connection.call_method(request); + // Remote call + const wisc::RPCMsg response = connection.call_method(request); - // Check for errors - if (response.get_key_exists("rpcerror")) { - throw MessageException(response.get_string("rpcerror")); - } else if (response.get_key_exists(std::string(abiVersion) + ".error")) { - throw RemoteException(response); - } + // Check for errors + if (response.get_key_exists("rpcerror")) { + throw MessageException(response.get_string("rpcerror")); + } else if (response.get_key_exists(std::string(abiVersion) + ".error")) { + throw RemoteException(response); + } - // The RPC method can return a void so the void_holder is required - compat::void_holder> return_v; + // The RPC method can return a void so the void_holder is required + compat::void_holder> return_v; - MessageDeserializer reply{&response}; - reply >> return_v; + MessageDeserializer reply{&response}; + reply >> return_v; - return return_v.get(); + return return_v.get(); } catch (const wisc::RPCMsg::BadKeyException &e) { - throw MessageException(helper::getExceptionMessage(e)); + throw MessageException(helper::getExceptionMessage(e)); } catch (const wisc::RPCMsg::TypeException &e) { - throw MessageException(helper::getExceptionMessage(e)); + throw MessageException(helper::getExceptionMessage(e)); } catch (const wisc::RPCMsg::BufferTooSmallException &e) { - throw MessageException(helper::getExceptionMessage(e)); + throw MessageException(helper::getExceptionMessage(e)); } catch (const wisc::RPCMsg::CorruptMessageException &e) { - throw MessageException(helper::getExceptionMessage(e)); + throw MessageException(helper::getExceptionMessage(e)); } catch (const wisc::RPCSvc::RPCException &e) { - throw MessageException(helper::getExceptionMessage(e)); + throw MessageException(helper::getExceptionMessage(e)); } + } } } } diff --git a/xhal/include/xhal/common/rpc/common.h b/xhal/include/xhal/common/rpc/common.h index dc2cab1..b31e7b4 100644 --- a/xhal/include/xhal/common/rpc/common.h +++ b/xhal/include/xhal/common/rpc/common.h @@ -24,19 +24,19 @@ namespace xhal { namespace common { namespace rpc { - /** - * @brief Defines the templated RPC ABI version - */ - static constexpr const char* abiVersion = "v1"; - - /** - * @brief Class whose all remotely callable RPC method must inherit from - * - * The required inheritance is used as a compile time check so a developer - * cannot remotely call a local function by mistake. - */ - struct Method - { + /** + * @brief Defines the templated RPC ABI version + */ + static constexpr const char* abiVersion = "v1"; + + /** + * @brief Class whose all remotely callable RPC method must inherit from + * + * The required inheritance is used as a compile time check so a developer + * cannot remotely call a local function by mistake. + */ + struct Method + { /** * @brief The operator call must be define once and only once per * RPC method. @@ -46,16 +46,17 @@ namespace xhal { * * @warnng The call operator @b must be defined as @c const. */ - template R operator()(Args...) const; - }; + template + R operator()(Args...) const; + }; - /** - * @brief Base of the @c MessageSerializer and @c MessageDeserializer classes - * - * @c MessageBase provides the key index tracking functionnality which - * is mandatory for serialization. - */ - class MessageBase { + /** + * @brief Base of the @c MessageSerializer and @c MessageDeserializer classes + * + * @c MessageBase provides the key index tracking functionnality which + * is mandatory for serialization. + */ + class MessageBase { /** * @brief Index to the next free/unread key @@ -69,15 +70,15 @@ namespace xhal { */ inline uint32_t dispenseKey() { return _keyIdx++; } - }; + }; - /** - * @brief This class serializes parameters into a @c wisc::RPCMsg - */ - class MessageSerializer : public MessageBase - { + /** + * @brief This class serializes parameters into a @c wisc::RPCMsg + */ + class MessageSerializer : public MessageBase + { - protected: + protected: wisc::RPCMsg *m_wiscMsg; @@ -92,38 +93,39 @@ namespace xhal { * remembering the developer that she/he can transmit defined types over the * network. */ - template inline void save(const T &t) { - // This const_cast is safe when the API is used as intented - // More precisely when the object t is modified only with the operator& - serialize(*this, const_cast(t)); + template + inline void save(const T &t) { + // This const_cast is safe when the API is used as intented + // More precisely when the object t is modified only with the operator& + serialize(*this, const_cast(t)); } /** * @brief Adds a @c std::uint32_t to the message */ inline void save(const std::uint32_t value) { - m_wiscMsg->set_word(std::to_string(dispenseKey()), value); + m_wiscMsg->set_word(std::to_string(dispenseKey()), value); } /** * @brief Adds a @c std::vector to the message */ inline void save(const std::vector &value) { - m_wiscMsg->set_word_array(std::to_string(dispenseKey()), value); + m_wiscMsg->set_word_array(std::to_string(dispenseKey()), value); } /** * @brief Adds a @c std::string to the message */ inline void save(const std::string &value) { - m_wiscMsg->set_string(std::to_string(dispenseKey()), value); + m_wiscMsg->set_string(std::to_string(dispenseKey()), value); } /** * @brief Adds a @c std::vector to the message */ inline void save(const std::vector &value) { - m_wiscMsg->set_string_array(std::to_string(dispenseKey()), value); + m_wiscMsg->set_string_array(std::to_string(dispenseKey()), value); } /** @@ -134,45 +136,47 @@ namespace xhal { typename std::enable_if::value && !helper::is_bool::value, int>::type = 0 > inline void save(const std::array &value) { - m_wiscMsg->set_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); + m_wiscMsg->set_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); } /** * @brief Adds a @c std::map to the message where @c T is a serializable type */ - template inline void save(const std::map &value) { - // The first RPC key stores the std::map keys - // This is required to know the std::map size at deserialization - const auto keysKey = dispenseKey(); + template + inline void save(const std::map &value) { + // The first RPC key stores the std::map keys + // This is required to know the std::map size at deserialization + const auto keysKey = dispenseKey(); - std::vector keys{}; - keys.reserve(value.size()); + std::vector keys{}; + keys.reserve(value.size()); - for (const auto & elem : value) { - keys.push_back(elem.first); - this->save(elem.second); - } + for (const auto & elem : value) { + keys.push_back(elem.first); + this->save(elem.second); + } - m_wiscMsg->set_word_array(std::to_string(keysKey), keys); + m_wiscMsg->set_word_array(std::to_string(keysKey), keys); } /** * @brief Adds a @c std::map to the message where @c T is a serializable type */ - template inline void save(const std::map &value) { - // The first RPC key stores the std::map keys - // This is required to know the std::map size at deserialization - const auto keysKey = dispenseKey(); + template + inline void save(const std::map &value) { + // The first RPC key stores the std::map keys + // This is required to know the std::map size at deserialization + const auto keysKey = dispenseKey(); - std::vector keys{}; - keys.reserve(value.size()); + std::vector keys{}; + keys.reserve(value.size()); - for (const auto & elem : value) { - keys.push_back(elem.first); - this->save(elem.second); - } + for (const auto & elem : value) { + keys.push_back(elem.first); + this->save(elem.second); + } - m_wiscMsg->set_string_array(std::to_string(keysKey), keys); + m_wiscMsg->set_string_array(std::to_string(keysKey), keys); } /** @@ -180,8 +184,9 @@ namespace xhal { * * It should be used when setting the result from a function call. */ - template inline void save(const compat::void_holder &holder) { - this->save(holder.get()); + template + inline void save(const compat::void_holder &holder) { + this->save(holder.get()); } /** @@ -200,8 +205,8 @@ namespace xhal { typename std::enable_if::type = 0 > inline void save(const std::tuple &args) { - this->save(std::get(args)); - this->save(args); + this->save(std::get(args)); + this->save(args); } /** @@ -213,7 +218,7 @@ namespace xhal { > inline void save(const std::tuple &) {} - public: + public: /** * @brief Constructor @@ -227,8 +232,8 @@ namespace xhal { */ template inline MessageSerializer & operator<<(const T &t) { - this->save(t); - return *this; + this->save(t); + return *this; } /** @@ -240,22 +245,22 @@ namespace xhal { */ template inline MessageSerializer & operator&(const T &t) { - this->save(t); - return *this; + this->save(t); + return *this; } - }; + }; - /** - * @brief This class deserializes parameters from a @c wisc::RPCMsg - * - * While it cannot be made @c const because deserializing requires to keep - * track of the state, this class guarentees that the original @c wisc::RPCMsg - * object will remain untouched. - */ - class MessageDeserializer : public MessageBase { + /** + * @brief This class deserializes parameters from a @c wisc::RPCMsg + * + * While it cannot be made @c const because deserializing requires to keep + * track of the state, this class guarentees that the original @c wisc::RPCMsg + * object will remain untouched. + */ + class MessageDeserializer : public MessageBase { - protected: + protected: const wisc::RPCMsg *m_wiscMsg; @@ -270,36 +275,37 @@ namespace xhal { * remembering the developer that she/he can transmit defined types over the * network. */ - template inline void load(T &t) { - serialize(*this, t); + template + inline void load(T &t) { + serialize(*this, t); } /** * @brief Retrieves a @c std::uint32_t from the message */ inline void load(uint32_t &value) { - value = m_wiscMsg->get_word(std::to_string(dispenseKey())); + value = m_wiscMsg->get_word(std::to_string(dispenseKey())); } /** * @brief Retrieves a @c std::vector from the message */ inline void load(std::vector &value) { - value = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); + value = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); } /** * @brief Retrieves a @c std::string from the message */ inline void load(std::string &value) { - value = m_wiscMsg->get_string(std::to_string(dispenseKey())); + value = m_wiscMsg->get_string(std::to_string(dispenseKey())); } /** * @brief Retrieves a @c std::vector from the message */ inline void load(std::vector &value) { - value = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); + value = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); } /** @@ -310,33 +316,35 @@ namespace xhal { typename std::enable_if::value && !helper::is_bool::value, int>::type = 0 > inline void load(std::array &value) { - m_wiscMsg->get_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); + m_wiscMsg->get_binarydata(std::to_string(dispenseKey()), value.data(), N*sizeof(T)); } /** * @brief Retrieves a @c std::map from the message where @c T is a serializable type */ - template inline void load(std::map &value) { - const auto keys = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); - - for (const auto & key: keys) { - T val; - this->load(val); - value.emplace(key, std::move(val)); - } + template + inline void load(std::map &value) { + const auto keys = m_wiscMsg->get_word_array(std::to_string(dispenseKey())); + + for (const auto & key: keys) { + T val; + this->load(val); + value.emplace(key, std::move(val)); + } } /** * @brief Retrieves a @c std::map from the message where @c T is a serializable type */ - template inline void load(std::map &value) { - const auto keys = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); - - for (const auto & key: keys) { - T val; - this->load(val); - value.emplace(key, std::move(val)); - } + template + inline void load(std::map &value) { + const auto keys = m_wiscMsg->get_string_array(std::to_string(dispenseKey())); + + for (const auto & key: keys) { + T val; + this->load(val); + value.emplace(key, std::move(val)); + } } /** @@ -345,8 +353,9 @@ namespace xhal { * * It should be used when setting the result from a function. */ - template inline void load(compat::void_holder &value) { - this->load(value.get()); + template + inline void load(compat::void_holder &value) { + this->load(value.get()); } /** @@ -366,8 +375,8 @@ namespace xhal { typename std::enable_if::type = 0 > inline void load(std::tuple &args) { - this->load(std::get(args)); - this->load(args); + this->load(std::get(args)); + this->load(args); } /** @@ -379,7 +388,7 @@ namespace xhal { > inline void load(std::tuple &) { } - public: + public: /** * @brief Constructor @@ -391,10 +400,10 @@ namespace xhal { /** * @brief Allows to deserialiaze data from the message with a natural interface */ - template + template inline MessageDeserializer & operator>>(T &t) { - this->load(t); - return *this; + this->load(t); + return *this; } /** @@ -404,66 +413,66 @@ namespace xhal { * @c MessageDeserializer so custom types serialization can be defined in a single * function. */ - template + template inline MessageDeserializer & operator&(T &t) { - this->load(t); - return *this; + this->load(t); + return *this; } - }; + }; - /** - * @brief Provides a default (de)serialiazer in case the intrusive method is used - */ - template - inline void serialize(Message &msg, T &t) { + /** + * @brief Provides a default (de)serialiazer in case the intrusive method is used + */ + template + inline void serialize(Message &msg, T &t) { t.serialize(msg); - } + } - /** - * @brief Serializer for @c std::array where @c is a serializable type - * - * This a simple example of custom type serialization. - * - * The library provides two custom type serialization methods: - * - * 1. The intrusive method - * 2. The non-intrusive method - * - * Let's take an example : - * - * @code{.cpp} - * struct Point - * { - * std::uint32_t x, y; - * - * // The intrusive version is implemented as a new member function - * // which takes a message as parameter (i.e. the serializer or deserializer) - * template inline void serialize(Message & msg) { - * msg & x & y; - * } - * }; - * - * // The non-intrusive version allows to serialize objects defined in a library - * // Simply define the serialize function in the xhal::rpc namespace or the namespace - * // where the type is defined with two parameters (1) A message (i.e. the serializer - * // or deserializer) and (2) the custom type - * namespace xhal { namspace rpc { - * template inline void serialize(Message &msg, Point &point) { - * msq & point.x & point.y; - * } - * } } - * @endcode - * - * @warning In order to work as intended the @c serialize functions @b MUST modify - * the object only with the @c operator& - */ - template - inline void serialize(Message &msg, std::array &value) { + /** + * @brief Serializer for @c std::array where @c is a serializable type + * + * This a simple example of custom type serialization. + * + * The library provides two custom type serialization methods: + * + * 1. The intrusive method + * 2. The non-intrusive method + * + * Let's take an example : + * + * @code{.cpp} + * struct Point + * { + * std::uint32_t x, y; + * + * // The intrusive version is implemented as a new member function + * // which takes a message as parameter (i.e. the serializer or deserializer) + * template inline void serialize(Message & msg) { + * msg & x & y; + * } + * }; + * + * // The non-intrusive version allows to serialize objects defined in a library + * // Simply define the serialize function in the xhal::rpc namespace or the namespace + * // where the type is defined with two parameters (1) A message (i.e. the serializer + * // or deserializer) and (2) the custom type + * namespace xhal { namspace rpc { + * template inline void serialize(Message &msg, Point &point) { + * msq & point.x & point.y; + * } + * } } + * @endcode + * + * @warning In order to work as intended the @c serialize functions @b MUST modify + * the object only with the @c operator& + */ + template + inline void serialize(Message &msg, std::array &value) { // The std::array size is known at compile time (and part of // the signature), so we don't need to serialize it for (auto & elem: value) { - msg & elem; + msg & elem; } } } diff --git a/xhal/include/xhal/common/rpc/compat.h b/xhal/include/xhal/common/rpc/compat.h index 7163941..9a41cc6 100644 --- a/xhal/include/xhal/common/rpc/compat.h +++ b/xhal/include/xhal/common/rpc/compat.h @@ -22,127 +22,135 @@ namespace xhal { namespace rpc { namespace compat { - /** - * @brief This class can encapsulates any type, including @c void - * - * @c void is an incomplete type and cannot be easily used in fully generic - * templates. This class is designed to hold any type, including `void` so that - * it can be used in generic templates. - * - * The embedded object can be retrieved with the @c get() methods. - * - * In C++17 any code using this class is easily replaced with the - * constexpr if statement. - */ - template struct void_holder - { - T t; - T &get() { return t; } - const T &get() const { return t; } - }; + /** + * @brief This class can encapsulates any type, including @c void + * + * @c void is an incomplete type and cannot be easily used in fully generic + * templates. This class is designed to hold any type, including `void` so that + * it can be used in generic templates. + * + * The embedded object can be retrieved with the @c get() methods. + * + * In C++17 any code using this class is easily replaced with the + * constexpr if statement. + */ + template + struct void_holder + { + T t; + T &get() { return t; } + const T &get() const { return t; } + }; - /** - * @brief Specialization for the @c void type - */ - template<> struct void_holder - { - void get() const { return; } - }; + /** + * @brief Specialization for the @c void type + */ + template<> + struct void_holder + { + void get() const { return; } + }; - /** - * @brief This template class defines an indices sequence - * - * Please look at the @c integer_sequence from C++14 to get more - * information. - */ - template struct index_sequence {}; + /** + * @brief This template class defines an indices sequence + * + * Please look at the @c integer_sequence from C++14 to get more + * information. + */ + template + struct index_sequence + { + }; - /** - * @brief Generates an indices sequence - * - * The code follows the usual O(n) implementation. - * - * You can have a look at https://blog.galowicz.de/2016/06/24/integer_sequences_at_compile_time/ - * for more information. - */ - template struct index_sequence_gen; + /** + * @brief Generates an indices sequence + * + * The code follows the usual O(n) implementation. + * + * You can have a look at https://blog.galowicz.de/2016/06/24/integer_sequences_at_compile_time/ + * for more information. + */ + template + struct index_sequence_gen; - /** - * @brief Non-terminal call - */ - template struct index_sequence_gen - { - // I is the recursion index - // N... are the generated indices. - using type = typename index_sequence_gen::type; - }; + /** + * @brief Non-terminal call + */ + template + struct index_sequence_gen + { + // I is the recursion index + // N... are the generated indices. + using type = typename index_sequence_gen::type; + }; - /** - * @brief Terminal call - */ - template struct index_sequence_gen<0, N...> - { - using type = index_sequence; - }; + /** + * @brief Terminal call + */ + template + struct index_sequence_gen<0, N...> + { + using type = index_sequence; + }; - /** - * @brief Helper making an index sequence from @c 0 to @c N-1 - * - * Remind that an index sequence is the non-type template parameter of a - * specialization of the @c index_sequence template class. - */ - template + /** + * @brief Helper making an index sequence from @c 0 to @c N-1 + * + * Remind that an index sequence is the non-type template parameter of a + * specialization of the @c index_sequence template class. + */ + template using make_index_sequence = typename index_sequence_gen::type; - /** - * @brief Calls a function with arguments from a @c std::tuple - * - * This function is the implementation part of a specialized @c std::apply - * implementation. More information can be found in the C++17 standard. - * - * Please note that these functions are applied to our case and do not - * pretend to respect the C++17 standard in any way. Moreover the @c void - * return case is handled with our @c void_holder container. This imposes - * the first template argument to be explicitly set when calling @c tuple_apply - */ - template - auto tuple_apply_impl(F &&f, const std::tuple &tuple, index_sequence) - -> decltype(std::forward(f)(std::get(tuple)...)) - { - return std::forward(f)(std::get(tuple)...); - } + /** + * @brief Calls a function with arguments from a @c std::tuple + * + * This function is the implementation part of a specialized @c std::apply + * implementation. More information can be found in the C++17 standard. + * + * Please note that these functions are applied to our case and do not + * pretend to respect the C++17 standard in any way. Moreover the @c void + * return case is handled with our @c void_holder container. This imposes + * the first template argument to be explicitly set when calling @c tuple_apply + */ + template + auto tuple_apply_impl(F &&f, const std::tuple &tuple, index_sequence) + -> decltype(std::forward(f)(std::get(tuple)...)) + { + return std::forward(f)(std::get(tuple)...); + } - /** - * @brief Generic case - */ - template::value, int>::type = 0 - > - void_holder tuple_apply(F &&f, const std::tuple &tuple) - { - return void_holder{ + /** + * @brief Generic case + */ + template::value, int>::type = 0 + > + void_holder tuple_apply(F &&f, const std::tuple &tuple) + { + return void_holder{ tuple_apply_impl(std::forward(f), tuple, make_index_sequence{}) - }; - } + }; + } - /** - * @brief Specialization for the @c void type - */ - template::value, int>::type = 0 - > - void_holder tuple_apply(F &&f, const std::tuple &tuple) - { - tuple_apply_impl(std::forward(f), tuple, make_index_sequence{}); - return {}; - } + /** + * @brief Specialization for the @c void type + */ + template::value, int>::type = 0 + > + void_holder tuple_apply(F &&f, const std::tuple &tuple) + { + tuple_apply_impl(std::forward(f), tuple, make_index_sequence{}); + return {}; + } } } diff --git a/xhal/include/xhal/common/rpc/exceptions.h b/xhal/include/xhal/common/rpc/exceptions.h index 86bd925..f14e32d 100644 --- a/xhal/include/xhal/common/rpc/exceptions.h +++ b/xhal/include/xhal/common/rpc/exceptions.h @@ -15,64 +15,64 @@ namespace xhal { namespace rpc { namespace helper { - /** - * @brief Retrieves a user-friendly message for the given exception. - * - * Specialization for @c std::exception. - */ - std::string getExceptionMessage(const std::exception &e); + /** + * @brief Retrieves a user-friendly message for the given exception. + * + * Specialization for @c std::exception. + */ + std::string getExceptionMessage(const std::exception &e); - /** - * @brief Retrieves a user-friendly message for the given exception. - * - * Specialization for @c wisc::RPCMsg::BadKeyException. - * - * @note This function is never called because the constructor of @c BadKeyException calls - * @c std::abort. It is kept in case the issue is corrected in the future. - */ - std::string getExceptionMessage(const wisc::RPCMsg::BadKeyException &e); + /** + * @brief Retrieves a user-friendly message for the given exception. + * + * Specialization for @c wisc::RPCMsg::BadKeyException. + * + * @note This function is never called because the constructor of @c BadKeyException calls + * @c std::abort. It is kept in case the issue is corrected in the future. + */ + std::string getExceptionMessage(const wisc::RPCMsg::BadKeyException &e); - /** - * @brief Retrieves a user-friendly message for the given exception. - * - * Specialization for @c wisc::RPCMsg::TypeException. - */ - std::string getExceptionMessage(const wisc::RPCMsg::TypeException &e); + /** + * @brief Retrieves a user-friendly message for the given exception. + * + * Specialization for @c wisc::RPCMsg::TypeException. + */ + std::string getExceptionMessage(const wisc::RPCMsg::TypeException &e); - /** - * @brief Retrieves a user-friendly message for the given exception. - * - * Specialization for @c wisc::RPCMsg::BufferTooSmallException. - */ - std::string getExceptionMessage(const wisc::RPCMsg::BufferTooSmallException &e); + /** + * @brief Retrieves a user-friendly message for the given exception. + * + * Specialization for @c wisc::RPCMsg::BufferTooSmallException. + */ + std::string getExceptionMessage(const wisc::RPCMsg::BufferTooSmallException &e); - /** - * @brief Retrieves a user-friendly message for the given exception. - * - * Specialization for @c wisc::RPCMsg::CorruptMessageException. - */ - std::string getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e); + /** + * @brief Retrieves a user-friendly message for the given exception. + * + * Specialization for @c wisc::RPCMsg::CorruptMessageException. + */ + std::string getExceptionMessage(const wisc::RPCMsg::CorruptMessageException &e); - /** - * @brief Retrieves a user-friendly message for the given exception. - * - * Specialization for @c wisc::RPCSvc::RPCException and derived types. - */ - std::string getExceptionMessage(const wisc::RPCSvc::RPCException &e); + /** + * @brief Retrieves a user-friendly message for the given exception. + * + * Specialization for @c wisc::RPCSvc::RPCException and derived types. + */ + std::string getExceptionMessage(const wisc::RPCSvc::RPCException &e); - /** - * @brief Sets the type of the current exception in @c response. - * @internal This function makes use of low-level functions of the Itanium C++ ABI to - * retrieve the type name of the current exception. - */ - void setExceptionType(wisc::RPCMsg *response); + /** + * @brief Sets the type of the current exception in @c response. + * @internal This function makes use of low-level functions of the Itanium C++ ABI to + * retrieve the type name of the current exception. + */ + void setExceptionType(wisc::RPCMsg *response); - /** - * @brief Fetches an error message from @c response. - * - * The @c error key must be set and to a string. - */ - std::string readExceptionMessage(const wisc::RPCMsg &response); + /** + * @brief Fetches an error message from @c response. + * + * The @c error key must be set and to a string. + */ + std::string readExceptionMessage(const wisc::RPCMsg &response); } } diff --git a/xhal/include/xhal/common/rpc/helper.h b/xhal/include/xhal/common/rpc/helper.h index 3c6f6b0..02f3580 100644 --- a/xhal/include/xhal/common/rpc/helper.h +++ b/xhal/include/xhal/common/rpc/helper.h @@ -20,103 +20,111 @@ namespace xhal { namespace rpc { namespace helper { - /** - * @brief Allows to extract types of a functor - * - * This templated class provides the return type and argument types - * of a functor as traits. - * - * * @c return_type is the functor return type - * * @c decay_args_type are the decayed (cv-qualifiers and reference are - * removed) argument types in a @c std::tuple - * * @c forward_as_tuple returns a function converting its arguments - * to the arguments functor types - * - * Inspired by https://stackoverflow.com/a/10400131 - */ - template struct functor_traits; - - template - struct functor_traits - { - using return_type = R; - using decay_args_type = std::tuple::type...>; - - static constexpr inline auto forward_as_tuple() { + /** + * @brief Allows to extract types of a functor + * + * This templated class provides the return type and argument types + * of a functor as traits. + * + * * @c return_type is the functor return type + * * @c decay_args_type are the decayed (cv-qualifiers and reference are + * removed) argument types in a @c std::tuple + * * @c forward_as_tuple returns a function converting its arguments + * to the arguments functor types + * + * Inspired by https://stackoverflow.com/a/10400131 + */ + template + struct functor_traits; + + template + struct functor_traits + { + using return_type = R; + using decay_args_type = std::tuple::type...>; + + static constexpr inline auto forward_as_tuple() { return [](Args&&... args){ return std::forward_as_tuple(args...); }; - } - }; - - /** - * @brief Implementation of @c functor_return_t - * - * Should not be used as a function. - */ - template, - typename R = typename Traits::return_type - > - R functor_return_t_impl(Func); - - /** - * @brief Return type of the @c Obj functor - * - * Only works with @c const call operators since @c functor_traits is - * only defined for those. - */ - template + } + }; + + /** + * @brief Implementation of @c functor_return_t + * + * Should not be used as a function. + */ + template, + typename R = typename Traits::return_type + > + R functor_return_t_impl(Func); + + /** + * @brief Return type of the @c Obj functor + * + * Only works with @c const call operators since @c functor_traits is + * only defined for those. + */ + template using functor_return_t = decltype(functor_return_t_impl(&Obj::operator())); - /** - * @brief Implementation of @c functor_decay_args_t - * - * Should not be used as a function. - */ - template, - typename Args = typename Traits::decay_args_type - > - Args functor_decay_args_t_impl(Func); - - /** - * @brief @c std::tuple whose types are the functor argument types - * - * Only works with @c const call operators since @c functor_traits is - * only defined for those. - */ - template + /** + * @brief Implementation of @c functor_decay_args_t + * + * Should not be used as a function. + */ + template, + typename Args = typename Traits::decay_args_type + > + Args functor_decay_args_t_impl(Func); + + /** + * @brief @c std::tuple whose types are the functor argument types + * + * Only works with @c const call operators since @c functor_traits is + * only defined for those. + */ + template using functor_decay_args_t = decltype(functor_decay_args_t_impl(&Obj::operator())); - /** - * @brief Helper function to forward as a tuple matching the functor signature - */ - template - constexpr inline auto get_forward_as_tuple() { - return functor_traits::forward_as_tuple(); - } + /** + * @brief Helper function to forward as a tuple matching the functor signature + */ + template + constexpr inline auto get_forward_as_tuple() + { + return functor_traits::forward_as_tuple(); + } - /** - * @brief Checks whether the template parameter @c T is a @c bool - */ - template + /** + * @brief Checks whether the template parameter @c T is a @c bool + */ + template using is_bool = std::is_same::type, bool>; - /** - * @brief Checks whether the template parameter @c T is a @c std::tuple - */ - template - struct is_tuple_impl : std::false_type {}; - - template - struct is_tuple_impl> : std::true_type {}; - - /** - * @brief Helper alias for cv-qualified and reference types - */ - template + /** + * @brief Checks whether the template parameter @c T is a @c std::tuple + */ + template + struct is_tuple_impl : + std::false_type + { + }; + + template + struct is_tuple_impl> : + std::true_type + { + }; + + /** + * @brief Helper alias for cv-qualified and reference types + */ + template using is_tuple = is_tuple_impl::type>; } diff --git a/xhal/include/xhal/common/rpc/register.h b/xhal/include/xhal/common/rpc/register.h index 3224e8b..8aafeb2 100644 --- a/xhal/include/xhal/common/rpc/register.h +++ b/xhal/include/xhal/common/rpc/register.h @@ -30,11 +30,10 @@ namespace xhal { * In case a second exception occurs when setting the error key, @c std::terminate is called. */ template - void handleException(const Exception &e, wisc::RPCMsg *response) noexcept - { - // Log exception here? - response->set_string(std::string(abiVersion) + ".error", getExceptionMessage(e)); - setExceptionType(response); + void handleException(const Exception &e, wisc::RPCMsg *response) noexcept { + // Log exception here? + response->set_string(std::string(abiVersion) + ".error", getExceptionMessage(e)); + setExceptionType(response); } /** @@ -42,73 +41,70 @@ namespace xhal { * * In case an exception occurs when setting the error key, @c std::terminate is called. */ - void handleException(wisc::RPCMsg *response) noexcept - { - // Log exception here? - response->set_string(std::string(abiVersion) + ".error", "unknown exception type"); - setExceptionType(response); + void handleException(wisc::RPCMsg *response) noexcept { + // Log exception here? + response->set_string(std::string(abiVersion) + ".error", "unknown exception type"); + setExceptionType(response); } - } // namespace helper + } // namespace helper - /** - * @brief Locally invoke a RPC method - * - * This function is the wrapper called for every remote function call. It - * deserializes the arguments from the @c wisc::RPCMsg, calls the local functor - * and then serializes the return value to the @c wisc::RPCMsg. - */ - template::value, int>::type = 0 - > - void invoke(const wisc::RPCMsg *request, wisc::RPCMsg *response) noexcept - { + /** + * @brief Locally invoke a RPC method + * + * This function is the wrapper called for every remote function call. It + * deserializes the arguments from the @c wisc::RPCMsg, calls the local functor + * and then serializes the return value to the @c wisc::RPCMsg. + */ + template::value, int>::type = 0 + > + void invoke(const wisc::RPCMsg *request, wisc::RPCMsg *response) noexcept { try { - // Remove the cv-qualifiers and references since we need - // a copy of the object - helper::functor_decay_args_t args; + // Remove the cv-qualifiers and references since we need + // a copy of the object + helper::functor_decay_args_t args; - MessageDeserializer query(request); - query >> args; + MessageDeserializer query(request); + query >> args; - // Call the Method functor with the arguments received from - // the RPC message - auto result = compat::tuple_apply>(Method{}, args); + // Call the Method functor with the arguments received from + // the RPC message + auto result = compat::tuple_apply>(Method{}, args); - // Serialize the reply - MessageSerializer reply(response); - reply << result; + // Serialize the reply + MessageSerializer reply(response); + reply << result; } catch (const std::exception &e) { - helper::handleException(e, response); + helper::handleException(e, response); } catch (const wisc::RPCMsg::BadKeyException &e) { - helper::handleException(e, response); + helper::handleException(e, response); } catch (const wisc::RPCMsg::TypeException &e) { - helper::handleException(e, response); + helper::handleException(e, response); } catch (const wisc::RPCMsg::BufferTooSmallException &e) { - helper::handleException(e, response); + helper::handleException(e, response); } catch (const wisc::RPCMsg::CorruptMessageException &e) { - helper::handleException(e, response); + helper::handleException(e, response); } catch (...) { - helper::handleException(response); + helper::handleException(response); } - } + } - /** - * @brief Register a RPC method into the @c ModuleManager - * - * This helper function register a RPC method with the right parameters - * so it can be remotely called. - */ - template - void registerMethod(ModuleManager *modmgr) - { + /** + * @brief Register a RPC method into the @c ModuleManager + * + * This helper function register a RPC method with the right parameters + * so it can be remotely called. + */ + template + void registerMethod(ModuleManager *modmgr) { // The method name is taken from the typeid // This is implementation dependent but g++ and clang++ // follow the same convention return modmgr->register_method(abiVersion, typeid(Method).name(), xhal::rpc::invoke); - } + } } } } From 0b50eddd5eec52fb41a7418e7717daf70730cd99 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Tue, 17 Sep 2019 00:53:11 +0200 Subject: [PATCH 45/56] [style] Standardize whitespace and brace style in `server` files --- xhal/include/xhal/server/LMDB.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xhal/include/xhal/server/LMDB.h b/xhal/include/xhal/server/LMDB.h index cfe73f9..36ac0e7 100644 --- a/xhal/include/xhal/server/LMDB.h +++ b/xhal/include/xhal/server/LMDB.h @@ -34,7 +34,7 @@ namespace xhal { */ class LMDBGuard { - public: + public: /** * @brief Constructs a guard. */ From 1bd844142c32b18dbd90f3d1fcccb416d0cac191 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Thu, 10 Oct 2019 15:35:40 +0200 Subject: [PATCH 46/56] [bugfix] Fix incorrect namespaces after migration --- xhal/include/xhal/common/rpc/call.h | 8 ++++---- xhal/include/xhal/common/rpc/common.h | 4 ++-- xhal/include/xhal/common/rpc/register.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xhal/include/xhal/common/rpc/call.h b/xhal/include/xhal/common/rpc/call.h index 9b3f188..d346b75 100644 --- a/xhal/include/xhal/common/rpc/call.h +++ b/xhal/include/xhal/common/rpc/call.h @@ -32,7 +32,7 @@ namespace xhal { */ template::value, int>::type = 0 + typename std::enable_if::value, int>::type = 0 > helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args); @@ -48,7 +48,7 @@ namespace xhal { */ template::value, int>::type + typename std::enable_if::value, int>::type > friend helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args); @@ -88,7 +88,7 @@ namespace xhal { */ template::value, int>::type + typename std::enable_if::value, int>::type > friend helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args); @@ -107,7 +107,7 @@ namespace xhal { /* Implementation */ template::value, int>::type + typename std::enable_if::value, int>::type > helper::functor_return_t call(wisc::RPCSvc &connection, Args&&... args) { diff --git a/xhal/include/xhal/common/rpc/common.h b/xhal/include/xhal/common/rpc/common.h index b31e7b4..b23cc19 100644 --- a/xhal/include/xhal/common/rpc/common.h +++ b/xhal/include/xhal/common/rpc/common.h @@ -272,7 +272,7 @@ namespace xhal { * * 1. It delegates the deserialization to a well-known function. * 2. It aims at enforcing maximum type compatibility with the UW RPC API by - * remembering the developer that she/he can transmit defined types over the + * reminding the developer that she/he can transmit defined types over the * network. */ template @@ -454,7 +454,7 @@ namespace xhal { * }; * * // The non-intrusive version allows to serialize objects defined in a library - * // Simply define the serialize function in the xhal::rpc namespace or the namespace + * // Simply define the serialize function in the xhal::common::rpc namespace or the namespace * // where the type is defined with two parameters (1) A message (i.e. the serializer * // or deserializer) and (2) the custom type * namespace xhal { namspace rpc { diff --git a/xhal/include/xhal/common/rpc/register.h b/xhal/include/xhal/common/rpc/register.h index 8aafeb2..70dfe36 100644 --- a/xhal/include/xhal/common/rpc/register.h +++ b/xhal/include/xhal/common/rpc/register.h @@ -57,7 +57,7 @@ namespace xhal { * and then serializes the return value to the @c wisc::RPCMsg. */ template::value, int>::type = 0 + typename std::enable_if::value, int>::type = 0 > void invoke(const wisc::RPCMsg *request, wisc::RPCMsg *response) noexcept { try { @@ -103,7 +103,7 @@ namespace xhal { // follow the same convention return modmgr->register_method(abiVersion, typeid(Method).name(), - xhal::rpc::invoke); + xhal::common::rpc::invoke); } } } From ca76352ae56ff9dea8377a5f6d447f380f4e956b Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Sat, 21 Dec 2019 21:45:29 +0100 Subject: [PATCH 47/56] [packaging] migrate ModuleManager from ctp7_modules to xhal --- xhal/include/xhal/common/rpc/register.h | 2 +- xhal/include/xhal/extern/ModuleManager.h | 30 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 xhal/include/xhal/extern/ModuleManager.h diff --git a/xhal/include/xhal/common/rpc/register.h b/xhal/include/xhal/common/rpc/register.h index 70dfe36..67bc3b3 100644 --- a/xhal/include/xhal/common/rpc/register.h +++ b/xhal/include/xhal/common/rpc/register.h @@ -15,7 +15,7 @@ #include "xhal/common/rpc/exceptions.h" #include "xhal/common/rpc/helper.h" -#include "moduleapi.h" // Only present in the CTP7 modules +#include "xhal/extern/ModuleManager.h" // Only present in the CTP7 modules #include diff --git a/xhal/include/xhal/extern/ModuleManager.h b/xhal/include/xhal/extern/ModuleManager.h new file mode 100644 index 0000000..538336b --- /dev/null +++ b/xhal/include/xhal/extern/ModuleManager.h @@ -0,0 +1,30 @@ +#ifndef __MODULE_MANAGER_H +#define __MODULE_MANAGER_H + +#include "wiscRPCMsg.h" + +#include +#include + +class ModuleManager { + public: + typedef void (*rpc_method_t)(const wisc::RPCMsg *req, wisc::RPCMsg *rsp); + protected: + class ModuleMethod { + public: + rpc_method_t method; + int activity_color; + ModuleMethod(rpc_method_t method, int activity_color) : method(method), activity_color(activity_color) { }; + }; + std::map methods; + std::map modulestate; + int modload_activity_color; + public: + ModuleManager() { }; + int load_modules_dir(std::string dir); + bool load_module(std::string dir, std::string mod_name, std::string version_key); + void register_method(std::string service, std::string module, rpc_method_t func); + void invoke_method(std::string method, wisc::RPCMsg *request, wisc::RPCMsg *response); +}; + +#endif From 4862552869cb67597652d7b4688bc5acfc4d6cf1 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Tue, 17 Sep 2019 01:08:49 +0200 Subject: [PATCH 48/56] [refactor] Update boilerplate for new structure * [ci] run publish jobs only on cms-gem-daq-project * [ci] create release job --- .gitlab-ci.yml | 259 ++++++++++++++----------------------- Makefile | 9 +- config | 2 +- python/Makefile | 11 +- xhal/Makefile | 17 ++- xhal/include/packageinfo.h | 11 +- xhal/xhal.mk | 8 +- 7 files changed, 140 insertions(+), 177 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2fe0799..3c8af64 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,14 +13,14 @@ # GITLAB_USER_NAME ## ------------------- used secure variables: ------------------- ## - # EOS_ACCOUNT_USERNAME: Username of to write in the EOS folder whose path is EOS_PATH + # EOS_ACCOUNT_USERNAME: Username of to write in the EOS folder whose path is EOS_PATH # EOS_ACCOUNT_PASSWORD: Account password - # KRB_PASSWORD base64 hased value - # KRB_USERNAME base64 hased value - # GPG_SIGNING_KEY_PRIV base64 hased value - # GPG_PASSPHRASE base64 hased value - # CI_DEPLOY_USER - # CI_DEPLOY_PASSWORD + # KRB_PASSWORD: Kerberos account password + # KRB_USERNAME: Kerberos account username + # GPG_SIGNING_KEY_PRIV: GPG private key for signing + # GPG_PASSPHRASE: GPG key passphrase for signing + # CI_DEPLOY_USER: + # CI_DEPLOY_PASSWORD: ## ------------------- Stage definitions ------------------- ## stages: @@ -29,7 +29,7 @@ stages: - package # build the RPMs - test # test the packages (install, run basic tests) - publish # publish the RPMs and docs - - deploy # deploy the RPMs and docs + - release # create release page ## ------------------- Define up anchors for various tasks, shared across all jobs utilizing them ------------------- ## .common_variables: &common_variables @@ -40,9 +40,8 @@ stages: LD_LIBRARY_PATH: /opt/xdaq/lib:/opt/reedmuller/lib:/opt/wiscrpcsvc/lib PACKAGE_NAME: ${CI_PROJECT_NAME} ARTIFACTS_DIR: artifacts + XILINX_SDK_PATH: /data/bigdisk/sw/Xilinx/SDK GIT_SUBMODULE_STRATEGY: normal - PETA_STAGE: /data/bigdisk/sw/peta-stage - # REPO_NAME: ${${CI_REPOSITORY_URL##?*/}%%.*} variables: *common_variables @@ -66,10 +65,11 @@ variables: *common_variables pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* sudo yum install -y reedmuller\* --enablerepo=gemos* + +.common_zynq_setup: &common_zynq_setup |- sudo yum install -y gem-peta-stage-ctp7 --enablerepo=gemos* sudo yum install -y lmdb\* - source /data/bigdisk/sw/Xilinx/SDK/2016.2/settings64.sh - env | egrep CI + source ${XILINX_SDK_PATH}/2016.2/settings64.sh .retry_settings: &retry_settings retry: @@ -79,17 +79,9 @@ variables: *common_variables - stuck_or_timeout_failure .common_cache: &common_cache - # key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" - # key: "$BUILD_ARCH" untracked: true paths: - ~/.cache/pip - # - /opt/ctp7_modules - # - /opt/reedmuller - # - /opt/reg_utils - # - /opt/rwreg - # - /opt/wiscrpcsvc - # - /opt/xhal .common_artifacts: &common_artifacts name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" @@ -101,21 +93,14 @@ variables: *common_variables .compile_artifacts: &compile_artifacts untracked: true <<: *common_artifacts - # paths: - # - ${ARTIFACTS_DIR} .touch_compile_artifacts: &touch_compile_artifacts |- find ./ -type f -name '*.d' -print0 -exec touch {} \; find ./ -type f -name '*.o' -print0 -exec touch {} \; find ./ -type f -name 'lib*' -print0 -exec touch {} \; find ./ -type f -name 'xhalpy*' -print0 -exec touch {} \; - # find ./python/reg_interface_gem/pkg/xhal -type f -print0 -exec touch {} \; -.before_compile: &before_compile - ## these are set in the Dockerfile, but don't work in the gitlab CI by default? - - export BUILD_HOME=/builds/$CI_PROJECT_NAMESPACE - - export ARTIFACTS_DIR=$BUILD_HOME/artifacts - - *common_setup +# .before_compile: &before_compile |- .compile_common: &compile_common only: @@ -124,17 +109,18 @@ variables: *common_variables - /^release.*$/ - /^feature.*$/ - /^citest.*$/ - - develop - - master + - /^develop$/ + - /^master$/ + - merge_requests - tags tags: + - peta stage: compile before_script: - *before_compile + - *common_setup + - *common_zynq_setup script: - make all -j8 - # - mkdir ${ARTIFACTS_DIR}/${XDAQ_PLATFORM} - # - find . -iname '*.so' -print0 -exec mv -t ${ARTIFACTS_DIR}/${XDAQ_PLATFORM} {} \+ after_script: - ls -la ${ARTIFACTS_DIR} artifacts: @@ -148,20 +134,10 @@ compile:cc7: variables: cache: -# compile:cc8: -# <<: *cc8setup -# <<: *compile_common -# environment: -# variables: -# cache: - ##### ------------------- Generate docs ------------------- ##### .docs_artifacts: &docs_artifacts untracked: true <<: *common_artifacts - # paths: - # - ${ARTIFACTS_DIR} - # - doc/build/html .touch_docs_artifacts: &touch_docs_artifacts |- find ./python/reg_interface_gem/doc/_build -type f -print0 -exec touch {} \; @@ -173,19 +149,17 @@ docs: <<: *cc7setup stage: compile only: - - /^feature.*ci-cd*$/ + - /^release.*$/ + - /^feature.*$/ - /^citest.*$/ - /^develop$/ - - /^release.*$/ + - /^master$/ + - merge_requests - tags - - master dependencies: before_script: - - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` - - eval `set | egrep '^(BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` script: - make doc - # - doxygen -s ${BUILD_HOME}/doc/cmsgemos.cfg >& /dev/null after_script: - | mkdir -p ${ARTIFACTS_DIR}/api @@ -196,48 +170,60 @@ docs: coverage: '/Documentation coverage: \d+\.\d+/' ##### ------------------- Run tests using the compiled binaries ------------------- ##### -.before_test: &before_test - - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` - - eval `set | egrep '^(BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` - - | - sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* - sudo yum install -y reedmuller\* --enablerepo=gemos* +.test_artifacts: &test_artifacts + untracked: true + <<: *common_artifacts + expire_in: 1w + +.before_test: &before_test |- + *common_setup + +.before_abi_check: &before_abi_check |- + sudo yum install -y abi-compliance-checker abi-dumper # run tests using the binary built before test:cc7: <<: *cc7setup stage: test + tags: dependencies: - compile:cc7 before_script: - *before_test + - *common_setup script: - echo ./runmytests.sh after_script: - - 'echo "FIXME: parse-abi-changes.sh"' - 'echo "FIXME: test summary"' coverage: '/Test coverage: \d+\.\d+/' -# test:cc8: -# <<: *cc8setup -# stage: test -# dependencies: -# - compile:cc8 -# before_script: -# *before_test -# script: -# - echo ./runmytests.sh -# after_script: -# - 'echo "FIXME: parse-abi-changes.sh"' -# - 'echo "FIXME: test summary"' -# coverage: '/Test coverage: \d+\.\d+/' +test:abi:cc7: + <<: *cc7setup + stage: test + tags: + - peta + only: + - merge_requests + dependencies: + - compile:cc7 + before_script: + - *common_setup + - *common_zynq_setup + - *before_abi_check + script: + - make checkabi + allow_failure: true + after_script: + - find . -type d -iname compat_reports -print0 -exec tar cjf ${CI_PROJECT_NAME}_mr${CI_MERGE_REQUEST_ID}_abi_compat.tbz2 {} \+ + - 'echo "FIXME: API/ABI summary"' + artifacts: + name: ${CI_JOB_STAGE} + <<: *test_artifacts + coverage: '/Test coverage: \d+\.\d+/' ##### ------------------- Package generated files into RPMs and tarballs ------------------- ##### .package_artifacts: &package_artifacts untracked: true <<: *common_artifacts - # paths: - # - ${ARTIFACTS_DIR} .touch_package_artifacts: &touch_package_artifacts |- find ./python/reg_interface_gem/pkg/xhal -type f -print0 -exec touch {} \; @@ -259,78 +245,39 @@ test:cc7: stage: package before_script: - *common_setup + - *common_zynq_setup - *before_package script: ## Ensure compile artifacts are more recent than the checkout - *touch_compile_artifacts - *touch_docs_artifacts - make rpm - ## Move packaged files to deployment staging area - - eval `set | egrep '^(CI|GIT)' | awk -F= '{ print "export " $1 }'` - - eval `set | egrep '^(EOS|BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` after_script: -# - mv repos ${ARTIFACTS_DIR} - - ls -la ${ARTIFACTS_DIR} - - ls -la ${ARTIFACTS_DIR}/repos artifacts: name: ${CI_JOB_STAGE} <<: *package_artifacts # generate RPMs -package:cc7:unstable: +package:cc7: <<: *cc7setup only: - - /^develop$/ - - /^feature.*ci-cd*$/ + - /^release.*$/ + - /^feature.*$/ - /^citest.*$/ + - /^develop$/ + - /^master$/ + - merge_requests + - tags # - triggers ## should go into releases/'testing' or unstable? # - chat ## should go into releases/'testing' or unstable? # - api ## should go into releases/'testing' or unstable? tags: - variables: - COMPILER: 'gcc' - PYEXE: 'python2.7' - PACKAGE_TYPE: 'unstable' - dependencies: - - compile:cc7 - - docs - <<: *package_common - -package:cc7:testing: - <<: *cc7setup - only: - - /^release.*$/ - tags: - variables: - COMPILER: 'gcc' - PYEXE: 'python2.7' - PACKAGE_TYPE: 'testing' + - peta dependencies: - compile:cc7 - docs <<: *package_common -package:cc7:base: - <<: *cc7setup - only: - - tags - tags: - variables: - COMPILER: 'gcc' - PYEXE: 'python2.7' - PACKAGE_TYPE: 'base' - dependencies: - - compile:cc7 - - docs - <<: *package_common - -# package:cc8: -# <<: *cc8setup -# dependencies: -# - compile:cc8 -# - docs -# <<: *package_common - ##### ------------------- Publish RPMs, docs, and tarballs ------------------- ##### .publish_variables: &publish_variables EOS_BASE_WEB_DIR: "/eos/project/c/cmsgemdaq/www/ci-test" @@ -338,26 +285,23 @@ package:cc7:base: EOS_DOC_NAME: "api" EOS_REPO_NAME: "repos" EOS_SITE_WEB_DIR: "${EOS_BASE_WEB_DIR}/${CI_PROJECT_NAME}" - EOS_SW_DIR: "sw/${CI_PROJECT_NAME}" + EOS_SW_DIR: "sw/gemos" EOS_DOCS_DIR: "docs/${CI_PROJECT_NAME}" EOS_UNSTABLE_DIR: "unstable" EOS_RELEASE_DIR: "releases" +.before_publish: &before_publish |- + sudo yum install -y rpm-sign + .publish_common: &publish_common <<: *cc7setup stage: publish variables: *publish_variables before_script: - - eval `set | egrep '^(KRB|CI|GIT)' | awk -F= '{ print "export " $1 }'` - - eval `set | egrep '^(EOS|BUILD|REL|PACK|ARTI|XDAQ|CMS|LD)' | awk -F= '{ print "export " $1 }'` - *common_setup - - sudo yum install -y rpm-sign + - *common_zynq_setup + - *before_publish script: - # - push python packages to pypi/conda - # - push RPMs to packagecloud.io - # - push RPMs to gitlab yum repo, a la xDAQ? - # - push sphinx/rst/md/rtd docs to readthedocs.io - # - push sphinx/rst/md/rtd docs to $EOS_WEB_DIR/docs/${fulltag}, update doc main page index - 'echo "FIXME: github_changelog_generator"' - 'echo "FIXME: cp CHANGELOG.md ${ARTIFACTS_DIR}"' - *touch_compile_artifacts @@ -366,52 +310,41 @@ package:cc7:base: - make release - cp -rfp release/* ${ARTIFACTS_DIR} - ${BUILD_HOME}/${CI_PROJECT_NAME}/config/ci/publish_eos.sh - - if [ -n "${DEBUG_CI}" ]; then sleep 500; fi - -# publish:debug: -# variables: -# EOS_BASE_WEB_DIR: /tmp/ -# <<: *publish_common -# variables: -# DEBUG_CI: 'yes' -# only: -# - /^citest.*$/ -# when: manual -# after_script: - -publish:unstable: - variables: - EOS_BASE_WEB_DIR: /tmp/ - <<: *publish_common - only: - - /^feature.*ci-cd*$/ - - /^citest.*$/ - - /^develop$/ - dependencies: - - package:cc7:unstable - after_script: - - ls -la ${ARTIFACTS_DIR} + # - push python packages to pypi/conda + # - push RPMs to packagecloud.io + # - push RPMs to gitlab yum repo, a la xDAQ? + # - push sphinx/rst/md/rtd docs to readthedocs.io + # - push sphinx/rst/md/rtd docs to $EOS_WEB_DIR/docs/${fulltag}, update doc main page index -publish:testing: +publish: <<: *publish_common only: - - /^release.*$/ + - /^release.*$/@cms-gem-daq-project/xhal + - /^feature.*$/@cms-gem-daq-project/xhal + - /^citest.*$/@cms-gem-daq-project/xhal + - /^develop$/@cms-gem-daq-project/xhal + - /^master$/@cms-gem-daq-project/xhal + - merge_requests@cms-gem-daq-project/xhal + - tags@cms-gem-daq-project/xhal + tags: dependencies: - - package:cc7:testing + - package:cc7 after_script: + - 'echo "FIXME: github_changelog_generator"' + - 'echo "FIXME: generate_release_notes.sh"' # - notify mattermost # - send email # - generate_release.sh pre -publish:base: - <<: *publish_common +release: only: - - tags + - tags@cms-gem-daq-project/xhal dependencies: - - package:cc7:base - after_script: + - publish + stage: release + script: - 'echo "FIXME: github_changelog_generator"' - 'echo "FIXME: generate_release_notes.sh"' # - notify mattermost # - send email - # - generate_release.sh rel + # - generate_release.sh pre diff --git a/Makefile b/Makefile index 5dd3ae7..09a0ccc 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) SUBPACKAGES.CLEANALL := $(patsubst %,%.cleanall, $(SUBPACKAGES)) +SUBPACKAGES.CHECKABI := $(patsubst %,%.checkabi, $(SUBPACKAGES)) .PHONY: $(SUBPACKAGES) \ $(SUBPACKAGES.CLEAN) \ @@ -22,9 +23,10 @@ SUBPACKAGES.CLEANALL := $(patsubst %,%.cleanall, $(SUBPACKAGES)) $(SUBPACKAGES.CLEANRPM) \ $(SUBPACKAGES.DOC) \ $(SUBPACKAGES.CLEANDOC) \ + $(SUBPACKAGES.CHECKABI) \ $(SUBPACKAGES.CLEANALL) -.PHONY: all build doc install uninstall rpm release +.PHONY: all build checkabi doc install uninstall rpm release .PHONY: clean cleanall cleandoc cleanrpm cleanrelease build: $(SUBPACKAGES) @@ -59,6 +61,8 @@ cleanrelease: cleanall: $(SUBPACKAGES.CLEANALL) cleanrelease +checkabi: $(SUBPACKAGES.CHECKABI) + $(SUBPACKAGES): $(MAKE) -C $@ @@ -77,6 +81,9 @@ $(SUBPACKAGES.CLEANRPM): $(SUBPACKAGES.CLEANALL): $(MAKE) -C $(patsubst %.cleanall,%, $@) cleanall +$(SUBPACKAGES.CHECKABI): + $(MAKE) -C $(patsubst %.checkabi,%, $@) checkabi + $(SUBPACKAGES.DOC): $(MAKE) -C $(patsubst %.doc,%, $@) doc diff --git a/config b/config index 38f4b5a..a6ce520 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 38f4b5ac3f91bd04790e4f592a5e91ecac884b57 +Subproject commit a6ce520badaea440edb022571fbf1173ab4247bd diff --git a/python/Makefile b/python/Makefile index c940948..f08e2ae 100644 --- a/python/Makefile +++ b/python/Makefile @@ -11,6 +11,7 @@ SUBPACKAGES.CLEANRPM := $(patsubst %,%.cleanrpm, $(SUBPACKAGES)) SUBPACKAGES.DOC := $(patsubst %,%.doc, $(SUBPACKAGES)) SUBPACKAGES.CLEANDOC := $(patsubst %,%.cleandoc, $(SUBPACKAGES)) SUBPACKAGES.CLEANALL := $(patsubst %,%.cleanall, $(SUBPACKAGES)) +SUBPACKAGES.CHECKABI := $(patsubst %,%.checkabi, $(SUBPACKAGES)) .PHONY: $(SUBPACKAGES) \ $(SUBPACKAGES.CLEAN) \ @@ -21,9 +22,10 @@ SUBPACKAGES.CLEANALL := $(patsubst %,%.cleanall, $(SUBPACKAGES)) $(SUBPACKAGES.CLEANRPM) \ $(SUBPACKAGES.DOC) \ $(SUBPACKAGES.CLEANDOC) \ - $(SUBPACKAGES.CLEANALL) + $(SUBPACKAGES.CLEANALL) \ + $(SUBPACKAGES.CHECKABI) -.PHONY: all build doc install uninstall rpm release +.PHONY: all build checkabi doc install uninstall rpm release .PHONY: clean cleanall cleandoc cleanrpm build: $(SUBPACKAGES) @@ -47,6 +49,8 @@ release: $(SUBPACKAGES.RELEASE) cleanall: $(SUBPACKAGES.CLEANALL) +checkabi: $(SUBPACKAGES.CHECKABI) + $(SUBPACKAGES): $(MAKE) -C $@ @@ -65,6 +69,9 @@ $(SUBPACKAGES.CLEANRPM): $(SUBPACKAGES.CLEANALL): $(MAKE) -C $(patsubst %.cleanall,%, $@) cleanall +$(SUBPACKAGES.CHECKABI): + + $(SUBPACKAGES.DOC): $(MAKE) -C $(patsubst %.doc,%, $@) html diff --git a/xhal/Makefile b/xhal/Makefile index 2d79f2a..fc67fd2 100644 --- a/xhal/Makefile +++ b/xhal/Makefile @@ -5,19 +5,21 @@ TARGETS.CLEAN := $(patsubst %,%.clean, $(TARGETS)) TARGETS.CLEANRPM := $(patsubst %,%.cleanrpm, $(TARGETS)) TARGETS.CLEANALLRPM:= $(patsubst %,%.cleanallrpm, $(TARGETS)) TARGETS.CLEANALL := $(patsubst %,%.cleanall, $(TARGETS)) +TARGETS.CHECKABI := $(patsubst %,%.checkabi, $(TARGETS)) TARGETS.INSTALL := $(patsubst %,%.install, $(TARGETS)) TARGETS.UNINSTALL := $(patsubst %,%.uninstall, $(TARGETS)) TARGETS.RELEASE := $(patsubst %,%.release, $(TARGETS)) .PHONY: $(TARGETS) \ - $(TARGETS.CLEAN) \ - $(TARGETS.INSTALL) \ - $(TARGETS.UNINSTALL) \ - $(TARGETS.RELEASE) \ $(TARGETS.RPM) \ + $(TARGETS.CLEAN) \ $(TARGETS.CLEANRPM) \ $(TARGETS.CLEANALLRPM) \ - $(TARGETS.CLEANALL) + $(TARGETS.CLEANALL) \ + $(TARGETS.CHECKABI) \ + $(TARGETS.INSTALL) \ + $(TARGETS.UNINSTALL) \ + $(TARGETS.RELEASE) .PHONY: all default install uninstall rpm release .PHONY: clean cleanall cleanrpm cleanallrpm @@ -36,6 +38,8 @@ cleanrpm: $(TARGETS.CLEANRPM) cleanallrpm: $(TARGETS.CLEANALLRPM) +checkabi: $(TARGETS.CHECKABI) + install: $(TARGETS.INSTALL) uninstall: $(TARGETS.UNINSTALL) @@ -60,6 +64,9 @@ $(TARGETS.CLEANALLRPM): $(TARGETS.CLEANALL): TargetArch=$(patsubst %.cleanall,%,$@) $(MAKE) -f xhal.mk cleanall +$(TARGETS.CHECKABI): + TargetArch=$(patsubst %.checkabi,%,$@) $(MAKE) -f xhal.mk checkabi + $(TARGETS.INSTALL): TargetArch=$(patsubst %.install,%,$@) $(MAKE) -f xhal.mk install diff --git a/xhal/include/packageinfo.h b/xhal/include/packageinfo.h index 5b0528a..24e577a 100644 --- a/xhal/include/packageinfo.h +++ b/xhal/include/packageinfo.h @@ -3,8 +3,15 @@ #ifndef DOXYGEN_IGNORE_THIS -#define XHAL_REQUIRED_PACKAGE_LIST reedmuller, xerces-c -#define XHAL_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel +#define XHAL_REQUIRED_PACKAGE_LIST reedmuller,xerces-c +#define XHAL_BASE_REQUIRED_PACKAGE_LIST reedmuller,xerces-c +#define XHAL_CLIENT_REQUIRED_PACKAGE_LIST reedmuller,xerces-c +#define XHAL_SERVER_REQUIRED_PACKAGE_LIST reedmuller,xerces-c,lmdb + +#define XHAL_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel,gem-peta-stage-ctp7 +#define XHAL_BASE_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel,gem-peta-stage-ctp7 +#define XHAL_CLIENT_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel,gem-peta-stage-ctp7 +#define XHAL_SERVER_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel,lmdb-devel,gem-peta-stage-ctp7 #endif diff --git a/xhal/xhal.mk b/xhal/xhal.mk index a564ddf..682c6ac 100644 --- a/xhal/xhal.mk +++ b/xhal/xhal.mk @@ -17,13 +17,15 @@ include $(ConfigDir)/mfCommonDefs.mk ifeq ($(Arch),x86_64) include $(ConfigDir)/mfPythonDefs.mk -CFLAGS=-fno-inline -Wall -pthread -ADDFLAGS=-g -fPIC -std=c++11 -std=gnu++11 -m64 +CFLAGS=-Wall -pthread +ADDFLAGS=-fPIC -std=c++11 -std=gnu++11 -m64 else include $(ConfigDir)/mfZynq.mk -ADDFLAGS=-g -std=gnu++14 +ADDFLAGS=-std=gnu++14 endif +ADDFLAGS+=$(OPTFLAGS) + PackageSourceDir:=src PackageIncludeDir:=include PackageObjectDir:=$(PackagePath)/src/linux/$(Arch) From aae03c1505f9f01405ca97a8bc6fff6e3c9734e4 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Thu, 10 Oct 2019 15:37:09 +0200 Subject: [PATCH 49/56] [packaging] Ensure that `install` target puts cross-compilation libraries in expected location --- xhal/xhal.mk | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/xhal/xhal.mk b/xhal/xhal.mk index 682c6ac..5566c6e 100644 --- a/xhal/xhal.mk +++ b/xhal/xhal.mk @@ -40,16 +40,15 @@ XHAL_VER_PATCH:=$(shell $(ConfigDir)/tag2rel.sh | awk '{split($$0,a," "); print IncludeDirs+= $(XDAQ_ROOT)/include IncludeDirs+= $(PackageIncludeDir) IncludeDirs+= $(PackageIncludeDir)/xhal/extern -# IncludeDirs+= $(PackageIncludeDir)/server -# IncludeDirs+= $(PackageIncludeDir)/client INC=$(IncludeDirs:%=-I%) +Libraries+=-llog4cplus -lxerces-c -lstdc++ ifeq ($(Arch),x86_64) -Libraries+=-llog4cplus -lxerces-c -lwiscrpcsvc -lstdc++ +Libraries+=-lwiscrpcsvc LibraryDirs+=-L$(XDAQ_ROOT)/lib LibraryDirs+=-L/opt/wiscrpcsvc/lib else -Libraries+=-llog4cplus -lxerces-c -lstdc++ + endif LibraryDirs+=-L$(PackageLibraryDir) @@ -235,6 +234,30 @@ $(XHALPY_LIB): $(OBJS_XHALPY) $(XHAL_LIB) $(RPCMAN_LIB) $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal-base -lxhal-rpcman $(link-sonames) +ifeq ($(Arch),x86_64) +else +PETA_PATH?=/opt/gem-peta-stage +TARGET_BOARD?=ctp7 +.PHONY: crosslibinstall crosslibuninstall + +install: crosslibinstall + +## @xhal install libraries for cross-compilation +crosslibinstall: + echo "Installing cross-compiler libs" + if [ -d $(PackageLibraryDir) ]; then \ + cd $(PackageLibraryDir); \ + find . -type f -exec sh -ec 'install -D -m 755 $$0 $(INSTALL_PREFIX)$(PETA_PATH)/$(TARGET_BOARD)/$(INSTALL_PATH)/lib/$$0' {} \; ; \ + find . -type l -exec sh -ec 'if [ -n "$${0}" ]; then ln -sf $$(basename $$(readlink $$0)) $(INSTALL_PREFIX)$(PETA_PATH)/$(TARGET_BOARD)/$(INSTALL_PATH)/lib/$${0##./}; fi' {} \; ; \ + fi + +uninstall: crosslibuninstall + +## @xhal uninstall libraries for cross-compilation +crosslibuninstall: + $(RM) $(INSTALL_PREFIX)$(PETA_PATH)/$(TARGET_BOARD)/$(INSTALL_PATH) +endif + clean: $(RM) $(OBJS_XHAL) $(OBJS_CLIENT) $(OBJS_SERVER) $(OBJS_RPCMAN) $(OBJS_XHALPY) $(RM) $(PackageLibraryDir) From ce741d2aed509dd106fd65e910cb2a6e09caaa88 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Thu, 10 Oct 2019 15:41:20 +0200 Subject: [PATCH 50/56] [packaging] Update `config` subodule and packaging requirements * make spec template more generic * proper library flags --- Makefile | 2 +- config | 2 +- xhal/Makefile | 2 +- xhal/include/packageinfo.h | 4 ++-- xhal/spec.template | 31 ++++++++++++++++--------------- xhal/xhal.mk | 20 ++++++++++---------- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 09a0ccc..59cf7d5 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ $(SUBPACKAGES.DOC): $(SUBPACKAGES.INSTALL): $(SUBPACKAGES) $(MAKE) -C $(patsubst %.install,%, $@) install -$(SUBPACKAGES.UNINSTALL): $(SUBPACKAGES) +$(SUBPACKAGES.UNINSTALL): $(MAKE) -C $(patsubst %.uninstall,%, $@) uninstall $(SUBPACKAGES.RELEASE): $(SUBPACKAGES) diff --git a/config b/config index a6ce520..16d726e 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit a6ce520badaea440edb022571fbf1173ab4247bd +Subproject commit 16d726e1bd654055edc133ac70b63278f4e444ab diff --git a/xhal/Makefile b/xhal/Makefile index fc67fd2..dbf7449 100644 --- a/xhal/Makefile +++ b/xhal/Makefile @@ -22,7 +22,7 @@ TARGETS.RELEASE := $(patsubst %,%.release, $(TARGETS)) $(TARGETS.RELEASE) .PHONY: all default install uninstall rpm release -.PHONY: clean cleanall cleanrpm cleanallrpm +.PHONY: clean cleanrpm cleandoc cleanallrpm cleanall default: all diff --git a/xhal/include/packageinfo.h b/xhal/include/packageinfo.h index 24e577a..2d707a3 100644 --- a/xhal/include/packageinfo.h +++ b/xhal/include/packageinfo.h @@ -5,8 +5,8 @@ #define XHAL_REQUIRED_PACKAGE_LIST reedmuller,xerces-c #define XHAL_BASE_REQUIRED_PACKAGE_LIST reedmuller,xerces-c -#define XHAL_CLIENT_REQUIRED_PACKAGE_LIST reedmuller,xerces-c -#define XHAL_SERVER_REQUIRED_PACKAGE_LIST reedmuller,xerces-c,lmdb +#define XHAL_CLIENT_REQUIRED_PACKAGE_LIST xhal-base,reedmuller,xerces-c +#define XHAL_SERVER_REQUIRED_PACKAGE_LIST xhal-base,reedmuller,xerces-c,lmdb #define XHAL_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel,gem-peta-stage-ctp7 #define XHAL_BASE_BUILD_REQUIRED_PACKAGE_LIST reedmuller-devel,gem-peta-stage-ctp7 diff --git a/xhal/spec.template b/xhal/spec.template index b6af8b7..c4a2dcf 100644 --- a/xhal/spec.template +++ b/xhal/spec.template @@ -56,18 +56,18 @@ AutoReq: no __description__ %if %not_arm -## xhal-client subpackage +## %{_packagename}-client subpackage %package client Summary: Client package for %{_packagename} Requires: __client_requires_list__ BuildRequires: __client_build_requires_list__ %description client -Client libraries of the xhal package +Client libraries of the %{_packagename} package %endif %if %is_arm -%package -n ctp7-xhal-libs +%package -n ctp7-%{_packagename}-libs Summary: Libraries for cross-compiling %{_packagename} dependent applications for CTP7 Prefix: /opt/gem-peta-stage/ctp7/%{_prefix} Requires: gem-peta-stage-ctp7 @@ -75,20 +75,20 @@ BuildRequires: __build_requires_list__,__server_build_requires_list__ BuildArch: noarch AutoReq: no -%description -n ctp7-xhal-libs +%description -n ctp7-%{_packagename}-libs Provides the %{_packagename} libraries for the CTP7. These libraries are used when cross-compiling CTP7 applications. %endif -## xhal-server subpackage +## %{_packagename}-server subpackage %package server Summary: Server package for %{_packagename} Requires: __server_requires_list__ BuildRequires: __server_build_requires_list__ %description server -Server libraries of the xhal package +Server libraries of the %{_packagename} package ## Only build devel RPMs for non-ARM %if %not_arm @@ -104,14 +104,14 @@ Summary: Development files for %{_packagename}-server Requires: %{_packagename}-server %description -n %{_packagename}-server-devel -Development package for the server libraries of the xhal package +Development package for the server libraries of the %{_packagename} package %package -n %{_packagename}-client-devel Summary: Development package for %{_packagename}-client Requires: %{_packagename}-client %description -n %{_packagename}-client-devel -Development package for the client libraries of the xhal package +Development package for the client libraries of the %{_packagename} package %endif @@ -119,7 +119,7 @@ Development package for the client libraries of the xhal package #%%%if %not_arm %package -n %{_packagename}-debuginfo Summary: Debuginfos for %{_packagename} -Requires: %{_packagename} +Requires: %{_packagename}, %{_packagename}-devel %description -n %{_packagename}-debuginfo Debuginfos for the %{_packagename} package @@ -129,16 +129,16 @@ Debuginfos for the %{_packagename} package #%%##%%Requires: %{_packagename}-server #%%##%% #%%##%%%description -n %{_packagename}-server-debuginfo -#%%##%%Debuginfos for the server libraries of the xhal package +#%%##%%Debuginfos for the server libraries of the %{_packagename} package -## xhal-client is not for ARM -## xhal-client package and subpackages +## %{_packagename}-client is not for ARM +## %{_packagename}-client package and subpackages #%%##%%%package -n %{_packagename}-client-debuginfo #%%##%%Summary: Debuginfo for %{_packagename}-client #%%##%%Requires: %{_packagename}-client #%%##%% #%%##%%%description -n %{_packagename}-client-debuginfo -#%%##%%Debuginfos for the client libraries of the xhal package +#%%##%%Debuginfos for the client libraries of the %{_packagename} package #%%%endif # %pre @@ -242,13 +242,13 @@ popd # # Files that go in the binary RPM # -%files -n ctp7-xhal-libs +%files -n ctp7-%{_packagename}-libs %defattr(-,root,root,0755) %attr(0755,root,root) %{prefix}/lib/libxhal-*.so* ## Tries to put in the /mnt/persistent tree ## %%%dir -## %%%docdir /opt/xhal +## %%%docdir /opt/%{_packagename} ## %%%doc %{_project}/%{_packagename}/MAINTAINER.md ## %%%doc %{_project}/%{_packagename}/README.md ## %%%doc %{_project}/%{_packagename}/CHANGELOG.md @@ -264,6 +264,7 @@ popd %files -n %{_packagename}-devel %defattr(-,root,root,0755) %attr(0644,root,root) %{_prefix}/include/xhal/extern/wisc*.h +%attr(0644,root,root) %{_prefix}/include/xhal/extern/ModuleManager.h %dir %{_prefix}/include/xhal/common diff --git a/xhal/xhal.mk b/xhal/xhal.mk index 5566c6e..1c495da 100644 --- a/xhal/xhal.mk +++ b/xhal/xhal.mk @@ -45,15 +45,15 @@ INC=$(IncludeDirs:%=-I%) Libraries+=-llog4cplus -lxerces-c -lstdc++ ifeq ($(Arch),x86_64) Libraries+=-lwiscrpcsvc -LibraryDirs+=-L$(XDAQ_ROOT)/lib -LibraryDirs+=-L/opt/wiscrpcsvc/lib +LibraryDirs+=$(XDAQ_ROOT)/lib +LibraryDirs+=/opt/wiscrpcsvc/lib else endif -LibraryDirs+=-L$(PackageLibraryDir) +LibraryDirs+=$(PackageLibraryDir) -LDFLAGS+= -shared $(LibraryDirs) +LDFLAGS+=$(LibraryDirs:%=-L%) SRCS_XHAL = $(wildcard $(PackageSourceDir)/common/utils/*.cpp) SRCS_XHAL += $(wildcard $(PackageSourceDir)/common/rpc/*.cpp) @@ -144,7 +144,7 @@ default: $(TARGETS) rpmprep: build doc # Define as dependency everything that should cause a rebuild -TarballDependencies = $(XHAL_LIB) $(SERVER_LIB) Makefile xhal.mk spec.template +TarballDependencies = $(XHAL_LIB) $(SERVER_LIB) Makefile xhal.mk spec.template $(PackageIncludeDir)/packageinfo.h ifeq ($(Arch),x86_64) TarballDependencies+= $(CLIENT_LIB) $(XHALPY_LIB) $(RPCMAN_LIB) else @@ -211,27 +211,27 @@ $(TargetLibraries): $(XHAL_LIB): $(OBJS_XHAL) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(CXX) $(ADDFLAGS) $(LDFLAGS) $(SOFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) $(link-sonames) $(CLIENT_LIB): $(OBJS_CLIENT) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(CXX) $(ADDFLAGS) $(LDFLAGS) $(SOFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) $(link-sonames) $(SERVER_LIB): $(OBJS_SERVER) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(CXX) $(ADDFLAGS) $(LDFLAGS) $(SOFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) $(link-sonames) $(RPCMAN_LIB): $(OBJS_RPCMAN) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) + $(CXX) $(ADDFLAGS) $(LDFLAGS) $(SOFLAGS) -o $(@D)/$(LibraryFull) $^ $(Libraries) $(link-sonames) $(XHALPY_LIB): $(OBJS_XHALPY) $(XHAL_LIB) $(RPCMAN_LIB) $(MakeDir) -p $(@D) - $(CXX) $(ADDFLAGS) $(LDFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal-base -lxhal-rpcman + $(CXX) $(ADDFLAGS) $(LDFLAGS) $(SOFLAGS) -L$(PYTHON_LIB_PREFIX) -o $(@D)/$(LibraryFull) $^ $(Libraries) -lboost_python -l$(PYTHON_LIB) -lxhal-base -lxhal-rpcman $(link-sonames) ifeq ($(Arch),x86_64) From 6d8d337e07dc030d4131cced88a72f634ce4bc11 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Thu, 14 Nov 2019 10:15:15 +0100 Subject: [PATCH 51/56] [build-system] Generic python scriptlets * Ensure proper dependencies for python setup files --- config | 2 +- python/reg_interface_gem/Makefile | 6 +++++- python/reg_interface_gem/pkg/installrpm.sh | 19 ------------------- 3 files changed, 6 insertions(+), 21 deletions(-) delete mode 100755 python/reg_interface_gem/pkg/installrpm.sh diff --git a/config b/config index 16d726e..06d44eb 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 16d726e1bd654055edc133ac70b63278f4e444ab +Subproject commit 06d44eb4bdb60ced7dc7c1d1a99f276a0eb048ba diff --git a/python/reg_interface_gem/Makefile b/python/reg_interface_gem/Makefile index b38d5e4..5bbcc28 100644 --- a/python/reg_interface_gem/Makefile +++ b/python/reg_interface_gem/Makefile @@ -41,8 +41,11 @@ default: @cp -rf __init__.py $(PackageDir) # Override, as this package uses pkg/setup.py as the template file -$(PackageSetupFile): pkg/setup.py +$(PackageSetupFile): pkg/setup.py pkg/setup.cfg $(PackagePrepFile): $(PythonSources) Makefile | default + @cp -rf $(ConfigDir)/scriptlets/installrpm.sh pkg/ + @perl -pi -e "s|__PYTHON_SCRIPT_PATH__|$(INSTALL_PATH)/bin|g" pkg/installrpm.sh + @perl -pi -e "s|__PYTHON_NAMESPACE__|$(Namespace)|g" pkg/installrpm.sh $(MakeDir) $(ScriptDir) @cp -rf scripts/* $(ScriptDir) @cp -rf core $(PackageDir) @@ -60,6 +63,7 @@ clean: -rm -f pkg/MANIFEST.in -rm -f pkg/CHANGELOG.md -rm -f pkg/requirements.txt + -rm -f pkg/installrpm.sh print-env: @echo BUILD_HOME $(BUILD_HOME) diff --git a/python/reg_interface_gem/pkg/installrpm.sh b/python/reg_interface_gem/pkg/installrpm.sh deleted file mode 100755 index aec4f65..0000000 --- a/python/reg_interface_gem/pkg/installrpm.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -# default action -python setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES - -# install 'scripts' to /opt/xhal/bin -mkdir -p %{buildroot}/opt/xhal/bin -cp -rfp xhal/scripts/*.py %{buildroot}/opt/xhal/bin/ - -find %{buildroot} -type f -exec chmod a+r {} \; -find %{buildroot} -type f -iname '*.cfg' -exec chmod a-x {} \; - -# set permissions -cat <>INSTALLED_FILES -%attr(0755,root,root) /opt/xhal/bin/*.py -%attr(0755,root,root) /usr/lib/python*/site-packages/xhal/scripts/*.py -EOF -echo "Modified INSTALLED_FILES" -cat INSTALLED_FILES From 4ff82582da554be4dbfa2ca8bd97430b51a10182 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Fri, 20 Dec 2019 10:49:40 +0100 Subject: [PATCH 52/56] [build-system] Add cross-compile (un)install targets * variable location for wiscrpcsvc --- config | 2 +- xhal/xhal.mk | 16 +--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/config b/config index 06d44eb..1835e98 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 06d44eb4bdb60ced7dc7c1d1a99f276a0eb048ba +Subproject commit 1835e9843ce754c6749a9743ea15c0531ec25eae diff --git a/xhal/xhal.mk b/xhal/xhal.mk index 1c495da..573523c 100644 --- a/xhal/xhal.mk +++ b/xhal/xhal.mk @@ -46,7 +46,7 @@ Libraries+=-llog4cplus -lxerces-c -lstdc++ ifeq ($(Arch),x86_64) Libraries+=-lwiscrpcsvc LibraryDirs+=$(XDAQ_ROOT)/lib -LibraryDirs+=/opt/wiscrpcsvc/lib +LibraryDirs+=$(WISCRPC_ROOT)/lib else endif @@ -236,26 +236,12 @@ $(XHALPY_LIB): $(OBJS_XHALPY) $(XHAL_LIB) $(RPCMAN_LIB) ifeq ($(Arch),x86_64) else -PETA_PATH?=/opt/gem-peta-stage TARGET_BOARD?=ctp7 -.PHONY: crosslibinstall crosslibuninstall install: crosslibinstall -## @xhal install libraries for cross-compilation -crosslibinstall: - echo "Installing cross-compiler libs" - if [ -d $(PackageLibraryDir) ]; then \ - cd $(PackageLibraryDir); \ - find . -type f -exec sh -ec 'install -D -m 755 $$0 $(INSTALL_PREFIX)$(PETA_PATH)/$(TARGET_BOARD)/$(INSTALL_PATH)/lib/$$0' {} \; ; \ - find . -type l -exec sh -ec 'if [ -n "$${0}" ]; then ln -sf $$(basename $$(readlink $$0)) $(INSTALL_PREFIX)$(PETA_PATH)/$(TARGET_BOARD)/$(INSTALL_PATH)/lib/$${0##./}; fi' {} \; ; \ - fi - uninstall: crosslibuninstall -## @xhal uninstall libraries for cross-compilation -crosslibuninstall: - $(RM) $(INSTALL_PREFIX)$(PETA_PATH)/$(TARGET_BOARD)/$(INSTALL_PATH) endif clean: From 7a47c9822d1673710526adb5e1219197539df163 Mon Sep 17 00:00:00 2001 From: Jared Sturdy Date: Sat, 21 Dec 2019 21:46:36 +0100 Subject: [PATCH 53/56] [ci] CI pipeline updates * Update python packages for CI * Try to run job without special runner * Test the publish stage --- .gitlab-ci.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3c8af64..633917d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -50,9 +50,9 @@ variables: *common_variables image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:slc6 .cc7setup: &cc7setup - image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7 - # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7:xdaq14-6 - # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7:xdaq15 + image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7-xdaq14 + # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7-xdaq14-6 + # image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc7-xdaq15 .cc8setup: &cc8setup image: gitlab-registry.cern.ch/cms-gem-daq-project/gemdaq_ci_worker/extrapy/devtoolsroot:cc8 @@ -62,14 +62,17 @@ variables: *common_variables ### ------------------- Shared setup between stages ------------------- ### .common_setup: &common_setup |- mkdir -p ${ARTIFACTS_DIR} - pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" + pip install -I --user "pip" "importlib" "codecov" "setuptools<38.2" "sphinxcontrib-napoleon==0.2.9" sudo yum install -y wiscrpcsvc\* --enablerepo=gemos* sudo yum install -y reedmuller\* --enablerepo=gemos* .common_zynq_setup: &common_zynq_setup |- sudo yum install -y gem-peta-stage-ctp7 --enablerepo=gemos* sudo yum install -y lmdb\* - source ${XILINX_SDK_PATH}/2016.2/settings64.sh + # sudo /opt/arm/getarm.sh 4.9-2017.01 + export PETA_STAGE=/opt/gem-peta-stage/ctp7 + export PATH=/opt/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin:${PATH} + # source ${XILINX_SDK_PATH}/2016.2/settings64.sh .retry_settings: &retry_settings retry: @@ -114,7 +117,7 @@ variables: *common_variables - merge_requests - tags tags: - - peta + # - peta stage: compile before_script: - *common_setup @@ -200,7 +203,7 @@ test:abi:cc7: <<: *cc7setup stage: test tags: - - peta + # - peta only: - merge_requests dependencies: @@ -272,7 +275,7 @@ package:cc7: # - chat ## should go into releases/'testing' or unstable? # - api ## should go into releases/'testing' or unstable? tags: - - peta + # - peta dependencies: - compile:cc7 - docs @@ -309,6 +312,7 @@ package:cc7: - *touch_package_artifacts - make release - cp -rfp release/* ${ARTIFACTS_DIR} + - 'echo "Running as: " $(whoami)' - ${BUILD_HOME}/${CI_PROJECT_NAME}/config/ci/publish_eos.sh # - push python packages to pypi/conda # - push RPMs to packagecloud.io @@ -322,6 +326,7 @@ publish: - /^release.*$/@cms-gem-daq-project/xhal - /^feature.*$/@cms-gem-daq-project/xhal - /^citest.*$/@cms-gem-daq-project/xhal + - /^citest.*$/@sturdy/xhal - /^develop$/@cms-gem-daq-project/xhal - /^master$/@cms-gem-daq-project/xhal - merge_requests@cms-gem-daq-project/xhal From fe43ae6282e6a02861809847451a00ff12a4031f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Sat, 29 Feb 2020 01:05:28 +0100 Subject: [PATCH 54/56] Update the config submodule Implements the new PETA_PATH environment variable --- config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config b/config index 1835e98..30f5327 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 1835e9843ce754c6749a9743ea15c0531ec25eae +Subproject commit 30f5327e456c26b23a1f6ec224889c5c46610226 From 06822490f78ff81610e8dcc75ce2bbee1a401426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Sat, 29 Feb 2020 01:10:10 +0100 Subject: [PATCH 55/56] Compile against C++14 Enables auto return type deduction --- xhal/xhal.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xhal/xhal.mk b/xhal/xhal.mk index 573523c..cdfcf0f 100644 --- a/xhal/xhal.mk +++ b/xhal/xhal.mk @@ -18,10 +18,10 @@ include $(ConfigDir)/mfCommonDefs.mk ifeq ($(Arch),x86_64) include $(ConfigDir)/mfPythonDefs.mk CFLAGS=-Wall -pthread -ADDFLAGS=-fPIC -std=c++11 -std=gnu++11 -m64 +ADDFLAGS=-fPIC -std=c++14 -m64 else include $(ConfigDir)/mfZynq.mk -ADDFLAGS=-std=gnu++14 +ADDFLAGS=-std=c++14 endif ADDFLAGS+=$(OPTFLAGS) From bea638d63333a5e700a870231db90d9485d92bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= Date: Sat, 29 Feb 2020 01:16:46 +0100 Subject: [PATCH 56/56] Fix invalid use of strcat --- xhal/src/client/XHALDevice.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xhal/src/client/XHALDevice.cpp b/xhal/src/client/XHALDevice.cpp index c3f4c60..55eeba5 100644 --- a/xhal/src/client/XHALDevice.cpp +++ b/xhal/src/client/XHALDevice.cpp @@ -1,5 +1,7 @@ #include "xhal/client/XHALDevice.h" +#include + xhal::client::XHALDevice::XHALDevice(const std::string& board_domain_name, const std::string& address_table_filename) : xhal::client::XHALInterface(board_domain_name), m_address_table_filename(address_table_filename) @@ -62,7 +64,7 @@ uint32_t xhal::client::XHALDevice::readReg(std::string regName) return result; } else { XHAL_ERROR("Register not found in address table!"); - throw xhal::common::utils::XHALXMLParserException(strcat("XHAL XML exception: can't find node", regName.c_str())); + throw xhal::common::utils::XHALXMLParserException(std::string("XHAL XML exception: can't find node") + regName); } } @@ -140,7 +142,7 @@ void xhal::client::XHALDevice::writeReg(std::string regName, uint32_t value) } } else { XHAL_ERROR("Register not found in address table!"); - throw xhal::common::utils::XHALXMLParserException(strcat("XHAL XML exception: can't find node", regName.c_str())); + throw xhal::common::utils::XHALXMLParserException(std::string("XHAL XML exception: can't find node") + regName); } }