// $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.
//
using System;
using Org.Apache.Etch.Bindings.Csharp.Msg;
using Org.Apache.Etch.Bindings.Csharp.Util;
namespace Org.Apache.Etch.Bindings.Csharp.Support
{
public class RemoteBase
{
/// Constructs the RemoteBase.
/// svc
/// vf
public RemoteBase(DeliveryService svc, ValueFactory vf)
{
this._svc = svc;
this._vf = vf;
}
private DeliveryService _svc;
/// The value factory used to create messages and encode/decode types.
public ValueFactory _vf;
public override string ToString()
{
return String.Format("{0}/{1}", GetType(), _svc);
}
/// Constructs a new message to send using _send(Message) or _beginCall(Message)
/// type
/// a new message
public Message _NewMessage(XType type)
{
return new Message(type, _vf);
}
///Sends the message to the recipient, but does not wait for any response.
/// the message to send
/// Exception if there is a problem sending
public void _Send( Message msg )
{
_svc.TransportMessage(null,msg);
}
///Sends the message which begins a call sequence.
/// the message to send
///A mailbox which can be used to read the response, using _EndCall
public Mailbox _BeginCall( Message msg )
{
return _svc.BeginCall( msg );
}
///Finishes a call sequence by waiting for the response message.
///a mailbox which will be used to read the response, returned by
/// _BeginCall(Message)
/// the type of the expected response
///the value of the response field if it isn't an exception.
/// Exception if there is a problem sending or a timeout waiting or
/// if the result value was an exception.
public Object _EndCall( Mailbox mb, XType responseType )
{
return _svc.EndCall( mb, responseType );
}
///
/// Gets a configuration or operational value from the source. The
/// request is passed down the chain of sources until some source
/// recognises the query, whereupon it returns the requested value.
///
///
/// an object representing a query, which could be as
/// simple as a string, integer, or enum, or more complex such as
/// a class with instance variables for query terms.
/// the requested value, or null if not defined.
///
/// Exception:
/// throws Exception if the query is not recognised
/// by any source (which is to say, if the last source in the source
/// chain does not recognise it, it should throw this exception).
///
public object _TransportQuery( object query )
{
return _svc.TransportQuery( query );
}
///
/// Sets a configuration or operational value in the source. The
/// request is passed down the chain of sources until some source
/// recognises the control, whereupon it stores the specified value
/// and returns.
///
///
/// an object representing a control, which could be as
/// simple as a string, integer, or enum, or more complex such as
/// a class with instance variables for control terms.
///
/// the value to set.
///
/// Exception:
/// throws ArgumentException if the value is not the right
/// type or if the value is inappropriate.
///
/// throws Exception if the control is not recognised
/// by any source (which is to say, if the last source in the source
/// chain does not recognise it, it should throw this exception).
///
public void _TransportControl( object control, object value )
{
_svc.TransportControl( control, value );
}
///
/// Notifies the chain of sources of the specified event. Unlike query
/// and control operations above, events are always passed down to the
/// bottom to allow all sources to notice them.
///
///
/// a class which represents the event, possibly with
/// parameters. The simplest event could be a string, integer,
/// or enum, but any class instance will do (as long as some source
/// in the chain expects it).
///
public void _TransportNotify( object eventObj )
{
_svc.TransportNotify( eventObj );
}
///
/// Start the transport
///
public void _Start()
{
_svc.TransportControl( TransportConsts.START, null );
}
///
/// Waits for the transport to come up.
///
///
public void _WaitUp( int maxDelay )
{
_svc.TransportQuery( new TransportConsts.WaitUp( maxDelay ) );
}
///
/// Starts the transport and waits for it to come up.
///
///
public void _StartAndWaitUp( int maxDelay )
{
_Start();
_WaitUp(maxDelay);
}
///
/// Stops the transport.
///
public void _Stop()
{
_svc.TransportControl( TransportConsts.STOP, null );
}
///
/// Waits for the transport to go down.
///
///
public void _WaitDown( int maxDelay )
{
_svc.TransportQuery( new TransportConsts.WaitDown( maxDelay ) );
}
///
/// Stops the transport and waits for it to go down.
///
/// maxdelay in milliseconds
public void _StopAndWaitDown( int maxDelay )
{
_Stop();
_WaitDown(maxDelay);
}
}
}