Esempio n. 1
0
func (w WMATADbusInterface) NextTrains(stops []string) ([]map[string]string, *dbus.Error) {
	if len(stops) == 0 {
		return []map[string]string{}, dbus.NewError(
			"org.anized.wmata.Rail.NoStopsGiven",
			[]interface{}{fmt.Errorf("No stops given").Error()},
		)
	}

	log.Printf("Getting info")

	predictions, err := wmata.GetPredictionsByCodes(stops...)
	if err != nil {
		return []map[string]string{}, dbus.NewError(
			"org.anized.wmata.Rail.NotFound",
			[]interface{}{err.Error()},
		)
	}

	log.Printf("Building map")
	ret := []map[string]string{}
	for _, prediction := range predictions {
		ret = append(ret, map[string]string{
			"cars":             prediction.Cars,
			"group":            prediction.Group,
			"line":             prediction.Line.Code,
			"minutes":          prediction.Minutes,
			"desitnation":      prediction.Destination,
			"desitnation_name": prediction.DesitnationName,
			"desitnation_code": prediction.DesitnationCode,
			"location_name":    prediction.LocationName,
			"location_code":    prediction.LocationCode,
		})
	}
	return ret, nil
}
Esempio n. 2
0
func (a *AllJoynBridge) AddService(dbusService, dbusPath, allJoynService string) (string, *dbus.Error) {

	// TODO: make sure uuid is really unique and not present in a.services
	uuid, err := newUUID()
	if err != nil {
		log.Printf("Error: %v", err)
		return "", dbus.NewError("com.devicehive.Error", []interface{}{err.Error})
	}

	// go func() {

	var bindings []*AllJoynBindingInfo

	var dbusServiceId string
	err = a.bus.BusObject().Call("org.freedesktop.DBus.GetNameOwner", 0, dbusService).Store(&dbusServiceId)
	if err != nil {
		return "", dbus.NewError("com.devicehive.Error", []interface{}{err.Error})
	}

	log.Printf("Traversing objects tree for %s (%s [%s] at %s)", uuid, dbusService, dbusServiceId, dbusPath)

	traverseDbusObjects(a.bus, dbusServiceId, dbusPath, func(path string, node *introspect.Node) {
		allJoynPath := strings.TrimPrefix(path, dbusPath)
		bindings = append(bindings, &AllJoynBindingInfo{allJoynPath, path, node})
		log.Printf("Found Object: %s with %d interfaces", allJoynPath, len(node.Interfaces))
	})

	a.services[uuid] = &AllJoynServiceInfo{allJoynService, dbusServiceId, dbusService, bindings}

	log.Printf("Added %s service with %d AJ objects", allJoynService, len(bindings))

	go a.startAllJoyn(uuid)

	return uuid, nil
}
Esempio n. 3
0
func (b *Bus) TrackPosition() (float64, float64, *dbus.Error) {
	time, err := b.player.GetTrackPosition(false)
	if err != nil {
		return 0, 0, dbus.NewError("io.github.ghedo.grooved.Error",
			[]interface{}{err.Error()})
	}

	percent, err := b.player.GetTrackPosition(true)
	if err != nil {
		return 0, 0, dbus.NewError("io.github.ghedo.grooved.Error",
			[]interface{}{err.Error()})
	}

	return time, percent, nil
}
func (a *AllJoynBridge) AddService(dbusService, dbusPath, alljoynService string, sender dbus.Sender) (string, *dbus.Error) {
	// generate unique UUID
	var uuid string
	var err error
	for {
		uuid, err = newUUID()
		if err != nil {
			log.Printf("Error: %v", err)
			return "", dbus.NewError("com.devicehive.Error", []interface{}{err.Error})
		}

		if _, exists := a.services[uuid]; !exists {
			break // UUID is unique, done
		}

		// otherwise generate new one at next iteration...
	}

	// a.addService(uuid, string(sender), dbusService, dbusPath, alljoynService)
	async := exec.Command(os.Args[0],
		"--spawn-uuid", uuid,
		"--spawn-dbus-service-id", string(sender),
		"--spawn-dbus-service", dbusService,
		"--spawn-dbus-path", dbusPath,
		"--spawn-alljoyn-service", alljoynService)
	async.Stdout = os.Stdout
	async.Stderr = os.Stderr
	async.Start()
	// TODO: add 'async' to the list for management purposes

	return uuid, nil
}
Esempio n. 5
0
func SetVolume(c *prop.Change) *dbus.Error {
	err := bus.player.SetProperty("volume", c.Value)
	if err != nil {
		return dbus.NewError("io.github.ghedo.grooved.Error",
			[]interface{}{err.Error()})
	}

	return nil
}
Esempio n. 6
0
func (b *Bus) Quit() *dbus.Error {
	err := b.player.Quit()
	if err != nil {
		return dbus.NewError("io.github.ghedo.grooved.Error",
			[]interface{}{err.Error()})
	}

	return nil
}
Esempio n. 7
0
func (b *Bus) RemoveTrack(index int64) *dbus.Error {
	err := b.player.RemoveTrack(int64(index))
	if err != nil {
		return dbus.NewError("io.github.ghedo.grooved.Error",
			[]interface{}{err.Error()})
	}

	return nil
}
Esempio n. 8
0
func (b *Bus) AddList(path string) *dbus.Error {
	err := b.player.AddList(path)
	if err != nil {
		return dbus.NewError("io.github.ghedo.grooved.Error",
			[]interface{}{err.Error()})
	}

	return nil
}
Esempio n. 9
0
func (b *Bus) Seek(seconds int64) *dbus.Error {
	err := b.player.Seek(seconds)
	if err != nil {
		return dbus.NewError("io.github.ghedo.grooved.Error",
			[]interface{}{err.Error()})
	}

	return nil
}
Esempio n. 10
0
func (w WMATADbusInterface) NextLocalTrains() ([]map[string]string, *dbus.Error) {
	ssids, err := GetVisibleNetworks()
	if err != nil {
		return []map[string]string{}, dbus.NewError(
			"org.anized.wmata.Rail.NetworkError",
			[]interface{}{err.Error()},
		)
	}

	stops := []string{}
	for _, ssid := range ssids {
		if wifiStops, ok := wifiMetroMap[ssid]; ok {
			stops = append(stops, wifiStops...)
		}
	}

	if len(stops) == 0 {
		return []map[string]string{}, nil
	}

	return w.NextTrains(stops)
}
Esempio n. 11
0
// EmitType controls how org.freedesktop.DBus.Properties.PropertiesChanged is
// emitted for a property. If it is EmitTrue, the signal is emitted. If it is
// EmitInvalidates, the signal is also emitted, but the new value of the property
// is not disclosed.
type EmitType byte

