mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
SCHEDULER:New() implemented and routines.scheduleFunction removed
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
--- Models time events calling event handing functions.
|
||||
--
|
||||
-- @{SCHEDULER} class
|
||||
-- ===================
|
||||
-- The @{SCHEDULER} class models time events calling given event handling functions.
|
||||
--
|
||||
-- SCHEDULER constructor
|
||||
-- =====================
|
||||
-- The SCHEDULER class is quite easy to use:
|
||||
--
|
||||
-- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters.
|
||||
--
|
||||
-- SCHEDULER timer methods
|
||||
-- =======================
|
||||
-- The SCHEDULER can be stopped and restarted with the following methods:
|
||||
--
|
||||
-- * @{#SCHEDULER.Start}: (Re-)Start the scheduler.
|
||||
-- * @{#SCHEDULER.Start}: Stop the scheduler.
|
||||
--
|
||||
-- @module Scheduler
|
||||
-- @author FlightControl
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Cargo" )
|
||||
Include.File( "Message" )
|
||||
|
||||
|
||||
--- The SCHEDULER class
|
||||
@@ -16,19 +32,19 @@ SCHEDULER = {
|
||||
}
|
||||
|
||||
|
||||
--- SCHEDULER constructor.
|
||||
--- Constructor.
|
||||
-- @param #SCHEDULER self
|
||||
-- @param #table TimeEventObject
|
||||
-- @param #function TimeEventFunction
|
||||
-- @param #table TimeEventFunctionArguments
|
||||
-- @param #number StartSeconds
|
||||
-- @param #number RepeatSecondsInterval
|
||||
-- @param #number RandomizationFactor
|
||||
-- @param #number StopSeconds
|
||||
-- @return #SCHEDULER
|
||||
-- @param #table TimeEventObject Specified for which Moose object the timer is setup. If a value of nil is provided, a scheduler will be setup without an object reference.
|
||||
-- @param #function TimeEventFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in TimeEventFunctionArguments.
|
||||
-- @param #table TimeEventFunctionArguments Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
|
||||
-- @param #number StartSeconds Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called.
|
||||
-- @param #number RepeatSecondsInterval Specifies the interval in seconds when the scheduler will call the event function.
|
||||
-- @param #number RandomizationFactor Specifies a randomization factor between 0 and 1 to randomize the RepeatSecondsInterval.
|
||||
-- @param #number StopSeconds Specifies the amount of seconds when the scheduler will be stopped.
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F( { TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
||||
self:F2( { TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
||||
|
||||
self.TimeEventObject = TimeEventObject
|
||||
self.TimeEventFunction = TimeEventFunction
|
||||
@@ -60,8 +76,33 @@ function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArg
|
||||
return self
|
||||
end
|
||||
|
||||
function SCHEDULER:Scheduler()
|
||||
self:F( self.TimeEventFunctionArguments )
|
||||
--- (Re-)Starts the scheduler.
|
||||
-- @param #SCHEDULER self
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:Start()
|
||||
self:F2( self.TimeEventObject )
|
||||
|
||||
self.Repeat = true
|
||||
timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Stops the scheduler.
|
||||
-- @param #SCHEDULER self
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:Stop()
|
||||
self:F2( self.TimeEventObject )
|
||||
|
||||
self.Repeat = false
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-- Private Functions
|
||||
|
||||
function SCHEDULER:_Scheduler()
|
||||
self:F2( self.TimeEventFunctionArguments )
|
||||
|
||||
local ErrorHandler = function( errmsg )
|
||||
|
||||
@@ -83,7 +124,7 @@ function SCHEDULER:Scheduler()
|
||||
if Status and Status == true and Result and Result == true then
|
||||
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
|
||||
timer.scheduleFunction(
|
||||
self.Scheduler,
|
||||
self._Scheduler,
|
||||
self,
|
||||
timer.getTime() + self.RepeatSecondsInterval + math.random( - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ), ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ) ) + 0.01
|
||||
)
|
||||
@@ -92,20 +133,7 @@ function SCHEDULER:Scheduler()
|
||||
|
||||
end
|
||||
|
||||
function SCHEDULER:Start()
|
||||
self:F( self.TimeEventObject )
|
||||
|
||||
self.Repeat = true
|
||||
timer.scheduleFunction( self.Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function SCHEDULER:Stop()
|
||||
self:F( self.TimeEventObject )
|
||||
|
||||
self.Repeat = false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user