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 2010/11/26 11:17:50 UTC

svn commit: r1039299 [2/3] - in /thrift/trunk: ./ lib/c_glib/ lib/c_glib/src/ lib/c_glib/src/processor/ lib/c_glib/src/protocol/ lib/c_glib/src/server/ lib/c_glib/src/transport/ lib/c_glib/test/

Modified: thrift/trunk/lib/c_glib/src/thrift_struct.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/thrift_struct.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/thrift_struct.c (original)
+++ thrift/trunk/lib/c_glib/src/thrift_struct.c Fri Nov 26 10:17:48 2010
@@ -1,41 +1,26 @@
-#include "thrift_struct.h"
+/*
+ * 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.
+ */
 
-static void
-thrift_struct_class_init (ThriftStructClass *cls)
-{
-  ThriftStructClass *c = THRIFT_STRUCT_CLASS (cls);
-  c->read = thrift_struct_read;
-  c->write = thrift_struct_write;
-}
-
-GType
-thrift_struct_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo type_info =
-      {
-        sizeof (ThriftStructClass),
-        NULL, /* base_init */
-        NULL, /* base finalize */
-        (GClassInitFunc) thrift_struct_class_init,
-        NULL, /* class finalize */
-        NULL, /* class data */
-        sizeof (ThriftStruct),
-        0, /* n_preallocs */
-        NULL, /* instance_init */
-        NULL, /* value_table */
-      };
-
-    type = g_type_register_static (G_TYPE_OBJECT,
-                                   "ThriftStructType",
-                                   &type_info, G_TYPE_FLAG_ABSTRACT);
-  }
+#include "thrift.h"
+#include "thrift_struct.h"
 
-  return type;
-}
+G_DEFINE_ABSTRACT_TYPE(ThriftStruct, thrift_struct, G_TYPE_OBJECT)
 
 gint32
 thrift_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
@@ -53,3 +38,15 @@ thrift_struct_write (ThriftStruct *objec
   return THRIFT_STRUCT_GET_CLASS (object)->write (object, protocol, error);
 }
 
+static void
+thrift_struct_class_init (ThriftStructClass *cls)
+{
+  cls->read = thrift_struct_read;
+  cls->write = thrift_struct_write;
+}
+
+static void
+thrift_struct_init (ThriftStruct *structure)
+{
+  THRIFT_UNUSED_VAR (structure);
+}

Modified: thrift/trunk/lib/c_glib/src/thrift_struct.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/thrift_struct.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/thrift_struct.h (original)
+++ thrift/trunk/lib/c_glib/src/thrift_struct.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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.
+ */
+
 #ifndef THRIFT_STRUCT_H
 #define THRIFT_STRUCT_H
 
@@ -5,18 +24,14 @@
 
 #include "protocol/thrift_protocol.h"
 
+G_BEGIN_DECLS
+
 #define THRIFT_TYPE_STRUCT (thrift_struct_get_type ())
-#define THRIFT_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                THRIFT_TYPE_STRUCT, ThriftStruct))
-#define THRIFT_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                    THRIFT_TYPE_STRUCT, ThriftStructClass))
-#define THRIFT_IS_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                    THRIFT_TYPE_STRUCT))
-#define THRIFT_IS_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                       THRIFT_TYPE_STRUCT))
-#define THRIFT_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-                                          THRIFT_TYPE_STRUCT, \
-                                          ThriftStructClass))
+#define THRIFT_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_STRUCT, ThriftStruct))
+#define THRIFT_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_STRUCT, ThriftStructClass))
+#define THRIFT_IS_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_STRUCT))
+#define THRIFT_IS_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_STRUCT))
+#define THRIFT_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_STRUCT, ThriftStructClass))
 
 /* struct */
 struct _ThriftStruct
@@ -46,5 +61,6 @@ gint32 thrift_struct_read (ThriftStruct 
 
 gint32 thrift_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
                             GError **error);
+G_END_DECLS
 
 #endif

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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 <assert.h>
 #include <netdb.h>
 #include <stdlib.h>
@@ -18,190 +37,7 @@ enum _ThriftBufferedTransportProperties
   PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE
 };
 
-/* forward declarations */
-static void thrift_buffered_transport_instance_init (ThriftBufferedTransport *self);
-static void thrift_buffered_transport_class_init (ThriftBufferedTransportClass *cls);
-
-
-gboolean thrift_buffered_transport_is_open (ThriftTransport *transport);
-gboolean thrift_buffered_transport_open (ThriftTransport *transport,
-                                         GError **error);
-gboolean thrift_buffered_transport_close (ThriftTransport *transport,
-                                          GError **error);
-gint32 thrift_buffered_transport_read (ThriftTransport *transport, gpointer buf,
-                                       guint32 len, GError **error);
-gboolean thrift_buffered_transport_read_end (ThriftTransport *transport,
-                                             GError **error);
-gint32 thrift_buffered_transport_read_slow (ThriftTransport *transport,
-                                            gpointer buf, guint32 len,
-                                            GError **error);
-gboolean thrift_buffered_transport_write (ThriftTransport *transport,
-                                          const gpointer buf,
-                                          const guint32 len, GError **error);
-gboolean thrift_buffered_transport_write_end (ThriftTransport *transport,
-                                              GError **error);
-gint32 thrift_buffered_transport_write_slow (ThriftTransport *transport, 
-                                             gpointer buf, guint32 len, 
-                                             GError **error);
-gboolean thrift_buffered_transport_flush (ThriftTransport *transport,
-                                          GError **error);
-
-GType
-thrift_buffered_transport_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info =
-    {
-      sizeof (ThriftBufferedTransportClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_buffered_transport_class_init,
-      NULL, /* class finalize */
-      NULL, /* class data */
-      sizeof (ThriftBufferedTransport),
-      0, /* n_preallocs */
-      (GInstanceInitFunc) thrift_buffered_transport_instance_init,
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (THRIFT_TYPE_TRANSPORT,
-                                   "ThriftBufferedTransport", &info, 0);
-  }
-
-  return type;
-}
-
-/* initializes the instance */
-static void
-thrift_buffered_transport_instance_init (ThriftBufferedTransport *transport)
-{
-  transport->transport = NULL;
-  transport->r_buf = g_byte_array_new ();
-  transport->w_buf = g_byte_array_new ();
-}
-
-/* destructor */
-static void
-thrift_buffered_transport_finalize (GObject *object)
-{
-  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
-
-  if (transport->r_buf != NULL)
-  {
-    g_byte_array_free (transport->r_buf, TRUE);
-  }
-  transport->r_buf = NULL;
-
-  if (transport->w_buf != NULL)
-  {
-    g_byte_array_free (transport->w_buf, TRUE);
-  }
-  transport->w_buf = NULL;
-}
-
-/* property accessor */
-void
-thrift_buffered_transport_get_property (GObject *object, guint property_id,
-                                        GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
-      g_value_set_object (value, transport->transport);
-      break;
-    case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
-      g_value_set_uint (value, transport->r_buf_size);
-      break;
-    case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
-      g_value_set_uint (value, transport->w_buf_size);
-      break;
-  }
-}
-
-/* property mutator */
-void
-thrift_buffered_transport_set_property (GObject *object, guint property_id,
-                                        const GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
-      transport->transport = g_value_get_object (value);
-      break;
-    case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
-      transport->r_buf_size = g_value_get_uint (value);
-      break;
-    case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
-      transport->w_buf_size = g_value_get_uint (value);
-      break;
-  }
-}
-
-/* initializes the class */
-static void
-thrift_buffered_transport_class_init (ThriftBufferedTransportClass *cls)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
-  GParamSpec *param_spec = NULL;
-
-  /* setup accessors and mutators */
-  gobject_class->get_property = thrift_buffered_transport_get_property;
-  gobject_class->set_property = thrift_buffered_transport_set_property;
-
-  param_spec = g_param_spec_object ("transport", "transport (construct)",
-                                    "Thrift transport",
-                                    THRIFT_TYPE_TRANSPORT,
-                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-  g_object_class_install_property (gobject_class,
-                                   PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT,
-                                   param_spec);
-
-  param_spec = g_param_spec_uint ("r_buf_size",
-                                  "read buffer size (construct)",
-                                  "Set the read buffer size",
-                                  0, /* min */
-                                  1048576, /* max, 1024*1024 */
-                                  512, /* default value */
-                                  G_PARAM_CONSTRUCT_ONLY |
-                                  G_PARAM_READWRITE);
-  g_object_class_install_property (gobject_class,
-                                   PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE,
-                                   param_spec);
-
-  param_spec = g_param_spec_uint ("w_buf_size",
-                                  "write buffer size (construct)",
-                                  "Set the write buffer size",
-                                  0, /* min */
-                                  1048576, /* max, 1024*1024 */
-                                  512, /* default value */
-                                  G_PARAM_CONSTRUCT_ONLY |
-                                  G_PARAM_READWRITE);
-  g_object_class_install_property (gobject_class,
-                                   PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE,
-                                   param_spec);
-
-
-  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
-
-  gobject_class->finalize = thrift_buffered_transport_finalize;
-  ttc->is_open = thrift_buffered_transport_is_open;
-  ttc->open = thrift_buffered_transport_open;
-  ttc->close = thrift_buffered_transport_close;
-  ttc->read = thrift_buffered_transport_read;
-  ttc->read_end = thrift_buffered_transport_read_end;
-  ttc->write = thrift_buffered_transport_write;
-  ttc->write_end = thrift_buffered_transport_write_end;
-  ttc->flush = thrift_buffered_transport_flush;
-}
+G_DEFINE_TYPE(ThriftBufferedTransport, thrift_buffered_transport, THRIFT_TYPE_TRANSPORT)
 
 /* implements thrift_transport_is_open */
 gboolean