const (
	EmitFalse EmitType = iota
	EmitTrue
	EmitInvalidates
)

// ErrIfaceNotFound is the error returned to peers who try to access properties
// on interfaces that aren't found.
var ErrIfaceNotFound = dbus.NewError("org.freedesktop.DBus.Properties.Error.InterfaceNotFound", nil)

// ErrPropNotFound is the error returned to peers trying to access properties
// that aren't found.
var ErrPropNotFound = dbus.NewError("org.freedesktop.DBus.Properties.Error.PropertyNotFound", nil)

// ErrReadOnly is the error returned to peers trying to set a read-only
// property.
var ErrReadOnly = dbus.NewError("org.freedesktop.DBus.Properties.Error.ReadOnly", nil)

// ErrInvalidArg is returned to peers if the type of the property that is being
// changed and the argument don't match.
var ErrInvalidArg = dbus.NewError("org.freedesktop.DBus.Properties.Error.InvalidArg", nil)

// The introspection data for the org.freedesktop.DBus.Properties interface.
var IntrospectData = introspect.Interface{
func newDHError(message string) *dbus.Error {
	return dbus.NewError("com.devicehive.Error",
		[]interface{}{message})
}
Esempio n. 13
0
// NewError creates a dbus error.
//
func NewError(msg string) *dbus.Error {
	return dbus.NewError("org.freedesktop.DBus.Error.Failed", []interface{}{msg})
}
Esempio n. 14
0
func newError(name string, body ...interface{}) *dbus.Error {
	return dbus.NewError(name, body)
}