• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 
16 #ifndef OHOS_MECH_SUBSCRIPTION_CENTER_H
17 #define OHOS_MECH_SUBSCRIPTION_CENTER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <string>
22 
23 #include "mc_command_base.h"
24 #include "mc_event_listener.h"
25 #include "mechbody_controller_log.h"
26 #include "mc_data_buffer.h"
27 
28 namespace OHOS {
29 namespace MechBodyController {
30 class SubscriptionCenter {
31 public:
32     static SubscriptionCenter& GetInstance();
33 private:
34     SubscriptionCenter() = default;
35     ~SubscriptionCenter() = default;
36     SubscriptionCenter(const SubscriptionCenter&) = delete;
37     SubscriptionCenter& operator= (const SubscriptionCenter&) = delete;
38     SubscriptionCenter(SubscriptionCenter&&) = delete;
39     SubscriptionCenter& operator= (SubscriptionCenter&&) = delete;
40 
41 public:
42     int32_t Subscribe(uint16_t type, const std::shared_ptr<IMechEventListener> &listener);
43     int32_t UnSubscribe(uint16_t type, const std::shared_ptr<IMechEventListener> &listener);
44     int32_t Notify(const std::shared_ptr<CommandBase> &cmd);
45 
46 private:
47     mutable std::mutex mutex_;
48     std::map<uint16_t, std::vector<std::shared_ptr<IMechEventListener>>> subscribers_;
49 };
50 }  // namespace MechBodyController
51 }  // namespace OHOS
52 #endif  // OHOS_MECH_SUBSCRIPTION_CENTER_H
53