/
cameraClient.go
60 lines (50 loc) · 1.18 KB
/
cameraClient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"github.com/koestler/go-webcam/cameraClient"
"github.com/koestler/go-webcam/config"
"github.com/pkg/errors"
"log"
)
func runCameraClient(
cfg *config.Config,
initiateShutdown chan<- error,
) *cameraClient.ClientPool {
cameraClientPoolInstance := cameraClient.RunPool()
countStarted := 0
for _, camera := range cfg.Cameras() {
if cfg.LogWorkerStart() {
log.Printf(
"cameraClient[%s]: start: address='%s'",
camera.Name(),
camera.Address(),
)
}
cameraConfig := cameraClientConfig{
CameraConfig: *camera,
logDebug: cfg.LogDebug(),
}
if client, err := cameraClient.RunClient(&cameraConfig); err != nil {
log.Printf("cameraClient[%s]: start failed: %s", camera.Name(), err)
} else {
cameraClientPoolInstance.AddClient(client)
countStarted += 1
if cfg.LogWorkerStart() {
log.Printf(
"cameraClient[%s]: started",
camera.Name(),
)
}
}
}
if countStarted < 1 {
initiateShutdown <- errors.New("no cameraClient was started")
}
return cameraClientPoolInstance
}
type cameraClientConfig struct {
config.CameraConfig
logDebug bool
}
func (cc *cameraClientConfig) LogDebug() bool {
return cc.logDebug
}