1 /* 2 * Copyright (c) 2025 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 ANI_HIAPPEVENT_HOLDER_H 17 #define ANI_HIAPPEVENT_HOLDER_H 18 19 #include <ani.h> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "hiappevent_base.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 struct AppEventPackage { AppEventPackageAppEventPackage29 AppEventPackage() : packageId(0), row(0), size(0), data(0), events(0) {} ~AppEventPackageAppEventPackage30 ~AppEventPackage() {} 31 int packageId; 32 int row; 33 int size; 34 std::vector<std::string> data; 35 std::vector<std::shared_ptr<AppEventPack>> events; 36 }; 37 38 class AniAppEventHolder { 39 public: 40 AniAppEventHolder(const std::string& name, int64_t observerSeq = -1); ~AniAppEventHolder()41 ~AniAppEventHolder() {} 42 static void AniConstructor(ani_env *env, ani_object aniObject, ani_string watcherName); 43 static void AniFinalize(ani_env *env, ani_object object, ani_long nativeHolder); 44 static void AniSetRow(ani_env *env, ani_object object, ani_double size); 45 static void AniSetSize(ani_env *env, ani_object object, ani_double size); 46 static ani_object AniTakeNext(ani_env *env, ani_object object); 47 48 void SetRow(int row); 49 void SetSize(int size); 50 std::shared_ptr<AppEventPackage> TakeNext(); 51 52 private: 53 std::string name_; 54 int takeRow_; 55 int takeSize_; 56 int packageId_; 57 int64_t observerSeq_; 58 bool hasSetRow_; 59 bool hasSetSize_; 60 }; 61 } // namespace HiviewDFX 62 } // namespace OHOS 63 #endif // ANI_HIAPPEVENT_HOLDER_H 64