blob: 936cd2fa0cd13275be4ff46a03f0a030157832a8 [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 Sivakumar9d17e4a2015-02-02 22:42:16 -080027 flags.SetDefaultProtocol("tcp")
28 flags.SetDefaultHostPort("127.0.0.1:0")
29 commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime, flags.Listen)
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080030}
31
Matt Rosencrantzba470a52015-01-26 13:36:13 -080032func Init(ctx *context.T) (veyron2.Runtime, *context.T, veyron2.Shutdown, error) {
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080033 if err := internal.ParseFlags(commonFlags); err != nil {
34 return nil, nil, nil, err
35 }
36
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080037 ac := appcycle.New()
38
Suharsh Sivakumar9d17e4a2015-02-02 22:42:16 -080039 lf := commonFlags.ListenFlags()
40 listenSpec := ipc.ListenSpec{
41 Addrs: ipc.ListenAddrs(lf.Addrs),
42 AddressChooser: internal.IPAddressChooser,
43 Proxy: lf.ListenProxy,
44 }
45
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080046 runtime, ctx, shutdown, err := grt.Init(ctx,
47 ac,
48 nil,
Suharsh Sivakumar9d17e4a2015-02-02 22:42:16 -080049 &listenSpec,
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080050 commonFlags.RuntimeFlags(),
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080051 nil)
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080052 if err != nil {
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080053 return nil, nil, nil, err
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080054 }
Suharsh Sivakumard68949c2015-01-26 10:32:23 -080055 vlog.Log.VI(1).Infof("Initializing generic profile.")
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080056
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080057 profileShutdown := func() {
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080058 ac.Shutdown()
Suharsh Sivakumard5049b72015-01-21 14:11:35 -080059 shutdown()
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080060 }
Matt Rosencrantzaeed5d52015-01-14 15:18:34 -080061 return runtime, ctx, profileShutdown, nil
Suharsh Sivakumar628a8ee2015-01-14 11:38:56 -080062}