blob: 09ddd5617e2ef68a524e65554b5062b70a646645 [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package bind
import (
"errors"
"android.googlesource.com/platform/tools/gpu/client/shell"
"android.googlesource.com/platform/tools/gpu/framework/device"
)
// Simple is a very short implementation of the Device interface.
// It directly holds the devices Information struct, and it's last known Status, but provides no other active
// functionality. It can be used for fake devices, or as a building block to create a more complete device.
type Simple struct {
To device.Information
LastStatus Status
}
func (b *Simple) String() string {
if b.To.Name == "" {
return b.To.Address
}
return b.To.Name
}
// Info implements the Device interface returning the Information in the To field.
func (b *Simple) Info() *device.Information { return &b.To }
// Status implements the Device interface returning the Status from the LastStatus field.
func (b *Simple) Status() Status { return b.LastStatus }
// Shell implements the Device interface returning commands that will error if run.
func (b *Simple) Shell(name string, args ...string) shell.Cmd {
return shell.Command(name, args...).On(simpleTarget{})
}
// ABI implements the Device interface returning the first ABI from the Information, or UnknownABI if it has none.
func (b *Simple) ABI() device.ABI {
if len(b.To.Configuration.ABIs) <= 0 {
return device.UnknownABI
}
return b.To.Configuration.ABIs[0]
}
type simpleTarget struct{}
func (t simpleTarget) Start(cmd shell.Cmd) (shell.Process, error) {
return nil, errors.New("bind.Simple does not support shell commands")
}