Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Merge branch 'staging' into 'master'
Browse files Browse the repository at this point in the history
Library package versioning, fixing error message issue, changing default log level



See merge request !1
  • Loading branch information
deztructor committed Nov 3, 2015
2 parents 5e336c8 + 2ebe73b commit e82b352
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 54 deletions.
74 changes: 61 additions & 13 deletions include/qtaround/debug.hpp
Expand Up @@ -4,29 +4,54 @@
* @file debug.hpp
* @brief Debug tracing support
* @author Denis Zalevskiy <denis.zalevskiy@jolla.com>
* @copyright (C) 2014 Jolla Ltd.
* @copyright (C) 2014-2015 Jolla Ltd.
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
*/

#include <qtaround/util.hpp>

#include <QVariant>
#include <QDebug>
#include <QTextStream>

#include <memory>

namespace qtaround { namespace debug {

enum class Level { Debug = 1, Info, Warning, Error, Critical };

QDebug stream();

template <typename T, typename ... Args>
QDebug & operator << (QDebug &d, std::function<T(Args...)> const &)
{
d << "std::function<...>";
return d;
}

namespace qtaround { namespace debug {

enum class Level { First_ = 1, Debug = First_, Info, Warning, Error
, Critical, Last_ = Critical };
/// compatible with syslog priorities
enum class Priority { First_ = 0, Emerg = First_, Alert, Crit
, Err, Warning, Notice, Info
, Debug, Last_ = Debug };

void set_max_priority(Priority);
Priority get_priority(Level);
void init();

template <Priority P>
struct Traits {
Traits() { }
QDebug stream();
QMessageLogger logger;
};

extern template struct Traits<Priority::Debug>;
extern template struct Traits<Priority::Info>;
extern template struct Traits<Priority::Notice>;
extern template struct Traits<Priority::Warning>;
extern template struct Traits<Priority::Err>;
extern template struct Traits<Priority::Crit>;
extern template struct Traits<Priority::Alert>;
extern template struct Traits<Priority::Emerg>;

static inline void print(QDebug &&d)
{
QDebug dd(std::move(d));
Expand All @@ -39,14 +64,23 @@ void print(QDebug &&d, T &&v1, A&& ...args)
return print(std::move(d), std::forward<A>(args)...);
}

// template <Level L, typename ... A>
// void print_for(A&& ...args)
// {
// Traits<L> ctx;
// return print(ctx.stream(), std::forward<A>(args)...);
// }

template <typename ... A>
void print(A&& ...args)
{
return print(stream(), std::forward<A>(args)...);
Traits<Priority::Emerg> ctx;
return print(ctx.stream(), std::forward<A>(args)...);
}

void level(Level);
bool is_tracing_level(Level);
bool is_traceable(Priority);

template <typename ... A>
void print_ge(Level print_level, A&& ...args)
Expand All @@ -55,34 +89,48 @@ void print_ge(Level print_level, A&& ...args)
print(std::forward<A>(args)...);
}

template <typename ... A>
void print_ge(Priority prio, A&& ...args)
{
if (is_traceable(prio))
print(std::forward<A>(args)...);
}

template <Priority P, typename ... A>
void print_ge_for(A&& ...args)
{
if (is_traceable(P))
print(std::forward<A>(args)...);
}

template <typename ... A>
void debug(A&& ...args)
{
print_ge(Level::Debug, std::forward<A>(args)...);
print_ge_for<Priority::Debug, A...>(std::forward<A>(args)...);
}

template <typename ... A>
void info(A&& ...args)
{
print_ge(Level::Info, std::forward<A>(args)...);
print_ge(Priority::Info, std::forward<A>(args)...);
}

template <typename ... A>
void warning(A&& ...args)
{
print_ge(Level::Warning, std::forward<A>(args)...);
print_ge(Priority::Warning, std::forward<A>(args)...);
}

template <typename ... A>
void error(A&& ...args)
{
print_ge(Level::Error, std::forward<A>(args)...);
print_ge(Priority::Err, std::forward<A>(args)...);
}

template <typename ... A>
void critical(A&& ...args)
{
print_ge(Level::Critical, std::forward<A>(args)...);
print_ge(Priority::Crit, std::forward<A>(args)...);
}

}}
Expand Down
5 changes: 3 additions & 2 deletions include/qtaround/error.hpp
Expand Up @@ -26,12 +26,13 @@ QString dump(T && t)
class Error : public std::exception
{
public:
Error(QVariantMap const &from) : m(from) {}
virtual ~Error() noexcept(true) {}
Error(QVariantMap const &from) : m(from), cstr(nullptr) {}
virtual ~Error() noexcept(true) { if (cstr) free(cstr); }
virtual const char* what() const noexcept(true);

QVariantMap m;
mutable QString s;
mutable char *cstr;
};

QDebug operator << (QDebug dst, error::Error const &src);
Expand Down
42 changes: 42 additions & 0 deletions include/qtaround/util.hpp
Expand Up @@ -8,6 +8,7 @@
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
*/

#include <cor/util.hpp>
#include "error.hpp"

#include <QVariant>
Expand Down Expand Up @@ -124,6 +125,24 @@ QString get(QVariant const &from)
return from.toString();
}

