From: Fabrice Fontaine Date: Mon, 3 Jan 2022 07:32:27 +0000 (+0100) Subject: bindings/cxx: Increase compatibility for glibmm-2.68 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e446b3c461f88a85298fe6eec294b4906909c50b;p=libsigrok.git bindings/cxx: Increase compatibility for glibmm-2.68 Prefer the DateTime data type which has been available since glibmm-2.4 version 2.26, and also is available in glibmm-2.68. While glibmm-2.68 no longer provides the TimeVal data type. [ gsi: split Fabrice's commit, rephrase commit message ] --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index f9f79273..de600d03 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -287,12 +287,12 @@ shared_ptr Context::create_user_device( default_delete{}}; } -shared_ptr Context::create_header_packet(Glib::TimeVal start_time) +shared_ptr Context::create_header_packet(Glib::DateTime start_time) { auto header = g_new(struct sr_datafeed_header, 1); header->feed_version = 1; - header->starttime.tv_sec = start_time.tv_sec; - header->starttime.tv_usec = start_time.tv_usec; + header->starttime.tv_sec = start_time.to_unix(); + header->starttime.tv_usec = start_time.get_microsecond(); auto packet = g_new(struct sr_datafeed_packet, 1); packet->type = SR_DF_HEADER; packet->payload = header; @@ -1154,11 +1154,10 @@ int Header::feed_version() const return _structure->feed_version; } -Glib::TimeVal Header::start_time() const +Glib::DateTime Header::start_time() const { - return Glib::TimeVal( - _structure->starttime.tv_sec, - _structure->starttime.tv_usec); + Glib::DateTime time = Glib::DateTime::create_now_utc(_structure->starttime.tv_sec); + return time.add_seconds(_structure->starttime.tv_usec / 1.0e6); } Meta::Meta(const struct sr_datafeed_meta *structure) : diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index 97e54e17..d090c379 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -274,7 +274,7 @@ public: std::shared_ptr create_user_device( std::string vendor, std::string model, std::string version); /** Create a header packet. */ - std::shared_ptr create_header_packet(Glib::TimeVal start_time); + std::shared_ptr create_header_packet(Glib::DateTime start_time); /** Create a meta packet. */ std::shared_ptr create_meta_packet( std::map config); @@ -711,7 +711,7 @@ public: /* Feed version number. */ int feed_version() const; /* Start time of this session. */ - Glib::TimeVal start_time() const; + Glib::DateTime start_time() const; private: explicit Header(const struct sr_datafeed_header *structure); ~Header();