ETCH-198 Changes in helper and valuefactory
Refactoring of life cycle and memory management
Change-Id: If74bb9e43e0712fb8dca8cf52d364efa3d5d12a3
git-svn-id: https://svn.apache.org/repos/asf/incubator/etch/trunk@1376588 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java b/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java
index 27ec821..b6100c5 100644
--- a/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java
+++ b/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java
@@ -1186,7 +1186,7 @@
Token t = type.type();
switch (t.kind) {
case EtchGrammarConstants.BOOLEAN:
- return "EtchBool";
+ return "Bool";
case EtchGrammarConstants.BYTE:
return "Byte";
case EtchGrammarConstants.SHORT:
@@ -1202,7 +1202,7 @@
case EtchGrammarConstants.STRING:
return "String";
case EtchGrammarConstants.OBJECT:
- return "";
+ return "Object";
default: {
// we have to use a fully qualified name here.
// find the actual type...
@@ -1258,7 +1258,11 @@
// TODO Auto-generated method stub
if(pointer)
return "EtchNativeArray" + this.getNativeArrayTypeName( type ) + "Ptr";
- return "EtchNativeArray" + this.getNativeArrayTypeName( type ) + "Obj";
+ if (type.type().kind == EtchGrammarConstants.BYTE) {
+ return "EtchNativeArray<" + this.getNativeTypeName( type, true ) + "> ";
+ } else {
+ return "EtchNativeArray<" + this.getNativeTypeName( type, true ) + "Ptr> ";
+ }
}
public String getNativeTypeName(TypeRef type, boolean etch_type) {
@@ -1269,7 +1273,7 @@
case EtchGrammarConstants.BOOLEAN:
return (etch_type ? "EtchBool" : "capu::bool_t");
case EtchGrammarConstants.BYTE:
- return (etch_type ? "EtchByte" : "capu::int8_t");
+ return (etch_type ? "capu::int8_t" : "capu::int8_t");
case EtchGrammarConstants.SHORT:
return (etch_type ? "EtchShort" : "capu::int16_t");
case EtchGrammarConstants.INT:
@@ -1295,7 +1299,10 @@
if (n.isBuiltin()) {
Builtin b = (Builtin) n;
if (n.efqname(this).equals("EtchDate")) return b.className();
- return b.className() + "Obj";
+ if (n.efqname(this).equals("EtchHashTable")) return b.className()+"<EtchObjectPtr, EtchObjectPtr> ";
+ if (n.efqname(this).equals("EtchHashSet")) return b.className()+"<EtchObjectPtr> ";
+ throw new IllegalArgumentException(String.format(
+ "unable to find correct Etch data type for type at line %d: %s", t.beginLine, n.efqname(this)));
}
if (n.isEnumx()) {
return n.efqname(this);
@@ -1494,8 +1501,13 @@
Builtin b = (Builtin) n;
String cn = b.className();
- if (!n.efqname(this).equals("EtchDate"))
- cn += "Obj";
+ if (n.efqname(this).equals("EtchHashTable")) {
+ cn += "<EtchObjectPtr, EtchObjectPtr>";
+ }
+ if (n.efqname(this).equals("EtchHashSet")) {
+ cn += "<EtchObjectPtr>";
+ }
+
/*
* int i = cn.indexOf( '<' ); if (i >= 0) cn = cn.substring( 0, i );
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
index 7c7da98..8b35c5b 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
@@ -35,12 +35,8 @@
#end
\#include "support/EtchRuntime.h"
-#if($helper.isServer($mc) || $helper.isBoth($mc))
-\#include "support/EtchServerStack.h"
-#end
-#if($helper.isClient($mc) || $helper.isBoth($mc))
-\#include "support/EtchClientStack.h"
-#end
+\#include "support/EtchStackClient.h"
+\#include "support/EtchStackServer.h"
\#include "support/EtchPool.h"
\#include "transport/EtchPlainMailboxManager.h"
\#include "transport/EtchDefaultDeliveryService.h"
@@ -61,6 +57,10 @@
status_t $clname::Listener${i}Server::newServer(EtchRuntime* runtime, EtchTransportMessage* transport, const EtchString& uri, EtchResources* resources)
{
+ //get stack instance
+ EtchStackServer* stack = NULL;
+ resources->get(EtchStack::STACK(), (EtchObject*&)stack );
+
//get value factory
EtchObject* obj;
resources->get( EtchTransport<EtchValueFactory*>::VALUE_FACTORY(), obj );
@@ -68,8 +68,11 @@
//create stack layers
EtchMailboxManager* mbm = new EtchPlainMailboxManager(transport, uri, resources);
+ stack->setMailboxManager(mbm);
EtchDeliveryService* dvs = new EtchDefaultDeliveryService(mbm, uri);
- Remote${i}Client* client = new Remote${i}Client(runtime, dvs, vf);
+ stack->setDeliveryService(dvs);
+ Remote${i}Client* client = new Remote${i}Client(runtime, dvs, vf, stack);
+ stack->setRemote(client);
${i}Server* server = mFactory->new${i}Server(client);
//get thread pools
@@ -81,7 +84,9 @@
//create stub
Stub${i}Server* tmp${i}Server = new Stub${i}Server(dvs, server, qp, fp);
- EtchStack* stack = new EtchServerStack(client, tmp${i}Server, resources, vf);
+ stack->setStub(tmp${i}Server);
+
+ //start remote client
client->start();
return ETCH_OK;
}
@@ -117,7 +122,7 @@
status_t status = ETCH_OK;
//static initialization of value factory
- ValueFactory${i}::__INIT(runtime);
+ ValueFactory${i}::InitValueFactory(runtime);
//init resources
EtchResources *res;
@@ -159,8 +164,10 @@
{
status_t status = ETCH_OK;
+ EtchStackClient* stack = new EtchStackClient();
+
//static initialization of value factory
- ValueFactory${i}::__INIT(runtime);
+ ValueFactory${i}::InitValueFactory(runtime);
//init resources
EtchResources* res;
@@ -169,6 +176,10 @@
return status;
}
+ EtchObject* tmp = NULL;
+ res->put(EtchStack::STACK(),stack, tmp);
+ stack->mStaticResources = res;
+
//create valuefactory instance
ValueFactory${i}* vf = new ValueFactory${i}(uri);
EtchObject* vfobj = (EtchObject*) vf;
@@ -180,8 +191,10 @@
EtchTransportMessage* m;
EtchTransportFactory::getTransport(runtime, uri, res, m);
EtchMailboxManager* mbm = new EtchPlainMailboxManager(m, uri, res);
+ stack->setMailboxManager(mbm);
EtchDeliveryService* dvs = new EtchDefaultDeliveryService(mbm, uri);
- Remote${i}Server* _server = new Remote${i}Server(runtime, dvs, vf);
+ stack->setDeliveryService(dvs);
+ Remote${i}Server* _server = new Remote${i}Server(runtime, dvs, vf, stack);
${i}Client* client = implFactory.new${i}Client( server );
//get pools
@@ -193,7 +206,7 @@
//init stub
Stub${i}Client* tmpStub${i}Client = new Stub${i}Client(dvs, client, qp, fp);
- EtchStack* stack = new EtchClientStack(server, tmpStub${i}Client, res, vf);
+ stack->setStub(tmpStub${i}Client);
//return server
server = _server;
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_h.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_h.vm
index e1bbd55..fae79b6 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_h.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_h.vm
@@ -147,7 +147,7 @@
#end
#if($helper.isClient($mc) || $helper.isBoth($mc))
- static status_t newServer(EtchRuntime* runtime, EtchString uri, EtchResources* resources, ${i}ClientFactory& implFactory, RemoteHelloWorldServer*& server);
+ static status_t newServer(EtchRuntime* runtime, EtchString uri, EtchResources* resources, ${i}ClientFactory& implFactory, Remote${i}Server*& server);
#end
};
}
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/intf_h.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/intf_h.vm
index 13e19b0..2d6ce96 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/intf_h.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/intf_h.vm
@@ -98,7 +98,7 @@
* $s
#end
*/
- $i.name()#if($enumHelper < $count),#end
+ $n.name()_$i.name()#if($enumHelper < $count),#end
#end
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
index 0a5e241..c08c498 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
@@ -70,7 +70,7 @@
return ETCH_OK;
}
-$intfname::$n.name()AsyncResultPtr $clname::$n.name()AsyncResultRemote::Begin($clname* base, #set($sep = "")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name()#set($sep = ", ")#end) {
+$intfname::$n.name()AsyncResultPtr $clname::$n.name()AsyncResultRemote::Begin($clname* base#set($sep = ", ")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name()#end) {
status_t status;
capu::SmartPointer<EtchMessage> msg;
@@ -108,11 +108,11 @@
* @param vf
*/
#if($hasBaseClass)
-$clname::$clname(EtchRuntime* runtime, EtchDeliveryService* svc, EtchValueFactory* vf )
- : Remote${i}(runtime, svc, vf) {
+$clname::$clname(EtchRuntime* runtime, EtchDeliveryService* svc, EtchValueFactory* vf, EtchStack* stack )
+ : Remote${i}(runtime, svc, vf, stack) {
#else
-$clname::$clname(EtchRuntime* runtime, EtchDeliveryService* svc, EtchValueFactory* vf )
- : EtchRemoteBase(svc, vf), mRuntime(runtime) {
+$clname::$clname(EtchRuntime* runtime, EtchDeliveryService* svc, EtchValueFactory* vf, EtchStack* stack )
+ : EtchRemoteBase(svc, vf, stack), mRuntime(runtime) {
#end
}
@@ -131,7 +131,7 @@
}
#else
$intfname::$n.name()AsyncResultPtr $clname::$n.name()(#set( $sep = "" )#foreach( $p in $n.iterator() )$sep$helper.getEtchTypeName( $p.type(), true ) $p.name() #set( $sep = ", " )#end) {
- $n.name()AsyncResultPtr result = $clname::$n.name()AsyncResultRemote::Begin(this, #set($sep = "")#foreach($p in $n.iterator())$p.name() #set( $sep = ", ")#end);
+ $n.name()AsyncResultPtr result = $clname::$n.name()AsyncResultRemote::Begin(this#set( $sep = ", ")#foreach($p in $n.iterator())$sep$p.name()#end);
return result;
}
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
index 2e5bce7..bfc8f97 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
@@ -33,7 +33,7 @@
#if(!$hasBaseClass)
\#include "support/EtchRemoteBase.h"
#else
-\#include "ValueFactoryHelloWorld.h"
+\#include "${vfname}.h"
\#include "$inc"
\#include "Remote${i}.h"
#end
@@ -79,7 +79,7 @@
/**
* Create a new instance from $clname class
*/
- static $n.name()AsyncResultPtr Begin($clname* base, #set($sep = "")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name()#set($sep = ", ")#end);
+ static $n.name()AsyncResultPtr Begin($clname* base#set($sep = ", ")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name()#end);
private:
$clname* mBase;
@@ -94,8 +94,9 @@
*
* @param svc
* @param vf
+ * @param stack
*/
- $clname(EtchRuntime* runtime, EtchDeliveryService* svc, EtchValueFactory* vf );
+ $clname(EtchRuntime* runtime, EtchDeliveryService* svc, EtchValueFactory* vf, EtchStack* stack );
/**
* Destructor
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/stub_h.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/stub_h.vm
index 8105003..b36ce25 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/stub_h.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/stub_h.vm
@@ -143,33 +143,33 @@
{
}
virtual ~Stub$i$suffix() {}
- static void init()
- {
- // nothing to do.
- }
-
+
##if($notEmpty)
- /*
- * Static Initialization-Helper
- */
+
private:
friend class ValueFactory${i};
- static void __INIT()
+
+ /**
+ * Static Initialization-Helper
+ */
+ static status_t Init()
{
-#foreach( $mthd in $intf.iterator() )
-#if ($mthd.isMsgDir($mc))
-#if (!$mthd.isHidden())
- ValueFactory$i::${mthd.vname( $helper )}->setStubHelper(new Run${mthd.vname($helper)}());
-#end
-#end
-#if( $n.isMixin() )
-#set( $m = $n.getModule() )
-#set( $z = $m.iterator().next() )
- ${m.name()}::Stub${z.name()}${suffix}::init();
-#end
-#end
+ #foreach( $mthd in $intf.iterator() )
+ #if ($mthd.isMsgDir($mc))
+ #if (!$mthd.isHidden())
+ ValueFactory$i::${mthd.vname( $helper )}->setStubHelper(new Run${mthd.vname($helper)}());
+ #end
+ #end
+ #if( $n.isMixin() )
+ #set( $m = $n.getModule() )
+ #set( $z = $m.iterator().next() )
+ ${m.name()}::Stub${z.name()}${suffix}::Init();
+ #end
+ #end
+ return ETCH_OK;
}
+
##end
};
}
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
index 3d5829b..98ebbbb 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
@@ -26,17 +26,37 @@
#set( $vf = "ValueFactory$intf.name()" )
\#include "$inc"
+\#include "${intf.name()}.h"
+\#include "Stub${i}Server.h"
+\#include "Stub${i}Client.h"
\#include "common/EtchError.h"
\#include "serialization/EtchField.h"
\#include "serialization/EtchAsyncMode.h"
\#include "serialization/EtchDirection.h"
-\#include "${intf.name()}.h"
\#include "serialization/EtchValidators.h"
-\#include "Stub${i}Server.h"
-\#include "Stub${i}Client.h"
using namespace $namespace;
+status_t $vf::Etch${intf.name()}RuntimeListener::onRuntimeChanged(EtchRuntime* runtime) {
+ capu::int_t index = $vf::SRuntimes.find(runtime->getId());
+ if (index == -1) {
+ return ETCH_ERROR;
+ }
+ if (runtime->isClosed()) {
+ //the runtime is closed and is removed
+ $vf::SRuntimes.removeAt(index);
+ }
+ if ($vf::SRuntimes.isEmpty()) {
+ //clean up all static members
+ $vf::DestroyValueFactory();
+ }
+ return ETCH_OK;
+}
+
+capu::Mutex $vf::SRuntimesMutex;
+capu::List<capu::uint64_t> $vf::SRuntimes;
+$vf::Etch${intf.name()}RuntimeListener $vf::S${intf.name()}RuntimeListener;
+
##--------------------------------------------------------------
## Classes that represent anonym creation in java
##--------------------------------------------------------------
@@ -90,7 +110,7 @@
switch (v->Value)
{
#foreach ($p in $n.iterator())
- case $tname::$p.name(): _struct->put($vf::$p.vname($helper)(), new EtchBool(true) ); break;
+ case $tname::${tname}_$p.name(): _struct->put($vf::$p.vname($helper)(), new EtchBool(true) ); break;
#end
}
result = _struct;
@@ -105,11 +125,14 @@
return ETCH_EINVAL;
// there should only be a single key, so take the first one
- EtchField key = value->getFirstField();
+ EtchHashTable<EtchField, capu::SmartPointer<EtchObject> >::Iterator it = value->begin();
+ EtchHashTable<EtchField, capu::SmartPointer<EtchObject> >::Pair pair;
+ it.next(&pair);
+ EtchField key = pair.first;
#foreach ($p in $n.iterator())
if (key.equals(&$vf::$p.vname($helper)()))
{
- result = new ${tname}(${tname}::$p.name());
+ result = new ${tname}(${tname}::${tname}_$p.name());
return ETCH_OK;
}
#end
@@ -170,16 +193,17 @@
#end
}
-void ${vf}::initTypes()
+status_t ${vf}::InitTypes()
{
#foreach ( $n in $intf.iterator() )
#if ($n.isEnumx() || $n.isStruct() || $n.isExtern() || $n.isExcept() || $n.isMessage())
types()->get(EtchString("$n.fqname()"), ${vf}::${n.vname( $helper )});
#end
#end
+ return ETCH_OK;
}
-void ${vf}::initResults()
+status_t ${vf}::InitResults()
{
//AF: TO-REVIEW: finde die Verwendung von Anonymer Enum bei EchtDirection und bei EtchAsyncMode unschoen
@@ -202,10 +226,11 @@
#end
#end
#end
+ return ETCH_OK;
}
## ----------------------------- import / export -----------------------------
-void ${vf}::initImportExport()
+status_t ${vf}::InitImportExport()
{
#foreach ( $n in $intf.iterator() )
#if ($n.isStruct() || $n.isExcept())
@@ -225,11 +250,13 @@
$vf::${n.vname( $helper )}->setImportExportHelper(new ImportExportHelper$n.vname($helper)());
#end
#end
+
+ return ETCH_OK;
}
## ----------------------------- fields -----------------------------
-void ${vf}::initFields()
+status_t ${vf}::InitFields()
{
#set( $x = $params.clear() )
## standard params from DefaultValueFactory
@@ -245,24 +272,17 @@
#end
#end
#end
+ return ETCH_OK;
}
#set( $ctr = 0 )
-void $vf::initParams()
+status_t $vf::InitParams()
{
capu::SmartPointer<EtchValidator> tmpValue;
#foreach( $n in $intf.iterator() )
#if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
-#if ($ctr > 0 && $ctr % 100 == 0)
- initParams${ctr}();
-}
-
-void $vf::initParams${ctr}()
-{
- capu::SmartPointer<EtchValidator> tmpValue;
-#end
#set( $ctr = $ctr + 1 )
// params for $n.name()
#if ($n.isStruct() || $n.isExcept())
@@ -270,14 +290,14 @@
$helper.getValidator($param);
$vf::${n.vname( $helper )}->putValidator($vf::$param.vname($helper)(), tmpValue);
-#end
+#end ## -- foreach --
#else
#foreach( $param in $n.iterator() )
$helper.getValidator($param);
$vf::${n.vname( $helper )}->putValidator($vf::$param.vname($helper)(), tmpValue);
-#end
-#end
+#end ## -- foreach --
+#end ## -- else --
#if ($n.isMessage())
EtchValidatorLong::Get(0, tmpValue);
${n.vname( $helper )}->putValidator($vf::_mf__messageId(), tmpValue);
@@ -289,52 +309,104 @@
$helper.getValidator($t)
$vf::${n.vname( $helper )}->putValidator($vf::$param.vname($helper)(), tmpValue); // thrown $t.name()
-#end
+#end ## -- foreach --
EtchValidatorRuntimeException::Get(tmpValue);
$vf::${n.vname( $helper )}->putValidator($vf::$param.vname($helper)(), tmpValue); // thrown RuntimeException
EtchValidatorLong::Get(0, tmpValue);
$vf::${n.vname( $helper )}->putValidator($vf::_mf__inReplyTo(), tmpValue);
+#end ## -- isHidden --
+#end ## -- isMessage --
+#end ## -- $n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage() --
+#end ## -- foreach --
-#end
-#end
-#end
-#end
+ return ETCH_OK;
}
-void $vf::__ShutDown()
+status_t $vf::InitValueFactory(EtchRuntime* runtime)
{
- $vf::types()->clear();
- delete $vf::types();
- delete $vf::class2type();
-}
+ status_t status;
+ SRuntimesMutex.lock();
+ if (SRuntimes.find(runtime->getId()) != -1) {
+ //runtime is already in list
+ return ETCH_OK;
+ }
-/**
- * Static Initialization-Helper
- */
-bool $vf::INIT = false;
-void $vf::__INIT(EtchRuntime* runtime)
-{
- if(INIT)
- return;
- INIT = true;
- $vf::Init( types(), class2type() );
- $vf::initTypes();
- $vf::initResults();
- $vf::initFields();
+ status = SRuntimes.add(runtime->getId());
+ runtime->registerListener(&S${i}RuntimeListener);
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ if (SRuntimes.size() > 1) {
+ //Valuefactory is already initialized
+ SRuntimesMutex.unlock();
+ return ETCH_OK;
+ }
+ SRuntimesMutex.unlock();
+
+ status = $vf::Init( types(), class2type() );
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ status = $vf::InitTypes();
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ status = $vf::InitResults();
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ status = $vf::InitFields();
+ if (status != ETCH_OK) {
+ return status;
+ }
#foreach( $n in $intf.iterator() )
#if ($n.isExtern())
- ${n.sname( $helper )}.init( ${n.vname($helper)}(), class2type );
+ status = ${n.sname( $helper )}.Init( ${n.vname($helper)}(), class2type );
+ if (status != ETCH_OK) {
+ return status;
+ }
#end
#end
- $vf::initParams();
- $vf::initImportExport();
+ status = $vf::InitParams();
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ status = $vf::InitImportExport();
+ if (status != ETCH_OK) {
+ return status;
+ }
- Stub${i}<void>::__INIT();
- Stub${i}Server::__INIT();
- Stub${i}Client::__INIT();
+ status = Stub${i}<void>::Init();
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ status = Stub${i}Server::Init();
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ status = Stub${i}Client::Init();
+ if (status != ETCH_OK) {
+ return status;
+ }
// done updating types, and class2type: lock them.
types()->lock();
class2type()->lock();
+
+ return ETCH_OK;
+}
+status_t $vf::DestroyValueFactory()
+{
+ $vf::types()->clear();
+ delete $vf::types();
+ delete $vf::class2type();
+ return ETCH_OK;
}
\ No newline at end of file
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
index 5b68ca6..219f4e5 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
@@ -26,6 +26,8 @@
#ifndef __$helper.getVfName($intf).toUpperCase()_H__
\#define __$helper.getVfName($intf).toUpperCase()_H__
+\#include "capu/os/Mutex.h"
+\#include "capu/container/List.h"
\#include "common/EtchTypes.h"
\#include "serialization/EtchDefaultValueFactory.h"
\#include "support/EtchRuntime.h"
@@ -74,29 +76,44 @@
static EtchTypeMap* types();
static EtchClass2TypeMap* class2type();
- static void initTypes();
- static void initResults();
- static void initFields();
- static void initParams();
+ static status_t InitTypes();
+ static status_t InitResults();
+ static status_t InitFields();
+ static status_t InitParams();
#set( $ctr = 0 )
#foreach( $n in $intf.iterator() )
#if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
#if ($ctr > 0 && $ctr % 100 == 0)
- static void initParams${ctr}();
+ static status_t InitParams${ctr}();
#end
#set( $ctr = $ctr + 1 )
#end
#end
- static void initImportExport();
+ static status_t InitImportExport();
/**
* Static Initialization-Helper
*/
private:
+ /**
+ * Listener which reacts to changes in runtime
+ * Destroys the statically initialized members if the last runtime has been deleted
+ */
+ class Etch${i}RuntimeListener : public EtchRuntimeListener {
+ /**
+ * @see EtchRuntime
+ */
+ status_t onRuntimeChanged(EtchRuntime* runtime);
+ };
+
friend class ${i}Helper;
- static void __ShutDown();
- static bool INIT;
- static void __INIT(EtchRuntime* runtime);
+ friend class Etch${i}RuntimeListener;
+ static status_t InitValueFactory(EtchRuntime* runtime);
+ static status_t DestroyValueFactory();
+ static capu::Mutex SRuntimesMutex;
+ static capu::List<capu::uint64_t> SRuntimes;
+ static Etch${i}RuntimeListener S${i}RuntimeListener;
+
};
}
#endif
diff --git a/binding-cpp/runtime/include/common/EtchObjectType.h b/binding-cpp/runtime/include/common/EtchObjectType.h
index 9969547..9de7672 100644
--- a/binding-cpp/runtime/include/common/EtchObjectType.h
+++ b/binding-cpp/runtime/include/common/EtchObjectType.h
@@ -71,6 +71,9 @@
EOTID_STUBHELPER,
EOTID_VALIDATOR_CUSTOM,
EOTID_VALIDATOR_CUSTOM_KEY,
+ EOTID_STACK,
+ EOTID_STACK_CLIENT,
+ EOTID_STACK_SERVER,
EOTID_DYNAMIC_START
};
diff --git a/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h b/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h
index 56b3094..255f316 100644
--- a/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h
+++ b/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h
@@ -98,7 +98,7 @@
public:
- static void Init(EtchTypeMap* types, EtchClass2TypeMap* class2type);
+ static status_t Init(EtchTypeMap* types, EtchClass2TypeMap* class2type);
/**
* The msg field of the standard unchecked exception.
diff --git a/binding-cpp/runtime/include/support/EtchClientStack.h b/binding-cpp/runtime/include/support/EtchClientStack.h
deleted file mode 100644
index b961f05..0000000
--- a/binding-cpp/runtime/include/support/EtchClientStack.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* $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 __ETCHCLIENTSTACK_H__
-#define __ETCHCLIENTSTACK_H__
-
-#include "support/EtchStack.h"
-#include "support/EtchRemoteBase.h"
-#include "transport/EtchSessionMessage.h"
-#include "support/EtchTransportHelper.h"
-
-// TODO: Refactoring of stack lifecycle ETCH-240
-
-//Entry for EtchRuntime
-class EtchClientStack : public EtchStack {
-public:
-
- /**
- * Constructs the EtchClientStack.
- */
- EtchClientStack(EtchRemoteBase* rb, EtchSessionMessage *helper, EtchResources *res, EtchValueFactory* vf);
-
- /**
- * Destructor
- */
- virtual ~EtchClientStack();
-
-private:
- EtchValueFactory *mVf;
- EtchRemoteBase *mRemoteBase;
- EtchSessionMessage *mStubHelper;
- EtchResources *mResources;
-};
-
-#endif /* ETCHCLIENTSTACK_H */
diff --git a/binding-cpp/runtime/include/support/EtchRemoteBase.h b/binding-cpp/runtime/include/support/EtchRemoteBase.h
index e3f3d02..9297de0 100644
--- a/binding-cpp/runtime/include/support/EtchRemoteBase.h
+++ b/binding-cpp/runtime/include/support/EtchRemoteBase.h
@@ -24,6 +24,7 @@
#include "common/EtchTypes.h"
#include "support/EtchDeliveryService.h"
+#include "support/EtchStack.h"
#include "serialization/EtchValueFactory.h"
class EtchRuntime;
@@ -39,7 +40,7 @@
* @param svc the delivery service used to send messages.
* @param vf the value factory used to create messages and encode/decode types.
*/
- EtchRemoteBase(EtchDeliveryService* svc, EtchValueFactory* vf);
+ EtchRemoteBase(EtchDeliveryService* svc, EtchValueFactory* vf, EtchStack* stack);
/**
* Destructor
@@ -189,6 +190,7 @@
private:
EtchRuntime* mRuntime;
EtchDeliveryService * mSvc;
+ EtchStack* mStack;
EtchValueFactory* mVf;
};
diff --git a/binding-cpp/runtime/include/support/EtchServerStack.h b/binding-cpp/runtime/include/support/EtchServerStack.h
deleted file mode 100644
index f72ee04..0000000
--- a/binding-cpp/runtime/include/support/EtchServerStack.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* $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 __ETCHSERVERSTACK_H__
-#define __ETCHSERVERSTACK_H__
-
-#include "support/EtchStack.h"
-#include "support/EtchRemoteBase.h"
-#include "transport/EtchSessionMessage.h"
-#include "support/EtchTransportHelper.h"
-
-// TODO: Refactoring of stack lifecycle ETCH-240
-
-//Entry for EtchRuntime
-class EtchServerStack : public EtchStack {
-public:
-
- /**
- * Constructs the EtchClientStack.
- */
- EtchServerStack(EtchRemoteBase* rb, EtchSessionMessage *helper, EtchResources *res, EtchValueFactory* vf);
-
- /**
- * Destructor
- */
- virtual ~EtchServerStack();
-
-private:
- EtchValueFactory *mVf;
- EtchRemoteBase *mRemoteBase;
- EtchSessionMessage *mStubHelper;
- EtchResources *mResources;
-};
-
-#endif /* ETCHSERVERSTACK_H */
diff --git a/binding-cpp/runtime/include/support/EtchStack.h b/binding-cpp/runtime/include/support/EtchStack.h
index a1d798d..a8bab43 100644
--- a/binding-cpp/runtime/include/support/EtchStack.h
+++ b/binding-cpp/runtime/include/support/EtchStack.h
@@ -16,11 +16,133 @@
*/
#ifndef ETCHSTACK_H
-#define ETCHSTACK_H
+#define ETCHSTACK_H
-class EtchStack {
+#include "support/EtchStubBase.h"
+#include "transport/EtchTransportData.h"
+#include "transport/EtchTransportPacket.h"
+#include "transport/EtchTransportMessage.h"
+#include "transport/EtchPlainMailboxManager.h"
+#include "transport/EtchDefaultDeliveryService.h"
+#include "serialization/EtchValueFactory.h"
+#include "util/EtchResources.h"
+
+/* *
+ * This class serves as a container for all layers created during the setup of a new stack (connection, packetizer, messagizer, ...).
+ */
+class EtchStack : public EtchObject{
public:
- virtual ~EtchStack() {}
+
+ /**
+ * EtchObjectType for EtchStack.
+ */
+ static const EtchObjectType* TYPE();
+
+ /**
+ * Resource identifier
+ */
+ const static EtchString& STACK();
+
+ /**
+ * Default Constructor
+ */
+ EtchStack();
+
+ /**
+ * Destructor which cleans the whole stack
+ */
+ virtual ~EtchStack();
+
+ /**
+ * sets the transport interface
+ */
+ void setTransportData(EtchTransportData* transportData);
+
+ /**
+ * sets the packet interface
+ */
+ void setTransportPacket(EtchTransportPacket* transportPacket);
+
+ /**
+ * sets the message interface
+ */
+ void setTransportMessage(EtchTransportMessage* transportMessage);
+
+ /**
+ * sets the resources
+ */
+ void setResources(EtchResources* resources);
+
+ /**
+ * sets the value factory
+ */
+ void setValueFactory(EtchValueFactory* valuefactory);
+
+ /**
+ * sets the mailbox manager
+ */
+ void setMailboxManager(EtchMailboxManager* mailboxmanager);
+
+ /**
+ * sets the delivery service
+ */
+ void setDeliveryService(EtchDeliveryService* deliveryservice);
+
+ /**
+ * sets the stub implemenation
+ */
+ void setStub(EtchSessionMessage* stub);
+
+ /**
+ * returns the transport interface
+ */
+ EtchTransportData* getTransportData();
+
+ /**
+ * returns the packet interface
+ */
+ EtchTransportPacket* getTransportPacket();
+
+ /**
+ * returns the message interface
+ */
+ EtchTransportMessage* getTransportMessage();
+
+ /**
+ * returns the resources
+ */
+ EtchResources* getResources();
+
+ /**
+ * returns the value factory
+ */
+ EtchValueFactory* getValueFactory();
+
+ /**
+ * returns the mailbox manager
+ */
+ EtchMailboxManager* getMailboxManager();
+
+ /**
+ * returns the delivery service
+ */
+ EtchDeliveryService* getDeliveryService();
+
+ /**
+ * returns the stub implemenatation
+ */
+ EtchSessionMessage* getStub();
+
+private:
+ EtchTransportData* mTransportData;
+ EtchTransportPacket* mTransportPacket;
+ EtchTransportMessage* mTransportMessage;
+ EtchResources* mResources;
+ EtchValueFactory* mValueFactory;
+ EtchMailboxManager* mMailboxManager;
+ EtchDeliveryService* mDeliveryService;
+ EtchSessionMessage* mStub;
+
};
#endif /* ETCHSTACK_H */
diff --git a/binding-cpp/runtime/include/support/EtchStackClient.h b/binding-cpp/runtime/include/support/EtchStackClient.h
new file mode 100644
index 0000000..b527bc4
--- /dev/null
+++ b/binding-cpp/runtime/include/support/EtchStackClient.h
@@ -0,0 +1,51 @@
+/* $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 __ETCHSTACKCLIENT_H__
+#define __ETCHSTACKCLIENT_H__
+
+#include "support/EtchStack.h"
+#include "util/EtchResources.h"
+
+/* *
+ * This class serves as a container for all layers created during the setup of a new stack (connection, packetizer, messagizer, ...).
+ */
+class EtchStackClient : public EtchStack {
+public:
+
+ /**
+ * EtchObjectType for EtchStackClient.
+ */
+ static const EtchObjectType* TYPE();
+
+ /**
+ * Default Constructor
+ */
+ EtchStackClient();
+
+ /**
+ * Destructor which cleans the whole stack
+ */
+ virtual ~EtchStackClient();
+
+public:
+ EtchResources* mStaticResources;
+
+
+};
+
+#endif /* __ETCHSTACKCLIENT_H__ */
diff --git a/binding-cpp/runtime/include/support/EtchStackServer.h b/binding-cpp/runtime/include/support/EtchStackServer.h
new file mode 100644
index 0000000..9db34af
--- /dev/null
+++ b/binding-cpp/runtime/include/support/EtchStackServer.h
@@ -0,0 +1,62 @@
+/* $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 __ETCHSTACKSERVER_H__
+#define __ETCHSTACKSERVER_H__
+
+#include "support/EtchRemoteBase.h"
+
+/* *
+ * This class serves as a container for all layers created during the setup of a new stack (connection, packetizer, messagizer, ...).
+ */
+class EtchStackServer : public EtchStack{
+public:
+
+ /**
+ * EtchObjectType for EtchStackServer.
+ */
+ static const EtchObjectType* TYPE();
+
+ /**
+ * Default Constructor
+ */
+ EtchStackServer();
+
+ /**
+ * Destructor which cleans the whole stack
+ */
+ virtual ~EtchStackServer();
+
+
+ /**
+ * sets the remote implementation
+ */
+ void setRemote(EtchRemoteBase* remote);
+
+ /**
+ * returns the remote implementation
+ */
+ EtchRemoteBase* getRemote();
+
+private:
+ EtchRemoteBase* mRemote;
+
+
+
+};
+
+#endif /* __ETCHSTACKSERVER_H__ */
diff --git a/binding-cpp/runtime/include/support/EtchStubBase.h b/binding-cpp/runtime/include/support/EtchStubBase.h
index 613e8ca..c19750b 100644
--- a/binding-cpp/runtime/include/support/EtchStubBase.h
+++ b/binding-cpp/runtime/include/support/EtchStubBase.h
@@ -34,7 +34,7 @@
template<typename T>
class EtchStubBase : public EtchSessionMessage {
public:
- template <typename Class>
+ template <typename U>
friend class EtchStubPoolRunnable;
/**
@@ -84,7 +84,7 @@
T* mObj;
};
-template<typename T>
+template<typename U>
class EtchStubPoolRunnable : public EtchPoolRunnable {
public:
@@ -97,7 +97,7 @@
* @param msg the message.
* @param helper the StubHelper which will dispatch the message.
*/
- EtchStubPoolRunnable(EtchStubBase<T>* stub, capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg, EtchStubHelper<T>* helper)
+ EtchStubPoolRunnable(EtchStubBase<U>* stub, capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg, EtchStubHelper<U>* helper)
: mStub(stub)
, mSender(sender)
, mMsg(msg)
@@ -118,10 +118,10 @@
}
private:
- EtchStubBase<T>* mStub;
+ EtchStubBase<U>* mStub;
capu::SmartPointer<EtchWho> mSender;
capu::SmartPointer<EtchMessage> mMsg;
- EtchStubHelper<T>* mHelper;
+ EtchStubHelper<U>* mHelper;
};
template<typename T>
@@ -133,7 +133,6 @@
template<typename T>
EtchStubBase<T>::~EtchStubBase() {
delete mObj;
- delete mSvc;
}
template<typename T>
@@ -190,4 +189,4 @@
return ETCH_EUNIMPL;
}
-#endif
+#endif /* __ETCHSTUBBASE_H__ */
diff --git a/binding-cpp/runtime/include/transport/EtchConnection.h b/binding-cpp/runtime/include/transport/EtchConnection.h
index d60e44e..58d6651 100644
--- a/binding-cpp/runtime/include/transport/EtchConnection.h
+++ b/binding-cpp/runtime/include/transport/EtchConnection.h
@@ -168,7 +168,7 @@
if (mSession != NULL) {
//TODO: run this in seperate thread
- mMutex.unlock();
+ mMutex.unlock();
return mSession->sessionNotify(new EtchString(EtchSession::UP()));
}
mMutex.unlock();
diff --git a/binding-cpp/runtime/include/transport/EtchTcpListener.h b/binding-cpp/runtime/include/transport/EtchTcpListener.h
index f57fff6..8fe1899 100644
--- a/binding-cpp/runtime/include/transport/EtchTcpListener.h
+++ b/binding-cpp/runtime/include/transport/EtchTcpListener.h
@@ -103,13 +103,6 @@
*/
virtual status_t readSocket();
-private:
- EtchRuntime* mRuntime;
- EtchServerSocket* mSocket;
- capu::uint16_t mPort;
- capu::uint8_t mBackLog;
-
-
public:
/**
* Query term for URI to specify backlog value to ServerSocket. The value
@@ -122,6 +115,40 @@
* @see #TcpListener(String, Resources)
*/
const static EtchString& BACKLOG();
+
+ const static EtchString& CONNECTION_CHECK();
+
+private:
+ class ConnectionChecker : public capu::Runnable {
+ public:
+ /**
+ * Constructor
+ * @param instance of TcpListener
+ */
+ ConnectionChecker(EtchTcpListener* listener);
+
+ /**
+ * Destructor
+ */
+ virtual ~ConnectionChecker();
+
+ /**
+ * @see Runnable
+ */
+ void run();
+ private:
+ EtchTcpListener *mListener;
+ };
+
+ friend class ConnectionChecker;
+
+ EtchRuntime* mRuntime;
+ EtchServerSocket* mSocket;
+ capu::uint16_t mPort;
+ capu::uint8_t mBackLog;
+ capu::Thread* mConnectionCheckerThread;
+ ConnectionChecker* mConnectionChecker;
+
};
#endif /* ETCHTCPLISTENER_H */
diff --git a/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h b/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
index a71f76d..8a3f47d 100644
--- a/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
+++ b/binding-cpp/runtime/include/transport/EtchTcpTransportFactory.h
@@ -23,6 +23,7 @@
#include "common/EtchString.h"
#include "common/EtchConfig.h"
#include "support/EtchServerFactory.h"
+#include "support/EtchStack.h"
#include "transport/EtchTransportMessage.h"
#include "transport/EtchTransportData.h"
#include "transport/EtchTcpConnection.h"
@@ -38,6 +39,7 @@
: public EtchTransportFactory {
public:
+ friend class MySessionListener;
/**
* Constructor
* @param runtime
@@ -81,7 +83,7 @@
* @param uri
* @param resources
*/
- MySessionListener(EtchRuntime* runtime, EtchTransport<EtchSessionListener<EtchSocket> > *transport,
+ MySessionListener(EtchRuntime* runtime, EtchTcpTransportFactory* factory, EtchTransport<EtchSessionListener<EtchSocket> > *transport,
EtchString uri, EtchResources* resources, capu::bool_t secure);
/**
@@ -141,6 +143,8 @@
EtchServerFactory* mSession;
EtchRuntime* mRuntime;
capu::bool_t mIsSecure;
+ capu::List<EtchStack*>* mConnectionStacks;
+ EtchTcpTransportFactory* mFactory;
};
diff --git a/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/ServerSocket.inc b/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/ServerSocket.inc
index 0ab6a5d..f949c57 100644
--- a/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/ServerSocket.inc
+++ b/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/ServerSocket.inc
@@ -60,7 +60,11 @@
inline Socket* ServerSocket::accept()
{
- Socket *clientSocket = new Socket(::accept(mServerSocket, NULL, NULL));
+ SOCKET handle = ::accept(mServerSocket, NULL, NULL);
+ if (handle == INVALID_SOCKET) {
+ return NULL;
+ }
+ Socket *clientSocket = new Socket(handle);
return clientSocket;
}
diff --git a/binding-cpp/runtime/src/main/CMakeLists.txt b/binding-cpp/runtime/src/main/CMakeLists.txt
index bca4edf..76b7b1f 100644
--- a/binding-cpp/runtime/src/main/CMakeLists.txt
+++ b/binding-cpp/runtime/src/main/CMakeLists.txt
@@ -58,7 +58,7 @@
${PROJECT_SOURCE_DIR}/include/transport/EtchTransportData.h
${PROJECT_SOURCE_DIR}/include/transport/EtchTransportMessage.h
${PROJECT_SOURCE_DIR}/include/transport/EtchTransportPacket.h
- ${PROJECT_SOURCE_DIR}/include/transport/EtchTransportFactory.h
+ ${PROJECT_SOURCE_DIR}/include/transport/EtchTransportFactory.h
${PROJECT_SOURCE_DIR}/include/transport/EtchMessagizer.h
${PROJECT_SOURCE_DIR}/include/transport/EtchFormat.h
${PROJECT_SOURCE_DIR}/include/transport/EtchTcpTransportFactory.h
@@ -127,7 +127,7 @@
${PROJECT_SOURCE_DIR}/include/support/EtchPoolRunnable.h
${PROJECT_SOURCE_DIR}/include/support/EtchFreePool.h
${PROJECT_SOURCE_DIR}/include/support/EtchQueuedPool.h
- ${PROJECT_SOURCE_DIR}/include/support/EtchRemoteBase.h
+ ${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
@@ -135,9 +135,9 @@
${PROJECT_SOURCE_DIR}/include/support/EtchPlainMailbox.h
${PROJECT_SOURCE_DIR}/include/support/EtchMonitor.h
${PROJECT_SOURCE_DIR}/include/support/EtchStack.h
+ ${PROJECT_SOURCE_DIR}/include/support/EtchStackClient.h
+ ${PROJECT_SOURCE_DIR}/include/support/EtchStackServer.h
${PROJECT_SOURCE_DIR}/include/support/EtchRuntime.h
- ${PROJECT_SOURCE_DIR}/include/support/EtchServerStack.h
- ${PROJECT_SOURCE_DIR}/include/support/EtchClientStack.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
${PROJECT_SOURCE_DIR}/include/util/EtchCircularQueue.h
${PROJECT_SOURCE_DIR}/include/util/EtchIdGenerator.h
@@ -223,8 +223,9 @@
support/EtchTransportHelper.cpp
support/EtchMonitor.cpp
support/EtchRuntime.cpp
- support/EtchServerStack.cpp
- support/EtchClientStack.cpp
+ support/EtchStack.cpp
+ support/EtchStackClient.cpp
+ support/EtchStackServer.cpp
support/EtchAsyncResultNone.cpp
util/EtchCircularQueue.cpp
util/EtchUtil.cpp
diff --git a/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp b/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp
index 9b53243..902aec6 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp
@@ -71,21 +71,34 @@
EtchRuntime* runtime = EtchRuntime::getRuntime();
status_t result;
- EtchField field_ptr;
- result = type->getField(FIELD_NAME(), &field_ptr);
- if (result != ETCH_OK)
+
+ EtchField field;
+ result = type->getField(FIELD_NAME(), &field);
+ if (result != ETCH_OK) {
return result;
- class2type->put(EtchAuthenticationException::TYPE(), type);
+ }
+
+ result = class2type->put(EtchAuthenticationException::TYPE(), type);
+ if (result != ETCH_OK) {
+ return result;
+ }
+
type->setComponentType(EtchAuthenticationException::TYPE());
+
//set the import export helper
- type->setImportExportHelper(new EtchAuthenticationExceptionSerializer(type, &field_ptr));
+ type->setImportExportHelper(new EtchAuthenticationExceptionSerializer(type, &field));
+
+ //get validator
capu::SmartPointer<EtchValidator> tmp;
result = EtchValidatorString::Get(0, tmp);
- if (result != ETCH_OK)
+ if (result != ETCH_OK) {
return result;
- result = type->putValidator(field_ptr, tmp);
- if (result != ETCH_OK)
+ }
+ result = type->putValidator(field, tmp);
+ if (result != ETCH_OK) {
return result;
+ }
+
type->lock();
CAPU_LOG_TRACE(runtime->getLogger(), TAG, "EtchAuthenticationExceptionSerializer has been initialized");
return ETCH_OK;
diff --git a/binding-cpp/runtime/src/main/serialization/EtchClass2TypeMap.cpp b/binding-cpp/runtime/src/main/serialization/EtchClass2TypeMap.cpp
index 3ae5d7b..a3d4967 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchClass2TypeMap.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchClass2TypeMap.cpp
@@ -39,9 +39,6 @@
EtchType* tmp = NULL;
if (mC2T.get(classType, &tmp) == ETCH_OK) {
- if (!tmp->equals(type)) {
- return ETCH_ERANGE;
- }
return ETCH_OK;
}
diff --git a/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp b/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp
index fc26c71..a3e7743 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp
@@ -72,22 +72,34 @@
EtchRuntime* runtime = EtchRuntime::getRuntime();
status_t result;
- EtchField field_ptr;
- result = type->getField(FIELD_NAME(), &field_ptr);
- if (result != ETCH_OK)
+
+ EtchField field;
+ result = type->getField(FIELD_NAME(), &field);
+ if (result != ETCH_OK) {
return result;
- class2type->put(EtchDate::TYPE(), type);
+ }
+
+ result = class2type->put(EtchDate::TYPE(), type);
+ if (result != ETCH_OK) {
+ return result;
+ }
+
type->setComponentType(EtchDate::TYPE());
//set the import export helper
- type->setImportExportHelper(new EtchDateSerializer(type, &field_ptr));
+ type->setImportExportHelper(new EtchDateSerializer(type, &field));
+
+ //get validator
capu::SmartPointer<EtchValidator> val;
result = EtchValidatorLong::Get(0, val);
- if (result != ETCH_OK)
+ if (result != ETCH_OK) {
return result;
- result = type->putValidator(field_ptr, val);
- if (result != ETCH_OK)
+ }
+ result = type->putValidator(field, val);
+ if (result != ETCH_OK) {
return result;
+ }
+
type->lock();
CAPU_LOG_TRACE(runtime->getLogger(), TAG, "EtchDateSerializer has been initialized");
return ETCH_OK;
diff --git a/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp b/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp
index 7521f1b..3edea9f 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp
@@ -131,36 +131,39 @@
delete mDynamicTypes;
}
-void EtchDefaultValueFactory::Init(EtchTypeMap* types, EtchClass2TypeMap* class2type) {
+status_t EtchDefaultValueFactory::Init(EtchTypeMap* types, EtchClass2TypeMap* class2type) {
+ status_t result;
EtchType *type;
- types->get(ETCH_RUNTIME_EXCEPTION_TYPE_NAME(), type);
- EtchRuntimeExceptionSerializer::Init(type, class2type);
+ result = types->get(ETCH_RUNTIME_EXCEPTION_TYPE_NAME(), type);
+ result = EtchRuntimeExceptionSerializer::Init(type, class2type);
- types->get(ETCH_LIST_TYPE_NAME(), type);
- EtchListSerializer::Init(type, class2type);
+ result = types->get(ETCH_LIST_TYPE_NAME(), type);
+ result = EtchListSerializer::Init(type, class2type);
- types->get(ETCH_MAP_TYPE_NAME(), type);
- EtchHashTableSerializer::Init(type, class2type);
+ result = types->get(ETCH_MAP_TYPE_NAME(), type);
+ result = EtchHashTableSerializer::Init(type, class2type);
- types->get(ETCH_SET_TYPE_NAME(), type);
- EtchSetSerializer::Init(type, class2type);
+ result = types->get(ETCH_SET_TYPE_NAME(), type);
+ result = EtchSetSerializer::Init(type, class2type);
- types->get(ETCH_DATETIME_TYPE_NAME(), type);
- EtchDateSerializer::Init(type, class2type);
+ result = types->get(ETCH_DATETIME_TYPE_NAME(), type);
+ result = EtchDateSerializer::Init(type, class2type);
- types->get(ETCH_AUTH_EXCEPTION_TYPE_NAME(), type);
- EtchAuthenticationExceptionSerializer::Init(type, class2type);
+ result = types->get(ETCH_AUTH_EXCEPTION_TYPE_NAME(), type);
+ result = EtchAuthenticationExceptionSerializer::Init(type, class2type);
{
- types->get(ETCH_EXCEPTION_MESSAGE_NAME(), type);
+ result = types->get(ETCH_EXCEPTION_MESSAGE_NAME(), type);
capu::SmartPointer<EtchValidator> val;
EtchValidatorRuntimeException::Get(val);
- type->putValidator(_mf_result(), val);
+ result = type->putValidator(_mf_result(), val);
EtchValidatorLong::Get(0, val);
- type->putValidator(_mf__messageId(), val);
- type->putValidator(_mf__inReplyTo(), val);
+ result = type->putValidator(_mf__messageId(), val);
+ result = type->putValidator(_mf__inReplyTo(), val);
}
+
+ return ETCH_OK;
}
const EtchType * EtchDefaultValueFactory::get_mt__Etch_RuntimeException() {
diff --git a/binding-cpp/runtime/src/main/serialization/EtchHashTableSerializer.cpp b/binding-cpp/runtime/src/main/serialization/EtchHashTableSerializer.cpp
index fa4ef68..bba1623 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchHashTableSerializer.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchHashTableSerializer.cpp
@@ -103,21 +103,34 @@
EtchRuntime* runtime = EtchRuntime::getRuntime();
status_t result;
- EtchField field_ptr;
- result = type->getField(FIELD_NAME(), &field_ptr);
- if (result != ETCH_OK)
+
+ EtchField field;
+ result = type->getField(FIELD_NAME(), &field);
+ if (result != ETCH_OK) {
return result;
- class2type->put(EtchNativeArray<capu::SmartPointer<EtchObject> >::TYPE(), type);
+ }
+
+ result = class2type->put(EtchNativeArray<capu::SmartPointer<EtchObject> >::TYPE(), type);
+ if (result != ETCH_OK) {
+ return result;
+ }
+
type->setComponentType(EtchHashTable<capu::SmartPointer<EtchObject>, capu::SmartPointer<EtchObject> >::TYPE());
+
//set the import export helper
- type->setImportExportHelper(new EtchHashTableSerializer(type, &field_ptr));
+ type->setImportExportHelper(new EtchHashTableSerializer(type, &field));
+
+ //get validator
capu::SmartPointer<EtchValidator> tmp;
result = EtchValidatorObject::Get(1, tmp);
- if (result != ETCH_OK)
+ if (result != ETCH_OK) {
return result;
- result = type->putValidator(field_ptr, tmp);
- if (result != ETCH_OK)
+ }
+ result = type->putValidator(field, tmp);
+ if (result != ETCH_OK) {
return result;
+ }
+
type->lock();
CAPU_LOG_TRACE(runtime->getLogger(), TAG, "EtchHashTableSerializer has been initialized");
return ETCH_OK;
diff --git a/binding-cpp/runtime/src/main/serialization/EtchListSerializer.cpp b/binding-cpp/runtime/src/main/serialization/EtchListSerializer.cpp
index fdfd292..77517b1 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchListSerializer.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchListSerializer.cpp
@@ -104,11 +104,18 @@
return result;
}
- class2type->put(EtchNativeArray<capu::SmartPointer<EtchObject> >::TYPE(), type);
+ result = class2type->put(EtchNativeArray<capu::SmartPointer<EtchObject> >::TYPE(), type);
+ if (result != ETCH_OK) {
+ return result;
+ }
+
type->setComponentType(EtchList<capu::SmartPointer<EtchObject> >::TYPE());
+
//set the import export helper
// TODO memory EtchField
type->setImportExportHelper(new EtchListSerializer(type, &field));
+
+ //get validator
capu::SmartPointer<EtchValidator> validator;
result = EtchValidatorObject::Get(1, validator);
if (result != ETCH_OK) {
diff --git a/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp b/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp
index 8104adf..ce4887c 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp
@@ -76,21 +76,35 @@
EtchRuntime* runtime = EtchRuntime::getRuntime();
status_t result;
- EtchField field_ptr;
- result = type->getField(FIELD_NAME(), &field_ptr);
- if (result != ETCH_OK)
+
+ EtchField field;
+ result = type->getField(FIELD_NAME(), &field);
+ if (result != ETCH_OK) {
return result;
- class2type->put(EtchRuntimeException::TYPE(), type);
+ }
+
+ result = class2type->put(EtchRuntimeException::TYPE(), type);
+ if (result != ETCH_OK) {
+ return result;
+ }
+
type->setComponentType(EtchRuntimeException::TYPE());
+
//set the import export helper
- type->setImportExportHelper(new EtchRuntimeExceptionSerializer(type, &field_ptr));
+ type->setImportExportHelper(new EtchRuntimeExceptionSerializer(type, &field));
+
+ //get validator
capu::SmartPointer<EtchValidator> tmp;
result = EtchValidatorString::Get(0, tmp);
- if (result != ETCH_OK)
+ if (result != ETCH_OK) {
return result;
- result = type->putValidator(field_ptr, tmp);
- if (result != ETCH_OK)
+ }
+ result = type->putValidator(field, tmp);
+ if (result != ETCH_OK) {
return result;
+ }
+
+ //lock type
type->lock();
CAPU_LOG_TRACE(runtime->getLogger(), TAG, "EtchRuntimeExceptionSerializer has been initialized");
return ETCH_OK;
diff --git a/binding-cpp/runtime/src/main/serialization/EtchSetSerializer.cpp b/binding-cpp/runtime/src/main/serialization/EtchSetSerializer.cpp
index f3f46f4..d112af9 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchSetSerializer.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchSetSerializer.cpp
@@ -94,21 +94,34 @@
EtchRuntime* runtime = EtchRuntime::getRuntime();
status_t result;
- EtchField field_ptr;
- result = type->getField(FIELD_NAME(), &field_ptr);
- if (result != ETCH_OK)
+
+ EtchField field;
+ result = type->getField(FIELD_NAME(), &field);
+ if (result != ETCH_OK) {
return result;
- class2type->put(EtchNativeArray<capu::SmartPointer<EtchObject> >::TYPE(), type);
+ }
+
+ result = class2type->put(EtchNativeArray<capu::SmartPointer<EtchObject> >::TYPE(), type);
+ if (result != ETCH_OK) {
+ return result;
+ }
+
type->setComponentType(EtchHashSet<capu::SmartPointer<EtchObject> >::TYPE());
+
//set the import export helper
- type->setImportExportHelper(new EtchSetSerializer(type, &field_ptr));
+ type->setImportExportHelper(new EtchSetSerializer(type, &field));
+
+ //get validator
capu::SmartPointer<EtchValidator> tmp;
result = EtchValidatorObject::Get(1, tmp);
- if (result != ETCH_OK)
+ if (result != ETCH_OK) {
return result;
- result = type->putValidator(field_ptr, tmp);
- if (result != ETCH_OK)
+ }
+ result = type->putValidator(field, tmp);
+ if (result != ETCH_OK) {
return result;
+ }
+
type->lock();
CAPU_LOG_TRACE(runtime->getLogger(), TAG, "EtchSetSerializer has been initialized");
return ETCH_OK;
diff --git a/binding-cpp/runtime/src/main/serialization/EtchTypeMap.cpp b/binding-cpp/runtime/src/main/serialization/EtchTypeMap.cpp
index 09583f1..de5829c 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchTypeMap.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchTypeMap.cpp
@@ -24,6 +24,14 @@
}
EtchTypeMap::~EtchTypeMap() {
+ EtchHashTable<capu::int32_t, EtchType*, capu::Hash, capu::Comparator >::Iterator it = mById.begin();
+ while (it.hasNext()) {
+ capu::Pair<capu::int32_t, EtchType*> pair;
+ it.next(&pair);
+ delete pair.second;
+ }
+ mById.clear();
+ mByName.clear();
}
status_t EtchTypeMap::add(EtchType *type) {
diff --git a/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp b/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp
index 13d2931..b0c2063 100644
--- a/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp
+++ b/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp
@@ -20,16 +20,22 @@
#include "transport/EtchTransportData.h"
#include "support/EtchRuntime.h"
#include "util/EtchLogger.h"
+#include "support/EtchStackClient.h"
static char* TAG = "EtchRemoteBase";
-EtchRemoteBase::EtchRemoteBase(EtchDeliveryService* svc, EtchValueFactory* vf)
- : mSvc(svc), mVf(vf) {
+EtchRemoteBase::EtchRemoteBase(EtchDeliveryService* svc, EtchValueFactory* vf, EtchStack* stack)
+ : mSvc(svc), mVf(vf), mStack(stack) {
//TODO refactor this
mRuntime = EtchRuntime::getRuntime();
}
EtchRemoteBase::~EtchRemoteBase() {
+ if (mStack != NULL) {
+ if (mStack->isInstanceOf(EtchStackClient::TYPE())) {
+ delete mStack;
+ }
+ }
}
status_t EtchRemoteBase::newMessage( EtchType* type, capu::SmartPointer<EtchMessage> *message) {
diff --git a/binding-cpp/runtime/src/main/support/EtchServerStack.cpp b/binding-cpp/runtime/src/main/support/EtchServerStack.cpp
deleted file mode 100644
index 8923577..0000000
--- a/binding-cpp/runtime/src/main/support/EtchServerStack.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/* $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 "support/EtchServerStack.h"
-
-EtchServerStack::EtchServerStack(EtchRemoteBase* rb, EtchSessionMessage *helper, EtchResources *res, EtchValueFactory* vf)
-: mRemoteBase(rb), mStubHelper(helper),mResources(res), mVf(vf) {
-}
-
-EtchServerStack::~EtchServerStack() {
- delete mResources;
- delete mRemoteBase;
- delete mStubHelper;
- delete mVf;
-}
diff --git a/binding-cpp/runtime/src/main/support/EtchStack.cpp b/binding-cpp/runtime/src/main/support/EtchStack.cpp
new file mode 100644
index 0000000..8674e87
--- /dev/null
+++ b/binding-cpp/runtime/src/main/support/EtchStack.cpp
@@ -0,0 +1,134 @@
+/* $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 "support/EtchStack.h"
+#include "support/EtchTransportHelper.h"
+
+const EtchObjectType* EtchStack::TYPE() {
+ const static EtchObjectType TYPE(EOTID_STACK, NULL);
+ return &TYPE;
+}
+
+const EtchString& EtchStack::STACK() {
+ static const EtchString cmd("STACK");
+ return cmd;
+}
+
+EtchStack::EtchStack() : EtchObject()
+ , mTransportData(NULL)
+ , mTransportPacket(NULL)
+ , mTransportMessage(NULL)
+ , mResources(NULL)
+ , mMailboxManager(NULL)
+ , mDeliveryService(NULL)
+ , mStub(NULL)
+ {
+ EtchObject::addObjectType(EtchStack::TYPE());
+}
+
+EtchStack::~EtchStack() {
+ if (mTransportMessage != NULL) {
+ delete mTransportMessage;
+ }
+ if (mTransportPacket != NULL) {
+ delete mTransportPacket;
+ }
+ if (mTransportData != NULL) {
+ delete mTransportData;
+ }
+ if (mResources != NULL) {
+ delete mResources;
+ }
+ if (mValueFactory != NULL) {
+ delete mValueFactory;
+ }
+ if (mMailboxManager != NULL) {
+ delete mMailboxManager;
+ }
+ if (mDeliveryService != NULL) {
+ delete mDeliveryService;
+ }
+
+ if (mStub != NULL) {
+ delete mStub;
+ }
+}
+
+void EtchStack::setTransportData(EtchTransportData* transportData) {
+ mTransportData = transportData;
+}
+
+void EtchStack::setTransportPacket(EtchTransportPacket* transportPacket) {
+ mTransportPacket = transportPacket;
+}
+
+void EtchStack::setTransportMessage(EtchTransportMessage* transportMessage) {
+ mTransportMessage = transportMessage;
+}
+
+void EtchStack::setResources(EtchResources* resources) {
+ mResources = resources;
+}
+
+void EtchStack::setValueFactory(EtchValueFactory* valuefactory) {
+ mValueFactory = valuefactory;
+}
+
+void EtchStack::setMailboxManager(EtchMailboxManager* mailboxmanager) {
+ mMailboxManager = mailboxmanager;
+}
+
+void EtchStack::setDeliveryService(EtchDeliveryService* deliveryservice) {
+ mDeliveryService = deliveryservice;
+}
+
+void EtchStack::setStub(EtchSessionMessage* stub) {
+ mStub = stub;
+}
+
+EtchTransportData* EtchStack::getTransportData() {
+ return mTransportData;
+}
+
+EtchTransportPacket* EtchStack::getTransportPacket() {
+ return mTransportPacket;
+}
+
+EtchTransportMessage* EtchStack::getTransportMessage() {
+ return mTransportMessage;
+}
+
+EtchResources* EtchStack::getResources() {
+ return mResources;
+}
+
+EtchValueFactory* EtchStack::getValueFactory() {
+ return mValueFactory;
+}
+
+EtchMailboxManager* EtchStack::getMailboxManager() {
+ return mMailboxManager;
+}
+
+EtchDeliveryService* EtchStack::getDeliveryService() {
+ return mDeliveryService;
+}
+
+EtchSessionMessage* EtchStack::getStub() {
+ return mStub;
+}
+
diff --git a/binding-cpp/runtime/src/main/support/EtchClientStack.cpp b/binding-cpp/runtime/src/main/support/EtchStackClient.cpp
similarity index 60%
rename from binding-cpp/runtime/src/main/support/EtchClientStack.cpp
rename to binding-cpp/runtime/src/main/support/EtchStackClient.cpp
index cfb2674..d910789 100644
--- a/binding-cpp/runtime/src/main/support/EtchClientStack.cpp
+++ b/binding-cpp/runtime/src/main/support/EtchStackClient.cpp
@@ -15,22 +15,22 @@
* limitations under the License.
*/
-#include "support/EtchClientStack.h"
+#include "support/EtchStackClient.h"
+#include "support/EtchTransportHelper.h"
-EtchClientStack::EtchClientStack(EtchRemoteBase* rb, EtchSessionMessage *helper, EtchResources *res, EtchValueFactory* vf)
-: mRemoteBase(rb), mStubHelper(helper),mResources(res), mVf(vf) {
+const EtchObjectType* EtchStackClient::TYPE() {
+ const static EtchObjectType TYPE(EOTID_STACK_CLIENT, NULL);
+ return &TYPE;
}
-EtchClientStack::~EtchClientStack() {
- status_t status;
- status = EtchTransportHelper::DestroyResources(mResources);
- if(status != ETCH_OK) {
- // Log error
- }
- if(mStubHelper != NULL) {
- delete mStubHelper;
- }
- if(mVf != NULL) {
- delete mVf;
+EtchStackClient::EtchStackClient() : EtchStack(), mStaticResources(NULL) {
+ EtchObject::addObjectType(EtchStackClient::TYPE());
+ EtchObject::setObjectType(EtchStackClient::TYPE());
+}
+
+EtchStackClient::~EtchStackClient() {
+ if (mStaticResources != NULL) {
+ EtchTransportHelper::DestroyResources(mStaticResources);
}
}
+
diff --git a/binding-cpp/runtime/src/main/support/EtchStackServer.cpp b/binding-cpp/runtime/src/main/support/EtchStackServer.cpp
new file mode 100644
index 0000000..1e2d334
--- /dev/null
+++ b/binding-cpp/runtime/src/main/support/EtchStackServer.cpp
@@ -0,0 +1,45 @@
+/* $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 "support/EtchStackServer.h"
+
+const EtchObjectType* EtchStackServer::TYPE() {
+ const static EtchObjectType TYPE(EOTID_STACK_SERVER, NULL);
+ return &TYPE;
+}
+
+EtchStackServer::EtchStackServer()
+: EtchStack()
+ , mRemote(NULL)
+{
+ EtchObject::addObjectType(EtchStackServer::TYPE());
+ EtchObject::setObjectType(EtchStackServer::TYPE());
+}
+
+EtchStackServer::~EtchStackServer() {
+ if (mRemote != NULL) {
+ delete mRemote;
+ }
+}
+
+void EtchStackServer::setRemote(EtchRemoteBase* remote) {
+ mRemote = remote;
+}
+
+EtchRemoteBase* EtchStackServer::getRemote() {
+ return mRemote;
+}
diff --git a/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp b/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp
index 67c07eb..32817bb 100644
--- a/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp
@@ -67,9 +67,7 @@
}
EtchDefaultDeliveryService::~EtchDefaultDeliveryService() {
- if(mTransport != NULL) {
- delete mTransport;
- }
+
}
const EtchMailboxManager* EtchDefaultDeliveryService::getTransport() {
diff --git a/binding-cpp/runtime/src/main/transport/EtchMessagizer.cpp b/binding-cpp/runtime/src/main/transport/EtchMessagizer.cpp
index deee7f4..fa4408c 100644
--- a/binding-cpp/runtime/src/main/transport/EtchMessagizer.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchMessagizer.cpp
@@ -51,8 +51,6 @@
}
EtchMessagizer::~EtchMessagizer() {
- if(mTransport != NULL)
- delete mTransport;
if (mTdi != NULL)
delete mTdi;
if (mTdo != NULL)
diff --git a/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp b/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp
index 7b8155f..bd09c3d 100644
--- a/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp
@@ -85,8 +85,7 @@
}
EtchPacketizer::~EtchPacketizer() {
- if (mTransport != NULL)
- delete mTransport;
+
}
capu::int32_t EtchPacketizer::getHeaderSize() {
diff --git a/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp b/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
index e90a7c4..19b4307 100644
--- a/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
@@ -36,7 +36,6 @@
p.second->closeDelivery();
delete p.second;
}
- delete mTransport;
}
EtchTransportMessage* EtchPlainMailboxManager::getTransport() {
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
index 8683177..a486520 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
@@ -122,7 +122,9 @@
}
}
// try to open a socket.
- mSocket = new EtchSocket();
+ if (mSocket == NULL) {
+ mSocket = new EtchSocket();
+ }
if (mSocket->connect((unsigned char *) mHost.c_str(), mPort) == ETCH_OK) {
mMutexConnection.unlock();
CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Connection established", mHost.c_str(), mPort);
@@ -131,6 +133,7 @@
mSocket->close();
delete mSocket;
mSocket = NULL;
+ first = false;
}
CAPU_LOG_WARN(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Connection could not be established for stack %d", mHost.c_str(), mPort);
}
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
index ff6d4f5..561b261 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
@@ -21,11 +21,33 @@
+EtchTcpListener::ConnectionChecker::ConnectionChecker(EtchTcpListener* listener) : mListener(listener){ }
+
+EtchTcpListener::ConnectionChecker::~ConnectionChecker() {}
+
+void EtchTcpListener::ConnectionChecker::run() {
+ status_t result;
+ while (mListener->mIsStarted) {
+ if (mListener->mSession != NULL) {
+ result = mListener->mSession->sessionNotify(new EtchString(EtchTcpListener::CONNECTION_CHECK()));
+ if (result != ETCH_OK) {
+ //TODO handle error
+ }
+ capu::Thread::Sleep(1000);
+ }
+ }
+}
+
const EtchString& EtchTcpListener::BACKLOG() {
static const EtchString name("TcpTransportFactory.socket");
return name;
}
+const EtchString& EtchTcpListener::CONNECTION_CHECK() {
+ static const EtchString name("connection.check");
+ return name;
+}
+
EtchTcpListener::EtchTcpListener(EtchURL *url)
: mPort(url->getPort()) {
//TODO rafactor this
@@ -45,6 +67,8 @@
mIsStarted = false;
mThread = NULL;
mSocket = NULL;
+ mConnectionCheckerThread = NULL;
+ mConnectionChecker = NULL;
}
EtchTcpListener::~EtchTcpListener() {
@@ -52,12 +76,18 @@
mThread->join();
delete mThread;
}
+ if (mConnectionCheckerThread != NULL) {
+ mConnectionCheckerThread->join();
+ delete mConnectionCheckerThread;
+ }
if (mSocket != NULL) {
mSocket->close();
delete mSocket;
mSocket = NULL;
}
+ delete mConnectionChecker;
+
}
capu::bool_t EtchTcpListener::isStarted() {
@@ -65,8 +95,9 @@
}
status_t EtchTcpListener::close() {
- if (mSocket != NULL)
+ if (mSocket != NULL) {
return mSocket->close();
+ }
return ETCH_ERROR;
}
@@ -74,18 +105,19 @@
// if a one time connection from a server socket listener, just
// return the existing socket.
mMutexConnection.lock();
- if (!reconnect && (mSocket != NULL)) {
+ if (reconnect && (mSocket != NULL)) {
mMutexConnection.unlock();
return ETCH_OK;
}
- while (isStarted()) {
+ while (mIsStarted) {
// if reconnect is false and first is true, this is our
// very first attempt to connect. otherwise, we are trying
// to reconnect a broken link or establish a link where we
// have already failed at least once.
// try to open a socket.
-
- mSocket = new EtchServerSocket();
+ if (mSocket == NULL) {
+ mSocket = new EtchServerSocket();
+ }
if (mSocket->bind(mPort) == ETCH_OK) {
if (mSocket->listen(mBackLog) == ETCH_OK) {
mMutexConnection.unlock();
@@ -97,7 +129,6 @@
CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpListener", "Listening on specified port has failed");
}
} else {
- mSocket->close();
delete mSocket;
mSocket = NULL;
CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpListener", "Binding to specified port has failed");
@@ -110,7 +141,7 @@
status_t EtchTcpListener::readSocket() {
EtchSocket* s = NULL;
- while (isStarted()) {
+ while (mIsStarted) {
s = mSocket->accept();
if (s == NULL)
break;
@@ -136,8 +167,11 @@
mIsStarted = true;
mMutex.unlock();
mThread = new capu::Thread(this);
+ mConnectionChecker = new ConnectionChecker(this);
+ mConnectionCheckerThread = new capu::Thread(mConnectionChecker);
mThread->start();
CAPU_LOG_DEBUG(mRuntime->getLogger(), "EtchTcpListener", "Start command received and EtchTcpListener starts listening on port %d", mPort);
+ mConnectionCheckerThread->start();
return ETCH_OK;
}
@@ -150,8 +184,11 @@
mIsStarted = true;
mMutex.unlock();
mThread = new capu::Thread(this);
+ mConnectionChecker = new ConnectionChecker(this);
+ mConnectionCheckerThread = new capu::Thread(mConnectionChecker);
mThread->start();
CAPU_LOG_DEBUG(mRuntime->getLogger(), "EtchTcpListener", "Start and wait up command received and EtchTcpListener starts listening on port %d", mPort);
+ mConnectionCheckerThread->start();
return waitUp(((EtchInt32*) value.get())->get());
}
@@ -175,10 +212,9 @@
mMutex.lock();
mIsStarted = false;
mMutex.unlock();
- status_t ret = waitDown(((EtchInt32*) value.get())->get());
close();
CAPU_LOG_DEBUG(mRuntime->getLogger(), "EtchTcpListener", "Stop and wait command received and EtchTcpListener sets the stop flag");
- //TODO: Wait handling in one of the next releases
+ status_t ret = waitDown(((EtchInt32*) value.get())->get());
return ret;
}
@@ -223,7 +259,7 @@
while (mIsStarted) {
- if (openSocket(!first) != ETCH_OK) {
+ if (openSocket(first) != ETCH_OK) {
CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpListener", "Socket has not been created");
break;
}
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
index 8e377c1..16641e2 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
@@ -15,6 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "support/EtchTransportHelper.h"
+#include "support/EtchStackServer.h"
#include "transport/EtchTcpTransportFactory.h"
static const char* TAG = "EtchTcpTransportFactory";
@@ -39,9 +41,20 @@
}
status_t EtchTcpTransportFactory::newTransport(EtchString uri, EtchResources* resources, EtchTransportMessage*& result) {
+ status_t status;
+
+ if (resources == NULL) {
+ return ETCH_ERROR;
+ }
+
+ EtchStack* stack = NULL;
+ status = resources->get(EtchStack::STACK(), (EtchObject*&)stack);
+ if (status != ETCH_OK) {
+ return status;
+ }
+
EtchURL u(uri);
- status_t status;
EtchObject* socket = NULL;
status = resources->get(SOCKET(), socket);
@@ -54,22 +67,20 @@
// TODO add runtime
c = new EtchTcpConnection(NULL, (EtchSocket*) socket, &u);
}
+ stack->setTransportData(c);
EtchTransportPacket* p = new EtchPacketizer(c, &u);
+ stack->setTransportPacket(p);
EtchTransportMessage* m = new EtchMessagizer(p, &u, resources);
+ stack->setTransportMessage(m);
//TODO: ADD FILTERS HERE
EtchObject* obj = NULL;
if (resources->get(EtchTransport<EtchSocket>::VALUE_FACTORY(), obj) != ETCH_OK) {
- c->setSession(NULL);
- p->setSession(NULL);
- m->setSession(NULL);
- delete c;
- delete p;
- delete m;
+ delete stack;
return ETCH_ENOT_EXIST;
}
EtchValueFactory *vf = (EtchValueFactory*) obj;
@@ -90,18 +101,19 @@
l = new EtchTcpListener(&u);
}
- result = new MySessionListener(mRuntime, l, uri, resources, mIsSecure);
+ result = new MySessionListener(mRuntime, this, l, uri, resources, mIsSecure);
if (result == NULL) {
return ETCH_ERROR;
}
return ETCH_OK;
}
-EtchTcpTransportFactory::MySessionListener::MySessionListener(EtchRuntime* runtime, EtchTransport<EtchSessionListener<EtchSocket> > *transport, EtchString uri, EtchResources* resources, capu::bool_t secure)
-: mRuntime(runtime), mTransport(transport), mUri(uri), mResources(resources), mIsSecure(secure) {
+EtchTcpTransportFactory::MySessionListener::MySessionListener(EtchRuntime* runtime, EtchTcpTransportFactory* factory, EtchTransport<EtchSessionListener<EtchSocket> > *transport, EtchString uri, EtchResources* resources, capu::bool_t secure)
+: mRuntime(runtime), mFactory(factory), mTransport(transport), mUri(uri), mResources(resources), mIsSecure(secure) {
if (mTransport != NULL) {
mTransport->setSession(this);
}
+ mConnectionStacks = new capu::List<EtchStack*>();
}
EtchServerFactory* EtchTcpTransportFactory::MySessionListener::getSession() {
@@ -112,6 +124,22 @@
if(mTransport != NULL) {
delete mTransport;
}
+ if(mFactory != NULL) {
+ delete mFactory;
+ }
+ if (mResources != NULL) {
+ EtchTransportHelper::DestroyResources(mResources);
+ }
+
+ capu::List<EtchStack*>::Iterator it = mConnectionStacks->begin();
+ while (it.hasNext()) {
+ EtchStack* st = NULL;
+ it.next(&st);
+ if (st != NULL) {
+ delete st;
+ }
+ }
+ delete mConnectionStacks;
}
void EtchTcpTransportFactory::MySessionListener::setSession(EtchServerFactory* session) {
@@ -139,7 +167,30 @@
}
status_t EtchTcpTransportFactory::MySessionListener::sessionNotify(capu::SmartPointer<EtchObject> event) {
+ if (event->equals(&EtchTcpListener::CONNECTION_CHECK())) {
+ //go through the list of connection and check if the connection is still dead and we have to clean the stack up
+ capu::List<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) {
+ if (!con->isStarted()) {
+ //delete all instances for this stack
+ delete stack;
+ //remote stack from list
+ mConnectionStacks->removeAt(it);
+ }
+ }
+ }
+ it.next();
+ }
+ return ETCH_OK;
+ }
+
return mSession->sessionNotify(event);
+
}
status_t EtchTcpTransportFactory::MySessionListener::sessionAccepted(EtchSocket* connection) {
@@ -147,60 +198,56 @@
return ETCH_ERROR;
}
+ status_t status;
+
+ EtchStackServer *stack = new EtchStackServer();
+
EtchResources *res = new EtchResources(mResources);
+ stack->setResources(res);
// put socket to the resources
EtchObject *obj = NULL;
- if (res->put(SOCKET(), connection, obj) != ETCH_OK) {
- delete res;
+ status = res->put(SOCKET(), connection, obj);
+ if (status != ETCH_OK) {
+ delete stack;
return ETCH_ERROR;
}
// create value vatory and put it to the resources
EtchValueFactory* vf = NULL;
- if(mSession->newValueFactory(mUri, vf) != ETCH_OK) {
- delete res;
+ status = mSession->newValueFactory(mUri, vf);
+ if(status != ETCH_OK) {
+ delete stack;
return ETCH_ERROR;
}
- if(res->put(EtchTransport<EtchSocket>::VALUE_FACTORY(), vf, obj) != ETCH_OK)
- {
- delete vf;
- delete res;
+ stack->setValueFactory(vf);
+
+ status = res->put(EtchTransport<EtchSocket>::VALUE_FACTORY(), vf, obj);
+ if(status != ETCH_OK) {
+ delete stack;
return ETCH_ERROR;
}
- EtchURL u = EtchURL(mUri);
-
- EtchObject* socket = NULL;
- if (res->get(SOCKET(), socket) != ETCH_OK) {
- return ETCH_ENOT_EXIST;
+ EtchObject* old = NULL;
+ status = res->put(EtchStack::STACK(), stack, old);
+ if (status != ETCH_OK) {
+ delete stack;
+ return ETCH_ERROR;
}
- // TODO check if we should register a new stack to the runtime
-
- EtchTransportData *c = NULL;
- if (mIsSecure) {
- //TODO : secure communication via ssl sockets
- return ETCH_EUNIMPL;
- } else {
- c = new EtchTcpConnection(mRuntime, (EtchSocket*) socket, &u);
+ if (old != NULL) {
+ delete old;
}
- EtchTransportPacket* p = new EtchPacketizer(c, &u);
+ //add stack container to list
+ mConnectionStacks->add(stack);
- EtchTransportMessage* m = new EtchMessagizer(p, &u, res);
-
- //TODO: ADD FILTERS HERE
-
- if (res->get(EtchTransport<EtchSocket>::VALUE_FACTORY(), obj) != ETCH_OK) {
- c->setSession(NULL);
- p->setSession(NULL);
- m->setSession(NULL);
- delete c;
- delete p;
- delete m;
- return ETCH_ENOT_EXIST;
+ EtchTransportMessage *m = NULL;
+ status = mFactory->newTransport(mUri, res, m);
+ if (status != ETCH_OK) {
+ delete stack;
+ return status;
}
- vf->lockDynamicTypes();
CAPU_LOG_DEBUG(mRuntime->getLogger(), TAG, "New stack for the accepted connection has been created");
+
return mSession->newServer(mRuntime, m, mUri, res);
}
diff --git a/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp b/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp
index cc4f853..9991bad 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTransportFactory.cpp
@@ -61,7 +61,7 @@
}
status_t ret = f->newListener(uri, resources, result);
- delete f;
+
return ret;
}
diff --git a/binding-cpp/runtime/src/test/serialization/EtchClass2TypeMapTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchClass2TypeMapTest.cpp
index c45acaa..eef622f 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchClass2TypeMapTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchClass2TypeMapTest.cpp
@@ -68,17 +68,12 @@
//Try to add existing field
EXPECT_EQ(ETCH_OK, test->put(EtchString::TYPE(), type));
- //Try to add a new field
- EtchType* type2 = new EtchType(EtchString("string2"));
- EXPECT_EQ(ETCH_ERANGE, test->put(EtchString::TYPE(), type2));
-
//lock the collection
test->lock();
//try to add new field
EXPECT_EQ(ETCH_EINVAL, test->put(EtchString::TYPE(), type));
delete test;
delete type;
- delete type2;
}
TEST(EtchClass2TypeMapTest, lockTest) {
diff --git a/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp
index 1be2826..6511378 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp
@@ -20,7 +20,29 @@
#include "serialization/EtchValidatorString.h"
#include "serialization/EtchValidatorInt.h"
-TEST(EtchComboValidatorTest, createTest) {
+class EtchComboValidatorTest
+ : public ::testing::Test {
+protected:
+ virtual void SetUp() {
+ mRuntime = new EtchRuntime();
+ mRuntime->setLogger(new EtchLogger());
+ mRuntime->start();
+ }
+
+ virtual void TearDown() {
+ mRuntime->shutdown();
+ EtchLogger* logger = mRuntime->getLogger();
+ if(logger != NULL) {
+ delete logger;
+ }
+ delete mRuntime;
+ mRuntime = NULL;
+ }
+
+ EtchRuntime* mRuntime;
+};
+
+TEST_F(EtchComboValidatorTest, createTest) {
capu::SmartPointer<EtchValidator> ptr;
capu::SmartPointer<EtchValidator> ptr2;
@@ -32,7 +54,7 @@
delete combo;
}
-TEST(EtchComboValidatorTest, validateTest) {
+TEST_F(EtchComboValidatorTest, validateTest) {
capu::SmartPointer<EtchObject> byte = NULL;
capu::SmartPointer<EtchObject> integer = new EtchInt32(capu::NumericLimitMin<capu::int32_t>());
@@ -92,7 +114,7 @@
delete ptr;
}
-TEST(EtchComboValidatorTest, validateValueTest) {
+TEST_F(EtchComboValidatorTest, validateValueTest) {
capu::SmartPointer<EtchObject> byte = NULL;
capu::SmartPointer<EtchObject> result = NULL;
@@ -127,7 +149,7 @@
delete ptr;
}
-TEST(EtchComboValidatorTest, elementValidatorTest) {
+TEST_F(EtchComboValidatorTest, elementValidatorTest) {
//create combo validator
EtchComboValidator *ptr = NULL;
capu::SmartPointer<EtchValidator> ptr1;
diff --git a/binding-cpp/runtime/src/test/serialization/EtchTypeMapTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchTypeMapTest.cpp
index 633f393..23cd9f0 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchTypeMapTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchTypeMapTest.cpp
@@ -41,7 +41,6 @@
test->lock();
//try to add new type
EXPECT_EQ(ETCH_EINVAL, test->add(type));
- delete type;
delete test;
}
@@ -81,8 +80,6 @@
EXPECT_EQ(ETCH_OK, test->get("testtype2", tmp1));
delete test;
- delete type;
- delete tmp1;
}
TEST(EtchTypeMapTest, sizeTest) {
@@ -101,7 +98,6 @@
//check size
EXPECT_EQ(1, test->size());
delete test;
- delete type;
}
TEST(EtchTypeMapTest, lockTest) {
@@ -122,7 +118,6 @@
//check size again
EXPECT_EQ(1, test->size());
delete test;
- delete type;
}
TEST(EtchTypeMapTest, getAllTest) {
@@ -149,5 +144,4 @@
}
delete test;
- delete type;
}
\ No newline at end of file
diff --git a/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp b/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp
index fc1d8ab..33bfd16 100644
--- a/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp
+++ b/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp
@@ -129,13 +129,15 @@
EtchDeliveryService * service = NULL;
service = new EtchDefaultDeliveryService(manager, &u);
EtchRemoteBase * remote = NULL;
- remote = new EtchRemoteBase(service, factory->factory);
+ remote = new EtchRemoteBase(service, factory->factory, NULL);
EXPECT_TRUE(remote != NULL);
manager->setSession(service);
service->setSession(&session);
delete remote;
+ delete transport;
+ delete manager;
delete service;
delete factory;
}
@@ -154,7 +156,7 @@
EtchDeliveryService * service = NULL;
service = new EtchDefaultDeliveryService(manager, &u);
EtchRemoteBase * remote = NULL;
- remote = new EtchRemoteBase(service, factory->factory);
+ remote = new EtchRemoteBase(service, factory->factory, NULL);
EXPECT_TRUE(remote != NULL);
manager->setSession(service);
@@ -173,7 +175,9 @@
//check the assigned factory
EXPECT_TRUE(factory->factory == msg->getValueFactory());
+ delete transport;
delete remote;
+ delete manager;
delete service;
delete factory;
}
@@ -192,7 +196,7 @@
EtchDeliveryService * service = NULL;
service = new EtchDefaultDeliveryService(manager, &u);
EtchRemoteBase * remote = NULL;
- remote = new EtchRemoteBase(service, factory->factory);
+ remote = new EtchRemoteBase(service, factory->factory, NULL);
EXPECT_TRUE(remote != NULL);
manager->setSession(service);
@@ -215,7 +219,10 @@
EXPECT_TRUE(remote->send(msg) == ETCH_OK);
factory->types.clear();
+
+ delete transport;
delete remote;
+ delete manager;
delete service;
delete factory;
}
@@ -234,7 +241,7 @@
EtchDeliveryService * service = NULL;
service = new EtchDefaultDeliveryService(manager, &u);
EtchRemoteBase * remote = NULL;
- remote = new EtchRemoteBase(service, factory->factory);
+ remote = new EtchRemoteBase(service, factory->factory, NULL);
EXPECT_TRUE(remote != NULL);
manager->setSession(service);
@@ -262,7 +269,10 @@
EXPECT_TRUE(mail != NULL);
factory->types.clear();
+
+ delete transport;
delete remote;
+ delete manager;
delete service;
delete factory;
}
@@ -281,7 +291,7 @@
EtchDeliveryService * service = NULL;
service = new EtchDefaultDeliveryService(manager, &u);
EtchRemoteBase * remote = NULL;
- remote = new EtchRemoteBase(service, factory->factory);
+ remote = new EtchRemoteBase(service, factory->factory, NULL);
EXPECT_TRUE(remote != NULL);
manager->setSession(service);
@@ -331,8 +341,11 @@
EXPECT_TRUE(result == data);
factory->types.clear();
+
+ delete transport;
delete mail;
delete remote;
+ delete manager;
delete service;
delete factory;
}
diff --git a/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp b/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp
index 514e970..3d94671 100644
--- a/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp
+++ b/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp
@@ -142,6 +142,8 @@
// create mock layer for session
MockSession1* session = new MockSession1(deliveryService);
+ delete transport;
+ delete mailboxManager;
delete session;
}
@@ -190,6 +192,8 @@
//put the stack down
mailboxManager->sessionNotify(new EtchString(EtchSession::DOWN()));
+ delete transport;
+ delete mailboxManager;
delete session;
delete factory;
}
@@ -264,6 +268,8 @@
//check the result
EXPECT_TRUE(result->equals(data.get()));
+ delete transport;
+ delete mailboxManager;
delete session;
delete factory;
}
diff --git a/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp b/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp
index 2ff65b1..e767605 100644
--- a/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp
+++ b/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp
@@ -1,35 +1,35 @@
-/* $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 <gtest/gtest.h>
-#include <gmock/gmock.h>
-#include "serialization/EtchDefaultValueFactory.h"
-#include "serialization/EtchBinaryTaggedData.h"
-#include "serialization/EtchBinaryTaggedDataInput.h"
-#include "serialization/EtchValidatorShort.h"
-#include "transport/EtchMessagizer.h"
-#include "transport/EtchTcpConnection.h"
-#include "transport/EtchPacketizer.h"
-#include "transport/EtchSessionListener.h"
-#include "transport/EtchTcpListener.h"
-
-
-class MockListener11 : public virtual EtchSessionListener<EtchSocket> {
-public:
-
+/* $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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include "serialization/EtchDefaultValueFactory.h"
+#include "serialization/EtchBinaryTaggedData.h"
+#include "serialization/EtchBinaryTaggedDataInput.h"
+#include "serialization/EtchValidatorShort.h"
+#include "transport/EtchMessagizer.h"
+#include "transport/EtchTcpConnection.h"
+#include "transport/EtchPacketizer.h"
+#include "transport/EtchSessionListener.h"
+#include "transport/EtchTcpListener.h"
+
+
+class MockListener11 : public virtual EtchSessionListener<EtchSocket> {
+public:
+
MockListener11(EtchTransport<EtchSessionListener<EtchSocket> >* transport)
: mTransport(transport) {
if(mTransport != NULL) {
@@ -42,38 +42,38 @@
delete mTransport;
}
}
-
+
//This method is called
- status_t sessionAccepted(EtchSocket* connection) {
- delete connection;
- return ETCH_OK;
- }
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
+ status_t sessionAccepted(EtchSocket* connection) {
+ delete connection;
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
private:
EtchTransport<EtchSessionListener<EtchSocket> >* mTransport;
-};
-
-class MockMailboxManager : public EtchSessionMessage {
-public:
-
- status_t sessionMessage(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchMessage> buf) {
- EXPECT_TRUE(buf->count() == 1);
+};
+
+class MockMailboxManager : public EtchSessionMessage {
+public:
+
+ status_t sessionMessage(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchMessage> buf) {
+ EXPECT_TRUE(buf->count() == 1);
buf->clear();
- return ETCH_OK;
- }
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
@@ -116,43 +116,48 @@
EtchTransportData* conn = new EtchTcpConnection(mRuntime, NULL, &u);
EtchTransportPacket* pac = new EtchPacketizer(conn, &u);
EtchSessionPacket* mes = new EtchMessagizer(pac, &u, &r);
- //Created stack
- delete mes;
+
+ //Delete created stack
+ delete conn;
+ delete mes;
+ delete pac;
delete factory;
types.clear();
}
-TEST_F(EtchMessagizerTest, TransportControlTest) {
- EtchTypeMap types;
- EtchClass2TypeMap class2type;
- EtchDefaultValueFactory * factory;
+TEST_F(EtchMessagizerTest, TransportControlTest) {
+ EtchTypeMap types;
+ EtchClass2TypeMap class2type;
+ EtchDefaultValueFactory * factory;
MockMailboxManager manager;
- EtchDefaultValueFactory::Init(&types, &class2type);
- EtchString uri("tcp://127.0.0.1:4001");
- factory = new EtchDefaultValueFactory(uri, &types, &class2type);
- //created value factory
- EtchURL u("tcp://127.0.0.1:4001");
- EtchResources r;
- EtchObject *out;
+ EtchDefaultValueFactory::Init(&types, &class2type);
+ EtchString uri("tcp://127.0.0.1:4001");
+ factory = new EtchDefaultValueFactory(uri, &types, &class2type);
+ //created value factory
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchResources r;
+ EtchObject *out;
r.put(EtchTransport<EtchSessionMessage>::VALUE_FACTORY(), factory, out);
EtchTransportData* conn = new EtchTcpConnection(mRuntime, NULL, &u);
EtchPacketizer* pac = new EtchPacketizer(conn, &u);
EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
mess->setSession(&manager);
-
+
EtchTcpListener* transport = new EtchTcpListener(&u);
EtchSessionListener<EtchSocket>* mSessionListener = new MockListener11(transport);
transport->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP()), new EtchInt32(1000));
mess->transportControl(new EtchString(EtchPacketizer::START_AND_WAIT_UP()), new EtchInt32(1000));
- //test transport commands
+ //test transport commands
mess->transportControl(new EtchString(EtchPacketizer::STOP_AND_WAIT_DOWN()), new EtchInt32(1000));
transport->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN()), new EtchInt32(1000));
- delete mSessionListener;
- delete mess;
+ delete conn;
+ delete mSessionListener;
+ delete pac;
+ delete mess;
delete factory;
types.clear();
}
@@ -162,34 +167,36 @@
EtchClass2TypeMap class2type;
EtchDefaultValueFactory * factory;
MockMailboxManager manager;
- EtchDefaultValueFactory::Init(&types, &class2type);
- EtchString uri("tcp://127.0.0.1:4001");
- factory = new EtchDefaultValueFactory(uri, &types, &class2type);
- //default value factory
- EtchURL u("tcp://127.0.0.1:4001");
- EtchResources r;
- EtchObject *out;
- //add to the resource
+ EtchDefaultValueFactory::Init(&types, &class2type);
+ EtchString uri("tcp://127.0.0.1:4001");
+ factory = new EtchDefaultValueFactory(uri, &types, &class2type);
+ //default value factory
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchResources r;
+ EtchObject *out;
+ //add to the resource
r.put(EtchTransport<EtchSessionMessage>::VALUE_FACTORY(), factory, out);
EtchTransportData* conn = new EtchTcpConnection(mRuntime, NULL, &u);
EtchPacketizer* pac = new EtchPacketizer(conn, &u);
EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
mess->setSession(&manager);
- //creation of example message which will be serialized
- EtchType *mt_foo = NULL;
- EtchField mf_x("x");
- EtchString str("foo");
- factory->getType(str, mt_foo);
- capu::SmartPointer<EtchValidator> v;
- EtchValidatorShort::Get(0, v);
- mt_foo->putValidator(mf_x, v);
- capu::SmartPointer<EtchShort> data = new EtchShort(10000);
- capu::SmartPointer<EtchMessage> msg = new EtchMessage(mt_foo, factory);
- msg->put(mf_x, data);
-
+ //creation of example message which will be serialized
+ EtchType *mt_foo = NULL;
+ EtchField mf_x("x");
+ EtchString str("foo");
+ factory->getType(str, mt_foo);
+ capu::SmartPointer<EtchValidator> v;
+ EtchValidatorShort::Get(0, v);
+ mt_foo->putValidator(mf_x, v);
+ capu::SmartPointer<EtchShort> data = new EtchShort(10000);
+ capu::SmartPointer<EtchMessage> msg = new EtchMessage(mt_foo, factory);
+ msg->put(mf_x, data);
+
EXPECT_TRUE(mess->transportMessage(NULL, msg) == ETCH_ERROR);
- delete mess;
+ delete conn;
+ delete mess;
+ delete pac;
delete factory;
types.clear();
}
@@ -248,7 +255,9 @@
mess->setSession(NULL);
types.clear();
- delete mMailboxManager;
- delete mess;
+ delete conn;
+ delete mMailboxManager;
+ delete pac;
+ delete mess;
delete factory;
}
diff --git a/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp b/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp
index 70afd25..bdb72e7 100644
--- a/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp
+++ b/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp
@@ -1,36 +1,36 @@
-/* $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 <gtest/gtest.h>
-#include <gmock/gmock.h>
-#include "transport/EtchPacketizer.h"
-#include "common/EtchString.h"
-#include "common/EtchError.h"
-#include "util/EtchURL.h"
-#include "transport/EtchTcpConnection.h"
-#include "capu/util/SmartPointer.h"
-#include "common/EtchSocket.h"
-#include "transport/EtchSessionListener.h"
-#include "transport/EtchTcpListener.h"
-#include "transport/EtchSessionPacket.h"
-#include "transport/EtchFlexBuffer.h"
-
-class MockListener3 : public virtual EtchSessionListener<EtchSocket> {
-public:
-
+/* $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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include "transport/EtchPacketizer.h"
+#include "common/EtchString.h"
+#include "common/EtchError.h"
+#include "util/EtchURL.h"
+#include "transport/EtchTcpConnection.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchSocket.h"
+#include "transport/EtchSessionListener.h"
+#include "transport/EtchTcpListener.h"
+#include "transport/EtchSessionPacket.h"
+#include "transport/EtchFlexBuffer.h"
+
+class MockListener3 : public virtual EtchSessionListener<EtchSocket> {
+public:
+
MockListener3(EtchTransport<EtchSessionListener<EtchSocket> >* transport) :
mTransport(transport) {
if(mTransport != NULL) {
@@ -43,34 +43,34 @@
delete mTransport;
}
}
-
+
//This method is called
- status_t sessionAccepted(EtchSocket* connection) {
- delete connection;
- return ETCH_OK;
- }
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
+ status_t sessionAccepted(EtchSocket* connection) {
+ delete connection;
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
private:
EtchTransport<EtchSessionListener<EtchSocket> >* mTransport;
-};
-
-class MockMessagizer : public EtchSessionPacket {
-public:
-
- MOCK_METHOD2(sessionPacket, status_t(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchFlexBuffer> buf));
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
+};
+
+class MockMessagizer : public EtchSessionPacket {
+public:
+
+ MOCK_METHOD2(sessionPacket, status_t(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchFlexBuffer> buf));
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
@@ -102,7 +102,10 @@
EtchURL u("tcp://127.0.0.1:4001");
EtchTransportData* conn = new EtchTcpConnection(mRuntime, NULL, &u);
EtchSessionData* packetizer = new EtchPacketizer(conn, &u);
- delete packetizer;
+
+ delete conn;
+ delete packetizer;
+
}
TEST_F(EtchPacketizerTest, TransportControlTest) {
@@ -112,18 +115,18 @@
MockMessagizer mes;
packetizer->setSession(&mes);
-
EtchTcpListener* transport = new EtchTcpListener(&u);
EtchSessionListener<EtchSocket>* listener = new MockListener3(transport);
- //Start the mock listener
+ //Start the mock listener
transport->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP()), new EtchInt32(1000));
-
+
packetizer->transportControl(new EtchString(EtchPacketizer::START_AND_WAIT_UP()), new EtchInt32(1000));
packetizer->transportControl(new EtchString(EtchPacketizer::STOP_AND_WAIT_DOWN()), new EtchInt32(1000));
-
+
transport->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN()), new EtchInt32(1000));
-
+
+ delete conn;
delete packetizer;
delete listener;
}
@@ -142,6 +145,8 @@
buffer->setIndex(0);
EXPECT_TRUE(packetizer->transportPacket(NULL, buffer) == ETCH_ERROR);
+
+ delete conn;
delete packetizer;
}
@@ -151,21 +156,22 @@
EtchPacketizer* packetizer = new EtchPacketizer(conn, &u);
capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
//A packet is created
- capu::int32_t pktsize = 4;
+ capu::int32_t pktsize = 4;
buffer->putInt(packetizer->SIG());
buffer->putInt(pktsize);
- buffer->put((capu::int8_t *)"test", pktsize);
- buffer->setIndex(0);
- EXPECT_TRUE(buffer->getLength() == 12);
-
- EtchSessionPacket* mSessionPacker = new MockMessagizer();
- packetizer->setSession(mSessionPacker);
-
- MockMessagizer * mock = (MockMessagizer*) mSessionPacker;
- EXPECT_CALL(*mock, sessionPacket(capu::SmartPointer<EtchWho > (NULL), buffer));
- EXPECT_TRUE(packetizer->sessionData(NULL, buffer) == ETCH_OK);
-
- packetizer->setSession(NULL);
- delete mSessionPacker;
- delete packetizer;
+ buffer->put((capu::int8_t *)"test", pktsize);
+ buffer->setIndex(0);
+ EXPECT_TRUE(buffer->getLength() == 12);
+
+ EtchSessionPacket* mSessionPacker = new MockMessagizer();
+ packetizer->setSession(mSessionPacker);
+
+ MockMessagizer * mock = (MockMessagizer*) mSessionPacker;
+ EXPECT_CALL(*mock, sessionPacket(capu::SmartPointer<EtchWho > (NULL), buffer));
+ EXPECT_TRUE(packetizer->sessionData(NULL, buffer) == ETCH_OK);
+
+ packetizer->setSession(NULL);
+ delete mSessionPacker;
+ delete packetizer;
+ delete conn;
}
diff --git a/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp b/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp
index bf5866d..fd4f211 100644
--- a/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp
+++ b/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp
@@ -126,6 +126,7 @@
EXPECT_TRUE(manager != NULL);
manager->setSession(&session);
+ delete transport;
delete manager;
delete factory;
}
@@ -165,6 +166,8 @@
EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
message->clear();
+
+ delete transport;
delete manager;
delete factory;
}
@@ -207,6 +210,8 @@
EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
message->clear();
+
+ delete transport;
delete manager;
delete factory;
}
@@ -248,6 +253,8 @@
EXPECT_TRUE(ETCH_OK == manager->getMailbox(id, mail));
message->clear();
+
+ delete transport;
delete manager;
delete factory;
}
@@ -293,6 +300,8 @@
EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
message->clear();
+
+ delete transport;
delete manager;
delete factory;
}
@@ -354,6 +363,7 @@
//deallocations
delete x;
+ delete transport;
delete manager;
delete factory;
}
diff --git a/examples/helloworld/cpp/CMakeLists.txt b/examples/helloworld/cpp/CMakeLists.txt
index 9e36c65..ec5c7c9 100644
--- a/examples/helloworld/cpp/CMakeLists.txt
+++ b/examples/helloworld/cpp/CMakeLists.txt
@@ -21,6 +21,9 @@
cmake_minimum_required (VERSION 2.8)
project (etch-cpp-helloworld)
+IF (EXISTS "${CMAKE_SOURCE_DIR}/CMakeLists_local.txt")
+ INCLUDE ("${CMAKE_SOURCE_DIR}/CMakeLists_local.txt" OPTIONAL)
+ENDIF()
IF(UNIX)
add_definitions("-DOS_LINUX")
@@ -116,6 +119,12 @@
set_target_properties(etch-cpp-helloworld-server PROPERTIES COMPILE_FLAGS "-m32 -g" LINK_FLAGS "-m32")
ELSEIF(WIN32)
target_link_libraries(etch-cpp-helloworld-server ${ETCH_LIBRARY} ${CAPU_LIBRARY})
+IF (BUILD_CHECK_MEMORY)
+ file (COPY ${VLD}/vld.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ file (COPY ${VLD}/bin/dbghelp.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ file (COPY ${VLD}/bin/vld.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ target_link_libraries (etch-cpp-helloworld-server ${VLD}/lib/vld.lib)
+ENDIF (BUILD_CHECK_MEMORY)
ENDIF ()
set_target_properties(etch-cpp-helloworld-server PROPERTIES OUTPUT_NAME "helloworld-server")
@@ -147,6 +156,12 @@
set_target_properties(etch-cpp-helloworld-client PROPERTIES COMPILE_FLAGS "-m32 -g" LINK_FLAGS "-m32")
ELSEIF(WIN32)
target_link_libraries(etch-cpp-helloworld-client ${ETCH_LIBRARY} ${CAPU_LIBRARY})
+IF (BUILD_CHECK_MEMORY)
+ file (COPY ${VLD}/vld.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ file (COPY ${VLD}/bin/dbghelp.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ file (COPY ${VLD}/bin/vld.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ target_link_libraries (etch-cpp-helloworld-client ${VLD}/lib/vld.lib)
+ENDIF (BUILD_CHECK_MEMORY)
ENDIF ()
set_target_properties(etch-cpp-helloworld-client PROPERTIES OUTPUT_NAME "helloworld-client")
diff --git a/examples/helloworld/cpp/src/main/src/MainHelloWorldClient.cpp b/examples/helloworld/cpp/src/main/src/MainHelloWorldClient.cpp
index 137e699..ddc34f4 100644
--- a/examples/helloworld/cpp/src/main/src/MainHelloWorldClient.cpp
+++ b/examples/helloworld/cpp/src/main/src/MainHelloWorldClient.cpp
@@ -12,7 +12,9 @@
#include "MainHelloWorldClient.h"
#include "ImplHelloWorldClient.h"
#include "transport/EtchTransportData.h"
-
+#ifdef BUILD_CHECK_MEMORY
+#include "vld.h"
+#endif
using namespace org_apache_etch_examples_helloworld_HelloWorld;
@@ -64,6 +66,9 @@
// Disconnect from the service
remote->transportControl(new EtchString(EtchTransportData::STOP_AND_WAIT_DOWN()), new EtchInt32(4000));
+ //delete remote
+ delete remote;
+
//delete runtime
result = runtime->shutdown();
if (result != ETCH_OK) {
diff --git a/examples/helloworld/cpp/src/main/src/MainHelloWorldListener.cpp b/examples/helloworld/cpp/src/main/src/MainHelloWorldListener.cpp
index ca88a96..cfa5b37 100644
--- a/examples/helloworld/cpp/src/main/src/MainHelloWorldListener.cpp
+++ b/examples/helloworld/cpp/src/main/src/MainHelloWorldListener.cpp
@@ -6,16 +6,18 @@
// overwritten once it exists! Please edit this file as necessary to implement
// your service logic.
+#include "MainHelloWorldListener.h"
+#include "ImplHelloWorldServer.h"
+#include "RemoteHelloWorldClient.h"
+
#include "capu/os/Thread.h"
#include "common/EtchTypes.h"
#include "support/EtchRuntime.h"
-#include "RemoteHelloWorldClient.h"
-#include "MainHelloWorldListener.h"
-#include "ImplHelloWorldServer.h"
#include "transport/EtchTransportData.h"
-#include "util/EtchLogger.h"
-
+#ifdef BUILD_CHECK_MEMORY
+#include "vld.h"
+#endif
using namespace org_apache_etch_examples_helloworld_HelloWorld;
@@ -36,13 +38,6 @@
EtchRuntime* runtime = new EtchRuntime();
status = runtime->start();
- EtchLogger* logger = new EtchLogger();
- EtchAppender* appender = new EtchConsoleAppender();
- appender->setLoggingLevel(capu::CLL_TRACE);
- logger->setAppender(appender);
- EtchRuntime::setLogger(logger);
-
-
// TODO Change to correct URI
EtchString uri("tcp://0.0.0.0:4001");
@@ -52,21 +47,29 @@
status = HelloWorldHelper::newListener(runtime, uri, NULL, &mainHelloWorldlistener, listener);
- // Start the Listener
+ //start the Listener
status = listener->transportControl(new EtchString(EtchTransportData::START_AND_WAIT_UP()), new EtchInt32(4000));
+ if (status == ETCH_OK) {
+ printf("Hello World Server started successfully. Listening on port 4001\n\n");
+ } else {
+ printf("Error while starting Hello World Server. Errorcode %d \n\n", status);
+ return -1;
+ }
+
+ //waiting
+ printf("press any key to stop server\n");
+ getchar();
- //Wait for finish...
- capu::Thread::Sleep(200000);
-
- //Stop the Listener
+ //stop the Listener
listener->transportControl(new EtchString(EtchTransportData::STOP_AND_WAIT_DOWN()), new EtchInt32(4000));
+ //delete listener
+ delete listener;
+
//delete runtime
status = runtime->shutdown();
-
+
delete runtime;
- delete logger;
- delete appender;
return 0;
}