template <typename T, typename I>
static bool can_convert
(I v, typename std::enable_if<std::is_enum<T>::value>::type* = 0)
{
return (v >= static_cast<I>(T::First_)
&& v <= static_cast<I>(T::Last_));
}

template <typename T, typename FnT, typename I>
static bool call_if_convertible
(I v, FnT fn, typename std::enable_if<std::is_enum<T>::value>::type* = 0)
{
bool res = can_convert<T>(v);
if (res)
fn(static_cast<T>(v));
return res;
}

}

template <typename ... A>
Expand All @@ -146,8 +165,10 @@ T unbox(std::unique_ptr<T> p)
return std::move(*p);
}

/// deprecated
template <typename T> struct StructTraits;

/// deprecated
template <typename FieldsT>
struct Struct
{
Expand Down Expand Up @@ -197,6 +218,7 @@ constexpr size_t count(Args &&...)
return sizeof...(Args);
}

/// deprecated
#define STRUCT_NAMES(Id, id_names...) \
template <Id i> \
static char const * name() \
Expand All @@ -209,6 +231,7 @@ constexpr size_t count(Args &&...)

namespace qtaround { namespace debug {

/// deprecated
template <size_t N>
struct StructDump
{
Expand All @@ -224,6 +247,7 @@ struct StructDump
}
};

/// deprecated
template <>
struct StructDump<1>
{
Expand All @@ -238,6 +262,7 @@ struct StructDump<1>
}
};

/// deprecated
template <typename FieldsT>
QDebug & operator <<(QDebug &d, Struct<FieldsT> const &v)
{
Expand All @@ -249,6 +274,23 @@ QDebug & operator <<(QDebug &d, Struct<FieldsT> const &v)

}}

template <typename FieldsT, typename... ElementsT>
QDebug & operator <<(QDebug &dst, Record<FieldsT, ElementsT...> const &v)
{
static constexpr auto index = static_cast<size_t>(FieldsT::Last_);
dst << "("; RecordDump<index>::out(dst, v); dst << ")";
return dst;
}

template <typename FieldsT, typename... ElementsT>
QString loggable(Record<FieldsT, ElementsT...> const &v)
{
QString res;
QDebug dst(res);
dst << v;
return res;
}

