Ejemplo n.º 1
0
        /// <summary>
        /// Overrides RobotBrain Bind function to implement addition LEDAdapter functions.
        /// </summary>
        protected override void Bind()
        {
            base.Bind();

            //Bind to scribbler specific sensors

            //Specialized LED array
            directory.Query dquery = new directory.Query(new directory.QueryRequestType(
                                                             new Microsoft.Dss.ServiceModel.Dssp.ServiceInfoType("http://www.roboteducation.org/scribblerledarray.html")));
            //Uri direcURI = DssEnvironment.FindService(directory.Contract.Identifier);
            //TODO: remove the line below once the above line works
            Uri direcURI = new Uri("http://localhost:" + httpPort + "/directory");

            directory.DirectoryPort dport = DssEnvironment.ServiceForwarder <directory.DirectoryPort>(direcURI);
            dport.Post(dquery);

            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Choice(dquery.ResponsePort,
                                            delegate(directory.QueryResponseType success)
            {
                sledadapter = new ScribblerLEDArrayAdapter(success.RecordList[0].Service);
            },
                                            delegate(Fault fault) { }
                                            )
                             );
        }
        public IEnumerator<ITask> ConnectToBiclopsService()
        {
            _biclopsConnected = false;

            loadRemoteServiceDirectoryPorts();

            ds.DirectoryPort remoteDir;
            int k;

            List<biclops.BiclopsOperations> PortList = new List<biclops.BiclopsOperations>();

            while (_biclopsConnected == false)
            {
                for (k = 0; k < _remoteHosts.Count; k++)
                {
                    remoteDir = ServiceForwarder<ds.DirectoryPort>(_remoteHosts[k] + "/directory");
                    ServiceInfoType ServiceInfo = new ServiceInfoType(biclops.Contract.Identifier);
                    ds.QueryRequestType ReqBody;
                    ds.Query Query;

                    ReqBody = new ds.QueryRequestType(ServiceInfo);
                    Query = new ds.Query(ReqBody);

                    // Post query
                    remoteDir.Post(Query);
                    yield return Arbiter.Choice(Query.ResponsePort,
                        delegate(ds.QueryResponseType success)
                        {
                            if (success.RecordList != null)
                            {
                                Console.Write("Received {0} biclops service responses from directory\n", success.RecordList.Length);
                                foreach (ServiceInfoType si in success.RecordList)
                                {
                                    _biclopsPort = base.ServiceForwarder<biclops.BiclopsOperations>(si.Service);
                                    _biclopsConnected = true;
                                    break;
                                }
                            }
                        },
                        delegate(Fault f)
                        {
                            LogError(LogGroups.Console, f.ToString());
                        }
                    );
                    if (_biclopsConnected)
                        break;
                    else
                    {
                        Console.WriteLine("BiclopsRightCameraJointConfiguration: cannot to connect to the Biclops Service\nStart one now if it has not been started and add the host/port to the hosts.txt");
                        Thread.Sleep(2000);
                    }
                }

            }

            yield break;
        }
