1 /* 2 * Copyright (c) 2022 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_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_HIAPPEVENT_HOLDER_H 16 #define HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_HIAPPEVENT_HOLDER_H 17 18 #include <memory> 19 #include <string> 20 #include <vector> 21 22 #include "napi/native_api.h" 23 #include "napi/native_node_api.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 struct AppEventPackage { AppEventPackageAppEventPackage28 AppEventPackage() : packageId(0), row(0), size(0), events(0) {} ~AppEventPackageAppEventPackage29 ~AppEventPackage() {} 30 int packageId; 31 int row; 32 int size; 33 std::vector<std::string> events; 34 }; 35 36 class NapiAppEventHolder { 37 public: 38 NapiAppEventHolder(std::string name); ~NapiAppEventHolder()39 ~NapiAppEventHolder() {} 40 static napi_value NapiConstructor(napi_env env, napi_callback_info info); 41 static napi_value NapiExport(napi_env env, napi_value exports); 42 static napi_value NapiSetSize(napi_env env, napi_callback_info info); 43 static napi_value NapiTakeNext(napi_env env, napi_callback_info info); 44 45 void SetSize(int size); 46 std::shared_ptr<AppEventPackage> TakeNext(); 47 48 public: 49 static thread_local napi_ref constructor_; 50 51 private: 52 std::string name_; 53 int takeSize_; 54 int packageId_; 55 }; 56 } // namespace HiviewDFX 57 } // namespace OHOS 58 #endif // HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_HIAPPEVENT_HOLDER_H 59