• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_DEVICE_MANAGER_NATIVE_EVENT_H
16 #define OHOS_DEVICE_MANAGER_NATIVE_EVENT_H
17 
18 #include <map>
19 #include <memory>
20 #include <string>
21 #include "jsi.h"
22 #include "dm_device_info.h"
23 
24 namespace OHOS {
25 namespace ACELite {
26 struct DmEventListener {
27     std::string eventType;
28     JSIValue handlerRef = JSI::CreateUndefined();
29     JSIValue thisVarRef_ = JSI::CreateUndefined();
30 };
31 
32 struct FuncParams {
33     JSIValue handlerRef = JSI::CreateUndefined();
34     JSIValue thisVarRef_ = JSI::CreateUndefined();
35     const JSIValue *args = nullptr;
36     uint8_t argsSize = 0;
37 };
38 
39 class DmNativeEvent {
40 public:
41     DmNativeEvent();
42     DmNativeEvent(JSIValue thisVar);
43     virtual ~DmNativeEvent();
44     virtual void On(std::string &eventType, JSIValue handler, JSIValue thisVal);
45     virtual void Off(std::string &eventType);
46     virtual void OnEvent(const std::string &eventType, uint8_t argsSize, const JSIValue *data);
47     static void OnEventAsyncWorkFunc(void *data);
48 protected:
49     static std::map<std::string, std::shared_ptr<DmEventListener>> eventMap_;
50 };
51 }
52 }
53 
54 #endif /* OHOS_DEVICE_MANAGER_NATIVE_EVENT_H */