diff options
author | Justin Clark-Casey (justincc) | 2013-08-09 17:57:24 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-08-09 17:57:24 +0100 |
commit | aec701972844d4e006bb5d50e7983b818fb39249 (patch) | |
tree | 40f59f9ed4b84194c91340ba0a3a51012a490d5f /OpenSim | |
parent | Merge branch 'TeleportWork' (diff) | |
download | opensim-SC-aec701972844d4e006bb5d50e7983b818fb39249.zip opensim-SC-aec701972844d4e006bb5d50e7983b818fb39249.tar.gz opensim-SC-aec701972844d4e006bb5d50e7983b818fb39249.tar.bz2 opensim-SC-aec701972844d4e006bb5d50e7983b818fb39249.tar.xz |
Add missing file from b1c26a56
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresenceStateMachine.cs | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresenceStateMachine.cs b/OpenSim/Region/Framework/Scenes/ScenePresenceStateMachine.cs new file mode 100644 index 0000000..dc3a212 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/ScenePresenceStateMachine.cs | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace OpenSim.Region.Framework.Scenes | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// The possible states that a scene presence can be in. This is currently orthagonal to whether a scene presence | ||
34 | /// is root or child. | ||
35 | /// </summary> | ||
36 | /// <remarks> | ||
37 | /// This is a state machine. | ||
38 | /// | ||
39 | /// [Entry] => Running | ||
40 | /// Running => Removing | ||
41 | /// Removing => Removed | ||
42 | /// | ||
43 | /// All other methods should only see the scene presence in running state - this is the normal operational state | ||
44 | /// Removed state occurs when the presence has been removed. This is the end state with no exit. | ||
45 | /// </remarks> | ||
46 | public enum ScenePresenceState | ||
47 | { | ||
48 | Running, // Normal operation state. The scene presence is available. | ||
49 | Removing, // The presence is in the process of being removed from the scene via Scene.RemoveClient. | ||
50 | Removed, // The presence has been removed from the scene and is effectively dead. | ||
51 | // There is no exit from this state. | ||
52 | } | ||
53 | |||
54 | internal class ScenePresenceStateMachine | ||
55 | { | ||
56 | private ScenePresence m_sp; | ||
57 | private ScenePresenceState m_state; | ||
58 | |||
59 | internal ScenePresenceStateMachine(ScenePresence sp) | ||
60 | { | ||
61 | m_sp = sp; | ||
62 | m_state = ScenePresenceState.Running; | ||
63 | } | ||
64 | |||
65 | internal ScenePresenceState GetState() | ||
66 | { | ||
67 | return m_state; | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Updates the state of an agent that is already in transit. | ||
72 | /// </summary> | ||
73 | /// <param name='id'></param> | ||
74 | /// <param name='newState'></param> | ||
75 | /// <returns></returns> | ||
76 | /// <exception cref='Exception'>Illegal transitions will throw an Exception</exception> | ||
77 | internal void SetState(ScenePresenceState newState) | ||
78 | { | ||
79 | bool transitionOkay = false; | ||
80 | |||
81 | lock (this) | ||
82 | { | ||
83 | if (newState == ScenePresenceState.Removing && m_state == ScenePresenceState.Running) | ||
84 | transitionOkay = true; | ||
85 | else if (newState == ScenePresenceState.Removed && m_state == ScenePresenceState.Removing) | ||
86 | transitionOkay = true; | ||
87 | } | ||
88 | |||
89 | if (!transitionOkay) | ||
90 | { | ||
91 | throw new Exception( | ||
92 | string.Format( | ||
93 | "Scene presence {0} is not allowed to move from state {1} to new state {2} in {3}", | ||
94 | m_sp.Name, m_state, newState, m_sp.Scene.Name)); | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | m_state = newState; | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | } \ No newline at end of file | ||