aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs161
1 files changed, 0 insertions, 161 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs
deleted file mode 100644
index 3dd875a..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs
+++ /dev/null
@@ -1,161 +0,0 @@
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 OpenSim 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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32
33namespace OpenSim.Region.ScriptEngine.XEngine.AsyncCommandPlugins
34{
35 public class Timer
36 {
37 public AsyncCommandManager m_CmdManager;
38
39 public Timer(AsyncCommandManager CmdManager)
40 {
41 m_CmdManager = CmdManager;
42 }
43
44 //
45 // TIMER
46 //
47 private class TimerClass
48 {
49 public uint localID;
50 public LLUUID itemID;
51 //public double interval;
52 public long interval;
53 //public DateTime next;
54 public long next;
55 }
56
57 private List<TimerClass> Timers = new List<TimerClass>();
58 private object TimerListLock = new object();
59
60 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec)
61 {
62 // Always remove first, in case this is a re-set
63 UnSetTimerEvents(m_localID, m_itemID);
64 if (sec == 0) // Disabling timer
65 return;
66
67 // Add to timer
68 TimerClass ts = new TimerClass();
69 ts.localID = m_localID;
70 ts.itemID = m_itemID;
71 ts.interval = Convert.ToInt64(sec * 10000000); // How many 100 nanoseconds (ticks) should we wait
72 // 2193386136332921 ticks
73 // 219338613 seconds
74
75 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
76 ts.next = DateTime.Now.Ticks + ts.interval;
77 lock (TimerListLock)
78 {
79 Timers.Add(ts);
80 }
81 }
82
83 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID)
84 {
85 // Remove from timer
86 lock (TimerListLock)
87 {
88 foreach (TimerClass ts in new ArrayList(Timers))
89 {
90 if (ts.localID == m_localID && ts.itemID == m_itemID)
91 Timers.Remove(ts);
92 }
93 }
94 }
95
96 public void CheckTimerEvents()
97 {
98 // Nothing to do here?
99 if (Timers.Count == 0)
100 return;
101
102 lock (TimerListLock)
103 {
104 // Go through all timers
105 foreach (TimerClass ts in Timers)
106 {
107 // Time has passed?
108 if (ts.next < DateTime.Now.Ticks)
109 {
110 // Console.WriteLine("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
111 // Add it to queue
112 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
113 new XEventParams("timer", new Object[0],
114 new XDetectParams[0]));
115 // set next interval
116
117 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
118 ts.next = DateTime.Now.Ticks + ts.interval;
119 }
120 }
121 }
122 }
123
124 public Object[] GetSerializationData(LLUUID itemID)
125 {
126 List<Object> data = new List<Object>();
127
128 lock (TimerListLock)
129 {
130 foreach (TimerClass ts in Timers)
131 {
132 if (ts.itemID == itemID)
133 {
134 data.Add(ts.interval);
135 data.Add(ts.next-DateTime.Now.Ticks);
136 }
137 }
138 }
139 return data.ToArray();
140 }
141
142 public void CreateFromData(uint localID, LLUUID itemID, LLUUID objectID,
143 Object[] data)
144 {
145 int idx = 0;
146
147 while (idx < data.Length)
148 {
149 TimerClass ts = new TimerClass();
150
151 ts.localID = localID;
152 ts.itemID = itemID;
153 ts.interval = (long)data[idx];
154 ts.next = DateTime.Now.Ticks + (long)data[idx+1];
155 idx += 2;
156
157 Timers.Add(ts);
158 }
159 }
160 }
161}