encapuslating Delay

This commit is contained in:
Axel Kittenberger 2016-12-14 09:02:51 +01:00
parent 20edbe5f6e
commit 4005c2899b
1 changed files with 92 additions and 42 deletions

View File

@ -189,8 +189,8 @@ end )( )
-- since Lua's # operator does not work on tables whose key values are not -- since Lua's # operator does not work on tables whose key values are not
-- strictly linear. -- strictly linear.
-- --
local CountArray = ( function( ) local CountArray = ( function
( )
-- --
-- Metatable -- Metatable
-- --
@ -279,7 +279,7 @@ local CountArray = ( function( )
[ k_nt ] = { } [ k_nt ] = { }
} }
setmetatable(o, mt) setmetatable( o, mt )
return o return o
end end
@ -505,8 +505,73 @@ end
-- --
-- Holds the information about a delayed event for one Sync. -- Holds the information about a delayed event for one Sync.
-- --
-- Valid stati of an delay are:
-- 'wait' ... the event is ready to be handled.
-- 'active' ... there is process running catering for this event.
-- 'blocked' ... this event waits for another to be handled first.
--
local Delay = ( function local Delay = ( function
( ) ( )
--
-- Metatable.
--
local mt = { }
--
-- Key to native table
--
local k_nt = { }
--
-- On accessing a nil index.
--
mt.__index = function
(
t, -- table accessed
k -- key value accessed
)
return t[ k_nt ][ k ]
end
--
-- On assigning a new index.
--
mt.__newindex = function
(
t, -- table getting a new index assigned
k, -- key value to assign to
v -- value to assign
)
if not t[ k_nt ][ k ]
then
error( 'Cannot assign new values to Delays' )
end
t[ k_nt ][ k ] = v
end
--
-- This delay is being blocked by another delay
--
local function blockedBy
(
self, -- this delay
delay -- the blocking delay
)
self[ k_nt ].status = 'block'
if not self[ k_nt ].blocks
then
blocks = { }
self[ k_nt ].blocks = blocks
else
blocks = self[ k_nt ]
end
table.insert( blocks, delay )
end
-- --
-- Creates a new delay. -- Creates a new delay.
-- --
@ -521,32 +586,22 @@ local Delay = ( function
path2 -- used only in moves, path and file-/dirname of path2 -- used only in moves, path and file-/dirname of
-- move destination -- move destination
) )
return { local delay =
etype = etype, {
sync = sync, blockedBy = blockedBy,
alarm = alarm, [ k_nt ] =
path = path, {
path2 = path2, etype = etype,
-- sync = sync,
-- Status of the event. alarm = alarm,
-- Valid stati are: path = path,
-- path2 = path2,
-- 'wait' ... the event is ready to be handled. },
-- }
-- 'active' ... there is process running catering for this event.
-- setmetatable( delay, mt )
-- 'blocked' ... this event waits for another to be handled first.
-- return delay
-- 'done' ... event has been collected. This should never be
-- visible as all references should be droped on
-- collection, nevertheless the seperate status is
-- used as insurrance everything is running correctly.
status = 'wait',
--
-- Position in the queue
--
dpos = -1,
}
end end
-- --
@ -861,7 +916,6 @@ local Combiner = ( function
if d1.etype == 'Move' and d2.etype == 'Move' if d1.etype == 'Move' and d2.etype == 'Move'
then then
-- TODO combine moves, -- TODO combine moves,
if d1.path == d2.path if d1.path == d2.path
or d1.path == d2.path2 or d1.path == d2.path2
or d1.path2 == d2.path or d1.path2 == d2.path
@ -992,7 +1046,10 @@ local InletFactory = ( function
-- --
-- Can be: 'Attrib', 'Create', 'Delete', 'Modify' or 'Move', -- Can be: 'Attrib', 'Create', 'Delete', 'Modify' or 'Move',
-- --
etype = function( event ) etype = function
(
event
)
return e2d[ event ].etype return e2d[ event ].etype
end, end,
@ -1752,8 +1809,8 @@ local Excludes = ( function( )
-- --
-- Cretes a new exclude set. -- Cretes a new exclude set.
-- --
local function new( ) local function new
( )
return { return {
list = { }, list = { },
@ -1822,7 +1879,7 @@ local Sync = ( function
Queue.remove( self.delays, delay.dpos ) Queue.remove( self.delays, delay.dpos )
-- free all delays blocked by this one. -- frees all delays blocked by this one.
if delay.blocks if delay.blocks
then then
for _, vd in pairs( delay.blocks ) for _, vd in pairs( delay.blocks )
@ -1991,14 +2048,7 @@ local Sync = ( function
oldDelay, oldDelay,
newDelay newDelay
) )
newDelay.status = 'block' newDelay:blockedBy( oldDelay )
if not oldDelay.blocks
then
oldDelay.blocks = { }
end
table.insert( oldDelay.blocks, newDelay )
end end
-- --