1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_NAPI_TEST_NATIVE_MODULE_NETSERVER_EVENT_TARGET_H 17 #define FOUNDATION_ACE_NAPI_TEST_NATIVE_MODULE_NETSERVER_EVENT_TARGET_H 18 19 #include "napi/native_api.h" 20 21 struct EventListener; 22 23 class Event { 24 public: 25 virtual napi_value ToJsObject() = 0; 26 }; 27 28 class EventTarget { 29 public: 30 EventTarget(napi_env env, napi_value thisVar); 31 virtual ~EventTarget(); 32 33 virtual void On(const char* type, napi_value handler); 34 virtual void Once(const char* type, napi_value handler); 35 virtual void Off(const char* type, napi_value handler); 36 virtual void Off(const char* type); 37 virtual void Emit(const char* type, Event* event); 38 39 protected: 40 napi_env env_; 41 napi_ref thisVarRef_; 42 EventListener* first_; 43 EventListener* last_; 44 }; 45 46 #endif /* FOUNDATION_ACE_NAPI_TEST_NATIVE_MODULE_NETSERVER_EVENT_TARGET_H */ 47