• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 LOCATING_REQUIRED_DATA_CALLBACK_HOST_H
17 #define LOCATING_REQUIRED_DATA_CALLBACK_HOST_H
18 
19 #include "i_locating_required_data_callback.h"
20 #include "iremote_stub.h"
21 #include "message_parcel.h"
22 #include "message_option.h"
23 #include "common_utils.h"
24 #include "napi/native_api.h"
25 #include "uv.h"
26 
27 namespace OHOS {
28 namespace Location {
29 class LocatingRequiredDataCallbackHost : public IRemoteStub<ILocatingRequiredDataCallback> {
30 public:
31     LocatingRequiredDataCallbackHost();
32     virtual ~LocatingRequiredDataCallbackHost();
33     virtual int OnRemoteRequest(
34         uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
35     bool IsRemoteDied();
36     bool Send(const std::vector<std::shared_ptr<LocatingRequiredData>>& data);
37     void OnLocatingDataChange(const std::vector<std::shared_ptr<LocatingRequiredData>>& data) override;
38     void DeleteHandler();
39     void UvQueueWork(uv_loop_s* loop, uv_work_t* work);
40     bool IsSingleLocationRequest();
41     void CountDown();
42     void Wait(int time);
43     int GetCount();
44     void SetCount(int count);
45     void InitLatch();
46 
GetEnv()47     inline napi_env GetEnv() const
48     {
49         return env_;
50     }
51 
SetEnv(const napi_env & env)52     inline void SetEnv(const napi_env& env)
53     {
54         env_ = env;
55     }
56 
GetHandleCb()57     inline napi_ref GetHandleCb() const
58     {
59         return handlerCb_;
60     }
61 
SetHandleCb(const napi_ref & handlerCb)62     inline void SetHandleCb(const napi_ref& handlerCb)
63     {
64         handlerCb_ = handlerCb;
65     }
66 
GetRemoteDied()67     inline bool GetRemoteDied() const
68     {
69         return remoteDied_;
70     }
71 
SetRemoteDied(const bool remoteDied)72     inline void SetRemoteDied(const bool remoteDied)
73     {
74         remoteDied_ = remoteDied;
75     }
76 
GetSingleResult()77     inline std::vector<std::shared_ptr<LocatingRequiredData>> GetSingleResult()
78     {
79         return singleResult_;
80     }
81 
GetFixNumber()82     inline int GetFixNumber() const
83     {
84         return fixNumber_;
85     }
86 
SetFixNumber(const int fixNumber)87     inline void SetFixNumber(const int fixNumber)
88     {
89         fixNumber_ = fixNumber;
90     }
91 private:
92     int fixNumber_;
93     napi_env env_;
94     napi_ref handlerCb_;
95     bool remoteDied_;
96     std::mutex mutex_;
97     CountDownLatch* latch_;
98     std::vector<std::shared_ptr<LocatingRequiredData>> singleResult_;
99 };
100 } // namespace Location
101 } // namespace OHOS
102 #endif // LOCATING_REQUIRED_DATA_CALLBACK_HOST_H
103