1 #pragma once
2 
3 #include "MCTPDeviceRepository.hpp"
4 #include "MCTPEndpoint.hpp"
5 #include "Utils.hpp"
6 
7 #include <string>
8 #include <vector>
9 
10 struct AssociationServer
11 {
12     virtual ~AssociationServer() = default;
13 
14     virtual void associate(const std::string& path,
15                            const std::vector<Association>& associations) = 0;
16     virtual void disassociate(const std::string& path) = 0;
17 };
18 
19 class MCTPReactor : public std::enable_shared_from_this<MCTPReactor>
20 {
21     using MCTPDeviceFactory = std::function<std::shared_ptr<MCTPDevice>(
22         const std::string& interface, const std::vector<std::uint8_t>& physaddr,
23         std::optional<std::uint8_t> eid)>;
24 
25   public:
26     MCTPReactor() = delete;
27     MCTPReactor(const MCTPReactor&) = delete;
28     MCTPReactor(MCTPReactor&&) = delete;
MCTPReactor(AssociationServer & server)29     explicit MCTPReactor(AssociationServer& server) : server(server) {}
30     ~MCTPReactor() = default;
31     MCTPReactor& operator=(const MCTPReactor&) = delete;
32     MCTPReactor& operator=(MCTPReactor&&) = delete;
33 
34     void tick();
35 
36     void manageMCTPDevice(const std::string& path,
37                           const std::shared_ptr<MCTPDevice>& device);
38     void unmanageMCTPDevice(const std::string& path);
39 
40   private:
41     static std::optional<std::string> findSMBusInterface(int bus);
42 
43     AssociationServer& server;
44     MCTPDeviceRepository devices;
45 
46     // Tracks MCTP devices that have failed their setup
47     std::set<std::shared_ptr<MCTPDevice>> deferred;
48 
49     void deferSetup(const std::shared_ptr<MCTPDevice>& dev);
50     void setupEndpoint(const std::shared_ptr<MCTPDevice>& dev);
51     void trackEndpoint(const std::shared_ptr<MCTPEndpoint>& ep);
52     void untrackEndpoint(const std::shared_ptr<MCTPEndpoint>& ep);
53 };
54