@@ -227,36 +63,6 @@ thrift_buffered_transport_close (ThriftT
   return THRIFT_TRANSPORT_GET_CLASS (t->transport)->close (t->transport, error);
 }
 
-/* implements thrift_transport_read */
-gint32
-thrift_buffered_transport_read (ThriftTransport *transport, gpointer buf,
-                                guint32 len, GError **error)
-{
-  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
-
-  /* if we have enough buffer data to fulfill the read, just use
-   * a memcpy */
-  if (len <= t->r_buf->len)
-  {
-    memcpy (buf, t->r_buf->data, len);
-    g_byte_array_remove_range (t->r_buf, 0, len);
-    return len;
-  }
-
-  return thrift_buffered_transport_read_slow (transport, buf, len, error);
-}
-
-/* implements thrift_transport_read_end
- * called when write is complete.  nothing to do on our end. */
-gboolean
-thrift_buffered_transport_read_end (ThriftTransport *transport, GError **error)
-{
-  /* satisfy -Wall */
-  THRIFT_UNUSED_VAR (transport);
-  THRIFT_UNUSED_VAR (error);
-  return TRUE;
-}
-
 /* the actual read is "slow" because it calls the underlying transport */
 gint32
 thrift_buffered_transport_read_slow (ThriftTransport *transport, gpointer buf,
@@ -311,29 +117,29 @@ thrift_buffered_transport_read_slow (Thr
   }
 }
 
-
-/* implements thrift_transport_write */
-gboolean
-thrift_buffered_transport_write (ThriftTransport *transport,
-                                 const gpointer buf,     
-                                 const guint32 len, GError **error)
+/* implements thrift_transport_read */
+gint32
+thrift_buffered_transport_read (ThriftTransport *transport, gpointer buf,
+                                guint32 len, GError **error)
 {
   ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
 
-  /* the length of the current buffer plus the length of the data being read */
-  if (t->w_buf->len + len <= t->w_buf_size)
+  /* if we have enough buffer data to fulfill the read, just use
+   * a memcpy */
+  if (len <= t->r_buf->len)
   {
-    t->w_buf = g_byte_array_append (t->w_buf, buf, len);
+    memcpy (buf, t->r_buf->data, len);
+    g_byte_array_remove_range (t->r_buf, 0, len);
     return len;
   }
 
-  return thrift_buffered_transport_write_slow (transport, buf, len, error);
+  return thrift_buffered_transport_read_slow (transport, buf, len, error);
 }
 
-/* implements thrift_transport_write_end
+/* implements thrift_transport_read_end
  * called when write is complete.  nothing to do on our end. */
 gboolean
