1676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong/* 2676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Copyright (C) 2017 The Android Open Source Project 3676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * 4676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Licensed under the Apache License, Version 2.0 (the "License"); 5676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * you may not use this file except in compliance with the License. 6676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * You may obtain a copy of the License at 7676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * 8676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * http://www.apache.org/licenses/LICENSE-2.0 9676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * 10676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Unless required by applicable law or agreed to in writing, software 11676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * distributed under the License is distributed on an "AS IS" BASIS, 12676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * See the License for the specific language governing permissions and 14676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * limitations under the License. 15676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong */ 16676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 17676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 18676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#ifndef ANDROID_VINTF_VERSION_H 19676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#define ANDROID_VINTF_VERSION_H 20676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 21676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <stdint.h> 22676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <string> 23676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <utility> 24676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 25676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongnamespace android { 26676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongnamespace vintf { 27676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 28676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstruct Version { 29676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 30676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong constexpr Version() : Version(0u, 0u) {} 31676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong constexpr Version(size_t mj, size_t mi) : majorVer(mj), minorVer(mi) {} 32676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 33676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong size_t majorVer; 34676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong size_t minorVer; 35676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 36676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong inline bool operator==(const Version &other) const { 37676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return majorVer == other.majorVer && minorVer == other.minorVer; 38676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong } 39676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong inline bool operator!=(const Version &other) const { 40676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return !((*this) == other); 41676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong } 42676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong inline bool operator<(const Version &other) const { 43676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong if (majorVer < other.majorVer) 44676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return true; 45676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong if (majorVer > other.majorVer) 46676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return false; 47676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return minorVer < other.minorVer; 48676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong } 49676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong inline bool operator>(const Version &other) const { 50676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return other < (*this); 51676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong } 52676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong inline bool operator<=(const Version &other) const { 53676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return !((*this) > other); 54676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong } 55676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong inline bool operator>=(const Version &other) const { 56676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong return !((*this) < other); 57676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong } 58d48579083ce6d35949444801a9c34e20f4eae254Yifan Hong // Version(2, 1).minorAtLeast(Version(1, 0)) == false 59d48579083ce6d35949444801a9c34e20f4eae254Yifan Hong // Version(2, 1).minorAtLeast(Version(2, 0)) == true 60d48579083ce6d35949444801a9c34e20f4eae254Yifan Hong // Version(2, 1).minorAtLeast(Version(2, 1)) == true 61d48579083ce6d35949444801a9c34e20f4eae254Yifan Hong // Version(2, 1).minorAtLeast(Version(2, 2)) == false 62d48579083ce6d35949444801a9c34e20f4eae254Yifan Hong inline bool minorAtLeast(const Version& other) const { 63d48579083ce6d35949444801a9c34e20f4eae254Yifan Hong return majorVer == other.majorVer && minorVer >= other.minorVer; 64d48579083ce6d35949444801a9c34e20f4eae254Yifan Hong } 65676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong}; 66676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 673f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongstruct KernelVersion { 683f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong 693f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong constexpr KernelVersion() : KernelVersion(0u, 0u, 0u) {} 703f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong constexpr KernelVersion(size_t v, size_t mj, size_t mi) : 713f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong version(v), majorRev(mj), minorRev(mi) {} 723f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong 733f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong size_t version; 743f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong size_t majorRev; 753f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong size_t minorRev; 763f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong 773f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong inline bool operator==(const KernelVersion &other) const { 783f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong return version == other.version 793f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong && majorRev == other.majorRev 803f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong && minorRev == other.minorRev; 813f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong } 823f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong inline bool operator!=(const KernelVersion &other) const { 833f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong return !((*this) == other); 843f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong } 853f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong}; 863f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong 87676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong} // namespace vintf 88676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong} // namespace android 89676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong 90676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#endif // ANDROID_VINTF_VERSION_H 91