• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     const int32_t ERR_INVALID_INSTANCE_ID = -1;
24 
25     struct AsyncCallbackInfoSubscribe {
26         std::function<void(CCommonEventData)> callback;
27         std::shared_ptr<SubscriberImpl> subscriber = nullptr;
28         int8_t errorCode = NO_ERROR;
29     };
30 
31     struct SubscriberInstanceInfo {
32         std::vector<AsyncCallbackInfoSubscribe *> asyncCallbackInfo;
33         std::shared_ptr<AsyncCommonEventResult> commonEventResult = nullptr;
34     };
35 
36     void SetPublishResult(OHOS::CommonEventManager::SubscriberImpl *subImpl);
37 
38     std::shared_ptr<AsyncCommonEventResult> GetAsyncResult(const SubscriberImpl *objectInfo);
39 
40     void SetSubscribeInfo(std::shared_ptr<SubscriberImpl> subscriber,
41         const std::function<void(CCommonEventData)> &callback);
42 
43     int64_t GetManagerId(int64_t id, bool &haveId);
44 
45     void DeleteSubscribe(std::shared_ptr<SubscriberImpl> subscriber);
46 
47     void GetSubscriberCode(std::shared_ptr<SubscriberImpl> subscriber, int32_t &code);
48 
49     int32_t SetSubscriberCode(std::shared_ptr<SubscriberImpl> subscriber, int32_t code);
50 
51     std::string GetSubscriberData(std::shared_ptr<SubscriberImpl> subscriber);
52 
53     int32_t SetSubscriberData(std::shared_ptr<SubscriberImpl> subscriber, const char *data);
54 
55     int32_t SetSubscriberCodeAndData(std::shared_ptr<SubscriberImpl> subscriber, int32_t code, const char *data);
56 
57     void IsCommonEventSticky(std::shared_ptr<SubscriberImpl> subscriber, bool &data);
58 
59     void IsCommonEventOrdered(std::shared_ptr<SubscriberImpl> subscriber, bool &data);
60 }
61 
62 #endif