]> sigrok.org Git - libsigrok.git/commitdiff
bindings/cxx: Increase compatibility for glibmm-2.68
authorFabrice Fontaine <redacted>
Mon, 3 Jan 2022 07:32:27 +0000 (08:32 +0100)
committerGerhard Sittig <redacted>
Thu, 24 Nov 2022 12:52:01 +0000 (13:52 +0100)
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 ]

bindings/cxx/classes.cpp
bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp

index f9f79273495026f52c61989b74fca89d1b99e50a..de600d039b7b41f2dac6190984e6f6523ccd724b 100644 (file)
@@ -287,12 +287,12 @@ shared_ptr<UserDevice> Context::create_user_device(
                default_delete<UserDevice>{}};
 }
 
-shared_ptr<Packet> Context::create_header_packet(Glib::TimeVal start_time)
+shared_ptr<Packet> 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) :
index 97e54e1731a88d1da3eb597c9d1c49cb20bd7750..d090c37997525b8851f23f0772c80d355a165365 100644 (file)
@@ -274,7 +274,7 @@ public:
        std::shared_ptr<UserDevice> create_user_device(
                std::string vendor, std::string model, std::string version);
        /** Create a header packet. */
-       std::shared_ptr<Packet> create_header_packet(Glib::TimeVal start_time);
+       std::shared_ptr<Packet> create_header_packet(Glib::DateTime start_time);
        /** Create a meta packet. */
        std::shared_ptr<Packet> create_meta_packet(
                std::map<const ConfigKey *, Glib::VariantBase> 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();