• 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_INNERKITS_INCLUDE_ICOMMON_EVENT_H
17 #define FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_ICOMMON_EVENT_H
18 
19 #include "common_event_data.h"
20 #include "common_event_publish_info.h"
21 #include "common_event_subscribe_info.h"
22 #include "iremote_broker.h"
23 #include "iremote_object.h"
24 
25 namespace OHOS {
26 namespace EventFwk {
27 class ICommonEvent : public IRemoteBroker {
28 public:
29     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.eventfwk.ICommonEvent");
30 
31     /**
32      * Publishes a common event.
33      *
34      * @param event Indicates the common event data.
35      * @param publishInfo Indicates the publish info.
36      * @param commonEventListener Indicates the last subscriber to receive the event.
37      * @param userId Indicates the user ID.
38      * @return Returns true if successful; false otherwise.
39      */
40     virtual int32_t PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
41         const sptr<IRemoteObject> &commonEventListener, const int32_t &userId) = 0;
42 
43     /**
44      * Publishes a common event.
45      *
46      * @param event Indicates the common event data.
47      * @param publishInfo Indicates the publish info.
48      * @param commonEventListener Indicates the last subscriber to receive the event.
49      * @param uid Indicates the uid.
50      * @param callerToken Indicates the caller token
51      * @param userId Indicates the user ID.
52      * @return Returns true if successful; false otherwise.
53      */
54     virtual bool PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
55         const sptr<IRemoteObject> &commonEventListener, const uid_t &uid, const int32_t &callerToken,
56         const int32_t &userId) = 0;
57 
58     /**
59      * Subscribes to common events.
60      *
61      * @param subscribeInfo Indicates the subscribe information.
62      * @param commonEventListener Indicates the subscriber object.
63      * @return Returns true if successful; false otherwise.
64      */
65     virtual int32_t SubscribeCommonEvent(
66         const CommonEventSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &commonEventListener) = 0;
67 
68     /**
69      * Unsubscribes from common events.
70      *
71      * @param commonEventListener Indicates the subscriber object.
72      * @return Returns true if successful; false otherwise.
73      */
74     virtual int32_t UnsubscribeCommonEvent(const sptr<IRemoteObject> &commonEventListener) = 0;
75 
76     /**
77      * Gets the current sticky common event
78      *
79      * @param event Indicates the common event.
80      * @param eventData Indicates he common event data.
81      * @return Returns true if successful; false otherwise.
82      */
83     virtual bool GetStickyCommonEvent(const std::string &event, CommonEventData &eventData) = 0;
84 
85     /**
86      * Dumps the state for common event service.
87      *
88      * @param dumpType Indicates the dump type.
89      * @param event Indicates the specified event.
90      * @param userId Indicates the user id.
91      * @param state Indicates the output result.
92      * @return Returns true if successful; false otherwise.
93      */
94     virtual bool DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
95         std::vector<std::string> &state) = 0;
96 
97     /**
98      * Finishes the receiver for the ordered common event.
99      *
100      * @param proxy Indicates the current subscriber object.
101      * @param code Indicates the result code.
102      * @param receiverData Indicates the result data.
103      * @param abortEvent Indicates whether the current ordered common event should be aborted.
104      * @return Returns true if successful; false otherwise.
105      */
106     virtual bool FinishReceiver(const sptr<IRemoteObject> &proxy, const int32_t &code,
107         const std::string &receiverData, const bool &abortEvent) = 0;
108 
109     /**
110      * Freezes the specified process.
111      *
112      * @param uid Indicates the uid of frozen process.
113      * @return Returns true if successful; false otherwise.
114      */
115     virtual bool Freeze(const uid_t &uid) = 0;
116 
117     /**
118      * Unfreezes the specified process.
119      *
120      * @param uid Indicates the uid of unfrozen process.
121      * @return Returns true if successful; false otherwise.
122      */
123     virtual bool Unfreeze(const uid_t &uid) = 0;
124 
125     /**
126      * Unfreezes all frozen applications.
127      *
128      * @return Returns true if successful; false otherwise.
129      */
130     virtual bool UnfreezeAll() = 0;
131 
132     enum class Message {
133         CES_PUBLISH_COMMON_EVENT = 0,
134         CES_PUBLISH_COMMON_EVENT2,
135         CES_SUBSCRIBE_COMMON_EVENT,
136         CES_UNSUBSCRIBE_COMMON_EVENT,
137         CES_GET_STICKY_COMMON_EVENT,
138         CES_FINISH_RECEIVER,
139         CES_FREEZE,
140         CES_UNFREEZE,
141         CES_UNFREEZE_ALL,
142         // ipc id 2001-3000 for tools
143         // ipc id for dumping Subscribe State (2001)
144         CES_DUMP_STATE = 2001,
145     };
146 };
147 }  // namespace EventFwk
148 }  // namespace OHOS
149 
150 #endif  // FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_ICOMMON_EVENT_H
151