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