blob: 4d1533c58908ae7842809f3cfd81ca220e995b77 [file] [log] [blame]
/*
* Copyright 2014 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_BASE_GENERICSLOT_H_
#define WEBRTC_BASE_GENERICSLOT_H_
// To generate genericslot.h from genericslot.h.pump, execute:
// /home/build/google3/third_party/gtest/scripts/pump.py genericslot.h.pump
// Generic-slots are pure slots that can be hooked up to signals. They're
// mainly intended to be used in tests where we want to check if a signal
// was invoked and what arguments were passed. NOTE: They do not do any
// lifetime management of the arguments received via callbacks.
//
// Example:
// /* Some signal */
// sigslot::signal1<int> foo;
//
// /* We want to monitor foo in some test */
// rtc::GenericSlot1<int> slot(&foo, 0);
// foo.emit(5);
// EXPECT_TRUE(slot.callback_received());
// EXPECT_EQ(5, *(slot.arg1()));
//
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/sigslot.h"
namespace rtc {
$var n = 5
$range i 1..n
$for i [[
$range j 1..i
template <$for j , [[class A$j]]>
class GenericSlot$i : public sigslot::has_slots<> {
public:
GenericSlot$i(sigslot::signal$i<$for j , [[A$j]]>* signal,
$for j , [[const A$j& arg$j[[]]_initial]])
: $for j , [[arg$j[[]]_initial_(arg$j[[]]_initial)]] {
Reset();
signal->connect(this, &GenericSlot$i::OnSignalCallback);
}
void Reset() {
callback_received_ = false;$for j [[
arg$j[[]]_ = arg$j[[]]_initial_; ]]
}
bool callback_received() const { return callback_received_; }$for j [[
const A$j& arg$j() const { return arg$j[[]]_; }]]
private:
void OnSignalCallback($for j , [[A$j arg$j]]) {
callback_received_ = true;$for j [[
arg$j[[]]_ = arg$j;]]
}
bool callback_received_;$for j [[
A$j arg$j[[]]_initial_, arg$j[[]]_;]]
DISALLOW_COPY_AND_ASSIGN(GenericSlot$i);
};
]]
} // namespace rtc
#endif // WEBRTC_BASE_GENERICSLOT_H_