Ejemplo n.º 3
0
        public IEnumerator <ITask> OnHandOff(HandOff handOff)
        {
            Fault fault = null;

            ServiceInfoType[] services = null;

            dir.QueryRequestType request = new dir.QueryRequestType(
                new ServiceInfoType(Contract.Identifier)
                );
            dir.Query query = new dir.Query(request);
            query.TimeSpan = new TimeSpan(0, 0, 2);
            DirectoryPort.Post(query);

            yield return(Arbiter.Choice(
                             query.ResponsePort,
                             delegate(dir.QueryResponseType success)
            {
                services = success.RecordList;
            },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            if (fault != null)
            {
                handOff.ResponsePort.Post(fault);
                yield break;
            }

            foreach (ServiceInfoType service in services)
            {
                FlexDialogOperations fwd   = ServiceForwarder <FlexDialogOperations>(service.Service);
                FlexDialogState      state = null;

                Get get = new Get();
                get.TimeSpan = new TimeSpan(0, 0, 2);
                fwd.Post(get);

                yield return(Arbiter.Choice(
                                 get.ResponsePort,
                                 delegate(FlexDialogState success)
                {
                    state = success;
                },
                                 delegate(Fault f)
                {
                    fault = f;
                }
                                 ));

                if (state != null && state.Title == handOff.Body.Title)
                {
                    handOff.Body.Service = service.HttpServiceAlias.ToString();
                    DoSendNotification(handOff);
                    handOff.ResponsePort.Post(handOff.Body);
                    yield break;
                }
            }

            handOff.ResponsePort.Post(
                Fault.FromCodeSubcodeReason(
                    FaultCodes.Receiver,
                    DsspFaultCodes.UnknownEntry,
                    "Unable to find dialog with title: " + handOff.Body.Title
                    )
                );
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Searches service directory for a service with the specified contract. On success binds it to an Adapter object and inserts it in the
        /// adapters lookup dictionary.
        /// </summary>
        /// <param name="contract">The contract of the service</param>
        /// <returns>Nothing</returns>
        protected virtual IEnumerator <ITask> DirectorySearch(string contract)
        {
            directory.Query dquery = new directory.Query(new directory.QueryRequestType(
                                                             new Microsoft.Dss.ServiceModel.Dssp.ServiceInfoType(contract)));

            //Uri direcURI = DssEnvironment.FindService(directory.Contract.Identifier);
            //TODO: remove the line below once the above line works
            Uri direcURI = new Uri("http://localhost:" + httpPort + "/directory");

            directory.DirectoryPort dport = DssEnvironment.ServiceForwarder <directory.DirectoryPort>(direcURI);
            dport.Post(dquery);

            yield return(Arbiter.Choice(
                             dquery.ResponsePort,
                             delegate(directory.QueryResponseType success)
            {
                switch (contract)
                {
                case drive.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new DriveAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.DriveAdapter, list);
                        break;
                    }

                case analog.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new AnalogSensorAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.AnalogSensorAdapter, list);
                        break;
                    }

                case contact.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new ContactSensorArrayAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.ContactSensorArrayAdapter, list);
                        break;
                    }

                case analogArray.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new AnalogSensorArrayAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.AnalogSensorArrayAdapter, list);
                        break;
                    }

                case tonegen.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new ToneGeneratorAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.ToneGeneratorAdapter, list);
                        break;
                    }

                case ledarray.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new LEDArrayAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.LEDArrayAdapter, list);
                        break;
                    }

                case sonar.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new SonarAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.SonarAdapter, list);
                        break;
                    }
                }
            },
                             delegate(Fault fault) { }
                             ));

            yield break;
        }
Ejemplo n.º 5
0
        private IEnumerator <ITask> OnStartup()
        {
            #region CODECLIP 02-3
            PartnerType      remote    = FindPartner("Remote");
            ds.DirectoryPort remoteDir = DirectoryPort;

            if (remote != null && !string.IsNullOrEmpty(remote.Service))
            {
                remoteDir = ServiceForwarder <ds.DirectoryPort>(remote.Service);
            }
            #endregion

            #region CODECLIP 02-4
            cs.ConstructorPort remoteConstructor = ConstructorPort;
            ds.Query           query             = new ds.Query(
                new ds.QueryRequestType(
                    new ServiceInfoType(cs.Contract.Identifier)
                    )
                );

            remoteDir.Post(query);
            yield return((Choice)query.ResponsePort);

            ds.QueryResponseType queryRsp = query.ResponsePort;
            if (queryRsp != null)
            {
                remoteConstructor = ServiceForwarder <cs.ConstructorPort>(queryRsp.RecordList[0].Service);
            }
            #endregion

            #region CODECLIP 02-5
            string    clockService = null;
            cs.Create create       = new cs.Create(new ServiceInfoType(rst4.Contract.Identifier));
            remoteConstructor.Post(create);
            yield return((Choice)create.ResponsePort);

            CreateResponse createRsp = create.ResponsePort;
            if (createRsp != null)
            {
                clockService = createRsp.Service;
            }
            else
            {
                LogError((Fault)create.ResponsePort);
                yield break;
            }

            _clockPort = ServiceForwarder <rst4.ServiceTutorial4Operations>(clockService);
            #endregion

            rst4.Get get;
            yield return(_clockPort.Get(GetRequestType.Instance, out get));

            rst4.ServiceTutorial4State state = get.ResponsePort;

            if (state != null)
            {
                ServiceTutorial7State initState = new ServiceTutorial7State();

                PartnerType partner = FindPartner("Local");
                if (partner != null)
                {
                    initState.Clocks.Add(partner.Service);
                }
                initState.Clocks.Add(clockService);

                Replace replace = new Replace();
                replace.Body = initState;

                _mainPort.Post(replace);
            }
            else
            {
                LogError("Unable to Get state from ServiceTutorial4", (Fault)get.ResponsePort);
                yield break;
            }

            rst4.Subscribe subscribe;
            yield return(_clockPort.Subscribe(_clockNotify, out subscribe));

            if ((Fault)subscribe.ResponsePort != null)
            {
                LogError("Unable to subscribe to remote ServiceTutorial4", (Fault)subscribe.ResponsePort);
            }

            yield return(_localClockPort.Subscribe(_localClockNotify, out subscribe));

            if ((Fault)subscribe.ResponsePort != null)
            {
                LogError("Unable to subscribe to local ServiceTutorial4", (Fault)subscribe.ResponsePort);
            }
        }