Exemple #1
0
        public static Protocol createStack(Protocol middle, out Protocol bot)
        {
            ProtocolSinkStack stack = new ProtocolSinkStack(null,null);
            middle.ProtocolSinkStack = stack;

            TOP top = new TOP("TOP");
            BOTTOM bottom = new BOTTOM();
            bot = bottom;
            top.DownProtocol = middle;
            middle.DownProtocol = bottom;
            bottom.DownProtocol = null;

            top.UpProtocol = null;
            middle.UpProtocol = top;
            bottom.UpProtocol = middle;

            bottom.startDownHandler();
            bottom.startUpHandler();
            middle.startDownHandler();
            middle.startUpHandler();
            top.startDownHandler();
            top.startUpHandler();

            top.start();
            middle.start();
            bottom.start();

            bottom.up(new Event(Event.SET_LOCAL_ADDRESS,localAddr));

            return top;
        }
Exemple #2
0
            /// <remarks>
            /// Uses <c>Activator.CreateInstance()</c> initialise each <c>Protocol</c>
            /// </remarks>
            /// <summary>
            /// Creates the Protocol, sets the properties and calls <c>init()</c>
            /// </summary>
            /// <param name="st">The <c>ProtocolSinkStack</c> the <c>Protocol</c>
            /// should be linked to
            /// </param>
            /// <returns></returns>
            public Object createLayer(ProtocolSinkStack st)
            {
                ObjectHandle obj = null;

                int prefixSize = 3;

                String[] prefix = new String[prefixSize];
                prefix[0] = "GCT.Protocols.";
                prefix[1] = "GCT.";
                prefix[2] = "GCT.Protocols.";

                if (assembly_name != null)
                {
                    prefix[0] = "";
                }

                for (int i = 0; i < prefixSize; i++)
                {
                    try
                    {
                        obj = Activator.CreateInstance(assembly_name, prefix[i] + protocol_name);
                        if (Trace.trace)
                        {
                            Trace.info("Configurator.createLayer()", "Created Layer " + prefix[i] + protocol_name);
                        }
                        if (obj != null)
                        {
                            break;
                        }
                    }
                    catch (Exception e1)
                    {
                        Console.WriteLine(e1 + "\n" + e1.StackTrace);
                        Console.WriteLine();
                    }
                }

                Protocol gSink = null;

                if (obj != null)
                {
                    gSink = (Protocol)obj.Unwrap();
                    gSink.ProtocolSinkStack = st;
                    if (!gSink.setPropertiesInternal(properties))
                    {
                        return(null);
                    }
                    gSink.init();
                }
                else
                {
                    if (Trace.trace)
                    {
                        Trace.error("Configurator.createLayer()", "Couldn't create layer: " + protocol_name);
                    }
                }

                return(gSink);
            }
        /// <remarks>
        /// The following steps are followed:
        /// <list type="">
        /// <item>A <c>ProtocolConfiguration</c> object is created for each protocol</item>
        /// <item>The <c>Protocol</c>s are created from the <c>ProtocolConfiguration</c> objects</item>
        /// <item>The Protocols are all connected together</item>
        /// </list>
        /// </remarks>
        /// <summary>
        /// Sets up the <c>ProtocolSinkStack</c> with the specified configuration string.
        /// </summary>
        /// <param name="configuration">The String configuration of the stack</param>
        /// <param name="st">Reference to the <c>ProtocolSinkStack</c> which each <c>Protocol</c> should reference</param>
        /// <returns>The top-most <c>Protocol</c> in the stack</returns>
        public Protocol setupStack(string configuration, ProtocolSinkStack st)
        {
            ProtocolConfiguration[]		layer_configs;
            Protocol[]					layers;
            Protocol					top_prot;

            layer_configs = parseConfigurations(configuration);
            layers = createProtocols(layer_configs, st);
            if(layers == null)
                return null;
            top_prot = connectProtocols(layers);
            return top_prot;
        }
Exemple #4
0
        /// <remarks>
        /// The following steps are followed:
        /// <list type="">
        /// <item>A <c>ProtocolConfiguration</c> object is created for each protocol</item>
        /// <item>The <c>Protocol</c>s are created from the <c>ProtocolConfiguration</c> objects</item>
        /// <item>The Protocols are all connected together</item>
        /// </list>
        /// </remarks>
        /// <summary>
        /// Sets up the <c>ProtocolSinkStack</c> with the specified configuration string.
        /// </summary>
        /// <param name="configuration">The String configuration of the stack</param>
        /// <param name="st">Reference to the <c>ProtocolSinkStack</c> which each <c>Protocol</c> should reference</param>
        /// <returns>The top-most <c>Protocol</c> in the stack</returns>
        public Protocol setupStack(string configuration, ProtocolSinkStack st)
        {
            ProtocolConfiguration[] layer_configs;
            Protocol[] layers;
            Protocol   top_prot;

            layer_configs = parseConfigurations(configuration);
            layers        = createProtocols(layer_configs, st);
            if (layers == null)
            {
                return(null);
            }
            top_prot = connectProtocols(layers);
            return(top_prot);
        }
