Skip to content

Commit 6155307

Browse files
authored
Merge pull request #995 from leapmotion/feature-signalhandlerquery
Add a way to determine whether a signal has listeners
2 parents 481deb7 + 082bfa5 commit 6155307

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/autowiring/signal.h

+3
Original file line numberDiff line numberDiff line change
@@ -594,5 +594,8 @@ namespace autowiring {
594594
// template format of the earlier function call overload, overload resolution will never
595595
// select this variant.
596596
//void operator()(Args... args) const;
597+
598+
bool has_listeners(void) const { return m_pFirstListener != nullptr; }
599+
operator bool() const { return has_listeners(); }
597600
};
598601
}

src/autowiring/test/AutoSignalTest.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,12 @@ TEST_F(AutoSignalTest, MoveInInvoke) {
819819
ASSERT_NE(nullptr, vRecovered);
820820
ASSERT_EQ(404, *vRecovered) << "Recovered unique pointer was not the expected value";
821821
}
822+
823+
TEST_F(AutoSignalTest, ListenerCheck) {
824+
autowiring::signal<void()> s;
825+
ASSERT_FALSE(s) << "Signal did not correctly report it had no listeners";
826+
registration_t reg = s += [] {};
827+
ASSERT_TRUE(s) << "Signal stated that it had no listeners when it should have had at least one";
828+
s -= reg;
829+
ASSERT_FALSE(s) << "Signal believed it still had listeners even after they were all unregistered";
830+
}

0 commit comments

Comments
 (0)