-thrift_buffered_transport_write_end (ThriftTransport *transport, GError **error)
+thrift_buffered_transport_read_end (ThriftTransport *transport, GError **error)
 {
   /* satisfy -Wall */
   THRIFT_UNUSED_VAR (transport);
@@ -382,6 +188,35 @@ thrift_buffered_transport_write_slow (Th
   return TRUE;
 }
 
+/* implements thrift_transport_write */
+gboolean
+thrift_buffered_transport_write (ThriftTransport *transport,
+                                 const gpointer buf,
+                                 const guint32 len, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+
+  /* the length of the current buffer plus the length of the data being read */
+  if (t->w_buf->len + len <= t->w_buf_size)
+  {
+    t->w_buf = g_byte_array_append (t->w_buf, buf, len);
+    return len;
+  }
+
+  return thrift_buffered_transport_write_slow (transport, buf, len, error);
+}
+
+/* implements thrift_transport_write_end
+ * called when write is complete.  nothing to do on our end. */
+gboolean
+thrift_buffered_transport_write_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
 /* implements thrift_transport_flush */
 gboolean
 thrift_buffered_transport_flush (ThriftTransport *transport, GError **error)
@@ -403,4 +238,131 @@ thrift_buffered_transport_flush (ThriftT
   return TRUE;
 }
 
+/* initializes the instance */
+static void
+thrift_buffered_transport_init (ThriftBufferedTransport *transport)
+{
+  transport->transport = NULL;
+  transport->r_buf = g_byte_array_new ();
+  transport->w_buf = g_byte_array_new ();
+}
+
+/* destructor */
+static void
+thrift_buffered_transport_finalize (GObject *object)
+{
+  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
+
+  if (transport->r_buf != NULL)
+  {
+    g_byte_array_free (transport->r_buf, TRUE);
+  }
+  transport->r_buf = NULL;
+
+  if (transport->w_buf != NULL)
+  {
+    g_byte_array_free (transport->w_buf, TRUE);
+  }
+  transport->w_buf = NULL;
+}
+
+/* property accessor */
+void
+thrift_buffered_transport_get_property (GObject *object, guint property_id,
+                                        GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
+      g_value_set_object (value, transport->transport);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
+      g_value_set_uint (value, transport->r_buf_size);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
+      g_value_set_uint (value, transport->w_buf_size);
+      break;
+  }
+}
+
+/* property mutator */
+void
+thrift_buffered_transport_set_property (GObject *object, guint property_id,
+                                        const GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
+      transport->transport = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
+      transport->r_buf_size = g_value_get_uint (value);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
+      transport->w_buf_size = g_value_get_uint (value);
+      break;
+  }
+}
+
+/* initializes the class */
+static void
+thrift_buffered_transport_class_init (ThriftBufferedTransportClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+  GParamSpec *param_spec = NULL;
+
+  /* setup accessors and mutators */
+  gobject_class->get_property = thrift_buffered_transport_get_property;
+  gobject_class->set_property = thrift_buffered_transport_set_property;
+
+  param_spec = g_param_spec_object ("transport", "transport (construct)",
+                                    "Thrift transport",
+                                    THRIFT_TYPE_TRANSPORT,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("r_buf_size",
+                                  "read buffer size (construct)",
+                                  "Set the read buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE,
+                                   param_spec);
 
+  param_spec = g_param_spec_uint ("w_buf_size",
+                                  "write buffer size (construct)",
+                                  "Set the write buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE,
+                                   param_spec);
+
+
+  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
+
+  gobject_class->finalize = thrift_buffered_transport_finalize;
+  ttc->is_open = thrift_buffered_transport_is_open;
+  ttc->open = thrift_buffered_transport_open;
+  ttc->close = thrift_buffered_transport_close;
+  ttc->read = thrift_buffered_transport_read;
+  ttc->read_end = thrift_buffered_transport_read_end;
+  ttc->write = thrift_buffered_transport_write;
+  ttc->write_end = thrift_buffered_transport_write_end;
+  ttc->flush = thrift_buffered_transport_flush;
+}

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_buffered_transport.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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.
+ */
+
 #ifndef _THRIFT_BUFFERED_TRANSPORT_H
 #define _THRIFT_BUFFERED_TRANSPORT_H
 
@@ -6,27 +25,20 @@
 
 #include "transport/thrift_transport.h"
 
+G_BEGIN_DECLS
+
 /*! \file thrift_buffered_transport.h
- *  \brief Implementation of a Thrift buffered transport.  Subclasses 
+ *  \brief Implementation of a Thrift buffered transport.  Subclasses
  *         the ThriftTransport class.
  */
 
 /* type macros */
 #define THRIFT_TYPE_BUFFERED_TRANSPORT (thrift_buffered_transport_get_type ())
-#define THRIFT_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                        THRIFT_TYPE_BUFFERED_TRANSPORT, \
-                                        ThriftBufferedTransport))
-#define THRIFT_IS_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                           THRIFT_TYPE_BUFFERED_TRANSPORT))
-#define THRIFT_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                            THRIFT_TYPE_BUFFERED_TRANSPORT, \
-                                            ThriftBufferedTransportClass))
-#define THRIFT_IS_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                               THRIFT_TYPE_BUFFERED_TRANSPORT)
-#define THRIFT_BUFFERED_TRANSPORT_GET_CLASS(obj) \
-            (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-             THRIFT_TYPE_BUFFERED_TRANSPORT, \
-             ThriftBufferedTransportClass))
+#define THRIFT_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransport))
+#define THRIFT_IS_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT))
+#define THRIFT_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransportClass))
+#define THRIFT_IS_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_BUFFERED_TRANSPORT)
+#define THRIFT_BUFFERED_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransportClass))
 
 /*!
  * ThriftBufferedTransport  instance.
@@ -58,4 +70,6 @@ typedef struct _ThriftBufferedTransportC
 /* used by THRIFT_TYPE_BUFFERED_TRANSPORT */
 GType thrift_buffered_transport_get_type (void);
 
+G_END_DECLS
+
 #endif

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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 <assert.h>
 #include <netdb.h>
 #include <stdlib.h>
@@ -18,192 +37,7 @@ enum _ThriftFramedTransportProperties
   PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE
 };
 
