|
|
|
|
@ -10,32 +10,40 @@ import (
|
|
|
|
|
// over an RPC connection.
|
|
|
|
|
type hook struct {
|
|
|
|
|
client *rpc.Client
|
|
|
|
|
mux *MuxConn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HookServer wraps a packer.Hook implementation and makes it exportable
|
|
|
|
|
// as part of a Golang RPC server.
|
|
|
|
|
type HookServer struct {
|
|
|
|
|
hook packer.Hook
|
|
|
|
|
mux *MuxConn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HookRunArgs struct {
|
|
|
|
|
Name string
|
|
|
|
|
Data interface{}
|
|
|
|
|
RPCAddress string
|
|
|
|
|
Name string
|
|
|
|
|
Data interface{}
|
|
|
|
|
StreamId uint32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Hook(client *rpc.Client) *hook {
|
|
|
|
|
return &hook{client}
|
|
|
|
|
return &hook{client: client}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *hook) Run(name string, ui packer.Ui, comm packer.Communicator, data interface{}) error {
|
|
|
|
|
server := rpc.NewServer()
|
|
|
|
|
RegisterCommunicator(server, comm)
|
|
|
|
|
RegisterUi(server, ui)
|
|
|
|
|
address := serveSingleConn(server)
|
|
|
|
|
nextId := h.mux.NextId()
|
|
|
|
|
server := NewServerWithMux(h.mux, nextId)
|
|
|
|
|
server.RegisterCommunicator(comm)
|
|
|
|
|
server.RegisterUi(ui)
|
|
|
|
|
go server.Serve()
|
|
|
|
|
|
|
|
|
|
args := &HookRunArgs{name, data, address}
|
|
|
|
|
return h.client.Call("Hook.Run", args, new(interface{}))
|
|
|
|
|
args := HookRunArgs{
|
|
|
|
|
Name: name,
|
|
|
|
|
Data: data,
|
|
|
|
|
StreamId: nextId,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h.client.Call("Hook.Run", &args, new(interface{}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *hook) Cancel() {
|
|
|
|
|
@ -46,12 +54,13 @@ func (h *hook) Cancel() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *HookServer) Run(args *HookRunArgs, reply *interface{}) error {
|
|
|
|
|
client, err := rpcDial(args.RPCAddress)
|
|
|
|
|
client, err := NewClientWithMux(h.mux, args.StreamId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
return NewBasicError(err)
|
|
|
|
|
}
|
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
|
|
if err := h.hook.Run(args.Name, &Ui{client: client}, Communicator(client), args.Data); err != nil {
|
|
|
|
|
if err := h.hook.Run(args.Name, client.Ui(), client.Communicator(), args.Data); err != nil {
|
|
|
|
|
return NewBasicError(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|