Hazelcast C++ Client
Hazelcast C++ Client Library
listener.h
1 /*
2  * Copyright (c) 2008-2021, 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 
29 namespace hazelcast {
30  namespace client {
31  namespace topic {
32  class message;
33  namespace impl {
34  class TopicEventHandlerImpl;
35  }
36 
41  class HAZELCAST_API listener final {
42  public:
52  template<typename Handler,
53  typename = util::enable_if_rvalue_ref_t<Handler &&>>
54  listener &on_received(Handler &&h) & {
55  received_ = std::move(h);
56  return *this;
57  }
58 
62  template<typename Handler,
63  typename = util::enable_if_rvalue_ref_t<Handler &&>>
64  listener &&on_received(Handler &&h) && {
65  on_received(std::move(h));
66  return std::move(*this);
67  }
68 
69  private:
70  using HandlerType = std::function<void(message &&)>;
71 
72  HandlerType received_ = util::noop<message &&>;
73 
74  friend class impl::TopicEventHandlerImpl;
75  };
76  }
77  }
78 }
79 
80 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
81 #pragma warning(pop)
82 #endif
83 
84 
85 
Listen to messages from an ITopic.
Definition: listener.h:41
listener && on_received(Handler &&h) &&
Definition: listener.h:64
listener & on_received(Handler &&h) &
Set an handler function to be invoked when a message is received for the subscribed topic.
Definition: listener.h:54