2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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 #ifndef EVENTSYSTEM_LIB_METHOD_BROKER_HH_
18 #define EVENTSYSTEM_LIB_METHOD_BROKER_HH_
29 virtual ~ParamsBase() = default;
32 template <class... ArgTypes>
33 class Params : public ParamsBase {
35 using FuncType = std::function<void(ArgTypes...)>;
38 Params(FuncType f) : func_(f) {}
40 void operator()(ArgTypes... args) {
52 void Register(std::string name, const T& cmd) {
53 fmap_.insert(std::pair<std::string,
54 std::shared_ptr<ParamsBase>>(name, std::make_shared<T>(cmd)));
57 void Unregister(std::string name) {
58 fmap_.erase(std::move(name));
61 template <class... ArgTypes>
62 bool Invoke(std::string name, ArgTypes... args) {
63 using ParamsType = Params<ArgTypes...>;
65 auto it = fmap_.find(name);
66 if (it != fmap_.end()) {
67 auto* p = dynamic_cast<ParamsType*>(it->second.get());
78 std::map<std::string, std::shared_ptr<ParamsBase>> fmap_;
81 } // namespace esd::api
83 #endif // EVENTSYSTEM_LIB_METHOD_BROKER_HH_