forked from MTSR/mapserver
parsed mapblock listener
This commit is contained in:
parent
11ebd96b9b
commit
9f9e50329c
@ -12,6 +12,11 @@ import (
|
||||
type MapBlockAccessor struct {
|
||||
accessor db.DBAccessor
|
||||
c *cache.Cache
|
||||
listeners []MapBlockListener
|
||||
}
|
||||
|
||||
type MapBlockListener interface {
|
||||
OnParsedMapBlock(block *mapblockparser.MapBlock)
|
||||
}
|
||||
|
||||
func getKey(pos coords.MapBlockCoords) string {
|
||||
@ -24,6 +29,10 @@ func NewMapBlockAccessor(accessor db.DBAccessor) *MapBlockAccessor {
|
||||
return &MapBlockAccessor{accessor: accessor, c: c}
|
||||
}
|
||||
|
||||
func (a *MapBlockAccessor) AddListener(l MapBlockListener) {
|
||||
a.listeners = append(a.listeners, l)
|
||||
}
|
||||
|
||||
func (a *MapBlockAccessor) Update(pos coords.MapBlockCoords, mb *mapblockparser.MapBlock) {
|
||||
key := getKey(pos)
|
||||
a.c.Set(key, mb, cache.DefaultExpiration)
|
||||
@ -46,6 +55,10 @@ func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*map
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, listener := range(a.listeners) {
|
||||
listener.OnParsedMapBlock(mapblock)
|
||||
}
|
||||
|
||||
a.c.Set(key, mapblock, cache.DefaultExpiration)
|
||||
mblist = append(mblist, mapblock)
|
||||
}
|
||||
@ -75,6 +88,10 @@ func (a *MapBlockAccessor) GetMapBlock(pos coords.MapBlockCoords) (*mapblockpars
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, listener := range(a.listeners) {
|
||||
listener.OnParsedMapBlock(mapblock)
|
||||
}
|
||||
|
||||
a.c.Set(key, mapblock, cache.DefaultExpiration)
|
||||
|
||||
return mapblock, nil
|
||||
|
Loading…
Reference in New Issue
Block a user