-/* forward declarations */
-static void thrift_framed_transport_instance_init (ThriftFramedTransport *self);
-static void thrift_framed_transport_class_init (ThriftFramedTransportClass *cls);
-
-
-gboolean thrift_framed_transport_is_open (ThriftTransport *transport);
-gboolean thrift_framed_transport_open (ThriftTransport *transport,
-                                       GError **error);
-gboolean thrift_framed_transport_close (ThriftTransport *transport,
-                                        GError **error);
-gint32 thrift_framed_transport_read (ThriftTransport *transport, gpointer buf,
-                                     guint32 len, GError **error);
-gboolean thrift_framed_transport_read_end (ThriftTransport *transport,
-                                           GError **error);
-gint32 thrift_framed_transport_read_slow (ThriftTransport *transport,
-                                          gpointer buf, guint32 len,
-                                          GError **error);
-gboolean thrift_framed_transport_read_frame (ThriftTransport *transport,
-                                             GError **error);
-gboolean thrift_framed_transport_write (ThriftTransport *transport,
-                                        const gpointer buf,
-                                        const guint32 len, GError **error);
-gboolean thrift_framed_transport_write_end (ThriftTransport *transport,
-                                            GError **error);
-gint32 thrift_framed_transport_write_slow (ThriftTransport *transport, 
-                                           gpointer buf, guint32 len, 
-                                           GError **error);
-gboolean thrift_framed_transport_flush (ThriftTransport *transport,
-                                        GError **error);
-
-GType
-thrift_framed_transport_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info =
-    {
-      sizeof (ThriftFramedTransportClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_framed_transport_class_init,
-      NULL, /* class finalize */
-      NULL, /* class data */
-      sizeof (ThriftFramedTransport),
-      0, /* n_preallocs */
-      (GInstanceInitFunc) thrift_framed_transport_instance_init,
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (THRIFT_TYPE_TRANSPORT,
-                                   "ThriftFramedTransport", &info, 0);
-  }
-
-  return type;
-}
-
-/* initializes the instance */
-static void
-thrift_framed_transport_instance_init (ThriftFramedTransport *transport)
-{
-  transport->transport = NULL;
-  transport->r_buf = g_byte_array_new ();
-  transport->w_buf = g_byte_array_new ();
-}
-
-/* destructor */
-static void
-thrift_framed_transport_finalize (GObject *object)
-{
-  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
-
-  if (transport->r_buf != NULL)
-  {
-    g_byte_array_free (transport->r_buf, TRUE);
-  }
-  transport->r_buf = NULL;
-
-  if (transport->w_buf != NULL)
-  {
-    g_byte_array_free (transport->w_buf, TRUE);
-  }
-  transport->w_buf = NULL;
-}
-
-/* property accessor */
-void
-thrift_framed_transport_get_property (GObject *object, guint property_id,
-                                      GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
-      g_value_set_object (value, transport->transport);
-      break;
-    case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
-      g_value_set_uint (value, transport->r_buf_size);
-      break;
-    case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
-      g_value_set_uint (value, transport->w_buf_size);
-      break;
-  }
-}
-
-/* property mutator */
-void
-thrift_framed_transport_set_property (GObject *object, guint property_id,
-                                      const GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
-      transport->transport = g_value_get_object (value);
-      break;
-    case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
-      transport->r_buf_size = g_value_get_uint (value);
-      break;
-    case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
-      transport->w_buf_size = g_value_get_uint (value);
-      break;
-  }
-}
-
-/* initializes the class */
-static void
-thrift_framed_transport_class_init (ThriftFramedTransportClass *cls)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
-  GParamSpec *param_spec = NULL;
-
-  /* setup accessors and mutators */
-  gobject_class->get_property = thrift_framed_transport_get_property;
-  gobject_class->set_property = thrift_framed_transport_set_property;
-
-  param_spec = g_param_spec_object ("transport", "transport (construct)",
-                                    "Thrift transport",
-                                    THRIFT_TYPE_TRANSPORT,
-                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-  g_object_class_install_property (gobject_class,
-                                   PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT,
-                                   param_spec);
-
-  param_spec = g_param_spec_uint ("r_buf_size",
-                                  "read buffer size (construct)",
-                                  "Set the read buffer size",
-                                  0, /* min */
-                                  1048576, /* max, 1024*1024 */
-                                  512, /* default value */
-                                  G_PARAM_CONSTRUCT_ONLY |
-                                  G_PARAM_READWRITE);
-  g_object_class_install_property (gobject_class,
-                                   PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE,
-                                   param_spec);
-
-  param_spec = g_param_spec_uint ("w_buf_size",
-                                  "write buffer size (construct)",
-                                  "Set the write buffer size",
-                                  0, /* min */
-                                  1048576, /* max, 1024*1024 */
-                                  512, /* default value */
-                                  G_PARAM_CONSTRUCT_ONLY |
-                                  G_PARAM_READWRITE);
-  g_object_class_install_property (gobject_class,
-                                   PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE,
-                                   param_spec);
-
-
-  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
-
-  gobject_class->finalize = thrift_framed_transport_finalize;
-  ttc->is_open = thrift_framed_transport_is_open;
-  ttc->open = thrift_framed_transport_open;
-  ttc->close = thrift_framed_transport_close;
-  ttc->read = thrift_framed_transport_read;
-  ttc->read_end = thrift_framed_transport_read_end;
-  ttc->write = thrift_framed_transport_write;
-  ttc->write_end = thrift_framed_transport_write_end;
-  ttc->flush = thrift_framed_transport_flush;
-}
+G_DEFINE_TYPE(ThriftFramedTransport, thrift_framed_transport, THRIFT_TYPE_TRANSPORT)
 
 /* implements thrift_transport_is_open */
 gboolean
@@ -229,33 +63,30 @@ thrift_framed_transport_close (ThriftTra
   return THRIFT_TRANSPORT_GET_CLASS (t->transport)->close (t->transport, error);
 }
 
-/* implements thrift_transport_read */
-gint32
-thrift_framed_transport_read (ThriftTransport *transport, gpointer buf,
-                              guint32 len, GError **error)
+/* reads a frame and puts it into the buffer */
+gboolean
+thrift_framed_transport_read_frame (ThriftTransport *transport,
+                                    GError **error)
 {
   ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+  gint32 sz, bytes;
 
-  /* if we have enough buffer data to fulfill the read, just use
-   * a memcpy from the buffer */
-  if (len <= t->r_buf->len)
-  {
-    memcpy (buf, t->r_buf->data, len);
-    g_byte_array_remove_range (t->r_buf, 0, len);
-    return len;
-  }
+  /* read the size */
+  THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
+                                                   (guint32 *) &sz,
+                                                   sizeof (sz), error);
+  sz = ntohl (sz);
 
-  return thrift_framed_transport_read_slow (transport, buf, len, error);
-}
+  /* create a buffer to hold the data and read that much data */
+  guchar tmpdata[sz];
+  bytes = THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
+                                                           tmpdata,
+                                                           sz - sizeof (sz),
+                                                           error);
+
+  /* add the data to the buffer */
+  g_byte_array_append (t->r_buf, tmpdata, bytes);
 
-/* implements thrift_transport_read_end
- * called when read is complete.  nothing to do on our end. */
-gboolean
-thrift_framed_transport_read_end (ThriftTransport *transport, GError **error)
-{
-  /* satisfy -Wall */
-  THRIFT_UNUSED_VAR (transport);
-  THRIFT_UNUSED_VAR (error);
   return TRUE;
 }
 
@@ -293,29 +124,45 @@ thrift_framed_transport_read_slow (Thrif
   return (len - want);
 }
 
-/* reads a frame and puts it into the buffer */
-gboolean
-thrift_framed_transport_read_frame (ThriftTransport *transport,
-                                    GError **error)
+/* implements thrift_transport_read */
+gint32
+thrift_framed_transport_read (ThriftTransport *transport, gpointer buf,
+                              guint32 len, GError **error)
 {
   ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
-  gint32 sz, bytes;
 
-  /* read the size */
-  THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
-                                                   (guint32 *) &sz,
-                                                   sizeof (sz), error);
-  sz = ntohl (sz);
+  /* if we have enough buffer data to fulfill the read, just use
+   * a memcpy from the buffer */
+  if (len <= t->r_buf->len)
+  {
+    memcpy (buf, t->r_buf->data, len);
+    g_byte_array_remove_range (t->r_buf, 0, len);
+    return len;
+  }
 
-  /* create a buffer to hold the data and read that much data */
-  guchar tmpdata[sz];
-  bytes = THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
-                                                           tmpdata,
-                                                           sz - sizeof (sz),
-                                                           error);
+  return thrift_framed_transport_read_slow (transport, buf, len, error);
+}
 
-  /* add the data to the buffer */
-  g_byte_array_append (t->r_buf, tmpdata, bytes);
+/* implements thrift_transport_read_end
+ * called when read is complete.  nothing to do on our end. */
+gboolean
+thrift_framed_transport_read_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+gboolean
+thrift_framed_transport_write_slow (ThriftTransport *transport, gpointer buf,
+                                    guint32 len, GError **error)
+{
+  THRIFT_UNUSED_VAR (error);
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+
+  // append the data to the buffer and we're done
+  g_byte_array_append (t->w_buf, buf, len);
 
   return TRUE;
 }
