Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
listener.h
1/*
2 * Copyright (c) 2008-2025, Hazelcast, Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <functional>
19
20#include "hazelcast/util/export.h"
21#include "hazelcast/util/type_traits.h"
22#include "hazelcast/util/noop.h"
23
24#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25#pragma warning(push)
26#pragma warning(disable : 4251) // for dll export
27#endif
28
29namespace hazelcast {
30namespace client {
31namespace topic {
32class message;
33namespace impl {
34class TopicEventHandlerImpl;
35}
36
41class HAZELCAST_API listener final
42{
43public:
56 template<typename Handler,
57 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
58 listener& on_received(Handler&& h) &
59 {
60 received_ = std::move(h);
61 return *this;
62 }
63
67 template<typename Handler,
68 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
69 listener&& on_received(Handler&& h) &&
70 {
71 on_received(std::move(h));
72 return std::move(*this);
73 }
74
75private:
76 using HandlerType = std::function<void(message&&)>;
77
78 HandlerType received_ = util::noop<message&&>;
79
80 friend class impl::TopicEventHandlerImpl;
81};
82} // namespace topic
83} // namespace client
84} // namespace hazelcast
85
86#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
87#pragma warning(pop)
88#endif
Listen to messages from an ITopic.
Definition listener.h:42
listener && on_received(Handler &&h) &&
Definition listener.h:69
listener & on_received(Handler &&h) &
Set an handler function to be invoked when a message is received for the subscribed topic.
Definition listener.h:58