init.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) 2020-2022 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_IMPL_INIT_H
  19. #define RTC_IMPL_INIT_H
  20. #include "common.hpp"
  21. #include "global.hpp" // for SctpSettings
  22. #include <chrono>
  23. #include <future>
  24. #include <mutex>
  25. namespace rtc::impl {
  26. using init_token = shared_ptr<void>;
  27. class Init {
  28. public:
  29. static Init &Instance();
  30. Init(const Init &) = delete;
  31. Init &operator=(const Init &) = delete;
  32. Init(Init &&) = delete;
  33. Init &operator=(Init &&) = delete;
  34. init_token token();
  35. void preload();
  36. std::shared_future<void> cleanup();
  37. void setSctpSettings(SctpSettings s);
  38. private:
  39. Init();
  40. ~Init();
  41. void doInit();
  42. void doCleanup();
  43. std::optional<shared_ptr<void>> mGlobal;
  44. weak_ptr<void> mWeak;
  45. bool mInitialized = false;
  46. SctpSettings mCurrentSctpSettings = {};
  47. std::mutex mMutex;
  48. std::shared_future<void> mCleanupFuture;
  49. struct TokenPayload;
  50. };
  51. } // namespace rtc::impl
  52. #endif