opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 => PreRemove, Removing |
||
41 | /// PreRemove => Running, Removing |
||
42 | /// Removing => Removed |
||
43 | /// |
||
44 | /// All other methods should only see the scene presence in running state - this is the normal operational state |
||
45 | /// Removed state occurs when the presence has been removed. This is the end state with no exit. |
||
46 | /// </remarks> |
||
47 | public enum ScenePresenceState |
||
48 | { |
||
49 | Running, // Normal operation state. The scene presence is available. |
||
50 | PreRemove, // The presence is due to be removed but can still be returning to running. |
||
51 | Removing, // The presence is in the process of being removed from the scene via Scene.RemoveClient. |
||
52 | Removed, // The presence has been removed from the scene and is effectively dead. |
||
53 | // There is no exit from this state. |
||
54 | } |
||
55 | |||
56 | internal class ScenePresenceStateMachine |
||
57 | { |
||
58 | private ScenePresence m_sp; |
||
59 | private ScenePresenceState m_state; |
||
60 | |||
61 | internal ScenePresenceStateMachine(ScenePresence sp) |
||
62 | { |
||
63 | m_sp = sp; |
||
64 | m_state = ScenePresenceState.Running; |
||
65 | } |
||
66 | |||
67 | internal ScenePresenceState GetState() |
||
68 | { |
||
69 | return m_state; |
||
70 | } |
||
71 | |||
72 | /// <summary> |
||
73 | /// Updates the state of an agent that is already in transit. |
||
74 | /// </summary> |
||
75 | /// <param name='id'></param> |
||
76 | /// <param name='newState'></param> |
||
77 | /// <returns></returns> |
||
78 | /// <exception cref='Exception'>Illegal transitions will throw an Exception</exception> |
||
79 | internal void SetState(ScenePresenceState newState) |
||
80 | { |
||
81 | bool transitionOkay = false; |
||
82 | |||
83 | lock (this) |
||
84 | { |
||
85 | if (newState == m_state) |
||
86 | return; |
||
87 | else if (newState == ScenePresenceState.Running && m_state == ScenePresenceState.PreRemove) |
||
88 | transitionOkay = true; |
||
89 | else if (newState == ScenePresenceState.PreRemove && m_state == ScenePresenceState.Running) |
||
90 | transitionOkay = true; |
||
91 | else if (newState == ScenePresenceState.Removing) |
||
92 | { |
||
93 | if (m_state == ScenePresenceState.Running || m_state == ScenePresenceState.PreRemove) |
||
94 | transitionOkay = true; |
||
95 | } |
||
96 | else if (newState == ScenePresenceState.Removed && m_state == ScenePresenceState.Removing) |
||
97 | transitionOkay = true; |
||
98 | } |
||
99 | |||
100 | if (!transitionOkay) |
||
101 | { |
||
102 | throw new Exception( |
||
103 | string.Format( |
||
104 | "Scene presence {0} is not allowed to move from state {1} to new state {2} in {3}", |
||
105 | m_sp.Name, m_state, newState, m_sp.Scene.Name)); |
||
106 | } |
||
107 | else |
||
108 | { |
||
109 | m_state = newState; |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | } |