You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2014/07/29 23:59:23 UTC

[1/2] git commit: THRIFT-2639 c_glib: Expose as properties members of generated structs

Repository: thrift
Updated Branches:
  refs/heads/master 87a0477a0 -> 2814c2e72


THRIFT-2639 c_glib: Expose as properties members of generated structs

Patch: Simon South

Signed-off-by: Roger Meier <ro...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/60b7ad6b
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/60b7ad6b
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/60b7ad6b

Branch: refs/heads/master
Commit: 60b7ad6b3d84127b322d65eba049ce3b6dd17e6b
Parents: 87a0477
Author: Roger Meier <ro...@apache.org>
Authored: Tue Jul 29 23:23:36 2014 +0200
Committer: Roger Meier <ro...@apache.org>
Committed: Tue Jul 29 23:25:53 2014 +0200

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_c_glib_generator.cc | 621 ++++++++++++-
 compiler/cpp/src/parse/t_enum.h                 |  45 +
 lib/c_glib/test/testdebugproto.c                | 907 +++++++++++++++++--
 3 files changed, 1505 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/60b7ad6b/compiler/cpp/src/generate/t_c_glib_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_c_glib_generator.cc b/compiler/cpp/src/generate/t_c_glib_generator.cc
index 576c60b..807b628 100644
--- a/compiler/cpp/src/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/generate/t_c_glib_generator.cc
@@ -126,6 +126,7 @@ class t_c_glib_generator : public t_oop_generator {
   string type_name(t_type* ttype, bool in_typedef=false, bool is_const=false);
   string base_type_name(t_base_type *type);
   string type_to_enum(t_type *type);
+  string constant_literal(t_type *type, t_const_value *value);
   string constant_value(string name, t_type *type, t_const_value *value);
   string function_signature(t_function *tfunction);
   string argument_list(t_struct *tstruct);
@@ -224,6 +225,12 @@ void t_c_glib_generator::init_generator() {
   }
   f_types_ << endl;
 
+  /* include math.h (for "INFINITY") in the implementation file, in case we
+     encounter a struct with a member of type double */
+  f_types_impl_ <<
+    endl <<
+    "#include <math.h>" << endl;
+
   // include the types file
   f_types_impl_ <<
     endl <<
@@ -667,6 +674,70 @@ string t_c_glib_generator::type_to_enum (t_type *type) {
 
 
 /**
+ * Returns a Thrift constant formatted as a literal for inclusion in C code.
+ */
+string t_c_glib_generator::constant_literal(t_type *type, t_const_value *value) {
+  ostringstream render;
+
+  if (type->is_base_type()) {
+    /* primitives */
+    t_base_type::t_base tbase = ((t_base_type *) type)->get_base();
+
+    switch (tbase) {
+      case t_base_type::TYPE_STRING:
+        render << "\"" + value->get_string() + "\"";
+        break;
+      case t_base_type::TYPE_BOOL:
+        render << ((value->get_integer() != 0) ? "TRUE" : "FALSE");
+        break;
+      case t_base_type::TYPE_BYTE:
+      case t_base_type::TYPE_I16:
+      case t_base_type::TYPE_I32:
+      case t_base_type::TYPE_I64:
+        render << value->get_integer();
+        break;
+      case t_base_type::TYPE_DOUBLE:
+        render << value->get_double();
+        break;
+      default:
+        throw "compiler error: no const of base type "
+              + t_base_type::t_base_name (tbase);
+    }
+  } else {
+    t_const_value::t_const_value_type value_type = value->get_type();
+
+    switch (value_type) {
+      case t_const_value::CV_IDENTIFIER:
+        render << value->get_integer();
+        break;
+      case t_const_value::CV_LIST:
+        render << "{ ";
+        {
+          t_type *elem_type = ((t_list *) type)->get_elem_type();
+          const vector<t_const_value *> &list = value->get_list();
+          vector<t_const_value *>::const_iterator list_iter;
+
+          if (list.size() > 0) {
+            list_iter = list.begin();
+            render << constant_literal(elem_type, *list_iter);
+
+            while (++list_iter != list.end()) {
+              render << ", " << constant_literal(elem_type, *list_iter);
+            }
+          }
+        }
+        render << " }";
+        break;
+      case t_const_value::CV_MAP:
+      default:
+        render << "NULL /* not supported */";
+    }
+  }
+
+  return render.str();
+}
+
+/**
  * Returns C code that represents a Thrift constant.
  */
 string t_c_glib_generator::constant_value(string name, t_type *type, t_const_value *value) {
@@ -1741,6 +1812,13 @@ void t_c_glib_generator::generate_object(t_struct *tstruct) {
   string name_u = initial_caps_to_underscores(name);
   string name_uc = to_upper_case(name_u);
 
+  string class_name = this->nspace + name;
+  string class_name_lc = to_lower_case(initial_caps_to_underscores(class_name));
+  string class_name_uc = to_upper_case(class_name_lc);
+
+  string function_name;
+  string args_indent;
+
   // write the instance definition
   f_types_ <<
     "struct _" << this->nspace << name << endl <<
@@ -1790,27 +1868,338 @@ void t_c_glib_generator::generate_object(t_struct *tstruct) {
     endl;
 
   // start writing the object implementation .c file
+
+  // generate properties enum
+  if (members.size() > 0) {
+    f_types_impl_ <<
+      "enum _" << class_name << "Properties" << endl <<
+      "{" << endl;
+    indent_up();
+    f_types_impl_ <<
+      indent() << "PROP_" << class_name_uc << "_0";
+    for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+      string member_name_uc =
+        to_upper_case(to_lower_case
+                      (initial_caps_to_underscores((*m_iter)->get_name())));
+
+      f_types_impl_ << "," << endl <<
+        indent() << "PROP_" << class_name_uc << "_" << member_name_uc;
+    }
+    f_types_impl_ << endl;
+    indent_down();
+    f_types_impl_ <<
+      "};" << endl <<
+      endl;
+  }
+
   // generate struct I/O methods
   string this_get = this->nspace + name + " * this_object = " 
                     + this->nspace_uc + name_uc + "(object);";
   generate_struct_reader (f_types_impl_, tstruct, "this_object->", this_get);
   generate_struct_writer (f_types_impl_, tstruct, "this_object->", this_get);
 
+  // generate property setter and getter
+  if (members.size() > 0) {
+    // generate property setter
+    function_name = class_name_lc + "_set_property";
+    args_indent = string(function_name.length() + 2, ' ');
+    f_types_impl_ <<
+      "static void" << endl <<
+      function_name << " (GObject *object," << endl <<
+      args_indent << "guint property_id," << endl <<
+      args_indent << "const GValue *value," << endl <<
+      args_indent << "GParamSpec *pspec)" << endl;
+    scope_up(f_types_impl_);
+    f_types_impl_ <<
+      indent() << class_name << " *self = " <<
+      class_name_uc << " (object);" << endl <<
+      endl <<
+      indent() << "switch (property_id)" << endl;
+    scope_up(f_types_impl_);
+    for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+      t_field *member = (*m_iter);
+      string member_name = member->get_name();
+      string member_name_uc =
+        to_upper_case(to_lower_case(initial_caps_to_underscores(member_name)));
+      t_type *member_type = get_true_type(member->get_type());
+
+      string property_identifier =
+        "PROP_" + class_name_uc + "_" + member_name_uc;
+
+      f_types_impl_ <<
+        indent() << "case " << property_identifier + ":" << endl;
+      indent_up();
+
+      if (member_type->is_base_type()) {
+        t_base_type *base_type = ((t_base_type *) member_type);
+        string assign_function_name;
+
+        if (base_type->get_base() == t_base_type::TYPE_STRING) {
+          string release_function_name;
+
+          f_types_impl_ <<
+            indent() << "if (self->" << member_name << " != NULL)" << endl;
+          indent_up();
+
+          if (base_type->is_binary()) {
+            release_function_name = "g_byte_array_unref";
+            assign_function_name = "g_value_dup_boxed";
+          } else {
+            release_function_name = "g_free";
+            assign_function_name = "g_value_dup_string";
+          }
+
+          f_types_impl_ <<
+            indent() << release_function_name <<
+            " (self->" << member_name << ");" << endl;
+          indent_down();
+        } else {
+          switch (base_type->get_base()) {
+          case t_base_type::TYPE_BOOL:
+            assign_function_name = "g_value_get_boolean";
+            break;
+
+          case t_base_type::TYPE_BYTE:
+          case t_base_type::TYPE_I16:
+          case t_base_type::TYPE_I32:
+            assign_function_name = "g_value_get_int";
+            break;
+
+          case t_base_type::TYPE_I64:
+            assign_function_name = "g_value_get_int64";
+            break;
+
+          case t_base_type::TYPE_DOUBLE :
+            assign_function_name = "g_value_get_double";
+            break;
+
+          default:
+            throw "compiler error: "
+              "unrecognized base type \"" + base_type->get_name() + "\" "
+              "for struct member \"" + member_name + "\"";
+            break;
+          }
+        }
+
+        f_types_impl_ <<
+          indent() << "self->" << member_name <<
+          " = " << assign_function_name << " (value);" << endl;
+      } else if (member_type->is_enum()) {
+        f_types_impl_ <<
+          indent() << "self->" << member_name <<
+          " = g_value_get_int (value);" << endl;
+      } else if (member_type->is_container()) {
+        string release_function_name;
+        string assign_function_name;
+
+        if (member_type->is_list()) {
+          t_type *elem_type = ((t_list *) member_type)->get_elem_type();
+
+          // Lists of base types other than strings are represented as GArrays;
+          // all others as GPtrArrays
+          if (elem_type->is_base_type() && !elem_type->is_string()) {
+            release_function_name = "g_array_unref";
+          } else {
+            release_function_name = "g_ptr_array_unref";
+          }
+
+          assign_function_name = "g_value_dup_boxed";
+        } else if (member_type->is_set() || member_type->is_map()) {
+          release_function_name = "g_hash_table_unref";
+          assign_function_name = "g_value_dup_boxed";
+        }
+
+        f_types_impl_ <<
+          indent() << "if (self->" << member_name << " != NULL)" << endl;
+        indent_up();
+        f_types_impl_ <<
+          indent() << release_function_name << " (self->" << member_name <<
+          ");" << endl;
+        indent_down();
+        f_types_impl_ <<
+          indent() << "self->" << member_name << " = " <<
+          assign_function_name << " (value);" << endl;
+      } else if (member_type->is_struct()) {
+        f_types_impl_ <<
+          indent() << "if (self->" << member_name << " != NULL)" << endl;
+        indent_up();
+        f_types_impl_ <<
+          indent() << "g_object_unref (self->" << member_name <<
+          ");" << endl;
+        indent_down();
+        f_types_impl_ <<
+          indent() << "self->" << member_name <<
+          " = g_value_dup_object (value);" << endl;
+      }
+
+      if (member->get_req() != t_field::T_REQUIRED) {
+        f_types_impl_ <<
+          indent() << "self->__isset_" << member_name << " = TRUE;" << endl;
+      }
+
+      f_types_impl_ <<
+        indent() << "break;" << endl <<
+        endl;
+      indent_down();
+    }
+    f_types_impl_ <<
+      indent() << "default:" << endl;
+    indent_up();
+    f_types_impl_ <<
+      indent() <<
+      "G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);" << endl <<
+      indent() << "break;" << endl;
+    indent_down();
+    scope_down(f_types_impl_);
+    scope_down(f_types_impl_);
+    f_types_impl_ << endl;
+
+    // generate property getter
+    function_name = class_name_lc + "_get_property";
+    args_indent = string(function_name.length() + 2, ' ');
+    f_types_impl_ <<
+      "static void" << endl <<
+      function_name << " (GObject *object," << endl <<
+      args_indent << "guint property_id," << endl <<
+      args_indent << "GValue *value," << endl <<
+      args_indent << "GParamSpec *pspec)" << endl;
+    scope_up(f_types_impl_);
+    f_types_impl_ <<
+      indent() << class_name << " *self = " <<
+      class_name_uc << " (object);" << endl <<
+      endl <<
+      indent() << "switch (property_id)" << endl;
+    scope_up(f_types_impl_);
+    for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+      t_field *member = (*m_iter);
+      string member_name = (*m_iter)->get_name();
+      string member_name_uc =
+        to_upper_case(to_lower_case(initial_caps_to_underscores(member_name)));
+      t_type *member_type = get_true_type(member->get_type());
+
+      string property_identifier =
+        "PROP_" + class_name_uc + "_" + member_name_uc;
+
+      string setter_function_name;
+
+      if (member_type->is_base_type()) {
+        t_base_type *base_type = ((t_base_type *) member_type);
+
+        switch (base_type->get_base()) {
+        case t_base_type::TYPE_BOOL:
+          setter_function_name = "g_value_set_boolean";
+          break;
+
+        case t_base_type::TYPE_BYTE:
+        case t_base_type::TYPE_I16:
+        case t_base_type::TYPE_I32:
+          setter_function_name = "g_value_set_int";
+          break;
+
+        case t_base_type::TYPE_I64:
+          setter_function_name = "g_value_set_int64";
+          break;
+
+        case t_base_type::TYPE_DOUBLE :
+          setter_function_name = "g_value_set_double";
+          break;
+
+        case t_base_type::TYPE_STRING:
+          if (base_type->is_binary()) {
+            setter_function_name = "g_value_set_boxed";
+          } else {
+            setter_function_name = "g_value_set_string";
+          }
+          break;
+
+        default:
+          throw "compiler error: "
+            "unrecognized base type \"" + base_type->get_name() + "\" "
+            "for struct member \"" + member_name + "\"";
+          break;
+        }
+      } else if (member_type->is_enum()) {
+        setter_function_name = "g_value_set_int";
+      } else if (member_type->is_struct()) {
+        setter_function_name = "g_value_set_object";
+      } else if (member_type->is_container()) {
+        setter_function_name = "g_value_set_boxed";
+      } else {
+        throw "compiler error: "
+          "unrecognized type for struct member \"" + member_name + "\"";
+      }
+
+      f_types_impl_ <<
+        indent() << "case " << property_identifier + ":" << endl;
+      indent_up();
+      f_types_impl_ <<
+        indent() << setter_function_name << " (value, self->" <<
+        member_name << ");" << endl <<
+        indent() << "break;" << endl <<
+        endl;
+      indent_down();
+    }
+    f_types_impl_ <<
+      indent() << "default:" << endl;
+    indent_up();
+    f_types_impl_ <<
+      indent() <<
+      "G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);" << endl <<
+      indent() << "break;" << endl;
+    indent_down();
+    scope_down(f_types_impl_);
+    scope_down(f_types_impl_);
+    f_types_impl_ << endl;
+  }
+
   // generate the instance init function
+
   f_types_impl_ <<
     "static void " << endl <<
     this->nspace_lc << name_u << "_instance_init (" << this->nspace << name << " * object)" << endl <<
     "{" << endl;
+  indent_up();
+
+  // generate default-value structures for container-type members
+  bool constant_declaration_output = false;
+  for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+    t_field *member = *m_iter;
+    t_const_value *member_value = member->get_value();
+
+    if (member_value != NULL) {
+      string member_name = member->get_name();
+      t_type* member_type = get_true_type (member->get_type());
+
+      if (member_type->is_list()) {
+        const vector<t_const_value *> &list = member_value->get_list();
+        t_type *elem_type = ((t_list *) member_type)->get_elem_type();
+
+        // Generate an array with the list literal
+        indent(f_types_impl_) <<
+          "static " << type_name(elem_type, false, true) <<
+          " __default_" << member_name << "[" << list.size() << "] = " << endl;
+        indent_up();
+        f_types_impl_ <<
+          indent() << constant_literal (member_type, member_value) << ";" << endl;
+        indent_down();
+
+        constant_declaration_output = true;
+      }
+
+      // TODO: Handle container types other than list
+    }
+  }
+  if (constant_declaration_output) {
+    f_types_impl_ << endl;
+  }
 
   // satisfy compilers with -Wall turned on
-  indent_up();
   indent(f_types_impl_) << "/* satisfy -Wall */" << endl <<
                indent() << "THRIFT_UNUSED_VAR (object);" << endl;
 
   for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
     t_type* t = get_true_type ((*m_iter)->get_type());
     if (t->is_base_type()) {
-      // only have init's for base types
       string dval = " = ";
       if (t->is_enum()) {
         dval += "(" + type_name (t) + ")";
@@ -1849,6 +2238,21 @@ void t_c_glib_generator::generate_object(t_struct *tstruct) {
       indent(f_types_impl_) << "object->" << name << " = " <<
                                   init_function << endl;
 
+      // Pre-populate the container with the specified default values, if any
+      if ((*m_iter)->get_value()) {
+        t_const_value *member_value = (*m_iter)->get_value();
+
+        if (t->is_list()) {
+          const vector<t_const_value *> &list = member_value->get_list();
+
+          indent(f_types_impl_) <<
+            "g_array_append_vals (object->" << name <<
+            ", &__default_" << name <<
+            ", " << list.size() << ");" << endl;
+        }
+
+        // TODO: Handle container types other than list
+      }
     }
 
     /* if not required, initialize the __isset variable */
@@ -1955,25 +2359,216 @@ void t_c_glib_generator::generate_object(t_struct *tstruct) {
     "}" << endl <<
     endl;
 
+  // generate the class init function
 
   f_types_impl_ <<
-    "static void " << endl <<
-    this->nspace_lc << name_u << "_class_init (ThriftStructClass * cls)" << endl <<
-    "{" << endl;
-  indent_up();
+    "static void" << endl <<
+    class_name_lc << "_class_init (" << class_name << "Class * cls)" << endl;
+  scope_up(f_types_impl_);
 
   f_types_impl_ <<   
     indent() << "GObjectClass *gobject_class = G_OBJECT_CLASS (cls);" << endl <<
+    indent() << "ThriftStructClass *struct_class = "  <<
+    "THRIFT_STRUCT_CLASS (cls);" << endl <<
+    endl <<
+    indent() << "struct_class->read = " << class_name_lc << "_read;" << endl <<
+    indent() << "struct_class->write = " << class_name_lc << "_write;" << endl <<
     endl <<
-    indent() << "gobject_class->finalize = " << this->nspace_lc << name_u << "_finalize;" << endl <<
-    indent() << "cls->read = " << this->nspace_lc << name_u << "_read;" << endl <<
-    indent() << "cls->write = " << this->nspace_lc << name_u << "_write;" << endl;
+    indent() << "gobject_class->finalize = " << class_name_lc << "_finalize;" << endl;
+  if (members.size() > 0) {
+    f_types_impl_ <<
+      indent() << "gobject_class->get_property = " <<
+      class_name_lc << "_get_property;" << endl <<
+      indent() << "gobject_class->set_property = " <<
+      class_name_lc << "_set_property;" << endl;
+
+    // install a property for each member
+    for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+      t_field *member = (*m_iter);
+      string member_name = member->get_name();
+      string member_name_uc =
+        to_upper_case(to_lower_case(initial_caps_to_underscores(member_name)));
+      t_type *member_type = get_true_type(member->get_type());
+      t_const_value *member_value = member->get_value();
+
+      string property_identifier =
+        "PROP_" + class_name_uc + "_" + member_name_uc;
+
+      f_types_impl_ << endl <<
+        indent() << "g_object_class_install_property" << endl;
+      indent_up();
+      args_indent = indent() + ' ';
+      f_types_impl_ <<
+        indent() << "(gobject_class," << endl <<
+        args_indent << property_identifier << "," << endl <<
+        args_indent;
+
+      if (member_type->is_base_type()) {
+        t_base_type::t_base base_type =
+          ((t_base_type *) member_type)->get_base();
+
+        if (base_type == t_base_type::TYPE_STRING) {
+          if (((t_base_type *) member_type)->is_binary()) {
+            args_indent += string(20, ' ');
+            f_types_impl_ <<
+              "g_param_spec_boxed (\"" << member_name << "\"," << endl <<
+              args_indent << "NULL," << endl <<
+              args_indent << "NULL," << endl <<
+              args_indent << "G_TYPE_BYTE_ARRAY," << endl <<
+              args_indent << "G_PARAM_READWRITE));" << endl;
+          } else {
+            args_indent += string(21, ' ');
+            f_types_impl_ <<
+              "g_param_spec_string (\"" << member_name << "\"," << endl <<
+              args_indent << "NULL," << endl <<
+              args_indent << "NULL," << endl <<
+              args_indent <<
+              ((member_value != NULL) ?
+               "\"" + member_value->get_string() + "\"" :
+               "NULL") <<
+              "," << endl <<
+              args_indent << "G_PARAM_READWRITE));" << endl;
+          }
+        } else if (base_type == t_base_type::TYPE_BOOL) {
+          args_indent += string(22, ' ');
+          f_types_impl_ <<
+            "g_param_spec_boolean (\"" << member_name << "\"," << endl <<
+            args_indent << "NULL," << endl <<
+            args_indent << "NULL," << endl <<
+            args_indent <<
+            (((member_value != NULL) &&
+              (member_value->get_integer() != 0)) ? "TRUE" : "FALSE") <<
+            "," << endl <<
+            args_indent << "G_PARAM_READWRITE));" << endl;
+        } else if ((base_type == t_base_type::TYPE_BYTE) ||
+                   (base_type == t_base_type::TYPE_I16) ||
+                   (base_type == t_base_type::TYPE_I32) ||
+                   (base_type == t_base_type::TYPE_I64) ||
+                   (base_type == t_base_type::TYPE_DOUBLE)) {
+          string param_spec_function_name = "g_param_spec_int";
+          string min_value;
+          string max_value;
+          string default_value =
+            std::to_string((member_value != NULL) ?
+                           member_value->get_integer() :
+                           0);
+
+          switch (base_type) {
+          case t_base_type::TYPE_BYTE:
+            min_value = "G_MININT8";
+            max_value = "G_MAXINT8";
+            break;
 
-  indent_down();
-  f_types_impl_ <<
-    "}" << endl <<
-    endl;
+          case t_base_type::TYPE_I16:
+            min_value = "G_MININT16";
+            max_value = "G_MAXINT16";
+            break;
+
+          case t_base_type::TYPE_I32:
+            min_value = "G_MININT32";
+            max_value = "G_MAXINT32";
+            break;
 
+          case t_base_type::TYPE_I64:
+            param_spec_function_name = "g_param_spec_int64";
+            min_value = "G_MININT64";
+            max_value = "G_MAXINT64";
+            break;
+
+          case t_base_type::TYPE_DOUBLE:
+            param_spec_function_name = "g_param_spec_double";
+            min_value = "-INFINITY";
+            max_value = "INFINITY";
+            if (member_value != NULL) {
+              default_value = std::to_string(member_value->get_double());
+            }
+            break;
+
+          default:
+            throw "compiler error: "
+              "unrecognized base type \"" + member_type->get_name() + "\" "
+              "for struct member \"" + member_name + "\"";
+            break;
+          }
+
+          args_indent += string(param_spec_function_name.length() + 2, ' ');
+          f_types_impl_ <<
+            param_spec_function_name << " (\"" << member_name << "\"," << endl <<
+            args_indent << "NULL," << endl <<
+            args_indent << "NULL," << endl <<
+            args_indent << min_value << "," << endl <<
+            args_indent << max_value << "," << endl <<
+            args_indent << default_value << "," << endl <<
+            args_indent << "G_PARAM_READWRITE));" << endl;
+        }
+
+        indent_down();
+      } else if (member_type->is_enum()) {
+        t_enum_value *enum_min_value =
+          ((t_enum *) member_type)->get_min_value();
+        t_enum_value *enum_max_value =
+          ((t_enum *) member_type)->get_max_value();
+        int min_value =
+          (enum_min_value != NULL) ? enum_min_value->get_value() : 0;
+        int max_value =
+          (enum_max_value != NULL) ? enum_max_value->get_value() : 0;
+
+        args_indent += string(18, ' ');
+        f_types_impl_ <<
+          "g_param_spec_int (\"" << member_name << "\"," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << min_value << "," << endl <<
+          args_indent << max_value << "," << endl <<
+          args_indent << min_value << "," << endl <<
+          args_indent << "G_PARAM_READWRITE));" << endl;
+        indent_down();
+      } else if (member_type->is_struct()) {
+        string param_type =
+          this->nspace_uc +
+          "TYPE_" +
+          to_upper_case(initial_caps_to_underscores(member_type->get_name()));
+
+        args_indent += string(20, ' ');
+        f_types_impl_ <<
+          "g_param_spec_object (\"" << member_name << "\"," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << param_type << "," << endl <<
+          args_indent << "G_PARAM_READWRITE));" << endl;
+        indent_down();
+      } else if (member_type->is_list()) {
+        t_type *elem_type = ((t_list *) member_type)->get_elem_type();
+        string param_type;
+
+        if (elem_type->is_base_type() && !elem_type->is_string()) {
+          param_type = "G_TYPE_ARRAY";
+        } else {
+          param_type = "G_TYPE_PTR_ARRAY";
+        }
+
+        args_indent += string(20, ' ');
+        f_types_impl_ <<
+          "g_param_spec_boxed (\"" << member_name << "\"," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << param_type << "," << endl <<
+          args_indent << "G_PARAM_READWRITE));" << endl;
+        indent_down();
+      } else if (member_type->is_set() || member_type->is_map()) {
+        args_indent += string(20, ' ');
+        f_types_impl_ <<
+          "g_param_spec_boxed (\"" << member_name << "\"," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << "NULL," << endl <<
+          args_indent << "G_TYPE_HASH_TABLE," << endl <<
+          args_indent << "G_PARAM_READWRITE));" << endl;
+        indent_down();
+      }
+    }
+  }
+  scope_down(f_types_impl_);
+  f_types_impl_ << endl;
 
   f_types_impl_ <<
     "GType" << endl <<

http://git-wip-us.apache.org/repos/asf/thrift/blob/60b7ad6b/compiler/cpp/src/parse/t_enum.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/parse/t_enum.h b/compiler/cpp/src/parse/t_enum.h
index 45d1606..ec847d1 100644
--- a/compiler/cpp/src/parse/t_enum.h
+++ b/compiler/cpp/src/parse/t_enum.h
@@ -66,6 +66,51 @@ class t_enum : public t_type {
     return NULL;
   }
 
+  t_enum_value* get_min_value() {
+    const std::vector<t_enum_value*>& enum_values = get_constants();
+    std::vector<t_enum_value*>::const_iterator c_iter;
+    t_enum_value* min_value;
+    if (enum_values.size() == 0) {
+      min_value = NULL;
+    }
+    else {
+      int min_value_value;
+      min_value = enum_values.front();
+      min_value_value = (min_value->has_value() ? min_value->get_value() : 1);
+      for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
+        if ((*c_iter)->has_value() &&
+            ((*c_iter)->get_value() < min_value_value)) {
+          min_value = (*c_iter);
+          min_value_value = min_value->get_value();
+        }
+      }
+    }
+    return min_value;
+  }
+
+  t_enum_value* get_max_value() {
+    const std::vector<t_enum_value*>& enum_values = get_constants();
+    std::vector<t_enum_value*>::const_iterator c_iter;
+    t_enum_value* max_value;
+    if (enum_values.size() == 0) {
+      max_value = NULL;
+    }
+    else {
+      int max_value_value;
+      max_value = enum_values.back();
+      max_value_value =
+        (max_value->has_value() ? max_value->get_value() : enum_values.size());
+      for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
+        if ((*c_iter)->has_value() &&
+            ((*c_iter)->get_value() > max_value_value)) {
+          max_value = (*c_iter);
+          max_value_value = max_value->get_value();
+        }
+      }
+    }
+    return max_value;
+  }
+
   bool is_enum() const {
     return true;
   }

http://git-wip-us.apache.org/repos/asf/thrift/blob/60b7ad6b/lib/c_glib/test/testdebugproto.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testdebugproto.c b/lib/c_glib/test/testdebugproto.c
index f2ea3af..e343c1e 100644
--- a/lib/c_glib/test/testdebugproto.c
+++ b/lib/c_glib/test/testdebugproto.c
@@ -19,6 +19,7 @@
 
 #include <assert.h>
 #include <math.h>
+#include <string.h>
 #include <glib-object.h>
 
 #ifndef M_PI
@@ -33,60 +34,796 @@
 #include "gen-c_glib/t_test_inherited.h"
 
 static void
-test_structs(void)
-{
-  TTestOneOfEach *ooe = NULL;
-  TTestNesting *n = NULL;
-  TTestHolyMoley *hm = NULL;
-  gchar *random = g_strdup("random string");
-  gchar *nothing = g_strdup("nothing");
-
-  ooe = g_object_new (T_TEST_TYPE_ONE_OF_EACH, NULL);
-  ooe->im_true = TRUE;
-  ooe->im_false = FALSE;
-  ooe->a_bite = 0xd6;
-  ooe->integer16 = 27000;
-  ooe->integer32 = 1<<24;
-  ooe->integer64 = (guint64) 6000 * 1000 * 1000;
-  ooe->double_precision = M_PI;
-  ooe->some_characters = g_strdup("Debug THIS!");
-  ooe->zomg_unicode = g_strdup("\xd7\n\a\t");
-
-  n = g_object_new (T_TEST_TYPE_NESTING, NULL);
-  if (n->my_ooe != NULL)
-    g_object_unref(n->my_ooe);
-
-  n->my_ooe = ooe;
-  n->my_ooe->integer16 = 16;
-  n->my_ooe->integer32 = 32;
-  n->my_ooe->integer64 = 64;
-  n->my_ooe->double_precision = (sqrt(5.0) + 1) / 2;
-  n->my_ooe->some_characters = g_strdup(":R (me going \"rrrr\")");
-  n->my_ooe->zomg_unicode = g_strdup("\xd3\x80\xe2\x85\xae\xce\x9d\x20");
-  n->my_bonk->type = 31337;
-  n->my_bonk->message = g_strdup("I am a bonk... xor!");
-
-  hm = g_object_new (T_TEST_TYPE_HOLY_MOLEY, NULL);
-  g_ptr_array_add (hm->big, ooe);
-  g_ptr_array_add (hm->big, g_object_ref(n->my_ooe));
-  ((TTestOneOfEach *) g_ptr_array_index (hm->big, 0))->a_bite = 0x22;
-  ((TTestOneOfEach *) g_ptr_array_index (hm->big, 1))->a_bite = 0x33;
-
-  g_hash_table_insert (hm->contain, random, random);
+test_structs_doubles_create_and_destroy (void)
+{
+  GObject *object = NULL;
+
+  /* A Doubles structure can be created... */
+  object = g_object_new (T_TEST_TYPE_DOUBLES, NULL);
+
+  g_assert (object != NULL);
+  g_assert (T_TEST_IS_DOUBLES (object));
+
+  /* ...and destroyed */
+  g_object_unref (object);
+}
+
+static void
+test_structs_doubles_initialize (void)
+{
+  TTestDoubles *doubles = NULL;
+  gdouble nan;
+  gdouble inf;
+  gdouble neginf;
+  gdouble repeating;
+  gdouble big;
+  gdouble tiny;
+  gdouble zero;
+  gdouble negzero;
+
+  /* Note there seems to be no way to get not-a-number ("NAN") values past
+     GObject's range-checking, so that portion of the test has been commented
+     out below. */
+
+  /* A Doubles structure's members are available as GObject properties
+     that can be initialized at construction... */
+  doubles = g_object_new (T_TEST_TYPE_DOUBLES,
+                          /* "nan",      0 * INFINITY, */
+                          "inf",          INFINITY,
+                          "neginf",      -INFINITY,
+                          "repeating",     1.0 / 3,
+                          "big",       G_MAXDOUBLE,
+                          "tiny",          10E-101,
+                          "zero",          1.0 * 0,
+                          "negzero",      -1.0 * 0,
+                          NULL);
+
+  g_assert (doubles != NULL);
+
+  /* ...and later retrieved */
+  g_object_get (doubles,
+                "nan",       &nan,
+                "inf",       &inf,
+                "neginf",    &neginf,
+                "repeating", &repeating,
+                "big",       &big,
+                "tiny",      &tiny,
+                "zero",      &zero,
+                "negzero",   &negzero,
+                NULL);
+
+  /* g_assert_cmpint (isnan (nan),    !=,  0); */
+  g_assert_cmpint (isinf (inf),    ==,  1);
+  g_assert_cmpint (isinf (neginf), ==, -1);
+
+  g_assert_cmpfloat (repeating, ==,     1.0 / 3);
+  g_assert_cmpfloat (big,       ==, G_MAXDOUBLE);
+  g_assert_cmpfloat (tiny,      ==,     10E-101);
+  g_assert_cmpfloat (zero,      ==,     1.0 * 0);
+  g_assert_cmpfloat (negzero,   ==,    -1.0 * 0);
+
+  g_object_unref (doubles);
+}
+
+static void
+test_structs_one_of_each_create_and_destroy (void)
+{
+  GObject *object = NULL;
+
+  /* A OneOfEach structure can be created... */
+  object = g_object_new (T_TEST_TYPE_ONE_OF_EACH, NULL);
+
+  g_assert (object != NULL);
+  g_assert (T_TEST_IS_ONE_OF_EACH (object));
+
+  /* ...and destroyed */
+  g_object_unref (object);
+}
+
+static void
+test_structs_one_of_each_initialize_default_values (void)
+{
+  TTestOneOfEach *one_of_each = NULL;
+  gint   a_bite;
+  gint   integer16;
+  gint64 integer64;
+  GArray *byte_list;
+  GArray *i16_list;
+  GArray *i64_list;
+
+  /* A OneOfEach structure created with no explicit property values
+     will hold the default values specified in the .thrift file */
+  one_of_each = g_object_new (T_TEST_TYPE_ONE_OF_EACH, NULL);
+
+  g_object_get (one_of_each,
+                "a_bite",    &a_bite,
+                "integer16", &integer16,
+                "integer64", &integer64,
+                "byte_list", &byte_list,
+                "i16_list",  &i16_list,
+                "i64_list",  &i64_list,
+                NULL);
+
+  g_assert_cmpint (a_bite,    ==, 0x7f);
+  g_assert_cmpint (integer16, ==, 0x7fff);
+  g_assert_cmpint (integer64, ==, 10000000000);
+
+  g_assert (byte_list != NULL);
+  g_assert_cmpint (byte_list->len, ==, 3);
+  g_assert_cmpint (g_array_index (byte_list, gint8, 0), ==, 1);
+  g_assert_cmpint (g_array_index (byte_list, gint8, 1), ==, 2);
+  g_assert_cmpint (g_array_index (byte_list, gint8, 2), ==, 3);
+
+  g_assert (i16_list != NULL);
+  g_assert_cmpint (i16_list->len, ==, 3);
+  g_assert_cmpint (g_array_index (i16_list, gint16, 0), ==, 1);
+  g_assert_cmpint (g_array_index (i16_list, gint16, 1), ==, 2);
+  g_assert_cmpint (g_array_index (i16_list, gint16, 2), ==, 3);
+
+  g_assert (i64_list != NULL);
+  g_assert_cmpint (i64_list->len, ==, 3);
+  g_assert_cmpint (g_array_index (i64_list, gint64, 0), ==, 1);
+  g_assert_cmpint (g_array_index (i64_list, gint64, 1), ==, 2);
+  g_assert_cmpint (g_array_index (i64_list, gint64, 2), ==, 3);
+
+  g_array_unref (i64_list);
+  g_array_unref (i16_list);
+  g_array_unref (byte_list);
+  g_object_unref (one_of_each);
+}
+
+static void
+test_structs_one_of_each_initialize_specified_values (void)
+{
+  static const gint8 initial_byte_list[5] = { 13, 21, 34, 55, 89 };
+  static const gint16 initial_i16_list[5] = { 4181, 6765, 10946, 17711, 28657 };
+  static const gint64 initial_i64_list[5] =
+    {
+      1100087778366101931, 1779979416004714189, 2880067194370816120,
+      4660046610375530309, 7540113804746346429
+    };
+  static const guint8 initial_base64[8] =
+    {
+      0x56, 0x47, 0x68, 0x79, 0x61, 0x57, 0x5a, 0x30
+    };
+
+  TTestOneOfEach *one_of_each;
+  gboolean im_true;
+  gboolean im_false;
+  gint a_bite;
+  gint integer16;
+  gint integer32;
+  gint64 integer64;
+  double double_precision;
+  gchar *some_characters;
+  gchar *zomg_unicode;
+  gboolean what_who;
+  GByteArray *base64;
+  GArray *byte_list;
+  GArray *i16_list;
+  GArray *i64_list;
+
+  base64 = g_byte_array_new ();
+  g_byte_array_append (base64, initial_base64, 8);
+
+  byte_list = g_array_new (FALSE, FALSE, sizeof (gint8));
+  g_array_append_vals (byte_list, initial_byte_list, 5);
+
+  i16_list = g_array_new (FALSE, FALSE, sizeof (gint16));
+  g_array_append_vals (i16_list, initial_i16_list, 5);
+
+  i64_list = g_array_new (FALSE, FALSE, sizeof (gint64));
+  g_array_append_vals (i64_list, initial_i64_list, 5);
+
+  /* All of OneOfEach's properties can be set at construction... */
+  one_of_each = g_object_new (T_TEST_TYPE_ONE_OF_EACH,
+                              "im_true",          TRUE,
+                              "im_false",         FALSE,
+                              "a_bite",           0x50,
+                              "integer16",        0x7e57,
+                              "integer32",        0xdeadbeef,
+                              "integer64",        0xfa15efacade15bad,
+                              "double_precision", M_PI,
+                              "some_characters",  "Debug THIS!",
+                              "zomg_unicode",     "\xd7\n\a\t",
+                              "what_who",         TRUE,
+                              "base64",           base64,
+                              "byte_list",        byte_list,
+                              "i16_list",         i16_list,
+                              "i64_list",         i64_list,
+                              NULL);
+  g_assert (one_of_each != NULL);
+
+  g_array_unref (i64_list);
+  i64_list = NULL;
+  g_array_unref (i16_list);
+  i16_list = NULL;
+  g_array_unref (byte_list);
+  byte_list = NULL;
+  g_byte_array_unref (base64);
+  base64 = NULL;
+
+  /* ...and later retrieved */
+  g_object_get (one_of_each,
+                "im_true",          &im_true,
+                "im_false",         &im_false,
+                "a_bite",           &a_bite,
+                "integer16",        &integer16,
+                "integer32",        &integer32,
+                "integer64",        &integer64,
+                "double_precision", &double_precision,
+                "some_characters",  &some_characters,
+                "zomg_unicode",     &zomg_unicode,
+                "what_who",         &what_who,
+                "base64",           &base64,
+                "byte_list",        &byte_list,
+                "i16_list",         &i16_list,
+                "i64_list",         &i64_list,
+                NULL);
+
+  g_assert (im_true  == TRUE);
+  g_assert (im_false == FALSE);
+
+  g_assert_cmphex (a_bite,    ==, 0x50);
+  g_assert_cmphex (integer16, ==, 0x7e57);
+  g_assert_cmphex (integer32, ==, (gint32)0xdeadbeef);
+  g_assert_cmphex (integer64, ==, 0xfa15efacade15bad);
+
+  g_assert_cmpfloat (double_precision, ==, M_PI);
+
+  g_assert_cmpstr (some_characters, ==, "Debug THIS!");
+  g_assert_cmpstr (zomg_unicode,    ==, "\xd7\n\a\t");
+
+  g_assert (what_who == TRUE);
+
+  g_assert_cmpint (base64->len, ==, 8);
+  g_assert_cmpint (memcmp (base64->data,
+                           initial_base64,
+                           8 * sizeof (guint8)), ==, 0);
+
+  g_assert_cmpint (byte_list->len, ==, 5);
+  g_assert_cmpint (memcmp (byte_list->data,
+                           initial_byte_list,
+                           5 * sizeof (gint8)),  ==, 0);
+
+  g_assert_cmpint (i16_list->len, ==, 5);
+  g_assert_cmpint (memcmp (i16_list->data,
+                           initial_i16_list,
+                           5 * sizeof (gint16)), ==, 0);
+
+  g_assert_cmpint (i64_list->len, ==, 5);
+  g_assert_cmpint (memcmp (i64_list->data,
+                           initial_i64_list,
+                           5 * sizeof (gint64)), ==, 0);
+
+  g_array_unref (i64_list);
+  g_array_unref (i16_list);
+  g_array_unref (byte_list);
+  g_byte_array_unref (base64);
+
+  g_object_unref (one_of_each);
+}
+
+static void
+test_structs_one_of_each_properties_byte_list (void)
+{
+  TTestOneOfEach *one_of_each;
+  GArray *byte_list = NULL;
+
+  one_of_each = g_object_new (T_TEST_TYPE_ONE_OF_EACH, NULL);
+
+  /* OneOfEach's "byte_list" member is a list that holds eight-bit-wide integer
+     values */
+  g_object_get (one_of_each, "byte_list", &byte_list, NULL);
+
+  g_assert (byte_list != NULL);
+  g_assert_cmpint (g_array_get_element_size (byte_list), ==, sizeof (gint8));
+
+  g_array_unref (byte_list);
+  g_object_unref (one_of_each);
+}
+
+static void
+test_structs_one_of_each_properties_i16_list (void)
+{
+  TTestOneOfEach *one_of_each;
+  GArray *i16_list = NULL;
+
+  one_of_each = g_object_new (T_TEST_TYPE_ONE_OF_EACH, NULL);
+
+  /* OneOfEach's "i16_list" member is a list that holds sixteen-bit-wide integer
+     values */
+  g_object_get (one_of_each, "i16_list", &i16_list, NULL);
+
+  g_assert (i16_list != NULL);
+  g_assert_cmpint (g_array_get_element_size (i16_list), ==, sizeof (gint16));
+
+  g_array_unref (i16_list);
+  g_object_unref (one_of_each);
+}
+
+static void
+test_structs_one_of_each_properties_i64_list (void)
+{
+  TTestOneOfEach *one_of_each;
+  GArray *i64_list = NULL;
+
+  one_of_each = g_object_new (T_TEST_TYPE_ONE_OF_EACH, NULL);
+
+  /* OneOfEach's "i64_list" member is a list that holds sixty-four-bit-wide
+     integer values */
+  g_object_get (one_of_each, "i64_list", &i64_list, NULL);
+
+  g_assert (i64_list != NULL);
+  g_assert_cmpint (g_array_get_element_size (i64_list), ==, sizeof (gint64));
+
+  g_array_unref (i64_list);
+  g_object_unref (one_of_each);
+}
+
+static void
+test_structs_nesting_create_and_destroy (void)
+{
+  GObject *object = NULL;
+
+  /* A Nesting structure can be created... */
+  object = g_object_new (T_TEST_TYPE_NESTING, NULL);
+
+  g_assert (object != NULL);
+  g_assert (T_TEST_IS_NESTING (object));
+
+  /* ...and destroyed */
+  g_object_unref (object);
+}
+
+static void
+test_structs_nesting_properties_my_bonk (void)
+{
+  TTestNesting *nesting;
+  TTestBonk *bonk = NULL;
+  gint type;
+  gchar *message;
+
+  nesting = g_object_new (T_TEST_TYPE_NESTING, NULL);
+
+  /* Nesting's "my_bonk" member is initialized with a new, default Bonk object
+     during construction */
+  g_object_get (nesting, "my_bonk", &bonk, NULL);
+
+  g_assert (bonk != NULL);
+  g_assert (T_TEST_IS_BONK (bonk));
+
+  g_object_get (bonk,
+                "type",    &type,
+                "message", &message,
+                NULL);
+
+  g_assert_cmpint (type, ==, 0);
+  g_assert (message == NULL);
+
+  g_object_unref (bonk);
+  bonk = NULL;
+
+  /* It can be replaced... */
+  bonk = g_object_new (T_TEST_TYPE_BONK,
+                       "type",    100,
+                       "message", "Replacement Bonk",
+                       NULL);
+  g_object_set (nesting, "my_bonk", bonk, NULL);
+  g_object_unref (bonk);
+  bonk = NULL;
+
+  g_object_get (nesting, "my_bonk", &bonk, NULL);
+
+  g_assert (bonk != NULL);
+  g_assert (T_TEST_IS_BONK (bonk));
+
+  g_object_get (bonk,
+                "type",    &type,
+                "message", &message,
+                NULL);
+
+  g_assert_cmpint (type, ==, 100);
+  g_assert_cmpstr (message, ==, "Replacement Bonk");
+
+  g_free (message);
+  g_object_unref (bonk);
+  bonk = NULL;
+
+  /* ...or set to null */
+  g_object_set (nesting, "my_bonk", NULL, NULL);
+  g_object_get (nesting, "my_bonk", &bonk, NULL);
+
+  g_assert (bonk == NULL);
+
+  g_object_unref (nesting);
+}
+
+static void
+test_structs_nesting_properties_my_ooe (void)
+{
+  TTestNesting *nesting;
+  TTestOneOfEach *one_of_each = NULL;
+  gint a_bite;
+  gint integer16;
+
+  nesting = g_object_new (T_TEST_TYPE_NESTING, NULL);
+
+  /* Nesting's "my_ooe" member is initialized with a new, default OneOfEach
+     object during construction */
+  g_object_get (nesting, "my_ooe", &one_of_each, NULL);
+
+  g_assert (one_of_each != NULL);
+  g_assert (T_TEST_IS_ONE_OF_EACH (one_of_each));
+
+  g_object_get (one_of_each,
+                "a_bite",    &a_bite,
+                "integer16", &integer16,
+                NULL);
+
+  g_assert_cmphex (a_bite,    ==, 0x7f);
+  g_assert_cmphex (integer16, ==, 0x7fff);
+
+  g_object_unref (one_of_each);
+  one_of_each = NULL;
+
+  /* It can be replaced... */
+  one_of_each = g_object_new (T_TEST_TYPE_ONE_OF_EACH,
+                              "a_bite",    0x50,
+                              "integer16", 0x5050,
+                              NULL);
+  g_object_set (nesting, "my_ooe", one_of_each, NULL);
+  g_object_unref (one_of_each);
+  one_of_each = NULL;
+
+  g_object_get (nesting, "my_ooe", &one_of_each, NULL);
 
+  g_assert (one_of_each != NULL);
+  g_assert (T_TEST_IS_ONE_OF_EACH (one_of_each));
+
+  g_object_get (one_of_each,
+                "a_bite",    &a_bite,
+                "integer16", &integer16,
+                NULL);
+
+  g_assert_cmphex (a_bite,    ==, 0x50);
+  g_assert_cmphex (integer16, ==, 0x5050);
+
+  g_object_unref (one_of_each);
+  one_of_each = NULL;
+
+  /* ...or set to null */
+  g_object_set (nesting, "my_ooe", NULL, NULL);
+  g_object_get (nesting, "my_ooe", &one_of_each, NULL);
+
+  g_assert (one_of_each == NULL);
+
+  g_object_unref (nesting);
+}
+
+static void
+test_structs_holy_moley_create_and_destroy (void)
+{
+  GObject *object = NULL;
+
+  /* A HolyMoley structure can be created... */
+  object = g_object_new (T_TEST_TYPE_HOLY_MOLEY, NULL);
+
+  g_assert (object != NULL);
+  g_assert (T_TEST_IS_HOLY_MOLEY (object));
+
+  /* ...and destroyed */
+  g_object_unref (object);
+}
+
+static void
+test_structs_holy_moley_properties_big (void)
+{
+  TTestHolyMoley *holy_moley;
+  GPtrArray *big = NULL;
+  gint a_bite = 0;
+  gint integer16 = 0;
+
+  holy_moley = g_object_new (T_TEST_TYPE_HOLY_MOLEY, NULL);
+
+  /* A HolyMoley's "big" member is is initialized on construction */
+  g_object_get (holy_moley, "big", &big, NULL);
+
+  g_assert (big != NULL);
+  g_assert_cmpint (big->len, ==, 0);
+
+  /* It can be modified... */
+  g_ptr_array_add (big,
+                   g_object_new (T_TEST_TYPE_ONE_OF_EACH,
+                                 "a_bite",    0x50,
+                                 "integer16", 0x5050,
+                                 NULL));
+
+  g_ptr_array_unref (big);
+  big = NULL;
+
+  g_object_get (holy_moley, "big", &big, NULL);
+
+  g_assert_cmpint (big->len, ==, 1);
+  g_object_get (g_ptr_array_index (big, 0),
+                "a_bite",    &a_bite,
+                "integer16", &integer16,
+                NULL);
+
+  g_assert_cmphex (a_bite,    ==, 0x50);
+  g_assert_cmphex (integer16, ==, 0x5050);
+
+  g_ptr_array_unref (big);
+  big = NULL;
+
+  /* ...replaced... */
+  big = g_ptr_array_new_with_free_func (g_object_unref);
+  g_ptr_array_add (big,
+                   g_object_new (T_TEST_TYPE_ONE_OF_EACH,
+                                 "a_bite",    0x64,
+                                 "integer16", 0x1541,
+                                 NULL));
+
+  g_object_set (holy_moley, "big", big, NULL);
+
+  g_ptr_array_unref (big);
+  big = NULL;
+
+  g_object_get (holy_moley, "big", &big, NULL);
+
+  g_assert_cmpint (big->len, ==, 1);
+  g_object_get (g_ptr_array_index (big, 0),
+                "a_bite",    &a_bite,
+                "integer16", &integer16,
+                NULL);
+
+  g_assert_cmphex (a_bite,    ==, 0x64);
+  g_assert_cmphex (integer16, ==, 0x1541);
+
+  g_ptr_array_unref (big);
+  big = NULL;
+
+  /* ...or set to NULL */
+  g_object_set (holy_moley, "big", NULL, NULL);
+  g_object_get (holy_moley, "big", &big, NULL);
+
+  g_assert (big == NULL);
+
+  g_object_unref (holy_moley);
+}
+
+static void
+test_structs_holy_moley_properties_contain (void)
+{
+  static gchar *strings[2] = { "Apache", "Thrift" };
+
+  TTestHolyMoley *holy_moley;
+  GHashTable *contain = NULL;
+  GPtrArray *string_list;
+  GList *key_list;
+
+  holy_moley = g_object_new (T_TEST_TYPE_HOLY_MOLEY, NULL);
+
+  /* A HolyMoley's "contain" member is initialized on construction */
+  g_object_get (holy_moley, "contain", &contain, NULL);
+
+  g_assert (contain != NULL);
+  g_assert_cmpint (g_hash_table_size (contain), ==, 0);
+
+  /* It can be modified... */
+  string_list = g_ptr_array_new ();
+  g_ptr_array_add (string_list, strings[0]);
+  g_ptr_array_add (string_list, strings[1]);
+
+  g_hash_table_insert (contain, string_list, NULL);
+  string_list = NULL;
+
+  g_hash_table_unref (contain);
+  contain = NULL;
+
+  g_object_get (holy_moley, "contain", &contain, NULL);
+
+  g_assert_cmpint (g_hash_table_size (contain), ==, 1);
+
+  key_list = g_hash_table_get_keys (contain);
+  string_list = g_list_nth_data (key_list, 0);
+
+  g_assert_cmpint (string_list->len, ==, 2);
+  g_assert_cmpstr (g_ptr_array_index (string_list, 0), ==, "Apache");
+  g_assert_cmpstr (g_ptr_array_index (string_list, 1), ==, "Thrift");
+
+  g_list_free (key_list);
+  g_hash_table_unref (contain);
+  contain = NULL;
+
+  /* ...replaced... */
+  contain = g_hash_table_new_full (g_direct_hash,
+                                   g_direct_equal,
+                                   (GDestroyNotify) g_ptr_array_unref,
+                                   NULL);
+  g_object_set (holy_moley, "contain", contain, NULL);
+  g_hash_table_unref (contain);
+  contain = NULL;
+
+  g_object_get (holy_moley, "contain", &contain, NULL);
+
+  g_assert_cmpint (g_hash_table_size (contain), ==, 0);
+
+  g_hash_table_unref (contain);
+  contain = NULL;
+
+  /* ...or set to NULL */
+  g_object_set (holy_moley, "contain", NULL, NULL);
+  g_object_get (holy_moley, "contain", &contain, NULL);
+
+  g_assert (contain == NULL);
+
+  g_object_unref (holy_moley);
+}
+
+static void
+test_structs_holy_moley_properties_bonks (void)
+{
+  TTestHolyMoley *holy_moley;
+  GHashTable *bonks = NULL;
+  GPtrArray *bonk_list = NULL;
   TTestBonk *bonk = NULL;
-  bonk = g_object_new (T_TEST_TYPE_BONK, NULL);
-  GPtrArray *bonks = g_ptr_array_new_with_free_func (g_object_unref);
-  g_ptr_array_add (bonks, bonk);
-  g_hash_table_insert (hm->bonks, nothing, bonks);
+  gint type;
+  gchar *message;
+  GList *key_list;
+
+  holy_moley = g_object_new (T_TEST_TYPE_HOLY_MOLEY, NULL);
+
+  /* A HolyMoley's "bonks" member is initialized on construction */
+  g_object_get (holy_moley, "bonks", &bonks, NULL);
+
+  g_assert (bonks != NULL);
+  g_assert_cmpint (g_hash_table_size (bonks), ==, 0);
+
+  /* It can be modified... */
+  bonk = g_object_new (T_TEST_TYPE_BONK,
+                       "type",    100,
+                       "message", "Sample Bonk",
+                       NULL);
+  bonk_list = g_ptr_array_new_with_free_func (g_object_unref);
+  g_ptr_array_add (bonk_list, bonk);
+  bonk = NULL;
+
+  g_hash_table_insert (bonks, g_strdup ("Sample Bonks"), bonk_list);
+  bonk_list = NULL;
+
+  g_hash_table_unref (bonks);
+  bonks = NULL;
+
+  g_object_get (holy_moley, "bonks", &bonks, NULL);
+
+  g_assert_cmpint (g_hash_table_size (bonks), ==, 1);
+
+  key_list = g_hash_table_get_keys (bonks);
+  bonk_list = g_hash_table_lookup (bonks, g_list_nth_data (key_list, 0));
+
+  g_assert_cmpint (bonk_list->len, ==, 1);
+
+  bonk = (g_ptr_array_index (bonk_list, 0));
+  g_object_get (bonk,
+                "type",    &type,
+                "message", &message,
+                NULL);
+
+  g_assert_cmpint (type, ==, 100);
+  g_assert_cmpstr (message, ==, "Sample Bonk");
+
+  bonk = NULL;
+  g_free (message);
+  g_list_free (key_list);
+  g_hash_table_unref (bonks);
+  bonks = NULL;
+
+  /* ...replaced... */
+  bonks = g_hash_table_new_full (g_str_hash,
+                                 g_str_equal,
+                                 g_free,
+                                 (GDestroyNotify) g_ptr_array_unref);
+  g_object_set (holy_moley, "bonks", bonks, NULL);
+  g_hash_table_unref (bonks);
+  bonks = NULL;
+
+  g_object_get (holy_moley, "bonks", &bonks, NULL);
+
+  g_assert_cmpint (g_hash_table_size (bonks), ==, 0);
+
+  g_hash_table_unref (bonks);
+  bonks = NULL;
+
+  /* ...or set to NULL */
+  g_object_set (holy_moley, "bonks", NULL, NULL);
+  g_object_get (holy_moley, "bonks", &bonks, NULL);
+
+  g_assert (bonks == NULL);
+
+  g_object_unref (holy_moley);
+}
+
+static void
+test_structs_empty (void)
+{
+  GObject *object = NULL;
+  GParamSpec **properties;
+  guint property_count;
+
+  /* An Empty structure can be created */
+  object = g_object_new (T_TEST_TYPE_EMPTY, NULL);
+
+  g_assert (object != NULL);
+  g_assert (T_TEST_IS_EMPTY (object));
 
-  g_object_unref (hm);
+  /* An Empty structure has no members and thus no properties */
+  properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (object),
+                                               &property_count);
+  g_assert_cmpint (property_count, ==, 0);
+  g_free (properties);
 
-  return 0;
+  /* An Empty structure can be destroyed  */
+  g_object_unref (object);
 }
 
 static void
-test_service_inheritance (void)
+test_structs_wrapper_create_and_destroy (void)
+{
+  GObject *object = NULL;
+
+  /* A Wrapper structure can be created... */
+  object = g_object_new (T_TEST_TYPE_EMPTY, NULL);
+
+  g_assert (object != NULL);
+  g_assert (T_TEST_IS_EMPTY (object));
+
+  /* ...and destroyed  */
+  g_object_unref (object);
+}
+
+static void
+test_structs_wrapper_properties_foo (void) {
+  TTestWrapper *wrapper;
+  TTestEmpty *foo;
+
+  wrapper = g_object_new (T_TEST_TYPE_WRAPPER, NULL);
+
+  /* A Wrapper structure has one member, "foo", which is an Empty
+     structure initialized during construction */
+  g_object_get (wrapper, "foo", &foo, NULL);
+
+  g_assert (foo != NULL);
+  g_assert (T_TEST_IS_EMPTY (foo));
+
+  g_object_unref (foo);
+  foo = NULL;
+
+  /* A Wrapper's foo property can be replaced... */
+  foo = g_object_new (T_TEST_TYPE_EMPTY, NULL);
+  g_object_set (wrapper, "foo", foo, NULL);
+
+  g_object_unref (foo);
+  foo = NULL;
+
+  g_object_get (wrapper, "foo", &foo, NULL);
+  g_assert (foo != NULL);
+  g_assert (T_TEST_IS_EMPTY (foo));
+
+  g_object_unref (foo);
+  foo = NULL;
+
+  /* ...or set to NULL */
+  g_object_set (wrapper, "foo", NULL, NULL);
+  g_object_get (wrapper, "foo", &foo, NULL);
+
+  g_assert (foo == NULL);
+
+  g_object_unref (wrapper);
+}
+
+static void
+test_services_inherited (void)
 {
   ThriftProtocol *protocol;
   TTestInheritedClient *inherited_client;
@@ -104,8 +841,7 @@ test_service_inheritance (void)
   assert (g_type_is_a (T_TEST_TYPE_INHERITED_CLIENT,
                        T_TEST_TYPE_SRV_IF));
 
-  /* TTestInheritedClient's inherited properties can be set and
-   * retrieved */
+  /* TTestInheritedClient's inherited properties can be set and retrieved */
   g_object_set (inherited_client,
                 "input_protocol", protocol,
                 "output_protocol", protocol,
@@ -128,14 +864,75 @@ test_service_inheritance (void)
 int
 main(int argc, char *argv[])
 {
-  g_type_init();
+#if (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 36)
+  g_type_init ();
+#endif
+
   g_test_init (&argc, &argv, NULL);
 
-  g_test_add_func ("/testdebugproto/DebugProto/Structs", test_structs);
-  g_test_add_func ("/testdebugproto/DebugProto/ServiceInheritance",
-                   test_service_inheritance);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Doubles/CreateAndDestroy",
+     test_structs_doubles_create_and_destroy);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Doubles/Initialize",
+     test_structs_doubles_initialize);
 
-  return g_test_run ();
-}
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/OneOfEach/CreateAndDestroy",
+     test_structs_one_of_each_create_and_destroy);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/OneOfEach/Initialize/DefaultValues",
+     test_structs_one_of_each_initialize_default_values);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/OneOfEach/Initialize/SpecifiedValues",
+     test_structs_one_of_each_initialize_specified_values);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/OneOfEach/Properties/byte_list",
+     test_structs_one_of_each_properties_byte_list);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/OneOfEach/Properties/i16_list",
+     test_structs_one_of_each_properties_i16_list);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/OneOfEach/Properties/i64_list",
+     test_structs_one_of_each_properties_i64_list);
+
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Nesting/CreateAndDestroy",
+     test_structs_nesting_create_and_destroy);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Nesting/Properties/my_bonk",
+     test_structs_nesting_properties_my_bonk);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Nesting/Properties/my_ooe",
+     test_structs_nesting_properties_my_ooe);
+
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/HolyMoley/CreateAndDestroy",
+     test_structs_holy_moley_create_and_destroy);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/HolyMoley/Properties/big",
+     test_structs_holy_moley_properties_big);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/HolyMoley/Properties/contain",
+     test_structs_holy_moley_properties_contain);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/HolyMoley/Properties/bonks",
+     test_structs_holy_moley_properties_bonks);
+
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Empty",
+     test_structs_empty);
 
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Wrapper/CreateAndDestroy",
+     test_structs_wrapper_create_and_destroy);
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Structs/Wrapper/Properties/foo",
+     test_structs_wrapper_properties_foo);
 
