1 /*
2  * Copyright (c) 2024 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 COMMON_EVENT_H
17 #define COMMON_EVENT_H
18 
19 #include "subscriber.h"
20 
21 namespace OHOS::CommonEventManager {
22     using AsyncCommonEventResult = OHOS::EventFwk::AsyncCommonEventResult;
23 
24     struct AsyncCallbackInfoSubscribe {
25         std::function<void(CCommonEventData)> callback;
26         std::shared_ptr<SubscriberImpl> subscriber = nullptr;
27         int8_t errorCode = NO_ERROR;
28     };
29 
30     struct SubscriberInstanceInfo {
31         std::vector<AsyncCallbackInfoSubscribe *> asyncCallbackInfo;
32         std::shared_ptr<AsyncCommonEventResult> commonEventResult = nullptr;
33     };
34 
35     void SetPublishResult(OHOS::CommonEventManager::SubscriberImpl *subImpl);
36 
37     std::shared_ptr<AsyncCommonEventResult> GetAsyncResult(const SubscriberImpl *objectInfo);
38 
39     void SetSubscribeInfo(std::shared_ptr<SubscriberImpl> subscriber,
40         const std::function<void(CCommonEventData)> &callback);
41 
42     int64_t GetManagerId(int64_t id, bool &haveId);
43 
44     void DeleteSubscribe(std::shared_ptr<SubscriberImpl> subscriber);
45 
46     void GetSubscriberCode(std::shared_ptr<SubscriberImpl> subscriber, int64_t &code);
47 
48     int32_t SetSubscriberCode(std::shared_ptr<SubscriberImpl> subscriber, int32_t code);
49 
50     std::string GetSubscriberData(std::shared_ptr<SubscriberImpl> subscriber);
51 
52     int32_t SetSubscriberData(std::shared_ptr<SubscriberImpl> subscriber, const char *data);
53 
54     int32_t SetSubscriberCodeAndData(std::shared_ptr<SubscriberImpl> subscriber, int32_t code, const char *data);
55 
56     void IsCommonEventSticky(std::shared_ptr<SubscriberImpl> subscriber, bool &data);
57 
58     void IsCommonEventOrdered(std::shared_ptr<SubscriberImpl> subscriber, bool &data);
59 }
60 
61 #endif