public static int DriverMain(IntelResources resources)
        {
            ExtensionContract /*.Exp*/       ep = (resources.ec).Acquire();
            ServiceProviderContract /*.Exp*/ sp = (resources.nicsp).Acquire();

            Intel device = new Intel(resources);

            device.Initialize();

            ep.SendSuccess();

            try {
                for (bool run = true; run;)
                {
                    switch receive {
                    case sp.Connect(ServiceContract /*.Exp*/ exp):
                        NicDeviceContract /*.Exp*/ nd = exp as NicDeviceContract /*.Exp*/;

                        if (nd != null)
                        {
                            Tracing.Log(Tracing.Debug, "Connect success.");
                            sp.SendAckConnect();
                            IntelDeviceChannel.CreateThread(device, nd);
                        }
                        else
                        {
                            Tracing.Log(Tracing.Error, "Connect failed.");
                            sp.SendNackConnect(exp);
                        }
                        break;

                    case sp.ChannelClosed():
                        device.Shutdown();
                        run = false;
                        break;

                    case ep.Shutdown():
                        device.Shutdown();
                        ep.SendAckShutdown();
                        break;

                    case ep.ChannelClosed():
                        device.Shutdown();
                        run = false;
                        break;

                    case unsatisfiable:
                        DebugStub.Break();
                        break;
                    }
                }
            }
            finally {
                //delete ep;
                //delete sp;
            }
            return(0);
        }
        override protected void Run(StopThreadContract /*.Exp*/ terminator)
        {
            ServiceProviderContract /*.Exp*/ nsExp = spRef.Acquire();

            bool run = true;

            while (run)
            {
                switch receive {
                case nsExp.Connect(ServiceContract /*.Exp*/: Start newEp) :
                {
                        // We expect people to give us DnsContract/*.Exp*/ instances
                        DnsContract /*.Exp*/ newDnsEp = newEp as DnsContract /*.Exp*/;

                        if (newDnsEp == null)
                        {
                            // Invalid contract type. Fail.
                            nsExp.SendNackConnect(newEp);
                        }
                        else
                        {
                            // Signal ready and start servicing this contract
                            nsExp.SendAckConnect();
                            newDnsEp.SendReady();

                            // Spin up a new servicing thread
                            DNSExpConnection newConn = new DNSExpConnection(newDnsEp);
                            newConn.Start();
                        }
                }
                    break;

                case nsExp.ChannelClosed():
                    // Exit this thread
                    run = false;
                    break;

                case terminator.Terminate():
                    terminator.SendAckTerminate();
                    run = false;
                    break;

                case terminator.ChannelClosed():
                    run = false;
                    break;
                }
            }

            //delete nsExp;
        }
 public DNSExpManager(ServiceProviderContract /*.Exp*/ spRef)
 {
     this.spRef = spRef;
 }
Beispiel #4
0
        protected override void Run(StopThreadContract /*.Exp*/ terminator)
        {
            ServiceProviderContract /*.Exp*/ nsExp = spRef.Acquire();

            // Here is the set of client channels we service
            ESet < UdpContract /*.Exp*/ epSet = new ESet < UdpContract/*.Exp*/ ();

            while (true)
            {
                switch receive {
                //
                // Don't forget that we're selecting UdpContract endpoints
                // from the epSet endpoint-set. In each case that we
                // receive a message from one of those endpoints, we
                // need to remember to put the endpoint back into epSet
                // if we want to keep listening to it.
                //
                case ep.CreateUdpSession(UdpConnectionContract /*.Exp*/: Start newEP) in epSet:
                    {
                        // Move the endpoint to the ReadyState
                        newEP.SendReady();
                        // Create a dedicated thread to service this connection
                        UdpConnectionExpThread udpThread = new UdpConnectionExpThread(newEP);
                        udpThread.Start();
                        ep.SendAck();
                        epSet.Add(ep);
                    }
                    break;

                case nsExp.Connect(ServiceContract /*.Exp*/: Start newEp) :
                {
                        // We expect people top give us
                        // UdpContract/*.Exp*/ instances
                        // UdpContract/*.Exp*/:Start newUdpEp = newEp
                        // as UdpContract/*.Exp*/;
                        UdpContract /*.Exp*/ newUdpEp = newEp as UdpContract /*.Exp*/;

                        if (newUdpEp == null)
                        {
                            // Invalid contract type. Fail.
                            nsExp.SendNackConnect(newEp);
                        }
                        else
                        {
                            // Signal ready and start
                            // servicing this contract
                            nsExp.SendAckConnect();
                            newUdpEp.SendReady();
                            epSet.Add(newUdpEp);
                        }
                }
                    break;

                case ep.ChannelClosed() in epSet:
                    //delete ep;
                    break;

                case nsExp.ChannelClosed():
                    goto quit;

                case terminator.Terminate():
                    terminator.SendAckTerminate();
                    goto quit;

                case terminator.ChannelClosed():
                    goto quit;
                }
            }

quit:
            //delete nsExp;
            epSet.Dispose();
        }