43 lines
812 B
Go
43 lines
812 B
Go
package daemon
|
|
|
|
import (
|
|
"src.dualinventive.com/go/devsim/repository"
|
|
"src.dualinventive.com/go/devsim/simulator"
|
|
)
|
|
|
|
// TemplateTracker tracks template usage
|
|
type TemplateTracker struct {
|
|
template repository.Template
|
|
usage int
|
|
}
|
|
|
|
// Increment template use
|
|
func (t *TemplateTracker) Increment() {
|
|
t.usage++
|
|
if t.usage == 1 {
|
|
// TODO make it concurent safe and maybe in go routine?
|
|
// nolint
|
|
_ = t.template.Create()
|
|
}
|
|
}
|
|
|
|
// Decrement template use
|
|
func (t *TemplateTracker) Decrement() {
|
|
t.usage--
|
|
if t.usage == 0 {
|
|
// TODO make it concurent safe and maybe in go routine?
|
|
// nolint
|
|
_ = t.template.Destroy()
|
|
}
|
|
}
|
|
|
|
// Usage of template
|
|
func (t *TemplateTracker) Usage() int {
|
|
return t.usage
|
|
}
|
|
|
|
// Info of TemplateTracker
|
|
func (t *TemplateTracker) Info() simulator.Info {
|
|
return t.template
|
|
}
|