XtraSystemStatusObserver.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Copyright (c) 2017-2021 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. /*
  30. Changes from Qualcomm Innovation Center are provided under the following license:
  31. Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  32. SPDX-License-Identifier: BSD-3-Clause-Clear
  33. */
  34. #ifndef XTRA_SYSTEM_STATUS_OBS_H
  35. #define XTRA_SYSTEM_STATUS_OBS_H
  36. #include <cinttypes>
  37. #include <MsgTask.h>
  38. #include <LocIpc.h>
  39. #include <LocTimer.h>
  40. #include <stdlib.h>
  41. using namespace std;
  42. using namespace loc_util;
  43. using loc_core::IOsObserver;
  44. using loc_core::IDataItemObserver;
  45. using loc_core::IDataItemCore;
  46. struct StartDgnssNtripParams {
  47. GnssNtripConnectionParams ntripParams;
  48. string nmea;
  49. void clear() {
  50. ntripParams.hostNameOrIp.clear();
  51. ntripParams.mountPoint.clear();
  52. ntripParams.username.clear();
  53. ntripParams.password.clear();
  54. ntripParams.port = 0;
  55. ntripParams.useSSL = false;
  56. ntripParams.requiresNmeaLocation = false;
  57. nmea.clear();
  58. }
  59. };
  60. class XtraSystemStatusObserver : public IDataItemObserver {
  61. public :
  62. // constructor & destructor
  63. XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask);
  64. inline virtual ~XtraSystemStatusObserver() {
  65. subscribe(false);
  66. mIpc.stopNonBlockingListening();
  67. }
  68. // IDataItemObserver overrides
  69. inline virtual void getName(string& name);
  70. virtual void notify(const unordered_set<IDataItemCore*>& dlist);
  71. bool updateLockStatus(GnssConfigGpsLock lock);
  72. bool updateConnections(uint64_t allConnections,
  73. loc_core::NetworkInfoType* networkHandleInfo, bool roaming);
  74. bool updateTac(const string& tac);
  75. bool updateMccMnc(const string& mccmnc);
  76. bool updateXtraThrottle(const bool enabled);
  77. inline const MsgTask* getMsgTask() { return mMsgTask; }
  78. void subscribe(bool yes);
  79. bool notifySessionStart();
  80. bool onStatusRequested(int32_t xtraStatusUpdated);
  81. void startDgnssSource(const StartDgnssNtripParams& params);
  82. void restartDgnssSource();
  83. void stopDgnssSource();
  84. void updateNmeaToDgnssServer(const string& nmea);
  85. private:
  86. IOsObserver* mSystemStatusObsrvr;
  87. const MsgTask* mMsgTask;
  88. GnssConfigGpsLock mGpsLock;
  89. LocIpc mIpc;
  90. uint64_t mConnections;
  91. loc_core::NetworkInfoType mNetworkHandle[MAX_NETWORK_HANDLES];
  92. bool mRoaming;
  93. string mTac;
  94. string mMccmnc;
  95. bool mXtraThrottle;
  96. bool mReqStatusReceived;
  97. bool mIsConnectivityStatusKnown;
  98. shared_ptr<LocIpcSender> mXtraSender;
  99. shared_ptr<LocIpcSender> mDgnssSender;
  100. string mNtripParamsString;
  101. class DelayLocTimer : public LocTimer {
  102. LocIpcSender& mXtraSender;
  103. LocIpcSender& mDgnssSender;
  104. public:
  105. DelayLocTimer(LocIpcSender& xtraSender, LocIpcSender& dgnssSender) :
  106. mXtraSender(xtraSender), mDgnssSender(dgnssSender) {}
  107. void timeOutCallback() override {
  108. LocIpc::send(mXtraSender, (const uint8_t*)"halinit", sizeof("halinit"));
  109. LocIpc::send(mDgnssSender, (const uint8_t*)"halinit", sizeof("halinit"));
  110. }
  111. } mDelayLocTimer;
  112. };
  113. #endif