+  g_test_add_func
+    ("/testdebugproto/DebugProto/Services/Inherited",
+     test_services_inherited);
+
+  return g_test_run ();
+}


[2/2] git commit: THRIFT-976 c_glib tutorial

Posted by ro...@apache.org.
THRIFT-976 c_glib tutorial

Patch: Simon South
Signed-off-by: Roger Meier <ro...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/2814c2e7
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/2814c2e7
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/2814c2e7

Branch: refs/heads/master
Commit: 2814c2e7265ff7316cf9b2cad42827ec6df2bc47
Parents: 60b7ad6
Author: Roger Meier <ro...@apache.org>
Authored: Tue Jul 29 23:28:46 2014 +0200
Committer: Roger Meier <ro...@apache.org>
Committed: Tue Jul 29 23:28:46 2014 +0200

----------------------------------------------------------------------
 configure.ac                    |   1 +
 tutorial/Makefile.am            |   4 +
 tutorial/c_glib/Makefile.am     |  66 ++++++++++++
 tutorial/c_glib/c_glib_client.c | 190 +++++++++++++++++++++++++++++++++++
 4 files changed, 261 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/2814c2e7/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 5af20de..bccfc69 100755
--- a/configure.ac
+++ b/configure.ac
@@ -663,6 +663,7 @@ AC_CONFIG_FILES([
   test/py.tornado/Makefile
   test/rb/Makefile
   tutorial/Makefile
+  tutorial/c_glib/Makefile
   tutorial/cpp/Makefile
   tutorial/go/Makefile
   tutorial/hs/Makefile

http://git-wip-us.apache.org/repos/asf/thrift/blob/2814c2e7/tutorial/Makefile.am
----------------------------------------------------------------------
diff --git a/tutorial/Makefile.am b/tutorial/Makefile.am
index f3fd1dd..2b9be52 100755
--- a/tutorial/Makefile.am
+++ b/tutorial/Makefile.am
@@ -23,6 +23,10 @@ if MINGW
 # do nothing, just build the compiler
 else
 
+if WITH_C_GLIB
+SUBDIRS += c_glib
+endif
+
 if WITH_CPP
 SUBDIRS += cpp
 endif

http://git-wip-us.apache.org/repos/asf/thrift/blob/2814c2e7/tutorial/c_glib/Makefile.am
----------------------------------------------------------------------
diff --git a/tutorial/c_glib/Makefile.am b/tutorial/c_glib/Makefile.am
new file mode 100755
index 0000000..33d6c93
--- /dev/null
+++ b/tutorial/c_glib/Makefile.am
@@ -0,0 +1,66 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+AM_CFLAGS = -g -Wall -Wextra $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) @GCOV_CFLAGS@
+AM_CPPFLAGS = -I$(top_srcdir)/lib/c_glib/src -Igen-c_glib
+AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS) @GCOV_LDFLAGS@
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+
+.NOTPARALLEL:
+noinst_LTLIBRARIES = \
+	libtutorialgencglib.la
+
+nodist_libtutorialgencglib_la_SOURCES = \
+	gen-c_glib/calculator.c \
+	gen-c_glib/calculator.h \
+	gen-c_glib/shared_service.c \
+	gen-c_glib/shared_service.h \
+	gen-c_glib/shared_types.c \
+	gen-c_glib/shared_types.h \
+	gen-c_glib/tutorial_types.c \
+	gen-c_glib/tutorial_types.h
+
+libtutorialgencglib_la_LIBADD = \
+	$(top_builddir)/lib/c_glib/libthrift_c_glib.la
+
+
+noinst_PROGRAMS = \
+	tutorial_client
+
+tutorial_client_SOURCES = \
+	c_glib_client.c
+
+tutorial_client_LDADD = \
+	libtutorialgencglib.la \
+	$(top_builddir)/lib/c_glib/libthrift_c_glib.la
+
+
+$(nodist_libtutorialgencglib_la_SOURCES): $(top_srcdir)/tutorial/tutorial.thrift
+	$(THRIFT) --gen c_glib -r $<
+
+clean-local:
+	$(RM) -r gen-c_glib
+
+tutorialclient: all
+	./tutorial_client
+
+EXTRA_DIST = \
+	c_glib_client.c

