This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 508eb2f26f GH-44178: [GLib][FlightRPC] Add GAFlightCallOptions:timeout 
(#44181)
508eb2f26f is described below

commit 508eb2f26f0aa0b35f4c1223b496a2a8e58a93dd
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Sep 24 11:04:37 2024 +0900

    GH-44178: [GLib][FlightRPC] Add GAFlightCallOptions:timeout (#44181)
    
    ### Rationale for this change
    
    It's the bindings of `arrow::flight::FlightCallOptions::timeout`.
    
    ### What changes are included in this PR?
    
    Add `GAFlightCallOptions:timeout` property.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    * GitHub Issue: #44178
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-flight-glib/client.cpp     | 70 +++++++++++++++++++++++++++++++--
 c_glib/test/flight/test-call-options.rb |  6 +++
 2 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/c_glib/arrow-flight-glib/client.cpp 
b/c_glib/arrow-flight-glib/client.cpp
index 596aa4b3a5..8ec8e9729a 100644
--- a/c_glib/arrow-flight-glib/client.cpp
+++ b/c_glib/arrow-flight-glib/client.cpp
@@ -187,16 +187,20 @@ gaflight_metadata_reader_read(GAFlightMetadataReader 
*reader, GError **error)
   }
 }
 
-typedef struct GAFlightCallOptionsPrivate_
+struct GAFlightCallOptionsPrivate
 {
   arrow::flight::FlightCallOptions options;
-} GAFlightCallOptionsPrivate;
+};
+
+enum {
+  PROP_TIMEOUT = 1,
+};
 
 G_DEFINE_TYPE_WITH_PRIVATE(GAFlightCallOptions, gaflight_call_options, 
G_TYPE_OBJECT)
 
-#define GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(obj)                                 
          \
+#define GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(object)                              
          \
   static_cast<GAFlightCallOptionsPrivate *>(                                   
          \
-    gaflight_call_options_get_instance_private(GAFLIGHT_CALL_OPTIONS(obj)))
+    gaflight_call_options_get_instance_private(GAFLIGHT_CALL_OPTIONS(object)))
 
 static void
 gaflight_call_options_finalize(GObject *object)
@@ -208,6 +212,42 @@ gaflight_call_options_finalize(GObject *object)
   G_OBJECT_CLASS(gaflight_call_options_parent_class)->finalize(object);
 }
 
+static void
+gaflight_call_options_set_property(GObject *object,
+                                   guint prop_id,
+                                   const GValue *value,
+                                   GParamSpec *pspec)
+{
+  auto priv = GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(object);
+
+  switch (prop_id) {
+  case PROP_TIMEOUT:
+    priv->options.timeout = 
arrow::flight::TimeoutDuration(g_value_get_double(value));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+gaflight_call_options_get_property(GObject *object,
+                                   guint prop_id,
+                                   GValue *value,
+                                   GParamSpec *pspec)
+{
+  auto priv = GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(object);
+
+  switch (prop_id) {
+  case PROP_TIMEOUT:
+    g_value_set_double(value, priv->options.timeout.count());
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
 static void
 gaflight_call_options_init(GAFlightCallOptions *object)
 {
@@ -221,6 +261,28 @@ gaflight_call_options_class_init(GAFlightCallOptionsClass 
*klass)
   auto gobject_class = G_OBJECT_CLASS(klass);
 
   gobject_class->finalize = gaflight_call_options_finalize;
+  gobject_class->set_property = gaflight_call_options_set_property;
+  gobject_class->get_property = gaflight_call_options_get_property;
+
+  arrow::flight::FlightCallOptions options;
+  GParamSpec *spec;
+  /**
+   * GAFlightCallOptions:timeout:
+   *
+   * An optional timeout for this call. Negative durations mean an
+   * implementation-defined default behavior will be used
+   * instead. This is the default value.
+   *
+   * Since: 18.0.0
+   */
+  spec = g_param_spec_double("timeout",
+                             nullptr,
+                             nullptr,
+                             -G_MAXDOUBLE,
+                             G_MAXDOUBLE,
+                             options.timeout.count(),
+                             static_cast<GParamFlags>(G_PARAM_READWRITE));
+  g_object_class_install_property(gobject_class, PROP_TIMEOUT, spec);
 }
 
 /**
diff --git a/c_glib/test/flight/test-call-options.rb 
b/c_glib/test/flight/test-call-options.rb
index bf4dd6ae81..2574a9f7cb 100644
--- a/c_glib/test/flight/test-call-options.rb
+++ b/c_glib/test/flight/test-call-options.rb
@@ -44,4 +44,10 @@ class TestFlightCallOptions < Test::Unit::TestCase
     @options.clear_headers
     assert_equal([], collect_headers)
   end
+
+  def test_timeout
+    assert_in_delta(-1, @options.timeout)
+    @options.timeout = 10.1
+    assert_in_delta(10.1, @options.timeout)
+  end
 end

Reply via email to