static_nanoapps.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2017 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. // If the CHRE build variant wants to supply its own static nanoapps, include
  17. // chre/platform/static_nanoapp_init.h in the nanoapp to include and define
  18. // CHRE_STATIC_NANOAPP_INIT with the appropriate parameters (see examples under
  19. // chre/apps/). Then, define the UniquePtr created by CHRE_STATIC_NANOAPP_INIT
  20. // similar to chre/apps/apps.h and add that variable to kStaticNanoappList
  21. // below.
  22. #ifdef CHRE_INCLUDE_DEFAULT_STATIC_NANOAPPS
  23. #include "chre/apps/apps.h"
  24. #endif // CHRE_INCLUDE_DEFAULT_STATIC_NANOAPPS
  25. #include "chre/core/event_loop_manager.h"
  26. #include "chre/core/static_nanoapps.h"
  27. #include "chre/util/macros.h"
  28. namespace chre {
  29. // The CHRE build variant can supply this macro to override the default list of
  30. // static nanoapps. Most production variants will supply this macro as these
  31. // nanoapps are mostly intended for testing and evaluation purposes. This list
  32. // is supplied empty to ensure that the symbol is avilable for platforms with
  33. // no static nanoapps.
  34. #ifndef CHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST
  35. //! The default list of static nanoapps to load.
  36. const StaticNanoappInitFunction kStaticNanoappList[] = {};
  37. //! The size of the default static nanoapp list.
  38. const size_t kStaticNanoappCount = ARRAY_SIZE(kStaticNanoappList);
  39. #endif // CHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST
  40. void loadStaticNanoapps() {
  41. // Compare with zero to allow the compiler to optimize away the loop.
  42. // Tautological comparisons are not warnings when comparing a const with
  43. // another const.
  44. if (kStaticNanoappCount > 0) {
  45. // Cast the kStaticNanoappCount to size_t to avoid tautological comparison
  46. // warnings when the kStaticNanoappCount is zero.
  47. for (size_t i = 0; i < reinterpret_cast<size_t>(kStaticNanoappCount); i++) {
  48. UniquePtr<Nanoapp> nanoapp = kStaticNanoappList[i]();
  49. EventLoopManagerSingleton::get()->getEventLoop().startNanoapp(nanoapp);
  50. }
  51. }
  52. }
  53. } // namespace chre