@@ -349,19 +196,6 @@ thrift_framed_transport_write_end (Thrif
   return TRUE;
 }
 
-gboolean
-thrift_framed_transport_write_slow (ThriftTransport *transport, gpointer buf,
-                                    guint32 len, GError **error)
-{
-  THRIFT_UNUSED_VAR (error);
-  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
-
-  // append the data to the buffer and we're done
-  g_byte_array_append (t->w_buf, buf, len);
-
-  return TRUE;
-}
-
 /* implements thrift_transport_flush */
 gboolean
 thrift_framed_transport_flush (ThriftTransport *transport, GError **error)
@@ -394,4 +228,131 @@ thrift_framed_transport_flush (ThriftTra
   return TRUE;
 }
 
+/* initializes the instance */
+static void
+thrift_framed_transport_init (ThriftFramedTransport *transport)
+{
+  transport->transport = NULL;
+  transport->r_buf = g_byte_array_new ();
+  transport->w_buf = g_byte_array_new ();
+}
+
+/* destructor */
+static void
+thrift_framed_transport_finalize (GObject *object)
+{
+  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
+
+  if (transport->r_buf != NULL)
+  {
+    g_byte_array_free (transport->r_buf, TRUE);
+  }
+  transport->r_buf = NULL;
+
+  if (transport->w_buf != NULL)
+  {
+    g_byte_array_free (transport->w_buf, TRUE);
+  }
+  transport->w_buf = NULL;
+}
+
+/* property accessor */
+void
+thrift_framed_transport_get_property (GObject *object, guint property_id,
+                                      GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
+      g_value_set_object (value, transport->transport);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
+      g_value_set_uint (value, transport->r_buf_size);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
+      g_value_set_uint (value, transport->w_buf_size);
+      break;
+  }
+}
+
+/* property mutator */
+void
+thrift_framed_transport_set_property (GObject *object, guint property_id,
+                                      const GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
+      transport->transport = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
+      transport->r_buf_size = g_value_get_uint (value);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
+      transport->w_buf_size = g_value_get_uint (value);
+      break;
+  }
+}
+
+/* initializes the class */
+static void
+thrift_framed_transport_class_init (ThriftFramedTransportClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+  GParamSpec *param_spec = NULL;
+
+  /* setup accessors and mutators */
+  gobject_class->get_property = thrift_framed_transport_get_property;
+  gobject_class->set_property = thrift_framed_transport_set_property;
+
+  param_spec = g_param_spec_object ("transport", "transport (construct)",
+                                    "Thrift transport",
+                                    THRIFT_TYPE_TRANSPORT,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("r_buf_size",
+                                  "read buffer size (construct)",
+                                  "Set the read buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("w_buf_size",
+                                  "write buffer size (construct)",
+                                  "Set the write buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE,
+                                   param_spec);
+
 
+  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
+
+  gobject_class->finalize = thrift_framed_transport_finalize;
+  ttc->is_open = thrift_framed_transport_is_open;
+  ttc->open = thrift_framed_transport_open;
+  ttc->close = thrift_framed_transport_close;
+  ttc->read = thrift_framed_transport_read;
+  ttc->read_end = thrift_framed_transport_read_end;
+  ttc->write = thrift_framed_transport_write;
+  ttc->write_end = thrift_framed_transport_write_end;
+  ttc->flush = thrift_framed_transport_flush;
+}

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_framed_transport.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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.
+ */
+
 #ifndef _THRIFT_FRAMED_TRANSPORT_H
 #define _THRIFT_FRAMED_TRANSPORT_H
 
@@ -6,27 +25,20 @@
 
 #include "transport/thrift_transport.h"
 
+G_BEGIN_DECLS
+
 /*! \file thrift_framed_transport.h
- *  \brief Implementation of a Thrift framed transport.  Subclasses 
+ *  \brief Implementation of a Thrift framed transport.  Subclasses
  *         the ThriftTransport class.
  */
 
 /* type macros */
 #define THRIFT_TYPE_FRAMED_TRANSPORT (thrift_framed_transport_get_type ())
-#define THRIFT_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                      THRIFT_TYPE_FRAMED_TRANSPORT, \
-                                      ThriftFramedTransport))
-#define THRIFT_IS_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                         THRIFT_TYPE_FRAMED_TRANSPORT))
-#define THRIFT_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                          THRIFT_TYPE_FRAMED_TRANSPORT, \
-                                          ThriftFramedTransportClass))
-#define THRIFT_IS_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                             THRIFT_TYPE_FRAMED_TRANSPORT)
-#define THRIFT_FRAMED_TRANSPORT_GET_CLASS(obj) \
-            (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-             THRIFT_TYPE_FRAMED_TRANSPORT, \
-             ThriftFramedTransportClass))
+#define THRIFT_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransport))
+#define THRIFT_IS_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_FRAMED_TRANSPORT))
+#define THRIFT_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransportClass))
+#define THRIFT_IS_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_FRAMED_TRANSPORT)
+#define THRIFT_FRAMED_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransportClass))
 
 /*!
  * ThriftFramedTransport instance.
@@ -58,4 +70,6 @@ typedef struct _ThriftFramedTransportCla
 /* used by THRIFT_TYPE_FRAMED_TRANSPORT */
 GType thrift_framed_transport_get_type (void);
 
+G_END_DECLS
+
 #endif

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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 <assert.h>
 #include <netdb.h>
 #include <stdlib.h>
@@ -16,143 +35,7 @@ enum _ThriftMemoryBufferProperties
   PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE,
 };
 
-/* forward declarations */
-static void thrift_memory_buffer_instance_init (ThriftMemoryBuffer *self);
-static void thrift_memory_buffer_class_init (ThriftMemoryBufferClass *cls);
-
-
-gboolean thrift_memory_buffer_is_open (ThriftTransport *transport);
-gboolean thrift_memory_buffer_open (ThriftTransport *transport,
-                                    GError **error);
-gboolean thrift_memory_buffer_close (ThriftTransport *transport,
-                                     GError **error);
-gint32 thrift_memory_buffer_read (ThriftTransport *transport, gpointer buf,
-                                  guint32 len, GError **error);
-gboolean thrift_memory_buffer_read_end (ThriftTransport *transport,
-                                        GError **error);
-gboolean thrift_memory_buffer_write (ThriftTransport *transport,
-                                     const gpointer buf,
-                                     const guint32 len, GError **error);
-gboolean thrift_memory_buffer_write_end (ThriftTransport *transport,
-                                         GError **error);
-gboolean thrift_memory_buffer_flush (ThriftTransport *transport,
-                                     GError **error);
-
-GType
-thrift_memory_buffer_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info =
-    {
-      sizeof (ThriftMemoryBufferClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_memory_buffer_class_init,
-      NULL, /* class finalize */
-      NULL, /* class data */
-      sizeof (ThriftMemoryBuffer),
-      0, /* n_preallocs */
-      (GInstanceInitFunc) thrift_memory_buffer_instance_init,
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (THRIFT_TYPE_TRANSPORT,
-                                   "ThriftMemoryBuffer", &info, 0);
-  }
-
-  return type;
-}
-
-/* initializes the instance */
-static void
-thrift_memory_buffer_instance_init (ThriftMemoryBuffer *transport)
-{
-  transport->buf = g_byte_array_new ();
-}
-
-/* destructor */
-static void
-thrift_memory_buffer_finalize (GObject *object)
-{
-  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
-
-  if (transport->buf != NULL)
-  {
-    g_byte_array_free (transport->buf, TRUE);
-  }
-  transport->buf = NULL;
-}
-
-/* property accessor */
-void
-thrift_memory_buffer_get_property (GObject *object, guint property_id,
-                                   GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
-      g_value_set_uint (value, transport->buf_size);
-      break;
-  }
-}
-
-/* property mutator */
-void
-thrift_memory_buffer_set_property (GObject *object, guint property_id,
-                                   const GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
-      transport->buf_size = g_value_get_uint (value);
-      break;
-  }
-}
-
-/* initializes the class */
-static void
-thrift_memory_buffer_class_init (ThriftMemoryBufferClass *cls)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
-  GParamSpec *param_spec = NULL;
-
-  /* setup accessors and mutators */
-  gobject_class->get_property = thrift_memory_buffer_get_property;
-  gobject_class->set_property = thrift_memory_buffer_set_property;
-
-  param_spec = g_param_spec_uint ("buf_size",
-                                  "buffer size (construct)",
-                                  "Set the read buffer size",
-                                  0, /* min */
-                                  1048576, /* max, 1024*1024 */
-                                  512, /* default value */
-                                  G_PARAM_CONSTRUCT_ONLY |
-                                  G_PARAM_READWRITE);
-  g_object_class_install_property (gobject_class,
-                                   PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE,
-                                   param_spec);
-
-  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
-
-  gobject_class->finalize = thrift_memory_buffer_finalize;
-  ttc->is_open = thrift_memory_buffer_is_open;
-  ttc->open = thrift_memory_buffer_open;
-  ttc->close = thrift_memory_buffer_close;
-  ttc->read = thrift_memory_buffer_read;
-  ttc->read_end = thrift_memory_buffer_read_end;
-  ttc->write = thrift_memory_buffer_write;
-  ttc->write_end = thrift_memory_buffer_write_end;
-  ttc->flush = thrift_memory_buffer_flush;
-}
+G_DEFINE_TYPE(ThriftMemoryBuffer, thrift_memory_buffer, THRIFT_TYPE_TRANSPORT)
 
 /* implements thrift_transport_is_open */
 gboolean
@@ -257,4 +140,90 @@ thrift_memory_buffer_flush (ThriftTransp
   return TRUE;
 }
 
+/* initializes the instance */
+static void
+thrift_memory_buffer_init (ThriftMemoryBuffer *transport)
+{
+  transport->buf = g_byte_array_new ();
+}
+
+/* destructor */
+static void
+thrift_memory_buffer_finalize (GObject *object)
+{
+  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
+
+  if (transport->buf != NULL)
+  {
+    g_byte_array_free (transport->buf, TRUE);
+  }
+  transport->buf = NULL;
+}
+
+/* property accessor */
+void
+thrift_memory_buffer_get_property (GObject *object, guint property_id,
+                                   GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
+      g_value_set_uint (value, transport->buf_size);
+      break;
+  }
+}
+
+/* property mutator */
+void
+thrift_memory_buffer_set_property (GObject *object, guint property_id,
+                                   const GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
+      transport->buf_size = g_value_get_uint (value);
+      break;
+  }
+}
+
+/* initializes the class */
+static void
+thrift_memory_buffer_class_init (ThriftMemoryBufferClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+  GParamSpec *param_spec = NULL;
 
+  /* setup accessors and mutators */
+  gobject_class->get_property = thrift_memory_buffer_get_property;
+  gobject_class->set_property = thrift_memory_buffer_set_property;
+
+  param_spec = g_param_spec_uint ("buf_size",
+                                  "buffer size (construct)",
+                                  "Set the read buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE,
+                                   param_spec);
+
+  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
+
+  gobject_class->finalize = thrift_memory_buffer_finalize;
+  ttc->is_open = thrift_memory_buffer_is_open;
+  ttc->open = thrift_memory_buffer_open;
+  ttc->close = thrift_memory_buffer_close;
+  ttc->read = thrift_memory_buffer_read;
+  ttc->read_end = thrift_memory_buffer_read_end;
+  ttc->write = thrift_memory_buffer_write;
+  ttc->write_end = thrift_memory_buffer_write_end;
+  ttc->flush = thrift_memory_buffer_flush;
+}

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_memory_buffer.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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.
+ */
+
 #ifndef _THRIFT_MEMORY_BUFFER_H
 #define _THRIFT_MEMORY_BUFFER_H
 
@@ -6,26 +25,19 @@
 
 #include "transport/thrift_transport.h"
 
+G_BEGIN_DECLS
+
 /*! \file thrift_memory_buffer.h
- *  \brief Implementation of a Thrift memory buffer transport. 
+ *  \brief Implementation of a Thrift memory buffer transport.
  */
 
 /* type macros */
 #define THRIFT_TYPE_MEMORY_BUFFER (thrift_memory_buffer_get_type ())
-#define THRIFT_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                   THRIFT_TYPE_MEMORY_BUFFER, \
-                                   ThriftMemoryBuffer))
-#define THRIFT_IS_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                      THRIFT_TYPE_MEMORY_BUFFER))
-#define THRIFT_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                       THRIFT_TYPE_MEMORY_BUFFER, \
-                                       ThriftMemoryBufferClass))
-#define THRIFT_IS_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                          THRIFT_TYPE_MEMORY_BUFFER)
-#define THRIFT_MEMORY_BUFFER_GET_CLASS(obj) \
-            (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-             THRIFT_TYPE_MEMORY_BUFFER, \
-             ThriftMemoryBufferClass))
+#define THRIFT_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBuffer))
+#define THRIFT_IS_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_MEMORY_BUFFER))
+#define THRIFT_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBufferClass))
+#define THRIFT_IS_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_MEMORY_BUFFER)
+#define THRIFT_MEMORY_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBufferClass))
 
 /*!
  * ThriftMemoryBuffer instance.
@@ -52,4 +64,6 @@ typedef struct _ThriftMemoryBufferClass 
 /* used by THRIFT_TYPE_MEMORY_BUFFER */
 GType thrift_memory_buffer_get_type (void);
 
+G_END_DECLS
+
 #endif

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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 <errno.h>
 #include <netdb.h>
 #include <string.h>
@@ -24,43 +43,101 @@ enum _ThriftServerSocketProperties
 /* for errors coming from socket() and connect() */
 extern int errno;
 
