summaryrefslogtreecommitdiff
path: root/gps/gnss/XtraSystemStatusObserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gps/gnss/XtraSystemStatusObserver.cpp')
-rw-r--r--gps/gnss/XtraSystemStatusObserver.cpp146
1 files changed, 85 insertions, 61 deletions
diff --git a/gps/gnss/XtraSystemStatusObserver.cpp b/gps/gnss/XtraSystemStatusObserver.cpp
index e27e698..91c395f 100644
--- a/gps/gnss/XtraSystemStatusObserver.cpp
+++ b/gps/gnss/XtraSystemStatusObserver.cpp
@@ -52,94 +52,121 @@
using namespace loc_core;
-#define XTRA_HAL_SOCKET_NAME "/data/vendor/location/xtra/socket_hal_xtra"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "LocSvc_XSSO"
bool XtraSystemStatusObserver::updateLockStatus(uint32_t lock) {
+ mGpsLock = lock;
+
+ if (!mReqStatusReceived) {
+ return true;
+ }
+
stringstream ss;
ss << "gpslock";
ss << " " << lock;
- ss << "\n"; // append seperator
- return ( sendEvent(ss) );
+ return ( send(LOC_IPC_XTRA, ss.str()) );
}
-bool XtraSystemStatusObserver::updateConnectionStatus(bool connected, uint32_t type) {
+bool XtraSystemStatusObserver::updateConnections(uint64_t allConnections) {
+ mIsConnectivityStatusKnown = true;
+ mConnections = allConnections;
+
+ if (!mReqStatusReceived) {
+ return true;
+ }
+
stringstream ss;
ss << "connection";
- ss << " " << (connected ? "1" : "0");
- ss << " " << (int)type;
- ss << "\n"; // append seperator
- return ( sendEvent(ss) );
+ ss << " " << mConnections;
+ return ( send(LOC_IPC_XTRA, ss.str()) );
}
+
bool XtraSystemStatusObserver::updateTac(const string& tac) {
+ mTac = tac;
+
+ if (!mReqStatusReceived) {
+ return true;
+ }
+
stringstream ss;
ss << "tac";
ss << " " << tac.c_str();
- ss << "\n"; // append seperator
- return ( sendEvent(ss) );
+ return ( send(LOC_IPC_XTRA, ss.str()) );
}
bool XtraSystemStatusObserver::updateMccMnc(const string& mccmnc) {
+ mMccmnc = mccmnc;
+
+ if (!mReqStatusReceived) {
+ return true;
+ }
+
stringstream ss;
ss << "mncmcc";
ss << " " << mccmnc.c_str();
- ss << "\n"; // append seperator
- return ( sendEvent(ss) );
+ return ( send(LOC_IPC_XTRA, ss.str()) );
}
-bool XtraSystemStatusObserver::sendEvent(const stringstream& event) {
- int socketFd = createSocket();
- if (socketFd < 0) {
- LOC_LOGe("XTRA unreachable. sending failed.");
- return false;
- }
+bool XtraSystemStatusObserver::updateXtraThrottle(const bool enabled) {
+ mXtraThrottle = enabled;
- const string& data = event.str();
- int remain = data.length();
- ssize_t sent = 0;
- while (remain > 0 &&
- (sent = ::send(socketFd, data.c_str() + (data.length() - remain),
- remain, MSG_NOSIGNAL)) > 0) {
- remain -= sent;
+ if (!mReqStatusReceived) {
+ return true;
}
- if (sent < 0) {
- LOC_LOGe("sending error. reason:%s", strerror(errno));
+ stringstream ss;
+ ss << "xtrathrottle";
+ ss << " " << (enabled ? 1 : 0);
+ return ( send(LOC_IPC_XTRA, ss.str()) );
+}
+
+inline bool XtraSystemStatusObserver::onStatusRequested(int32_t xtraStatusUpdated) {
+ mReqStatusReceived = true;
+
+ if (xtraStatusUpdated) {
+ return true;
}
- closeSocket(socketFd);
+ stringstream ss;
- return (remain == 0);
-}
+ ss << "respondStatus" << endl;
+ (mGpsLock == -1 ? ss : ss << mGpsLock) << endl << mConnections << endl
+ << mTac << endl << mMccmnc << endl << mIsConnectivityStatusKnown;
+ return ( send(LOC_IPC_XTRA, ss.str()) );
+}
-int XtraSystemStatusObserver::createSocket() {
- int socketFd = -1;
+void XtraSystemStatusObserver::onReceive(const std::string& data) {
+ if (!strncmp(data.c_str(), "ping", sizeof("ping") - 1)) {
+ LOC_LOGd("ping received");
- if ((socketFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- LOC_LOGe("create socket error. reason:%s", strerror(errno));
+#ifdef USE_GLIB
+ } else if (!strncmp(data.c_str(), "connectBackhaul", sizeof("connectBackhaul") - 1)) {
+ mSystemStatusObsrvr->connectBackhaul();
- } else {
- const char* socketPath = XTRA_HAL_SOCKET_NAME ;
- struct sockaddr_un addr = { .sun_family = AF_UNIX };
- snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socketPath);
+ } else if (!strncmp(data.c_str(), "disconnectBackhaul", sizeof("disconnectBackhaul") - 1)) {
+ mSystemStatusObsrvr->disconnectBackhaul();
+#endif
- if (::connect(socketFd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
- LOC_LOGe("cannot connect to XTRA. reason:%s", strerror(errno));
- if (::close(socketFd)) {
- LOC_LOGe("close socket error. reason:%s", strerror(errno));
- }
- socketFd = -1;
- }
- }
+ } else if (!strncmp(data.c_str(), "requestStatus", sizeof("requestStatus") - 1)) {
+ int32_t xtraStatusUpdated = 0;
+ sscanf(data.c_str(), "%*s %d", &xtraStatusUpdated);
- return socketFd;
-}
+ struct HandleStatusRequestMsg : public LocMsg {
+ XtraSystemStatusObserver& mXSSO;
+ int32_t mXtraStatusUpdated;
+ inline HandleStatusRequestMsg(XtraSystemStatusObserver& xsso,
+ int32_t xtraStatusUpdated) :
+ mXSSO(xsso), mXtraStatusUpdated(xtraStatusUpdated) {}
+ inline void proc() const override { mXSSO.onStatusRequested(mXtraStatusUpdated); }
+ };
+ mMsgTask->sendMsg(new (nothrow) HandleStatusRequestMsg(*this, xtraStatusUpdated));
-void XtraSystemStatusObserver::closeSocket(const int socketFd) {
- if (socketFd >= 0) {
- if(::close(socketFd)) {
- LOC_LOGe("close socket error. reason:%s", strerror(errno));
- }
+ } else {
+ LOC_LOGw("unknown event: %s", data.c_str());
}
}
@@ -171,11 +198,11 @@ void XtraSystemStatusObserver::getName(string& name)
void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
{
- struct handleOsObserverUpdateMsg : public LocMsg {
+ struct HandleOsObserverUpdateMsg : public LocMsg {
XtraSystemStatusObserver* mXtraSysStatObj;
list <IDataItemCore*> mDataItemList;
- inline handleOsObserverUpdateMsg(XtraSystemStatusObserver* xtraSysStatObs,
+ inline HandleOsObserverUpdateMsg(XtraSystemStatusObserver* xtraSysStatObs,
const list<IDataItemCore*>& dataItemList) :
mXtraSysStatObj(xtraSysStatObs) {
for (auto eachItem : dataItemList) {
@@ -191,7 +218,7 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
}
}
- inline ~handleOsObserverUpdateMsg() {
+ inline ~HandleOsObserverUpdateMsg() {
for (auto each : mDataItemList) {
delete each;
}
@@ -205,8 +232,7 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
{
NetworkInfoDataItemBase* networkInfo =
static_cast<NetworkInfoDataItemBase*>(each);
- mXtraSysStatObj->updateConnectionStatus(networkInfo->mConnected,
- networkInfo->mType);
+ mXtraSysStatObj->updateConnections(networkInfo->getAllTypes());
}
break;
@@ -232,7 +258,5 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
}
}
};
- mMsgTask->sendMsg(new (nothrow) handleOsObserverUpdateMsg(this, dlist));
+ mMsgTask->sendMsg(new (nothrow) HandleOsObserverUpdateMsg(this, dlist));
}
-
-