//! Callback for sensor-manager topic. void OnGestureManagerEvent(TopicClient.Payload a_Payload) { IDictionary json = Json.Deserialize(Encoding.UTF8.GetString(a_Payload.Data)) as IDictionary; bool bFailed = false; string gestureId = json["gestureId"] as string; string instanceId = json["instanceId"] as string; string gestureKey = gestureId + "/" + instanceId; string event_name = json["event"] as string; IGesture gesture = null; if (m_Gestures.ContainsKey(gestureKey)) { if (m_Gestures.TryGetValue(gestureKey, out gesture)) { if (event_name.CompareTo("execute_gesture") == 0) { if (!gesture.Execute(OnGestureDone, json["params"] as IDictionary)) { Log.Error("GestureManager", "Failed to execute gesture {0}", gestureId); bFailed = true; } } else if (event_name.CompareTo("abort_gesture") == 0) { if (!gesture.Abort()) { Log.Error("GestureManager", "Failed to abort gesture {0}", gestureId); bFailed = true; } } } else { Log.Error("GestureManager", "Failed to find gesture {0}", gestureKey); bFailed = true; } // if we failed, send the message back with a different event if (bFailed) { json["failed_event"] = event_name; json["event"] = "error"; TopicClient.Publish("gesture-manager", Json.Serialize(json)); } } else { //do nothing } }