HAL handshake with XTRA
send XSSO state on XTRA request; send XTRA the init event on XSSO start. Change-Id: Ic1833dc85b7b29259069335bbce26d388ca83d32 CRs-fixed: 2074685
This commit is contained in:
parent
ccd6716531
commit
e21e18a836
2 changed files with 106 additions and 198 deletions
|
@ -57,6 +57,12 @@ using namespace loc_core;
|
|||
#define LOG_TAG "LocSvc_XSSO"
|
||||
|
||||
bool XtraSystemStatusObserver::updateLockStatus(uint32_t lock) {
|
||||
mGpsLock = lock;
|
||||
|
||||
if (!mReqStatusReceived) {
|
||||
return true;
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
ss << "gpslock";
|
||||
ss << " " << lock;
|
||||
|
@ -64,13 +70,34 @@ bool XtraSystemStatusObserver::updateLockStatus(uint32_t lock) {
|
|||
}
|
||||
|
||||
bool XtraSystemStatusObserver::updateConnectionStatus(bool connected, int32_t type) {
|
||||
if (connected) {
|
||||
mConnections.insert(type);
|
||||
} else {
|
||||
if (-1 == type) { // -1 for disconnecting all connections
|
||||
mConnections.clear();
|
||||
} else {
|
||||
mConnections.erase(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mReqStatusReceived) {
|
||||
return true;
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
ss << "connection";
|
||||
ss << " " << (connected ? "1" : "0");
|
||||
ss << " " << type;
|
||||
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();
|
||||
|
@ -78,6 +105,12 @@ bool XtraSystemStatusObserver::updateTac(const string& tac) {
|
|||
}
|
||||
|
||||
bool XtraSystemStatusObserver::updateMccMnc(const string& mccmnc) {
|
||||
mMccmnc = mccmnc;
|
||||
|
||||
if (!mReqStatusReceived) {
|
||||
return true;
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
ss << "mncmcc";
|
||||
ss << " " << mccmnc.c_str();
|
||||
|
@ -85,16 +118,67 @@ bool XtraSystemStatusObserver::updateMccMnc(const string& mccmnc) {
|
|||
}
|
||||
|
||||
bool XtraSystemStatusObserver::updateXtraThrottle(const bool enabled) {
|
||||
mXtraThrottle = enabled;
|
||||
|
||||
if (!mReqStatusReceived) {
|
||||
return true;
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
ss << "xtrathrottle";
|
||||
ss << " " << (enabled ? 1 : 0);
|
||||
return ( send(LOC_IPC_XTRA, ss.str()) );
|
||||
}
|
||||
|
||||
static inline ostream& operator<<(ostream& os, CONNECTIONS& data) {
|
||||
for (auto elem : data) {
|
||||
os << elem << ' ';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
inline bool XtraSystemStatusObserver::onStatusRequested(int32_t xtraStatusUpdated) {
|
||||
mReqStatusReceived = true;
|
||||
|
||||
if (xtraStatusUpdated) {
|
||||
return true;
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
|
||||
ss << "respondStatus" << endl;
|
||||
(mGpsLock == -1 ? ss : ss << mGpsLock) << endl << mConnections << endl
|
||||
<< mTac << endl << mMccmnc;
|
||||
|
||||
return ( send(LOC_IPC_XTRA, ss.str()) );
|
||||
}
|
||||
|
||||
void XtraSystemStatusObserver::onReceive(const std::string& data) {
|
||||
if (!strncmp(data.c_str(), "ping", sizeof("ping") - 1)) {
|
||||
LOC_LOGd("ping received");
|
||||
|
||||
#ifdef USE_GLIB
|
||||
} else if (!strncmp(data.c_str(), "connectBackhaul", sizeof("connectBackhaul") - 1)) {
|
||||
mSystemStatusObsrvr->connectBackhaul();
|
||||
|
||||
} else if (!strncmp(data.c_str(), "disconnectBackhaul", sizeof("disconnectBackhaul") - 1)) {
|
||||
mSystemStatusObsrvr->disconnectBackhaul();
|
||||
#endif
|
||||
|
||||
} else if (!strncmp(data.c_str(), "requestStatus", sizeof("requestStatus") - 1)) {
|
||||
int32_t xtraStatusUpdated = 0;
|
||||
sscanf(data.c_str(), "%*s %d", &xtraStatusUpdated);
|
||||
|
||||
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));
|
||||
|
||||
} else {
|
||||
LOC_LOGw("unknown event: %s", data.c_str());
|
||||
}
|
||||
|
@ -191,129 +275,3 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
|
|||
};
|
||||
mMsgTask->sendMsg(new (nothrow) HandleOsObserverUpdateMsg(this, dlist));
|
||||
}
|
||||
|
||||
#ifdef USE_GLIB
|
||||
bool XtraSystemStatusObserver::connectBackhaul()
|
||||
{
|
||||
return mSystemStatusObsrvr->connectBackhaul();
|
||||
}
|
||||
|
||||
bool XtraSystemStatusObserver::disconnectBackhaul()
|
||||
{
|
||||
return mSystemStatusObsrvr->disconnectBackhaul();
|
||||
}
|
||||
|
||||
// XtraHalListenerSocket class
|
||||
// TBD - this will be removed once bidirectional socket changes in
|
||||
// xtra-daemon will be implemented
|
||||
void XtraHalListenerSocket::receiveData(const int socketFd) {
|
||||
string data;
|
||||
array<char, 128> buf;
|
||||
const char* bin_msg_conn_backhaul = "connectBackhaul";
|
||||
const char* bin_msg_disconn_backhaul = "disconnectBackhaul";
|
||||
|
||||
while (true) {
|
||||
ssize_t len = recv(socketFd, buf.data(), buf.size(), 0);
|
||||
if (len > 0) {
|
||||
LOC_LOGd("received %lu bytes", len);
|
||||
data.append(buf.data(), len);
|
||||
|
||||
size_t pos = data.find("\n");
|
||||
if (pos == string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strncmp(data.c_str(), bin_msg_conn_backhaul,
|
||||
sizeof(bin_msg_conn_backhaul) - 1)) {
|
||||
mSystemStatusObsrvr->connectBackhaul();
|
||||
} else if (!strncmp(data.c_str(), bin_msg_disconn_backhaul,
|
||||
sizeof(bin_msg_disconn_backhaul) - 1)) {
|
||||
mSystemStatusObsrvr->disconnectBackhaul();
|
||||
}
|
||||
else {
|
||||
LOC_LOGw("unknown event: %s", data.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
} else {
|
||||
LOC_LOGd("XtraHalListenerSocket connection broken.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XtraHalListenerSocket::startListenerThread() {
|
||||
mThread = new (std::nothrow) LocThread();
|
||||
if (!mThread) {
|
||||
LOC_LOGe("create thread failed");
|
||||
}
|
||||
mRunning = true;
|
||||
if (!mThread->start("XtraHalListenerSocketThread", this, true)) {
|
||||
delete mThread;
|
||||
mThread = NULL;
|
||||
}
|
||||
|
||||
LOC_LOGd("Create listener socket in XtraHalListenerSocket");
|
||||
// create socket
|
||||
int socketFd;
|
||||
if ((socketFd = ::socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
LOC_LOGe("create socket error. reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
const char* socketPath = "/data/vendor/location/xtra/socket_xtra_locnetiface";
|
||||
unlink(socketPath);
|
||||
|
||||
struct sockaddr_un addr = { .sun_family = AF_UNIX };
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socketPath);
|
||||
|
||||
umask(0157);
|
||||
|
||||
if (::bind(socketFd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
LOC_LOGe("bind socket error. reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
// set up connection
|
||||
if (::listen(socketFd, 5/*backlog*/) < 0) {
|
||||
LOC_LOGe("cannot bind socket. reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
mSocketFd = socketFd;
|
||||
|
||||
}
|
||||
|
||||
bool XtraHalListenerSocket::run() {
|
||||
// infinite while loop till mRunning is false when stopListenXtraDaemon
|
||||
// is called
|
||||
while (mRunning) {
|
||||
int clientFd = -1;
|
||||
LOC_LOGd("XtraHalListenerSocket - waiting for msg...");
|
||||
if ( (clientFd = ::accept(mSocketFd, NULL, NULL)) < 0) {
|
||||
LOC_LOGe("connection error. reason:%s", strerror(errno));
|
||||
} else {
|
||||
LOC_LOGd("XtraHalListenerSocket - receiving data ...");
|
||||
receiveData(clientFd);
|
||||
if (::close(clientFd)) {
|
||||
LOC_LOGe("close connection fail.");
|
||||
}
|
||||
clientFd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// return false once we reach there
|
||||
return false;
|
||||
}
|
||||
|
||||
void XtraHalListenerSocket::stopListenXtraDaemon() {
|
||||
if (mSocketFd >= 0) {
|
||||
if (::close(mSocketFd)) {
|
||||
LOC_LOGe("close hal connection fail.");
|
||||
}
|
||||
mSocketFd = -1;
|
||||
}
|
||||
mRunning = false;
|
||||
mThread->stop();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,81 +31,27 @@
|
|||
|
||||
#include <cinttypes>
|
||||
#include <MsgTask.h>
|
||||
#ifdef USE_GLIB
|
||||
#include <LocThread.h>
|
||||
#endif
|
||||
#include <LocIpc.h>
|
||||
#include <LocTimer.h>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
using loc_core::IOsObserver;
|
||||
using loc_core::IDataItemObserver;
|
||||
using loc_core::IDataItemCore;
|
||||
using loc_util::LocIpc;
|
||||
|
||||
#ifdef USE_GLIB
|
||||
// XtraHalListenerSocket class
|
||||
// listener socket for getting msgs from xtra-daemon in LE for invoking
|
||||
// LocNetIface functions
|
||||
// TBD - this will be removed once bidirectional socket changes in
|
||||
// xtra-daemon will be implemented
|
||||
class XtraHalListenerSocket: public LocRunnable {
|
||||
public :
|
||||
// constructor & destructor
|
||||
XtraHalListenerSocket(IOsObserver* sysStatObs) :
|
||||
mThread(NULL),
|
||||
mRunning(false) {
|
||||
mSystemStatusObsrvr = sysStatObs;
|
||||
mRunning = true;
|
||||
// create listener socket in a thread
|
||||
startListenerThread();
|
||||
}
|
||||
XtraHalListenerSocket() {}
|
||||
inline virtual ~XtraHalListenerSocket() {
|
||||
if (mThread) {
|
||||
stopListenXtraDaemon();
|
||||
delete mThread;
|
||||
mThread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Overrides of LocRunnable methods
|
||||
// This method will be repeated called until it returns false; or
|
||||
// until thread is stopped.
|
||||
virtual bool run();
|
||||
|
||||
// The method to be run before thread loop (conditionally repeatedly)
|
||||
// calls run()
|
||||
inline virtual void prerun() {}
|
||||
|
||||
// The method to be run after thread loop (conditionally repeatedly)
|
||||
// calls run()
|
||||
inline virtual void postrun() {}
|
||||
|
||||
private:
|
||||
IOsObserver* mSystemStatusObsrvr;
|
||||
int mSocketFd;
|
||||
LocThread* mThread;
|
||||
bool mRunning;
|
||||
void startListenerThread();
|
||||
void stopListenXtraDaemon();
|
||||
void receiveData(const int socketFd);
|
||||
};
|
||||
#endif
|
||||
using CONNECTIONS = set<int32_t>;
|
||||
|
||||
class XtraSystemStatusObserver : public IDataItemObserver, public LocIpc{
|
||||
public :
|
||||
// constructor & destructor
|
||||
inline XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask):
|
||||
#ifdef USE_GLIB
|
||||
mHalListenerSocket(sysStatObs),
|
||||
#endif
|
||||
mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask) {
|
||||
mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask),
|
||||
mGpsLock(-1), mXtraThrottle(true), mReqStatusReceived(false), mDelayLocTimer(*this) {
|
||||
subscribe(true);
|
||||
startListeningNonBlocking(LOC_IPC_HAL);
|
||||
mDelayLocTimer.start(100 /*.1 sec*/, false);
|
||||
}
|
||||
inline XtraSystemStatusObserver() {
|
||||
startListeningNonBlocking(LOC_IPC_HAL);
|
||||
};
|
||||
inline virtual ~XtraSystemStatusObserver() {
|
||||
subscribe(false);
|
||||
stopListening();
|
||||
|
@ -115,12 +61,6 @@ public :
|
|||
inline virtual void getName(string& name);
|
||||
virtual void notify(const list<IDataItemCore*>& dlist);
|
||||
|
||||
#ifdef USE_GLIB
|
||||
// IFrameworkActionReq functions reqd
|
||||
virtual bool connectBackhaul();
|
||||
virtual bool disconnectBackhaul();
|
||||
#endif
|
||||
|
||||
bool updateLockStatus(uint32_t lock);
|
||||
bool updateConnectionStatus(bool connected, int32_t type);
|
||||
bool updateTac(const string& tac);
|
||||
|
@ -134,13 +74,23 @@ public :
|
|||
private:
|
||||
IOsObserver* mSystemStatusObsrvr;
|
||||
const MsgTask* mMsgTask;
|
||||
#ifdef USE_GLIB
|
||||
// XtraHalListenerSocket class
|
||||
// TBD - this will be removed once bidirectional socket changes in
|
||||
// xtra-daemon will be implemented
|
||||
XtraHalListenerSocket mHalListenerSocket;
|
||||
#endif
|
||||
int32_t mGpsLock;
|
||||
CONNECTIONS mConnections;
|
||||
string mTac;
|
||||
string mMccmnc;
|
||||
bool mXtraThrottle;
|
||||
bool mReqStatusReceived;
|
||||
|
||||
class DelayLocTimer : public LocTimer {
|
||||
XtraSystemStatusObserver& mXSSO;
|
||||
public:
|
||||
DelayLocTimer(XtraSystemStatusObserver& xsso) : mXSSO(xsso) {}
|
||||
void timeOutCallback() override {
|
||||
mXSSO.send(LOC_IPC_XTRA, "halinit");
|
||||
}
|
||||
} mDelayLocTimer;
|
||||
|
||||
bool onStatusRequested(int32_t xtraStatusUpdated);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue