THRIFT-4329: multiplexed processor, client and server for c_glib
Client: c_glib

This closes #1361
diff --git a/test/c_glib/Makefile.am b/test/c_glib/Makefile.am
index 0c478f9..4a03d29 100755
--- a/test/c_glib/Makefile.am
+++ b/test/c_glib/Makefile.am
@@ -45,6 +45,8 @@
 test_server_SOURCES = \
 	src/thrift_test_handler.c \
 	src/thrift_test_handler.h \
+	src/thrift_second_service_handler.c \
+	src/thrift_second_service_handler.h \
 	src/test_server.c
 
 test_server_LDADD = \
diff --git a/test/c_glib/src/test_client.c b/test/c_glib/src/test_client.c
index deff4e1..ef24ab7 100644
--- a/test/c_glib/src/test_client.c
+++ b/test/c_glib/src/test_client.c
@@ -412,7 +412,7 @@
                                                         "2nd",
                                                         &error)) {
           printf (" = \"%s\"\n", string);
-          if (strncmp (string, "testString(\"2nd\")", 18) != 0) {
+          if (strcmp (string, "testString(\"2nd\")") != 0) {
             ++fail_count;
           }
 
diff --git a/test/c_glib/src/test_server.c b/test/c_glib/src/test_server.c
index 7f41d3f..2d716ec 100644
--- a/test/c_glib/src/test_server.c
+++ b/test/c_glib/src/test_server.c
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/processor/thrift_multiplexed_processor.h>
 #include <thrift/c_glib/protocol/thrift_binary_protocol_factory.h>
 #include <thrift/c_glib/protocol/thrift_compact_protocol_factory.h>
 #include <thrift/c_glib/server/thrift_server.h>
@@ -37,8 +38,10 @@
 #include <thrift/c_glib/transport/thrift_transport_factory.h>
 
 #include "../gen-c_glib/t_test_thrift_test.h"
+#include "../gen-c_glib/t_test_second_service.h"
 
 #include "thrift_test_handler.h"
+#include "thrift_second_service_handler.h"
 
 /* Our server object, declared globally so it is accessible within the SIGINT
    signal handler */
@@ -96,7 +99,10 @@
   GType  protocol_factory_type  = THRIFT_TYPE_BINARY_PROTOCOL_FACTORY;
 
   TTestThriftTestHandler *handler;
+  TTestThriftTestHandler *handler_second_service = NULL;
   ThriftProcessor        *processor;
+  ThriftProcessor        *processor_test = NULL;
+  ThriftProcessor        *processor_second_service = NULL;
   ThriftServerTransport  *server_transport;
   ThriftTransportFactory *transport_factory;
   ThriftProtocolFactory  *protocol_factory;
@@ -138,6 +144,13 @@
       protocol_factory_type = THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY;
       protocol_name = "compact";
     }
+    else if (strncmp (protocol_option, "multi", 6) == 0) {
+	protocol_name = "binary:multi";
+    }
+    else if (strncmp (protocol_option, "multic", 7) == 0) {
+	protocol_factory_type = THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY;
+	protocol_name = "compact:multic";
+    }
     else if (strncmp (protocol_option, "binary", 7) != 0) {
       fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
       options_valid = FALSE;
@@ -161,16 +174,57 @@
   /* Establish all our connection objects */
   handler           = g_object_new (TYPE_THRIFT_TEST_HANDLER,
                                     NULL);
-  processor         = g_object_new (T_TEST_TYPE_THRIFT_TEST_PROCESSOR,
-                                    "handler", handler,
-                                    NULL);
+
+
+
+  if(strstr(protocol_name, ":multi")){
+      /* When a multiplexed processor is involved the handler is not
+         registered as usual. We create the processor and the real
+         processor is registered. Multiple processors can be registered
+         at once. This is why we don't have a constructor property */
+      processor = g_object_new (THRIFT_TYPE_MULTIPLEXED_PROCESSOR,
+					 NULL);
+
+      handler_second_service = g_object_new (TYPE_SECOND_SERVICE_HANDLER,
+     	                                    NULL);
+
+      processor_test = g_object_new (T_TEST_TYPE_THRIFT_TEST_PROCESSOR,
+				    "handler", handler,
+				    NULL);
+      processor_second_service =   g_object_new (T_TEST_TYPE_SECOND_SERVICE_PROCESSOR,
+				    "handler", handler_second_service,
+				    NULL);
+
+      /* We register a test processor with Multiplexed name ThriftTest */
+      if(!thrift_multiplexed_processor_register_processor(processor,
+						      "ThriftTest", processor_test,
+						      &error)){
+	    g_message ("thrift_server_serve: %s",
+	               error != NULL ? error->message : "(null)");
+	    g_clear_error (&error);
+      }
+      /* We register a second test processor with Multiplexed name SecondService
+       * we are responsible of freeing the processor when it's not used anymore */
+      if(!thrift_multiplexed_processor_register_processor(processor,
+						      "SecondService", processor_second_service,
+						      &error)){
+	    g_message ("thrift_server_serve: %s",
+	               error != NULL ? error->message : "(null)");
+	    g_clear_error (&error);
+      }
+
+  }else{
+      processor = g_object_new (T_TEST_TYPE_THRIFT_TEST_PROCESSOR,
+                                        "handler", handler,
+                                        NULL);
+  }
   server_transport  = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
                                     "port", port,
                                     NULL);
   transport_factory = g_object_new (transport_factory_type,
                                     NULL);
 
-  if (strncmp (protocol_name, "compact", 8) == 0) {
+  if (strstr (protocol_name, "compact") != NULL) {
     protocol_factory  = g_object_new (protocol_factory_type,
                                       "string_limit", string_limit,
                                       "container_limit", container_limit,
@@ -222,6 +276,15 @@
   g_object_unref (server_transport);
   g_object_unref (processor);
   g_object_unref (handler);
+  if(handler_second_service){
+      g_object_unref (handler_second_service);
+  }
+  if(processor_test){
+      g_object_unref (processor_test);
+  }
+  if(processor_second_service){
+      g_object_unref (processor_second_service);
+  }
 
   return 0;
 }
diff --git a/test/c_glib/src/thrift_second_service_handler.c b/test/c_glib/src/thrift_second_service_handler.c
new file mode 100644
index 0000000..c464372
--- /dev/null
+++ b/test/c_glib/src/thrift_second_service_handler.c
@@ -0,0 +1,82 @@
+/*
+ * 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 <inttypes.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/thrift_application_exception.h>
+
+#include "thrift_second_service_handler.h"
+
+/* A handler that implements the TTestSecondServiceIf interface */
+
+G_DEFINE_TYPE (SecondServiceHandler,
+               second_service_handler,
+	       T_TEST_TYPE_SECOND_SERVICE_HANDLER);
+
+
+gboolean
+second_service_handler_secondtest_string (TTestSecondServiceIf  *iface,
+                                 gchar             **_return,
+                                 const gchar        *thing,
+                                 GError            **error)
+{
+  THRIFT_UNUSED_VAR (iface);
+  THRIFT_UNUSED_VAR (error);
+  gchar buffer[256];
+
+  printf ("testSecondServiceMultiplexSecondTestString(\"%s\")\n", thing);
+  snprintf(buffer, 255, "testString(\"%s\")", thing);
+  *_return = g_strdup (buffer);
+
+  return TRUE;
+}
+
+gboolean
+second_service_handler_blah_blah (TTestSecondServiceIf *iface, GError **error)
+{
+  THRIFT_UNUSED_VAR (iface);
+  THRIFT_UNUSED_VAR (error);
+
+  printf ("blahBlah()\n");
+
+  return TRUE;
+}
+
+static void
+second_service_handler_init (SecondServiceHandler *self)
+{
+  THRIFT_UNUSED_VAR (self);
+}
+
+static void
+second_service_handler_class_init (SecondServiceHandlerClass *klass)
+{
+  TTestSecondServiceHandlerClass *base_class =
+      T_TEST_SECOND_SERVICE_HANDLER_CLASS (klass);
+
+
+  base_class->secondtest_string =
+      second_service_handler_secondtest_string;
+  base_class->blah_blah =
+      second_service_handler_blah_blah;
+
+}
diff --git a/test/c_glib/src/thrift_second_service_handler.h b/test/c_glib/src/thrift_second_service_handler.h
new file mode 100644
index 0000000..bbe048c
--- /dev/null
+++ b/test/c_glib/src/thrift_second_service_handler.h
@@ -0,0 +1,73 @@
+/*
+ * 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 _SECOND_SERVICE_HANDLER_H
+#define _SECOND_SERVICE_HANDLER_H
+
+#include <glib-object.h>
+#include <stdio.h>
+
+#include "../gen-c_glib/t_test_second_service.h"
+
+G_BEGIN_DECLS
+
+/* A handler that implements the TTestSecondServiceIf interface */
+
+#define TYPE_SECOND_SERVICE_HANDLER (second_service_handler_get_type ())
+
+#define SECOND_SERVICE_HANDLER(obj)                                \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                           \
+                               TYPE_SECOND_SERVICE_HANDLER,        \
+                               SecondServiceHandler))
+#define IS_SECOND_SERVICE_HANDLER(obj)                             \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj),                           \
+                               TYPE_SECOND_SERVICE_HANDLER))
+#define SECOND_SERVICE_HANDLER_CLASS(c)                    \
+  (G_TYPE_CHECK_CLASS_CAST ((c),                        \
+                            TYPE_SECOND_SERVICE_HANDLER,   \
+                            SecondServiceHandlerClass))
+#define IS_SECOND_SERVICE_HANDLER_CLASS(c)                 \
+  (G_TYPE_CHECK_CLASS_TYPE ((c),                        \
+                            TYPE_SECOND_SERVICE_HANDLER))
+#define SECOND_SERVICE_HANDLER_GET_CLASS(obj)              \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj),                    \
+                              TYPE_SECOND_SERVICE_HANDLER, \
+                              SecondServiceHandlerClass))
+
+typedef struct _SecondServiceHandler SecondServiceHandler;
+typedef struct _SecondServiceHandlerClass SecondServiceHandlerClass;
+
+struct _SecondServiceHandler {
+  TTestSecondServiceHandler parent;
+};
+
+struct _SecondServiceHandlerClass {
+  TTestSecondServiceHandlerClass parent;
+
+};
+
+/* Used by SECOND_SERVICE_HANDLER_GET_TYPE */
+GType second_service_handler_get_type (void);
+
+gboolean second_service_handler_blah_blah (TTestSecondServiceIf *iface, GError **error);
+gboolean second_service_handler_secondtest_string          (TTestSecondServiceIf *iface, gchar ** _return, const gchar * thing, GError **error);
+
+G_END_DECLS
+
+#endif /* _SECOND_SERVICE_HANDLER_H */
diff --git a/test/features/tests.json b/test/features/tests.json
index 3ab3b68..41e07d7 100644
--- a/test/features/tests.json
+++ b/test/features/tests.json
@@ -66,7 +66,6 @@
       "--string-limit=50"
     ],
     "protocols": [
-      "binary",
       "compact"
     ],
     "transports": ["buffered"],
@@ -84,7 +83,6 @@
       "--container-limit=50"
     ],
     "protocols": [
-      "binary",
       "compact"
     ],
     "transports": ["buffered"],
diff --git a/test/tests.json b/test/tests.json
index e62af24..c1c3155 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -8,6 +8,12 @@
       "command": [
         "test_server",
         "--lt-debug"
+      ],
+      "protocols": [
+        "binary:multi",
+        "compact:multic",
+        "multi",
+        "multic"
       ]
     },
     "client": {