http://git-wip-us.apache.org/repos/asf/thrift/blob/2814c2e7/tutorial/c_glib/c_glib_client.c
----------------------------------------------------------------------
diff --git a/tutorial/c_glib/c_glib_client.c b/tutorial/c_glib/c_glib_client.c
new file mode 100644
index 0000000..d3f2a34
--- /dev/null
+++ b/tutorial/c_glib/c_glib_client.c
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdio.h>
+#include <glib-object.h>
+
+#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
+#include <thrift/c_glib/transport/thrift_buffered_transport.h>
+#include <thrift/c_glib/transport/thrift_socket.h>
+
+#include "gen-c_glib/calculator.h"
+
+int main (void) {
+  ThriftSocket *socket;
+  ThriftTransport *transport;
+  ThriftProtocol *protocol;
+  CalculatorClient *client;
+  CalculatorIf *iface;
+
+  GError *error = NULL;
+  InvalidOperation *invalid_operation = NULL;
+
+  Work *work;
+
+  gint32 sum;
+  gint32 diff;
+
+  int exit_status = 0;
+
+  socket = g_object_new (THRIFT_TYPE_SOCKET,
+                         "hostname", "localhost",
+                         "port", 9090,
+                         NULL);
+  transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
+                            "transport", socket,
+                            NULL);
+  protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
+                           "transport", transport,
+                           NULL);
+
+  thrift_transport_open (transport, &error);
+
+
+  /* In the C (GLib) implementation of Thrift, service methods on the
+     server are accessed via a generated client class that implements
+     the service interface. In this tutorial, we access a Calculator
+     service through an instance of CalculatorClient, which implements
+     CalculatorIf. */
+  client = g_object_new (TYPE_CALCULATOR_CLIENT,
+                         "input_protocol", protocol,
+                         "output_protocol", protocol,
+                         NULL);
+  iface = CALCULATOR_IF (client);
+
+  /* Each of the client methods requires at least two parameters: A
+     pointer to the client-interface implementation (the client
+     object), and a handle to a GError structure to receive
+     information about any error that occurs.
+
+     On success, client methods return TRUE. A return value of FALSE
+     indicates an error occured and the error parameter has been
+     set. */
+  if (!error && calculator_client_ping (iface, &error)) {
+    puts ("ping()");
+  }
+
+  /* Service methods that return a value do so by passing the result
+     back via an output parameter (here, "sum"). */
+  if (!error && calculator_client_add (iface, &sum, 1, 1, &error)) {
+    printf ("1+1=%d\n", sum);
+  }
+
+  /* Thrift structs are implemented as GObjects, with each of the
+     struct's members exposed as an object property. */
+  work = g_object_new (TYPE_WORK, NULL);
+
+  if (!error) {
+    g_object_set (work,
+                  "num1", 1,
+                  "num2", 0,
+                  "op",   OPERATION_DIVIDE,
+                  NULL);
+
+    /* Exceptions are passed back from service methods in a manner
+       similar to return values. */
+    if (calculator_client_calculate (iface,
+                                     NULL,
+                                     1,
+                                     work,
+                                     &invalid_operation,
+                                     &error)) {
+      puts ("Whoa? We can divide by zero!");
+    }
+    else {
+      if (invalid_operation) {
+        gchar *why;
+
+        /* Like structs, exceptions are implemented as objects with
+           properties. */
+        g_object_get (invalid_operation, "why", &why, NULL);
+
+        printf ("InvalidOperation: %s\n", why);
+
+        if (why != NULL)
+          g_free (why);
+        g_object_unref (invalid_operation);
+        invalid_operation = NULL;
+      }
+
+      g_error_free (error);
+      error = NULL;
+    }
+  }
+
+  if (!error) {
+    /* Struct objects can be reused across method invocations. */
+    g_object_set (work,
+                  "num1", 15,
+                  "num2", 10,
+                  "op",   OPERATION_SUBTRACT,
+                  NULL);
+
+    if (calculator_client_calculate (iface,
+                                     &diff,
+                                     1,
+                                     work,
+                                     &invalid_operation,
+                                     &error)) {
+      printf ("15-10=%d\n", diff);
+    }
+  }
+
+  g_object_unref (work);
+
+  if (!error) {
+    SharedStruct *shared_struct;
+    gchar *value;
+
+    shared_struct = g_object_new (TYPE_SHARED_STRUCT, NULL);
+
+    /* As defined in the Thrift file, the Calculator service extends
+       the SharedService service. Correspondingly, in the generated
+       code CalculatorClient inherits from SharedServiceClient, and
+       the parent service's methods are accessible through a simple
+       cast. */
+     if (shared_service_client_get_struct (SHARED_SERVICE_IF (iface),
+                                          &shared_struct,
+                                          1,
+                                          &error)) {
+      g_object_get (shared_struct, "value", &value, NULL);
+      printf ("Check log: %s\n", value);
+      g_free (value);
+    }
+
+    g_object_unref (shared_struct);
+  }
+
+  if (error) {
+    printf ("ERROR: %s\n", error->message);
+    g_error_free (error);
+    error = NULL;
+
+    exit_status = 1;
+  }
+
+  thrift_transport_close (transport, NULL);
+
+  g_object_unref (client);
+  g_object_unref (protocol);
+  g_object_unref (transport);
+  g_object_unref (socket);
+
+  return exit_status;
+}