123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- namespace OpenSim.Region.Framework.Scenes
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public enum ScenePresenceState
- {
- Running,
- PreRemove,
- Removing,
- Removed,
-
- }
- internal class ScenePresenceStateMachine
- {
- private ScenePresence m_sp;
- private ScenePresenceState m_state;
- internal ScenePresenceStateMachine(ScenePresence sp)
- {
- m_sp = sp;
- m_state = ScenePresenceState.Running;
- }
- internal ScenePresenceState GetState()
- {
- return m_state;
- }
-
-
-
-
-
-
-
- internal void SetState(ScenePresenceState newState)
- {
- bool transitionOkay = false;
- lock (this)
- {
- if (newState == m_state)
- return;
- else if (newState == ScenePresenceState.Running && m_state == ScenePresenceState.PreRemove)
- transitionOkay = true;
- else if (newState == ScenePresenceState.PreRemove && m_state == ScenePresenceState.Running)
- transitionOkay = true;
- else if (newState == ScenePresenceState.Removing)
- {
- if (m_state == ScenePresenceState.Running || m_state == ScenePresenceState.PreRemove)
- transitionOkay = true;
- }
- else if (newState == ScenePresenceState.Removed && m_state == ScenePresenceState.Removing)
- transitionOkay = true;
- }
- if (!transitionOkay)
- {
- throw new Exception(
- string.Format(
- "Scene presence {0} is not allowed to move from state {1} to new state {2} in {3}",
- m_sp.Name, m_state, newState, m_sp.Scene.Name));
- }
- else
- {
- m_state = newState;
- }
- }
- }
- }
|