Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Service.hpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright 2016, Ableton AG, Berlin. All rights reserved.
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * If you would like to incorporate Link into a proprietary software application,
  17. * please contact <link-devs@ableton.com>.
  18. */
  19. #pragma once
  20. #include <ableton/discovery/PeerGateways.hpp>
  21. namespace ableton
  22. {
  23. namespace discovery
  24. {
  25. template <typename NodeState, typename GatewayFactory, typename IoContext>
  26. class Service
  27. {
  28. public:
  29. using ServicePeerGateways = PeerGateways<NodeState, GatewayFactory, IoContext>;
  30. Service(NodeState state, GatewayFactory factory, util::Injected<IoContext> io)
  31. : mGateways(
  32. std::chrono::seconds(5), std::move(state), std::move(factory), std::move(io))
  33. {
  34. }
  35. void enable(const bool bEnable)
  36. {
  37. mGateways.enable(bEnable);
  38. }
  39. // Asynchronously operate on the current set of peer gateways. The
  40. // handler will be invoked in the service's io context.
  41. template <typename Handler>
  42. void withGatewaysAsync(Handler handler)
  43. {
  44. mGateways.withGatewaysAsync(std::move(handler));
  45. }
  46. void updateNodeState(const NodeState& state)
  47. {
  48. mGateways.updateNodeState(state);
  49. }
  50. // Repair the gateway with the given address if possible. Its
  51. // sockets may have been closed, for example, and the gateway needs
  52. // to be regenerated.
  53. void repairGateway(const asio::ip::address& gatewayAddr)
  54. {
  55. mGateways.repairGateway(gatewayAddr);
  56. }
  57. private:
  58. ServicePeerGateways mGateways;
  59. };
  60. } // namespace discovery
  61. } // namespace ableton