gyrogpsc/core/service.go

108 lines
2.1 KiB
Go

package core
import (
"github.com/google/uuid"
"log"
"time"
)
type OpMode uint8
const (
STOPPED OpMode = iota
LIVE
REPLAY
)
type trackingService struct {
current *Tracking
config *Configuration
pipe *pipeline
repo Repo
opMode OpMode
collectors []Collector
}
func TrackingService(r Repo, d Publisher, c *Configuration) *trackingService {
t := &Tracking{}
return &trackingService{
current: t,
opMode: STOPPED,
config: c,
repo: r,
pipe: NewPipeline(d, t, c),
collectors: nil,
}
}
func (t *trackingService) AllTrackings() {
panic("implement me")
}
func (t *trackingService) NewTracking(cols ...CollectorType) {
log.Println("new tracking:", cols)
t.opMode = LIVE
t.collectors = nil
for _, col := range cols {
t.collectors = append(t.collectors, NewCollector(col, t.pipe, t.config))
}
*t.current = emptyTracking()
t.current.collectors = cols
for _, e := range t.collectors {
e.Collect()
}
t.pipe.Run()
}
func (t *trackingService) StartRecord() {
if t.opMode != LIVE {
log.Println("trackingservice: wrong mode of operation")
}
t.current.TimeCreated = time.Now()
t.pipe.Record()
}
func (t *trackingService) StopRecord() {
if t.opMode != LIVE {
log.Println("trackingservice: wrong mode of operation")
}
t.pipe.Stop()
for _, e := range t.collectors {
e.Stop()
}
err := t.repo.Save(*t.current)
if err != nil {
log.Println(err)
}
t.NewTracking(t.current.collectors...)
}
func (t *trackingService) Reset() {
t.opMode = STOPPED
t.collectors = nil
}
func (t *trackingService) DeleteTracking(trackingId uuid.UUID) {
panic("implement me")
}
func (t *trackingService) StartReplay() {
panic("implement me")
}
func (t *trackingService) PauseReplay() {
panic("implement me")
}
func (t *trackingService) StopReplay() {
panic("implement me")
}
func (t *trackingService) LoadTracking(trackingId uuid.UUID) {
}