| // 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 device |
| |
| var ( |
| UnknownHardware = product("unknown", "unknown", UnknownChipset) |
| |
| productsByCodename = map[string]Hardware{} |
| productsByName = map[string]Hardware{} |
| ) |
| |
| func product(codename string, name string, chipset Chipset) Hardware { |
| product := Hardware{ |
| Name: name, |
| Chipset: chipset, |
| } |
| productsByCodename[codename] = product |
| productsByName[name] = product |
| return product |
| } |
| |
| // HardwareByName looks up a hardware description by product name. |
| // If the product is not known, then a hardware object with no cores an an UnknownGPU will be returned. |
| func HardwareByName(name string) Hardware { |
| h, ok := productsByCodename[name] |
| if !ok { |
| h, ok = productsByName[name] |
| } |
| if !ok { |
| h = Hardware{ |
| Name: name, |
| Chipset: UnknownChipset, |
| } |
| } |
| return h |
| } |
| |
| // SameHardware returns true if the two hardware objects are a match. |
| func SameHardware(a, b Hardware) bool { |
| // If the product name is set, treat it as an authoratitive comparison point |
| if a.Name != "" && b.Name != "" { |
| return a.Name == b.Name |
| } |
| return SameChipset(a.Chipset, b.Chipset) |
| } |