2013-05-03 18:49:15 -04:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"net/rpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
// An implementation of packer.Ui where the Ui is actually executed
|
|
|
|
// over an RPC connection.
|
|
|
|
type Ui struct {
|
|
|
|
client *rpc.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// UiServer wraps a packer.Ui implementation and makes it exportable
|
|
|
|
// as part of a Golang RPC server.
|
|
|
|
type UiServer struct {
|
|
|
|
ui packer.Ui
|
|
|
|
}
|
|
|
|
|
2013-06-15 21:24:38 -04:00
|
|
|
func (u *Ui) Ask(query string) (result string, err error) {
|
|
|
|
err = u.client.Call("Ui.Ask", query, &result)
|
|
|
|
return
|
2013-06-14 18:17:03 -04:00
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *Ui) Error(message string) {
|
|
|
|
if err := u.client.Call("Ui.Error", message, new(interface{})); err != nil {
|
2013-05-21 14:58:14 -04:00
|
|
|
panic(err)
|
|
|
|
}
|
2013-05-08 18:12:48 -04:00
|
|
|
}
|
|
|
|
|
2013-06-03 14:30:38 -04:00
|
|
|
func (u *Ui) Message(message string) {
|
|
|
|
if err := u.client.Call("Ui.Message", message, new(interface{})); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *Ui) Say(message string) {
|
|
|
|
if err := u.client.Call("Ui.Say", message, new(interface{})); err != nil {
|
2013-05-21 14:58:14 -04:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 21:24:38 -04:00
|
|
|
func (u *UiServer) Ask(query string, reply *string) (err error) {
|
|
|
|
*reply, err = u.ui.Ask(query)
|
|
|
|
return
|
2013-06-14 18:17:03 -04:00
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *UiServer) Error(message *string, reply *interface{}) error {
|
|
|
|
u.ui.Error(*message)
|
2013-05-08 18:12:48 -04:00
|
|
|
|
|
|
|
*reply = nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-06-03 14:30:38 -04:00
|
|
|
func (u *UiServer) Message(message *string, reply *interface{}) error {
|
|
|
|
u.ui.Message(*message)
|
|
|
|
*reply = nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *UiServer) Say(message *string, reply *interface{}) error {
|
|
|
|
u.ui.Say(*message)
|
2013-05-03 18:49:15 -04:00
|
|
|
|
|
|
|
*reply = nil
|
|
|
|
return nil
|
|
|
|
}
|