105 lines
1.9 KiB
Go
105 lines
1.9 KiB
Go
package core
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"github.com/sirupsen/logrus"
|
|
"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) {
|
|
logrus.Debug("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 {
|
|
logrus.Println("trackingservice: wrong mode of operation")
|
|
}
|
|
t.current.TimeCreated = time.Now()
|
|
t.pipe.Record()
|
|
}
|
|
|
|
func (t *trackingService) StopRecord() {
|
|
if t.opMode != LIVE {
|
|
logrus.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 {
|
|
logrus.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) {
|
|
|
|
}
|