void HandleQueryResponse(IDictionary a_Message) { Log.Debug("TopicClient", "HandleQueryResponse()"); QueryInfo info = new QueryInfo(); info.bSuccess = true; info.Path = OriginToPath((string)a_Message["origin"]); info.SelfId = (string)a_Message["selfId"]; if (a_Message.Contains("name")) { info.Name = (string)a_Message["name"]; info.Type = (string)a_Message["type"]; info.Version = (string)a_Message["version"]; } if (a_Message.Contains("parentId")) { info.ParentId = (string)a_Message["parentId"]; } if (a_Message.Contains("children")) { IList children = (IList)a_Message["children"]; info.Children = new string[children.Count]; for (int i = 0; i < children.Count; ++i) { info.Children[i] = (string)children[i]; } } if (a_Message.Contains("topics")) { IList topics = (IList)a_Message["topics"]; info.Topics = new TopicInfo[topics.Count]; for (int i = 0; i < topics.Count; ++i) { IDictionary topic = (IDictionary)topics[i]; TopicInfo ti = new TopicInfo(); ti.TopicId = (string)topic["topicId"]; ti.Type = (string)topic["type"]; info.Topics[i] = ti; } } string reqId = (string)a_Message["request"]; OnQueryResponse callback = null; if (m_QueryRequestMap.TryGetValue(reqId, out callback)) { callback(info); m_QueryRequestMap.Remove(reqId); } }
//! This queries a node specified by the given path. public void Query(string a_Path, //! the path to the node, we will invoke the callback with a QueryInfo structure OnQueryResponse a_Callback, float a_fTimeout = 10.0f) { string reqId = string.Format("{0}", m_ReqId++); m_QueryRequestMap[reqId] = a_Callback; Dictionary <string, object> query = new Dictionary <string, object>(); query["targets"] = new string[] { a_Path }; query["msg"] = "query"; query["request"] = reqId; SendMessage(query); Runnable.Run(QueryTimeout(reqId, a_fTimeout)); }
void HandleNoRoute(IDictionary a_Message) { string failed_msg = (string)a_Message["failed_msg"]; string origin = (string)a_Message["origin"]; Log.Warning("TopicClient", "Failed to send message {1} to {0}", origin, failed_msg); if (failed_msg == "query") { string reqId = (string)a_Message["request"]; OnQueryResponse callback = null; if (m_QueryRequestMap.TryGetValue(reqId, out callback)) { callback(null); m_QueryRequestMap.Remove(reqId); } } }