Example #1
0
        private void OnQuery(TopicClient.QueryInfo a_Query)
        {
            Log.Debug("TopicClient", "OnQuery(). QueryResponse: {0}", a_Query);
            m_bQueryTested = true;

            TopicClient.Instance.Subscribe("sensor-Microphone", OnMicrophoneData);
        }
Example #2
0
            private void OnQueryResponse(TopicClient.QueryInfo a_Info)
            {
                m_Explorer.m_PendingRequests -= 1;
                m_Info = a_Info;

                if (m_Info != null)
                {
                    TopicClient.Subscribe(m_Path + "topic-manager", OnTopicManagerEvent);
                    m_bSubscribed = true;

                    if (!string.IsNullOrEmpty(m_Info.ParentId))
                    {
                        if (m_Info.ParentId != m_Source)
                        {
                            if (!IsCircular(m_Info.ParentId))
                            {
                                Parent = new Node(m_Explorer);
                                Parent.Children.Add(this);

                                if (m_Explorer.OnNodeAdded != null)
                                {
                                    m_Explorer.OnNodeAdded(Parent);
                                }

                                Parent.Refresh(m_Path + "../", SelfId);
                            }
                            else
                            {
                                Log.Warning("SelfExplorer", "Circular parent detected {0}", m_Info.ParentId);
                            }
                        }
                    }
                    else if (Parent != null)
                    {
                        if (m_Explorer.OnNodeRemoved != null)
                        {
                            m_Explorer.OnNodeRemoved(Parent);
                        }

                        Parent = null;
                    }

                    if (m_Info.Children != null)
                    {
                        foreach (string childId in m_Info.Children)
                        {
                            if (childId == m_Source || childId == SelfId)
                            {
                                continue;           // skip our source
                            }
                            // look for an existing node first..
                            Node child = null;
                            foreach (Node node in m_Children)
                            {
                                if (node.SelfId == childId)
                                {
                                    child = node;
                                    break;
                                }
                            }

                            if (child == null)
                            {
                                // no existing node found, create one..
                                child = new Node(m_Explorer);
                                m_Children.Add(child);

                                if (m_Explorer.OnNodeAdded != null)
                                {
                                    m_Explorer.OnNodeAdded(child);
                                }
                            }

                            // refresh the child node..
                            child.Refresh(m_Path + childId + "/", SelfId);
                        }
                    }

                    // remove children..
                    List <Node> remove = new List <Node>();
                    foreach (Node child in m_Children)
                    {
                        bool bFoundChild = false;
                        if (m_Info.Children != null)
                        {
                            foreach (string childId in m_Info.Children)
                            {
                                if (childId == child.SelfId)
                                {
                                    bFoundChild = true;
                                    break;
                                }
                            }
                        }

                        if (!bFoundChild)
                        {
                            if (m_Explorer.OnNodeRemoved != null)
                            {
                                m_Explorer.OnNodeRemoved(child);
                            }
                            remove.Add(child);
                        }
                    }

                    foreach (Node purge in remove)
                    {
                        m_Children.Remove(purge);
                    }
                }
                else if (m_Active)
                {
                    Log.Error("SelfExplorer", "Failed to query {0}", m_Path);
                    m_bError = true;

                    if (m_Explorer.Root == this)
                    {
                        m_RetryRoutine = Runnable.Run(OnRetryRefresh());
                    }
                }

                if (m_Explorer.OnNodeReady != null)
                {
                    m_Explorer.OnNodeReady(this);
                }
                if (m_Explorer.m_PendingRequests == 0 && m_Explorer.OnExplorerDone != null)
                {
                    m_Explorer.OnExplorerDone(m_Explorer);
                }
            }