Example #1
0
        /// -----------------------------------------------------------------
        /// <summary>
        /// </summary>
        /// -----------------------------------------------------------------
        public Dispatcher.Messages.ResponseBase RegisterTouchCallbackHandler(Dispatcher.Messages.RequestBase irequest)
        {
            if (irequest.GetType() != typeof(RegisterTouchCallbackRequest))
            {
                return(OperationFailed("wrong type"));
            }

            RegisterTouchCallbackRequest request = (RegisterTouchCallbackRequest)irequest;

            // Get the object and register a handler for it
            SceneObjectGroup sog = m_scene.GetSceneObjectGroup(request.ObjectID);

            if (sog == null)
            {
                return(OperationFailed(String.Format("no such object; {0}", request.ObjectID)));
            }

            if (sog.UUID != request.ObjectID)
            {
                return(OperationFailed("touch callback must be registered for root prim"));
            }

            UUID requestID = UUID.Random();

            sog.RootPart.SetScriptEvents(requestID, (int)scriptEvents.touch);

            // Create the event callback structure
            EventCallback cb = new EventCallback(request.ObjectID, request.EndPointID, requestID);

            // Add it to the object registry for handling the touch events
            lock (m_objectRegistry)
            {
                if (!m_objectRegistry.ContainsKey(request.ObjectID))
                {
                    m_objectRegistry.Add(request.ObjectID, new List <EventCallback>());
                }
                m_objectRegistry[request.ObjectID].Add(cb);
            }

            // Add it to the endpoint registry for handling changes in the endpoint state
            lock (m_endpointRegistry)
            {
                if (!m_endpointRegistry.ContainsKey(request.EndPointID))
                {
                    m_endpointRegistry.Add(request.EndPointID, new List <EventCallback>());

                    // Only need to register the handler for the first request for this endpoint
                    EndPoint ep = m_dispatcher.LookupEndPoint(request.EndPointID);
                    ep.AddCloseHandler(this.EndPointCloseHandler);
                }
                m_endpointRegistry[request.EndPointID].Add(cb);
            }

            m_log.DebugFormat("[EventHandlers] registered touch callback for {0}", request.ObjectID);
            return(new RegisterTouchCallbackResponse(requestID));
        }
Example #2
0
        /// -----------------------------------------------------------------
        /// <summary>
        /// </summary>
        /// -----------------------------------------------------------------
        ///
        public Dispatcher.Messages.ResponseBase RegisterUpdatedCallbackHandler(Dispatcher.Messages.RequestBase irequest)
        {
            if (irequest.GetType() != typeof(RegisterUpdatedCallbackRequest))
            {
                return(OperationFailed("wrong type"));
            }

            RegisterUpdatedCallbackRequest request = (RegisterUpdatedCallbackRequest)irequest;

            StringBuilder warnings  = new StringBuilder();
            UUID          requestID = UUID.Random();

            foreach (UUID oid in request.ObjectIDs)
            {
                // Get the object and register a handler for it
                SceneObjectGroup sog = m_scene.GetSceneObjectGroup(oid);
                if (sog == null)
                {
                    warnings.AppendFormat("no such object {0}; ", oid);
                    continue;
                }

                if (sog.UUID != oid)
                {
                    warnings.AppendFormat("updated callback must be registered for root prim; ");
                    continue;
                }

                // Create the event callback structure
                EventCallback cb = new EventCallback(oid, request.EndPointID, requestID, EventType.Position);

                // Add it to the object registry for handling events
                lock (m_objectRegistry)
                {
                    if (!m_objectRegistry.ContainsKey(oid))
                    {
                        m_objectRegistry.Add(oid, new List <EventCallback>());
                    }
                    m_objectRegistry[oid].Add(cb);
                }

                // Add it to the endpoint registry for handling changes in the endpoint state
                lock (m_endpointRegistry)
                {
                    if (!m_endpointRegistry.ContainsKey(request.EndPointID))
                    {
                        m_endpointRegistry.Add(request.EndPointID, new List <EventCallback>());

                        // Only need to register the handler for the first request for this endpoint
                        EndPoint ep = m_dispatcher.LookupEndPoint(request.EndPointID);
                        ep.AddCloseHandler(this.EndPointCloseHandler);
                    }
                    m_endpointRegistry[request.EndPointID].Add(cb);
                }

                m_LastPositions[oid] = sog.RootPart.GroupPosition;

                m_log.DebugFormat("[EventHandlers] registered updated callback for {0}", oid);
            }

            return(new RegisterUpdatedCallbackResponse(requestID, warnings.ToString()));
        }