Exemple #5
0
        /// <summary>
        /// Creates an array of <c>Protocols</c> from the configurations
        /// </summary>
        /// <param name="protocol_configs">Array of <c>ProtocolConfiguration</c> objects</param>
        /// <param name="stack">Instance <c>ProtocolSinkStack</c> which the Protocol layers should reference</param>
        /// <returns>Array of <c>Protocol</c> objects</returns>
        private Protocol[] createProtocols(ProtocolConfiguration[] protocol_configs, ProtocolSinkStack stack)
        {
            Protocol[] retval = new Protocol[protocol_configs.Length];
            Protocol   layer;

            for (int i = 0; i < protocol_configs.Length; i++)
            {
                layer = (Protocol)protocol_configs[i].createLayer(stack);                 //stack
                if (layer == null)
                {
                    return(null);
                }
                retval[i] = layer;
            }

            sanityCheck(retval);
            return(retval);
        }
            /// <remarks>
            /// Uses <c>Activator.CreateInstance()</c> initialise each <c>Protocol</c>
            /// </remarks>
            /// <summary>
            /// Creates the Protocol, sets the properties and calls <c>init()</c> 
            /// </summary>
            /// <param name="st">The <c>ProtocolSinkStack</c> the <c>Protocol</c>
            /// should be linked to
            /// </param>
            /// <returns></returns>
            public Object createLayer(ProtocolSinkStack st)
            {
                ObjectHandle obj = null;

                int prefixSize = 3;

                String[] prefix = new String[prefixSize];
                prefix[0] = "GCT.Protocols.";
                prefix[1] = "GCT.";
                prefix[2] = "GCT.Protocols.";

                if(assembly_name != null)
                    prefix[0] = "";

                for(int i = 0; i<prefixSize ; i++)
                {
                    try
                    {
                        obj = Activator.CreateInstance(assembly_name, prefix[i] + protocol_name);
                        if(Trace.trace)
                            Trace.info("Configurator.createLayer()","Created Layer " + prefix[i] + protocol_name);
                        if (obj != null)
                        {
                            break;
                        }
                    }
                    catch(Exception e1)
                    {
                        Console.WriteLine(e1+ "\n"+e1.StackTrace);
                        Console.WriteLine();
                    }
                }

                Protocol gSink = null;
                if (obj != null)
                {
                    gSink = (Protocol)obj.Unwrap();
                    gSink.ProtocolSinkStack = st;
                    if(!gSink.setPropertiesInternal(properties))
                        return null;
                    gSink.init();
                }
                else
                {
                    if(Trace.trace)
                        Trace.error("Configurator.createLayer()", "Couldn't create layer: " + protocol_name);
                }

                return gSink;
            }
        /// <summary>
        /// Creates an array of <c>Protocols</c> from the configurations
        /// </summary>
        /// <param name="protocol_configs">Array of <c>ProtocolConfiguration</c> objects</param>
        /// <param name="stack">Instance <c>ProtocolSinkStack</c> which the Protocol layers should reference</param>
        /// <returns>Array of <c>Protocol</c> objects</returns>
        private Protocol[] createProtocols(ProtocolConfiguration[] protocol_configs, ProtocolSinkStack stack)
        {
            Protocol[]             retval = new Protocol[protocol_configs.Length];
            Protocol               layer;

            for(int i=0; i < protocol_configs.Length; i++)
            {
                layer = (Protocol)protocol_configs[i].createLayer(stack); //stack
                if(layer == null)
                    return null;
                retval[i] = layer;
            }

            sanityCheck(retval);
            return retval;
        }
 // -=-=-=-=-=-=-=- Group Channel Methods -=-=-=-=-=-=-=-=-=-=-=-
 /// <summary>
 /// Sets up the ProtocolSinkStack
 /// </summary>
 private void SetupChannel()
 {
     prot_stack = new ProtocolSinkStack(this, props);
     prot_stack.ResponseChooser = responseChooser;
     prot_stack.setup();
 }