You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/08/02 16:59:09 UTC
svn commit: r1368504 - in /incubator/etch/trunk/binding-cpp/runtime:
include/transport/ src/main/ src/main/transport/
Author: veithm
Date: Thu Aug 2 14:59:08 2012
New Revision: 1368504
URL: http://svn.apache.org/viewvc?rev=1368504&view=rev
Log:
ETCH-216 : Implementation of EtchTransportFactories
- EtchTransportFactory (basic Interface)
- EtchTCPTransportFactory
Change-Id: Iee18c9c7ee176fdcc0c9e649f305181a9d32a351
Added:
incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportFactory.h
incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
Added: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h?rev=1368504&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h Thu Aug 2 14:59:08 2012
@@ -0,0 +1,145 @@
+/* $Id$
+ *
+ * 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 __ETCHTCPTRANSPORTFACTORY_H__
+#define __ETCHTCPTRANSPORTFACTORY_H__
+
+#include "common/EtchString.h"
+#include "common/EtchConfig.h"
+#include "support/EtchServerFactory.h"
+#include "transport/EtchTransportMessage.h"
+#include "transport/EtchTransportData.h"
+#include "transport/EtchTcpConnection.h"
+#include "transport/EtchTransportPacket.h"
+#include "transport/EtchPacketizer.h"
+#include "transport/EtchTcpConnection.h"
+#include "transport/EtchTcpListener.h"
+#include "transport/EtchMessagizer.h"
+#include "transport/EtchTransportFactory.h"
+#include "util/EtchResources.h"
+
+class EtchTcpTransportFactory : public EtchTransportFactory {
+public:
+ /**
+ * Constructor
+ */
+ EtchTcpTransportFactory();
+
+ /**
+ * Constructor
+ * @param secure indicates whether the connection should be secured by SSL or not
+ */
+ EtchTcpTransportFactory(capu::bool_t secure);
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchTcpTransportFactory();
+
+ /**
+ * @see EtchTransportFactory
+ */
+ status_t newTransport(EtchString uri, EtchResources* resources, EtchTransportMessage*& result);
+
+ /**
+ * @see EtchTransportFactory
+ */
+ status_t newListener(EtchString uri, EtchResources* resources, EtchTransport<EtchServerFactory>*& result);
+
+private:
+ static const EtchString SOCKET;
+ const capu::bool_t mIsSecure;
+
+
+ class MySessionListener : public EtchTransport<EtchServerFactory>, public EtchSessionListener<EtchSocket> {
+ public:
+
+ /**
+ * Creates a new Session Listener
+ * @param transport
+ * @param uri
+ * @param resources
+ */
+ MySessionListener(EtchTransport<EtchSessionListener<EtchSocket> > *transport,
+ EtchString uri, EtchResources* resources, capu::bool_t secure);
+
+ /**
+ * Destructor
+ */
+ virtual ~MySessionListener();
+
+ /**
+ * @see EtchTransport
+ */
+ EtchServerFactory* getSession();
+
+ /**
+ * @see EtchTransport
+ */
+ void setSession(EtchServerFactory* session);
+
+ /**
+ * @see EtchTransport
+ */
+ status_t transportQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result);
+
+ /**
+ * @see EtchTransport
+ */
+ status_t transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value);
+
+ /**
+ * @see EtchTransport
+ */
+ status_t transportNotify(capu::SmartPointer<EtchObject> event);
+
+ /**
+ * @see EtchSessionListener
+ */
+ status_t sessionAccepted(EtchSocket* connection);
+
+ /**
+ * @see EtchSessionListener
+ */
+ status_t sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result);
+
+ /**
+ * @see EtchSessionListener
+ */
+ status_t sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value);
+
+ /**
+ * @see EtchSessionListener
+ */
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event);
+
+ private:
+ EtchTransport<EtchSessionListener<EtchSocket> > *mTransport;
+ EtchString mUri;
+ EtchResources* mResources;
+ EtchServerFactory* mSession;
+ capu::bool_t mIsSecure;
+
+ };
+
+};
+
+
+#endif
+
Added: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportFactory.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportFactory.h?rev=1368504&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportFactory.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportFactory.h Thu Aug 2 14:59:08 2012
@@ -0,0 +1,123 @@
+/* $Id$
+ *
+ * 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 __ETCHTRANSPORTFACTORY_H__
+#define __ETCHTRANSPORTFACTORY_H__
+
+#include "common/EtchTypes.h"
+#include "common/EtchError.h"
+#include "support/EtchServerFactory.h"
+#include "transport/EtchTransport.h"
+#include "transport/EtchTransportMessage.h"
+#include "util/EtchResources.h"
+#include "util/EtchURL.h"
+
+/**
+ * Interface to transport factory.
+ */
+class EtchTransportFactory {
+public:
+ /**
+ * Query term on the transport uri which defines a set of filters which
+ * process messages as they move up and down the transport stack. Filter
+ * names are separated by one or more of these characters: ",:;| \t\r\n".
+ */
+ const static EtchString FILTER;
+
+ /**
+ * Constructs a new Transport stack topped by a TransportMessage
+ * which is used by the remote service implementations to send
+ * messages.
+ * @param uri transport configuration parameters.
+ * @param resources additional resources needed by the stack.
+ * @param result the TransportMessage topping the transport stack.
+ * @return ETCH_ENOT_EXIST if the required transport method is not available or not implememted
+ ETCH_OK otherwise
+ */
+ static status_t getTransport(EtchString uri, EtchResources* resources, EtchTransportMessage*& result);
+
+ /**
+ * Constructs a new Transport Listener which is used to construct
+ * server sessions.
+ * @param uri listener configuration parameters.
+ * @param resources additional resources needed by the listener.
+ * @param result an out-of-band source which may be used to control the listener.
+ * @return ETCH_ENOT_EXIST if the required listener is not available or not implememted
+ ETCH_OK otherwise
+ */
+ static status_t getListener(EtchString uri, EtchResources* resources, EtchTransport<EtchServerFactory>*& result);
+
+
+protected:
+ /**
+ * Destructor
+ */
+ virtual ~EtchTransportFactory();
+
+ /**
+ * Constructs a new Transport stack topped by a TransportMessage
+ * which is used by the remote service implementations to send
+ * messages.
+ * @param uri transport configuration parameters.
+ * @param resources additional resources needed by the stack.
+ * @param result the TransportMessage topping the transport stack.
+ * @return ETCH_ENOT_EXIST if the required transport method is not available or not implememted
+ ETCH_OK otherwise
+ */
+ virtual status_t newTransport(EtchString uri, EtchResources* resources, EtchTransportMessage*& result) = 0;
+
+
+ /**
+ * Constructs a new Transport Listener which is used to construct
+ * server sessions.
+ * @param uri listener configuration parameters.
+ * @param resources additional resources needed by the listener.
+ * @param result an out-of-band source which may be used to control the listener.
+ * @return ETCH_ENOT_EXIST if the required listener is not available or not implememted
+ ETCH_OK otherwise
+ */
+ virtual status_t newListener(EtchString uri, EtchResources* resources, EtchTransport<EtchServerFactory>*& result) = 0;
+
+ /**
+ * Adds any message filters specified on the uri. They are added in order
+ * from transport to session. The first filter is the session for Messagizer,
+ * the second is the session for the first, etc. The last filter added is
+ * returned, and becomes the TransportMessage for what follows.
+ * @param transport
+ * @param uri
+ * @param resources
+ * @param filter the newly added filter
+ */
+ status_t addFilters(EtchTransportMessage* transport, EtchURL* uri, EtchResources* resources, EtchTransportMessage*& filter);
+
+private:
+
+ status_t addFilter(EtchTransportMessage* transport, EtchString* name, EtchURL* uri, EtchResources* resources, EtchTransportMessage*& filter);
+ /**
+ * Gets the named transport factory.
+ * @param name the name of a configured transport factory.
+ * @param the named transport factory.
+ * @return ETCH_ENOT_EXIST if the requested transportfactory does not exist
+ ETCH_OK otherwise
+ */
+ static status_t getTransportFactory(const EtchString& name, EtchTransportFactory*& result);
+
+};
+#endif /* __ETCHTRANSPORTFACTORY_H__ */
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1368504&r1=1368503&r2=1368504&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Thu Aug 2 14:59:08 2012
@@ -121,7 +121,9 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/support/EtchRemoteBase.h
${PROJECT_SOURCE_DIR}/include/support/EtchServerFactory.h
${PROJECT_SOURCE_DIR}/include/support/EtchStubHelper.h
- ${PROJECT_SOURCE_DIR}/include/support/EtchStubBase.h
+ ${PROJECT_SOURCE_DIR}/include/support/EtchStubBase.h
+ ${PROJECT_SOURCE_DIR}/include/transport/EtchTransportFactory.h
+ ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpTransportFactory.h
${PROJECT_SOURCE_DIR}/include/support/EtchTransportHelper.h
${PROJECT_SOURCE_DIR}/include/support/EtchPlainMailbox.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
@@ -162,6 +164,8 @@ SET(MAIN_SOURCES
transport/EtchMessagizer.cpp
transport/EtchFormat.cpp
transport/EtchPlainMailboxManager.cpp
+ transport/EtchTransportFactory.cpp
+ transport/EtchTcpTransportFactory.cpp
serialization/EtchTypeValidator.cpp
serialization/EtchValidatorBoolean.cpp
serialization/EtchValidatorByte.cpp
@@ -199,6 +203,8 @@ SET(MAIN_SOURCES
support/EtchDefaultServerFactory.cpp
support/EtchStubBase.cpp
support/EtchRemoteBase.cpp
+ transport/EtchTransportFactory.cpp
+ transport/EtchTcpTransportFactory.cpp
support/EtchTransportHelper.cpp
util/EtchCircularQueue.cpp
util/EtchUtil.cpp
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp?rev=1368504&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp Thu Aug 2 14:59:08 2012
@@ -0,0 +1,163 @@
+/* $Id$
+ *
+ * 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 "transport/EtchTcpTransportFactory.h"
+
+const EtchString EtchTcpTransportFactory::SOCKET("TcpTransportFactory.socket");
+
+EtchTcpTransportFactory::EtchTcpTransportFactory()
+: mIsSecure(false) {
+
+}
+
+EtchTcpTransportFactory::EtchTcpTransportFactory(capu::bool_t secure)
+: mIsSecure(secure) {
+
+}
+
+EtchTcpTransportFactory::~EtchTcpTransportFactory() {
+
+}
+
+status_t EtchTcpTransportFactory::newTransport(EtchString uri, EtchResources* resources, EtchTransportMessage*& result) {
+ EtchURL u(uri);
+
+ EtchObject* socket = NULL;
+ if (resources->get((EtchString &) SOCKET, socket) != ETCH_OK) {
+ return ETCH_ENOT_EXIST;
+ }
+
+ EtchTransportData *c = NULL;
+
+ if (mIsSecure) {
+ //TODO : secure communication via ssl sockets
+ return ETCH_ENOT_EXIST;
+ } else {
+ c = new EtchTcpConnection((EtchSocket*) socket, &u);
+ }
+
+ EtchTransportPacket* p = new EtchPacketizer(c, &u);
+
+ EtchTransportMessage* m = new EtchMessagizer(p, &u, resources);
+
+ //TODO: ADD FILTERS HERE
+
+ EtchObject* obj = NULL;
+ EtchString tmp(EtchTransport<EtchSocket>::VALUE_FACTORY);
+ if (resources->get(tmp, obj) != ETCH_OK) {
+ c->setSession(NULL);
+ p->setSession(NULL);
+ m->setSession(NULL);
+ delete c;
+ delete p;
+ delete m;
+ return ETCH_ENOT_EXIST;
+ }
+ EtchValueFactory *vf = (EtchValueFactory*) obj;
+
+ vf->lockDynamicTypes();
+ result = m;
+ return ETCH_OK;
+}
+
+status_t EtchTcpTransportFactory::newListener(EtchString uri, EtchResources* resources, EtchTransport<EtchServerFactory>*& result) {
+ EtchURL u(uri);
+
+ EtchTransport<EtchSessionListener<EtchSocket> > *l = NULL;
+ if (mIsSecure) {
+ //TODO secure communication
+ return ETCH_ENOT_EXIST;
+ } else {
+ l = new EtchTcpListener(&u);
+ }
+
+ result = new MySessionListener(l, uri, resources, mIsSecure);
+ if (result == NULL) {
+ return ETCH_ENOT_EXIST;
+ }
+ return ETCH_OK;
+}
+
+EtchTcpTransportFactory::MySessionListener::MySessionListener(EtchTransport<EtchSessionListener<EtchSocket> > *transport, EtchString uri, EtchResources* resources, capu::bool_t secure)
+: mTransport(transport), mUri(uri), mResources(resources), mIsSecure(secure) {
+ if (transport != NULL) {
+ transport->setSession(this);
+ }
+}
+
+EtchServerFactory* EtchTcpTransportFactory::MySessionListener::getSession() {
+ return mSession;
+}
+
+void EtchTcpTransportFactory::MySessionListener::setSession(EtchServerFactory* session) {
+ mSession = session;
+}
+
+status_t EtchTcpTransportFactory::MySessionListener::transportQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result) {
+ return mTransport->transportQuery(query, result);
+}
+
+status_t EtchTcpTransportFactory::MySessionListener::transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+ return mTransport->transportControl(control, value);
+}
+
+status_t EtchTcpTransportFactory::MySessionListener::transportNotify(capu::SmartPointer<EtchObject> event) {
+ return mTransport->transportNotify(event);
+}
+
+status_t EtchTcpTransportFactory::MySessionListener::sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result) {
+ return mSession->sessionQuery(query, result);
+}
+
+status_t EtchTcpTransportFactory::MySessionListener::sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+ return mSession->sessionControl(control, value);
+}
+
+status_t EtchTcpTransportFactory::MySessionListener::sessionNotify(capu::SmartPointer<EtchObject> event) {
+ return mSession->sessionNotify(event);
+}
+
+status_t EtchTcpTransportFactory::MySessionListener::sessionAccepted(EtchSocket* connection) {
+ if (connection == NULL) {
+ return ETCH_ERROR;
+ }
+
+ EtchResources *res = new EtchResources(mResources);
+ EtchObject *obj = NULL;
+ if (res->put((EtchString &) SOCKET, connection, obj) != ETCH_OK) {
+ delete res;
+ return ETCH_ERROR;
+ }
+
+ EtchValueFactory* vf = NULL;
+ if (mSession->newValueFactory(&mUri, vf) != ETCH_OK) {
+ delete res;
+ return ETCH_ERROR;
+ }
+ if (res->put((EtchString &) VALUE_FACTORY, vf, obj)) {
+ delete res;
+ return ETCH_ERROR;
+ }
+
+ EtchTransportMessage *t = NULL;
+ if (getTransport(mUri, res, t) != ETCH_OK) {
+ delete res;
+ return ETCH_ERROR;
+ }
+
+ return mSession->newServer(t, &mUri, res);
+}
\ No newline at end of file
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp?rev=1368504&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp Thu Aug 2 14:59:08 2012
@@ -0,0 +1,74 @@
+/* $Id$
+ *
+ * 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 "transport/EtchTransportFactory.h"
+#include "transport/EtchTcpTransportFactory.h"
+
+const EtchString EtchTransportFactory::FILTER("filter");
+
+
+EtchTransportFactory::~EtchTransportFactory() {
+
+}
+
+status_t EtchTransportFactory::addFilters(EtchTransportMessage* transport, EtchURL* uri, EtchResources* resources, EtchTransportMessage *& filter) {
+ //TODO: Add implementation
+ return ETCH_EUNIMPL;
+}
+
+status_t EtchTransportFactory::addFilter(EtchTransportMessage* transport, EtchString* name, EtchURL* uri, EtchResources* resources, EtchTransportMessage *& filter) {
+ //TODO: Add implementation
+ return ETCH_EUNIMPL;
+}
+
+status_t EtchTransportFactory::getTransport(EtchString uri, EtchResources* resources, EtchTransportMessage*& result) {
+ EtchURL u(uri);
+ EtchTransportFactory* f = NULL;
+ if (getTransportFactory(u.getScheme(), f) != ETCH_OK) {
+ return ETCH_ENOT_EXIST;
+ }
+ if (f == NULL) {
+ return ETCH_ENOT_EXIST;
+ }
+ return f->newTransport(uri, resources, result);
+}
+
+status_t EtchTransportFactory::getListener(EtchString uri, EtchResources* resources, EtchTransport<EtchServerFactory>*& result) {
+ EtchURL u(uri);
+ EtchTransportFactory* f = NULL;
+ if (getTransportFactory(u.getScheme(), f) != ETCH_OK) {
+ return ETCH_ENOT_EXIST;
+ }
+ if (f == NULL) {
+ return ETCH_ENOT_EXIST;
+ }
+ return f->newListener(uri, resources, result);
+}
+
+status_t EtchTransportFactory::getTransportFactory(const EtchString& name, EtchTransportFactory*& result) {
+ EtchString tmp("tcp");
+ if (name.equals(&tmp)) {
+ result = new EtchTcpTransportFactory();
+ return ETCH_OK;
+ }
+ //TODO: result = new EtchUdpTransprtFactory();
+ return ETCH_ENOT_EXIST;
+
+}