-
Notifications
You must be signed in to change notification settings - Fork 10
/
api_accept.go
35 lines (29 loc) · 977 Bytes
/
api_accept.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
package bifrost_api
import (
stream_api "github.com/aperturerobotics/bifrost/stream/api"
stream_api_accept "github.com/aperturerobotics/bifrost/stream/api/accept"
"github.com/aperturerobotics/controllerbus/controller/loader"
"github.com/aperturerobotics/controllerbus/controller/resolver"
)
// AcceptStream accepts an incoming stream.
// Stream data is sent over the request / response streams.
func (a *API) AcceptStream(serv stream_api.SRPCStreamService_AcceptStreamStream) error {
ctx := serv.Context()
msg, err := serv.Recv()
if err != nil {
return err
}
conf := msg.GetConfig()
if err := conf.Validate(); err != nil {
return err
}
dir := resolver.NewLoadControllerWithConfig(conf)
// wait until it's ready
val, _, valRef, err := loader.WaitExecControllerRunning(ctx, a.bus, dir, nil)
if err != nil {
return err
}
defer valRef.Release()
ctrl := val.(*stream_api_accept.Controller)
return ctrl.AttachRPC(stream_api.NewAcceptServerRPC(serv))
}