Пример #1
0
func (o *OutputStreamer) Connect(ports []fwk.Port) error {
	var err error

	o.ports = make([]fwk.Port, len(ports))
	copy(o.ports, ports)

	// FIXME(sbinet): handle local/remote files, protocols
	o.w, err = os.Create(o.Name)
	if err != nil {
		return err
	}

	o.rio, err = rio.NewWriter(o.w)
	if err != nil {
		return err
	}

	for _, port := range o.ports {
		rec := o.rio.Record(port.Name)
		err = rec.Connect(port.Name, reflect.New(port.Type))
		if err != nil {
			return err
		}
		o.recs = append(o.recs, rec)
	}

	return err
}
Пример #2
0
func (svc *hsvc) StartSvc(ctx fwk.Context) error {
	var err error

	for name, stream := range svc.streams {
		switch stream.Mode {
		case Read:
			_, dup := svc.r[name]
			if dup {
				return fwk.Errorf("%s: duplicate read-stream %q", svc.Name(), name)
			}
			// FIXME(sbinet): handle remote/local files + protocols
			f, err := os.Open(stream.Name)
			if err != nil {
				return fwk.Errorf("error opening file [%s]: %v", stream.Name, err)
			}
			r, err := rio.NewReader(f)
			if err != nil {
				return fwk.Errorf("error opening rio-stream [%s]: %v", stream.Name, err)
			}

			svc.r[name] = istream{
				name:  name,
				fname: stream.Name,
				f:     f,
				r:     r,
			}

		case Write:
			_, dup := svc.w[name]
			if dup {
				return fwk.Errorf("%s: duplicate write-stream %q", svc.Name(), name)
			}
			// FIXME(sbinet): handle remote/local files + protocols
			f, err := os.Create(stream.Name)
			if err != nil {
				return fwk.Errorf("error creating file [%s]: %v", stream.Name, err)
			}
			w, err := rio.NewWriter(f)
			if err != nil {
				return fwk.Errorf("error creating rio-stream [%s]: %v", stream.Name, err)
			}

			svc.w[name] = ostream{
				name:  name,
				fname: stream.Name,
				f:     f,
				w:     w,
			}

		default:
			return fwk.Errorf("%s: invalid stream mode (%d)", svc.Name(), stream.Mode)
		}
	}
	return err
}