-/* forward declarations */
-static void thrift_server_socket_instance_init (ThriftServerSocket *self);
-static void thrift_server_socket_class_init (ThriftServerSocketClass *cls);
-
-gboolean thrift_server_socket_listen (ThriftServerTransport *transport,
-                                      GError **error);
-ThriftTransport *thrift_server_socket_accept (ThriftServerTransport *transport,
-                                              GError **error);
-gboolean thrift_server_socket_close (ThriftServerTransport *transport,
-                                     GError **error);
+G_DEFINE_TYPE(ThriftServerSocket, thrift_server_socket, THRIFT_TYPE_SERVER_TRANSPORT)
 
-GType
-thrift_server_socket_get_type (void)
+gboolean
+thrift_server_socket_listen (ThriftServerTransport *transport, GError **error)
 {
-  static GType type = 0;
+  int enabled = 1; /* for setsockopt() */
+  struct sockaddr_in pin;
+  ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
+
+  /* create a address structure */
+  memset (&pin, 0, sizeof(pin));
+  pin.sin_family = AF_INET;
+  pin.sin_addr.s_addr = INADDR_ANY;
+  pin.sin_port = htons(tsocket->port);
 
-  if (type == 0)
+  /* create a socket */
+  if ((tsocket->sd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
   {
-    static const GTypeInfo info =
-    {
-      sizeof (ThriftServerSocketClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_server_socket_class_init,
-      NULL, /* class finalize */
-      NULL, /* class data */
-      sizeof (ThriftServerSocket),
-      0, /* n_preallocs */
-      (GInstanceInitFunc) thrift_server_socket_instance_init,
-      NULL, /* value_table */
-    };
+    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
+                 THRIFT_SERVER_SOCKET_ERROR_SOCKET,
+                 "failed to create socket - %s", strerror (errno));
+    return FALSE;
+  }
 
-    type = g_type_register_static (THRIFT_TYPE_SERVER_TRANSPORT,
-                                   "ThriftServerSocket", &info, 0);
+  if (setsockopt(tsocket->sd, SOL_SOCKET, SO_REUSEADDR, &enabled,
+                 sizeof(enabled)) == -1)
+  {
+    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
+                 THRIFT_SERVER_SOCKET_ERROR_SETSOCKOPT,
+                 "unable to set SO_REUSEADDR - %s", strerror(errno));
+    return FALSE;
+  }
+
+  /* bind to the socket */
+  if (bind(tsocket->sd, (struct sockaddr *) &pin, sizeof(pin)) == -1)
+  {
+    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
+                 THRIFT_SERVER_SOCKET_ERROR_BIND,
+                 "failed to bind to port %d - %s",
+                 tsocket->port, strerror(errno));
+    return FALSE;
   }
 
-  return type;
+  if (listen(tsocket->sd, tsocket->backlog) == -1)
+  {
+    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
+                 THRIFT_SERVER_SOCKET_ERROR_LISTEN,
+                 "failed to listen to port %d - %s",
+                 tsocket->port, strerror(errno));
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+ThriftTransport *
+thrift_server_socket_accept (ThriftServerTransport *transport, GError **error)
+{
+  int sd = 0;
+  guint addrlen = 0;
+  struct sockaddr_in address;
+  ThriftSocket *socket = NULL;
+
+  ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
+
+  if ((sd = accept(tsocket->sd, (struct sockaddr *) &address, &addrlen)) == -1)
+  {
+    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
+                 THRIFT_SERVER_SOCKET_ERROR_ACCEPT,
+                 "failed to accept connection - %s",
+                 strerror(errno));
+    return FALSE;
+  }
+
+  socket = g_object_new (THRIFT_TYPE_SOCKET, NULL);
+  socket->sd = sd;
+
+  return THRIFT_TRANSPORT(socket);
+}
+
+gboolean
+thrift_server_socket_close (ThriftServerTransport *transport, GError **error)
+{
+  ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
+
+  if (close (tsocket->sd) == -1)
+  {
+    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
+                 THRIFT_SERVER_SOCKET_ERROR_CLOSE,
+                 "unable to close socket - %s", strerror(errno));
+    return FALSE;
+  }
+  tsocket->sd = 0;
+
+  return TRUE;
 }
 
 /* define the GError domain for this implementation */
@@ -72,7 +149,7 @@ thrift_server_socket_error_quark (void)
 
 /* initializes the instance */
 static void
-thrift_server_socket_instance_init (ThriftServerSocket *socket)
+thrift_server_socket_init (ThriftServerSocket *socket)
 {
   socket->sd = 0;
 }
@@ -175,98 +252,3 @@ thrift_server_socket_class_init (ThriftS
   tstc->close = thrift_server_socket_close;
 }
 
-gboolean
-thrift_server_socket_listen (ThriftServerTransport *transport, GError **error)
-{
-  int enabled = 1; /* for setsockopt() */
-  struct sockaddr_in pin;
-  ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
-
-  /* create a address structure */
-  memset (&pin, 0, sizeof(pin));
-  pin.sin_family = AF_INET;
-  pin.sin_addr.s_addr = INADDR_ANY;
-  pin.sin_port = htons(tsocket->port);
-
-  /* create a socket */
-  if ((tsocket->sd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
-  {
-    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR, 
-                 THRIFT_SERVER_SOCKET_ERROR_SOCKET,
-                 "failed to create socket - %s", strerror (errno));
-    return FALSE;
-  }
-
-  if (setsockopt(tsocket->sd, SOL_SOCKET, SO_REUSEADDR, &enabled,
-                 sizeof(enabled)) == -1)
-  {
-    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
-                 THRIFT_SERVER_SOCKET_ERROR_SETSOCKOPT,
-                 "unable to set SO_REUSEADDR - %s", strerror(errno));
-    return FALSE;
-  }
-
-  /* bind to the socket */
-  if (bind(tsocket->sd, (struct sockaddr *) &pin, sizeof(pin)) == -1)
-  {
-    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR, 
-                 THRIFT_SERVER_SOCKET_ERROR_BIND,
-                 "failed to bind to port %d - %s", 
-                 tsocket->port, strerror(errno));
-    return FALSE;
-  } 
-
-  if (listen(tsocket->sd, tsocket->backlog) == -1)
-  {
-    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
-                 THRIFT_SERVER_SOCKET_ERROR_LISTEN,
-                 "failed to listen to port %d - %s",
-                 tsocket->port, strerror(errno));
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-ThriftTransport *
-thrift_server_socket_accept (ThriftServerTransport *transport, GError **error)
-{
-  int sd = 0;
-  guint addrlen = 0;
-  struct sockaddr_in address;
-  ThriftSocket *socket = NULL;
-
-  ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
-
-  if ((sd = accept(tsocket->sd, (struct sockaddr *) &address, &addrlen)) == -1)
-  {
-    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
-                 THRIFT_SERVER_SOCKET_ERROR_ACCEPT,
-                 "failed to accept connection - %s",
-                 strerror(errno));
-    return FALSE;
-  }
-
-  socket = g_object_new (THRIFT_TYPE_SOCKET, NULL);
-  socket->sd = sd;
-
-  return THRIFT_TRANSPORT(socket);
-}
-
-gboolean
-thrift_server_socket_close (ThriftServerTransport *transport, GError **error)
-{
-  ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
-
-  if (close (tsocket->sd) == -1)
-  {
-    g_set_error (error, THRIFT_SERVER_SOCKET_ERROR, 
-                 THRIFT_SERVER_SOCKET_ERROR_CLOSE,
-                 "unable to close socket - %s", strerror(errno));
-    return FALSE;
-  }
-  tsocket->sd = 0;
-
-  return TRUE;
-}
-

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_server_socket.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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.
+ */
+
 #ifndef _THRIFT_SERVER_SOCKET_H
 #define _THRIFT_SERVER_SOCKET_H
 