namespace qtaround { namespace util {

template <typename ResT, typename T, typename FnT>
Expand Down
1 change: 1 addition & 0 deletions qtaround-1.pc.in
Expand Up @@ -5,5 +5,6 @@ includedir=${prefix}/include
Name: qtaround
Description: qtaround library
Version: @VERSION@
Requires.private: cor >= 0.1.17
Libs: -lqtaround -L${libdir}
Cflags: -I${includedir}
1 change: 1 addition & 0 deletions qtaround-dbus.pc.in
Expand Up @@ -5,5 +5,6 @@ includedir=${prefix}/include
Name: qtaround-dbus
Description: qtaround-dbus library
Version: @VERSION@
Requires.private: cor >= 0.1.17, qtaround = @VERSION@
Libs: -lqtaround-dbus -L${libdir}
Cflags: -I${includedir}
1 change: 1 addition & 0 deletions qtaround.pc.in
Expand Up @@ -5,5 +5,6 @@ includedir=${prefix}/include
Name: qtaround
Description: qtaround library
Version: @VERSION@
Requires.private: cor >= 0.1.17
Libs: -lqtaround -L${libdir}
Cflags: -I${includedir} -DQTAROUND_NO_NS
39 changes: 26 additions & 13 deletions rpm/qtaround.spec
Expand Up @@ -5,7 +5,7 @@ Name: qtaround
Version: 0.0.0
Release: 1
License: LGPL21
Group: Development/Liraries
Group: System/Libraries
URL: https://github.com/nemomobile/qtaround
Source0: %{name}-%{version}.tar.bz2
BuildRequires: cmake >= 2.8
Expand All @@ -19,37 +19,46 @@ Requires(postun): /sbin/ldconfig
QtAround library used to port the-vault to C++. Mostly consists of
thin wrappers around Qt classes and standard Linux utilities.

%package -n libqtaround2
Group: System/Libraries
Summary: QtAround library
Provides: libqtaround = %{version}-%{release}
Obsoletes: libqtaround < %{version}
%description -n libqtaround2
%summary

%package devel
Summary: QtAround library
Group: Development/Libraries
Requires: qtaround = %{version}-%{release}
Requires: libqtaround2 = %{version}
Requires: pkgconfig(cor) >= 0.1.17
%description devel
QtAround library used to port the-vault to C++. Mostly consists of
thin wrappers around Qt classes and standard Linux utilities.

%package dbus
Summary: QtAround D-Bus wrappers
Group: Development/Libraries
Requires: qtaround = %{version}-%{release}
Requires: libqtaround2 = %{version}
BuildRequires: pkgconfig(Qt5DBus) >= 5.2.0
%description dbus
QtAround library: D-Bus wrappers

%package dbus-devel
Summary: QtAround D-Bus development files
Group: Development/Libraries
Requires: qtaround = %{version}-%{release}
Requires: qtaround-dbus = %{version}-%{release}
Requires: qtaround-devel = %{version}-%{release}
Requires: libqtaround2 = %{version}
Requires: qtaround-dbus = %{version}
Requires: qtaround-devel = %{version}
%description dbus-devel
%{summary}

%package tests
Summary: Tests for qtaround
License: LGPLv2.1
Group: System Environment/Libraries
Requires: %{name} = %{version}-%{release}
Requires: %{name}-dbus = %{version}-%{release}
Requires: %{name} = %{version}
Requires: %{name}-dbus = %{version}
%if %{undefined suse_version}
Requires: btrfs-progs
%else
Expand All @@ -72,12 +81,14 @@ rm -rf $RPM_BUILD_ROOT
%clean
rm -rf $RPM_BUILD_ROOT

%files
%files -n libqtaround2
%defattr(-,root,root,-)
%{_libdir}/libqtaround.so*
%{_libdir}/libqtaround.so.2
%{_libdir}/libqtaround.so.%{version}

%files devel
%defattr(-,root,root,-)
%{_libdir}/libqtaround.so
%{_libdir}/pkgconfig/qtaround.pc
%{_libdir}/pkgconfig/qtaround-1.pc
%{_includedir}/qtaround/debug.hpp
Expand All @@ -91,19 +102,21 @@ rm -rf $RPM_BUILD_ROOT

%files dbus
%defattr(-,root,root,-)
%{_libdir}/libqtaround-dbus.so*
%{_libdir}/libqtaround-dbus.so.0
%{_libdir}/libqtaround-dbus.so.%{version}

%files dbus-devel
%defattr(-,root,root,-)
%{_libdir}/libqtaround-dbus.so
%{_libdir}/pkgconfig/qtaround-dbus.pc
%{_includedir}/qtaround/dbus.hpp

%files tests
%defattr(-,root,root,-)
/opt/tests/qtaround/*

%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%post -n libqtaround2 -p /sbin/ldconfig
%postun -n libqtaround2 -p /sbin/ldconfig

%post dbus -p /sbin/ldconfig
%postun dbus -p /sbin/ldconfig
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -11,7 +11,7 @@ add_library(qtaround SHARED
qt5_use_modules(qtaround Core)
target_link_libraries(qtaround ${COR_LIBRARIES})
set_target_properties(qtaround PROPERTIES
SOVERSION 1
SOVERSION 2
VERSION ${VERSION}
)
install(TARGETS qtaround DESTINATION ${DST_LIB})
Expand Down

0 comments on commit e82b352

Please sign in to comment.