Esempio n. 1
0
func (p *Plugin) init() {
	// redirect stdout
	stdout := os.Stdout
	os.Stdout = os.Stderr
	pio := common.NewPluginIO(os.Stdin, stdout)
	p.mpx = ipc.NewMultiplex(pio)
}
Esempio n. 2
0
func (pc *PluginClient) Start() error {
	if pc.proc != nil {
		return common.NewPluginError("plugin is already started")
	}

	pc.proc = exec.Command(pc.File)
	stderr, _ := pc.proc.StderrPipe()
	stdin, _ := pc.proc.StdinPipe()
	stdout, _ := pc.proc.StdoutPipe()

	fmt.Printf("Starting plugin %s\n", pc.File)
	err := pc.proc.Start()

	if err != nil {
		return err
	}

	go common.StdErrForward(stderr)

	pio := common.NewPluginIO(stdout, stdin)
	pc.mpx = ipc.NewMultiplex(pio)

	rpcwriter := pc.mpx.RawWriterChannel("rpcw")
	rpcreader := pc.mpx.RawReaderChannel("rpcr")

	pc.RPC = rpc.NewClient(common.NewPluginIO(rpcreader, rpcwriter))

	if !pc.VerifyRPC() {
		return common.NewPluginError("plugin is not a valid plugin or is not responding")
	}

	return nil
}