simplify app design

This commit is contained in:
Darien Raymond
2017-01-06 15:32:36 +01:00
parent 13e4506781
commit b11d48d73f
27 changed files with 286 additions and 283 deletions
+2 -6
View File
@@ -5,7 +5,7 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common/serial"
"v2ray.com/core/common"
"v2ray.com/core/proxy"
)
@@ -60,10 +60,6 @@ func (v OutboundHandlerManagerFactory) Create(space app.Space, config interface{
return New(), nil
}
func (v OutboundHandlerManagerFactory) AppId() app.ID {
return proxyman.APP_ID_OUTBOUND_MANAGER
}
func init() {
app.RegisterApplicationFactory(serial.GetMessageType(new(proxyman.OutboundConfig)), OutboundHandlerManagerFactory{})
common.Must(app.RegisterApplicationFactory((*proxyman.OutboundConfig)(nil), OutboundHandlerManagerFactory{}))
}
+17 -5
View File
@@ -3,14 +3,10 @@ package proxyman
import (
"v2ray.com/core/app"
"v2ray.com/core/common/serial"
"v2ray.com/core/proxy"
)
const (
APP_ID_INBOUND_MANAGER = app.ID(4)
APP_ID_OUTBOUND_MANAGER = app.ID(6)
)
type InboundHandlerManager interface {
GetHandler(tag string) (proxy.InboundHandler, int)
}
@@ -21,3 +17,19 @@ type OutboundHandlerManager interface {
SetDefaultHandler(handler proxy.OutboundHandler) error
SetHandler(tag string, handler proxy.OutboundHandler) error
}
func InboundHandlerManagerFromSpace(space app.Space) InboundHandlerManager {
app := space.(app.AppGetter).GetApp(serial.GetMessageType((*InboundConfig)(nil)))
if app == nil {
return nil
}
return app.(InboundHandlerManager)
}
func OutboundHandlerManagerFromSpace(space app.Space) OutboundHandlerManager {
app := space.(app.AppGetter).GetApp(serial.GetMessageType((*OutboundConfig)(nil)))
if app == nil {
return nil
}
return app.(OutboundHandlerManager)
}