• 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 LOCATION_SWITCH_CALLBACK_HOST_H
17 #define LOCATION_SWITCH_CALLBACK_HOST_H
18 #include "i_switch_callback.h"
19 
20 #include "iremote_stub.h"
21 #include "message_parcel.h"
22 #include "message_option.h"
23 #include "napi_util.h"
24 #include "napi/native_api.h"
25 #include "uv.h"
26 
27 namespace OHOS {
28 namespace Location {
29 class LocationSwitchCallbackHost : public IRemoteStub<ISwitchCallback> {
30 public:
31     LocationSwitchCallbackHost();
32     virtual ~LocationSwitchCallbackHost();
33     virtual int OnRemoteRequest(
34         uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
35     bool IsRemoteDied();
36     napi_value PackResult(bool switchState);
37     bool Send(int switchState);
38     void OnSwitchChange(int switchState) override;
39     void DeleteHandler();
40     void UvQueueWork(uv_loop_s* loop, uv_work_t* work);
41 
GetEnv()42     inline napi_env GetEnv() const
43     {
44         return env_;
45     }
46 
SetEnv(const napi_env & env)47     inline void SetEnv(const napi_env& env)
48     {
49         env_ = env;
50     }
51 
GetHandleCb()52     inline napi_ref GetHandleCb() const
53     {
54         return handlerCb_;
55     }
56 
SetHandleCb(const napi_ref & handlerCb)57     inline void SetHandleCb(const napi_ref& handlerCb)
58     {
59         handlerCb_ = handlerCb;
60     }
61 
GetRemoteDied()62     inline bool GetRemoteDied() const
63     {
64         return remoteDied_;
65     }
66 
SetRemoteDied(const bool remoteDied)67     inline void SetRemoteDied(const bool remoteDied)
68     {
69         remoteDied_ = remoteDied;
70     }
71 
72 private:
73     napi_env env_;
74     napi_ref handlerCb_;
75     bool remoteDied_;
76     std::mutex mutex_;
77 };
78 } // namespace Location
79 } // namespace OHOS
80 #endif // LOCATION_SWITCH_CALLBACK_HOST_H
81