2 * Copyright (c) 2012 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 CallbackSupport.h
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
21 #ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_CALLBACK_SUPPORT_H_
22 #define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_CALLBACK_SUPPORT_H_
27 #include <dpl/foreach.h>
29 namespace WrtPluginsApi
32 template<typename Sig>
36 typedef typename Sig::Signature SlotSignature;
37 typedef typename Sig::Type SlotType;
38 typedef std::string GroupType;
39 typedef std::vector<SlotType> SlotList;
41 void Connect(const GroupType& group, const SlotType& slot)
43 auto groupIt = m_slots.find(group);
44 if (m_slots.end() == groupIt)
46 groupIt = m_slots.insert(std::make_pair(group, SlotList())).first;
48 groupIt->second.push_back(slot);
51 void Disconnect(const GroupType& group)
56 template<typename...Args>
57 void Invoke(const Args&... args)
60 FOREACH(groupIt, m_slots)
62 FOREACH(slotIt, groupIt->second)
69 template<typename...Args>
70 void InvokeGroup(const GroupType& group, const Args&... args)
72 auto groupIt = m_slots.find(group);
74 if (m_slots.end() != groupIt)
76 FOREACH (slotIt, groupIt->second)
84 std::map<GroupType, SlotList> m_slots;