// ********************************************************************** // // Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** using System; using System.Collections; using System.Diagnostics; namespace Ice { /// /// Indicates the status of operation dispatch. /// public enum DispatchStatus { /// /// Indicates that an operation was dispatched synchronously and successfully. /// DispatchOK, /// /// Indicates that an operation was dispatched synchronously and raised a user exception. /// DispatchUserException, /// /// Indicates that an operation was dispatched asynchronously. /// DispatchAsync } public interface DispatchInterceptorAsyncCallback { bool response(bool ok); bool exception(System.Exception ex); } /// /// Interface for incoming requests. /// public interface Request { /// /// Returns the {@link Current} object for this the request. /// /// The Current object for this request. Current getCurrent(); } /// /// the base interface for servants. /// public interface Object : System.ICloneable { /// /// Tests whether this object supports a specific Slice interface. /// /// /// The type ID of the Slice interface to test against. /// True if this object has the interface /// specified by s or derives from the interface specified by s. bool ice_isA(string s); /// /// Tests whether this object supports a specific Slice interface. /// /// /// The type ID of the Slice interface to test against. /// The Current object for the invocation. /// True if this object has the interface /// specified by s or derives from the interface specified by s. bool ice_isA(string s, Current current); /// /// Tests whether this object can be reached. /// void ice_ping(); /// /// Tests whether this object can be reached. /// /// The Current object for the invocation. void ice_ping(Current current); /// /// Returns the Slice type IDs of the interfaces supported by this object. /// /// The Slice type IDs of the interfaces supported by this object, in base-to-derived /// order. The first element of the returned array is always ::Ice::Object. string[] ice_ids(); /// /// Returns the Slice type IDs of the interfaces supported by this object. /// /// The Current object for the invocation. /// The Slice type IDs of the interfaces supported by this object, in base-to-derived /// order. The first element of the returned array is always ::Ice::Object. string[] ice_ids(Current current); /// /// Returns the Slice type ID of the most-derived interface supported by this object. /// /// The Slice type ID of the most-derived interface. string ice_id(); /// /// Returns the Slice type ID of the most-derived interface supported by this object. /// /// The Current object for the invocation. /// The Slice type ID of the most-derived interface. string ice_id(Current current); /// /// The Ice run time invokes this method prior to marshaling an object's data members. This allows a subclass /// to override this method in order to validate its data members. /// void ice_preMarshal(); /// /// This Ice run time invokes this method vafter unmarshaling an object's data members. This allows a /// subclass to override this method in order to perform additional initialization. /// void ice_postUnmarshal(); /// /// Dispatches an invocation to a servant. This method is used by dispatch interceptors to forward an invocation /// to a servant (or to another interceptor). /// /// The details of the invocation. /// The callback object for asynchchronous dispatch. For synchronous dispatch, /// the callback object must be null. /// The dispatch status for the operation. DispatchStatus ice_dispatch(Request request, DispatchInterceptorAsyncCallback cb); /// /// Dispatches an invocation to a servant. This method is used by dispatch interceptors to forward an invocation /// to a servant (or to another interceptor). /// /// The details of the invocation. /// The dispatch status for the operation. DispatchStatus ice_dispatch(Request request); DispatchStatus dispatch__(IceInternal.Incoming inc, Current current); void write__(OutputStream os__); void read__(InputStream is__); } /// /// Base class for all Slice classes. /// public abstract class ObjectImpl : Object { /// /// Instantiates an Ice object. /// public ObjectImpl() { } /// /// Returns a copy of the object. The cloned object contains field-for-field copies /// of the state. /// /// The cloned object. public object Clone() { return MemberwiseClone(); } public static readonly string[] ids__ = { "::Ice::Object" }; /// /// Tests whether this object supports a specific Slice interface. /// /// The type ID of the Slice interface to test against. /// The return value is true if s is ::Ice::Object. public virtual bool ice_isA(string s) { return s.Equals(ids__[0]); } /// /// Tests whether this object supports a specific Slice interface. /// /// The type ID of the Slice interface to test against. /// The Current object for the invocation. /// The return value is true if s is ::Ice::Object. public virtual bool ice_isA(string s, Current current) { return s.Equals(ids__[0]); } public static DispatchStatus ice_isA___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current) { InputStream is__ = inS__.startReadParams(); string __id = is__.readString(); inS__.endReadParams(); bool __ret = __obj.ice_isA(__id, __current); OutputStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat); os__.writeBool(__ret); inS__.endWriteParams__(true); return DispatchStatus.DispatchOK; } /// /// Tests whether this object can be reached. /// public virtual void ice_ping() { // Nothing to do. } /// /// Tests whether this object can be reached. /// The Current object for the invocation. /// public virtual void ice_ping(Current current) { // Nothing to do. } public static DispatchStatus ice_ping___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current) { inS__.readEmptyParams(); __obj.ice_ping(__current); inS__.writeEmptyParams__(); return DispatchStatus.DispatchOK; } /// /// Returns the Slice type IDs of the interfaces supported by this object. /// /// An array whose only element is ::Ice::Object. public virtual string[] ice_ids() { return ids__; } /// /// Returns the Slice type IDs of the interfaces supported by this object. /// /// The Current object for the invocation. /// An array whose only element is ::Ice::Object. public virtual string[] ice_ids(Current current) { return ids__; } public static DispatchStatus ice_ids___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current) { inS__.readEmptyParams(); string[] ret__ = __obj.ice_ids(__current); OutputStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat); os__.writeStringSeq(ret__); inS__.endWriteParams__(true); return DispatchStatus.DispatchOK; } /// /// Returns the Slice type ID of the most-derived interface supported by this object. /// /// The return value is always ::Ice::Object. public virtual string ice_id() { return ids__[0]; } /// /// Returns the Slice type ID of the most-derived interface supported by this object. /// /// The Current object for the invocation. /// The return value is always ::Ice::Object. public virtual string ice_id(Current current) { return ids__[0]; } public static DispatchStatus ice_id___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current) { inS__.readEmptyParams(); string __ret = __obj.ice_id(__current); OutputStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat); os__.writeString(__ret); inS__.endWriteParams__(true); return DispatchStatus.DispatchOK; } /// /// Returns the Slice type ID of the interface supported by this object. /// /// The return value is always ::Ice::Object. public static string ice_staticId() { return ids__[0]; } /// /// The Ice run time invokes this method prior to marshaling an object's data members. This allows a subclass /// to override this method in order to validate its data members. /// public virtual void ice_preMarshal() { } /// /// This Ice run time invokes this method vafter unmarshaling an object's data members. This allows a /// subclass to override this method in order to perform additional initialization. /// public virtual void ice_postUnmarshal() { } private static readonly string[] all__ = new string[] { "ice_id", "ice_ids", "ice_isA", "ice_ping" }; /// /// Dispatches an invocation to a servant. This method is used by dispatch interceptors to forward an invocation /// to a servant (or to another interceptor). /// /// The details of the invocation. /// The callback object for asynchchronous dispatch. For synchronous dispatch, the /// callback object must be null. /// The dispatch status for the operation. public virtual DispatchStatus ice_dispatch(Request request, DispatchInterceptorAsyncCallback cb) { IceInternal.Incoming inc = (IceInternal.Incoming)request; if(cb != null) { inc.push(cb); } try { inc.startOver(); // may raise ResponseSentException return dispatch__(inc, inc.getCurrent()); } finally { if(cb != null) { inc.pop(); } } } /// /// Dispatches an invocation to a servant. This method is used by dispatch interceptors to forward an invocation /// to a servant (or to another interceptor). /// /// The details of the invocation. /// The dispatch status for the operation. public virtual DispatchStatus ice_dispatch(Request request) { return ice_dispatch(request, null); } public virtual DispatchStatus dispatch__(IceInternal.Incoming inc, Current current) { int pos = System.Array.BinarySearch(all__, current.operation); if(pos < 0) { throw new Ice.OperationNotExistException(current.id, current.facet, current.operation); } switch(pos) { case 0: { return ice_id___(this, inc, current); } case 1: { return ice_ids___(this, inc, current); } case 2: { return ice_isA___(this, inc, current); } case 3: { return ice_ping___(this, inc, current); } } Debug.Assert(false); throw new Ice.OperationNotExistException(current.id, current.facet, current.operation); } public virtual void write__(OutputStream os__) { os__.startObject(null); writeImpl__(os__); os__.endObject(); } public virtual void read__(InputStream is__) { is__.startObject(); readImpl__(is__); is__.endObject(false); } protected virtual void writeImpl__(OutputStream os__) { } protected virtual void readImpl__(InputStream is__) { } private static string operationModeToString(OperationMode mode) { if(mode == Ice.OperationMode.Normal) { return "::Ice::Normal"; } if(mode == Ice.OperationMode.Nonmutating) { return "::Ice::Nonmutating"; } if(mode == Ice.OperationMode.Idempotent) { return "::Ice::Idempotent"; } return "???"; } public static void checkMode__(OperationMode expected, OperationMode received) { if(expected != received) { if(expected == OperationMode.Idempotent && received == OperationMode.Nonmutating) { // // Fine: typically an old client still using the // deprecated nonmutating keyword // } else { Ice.MarshalException ex = new Ice.MarshalException(); ex.reason = "unexpected operation mode. expected = " + operationModeToString(expected) + " received = " + operationModeToString(received); throw ex; } } } public static Ice.Current defaultCurrent = new Ice.Current(); } /// /// Base class for dynamic dispatch servants. A server application /// derives a concrete servant class from Blobject that /// implements the Blobject.ice_invoke method. /// public abstract class Blobject : Ice.ObjectImpl { /// /// Dispatch an incoming request. /// /// The encoded in-parameters for the operation. /// The encoded out-paramaters and return value /// for the operation. The return value follows any out-parameters. /// The Current object to pass to the operation. /// If the operation completed successfully, the return value /// is true. If the operation raises a user exception, /// the return value is false; in this case, outParams /// must contain the encoded user exception. If the operation raises an /// Ice run-time exception, it must throw it directly. public abstract bool ice_invoke(byte[] inParams, out byte[] outParams, Current current); public override DispatchStatus dispatch__(IceInternal.Incoming inS__, Current current) { byte[] inEncaps = inS__.readParamEncaps(); byte[] outEncaps; bool ok = ice_invoke(inEncaps, out outEncaps, current); inS__.writeParamEncaps__(outEncaps, ok); if(ok) { return DispatchStatus.DispatchOK; } else { return DispatchStatus.DispatchUserException; } } } public abstract class BlobjectAsync : Ice.ObjectImpl { public abstract void ice_invoke_async(AMD_Object_ice_invoke cb, byte[] inEncaps, Current current); public override DispatchStatus dispatch__(IceInternal.Incoming inS__, Current current) { byte[] inEncaps = inS__.readParamEncaps(); AMD_Object_ice_invoke cb = new _AMD_Object_ice_invoke(inS__); try { ice_invoke_async(cb, inEncaps, current); } catch(System.Exception ex) { cb.ice_exception(ex); } return DispatchStatus.DispatchAsync; } } }