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