VintfObjectAfterUpdate.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <memory>
  18. #include "SchemaType.h"
  19. #include "VintfObject.h"
  20. namespace android {
  21. namespace vintf {
  22. namespace details {
  23. /**
  24. * Simulate the state of VintfObject after an update.
  25. *
  26. * - Old metadata is stored in parent VintfObject.
  27. * - New (updated) metadata is stored in this VintfObjectAfterUpdate
  28. * - Dependencies are from the given VintfObject (dep) before construction.
  29. */
  30. class VintfObjectAfterUpdate : public VintfObject {
  31. public:
  32. /* Use dependencies from the object dep. */
  33. VintfObjectAfterUpdate(VintfObject* dep) : mDependency(dep) {}
  34. std::shared_ptr<const HalManifest> getDeviceHalManifest(bool skipCache = false) override {
  35. if (mDeviceManifest != nullptr) return mDeviceManifest;
  36. return VintfObject::getDeviceHalManifest(skipCache);
  37. }
  38. std::shared_ptr<const HalManifest> getFrameworkHalManifest(bool skipCache = false) override {
  39. if (mFrameworkManifest != nullptr) return mFrameworkManifest;
  40. return VintfObject::getFrameworkHalManifest(skipCache);
  41. }
  42. std::shared_ptr<const CompatibilityMatrix> getDeviceCompatibilityMatrix(
  43. bool skipCache = false) override {
  44. if (mDeviceMatrix != nullptr) return mDeviceMatrix;
  45. return VintfObject::getDeviceCompatibilityMatrix(skipCache);
  46. }
  47. std::shared_ptr<const CompatibilityMatrix> getFrameworkCompatibilityMatrix(
  48. bool skipCache = false) override {
  49. if (mFrameworkMatrix != nullptr) return mFrameworkMatrix;
  50. return VintfObject::getFrameworkCompatibilityMatrix(skipCache);
  51. }
  52. const std::unique_ptr<FileSystem>& getFileSystem() override {
  53. return mDependency->getFileSystem();
  54. }
  55. const std::unique_ptr<PropertyFetcher>& getPropertyFetcher() override {
  56. return mDependency->getPropertyFetcher();
  57. }
  58. const std::unique_ptr<ObjectFactory<RuntimeInfo>>& getRuntimeInfoFactory() override {
  59. return mDependency->getRuntimeInfoFactory();
  60. }
  61. bool set(const std::shared_ptr<HalManifest>& o) {
  62. return set(o, &mDeviceManifest, &mFrameworkManifest);
  63. }
  64. bool set(const std::shared_ptr<CompatibilityMatrix>& o) {
  65. return set(o, &mDeviceMatrix, &mFrameworkMatrix);
  66. }
  67. private:
  68. VintfObject* mDependency = nullptr;
  69. std::shared_ptr<HalManifest> mDeviceManifest;
  70. std::shared_ptr<HalManifest> mFrameworkManifest;
  71. std::shared_ptr<CompatibilityMatrix> mDeviceMatrix;
  72. std::shared_ptr<CompatibilityMatrix> mFrameworkMatrix;
  73. template <typename T>
  74. bool set(const std::shared_ptr<T>& o, std::shared_ptr<T>* dev, std::shared_ptr<T>* fwk) {
  75. if (o->type() == SchemaType::DEVICE) {
  76. if (*dev != nullptr) return false;
  77. *dev = o;
  78. return true;
  79. } else if (o->type() == SchemaType::FRAMEWORK) {
  80. if (*fwk != nullptr) return false;
  81. *fwk = o;
  82. return true;
  83. }
  84. return false;
  85. }
  86. };
  87. } // namespace details
  88. } // namespace vintf
  89. } // namespace android