• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_MANAGER_H
17 #define FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_MANAGER_H
18 
19 #include "common_event_data.h"
20 #include "common_event_publish_info.h"
21 #include "common_event_subscriber.h"
22 
23 namespace OHOS {
24 namespace EventFwk {
25 class CommonEventManager {
26 public:
27     /**
28      * Publish a standard common event.
29      *
30      * @param data the common event data
31      */
32     static bool PublishCommonEvent(const CommonEventData &data);
33 
34     /**
35      * Publish a standard common event.
36      *
37      * @param data the common event data
38      * @param userId indicates the user ID
39      */
40     static bool PublishCommonEventAsUser(const CommonEventData &data, const int32_t &userId);
41 
42     /**
43      * Publish an ordered, sticky, or standard common event.
44      *
45      * @param data the common event data
46      * @param publishInfo the publish info
47      */
48     static bool PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo);
49 
50     /**
51      * Publish an ordered, sticky, or standard common event.
52      *
53      * @param data the common event data
54      * @param publishInfo the publish info
55      * @param userId indicates the user ID
56      */
57     static bool PublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
58         const int32_t &userId);
59 
60     /**
61      * Publish an ordered, sticky, or standard common event.
62      *
63      * @param data the common event data
64      * @param publishInfo the publish info
65      * @param subscriber the common event subscriber
66      */
67     static bool PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
68         const std::shared_ptr<CommonEventSubscriber> &subscriber);
69 
70     /**
71      * Publish an ordered, sticky, or standard common event.
72      *
73      * @param data the common event data
74      * @param publishInfo the publish info
75      * @param subscriber the common event subscriber
76      * @param userId indicates the user ID
77      */
78     static bool PublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
79         const std::shared_ptr<CommonEventSubscriber> &subscriber, const int32_t &userId);
80 
81     /**
82      * Publish an ordered, sticky, or standard common event.
83      *
84      * @param data the common event data
85      * @param publishInfo the publish info
86      * @param subscriber the common event subscriber
87      * @param uid Uid of application.
88      */
89     static bool PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
90         const std::shared_ptr<CommonEventSubscriber> &subscriber, const uid_t &uid);
91 
92     /**
93      * Publish an ordered, sticky, or standard common event.
94      *
95      * @param data the common event data
96      * @param publishInfo the publish info
97      * @param subscriber the common event subscriber
98      * @param uid Uid of application.
99      * @param userId indicates the user ID
100      */
101     static bool PublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
102         const std::shared_ptr<CommonEventSubscriber> &subscriber, const uid_t &uid, const int32_t &userId);
103 
104     /**
105      * Subscribe to common events.
106      *
107      * @param subscriber the common event subscriber
108      */
109     static bool SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber);
110 
111     /**
112      * Unsubscribe from common events.
113      *
114      * @param subscriber the common event subscriber
115      */
116     static bool UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber);
117 
118     /**
119      * Gets the current sticky common event
120      *
121      * @param event the common event
122      * @param commonEventData the common event data
123      */
124     static bool GetStickyCommonEvent(const std::string &event, CommonEventData &commonEventData);
125 };
126 }  // namespace EventFwk
127 }  // namespace OHOS
128 
129 #endif  // FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_MANAGER_H
130