1 /*
2  * Copyright (c) 2023 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 #ifndef HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_PROCESSOR_PROXY_H
16 #define HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_PROCESSOR_PROXY_H
17 
18 #include <string>
19 
20 #include "app_event_observer.h"
21 #include "app_event_processor.h"
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 namespace HiAppEvent {
26 class AppEventProcessorProxy : public AppEventObserver, public std::enable_shared_from_this<AppEventProcessorProxy> {
27 public:
AppEventProcessorProxy(const std::string & name,std::shared_ptr<AppEventProcessor> processor)28     AppEventProcessorProxy(const std::string& name, std::shared_ptr<AppEventProcessor> processor)
29         : AppEventObserver(name), processor_(processor), userIdVersion_(-1), userPropertyVersion_(-1) {}
30     ~AppEventProcessorProxy() = default;
31 
32     void OnEvents(const std::vector<std::shared_ptr<AppEventPack>>& events) override;
33     bool VerifyEvent(std::shared_ptr<AppEventPack> event) override;
34 
35 private:
36     void GetValidUserIds(std::vector<UserId>& userIds);
37     void GetValidUserProperties(std::vector<UserProperty>& userProperties);
38 
39 private:
40     std::shared_ptr<AppEventProcessor> processor_;
41     int64_t userIdVersion_;
42     int64_t userPropertyVersion_;
43     std::vector<UserId> userIds_;
44     std::vector<UserProperty> userProperties_;
45 };
46 } // namespace HiAppEvent
47 } // namespace HiviewDFX
48 } // namespace OHOS
49 #endif // HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_PROCESSOR_PROXY_H
50