2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 * @file communication-manager.h
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
26 #include <noncopyable.h>
31 * class responsible for keeping a list of listeners for given M type of message and notifying them
37 NONCOPYABLE(MessageManager);
39 // Listener is an object callable with const M& as argument
41 void Register(L&& listener)
43 m_listeners.push_back(std::move(listener));
46 // Sends message of type M to all registered listeners
47 void SendMessage(const M& msg)
49 for(auto it : m_listeners)
54 // No one is going to destroy this class directly (only via inherited class). Hence no 'virtual'
58 std::list<std::function<void(const M&)>> m_listeners;
61 // generic template declaration
62 template <typename... Args>
63 struct CommunicationManager;
66 * Class that combines MessageManagers of all requested Message types into a single object. Examples
67 * can be found in tests (test_msg-manager.cpp)
69 template <typename First, typename... Args>
70 struct CommunicationManager<First, Args...> :
71 public MessageManager<First>, public CommunicationManager<Args...>
74 CommunicationManager() {}
75 NONCOPYABLE(CommunicationManager);
77 // M - message type, L - listener to register
78 template <typename M, typename L>
79 void Register(L&& listener)
81 MessageManager<M>::Register(std::move(listener));
86 void SendMessage(const M& msg)
88 MessageManager<M>::SendMessage(msg);
92 // stop condition for recursive inheritance
94 struct CommunicationManager<> {