blob: 56a3a9c15ac62b714f19d142ea0b2b56785eea23 [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation, nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29#ifndef XTRA_SYSTEM_STATUS_OBS_H
30#define XTRA_SYSTEM_STATUS_OBS_H
31
32#include <cinttypes>
33#include <MsgTask.h>
34#include <LocIpc.h>
35#include <LocTimer.h>
36#include <stdlib.h>
37
38using namespace std;
39using namespace loc_util;
40using loc_core::IOsObserver;
41using loc_core::IDataItemObserver;
42using loc_core::IDataItemCore;
43
44struct StartDgnssNtripParams {
45 GnssNtripConnectionParams ntripParams;
46 string nmea;
47
48 void clear() {
49 ntripParams.hostNameOrIp.clear();
50 ntripParams.mountPoint.clear();
51 ntripParams.username.clear();
52 ntripParams.password.clear();
53 ntripParams.port = 0;
54 ntripParams.useSSL = false;
55 ntripParams.requiresNmeaLocation = false;
56 nmea.clear();
57 }
58};
59
60class XtraSystemStatusObserver : public IDataItemObserver {
61public :
62 // constructor & destructor
63 XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask);
64 inline virtual ~XtraSystemStatusObserver() {
65 subscribe(false);
66 mIpc.stopNonBlockingListening();
67 }
68
69 // IDataItemObserver overrides
70 inline virtual void getName(string& name);
71 virtual void notify(const list<IDataItemCore*>& dlist);
72
73 bool updateLockStatus(GnssConfigGpsLock lock);
74 bool updateConnections(uint64_t allConnections,
75 loc_core::NetworkInfoType* networkHandleInfo);
76 bool updateTac(const string& tac);
77 bool updateMccMnc(const string& mccmnc);
78 bool updateXtraThrottle(const bool enabled);
79 inline const MsgTask* getMsgTask() { return mMsgTask; }
80 void subscribe(bool yes);
81 bool onStatusRequested(int32_t xtraStatusUpdated);
82 void startDgnssSource(const StartDgnssNtripParams& params);
83 void restartDgnssSource();
84 void stopDgnssSource();
85 void updateNmeaToDgnssServer(const string& nmea);
86
87private:
88 IOsObserver* mSystemStatusObsrvr;
89 const MsgTask* mMsgTask;
90 GnssConfigGpsLock mGpsLock;
91 LocIpc mIpc;
92 uint64_t mConnections;
93 loc_core::NetworkInfoType mNetworkHandle[MAX_NETWORK_HANDLES];
94 string mTac;
95 string mMccmnc;
96 bool mXtraThrottle;
97 bool mReqStatusReceived;
98 bool mIsConnectivityStatusKnown;
99 shared_ptr<LocIpcSender> mSender;
100 string mNtripParamsString;
101
102 class DelayLocTimer : public LocTimer {
103 LocIpcSender& mSender;
104 public:
105 DelayLocTimer(LocIpcSender& sender) : mSender(sender) {}
106 void timeOutCallback() override {
107 LocIpc::send(mSender, (const uint8_t*)"halinit", sizeof("halinit"));
108 }
109 } mDelayLocTimer;
110};
111
112#endif