#ifndef MOJO_CORE_WATCHER_SET_H_
#define MOJO_CORE_WATCHER_SET_H_
#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "mojo/core/handle_signals_state.h"
#include "mojo/core/watcher_dispatcher.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace mojo {
namespace core {
class WatcherSet {
public:
explicit WatcherSet(Dispatcher* owner);
WatcherSet(const WatcherSet&) = delete;
WatcherSet& operator=(const WatcherSet&) = delete;
~WatcherSet();
void NotifyState(const HandleSignalsState& state);
void NotifyClosed();
MojoResult Add(const scoped_refptr<WatcherDispatcher>& watcher,
uintptr_t context,
const HandleSignalsState& current_state);
MojoResult Remove(WatcherDispatcher* watcher, uintptr_t context);
private:
using ContextSet = std::set<uintptr_t>;
struct Entry {
Entry(const scoped_refptr<WatcherDispatcher>& dispatcher);
Entry(const Entry&) = delete;
Entry& operator=(const Entry&) = delete;
Entry(Entry&& other);
~Entry();
Entry& operator=(Entry&& other);
scoped_refptr<WatcherDispatcher> dispatcher;
ContextSet contexts;
};
const raw_ptr<Dispatcher> owner_;
base::flat_map<WatcherDispatcher*, Entry> watchers_;
absl::optional<HandleSignalsState> last_known_state_;
};
}
}
#endif