Beispiel #1
0
        internal static int AppMain(Parameters !config)
        {
            IPContract.Imp ipConn = ((!)config.ipRef).Acquire();
            if (ipConn == null)
            {
                Console.WriteLine("Could not initialize IP endpoint.");
                return(1);
            }
            ipConn.RecvReady();

            try {
                if (config.name == null)
                {
                    char[] !in ExHeap repHost, repDomain;
                    ipConn.SendGetHostName();
                    ipConn.RecvHostName(out repHost);

                    ipConn.SendGetDomainName();
                    ipConn.RecvDomainName(out repDomain);

                    Console.WriteLine("{0}.{1}", Bitter.ToString(repHost), Bitter.ToString(repDomain));
                    delete repHost;
                    delete repDomain;
                    return(0); // success
                }
                else
                {
                    ipConn.SendSetHostName(Bitter.FromString2(config.name));

                    switch receive {
                    case ipConn.Err():
                        Console.WriteLine("Failure setting host name \"{0}\"", config.name);
                        return(1);    // failure;

                    case ipConn.OK():
                        Console.WriteLine("Success setting host name");
                        break;

                    case ipConn.ChannelClosed():
                        Console.WriteLine("Failure setting host name \"{0}\" (channel closed)", config.name);
                        return(1);    // failure;
                    }
                }
            }
            finally {
                delete ipConn;
            }

            return(0); // success
        }
Beispiel #2
0
        // Must be balanced with a call to ReleaseDnsConnection()!
        internal static DNSContract.Imp !GetDnsConnection()
        {
            LocalDataStoreSlot slot = SafeSlotFetchOrInitialize(ref DnsSlot, DnsSlotLock);

            if (Thread.GetData(slot) == null)
            {
                // We haven't created a channel for this thread yet. Create one.
                DNSContract.Imp !dnsImp;
                DNSContract.Exp !dnsExp;
                DirectoryServiceContract.Imp epNS = DirectoryService.NewClientEndpoint();

                DNSContract.NewChannel(out dnsImp, out dnsExp);

                try {
                    epNS.SendBind(Bitter.FromString2(DNSContract.ModuleName), dnsExp);

                    switch receive {
                    case epNS.NakBind(ServiceContract.Exp: Start rejectedEP, error) :
                        if (rejectedEP != null)
                    {
                            delete rejectedEP;
                    }
                        delete dnsImp;

                        // Do nothing; we will return null below.
                        break;

                    case epNS.AckBind():
                        // Success; put our remaining end of the channel
                        // into thread-local storage.
                        dnsImp.RecvReady();
                        TRef <DNSContract.Imp : ReadyState> dnsConnHolder = new TRef <DNSContract.Imp : ReadyState>(dnsImp);

                        Thread.SetData(slot, dnsConnHolder);
                        break;
                    }
                }
                finally {
                    delete epNS;
                }
            }

            // By now there should definitely be a channel in our thread-local storage.
            TRef <DNSContract.Imp : ReadyState> !connHolder = (TRef <DNSContract.Imp : ReadyState> !)Thread.GetData(slot);
            return(connHolder.Acquire());
        }
Beispiel #3
0
        internal static int DefaultMain(DefaultConfig !config)
        {
            IPContract.Imp ipConn = ((!)config.ipRef).Acquire();
            if (ipConn == null)
            {
                throw new Exception("Unable to acquire handle to the IP network");
            }
            ipConn.RecvReady();


            char[][] !in ExHeap ifNames;
            ipConn.SendGetInterfaces();
            ipConn.RecvInterfaceList(out ifNames);

            for (int i = 0; i < ifNames.Length; ++i)
            {
                CustomVector.Expose(ifNames, i);
                char[] in ExHeap ifName = ifNames[i];
                if (ifName == null)
                {
                    throw new Exception("ifName is null");
                }
                string !deviceName = Bitter.ToString2(ifName);
                CustomVector.UnExpose(ifNames, i);
                ipConn.SendGetInterfaceState(Bitter.FromString2(deviceName));
                switch receive {
                case ipConn.InterfaceNotFound():
                    Console.WriteLine("Unexpected error");
                    break;

                case ipConn.InterfaceState(InterfaceInfo ifInfo):
                    WriteInterfaceLine(ifInfo, deviceName);
                    break;

                case ipConn.ChannelClosed():
                    throw new Exception("ipConn channel closed");
                }
            }

            delete ifNames;
            delete ipConn;

            return(0);
        }
Beispiel #4
0
        public static KeyboardDeviceContract.Imp OpenKeyboard(string! devName)
        {
            KeyboardDeviceContract.Exp! exp;
            KeyboardDeviceContract.Imp! imp;
            KeyboardDeviceContract.NewChannel(out imp, out exp);

            // get NS endpoint
            DirectoryServiceContract.Imp ns = DirectoryService.NewClientEndpoint();

            bool success = false;
            ns.SendBind(Bitter.FromString2(devName),exp);
            switch receive {
                case ns.AckBind():
                    success = true;
                    break;
                case ns.NakBind(exp):
                    delete exp;
                    break;
                case ns.ChannelClosed():
                    break;
            }

            if (!success) {
                DebugStub.Print("OpenKeyboard lookup of {0} failed.\n",
                                __arglist(devName);

                delete imp;
                delete ns;
                return null;
            }

            switch receive {
                case imp.Success():
                    break;
                case unsatisfiable:
                    throw new Exception("Didn't imp.RecvAckConnect");
                    break;
            }

            delete ns;
            return imp;
        }