Merge "moving AGnssCbIface from static to class member"

This commit is contained in:
Linux Build Service Account 2018-02-26 13:28:20 -08:00 committed by Gerrit - the friendly Code Review server
commit 92b643d3ba
2 changed files with 24 additions and 7 deletions

View file

@ -30,12 +30,23 @@ namespace gnss {
namespace V1_0 { namespace V1_0 {
namespace implementation { namespace implementation {
sp<IAGnssCallback> AGnss::sAGnssCbIface = nullptr; static AGnss* spAGnss = nullptr;
AGnss::AGnss(Gnss* gnss) : mGnss(gnss) { AGnss::AGnss(Gnss* gnss) : mGnss(gnss) {
spAGnss = this;
}
AGnss::~AGnss() {
spAGnss = nullptr;
} }
void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){ void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){
if (nullptr != spAGnss) {
spAGnss->statusIpV4Cb(status);
}
}
void AGnss::statusIpV4Cb(AGnssExtStatusIpV4 status) {
IAGnssCallback::AGnssStatusIpV4 st = {}; IAGnssCallback::AGnssStatusIpV4 st = {};
switch (status.type) { switch (status.type) {
@ -72,9 +83,13 @@ void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){
} }
st.ipV4Addr = status.ipV4Addr; st.ipV4Addr = status.ipV4Addr;
auto r = sAGnssCbIface->agnssStatusIpV4Cb(st); if (mAGnssCbIface != nullptr) {
auto r = mAGnssCbIface->agnssStatusIpV4Cb(st);
if (!r.isOk()) { if (!r.isOk()) {
LOC_LOGE("Error invoking AGNSS status cb %s", r.description().c_str()); LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str());
}
} else {
LOC_LOGw("setCallback has not been called yet");
} }
} }
@ -86,7 +101,7 @@ Return<void> AGnss::setCallback(const sp<IAGnssCallback>& callback) {
} }
// Save the interface // Save the interface
sAGnssCbIface = callback; mAGnssCbIface = callback;
AgpsCbInfo cbInfo = {}; AgpsCbInfo cbInfo = {};
cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb;

View file

@ -43,7 +43,7 @@ struct Gnss;
struct AGnss : public IAGnss { struct AGnss : public IAGnss {
AGnss(Gnss* gnss); AGnss(Gnss* gnss);
~AGnss() = default; ~AGnss();
/* /*
* Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow. * Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow.
* These declarations were generated from IAGnss.hal. * These declarations were generated from IAGnss.hal.
@ -60,12 +60,14 @@ struct AGnss : public IAGnss {
Return<bool> setServer(IAGnssCallback::AGnssType type, Return<bool> setServer(IAGnssCallback::AGnssType type,
const hidl_string& hostname, int32_t port) override; const hidl_string& hostname, int32_t port) override;
void statusIpV4Cb(AGnssExtStatusIpV4 status);
/* Data call setup callback passed down to GNSS HAL implementation */ /* Data call setup callback passed down to GNSS HAL implementation */
static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status); static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status);
private: private:
Gnss* mGnss = nullptr; Gnss* mGnss = nullptr;
static sp<IAGnssCallback> sAGnssCbIface; sp<IAGnssCallback> mAGnssCbIface = nullptr;
}; };
} // namespace implementation } // namespace implementation