blob: b071c3123410a11e008b70176922565256d021f8 [file] [log] [blame]
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -08001package profiles
2
3import (
Suharsh Sivakumard68949c2015-01-26 10:32:23 -08004 "flag"
5
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -08006 "v.io/core/veyron2"
7 "v.io/core/veyron2/context"
Suharsh Sivakumard5049b72015-01-21 14:11:35 -08008 "v.io/core/veyron2/ipc"
Nicolas LaCasse0a22b452015-01-22 09:57:15 -08009 "v.io/core/veyron2/ipc/stream"
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080010 "v.io/core/veyron2/vlog"
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080011
12 "v.io/core/veyron/lib/appcycle"
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080013 "v.io/core/veyron/lib/flags"
Nicolas LaCasse0a22b452015-01-22 09:57:15 -080014 "v.io/core/veyron/lib/websocket"
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080015 "v.io/core/veyron/profiles/internal"
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080016 _ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
17 _ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
18 _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
19 grt "v.io/core/veyron/runtimes/google/rt"
20)
21
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080022var commonFlags *flags.Flags
23
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080024func init() {
25 veyron2.RegisterProfileInit(Init)
Nicolas LaCasse0a22b452015-01-22 09:57:15 -080026 stream.RegisterUnknownProtocol("wsh", websocket.HybridDial, websocket.HybridListener)
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080027 commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime)
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080028}
29
Matt Rosencrantzba470a52015-01-26 13:36:13 -080030func Init(ctx *context.T) (veyron2.Runtime, *context.T, veyron2.Shutdown, error) {
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080031 if err := internal.ParseFlags(commonFlags); err != nil {
32 return nil, nil, nil, err
33 }
34
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080035 ac := appcycle.New()
36
37 runtime, ctx, shutdown, err := grt.Init(ctx,
38 ac,
39 nil,
40 &ipc.ListenSpec{
41 Addrs: ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}},
42 AddressChooser: internal.IPAddressChooser,
43 },
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080044 commonFlags.RuntimeFlags(),
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080045 nil)
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080046 if err != nil {
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080047 return nil, nil, nil, err
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080048 }
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080049 vlog.Log.VI(1).Infof("Initializing generic profile.")
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080050
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080051 profileShutdown := func() {
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080052 ac.Shutdown()
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080053 shutdown()
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080054 }
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080055 return runtime, ctx, profileShutdown, nil
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080056}