-- Change concept of protocol and transport factory

Summary:
- Transport factories now wrap around one transport
- Protocol factories now wrap around one transport (as opposed to a pair of input/output
   transports)
- TServer now takes input/output transport and protocol factories

The motivation for this change is that you could concievably want to use a different protocol or
transport for input and output. An example is that incoming data is encoded using binary protocol
but outgoing data is encrypted XML (with encryption being done on the transport level).

This change should be mostly backwards compatible because the TServer classes have constructors
that take a transport factory and use that for both the input and transport factories. The only
change might be for anyone who is using the C++ client code directly i.e. instantiating
TBinaryProtocol() directly because the constructor now only accepts one transport.

Reviewed By: Slee

Test Plan: Everything compiles (for both thrift and search).

Notes:
I am going to make the same changes in all the supported languages after this...


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664940 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TServer.h b/lib/cpp/src/server/TServer.h
index b9f4fca..ad9c291 100644
--- a/lib/cpp/src/server/TServer.h
+++ b/lib/cpp/src/server/TServer.h
@@ -38,73 +38,92 @@
     return serverTransport_;
   }
 
-  shared_ptr<TTransportFactory> getTransportFactory() {
-    return transportFactory_;
+  shared_ptr<TTransportFactory> getInputTransportFactory() {
+    return inputTransportFactory_;
+  }
+
+  shared_ptr<TTransportFactory> getOutputTransportFactory() {
+    return outputTransportFactory_;
   }
   
-  shared_ptr<TProtocolFactory> getProtocolFactory() {
-    return protocolFactory_;
+  shared_ptr<TProtocolFactory> getInputProtocolFactory() {
+    return inputProtocolFactory_;
   }
 
+  shared_ptr<TProtocolFactory> getOutputProtocolFactory() {
+    return outputProtocolFactory_;
+  }
 
 protected:
+  TServer(shared_ptr<TProcessor> processor):
+    processor_(processor) {
+    setInputTransportFactory(shared_ptr<TTransportFactory>(new TTransportFactory()));
+    setOutputTransportFactory(shared_ptr<TTransportFactory>(new TTransportFactory()));
+    setInputProtocolFactory(shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
+    setOutputProtocolFactory(shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
+  }
+
+  TServer(shared_ptr<TProcessor> processor,
+          shared_ptr<TServerTransport> serverTransport):
+    processor_(processor),
+    serverTransport_(serverTransport) {
+    setInputTransportFactory(shared_ptr<TTransportFactory>(new TTransportFactory()));
+    setOutputTransportFactory(shared_ptr<TTransportFactory>(new TTransportFactory()));
+    setInputProtocolFactory(shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
+    setOutputProtocolFactory(shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
+  }
+
   TServer(shared_ptr<TProcessor> processor,
           shared_ptr<TServerTransport> serverTransport,
           shared_ptr<TTransportFactory> transportFactory,
-          shared_ptr<TProtocolFactory> protocolFactory) :
+          shared_ptr<TProtocolFactory> protocolFactory):
     processor_(processor),
     serverTransport_(serverTransport),
-    transportFactory_(transportFactory),
-    protocolFactory_(protocolFactory) {}
+    inputTransportFactory_(transportFactory),
+    outputTransportFactory_(transportFactory),
+    inputProtocolFactory_(protocolFactory),
+    outputProtocolFactory_(protocolFactory) {}
 
   TServer(shared_ptr<TProcessor> processor,
           shared_ptr<TServerTransport> serverTransport,
-          shared_ptr<TTransportFactory> transportFactory) :
+          shared_ptr<TTransportFactory> inputTransportFactory,
+          shared_ptr<TTransportFactory> outputTransportFactory,
+          shared_ptr<TProtocolFactory> inputProtocolFactory,
+          shared_ptr<TProtocolFactory> outputProtocolFactory):
     processor_(processor),
     serverTransport_(serverTransport),
-    transportFactory_(transportFactory) {
-  protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory());
- }
+    inputTransportFactory_(inputTransportFactory),
+    outputTransportFactory_(outputTransportFactory),
+    inputProtocolFactory_(inputProtocolFactory),
+    outputProtocolFactory_(outputProtocolFactory) {}
 
-  TServer(shared_ptr<TProcessor> processor,
-          shared_ptr<TServerTransport> serverTransport) :
-    processor_(processor),
-    serverTransport_(serverTransport) {
-    transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory());
-    protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory());
-  }
-
-  TServer(shared_ptr<TProcessor> processor) :
-    processor_(processor) {
-    transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory());
-    protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory());
-  }
-
-  TServer(shared_ptr<TProcessor> processor, 
-          shared_ptr<TTransportFactory> transportFactory) :
-    processor_(processor),
-    transportFactory_(transportFactory) {
-    protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory());
-  }
-
-  TServer(shared_ptr<TProcessor> processor, 
-          shared_ptr<TProtocolFactory> protocolFactory) :
-    processor_(processor) {
-    transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory());
-    protocolFactory_ = protocolFactory;
-  }
-
-  TServer(shared_ptr<TProcessor>        processor,           
-          shared_ptr<TProtocolFactory>  protocolFactory,
-          shared_ptr<TTransportFactory> transportFactory):
-    processor_(processor),
-    transportFactory_(transportFactory),
-    protocolFactory_(protocolFactory) {}
  
+  // Class variables
   shared_ptr<TProcessor> processor_;
   shared_ptr<TServerTransport> serverTransport_;
-  shared_ptr<TTransportFactory> transportFactory_;
-  shared_ptr<TProtocolFactory> protocolFactory_;
+
+  shared_ptr<TTransportFactory> inputTransportFactory_;
+  shared_ptr<TTransportFactory> outputTransportFactory_;
+
+  shared_ptr<TProtocolFactory> inputProtocolFactory_;
+  shared_ptr<TProtocolFactory> outputProtocolFactory_;
+
+  void setInputTransportFactory(shared_ptr<TTransportFactory> inputTransportFactory) {
+    inputTransportFactory_ = inputTransportFactory;
+  }
+
+  void setOutputTransportFactory(shared_ptr<TTransportFactory> outputTransportFactory) {
+    outputTransportFactory_ = outputTransportFactory;
+  }
+
+  void setInputProtocolFactory(shared_ptr<TProtocolFactory> inputProtocolFactory) {
+    inputProtocolFactory_ = inputProtocolFactory;
+  }
+
+  void setOutputProtocolFactory(shared_ptr<TProtocolFactory> outputProtocolFactory) {
+    outputProtocolFactory_ = outputProtocolFactory;
+  }
+
 };
   
 }}} // facebook::thrift::server