You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2009/01/30 23:25:07 UTC
svn commit: r739432 [3/9] - in
/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp:
./ Msg/ Support/ Transport/ Transport/Filter/ Transport/Fmt/
Transport/Fmt/Binary/ Util/
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TransportHelper.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TransportHelper.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TransportHelper.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TransportHelper.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,77 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Util;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Class to help construct transport stacks.
+ /// </summary>
+ public class TransportHelper
+ {
+ #region RESOURCES
+
+ /// <summary>
+ /// The Pool to use to execute queued async receiver messages. */
+ /// </summary>
+ public const String QUEUED_POOL = "QUEUED_POOL";
+
+ /// <summary>
+ /// The Pool to use to execute free async receiver messages.
+ /// </summary>
+ public const String FREE_POOL = "FREE_POOL";
+
+ /// <summary>
+ /// Binary transport format
+ /// </summary>
+ public const String BINARY = "binary";
+
+ /// <summary>
+ /// Xml transport format
+ /// </summary>
+ public const String XML = "xml";
+
+ #endregion
+
+ #region UTILITIES
+
+ /// <summary>
+ /// Initializes standard resources.
+ /// </summary>
+ /// <param name="resources">some initial values for resources. May be null to accept
+ /// all the defaults.</param>
+ /// <returns>copy of resources initialized with default values for standard items</returns>
+ public static Resources InitResources( Resources resources )
+ {
+ if ( resources == null )
+ resources = new Resources();
+ else
+ resources = new Resources(resources);
+
+ if ( !resources.ContainsKey( QUEUED_POOL ) )
+ resources.Add( QUEUED_POOL, new QueuedPool() );
+
+ if ( !resources.ContainsKey( FREE_POOL ) )
+ resources.Add( FREE_POOL, new FreePool() );
+
+ return resources;
+ }
+
+ #endregion
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TransportHelper.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TransportHelper.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TypeValidator.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TypeValidator.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TypeValidator.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TypeValidator.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,139 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Base class of validators which validate based on exact type.
+ /// </summary>
+ abstract public class TypeValidator : Validator
+ {
+
+ /// <summary>
+ /// Constructs the TypeValidator.
+ /// </summary>
+ /// <param name="scalarClass">class to use if nDims == 0</param>
+ /// <param name="arrayClass">class to use if nDims > 0</param>
+ /// <param name="nDims">the number of dimensions. 0 for a scalar.</param>
+ /// <param name="descr"></param>
+ public TypeValidator( Type scalarClass, Type arrayClass, int nDims,
+ String descr)
+ : this(scalarClass, arrayClass, nDims, descr, false)
+ {
+
+ }
+
+ /// <summary>
+ /// Constructs the TypeValidator.
+ /// </summary>
+ /// <param name="scalarClass">class to use if nDims == 0</param>
+ /// <param name="arrayClass">class to use if nDims > 0</param>
+ /// <param name="nDims">the number of dimensions. 0 for a scalar.</param>
+ /// <param name="descr"></param>
+ /// <param name="subclassOk">true of a subclass of the expected class is ok</param>
+ public TypeValidator(Type scalarClass, Type arrayClass, int nDims,
+ String descr, bool subclassOk)
+ {
+ CheckDims(nDims);
+
+ this.expectedClass = MkExpectedClass(scalarClass, arrayClass, nDims);
+ this.nDims = nDims;
+ this.descr = descr;
+ this.subclassOk = subclassOk;
+ }
+
+ /// <summary>
+ /// Checks the number of dimensions for standard validators.
+ /// </summary>
+ /// <param name="nDims"></param>
+ public static void CheckDims( int nDims )
+ {
+ if ( nDims < 0 || nDims > MAX_NDIMS )
+ throw new ArgumentOutOfRangeException( "nDims < 0 || nDims > MAX_NDIMS" );
+ }
+
+ private Type expectedClass;
+
+ /// <summary>
+ /// number of dimensions if this is an array
+ /// </summary>
+ protected int nDims;
+
+ protected bool subclassOk;
+
+ public int GetNDims()
+ {
+ return nDims;
+ }
+
+ private String descr;
+
+ public Type GetExpectedClass()
+ {
+ return expectedClass;
+ }
+
+ public override string ToString()
+ {
+ return descr;
+ }
+
+ public override bool Validate( object value )
+ {
+ if (value == null)
+ return false;
+ Type clss = value.GetType();
+
+ if (clss == expectedClass)
+ return true;
+
+ return subclassOk && expectedClass.IsAssignableFrom(clss);
+ }
+
+ public override object ValidateValue(object value)
+ {
+ if (Validate(value))
+ return value;
+
+ throw new Exception("value not appropriate for " + descr + ": " + value);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="scalarClass">class to use if nDims == 0</param>
+ /// <param name="arrayClass">class to use if nDims > 0</param>
+ /// <param name="nDims">number of dimensions, 0 for scalar</param>
+ /// <returns>an appropriate class given nDims.</returns>
+ ///
+ private static Type MkExpectedClass( Type scalarClass, Type arrayClass, int nDims )
+ {
+ if ( nDims == 0 )
+ return scalarClass;
+
+ Array tempArray = Array.CreateInstance( arrayClass, 1 );
+ // Note: About C# jagged arrays
+ //
+ for ( int i = 0; i < ( nDims - 1 ); i++ )
+ tempArray = Array.CreateInstance( tempArray.GetType(), 1 );
+
+ return tempArray.GetType();
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TypeValidator.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/TypeValidator.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_RuntimeException.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_RuntimeException.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_RuntimeException.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_RuntimeException.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,62 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for Runtime Exceptions
+ /// </summary>
+ public class Validator_RuntimeException : Validator
+ {
+ /// <summary></summary>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_RuntimeException Get()
+ {
+ if ( validator == null )
+ validator = new Validator_RuntimeException();
+
+ return validator;
+ }
+
+ private static Validator_RuntimeException validator;
+
+ public Validator_RuntimeException()
+ {
+ // nothing to do
+ }
+
+ public override Validator ElementValidator()
+ {
+ throw new Exception( "not an array" );
+ }
+
+ public override bool Validate( object value )
+ {
+ return ( value is Exception );
+ }
+
+ public override object ValidateValue(object value)
+ {
+ if (Validate(value))
+ return value;
+
+ throw new Exception("value not appropriate for RuntimeException: " + value);
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_RuntimeException.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_RuntimeException.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_StructValue.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_StructValue.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_StructValue.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_StructValue.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,60 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for structvalue
+ /// </summary>
+ public class Validator_StructValue : TypeValidator
+ {
+ public static Validator_StructValue Get(XType type, int nDims)
+ {
+ CheckDims(nDims);
+ return new Validator_StructValue(type,nDims);
+ }
+
+
+
+ private Validator_StructValue(XType type, int nDims)
+ : base( typeof( StructValue ), typeof( StructValue ), nDims, string.Format("StructValue[{0},{1}]",type,nDims) )
+ {
+ this.type = type;
+ }
+
+ private XType type;
+
+ public XType GetXType()
+ {
+ return type;
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get(type, nDims - 1);
+ }
+
+ public override bool Validate( object value )
+ {
+ return
+ base.Validate(value) &&
+ (value.GetType() != typeof (StructValue) || type.IsAssignableFrom(((StructValue) value).GetXType));
+
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_StructValue.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_StructValue.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_boolean.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_boolean.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_boolean.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_boolean.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,65 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for Boolean
+ /// </summary>
+ public class Validator_boolean : TypeValidator
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="nDims">number of dimensions. 0 for a scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_boolean Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_boolean( nDims );
+
+ Validator_boolean v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_boolean( nDims );
+
+ return v;
+ }
+
+ private static Validator_boolean[] validators = new Validator_boolean[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_boolean( int nDims )
+ : base( typeof( bool ), typeof( bool ), nDims, "boolean["+nDims+"]" )
+ {
+ }
+
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_boolean.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_boolean.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_byte.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_byte.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_byte.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_byte.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,106 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for byte
+ /// </summary>
+ public class Validator_byte : TypeValidator
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="nDims">number of dimensions. 0 for scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_byte Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_byte( nDims );
+
+ Validator_byte v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_byte( nDims );
+
+ return v;
+ }
+
+ private static Validator_byte[] validators = new Validator_byte[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_byte( int nDims )
+ : base( typeof( sbyte ), typeof( sbyte ), nDims, "byte["+nDims+"]" )
+ {
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+ public override bool Validate( object value )
+ {
+ if (nDims > 0)
+ return base.Validate(value);
+
+ if (value == null)
+ return false;
+
+ if (value.GetType() == typeof(sbyte))
+ return true;
+
+ if (value.GetType() == typeof(short))
+ {
+ short v = (short) value;
+ return v >= SByte.MinValue && v <= SByte.MaxValue;
+
+ }
+
+ if (value.GetType() == typeof(Int32))
+ {
+ int v = (Int32) value;
+ return v >= SByte.MinValue && v <= SByte.MaxValue;
+ }
+
+ if (value.GetType() == typeof(long))
+ {
+ long v = (long) value;
+ return v >= SByte.MinValue && v <= SByte.MaxValue;
+ }
+
+ return false;
+ }
+
+ public override object ValidateValue( object value )
+ {
+ value = base.ValidateValue(value);
+
+ if ((value.GetType() == typeof(sbyte)) || nDims > 0)
+ return value;
+
+ return Convert.ToSByte(value);
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_byte.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_byte.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_custom.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_custom.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_custom.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_custom.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,126 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using System.Collections.Generic;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for custom type
+ /// </summary>
+ public class Validator_custom : TypeValidator
+ {
+ /// <summary></summary>
+ /// <param name="clss">Class of the custom type</param>
+ /// <param name="nDims">number of dimensions. 0 for scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator Get( Type clss, int nDims, bool subclassOk )
+ {
+ CheckDims( nDims );
+
+ if ( nDims > MAX_CACHED )
+ return new Validator_custom( clss, nDims, subclassOk );
+
+ Key key = new Key(clss, nDims, subclassOk);
+ Validator v = null;
+
+ try
+ {
+ v = validators[key];
+ }
+ catch(Exception)
+ {
+ v = null;
+ }
+
+ if (v == null)
+ {
+ v = new Validator_custom(clss, nDims, subclassOk);
+ validators.Add(key, v);
+ }
+
+ return v;
+
+ }
+
+
+ private class Key
+ {
+ public Key( Type clss, int dims, bool subclassOk )
+ {
+ this.clss = clss;
+ this.dims = dims;
+ this.subclassOk = subclassOk;
+ }
+
+ private Type clss;
+
+ private int dims;
+
+ private bool subclassOk;
+
+
+ public override int GetHashCode()
+ {
+ return clss.GetHashCode() ^ (dims * 9131) ^ (subclassOk ? 21357 : 8547);
+ }
+
+
+ public override bool Equals( Object obj )
+ {
+ if (obj == this)
+ return true;
+
+ if (obj == null)
+ return false;
+
+ if (obj.GetType() != GetType())
+ return false;
+
+ Key other = (Key) obj;
+
+ return other.clss.Equals( clss)
+ && other.dims == dims
+ && other.subclassOk == subclassOk;
+ }
+ }
+
+ private static Dictionary<Key, Validator> validators =
+ new Dictionary<Key, Validator>();
+
+ /// <summary>
+ /// Constructs the validator
+ /// </summary>
+ /// <param name="clss">the class of the custom type</param>
+ /// <param name="nDims">the number of dimensions. 0 for scalar. </param>
+ private Validator_custom( Type clss, int nDims, bool subclassOk )
+ : base(clss, clss, nDims, subclassOk ? clss.ToString() + "[" + nDims + "]*" : clss.ToString() + "[" + nDims + "]", subclassOk)
+ {
+ this.clss = clss;
+ }
+
+ private Type clss;
+
+ public override Validator ElementValidator()
+ {
+ return Get( clss, nDims - 1, subclassOk );
+ }
+
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_custom.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_custom.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_double.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_double.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_double.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_double.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,62 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for double
+ /// </summary>
+ public class Validator_double : TypeValidator
+ {
+ /// <summary></summary>
+ /// <param name="nDims">number of dimensions. 0 for a scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_double Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_double( nDims );
+
+ Validator_double v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_double( nDims );
+
+ return v;
+ }
+
+ private static Validator_double[] validators = new Validator_double[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_double( int nDims )
+ : base( typeof( Double ), typeof( double ), nDims, "double["+nDims+"]" )
+ {
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_double.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_double.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_float.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_float.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_float.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_float.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,59 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ public class Validator_float : TypeValidator
+ {
+ /// <summary></summary>
+ /// <param name="nDims">number of dimensions. 0 for a scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_float Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_float( nDims );
+
+ Validator_float v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_float( nDims );
+
+ return v;
+ }
+
+ private static Validator_float[] validators = new Validator_float[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_float( int nDims )
+ : base( typeof( float ), typeof( float ), nDims, "float["+nDims+"]" )
+ {
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_float.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_float.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_int.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_int.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_int.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_int.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,96 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for int
+ /// </summary>
+ public class Validator_int : TypeValidator
+ {
+ /// <summary></summary>
+ /// <param name="nDims">number of dimensions. 0 for a scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_int Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_int( nDims );
+
+ Validator_int v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_int( nDims );
+
+ return v;
+ }
+
+ private static Validator_int[] validators = new Validator_int[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_int( int nDims )
+ : base( typeof( int ), typeof( int ), nDims, "int["+nDims+"]" )
+ {
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+
+ public override bool Validate( object value )
+ {
+ if (nDims > 0)
+ return base.Validate( value );
+
+ if (value == null)
+ return false;
+
+ Type type = value.GetType();
+
+ if ( type == typeof(Int32) || type == typeof(Int16) || type == typeof(sbyte) )
+ return true;
+
+ if (type == typeof(long))
+ {
+ long v = (long) value;
+ return v >= Int32.MinValue && v <= Int32.MaxValue;
+ }
+
+ return false;
+ }
+
+
+ public override object ValidateValue( object value )
+ {
+ value = base.ValidateValue( value );
+
+ if ( value.GetType() == typeof(Int32) || nDims > 0)
+ return value;
+
+ return Convert.ToInt32(value);
+ }
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_int.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_int.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_long.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_long.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_long.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_long.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,89 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for long
+ /// </summary>
+ public class Validator_long : TypeValidator
+ {
+ /// <summary></summary>
+ /// <param name="nDims">number of dimensions. 0 for a scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_long Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_long( nDims );
+
+ Validator_long v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_long( nDims );
+
+ return v;
+ }
+
+ private static Validator_long[] validators = new Validator_long[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_long( int nDims )
+ : base( typeof( long ), typeof( long ), nDims, "long["+nDims+"]" )
+ {
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+
+ public override bool Validate( object value )
+ {
+ if (nDims > 0)
+ return base.Validate( value );
+
+ if (value == null)
+ return false;
+
+ Type type = value.GetType();
+
+ return type == typeof(long) || type == typeof(Int32) ||
+ type == typeof(short) || type == typeof(sbyte);
+ }
+
+
+ public override object ValidateValue( object value )
+ {
+ value = base.ValidateValue( value );
+
+ if (value.GetType() == typeof(long) || nDims > 0)
+ return value;
+
+ return Convert.ToInt64(value);
+ }
+
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_long.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_long.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_object.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_object.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_object.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_object.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,52 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ public class Validator_object : TypeValidator
+ {
+
+ private static Validator_object[] validators = new Validator_object[MAX_CACHED];
+
+ public override Validator ElementValidator()
+ {
+ return nDims > 0 ? Get(nDims - 1) : this;
+ }
+
+ private Validator_object(int nDims)
+ : base(typeof (object), typeof (object), nDims, string.Format("object[{0}]", nDims), true)
+ {
+
+ }
+
+ public static Validator_object Get( int nDims )
+ {
+ CheckDims(nDims);
+
+ if (nDims >= validators.Length)
+ return new Validator_object(nDims);
+
+ Validator_object v = validators[nDims];
+
+ if ( v == null )
+ v=validators[nDims]= new Validator_object(nDims);
+
+ return v;
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_object.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_object.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_short.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_short.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_short.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_short.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,103 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for short
+ /// </summary>
+ public class Validator_short : TypeValidator
+ {
+ /// <summary></summary>
+ /// <param name="nDims">number of dimensions. 0 for a scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_short Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_short( nDims );
+
+ Validator_short v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_short( nDims );
+
+ return v;
+ }
+
+ private static Validator_short[] validators = new Validator_short[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_short( int nDims )
+ : base( typeof( short ), typeof( short ), nDims, "short["+nDims+"]" )
+ {
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+
+ public override bool Validate( object value )
+ {
+ if (nDims > 0)
+ return base.Validate( value );
+
+ if (value == null)
+ return false;
+
+ Type type = value.GetType();
+
+ if ( type == typeof(short) || type == typeof(sbyte))
+ return true;
+
+ if (type == typeof(Int32))
+ {
+ int v = (Int32) value;
+ return v >= short.MinValue&& v <= short.MaxValue;
+ }
+
+ if (type == typeof(long))
+ {
+ long v = (long) value;
+ return v >= short.MinValue && v <= short.MaxValue;
+ }
+
+ return false;
+ }
+
+
+ public override object ValidateValue( object value )
+ {
+ value = base.ValidateValue( value );
+
+ if (value.GetType() == typeof(short) || nDims > 0)
+ return value;
+
+ return Convert.ToInt16(value);
+ }
+
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_short.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_short.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_string.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_string.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_string.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_string.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,62 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for strings
+ /// </summary>
+ public class Validator_string : TypeValidator
+ {
+ /// <summary></summary>
+ /// <param name="nDims">number of dimensions. 0 for a scalar.</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_string Get( int nDims )
+ {
+ CheckDims( nDims );
+
+ if ( nDims >= validators.Length )
+ return new Validator_string( nDims );
+
+ Validator_string v = validators[ nDims ];
+
+ if ( v == null )
+ v = validators[ nDims ] = new Validator_string( nDims );
+
+ return v;
+ }
+
+ private static Validator_string[] validators = new Validator_string[ MAX_CACHED ];
+
+ /// <summary>
+ /// Constructs the validator.
+ /// </summary>
+ /// <param name="nDims"></param>
+ private Validator_string( int nDims )
+ : base( typeof( string ), typeof( string ), nDims, "string["+nDims+"]" )
+ {
+ }
+
+ public override Validator ElementValidator()
+ {
+ return Get( nDims - 1 );
+ }
+
+
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_string.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_string.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_void.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_void.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_void.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_void.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,66 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ /// <summary>
+ /// Validator for void
+ /// </summary>
+ public class Validator_void : Validator
+ {
+ /// <summary></summary>
+ /// <param name="nDims">the number of dimensions. 0 for scalar</param>
+ /// <returns>an instance of the validator</returns>
+ public static Validator_void Get( int nDims )
+ {
+ if ( nDims != 0 )
+ throw new ArgumentException( "nDims != 0" );
+
+ if ( validator == null )
+ validator = new Validator_void();
+
+ return validator;
+ }
+
+ private static Validator_void validator;
+
+ private Validator_void()
+ {
+ // nothing to do
+ }
+
+ public override Validator ElementValidator()
+ {
+ return null;
+ }
+
+ public override bool Validate( object value )
+ {
+ return value == null;
+ }
+
+ public override object ValidateValue(object value)
+ {
+ if (Validate(value))
+ return value;
+
+ throw new Exception("value not appropriate for void: " + value);
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_void.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/Validator_void.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_AuthException.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_AuthException.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_AuthException.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_AuthException.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,32 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+ public class _Etch_AuthException : _Etch_RuntimeException
+ {
+ public _Etch_AuthException()
+ {
+ // dont initialize anything
+ }
+
+ public _Etch_AuthException( String msg ) : base( msg )
+ {
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_AuthException.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_AuthException.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_RuntimeException.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_RuntimeException.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_RuntimeException.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_RuntimeException.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,71 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Support
+{
+
+ /// <summary>
+ /// Constructs the EtchRuntimeException. Don't init anything.
+ ///
+ /// Some common runtime exceptions are:
+ ///
+ /// ArgumentException
+ /// ArgumentNullException
+ /// ArgumentOutOfRangeException
+ /// ArithmeticException
+ /// DivideByZeroException
+ /// IndexOutOfRangeException
+ /// InvalidCastException
+ /// NotImplementedException
+ /// NotSupportedException
+ /// NullReferenceException
+ /// OverflowException
+ /// </summary>
+ public class _Etch_RuntimeException
+ : Exception
+ {
+ /// <summary>
+ /// Constructs the EtchRuntimeException. Don't init anything.
+ /// </summary>
+ public _Etch_RuntimeException()
+ {
+ // don't init anything.
+ }
+
+ /// <summary>Constructs the EtchRuntimeException</summary>
+ /// <param name = "msg">msg description of the exception that was caught by the stub on the remote side.</param>
+ public _Etch_RuntimeException(String msg)
+ {
+ this.msg = msg;
+ }
+
+
+ public String GetMessage()
+ {
+ return msg;
+ }
+
+ /// <summary>Description of the exception that was caught by the stub on the remote side. </summary>
+ public String msg;
+
+ public override string ToString()
+ {
+ return "Remote side threw this runtime exception: " + GetMessage();
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_RuntimeException.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Support/_Etch_RuntimeException.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/ArrayValue.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/ArrayValue.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/ArrayValue.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/ArrayValue.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,185 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using System.Collections;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+
+/// <summary>An array of values, where each value is of arbitrary type
+/// chosen from the basic java types boolean, byte, short, int,
+/// long, float, double, String, an array of those, the extended
+/// types ArrayValue and StructValue, and specific types supported
+/// by ValueFactory.
+///
+/// ArrayValue is not protected against concurrent access. </summary>
+
+namespace Org.Apache.Etch.Bindings.Csharp.Transport
+{
+
+ public class ArrayValue : IEnumerable
+ {
+ /// <summary>Constructs the ArrayValue.</summary>
+ public ArrayValue( Object array, sbyte typecode, XType customStructType, int dim )
+ {
+ if ( array == null )
+ throw new NullReferenceException( "array == null" );
+
+ if ( !( ( array.GetType() ).IsArray ) )
+ throw new ArgumentException( "object is not of type array" );
+
+ this.array = array;
+ this.typecode = typecode;
+ this.CustomStructType = customStructType;
+ this.Dim = dim;
+ }
+
+ /// <summary>
+ /// Constructs the arrayvalue without any type information
+ /// </summary>
+ public ArrayValue( Object array ) : this( array, ( sbyte ) 0, null, 0 )
+ {
+ }
+
+ private Object array;
+ private sbyte typecode;
+ private XType customStructType;
+ private int dim;
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns>the TypeCode for this array value.
+ /// For example, if the array is int[][], then
+ /// the type would be TypeCode.INT4.
+ /// </returns>
+ public sbyte Type
+ {
+ get
+ {
+ return typecode;
+ }
+ set
+ {
+ typecode = value;
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns>a struct type if a custom type code.</returns>
+ public XType CustomStructType
+ {
+ get
+ {
+ return customStructType;
+ }
+ private set
+ {
+ customStructType = value;
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns>the dimsionality of the array.
+ /// For example, if the array is int[][], the
+ /// dimensionality would be 2.</returns>
+ public int Dim
+ {
+ get
+ {
+ return dim;
+ }
+ private set
+ {
+ dim = value;
+ }
+ }
+
+ public int Size()
+ {
+ return ( ( Array ) array ).Length;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="index"></param>
+ /// <returns>the element at the specified index</returns>
+ public Object Get( int index )
+ {
+ return ( ( Array ) array ).GetValue( index );
+ }
+
+ /// <summary>
+ /// Reallocates the array so that it is only as long as needed.
+ /// </summary>
+ public void Compact()
+ {
+ if ( addIndex == Size() )
+ return;
+
+ Object narray = Array.CreateInstance( array.GetType().GetElementType(), addIndex );
+ Array.Copy( (Array)array, (Array)narray, addIndex );
+ array = narray;
+ }
+
+ /// <summary>
+ /// Adds the value to the end of the array, making more space
+ /// if needed
+ /// </summary>
+ /// <param name="value"></param>
+ public void Add( Object value )
+ {
+ int n = Size();
+
+ if ( addIndex >= n )
+ {
+ if ( n == 0 )
+ n = 8;
+ else
+ n *= 2;
+
+ Object narray = Array.CreateInstance( array.GetType().GetElementType(), n );
+ Array.Copy( (Array)array, (Array)narray, ( ( Array ) array ).Length );
+ array = narray;
+ }
+ ( ( Array ) array ).SetValue( value, addIndex++ );
+ }
+
+ private int addIndex;
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns>the array</returns>
+ public Object GetArray()
+ {
+ return array;
+ }
+
+
+ #region IEnumerable Members
+
+ public IEnumerator GetEnumerator()
+ {
+ return ( ( Array ) array ).GetEnumerator();
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/ArrayValue.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/ArrayValue.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/DefaultDeliveryService.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/DefaultDeliveryService.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/DefaultDeliveryService.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/DefaultDeliveryService.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,246 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Support;
+using Org.Apache.Etch.Bindings.Csharp.Util;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Transport
+{
+ public class DefaultDeliveryService : DeliveryService
+ {
+ public DefaultDeliveryService(MailboxManager transport, string uri, Resources resources)
+ : this(transport, new URL(uri), resources)
+ {
+ }
+
+
+ public DefaultDeliveryService(MailboxManager transport, URL uri, Resources resources)
+ {
+ this.transport = transport;
+ transport.SetSession(this);
+ disableTimeout = uri.GetBooleanTerm(DISABLE_TIMEOUT, false);
+ }
+
+
+ /// <summary>
+ /// Parameter to Globally Disable Timeout.
+ /// </summary>
+
+ public const string DISABLE_TIMEOUT = "DefaultDeliveryService.disableTimeout";
+
+
+ private bool disableTimeout = false;
+
+
+ private SessionMessage _stub;
+
+ private MailboxManager transport;
+
+
+
+ /// <summary>
+ /// Removes all the stubs in the set of stubs
+ /// </summary>
+ public void RemoveStub()
+ {
+ _stub = null;
+ }
+
+ public Object SessionQuery(object query)
+ {
+ if (_stub != null)
+ return _stub.SessionQuery(query);
+
+ throw new NotSupportedException("unknown query: " + query);
+ }
+
+ public void SessionControl(Object control, Object value)
+ {
+ if (_stub != null)
+ _stub.SessionControl(control, value);
+
+ throw new NotSupportedException("unknown control: " + control);
+ }
+
+ public void SessionNotify(Object eventObj)
+ {
+ if (eventObj is string)
+ {
+ string stringObj = (string) eventObj;
+ if (stringObj == SessionConsts.UP)
+ {
+ status.Set(SessionConsts.UP);
+ }
+ else if (stringObj == SessionConsts.DOWN)
+ {
+ status.Set(SessionConsts.DOWN);
+ }
+
+ }
+
+ _stub.SessionNotify(eventObj);
+
+
+
+
+ }
+
+ private Monitor<string> status = new Monitor<string>("session status");
+
+
+ public Object TransportQuery(Object query)
+ {
+ if(query.GetType() == typeof(TransportConsts.WaitUp))
+ {
+ waitUp(((TransportConsts.WaitUp) query)._maxDelay);
+ return null;
+ }
+ else if (query.GetType() == typeof(TransportConsts.WaitDown))
+ {
+ waitDown(((TransportConsts.WaitDown)query)._maxDelay);
+ return null;
+ }
+ else
+ {
+ return transport.TransportQuery(query);
+ }
+
+ }
+
+ private void waitUp(int maxDelay)
+ {
+ status.WaitUntilEq(SessionConsts.UP,maxDelay);
+ }
+
+ private void waitDown(int maxDelay)
+ {
+ status.WaitUntilEq(SessionConsts.DOWN, maxDelay);
+ }
+
+ public void TransportControl(Object control, Object value)
+ {
+ if (control is string)
+ {
+ string stringObj = (string) control;
+
+ if (stringObj == TransportConsts.START_AND_WAIT_UP)
+ {
+ transport.TransportControl(TransportConsts.START, null);
+ waitUp((int) value);
+ }
+ else if (stringObj == TransportConsts.STOP_AND_WAIT_DOWN)
+ {
+ transport.TransportControl(TransportConsts.STOP,null);
+ waitDown((int)value);
+ }
+ else
+ {
+ transport.TransportControl(control, value);
+ }
+ }
+ else
+ {
+ transport.TransportControl(control, value);
+ }
+
+ }
+
+ public void TransportNotify(Object eventObj)
+ {
+ transport.TransportNotify(eventObj);
+ }
+
+
+
+ public Mailbox BeginCall(Message msg)
+ {
+ return transport.TransportCall(null, msg);
+ }
+
+ public Object EndCall(Mailbox mb, XType responseType)
+ {
+ try
+ {
+ int timeout = disableTimeout ? 0 : responseType.Timeout;
+ Element mbe = mb.Read(timeout);
+ if (mbe == null)
+ throw new TimeoutException("timeout waiting for " + responseType);
+ Message rmsg = mbe.msg;
+ rmsg.CheckType(responseType);
+ Object r = rmsg.Get(responseType.ResponseField);
+ if (r is Exception)
+ {
+ Exception e = (Exception)r;
+ throw e;
+ }
+ return r;
+ }
+ finally
+ {
+ mb.CloseRead();
+ }
+ }
+
+ public override string ToString()
+ {
+ return transport.ToString();
+ }
+
+
+
+
+ #region SessionMessage Members
+
+ public bool SessionMessage(Who sender, Message msg)
+ {
+ return _stub.SessionMessage(sender, msg);
+ }
+
+ /// <summary>
+ /// Adds a stub to a list of stub
+ /// </summary>
+ /// <param name="stb"></param>
+ public void SetSession(SessionMessage stb)
+ {
+ if (_stub != null)
+ throw new Exception("Unsupported -- only one stub for now");
+ _stub = stb;
+ }
+
+ #endregion
+
+ #region TransportMessage Members
+
+ public void TransportMessage(Who recipient, Message msg)
+ {
+ transport.TransportMessage(recipient,msg);
+ }
+
+ #endregion
+
+ #region Transport<SessionMessage> Members
+
+
+ public SessionMessage GetSession()
+ {
+ return _stub;
+ }
+
+ #endregion
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/DefaultDeliveryService.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/DefaultDeliveryService.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/AbstractMessageFilter.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/AbstractMessageFilter.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/AbstractMessageFilter.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/AbstractMessageFilter.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,128 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Util;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Transport.Filter
+{
+ abstract public class AbstractMessageFilter : TransportMessage, SessionMessage
+ {
+ protected AbstractMessageFilter(TransportMessage transport, URL uri, Resources resources)
+ {
+ this.transport = transport;
+ transport.SetSession(this);
+ }
+
+ /// <summary>
+ /// Our transport.
+ /// </summary>
+ protected readonly TransportMessage transport;
+
+ /// <summary>
+ /// Returns a string such as "Filter/"+transport.
+ /// </summary>
+ /// <returns>a string such as "Filter/"+transport.</returns>
+ abstract public override string ToString();
+
+ public virtual void TransportMessage(Who recipient, Message msg)
+ {
+ transport.TransportMessage(recipient, msg);
+ }
+
+ public SessionMessage GetSession()
+ {
+ return session;
+ }
+
+ public void SetSession(SessionMessage session)
+ {
+ this.session = session;
+ }
+
+ /// <summary>
+ /// Our session.
+ /// </summary>
+ protected SessionMessage session;
+
+ public virtual object TransportQuery(object query)
+ {
+ return transport.TransportQuery(query);
+ }
+
+ public virtual void TransportControl(object control, object value)
+ {
+ transport.TransportControl(control, value);
+ }
+
+ public void TransportNotify(object evnt)
+ {
+ transport.TransportNotify(evnt);
+ }
+
+ public virtual bool SessionMessage(Who sender, Message msg)
+ {
+ return session.SessionMessage(sender, msg);
+ }
+
+ public object SessionQuery(object query)
+ {
+ return session.SessionQuery(query);
+ }
+
+ public void SessionControl(object control, object value)
+ {
+ session.SessionControl(control, value);
+ }
+
+ public void SessionNotify(object evnt)
+ {
+ if (evnt == (object) SessionConsts.UP)
+ if (!SessionUp())
+ return;
+
+ if (evnt == (object) SessionConsts.DOWN)
+ if (!SessionDown())
+ return;
+
+ session.SessionNotify(evnt);
+ }
+
+ /**
+ * Tells the filter that the session is up.
+ * @return true if the event should be passed on to our session, false
+ * if it should be swallowed.
+ * @throws Exception
+ */
+ protected virtual bool SessionUp()
+ {
+ // nothing to do.
+ return true;
+ }
+
+ /**
+ * Tells the filter that the session is down.
+ * @return true if the event should be passed on to our session, false
+ * if it should be swallowed.
+ * @throws Exception
+ */
+ protected virtual bool SessionDown()
+ {
+ // nothing to do.
+ return true;
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/AbstractMessageFilter.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/AbstractMessageFilter.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/KeepAlive.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/KeepAlive.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/KeepAlive.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/KeepAlive.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,305 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Support;
+using Org.Apache.Etch.Bindings.Csharp.Util;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Transport.Filter
+{
+ public class KeepAlive : AbstractMessageFilter, AlarmListener
+ {
+
+
+ public const String DELAY = "KeepAlive.delay";
+
+
+ public const String COUNT = "KeepAlive.count";
+
+ public KeepAlive(TransportMessage transport, URL uri, Resources resources)
+ : base(transport, uri, resources)
+ {
+
+ delay = uri.GetIntegerTerm(DELAY, 15);
+ if (delay <= 0)
+ throw new ArgumentException("delay <= 0");
+
+ count = uri.GetIntegerTerm(COUNT, 4);
+ if (count <= 0)
+ throw new ArgumentException("count <= 0");
+
+ server = (Boolean) transport.TransportQuery(TransportConsts.IS_SERVER);
+
+ // Log.report( "KeepAliveInstalled",
+ // "delay", delay, "count", count, "server", server );
+
+ vf = (ValueFactory)resources.Get(TransportConsts.VALUE_FACTORY);
+
+ mf_delay = new Field("delay");
+ mf_count = new Field("count");
+
+ mt_request = new XType("_Etch_KeepAliveReq");
+ mt_request.PutValidator(mf_delay, Validator_int.Get(0));
+ mt_request.PutValidator(mf_count, Validator_int.Get(0));
+ vf.AddType(mt_request);
+
+ mt_response = new XType("_Etch_KeepAliveResp");
+ vf.AddType(mt_response);
+
+ mt_request.SetResult(mt_response);
+ }
+
+ private int delay;
+
+ private int count;
+
+ private readonly bool server;
+
+ private readonly ValueFactory vf;
+
+ private readonly Field mf_delay;
+
+ private readonly Field mf_count;
+
+ private readonly XType mt_request;
+
+ private readonly XType mt_response;
+
+ public int GetDelay()
+ {
+ return delay;
+ }
+
+ public int GetCount()
+ {
+ return count;
+ }
+
+
+ public bool GetServer()
+ {
+ return server;
+ }
+
+
+ public override bool SessionMessage(Who sender, Message msg)
+ {
+ if (msg.IsType(mt_request))
+ {
+ handleRequest(msg);
+ return true;
+ }
+
+ if (msg.IsType(mt_response))
+ {
+ handleResponse(msg);
+ return true;
+ }
+
+ return base.SessionMessage(sender, msg);
+ }
+
+
+
+ protected override bool SessionUp()
+ {
+ // Log.report( "KeepAliveSessionUp", "server", server );
+ up = true;
+ AlarmManager.staticAdd(this, null, delay * 1000);
+ tickle();
+ return true;
+ }
+
+ protected override bool SessionDown()
+ {
+ // Log.report( "KeepAliveSessionDown", "server", server );
+ up = false;
+ AlarmManager.staticRemove(this);
+ return true;
+ }
+
+ private bool up;
+
+ private void handleRequest(Message msg)
+ {
+ if (!server)
+ {
+ // we're a client that got a request, likely we're talking to a
+ // server that is confused.
+ return;
+ }
+
+ //Log.report( "GotKeepAliveReq", "msg", msg );
+ // Console.WriteLine("GotKeepAliveReq:Msg " + msg);
+
+ int? d = (int?)msg.Get(mf_delay);
+ if (d != null && d.Value > 0)
+ {
+ //Console.WriteLine("KeepAliveResetDelay delay " + d );
+ delay = d.Value;
+ }
+
+ int? c = (int?)msg.Get(mf_count);
+ if (c != null && c.Value > 0)
+ {
+ // Console.WriteLine( "KeepAliveResetCount count " + c );
+ count = c.Value;
+ }
+
+ tickle();
+
+ sendKeepAliveResp(msg);
+ }
+
+ private void handleResponse(Message msg)
+ {
+ if (server)
+ {
+ // we're a server that got a response, which means either we sent
+ // a request (but we shouldn't do that if we're a server) or the
+ // client is confused.
+ return;
+ }
+
+ //Log.report( "GotKeepAliveResp", "msg", msg );
+ //Console.WriteLine(" GotKeepAliveResp: msg " + msg);
+
+ tickle();
+ }
+
+ private void tickle()
+ {
+ // lastTickle = Timer.GetNanos();
+ // lastTickle = HPTimer.Now();
+ lastTickle = HPTimer.Now();
+ }
+
+ private long lastTickle;
+
+ private void checkTickle()
+ {
+
+
+ long ms = HPTimer.MillisSince(lastTickle);
+ // Log.report( "KeepAliveIdle", "ms", ms, "server", server );
+ if (ms >= count * delay * 1000)
+ {
+ try
+ {
+ // Log.report( "KeepAliveReset", "server", server );
+ session.SessionNotify("KeepAlive resetting dead connection");
+ transport.TransportControl(TransportConsts.RESET, 0);
+ }
+ catch (Exception e)
+ {
+ reportError(e);
+ }
+ }
+ }
+
+ private void sendKeepAliveReq()
+ {
+ Message msg = new Message(mt_request, vf);
+ msg.Add(mf_delay, delay);
+ msg.Add(mf_count, count);
+ try
+ {
+ // Log.report( "SendKeepAliveReq", "msg", msg );
+ transport.TransportMessage(null, msg);
+ }
+ catch (Exception e)
+ {
+ reportError(e);
+ }
+ }
+
+ private void sendKeepAliveResp(Message msg)
+ {
+ Message rmsg = msg.Reply();
+ try
+ {
+ //Log.report( "SendKeepAliveResp", "rmsg", rmsg );
+ transport.TransportMessage(null, rmsg);
+ }
+ catch (Exception e)
+ {
+ reportError(e);
+ }
+ }
+
+ public int Wakeup(AlarmManager manager, Object state, long due)
+ {
+ // Log.report( "KeepAliveWakeup", "server", server );
+
+ if (!up)
+ return 0;
+
+ if (!server)
+ {
+ TodoManager.AddTodo(new MyTodo(sendKeepAliveReq, reportError));
+ }
+
+ checkTickle();
+
+ return delay * 1000;
+ }
+
+ private void reportError(Exception e)
+ {
+ try
+ {
+ session.SessionNotify(e);
+ }
+ catch (Exception e1)
+ {
+ Console.WriteLine(e1);
+ }
+ }
+
+ public override string ToString()
+ {
+ return "KeepAlive/" + transport;
+ }
+ }
+
+ public class MyTodo : Todo
+ {
+ public delegate void doit();
+
+ public delegate void report(Exception e);
+
+ public MyTodo(doit d, report r)
+ {
+ this.d = d;
+ this.r = r;
+ }
+
+ private readonly doit d;
+
+ private readonly report r;
+
+ public void Doit(TodoManager mgr)
+ {
+ d();
+ }
+
+ public void Exception(TodoManager mgr, Exception e)
+ {
+ r(e);
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/KeepAlive.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Transport/Filter/KeepAlive.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"