Add method to shutdown all connections

All connections are closed and the method waits until the connection
threads are terminated.

Change-Id: I079d216bd7a101514fbe10b1f1542e7033f8ea6e

git-svn-id: https://svn.apache.org/repos/asf/etch/trunk@1679594 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/runtime/include/transport/EtchConnection.h b/binding-cpp/runtime/include/transport/EtchConnection.h
index ab712c6..1585589 100644
--- a/binding-cpp/runtime/include/transport/EtchConnection.h
+++ b/binding-cpp/runtime/include/transport/EtchConnection.h
@@ -33,6 +33,8 @@
 class EtchConnection : public virtual EtchTransport<S> {
 public:
 
+  friend class EtchTcpTransportFactory;
+
   /**
    * Default Constructor
    */
diff --git a/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h b/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
index 08ce5f4..342bcff 100644
--- a/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
+++ b/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
@@ -136,6 +136,8 @@
     status_t sessionNotify(capu::SmartPointer<EtchObject> event);
 
   private:
+    void shutdownAllConnections();
+
     EtchRuntime* mRuntime;
     EtchTcpTransportFactory* mFactory;
     EtchTransport<EtchSessionListener<EtchSocket> > *mTransport;
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
index 3c49679..15f3422 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
@@ -191,6 +191,24 @@
 
 }
 
+void EtchTcpTransportFactory::MySessionListener::shutdownAllConnections()
+{
+    EtchList<EtchStack*>::Iterator it = mConnectionStacks->begin();
+    while (it.hasNext()) {
+        EtchStack* stack = NULL;
+        status_t res = it.current(stack);
+        if (res == ETCH_OK) {
+            EtchTcpConnection* con = (EtchTcpConnection*) stack->getTransportData();
+            if (con != NULL) {
+                con->mIsStarted = false;
+                con->close();
+                con->mThread->join();
+            }
+        }
+        it.next();
+    }
+}
+
 status_t EtchTcpTransportFactory::MySessionListener::sessionAccepted(EtchSocket* connection) {
   if (connection == NULL) {
     return ETCH_ERROR;