1 /* Copyright (c) 2017-2019, 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 
37 using namespace std;
38 using namespace loc_util;
39 using loc_core::IOsObserver;
40 using loc_core::IDataItemObserver;
41 using loc_core::IDataItemCore;
42 
43 class XtraSystemStatusObserver : public IDataItemObserver {
44 public :
45     // constructor & destructor
46     XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask);
~XtraSystemStatusObserver()47     inline virtual ~XtraSystemStatusObserver() {
48         subscribe(false);
49         mIpc.stopNonBlockingListening();
50     }
51 
52     // IDataItemObserver overrides
53     inline virtual void getName(string& name);
54     virtual void notify(const list<IDataItemCore*>& dlist);
55 
56     bool updateLockStatus(GnssConfigGpsLock lock);
57     bool updateConnections(uint64_t allConnections,
58             loc_core::NetworkInfoType* networkHandleInfo);
59     bool updateTac(const string& tac);
60     bool updateMccMnc(const string& mccmnc);
61     bool updateXtraThrottle(const bool enabled);
getMsgTask()62     inline const MsgTask* getMsgTask() { return mMsgTask; }
63     void subscribe(bool yes);
64     bool onStatusRequested(int32_t xtraStatusUpdated);
65 
66 private:
67     IOsObserver*    mSystemStatusObsrvr;
68     const MsgTask* mMsgTask;
69     GnssConfigGpsLock mGpsLock;
70     LocIpc mIpc;
71     uint64_t mConnections;
72     loc_core::NetworkInfoType mNetworkHandle[MAX_NETWORK_HANDLES];
73     string mTac;
74     string mMccmnc;
75     bool mXtraThrottle;
76     bool mReqStatusReceived;
77     bool mIsConnectivityStatusKnown;
78     shared_ptr<LocIpcSender> mSender;
79 
80     class DelayLocTimer : public LocTimer {
81         LocIpcSender& mSender;
82     public:
DelayLocTimer(LocIpcSender & sender)83         DelayLocTimer(LocIpcSender& sender) : mSender(sender) {}
timeOutCallback()84         void timeOutCallback() override {
85             LocIpc::send(mSender, (const uint8_t*)"halinit", sizeof("halinit"));
86         }
87     } mDelayLocTimer;
88 };
89 
90 #endif
91