• 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 
16 #ifndef DEVICESTATUS_EVENT_H
17 #define DEVICESTATUS_EVENT_H
18 
19 #include <string>
20 #include <list>
21 #include <memory>
22 #include <map>
23 
24 #include "napi/native_api.h"
25 
26 namespace OHOS {
27 namespace Msdp {
28 struct DevicestatusEventListener {
29     int32_t eventType;
30     napi_ref handlerRef = nullptr;
31 };
32 
33 class DevicestatusEvent {
34 public:
35     DevicestatusEvent(napi_env env, napi_value thisVar);
DevicestatusEvent()36     DevicestatusEvent() {};
37     virtual ~DevicestatusEvent();
38 
39     virtual bool On(const int32_t& eventType, napi_value handler, bool isOnce);
40     virtual bool Off(const int32_t& eventType, bool isOnce);
41     virtual void OnEvent(const int32_t& eventType, size_t argc, const int32_t& value, bool isOnce);
42 
43 protected:
44     napi_env env_;
45     napi_ref thisVarRef_;
46     std::map<int32_t, std::shared_ptr<DevicestatusEventListener>> eventMap_;
47     std::map<int32_t, std::shared_ptr<DevicestatusEventListener>> eventOnceMap_;
48 };
49 
50 class JsResponse {
51 public:
52     int32_t devicestatusValue_ = -1;
53 };
54 } // namespace Msdp
55 } // namespace OHOS
56 #endif // DEVICESTATUS_EVENT_H
57