|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
pb "FRMS/internal/pkg/grpc"
|
|
|
|
"FRMS/internal/pkg/logging"
|
|
|
|
"FRMS/internal/pkg/manager"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
//"FRMS/internal/pkg/device"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
_ "log"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// manager stuff
|
|
|
|
|
|
|
|
type Manager interface {
|
|
|
|
Start() error // status checks
|
|
|
|
Stop() error
|
|
|
|
Timeout() (time.Duration, error) // TO Generator
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewManager(max int) (Manager, error) {
|
|
|
|
// takes a heartbeat and max connection attempts
|
|
|
|
return manager.New(max)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReactorManager struct {
|
|
|
|
Manager // base manager interface
|
|
|
|
// *ClientManager // client manager (OUTDATED)
|
|
|
|
*Client // access to ID etc
|
|
|
|
// StatusMon *StatusMonitor putting on pause
|
|
|
|
// *ReactorDevices
|
|
|
|
Config *viper.Viper // config to update
|
|
|
|
Err chan error
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewReactorManager(cl *Client,
|
|
|
|
config *viper.Viper,
|
|
|
|
errCh chan error,
|
|
|
|
) (*ReactorManager, error) {
|
|
|
|
// making managers
|
|
|
|
m, err := NewManager(6)
|
|
|
|
r := &ReactorManager{
|
|
|
|
Manager: m,
|
|
|
|
Client: cl,
|
|
|
|
Config: config,
|
|
|
|
Err: errCh,
|
|
|
|
}
|
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReactorManager) Start() error {
|
|
|
|
// allows for extra stuff
|
|
|
|
logging.Debug(logging.DStart, "RMA %v starting", r.Id)
|
|
|
|
return r.Manager.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReactorManager) Exit() error {
|
|
|
|
// allows for extra stuff
|
|
|
|
logging.Debug(logging.DExit, "RMA %v exiting", r.Id)
|
|
|
|
return r.Manager.Exit()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReactorManager) UpdateClient(cl *Client) error {
|
|
|
|
// this is probably unnessecary
|
|
|
|
fmt.Printf("Reactor Manager %d updating client!\n", r.Id)
|
|
|
|
r.Client = cl
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReactorManager) ReactorStatusHandler(ctx context.Context, req *pb.ReactorStatusPing) (*pb.ReactorStatusResponse, error) {
|
|
|
|
// function client will call to update reactor information
|
|
|
|
fmt.Printf("Recieved ping from %d!\n", req.GetId())
|
|
|
|
// update devices/sensors
|
|
|
|
for _, dev := range req.GetDevices() {
|
|
|
|
fmt.Printf("Device %d is %s ", dev.GetAddr(), dev.GetStatus().String())
|
|
|
|
}
|
|
|
|
fmt.Printf("\n")
|
|
|
|
// go r.UpdateDevices(req.GetDevices())
|
|
|
|
|
|
|
|
return &pb.ReactorStatusResponse{Id: int32(r.Id)}, nil
|
|
|
|
}
|