@@ -5,6 +24,8 @@
 
 #include "thrift_server_transport.h"
 
+G_BEGIN_DECLS
+
 /*! \file thrift_server_socket.h
  *  \brief Socket implementation of a Thrift server transport.  Implements the
  *         ThriftServerTransport class.
@@ -12,19 +33,11 @@
 
 /* type macros */
 #define THRIFT_TYPE_SERVER_SOCKET (thrift_server_socket_get_type ())
-#define THRIFT_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                       THRIFT_TYPE_SERVER_SOCKET, \
-                                       ThriftServerSocket))
-#define THRIFT_IS_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                          THRIFT_TYPE_SERVER_SOCKET))
-#define THRIFT_SERVER_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                           THRIFT_TYPE_SERVER_SOCKET, \
-                                           ThriftServerSocketClass))
-#define THRIFT_IS_SERVER_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                              THRIFT_TYPE_SERVER_SOCKET))
-#define THRIFT_SERVER_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-                                                 THRIFT_TYPE_SERVER_SOCKET, \
-                                                 ThriftServerSocketClass))
+#define THRIFT_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SERVER_SOCKET, ThriftServerSocket))
+#define THRIFT_IS_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SERVER_SOCKET))
+#define THRIFT_SERVER_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SERVER_SOCKET, ThriftServerSocketClass))
+#define THRIFT_IS_SERVER_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SERVER_SOCKET))
+#define THRIFT_SERVER_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SERVER_SOCKET, ThriftServerSocketClass))
 
 /*!
  * Thrift ServerSocket instance.
@@ -70,4 +83,6 @@ typedef enum
 GQuark thrift_server_socket_error_quark (void);
 #define THRIFT_SERVER_SOCKET_ERROR (thrift_server_socket_error_quark ())
 
+G_END_DECLS
+
 #endif

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.c Fri Nov 26 10:17:48 2010
@@ -1,39 +1,27 @@
+/*
+ * 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 "thrift.h"
 #include "transport/thrift_transport.h"
 #include "transport/thrift_server_transport.h"
 
-/* forward declarations */
-static void thrift_server_transport_class_init (ThriftServerTransportClass *c);
-
-/* define ThriftTransportClass type */
-GType
-thrift_server_transport_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info =
-    {
-      sizeof (ThriftServerTransportClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_server_transport_class_init, 
-      NULL, /* class_finalize */
-      NULL, /* class_data */
-      sizeof (ThriftServerTransport),
-      0, /* n_preallocs */
-      NULL, /* instance_init */
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (G_TYPE_OBJECT,
-                                   "ThriftServerTransport",
-                                   &info, G_TYPE_FLAG_ABSTRACT);
-  }
-
-  return type;
-}
+G_DEFINE_ABSTRACT_TYPE(ThriftServerTransport, thrift_server_transport, G_TYPE_OBJECT)
 
 /* base initializer for the server transport interface */
 static void
@@ -44,6 +32,12 @@ thrift_server_transport_class_init (Thri
   c->close = thrift_server_transport_close;
 }
 
+static void
+thrift_server_transport_init (ThriftServerTransport *transport)
+{
+  THRIFT_UNUSED_VAR (transport);
+}
+
 gboolean
 thrift_server_transport_listen (ThriftServerTransport *transport,
                                 GError **error)
@@ -66,5 +60,3 @@ thrift_server_transport_close (ThriftSer
   return THRIFT_SERVER_TRANSPORT_GET_CLASS (transport)->close (transport,
                                                                error);
 }
-
-

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_server_transport.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * 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.
+ */
+
 #ifndef _THRIFT_SERVER_TRANSPORT_H
 #define _THRIFT_SERVER_TRANSPORT_H
 
@@ -5,25 +24,19 @@
 
 #include "thrift_transport.h"
 
+G_BEGIN_DECLS
+
 /*! \file thrift_server_transport.h
  *  \brief Abstract class for Thrift server transports.
  */
 
-/* type macros */	
+/* type macros */
 #define THRIFT_TYPE_SERVER_TRANSPORT (thrift_server_transport_get_type ())
-#define THRIFT_SERVER_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                          THRIFT_TYPE_SERVER_TRANSPORT, \
-                                          ThriftServerTransport))
-#define THRIFT_IS_SERVER_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                             THRIFT_TYPE_SERVER_TRANSPORT))
-#define THRIFT_SERVER_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                              THRIFT_TYPE_SERVER_TRANSPORT, \
-                                              ThriftServerTransportClass))
-#define THRIFT_IS_SERVER_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                                 THRIFT_TYPE_SERVER_TRANSPORT))
-#define THRIFT_SERVER_TRANSPORT_GET_CLASS(obj) \
-            (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SERVER_TRANSPORT, \
-                                        ThriftServerTransportClass))
+#define THRIFT_SERVER_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SERVER_TRANSPORT, ThriftServerTransport))
+#define THRIFT_IS_SERVER_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SERVER_TRANSPORT))
+#define THRIFT_SERVER_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SERVER_TRANSPORT, ThriftServerTransportClass))
+#define THRIFT_IS_SERVER_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SERVER_TRANSPORT))
+#define THRIFT_SERVER_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SERVER_TRANSPORT, ThriftServerTransportClass))
 
 struct _ThriftServerTransport
 {
@@ -46,7 +59,7 @@ struct _ThriftServerTransportClass
 typedef struct _ThriftServerTransportClass ThriftServerTransportClass;
 
 /* used by THRIFT_TYPE_SERVER_TRANSPORT */
-GType thrift_server_transport_get_type (void); 
+GType thrift_server_transport_get_type (void);
 
 /*!
  * Listen for new connections.
@@ -59,7 +72,7 @@ gboolean thrift_server_transport_listen 
  * Accept a connection.
  * \public \memberof ThriftServerTransportClass
  */
-ThriftTransport *thrift_server_transport_accept 
+ThriftTransport *thrift_server_transport_accept
     (ThriftServerTransport *transport, GError **error);
 
 /*!
@@ -69,4 +82,6 @@ ThriftTransport *thrift_server_transport
 gboolean thrift_server_transport_close (ThriftServerTransport *transport,
                                         GError **error);
 
+G_END_DECLS
+
 #endif /* _THRIFT_SERVER_TRANSPORT_H */