Example #1
0
        private void seedRequest_OnCapsResponse(object response, HttpRequestState state)
        {
            if (response is Dictionary<string, object>)
            {
                Dictionary<string, object> respTable = (Dictionary<string, object>)response;

                StringBuilder capsList = new StringBuilder();

                foreach (string cap in respTable.Keys)
                {
                    capsList.Append(cap);
                    capsList.Append(' ');

                    _Caps[cap] = (string)respTable[cap];
                }

                Simulator.Client.DebugLog("Got capabilities: " + capsList.ToString());

                // Signal that we have connected to the CAPS server and received a list of capability URIs
                CapsReceivedEvent.Set();

                if (_Caps.ContainsKey("EventQueueGet"))
                {
                    _EventQueueCap = new CapsEventQueue(Simulator, _Caps["EventQueueGet"]);
                    Simulator.Client.DebugLog("Starting event queue for " + Simulator.ToString());

                    _EventQueueCap.MakeRequest();
                }
            }
            else
            {
                // The initial CAPS connection failed, try again
                MakeSeedRequest();
            }
        }
Example #2
0
        private void EstablishAgentCommunicationEventHandler(string message, Dictionary<string, object> body, CapsEventQueue caps)
        {
            if (Client.Settings.MULTIPLE_SIMS && body.ContainsKey("sim-ip-and-port"))
            {
                string ipAndPort = (string)body["sim-ip-and-port"];
                string[] pieces = ipAndPort.Split(':');
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(pieces[0]), Convert.ToInt32(pieces[1]));
                Simulator sim = Client.Network.FindSimulator(endPoint);

                if (sim == null)
                {
                    Client.Log("Got EstablishAgentCommunication for unknown sim " + ipAndPort,
                        Helpers.LogLevel.Error);

                    // FIXME: Should we use this opportunity to connect to the simulator?
                }
                else
                {
                    Client.Log("Got EstablishAgentCommunication for " + sim.ToString(),
                        Helpers.LogLevel.Info);

                    sim.SetSeedCaps((string)body["seed-capability"]);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Fire the events registered for this event type synchronously
        /// </summary>
        /// <param name="capsEvent">Capability name</param>
        /// <param name="body">Decoded event body</param>
        /// <param name="eventQueue">Reference to the event queue that 
        /// generated this event</param>
        internal void RaiseEvent(string capsEvent, Dictionary<string, object> body, CapsEventQueue eventQueue)
        {
            bool specialHandler = false;
            Capabilities.EventQueueCallback callback;

            // Default handler first, if one exists
            if (_EventTable.TryGetValue(capsEvent, out callback))
            {
                if (callback != null)
                {
                    try { callback(capsEvent, body, eventQueue); }
                    catch (Exception ex) { Client.Log("CAPS Event Handler: " + ex.ToString(), Helpers.LogLevel.Error); }
                }
            }

            // Generic parser next
            Packet packet = Packet.BuildPacket(capsEvent, body);
            if (packet != null)
            {
                NetworkManager.IncomingPacket incomingPacket;
                incomingPacket.Simulator = eventQueue.Simulator;
                incomingPacket.Packet = packet;

                Client.DebugLog("Serializing " + packet.Type.ToString() + " capability with generic handler");

                Client.Network.PacketInbox.Enqueue(incomingPacket);
                specialHandler = true;
            }

            // Explicit handler next
            if (_EventTable.TryGetValue(capsEvent, out callback) && callback != null)
            {
                try { callback(capsEvent, body, eventQueue); }
                catch (Exception ex) { Client.Log("CAPS Event Handler: " + ex.ToString(), Helpers.LogLevel.Error); }

                specialHandler = true;
            }

            if (!specialHandler)
                Client.Log("Unhandled CAPS event " + capsEvent, Helpers.LogLevel.Warning);
        }
Example #4
0
        /// <summary>
        /// Fire the events registered for this event type asynchronously
        /// </summary>
        /// <param name="capsEvent">Capability name</param>
        /// <param name="body">Decoded event body</param>
        /// <param name="eventQueue">Reference to the event queue that 
        /// generated this event</param>
        internal void BeginRaiseEvent(string capsEvent, Dictionary<string, object> body, CapsEventQueue eventQueue)
        {
            bool specialHandler = false;
            Capabilities.EventQueueCallback callback;

            // Default handler first, if one exists
            if (_EventTable.TryGetValue(String.Empty, out callback))
            {
                if (callback != null)
                {
                    CapsCallbackWrapper wrapper;
                    wrapper.Callback = callback;
                    wrapper.CapsEvent = capsEvent;
                    wrapper.Body = body;
                    wrapper.EventQueue = eventQueue;
                    ThreadPool.QueueUserWorkItem(_ThreadPoolCallback, wrapper);
                }
            }

            // Generic parser next
            Packet packet = Packet.BuildPacket(capsEvent, body);
            if (packet != null)
            {
                NetworkManager.IncomingPacket incomingPacket;
                incomingPacket.Simulator = eventQueue.Simulator;
                incomingPacket.Packet = packet;

                Client.DebugLog("Serializing " + packet.Type.ToString() + " capability with generic handler");

                Client.Network.PacketInbox.Enqueue(incomingPacket);
                specialHandler = true;
            }
            
            // Explicit handler next
            if (_EventTable.TryGetValue(capsEvent, out callback) && callback != null)
            {
                CapsCallbackWrapper wrapper;
                wrapper.Callback = callback;
                wrapper.CapsEvent = capsEvent;
                wrapper.Body = body;
                wrapper.EventQueue = eventQueue;
                ThreadPool.QueueUserWorkItem(_ThreadPoolCallback, wrapper);

                specialHandler = true;
            }

            if (!specialHandler)
                Client.Log("Unhandled CAPS event " + capsEvent, Helpers.LogLevel.Warning);
        }
Example #5
0
        private void RequiredVoiceVersionEventHandler(string message, Dictionary<string, object> body, CapsEventQueue caps)
        {
            if (body.ContainsKey("major_version"))
            {
                int majorVersion = (int)body["major_version"];

                if (VOICE_MAJOR_VERSION != majorVersion)
                {
                    Client.Log(String.Format("Voice version mismatch! Got {0}, expecting {1}. Disabling the voice manager",
                        majorVersion, VOICE_MAJOR_VERSION), Helpers.LogLevel.Error);
                    Enabled = false;
                }
                else
                {
                    Client.DebugLog("Voice version " + majorVersion + " verified");
                }
            }
        }