Merge "Integrate XtraSysStatObs with SystemStatusObserver"
This commit is contained in:
commit
099f9405b1
9 changed files with 921 additions and 797 deletions
|
@ -37,6 +37,7 @@
|
|||
#include <platform_lib_log_util.h>
|
||||
#include <MsgTask.h>
|
||||
#include <loc_nmea.h>
|
||||
#include <DataItemsFactoryProxy.h>
|
||||
#include <SystemStatus.h>
|
||||
#include <SystemStatusOsObserver.h>
|
||||
|
||||
|
@ -1212,7 +1213,8 @@ IOsObserver* SystemStatus::getOsObserver()
|
|||
}
|
||||
|
||||
SystemStatus::SystemStatus(const MsgTask* msgTask) :
|
||||
mSysStatusObsvr(msgTask)
|
||||
mSysStatusObsvr(msgTask),
|
||||
mConnected(false)
|
||||
{
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
|
@ -1413,6 +1415,28 @@ bool SystemStatus::setPositionFailure(const SystemStatusPQWS1& nmea)
|
|||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
SystemStatus - storing dataitems
|
||||
******************************************************************************/
|
||||
bool SystemStatus::setNetworkInfo(IDataItemCore* dataitem)
|
||||
{
|
||||
SystemStatusNetworkInfo* data = reinterpret_cast<SystemStatusNetworkInfo*>(dataitem);
|
||||
SystemStatusNetworkInfo s(data->mType,data->mTypeName,data->mSubTypeName,
|
||||
data->mAvailable,data->mConnected,data->mRoaming);
|
||||
s.dump();
|
||||
mConnected = data->mConnected;
|
||||
|
||||
if (!mCache.mNetworkInfo.empty() && mCache.mNetworkInfo.back().equals(s)) {
|
||||
mCache.mNetworkInfo.back().mUtcReported = s.mUtcReported;
|
||||
} else {
|
||||
mCache.mNetworkInfo.push_back(s);
|
||||
if (mCache.mNetworkInfo.size() > maxNetworkInfo) {
|
||||
mCache.mNetworkInfo.erase(mCache.mNetworkInfo.begin());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@brief API to set report data into internal buffer
|
||||
|
||||
|
@ -1533,6 +1557,26 @@ bool SystemStatus::eventPosition(const UlpLocation& location,
|
|||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@brief API to set report DataItem event into internal buffer
|
||||
|
||||
@param[In] DataItem
|
||||
|
||||
@return true when successfully done
|
||||
******************************************************************************/
|
||||
bool SystemStatus::eventDataItemNotify(IDataItemCore* dataitem)
|
||||
{
|
||||
pthread_mutex_lock(&mMutexSystemStatus);
|
||||
switch(dataitem->getId())
|
||||
{
|
||||
case NETWORKINFO_DATA_ITEM_ID:
|
||||
setNetworkInfo(dataitem);
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&mMutexSystemStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@brief API to get report data into a given buffer
|
||||
|
||||
|
@ -1712,5 +1756,33 @@ bool SystemStatus::setDefaultReport(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@brief API to handle connection status update event from GnssRil
|
||||
|
||||
@param[In] Connection status
|
||||
|
||||
@return true when successfully done
|
||||
******************************************************************************/
|
||||
bool SystemStatus::eventConnectionStatus(bool connected, uint8_t type)
|
||||
{
|
||||
if (connected != mConnected) {
|
||||
mConnected = connected;
|
||||
|
||||
// send networkinof dataitem to systemstatus observer clients
|
||||
SystemStatusNetworkInfo s(type, "", "", false, connected, false);
|
||||
IDataItemCore *networkinfo =
|
||||
DataItemsFactoryProxy::createNewDataItem(NETWORKINFO_DATA_ITEM_ID);
|
||||
if (nullptr == networkinfo) {
|
||||
LOC_LOGE("Unable to create dataitemd");
|
||||
return false;
|
||||
}
|
||||
networkinfo->copy(&s);
|
||||
list<IDataItemCore*> dl(0);
|
||||
dl.push_back(networkinfo);
|
||||
mSysStatusObsvr.notify(dl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace loc_core
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <vector>
|
||||
#include <platform_lib_log_util.h>
|
||||
#include <MsgTask.h>
|
||||
#include <IDataItemCore.h>
|
||||
#include <IOsObserver.h>
|
||||
#include <SystemStatusOsObserver.h>
|
||||
|
||||
|
@ -367,19 +368,183 @@ public:
|
|||
void dump(void);
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
SystemStatus report data structure - from DataItem observer
|
||||
******************************************************************************/
|
||||
class SystemStatusGpsState : public SystemStatusItemBase, public IDataItemCore
|
||||
{
|
||||
public:
|
||||
inline SystemStatusGpsState() :
|
||||
mEnabled(false) {}
|
||||
inline SystemStatusGpsState(bool enabled) :
|
||||
mEnabled(enabled) {}
|
||||
|
||||
bool mEnabled;
|
||||
|
||||
inline bool equals(SystemStatusGpsState& peer) {
|
||||
return (mEnabled == peer.mEnabled);
|
||||
}
|
||||
inline void dump(void) {
|
||||
LOC_LOGD("GpsState: state=%u", mEnabled);
|
||||
}
|
||||
inline DataItemId getId() {
|
||||
return GPSSTATE_DATA_ITEM_ID;
|
||||
}
|
||||
inline void stringify(string& valueStr) {
|
||||
valueStr.clear();
|
||||
valueStr += "GpsState: enabled=";
|
||||
valueStr += to_string(mEnabled);
|
||||
}
|
||||
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
|
||||
SystemStatusGpsState* gpsstate = static_cast<SystemStatusGpsState*>(src);
|
||||
mEnabled = gpsstate->mEnabled;
|
||||
if (dataItemCopied) {
|
||||
*dataItemCopied = true;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
class SystemStatusNetworkInfo : public SystemStatusItemBase, public IDataItemCore
|
||||
{
|
||||
public:
|
||||
inline SystemStatusNetworkInfo() :
|
||||
mType(0),
|
||||
mTypeName(""),
|
||||
mSubTypeName(""),
|
||||
mAvailable(false),
|
||||
mConnected(false),
|
||||
mRoaming(false) {}
|
||||
inline SystemStatusNetworkInfo(
|
||||
uint32_t type,
|
||||
std::string typeName,
|
||||
std::string subTypeName,
|
||||
bool available,
|
||||
bool connected,
|
||||
bool roaming) :
|
||||
mType(type),
|
||||
mTypeName(typeName),
|
||||
mSubTypeName(subTypeName),
|
||||
mAvailable(available),
|
||||
mConnected(connected),
|
||||
mRoaming(roaming) {}
|
||||
|
||||
uint32_t mType;
|
||||
std::string mTypeName;
|
||||
std::string mSubTypeName;
|
||||
bool mAvailable;
|
||||
bool mConnected;
|
||||
bool mRoaming;
|
||||
|
||||
inline bool equals(SystemStatusNetworkInfo& peer) {
|
||||
if ((mType != peer.mType) ||
|
||||
(mTypeName != peer.mTypeName) ||
|
||||
(mSubTypeName != peer.mSubTypeName) ||
|
||||
(mAvailable != peer.mAvailable) ||
|
||||
(mConnected != peer.mConnected) ||
|
||||
(mRoaming != peer.mRoaming)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
inline void dump(void) {
|
||||
LOC_LOGD("NetworkInfo: type=%u connected=%u", mType, mConnected);
|
||||
}
|
||||
inline DataItemId getId() {
|
||||
return NETWORKINFO_DATA_ITEM_ID;
|
||||
}
|
||||
inline void stringify(string& /*valueStr*/) { }
|
||||
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
|
||||
SystemStatusNetworkInfo* networkinfo = static_cast<SystemStatusNetworkInfo*>(src);
|
||||
mType = networkinfo->mType;
|
||||
mTypeName = networkinfo->mTypeName;
|
||||
mSubTypeName = networkinfo->mSubTypeName;
|
||||
mAvailable = networkinfo->mAvailable;
|
||||
mConnected = networkinfo->mConnected;
|
||||
mRoaming = networkinfo->mRoaming;
|
||||
if (dataItemCopied) {
|
||||
*dataItemCopied = true;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
class SystemStatusTac : public SystemStatusItemBase, public IDataItemCore
|
||||
{
|
||||
public:
|
||||
inline SystemStatusTac() :
|
||||
mValue("") {}
|
||||
inline SystemStatusTac(std::string value) :
|
||||
mValue(value) {}
|
||||
|
||||
std::string mValue;
|
||||
|
||||
inline bool equals(SystemStatusTac& peer) {
|
||||
return (mValue == peer.mValue);
|
||||
}
|
||||
inline void dump(void) {
|
||||
LOC_LOGD("Tac: value=%s", mValue.c_str());
|
||||
}
|
||||
inline DataItemId getId() {
|
||||
return TAC_DATA_ITEM_ID;
|
||||
}
|
||||
inline void stringify(string& /*valueStr*/) { }
|
||||
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
|
||||
SystemStatusTac* tac = static_cast<SystemStatusTac*>(src);
|
||||
mValue = tac->mValue;
|
||||
if (dataItemCopied) {
|
||||
*dataItemCopied = true;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
class SystemStatusMccMnc : public SystemStatusItemBase, public IDataItemCore
|
||||
{
|
||||
public:
|
||||
inline SystemStatusMccMnc() :
|
||||
mValue("") {}
|
||||
inline SystemStatusMccMnc(std::string value) :
|
||||
mValue(value) {}
|
||||
|
||||
std::string mValue;
|
||||
|
||||
inline bool equals(SystemStatusMccMnc& peer) {
|
||||
return (mValue == peer.mValue);
|
||||
}
|
||||
inline void dump(void) {
|
||||
LOC_LOGD("TacMccMnc value=%s", mValue.c_str());
|
||||
}
|
||||
inline DataItemId getId() {
|
||||
return MCCMNC_DATA_ITEM_ID;
|
||||
}
|
||||
inline void stringify(string& /*valueStr*/) { }
|
||||
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
|
||||
SystemStatusMccMnc* mccmnc = static_cast<SystemStatusMccMnc*>(src);
|
||||
mValue = mccmnc->mValue;
|
||||
if (dataItemCopied) {
|
||||
*dataItemCopied = true;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
SystemStatusReports
|
||||
******************************************************************************/
|
||||
class SystemStatusReports
|
||||
{
|
||||
public:
|
||||
// from QMI_LOC indication
|
||||
std::vector<SystemStatusLocation> mLocation;
|
||||
|
||||
// from ME debug NMEA
|
||||
std::vector<SystemStatusTimeAndClock> mTimeAndClock;
|
||||
std::vector<SystemStatusXoState> mXoState;
|
||||
std::vector<SystemStatusRfAndParams> mRfAndParams;
|
||||
std::vector<SystemStatusErrRecovery> mErrRecovery;
|
||||
|
||||
// from PE debug NMEA
|
||||
std::vector<SystemStatusInjectedPosition> mInjectedPosition;
|
||||
std::vector<SystemStatusBestPosition> mBestPosition;
|
||||
std::vector<SystemStatusXtra> mXtra;
|
||||
|
@ -388,7 +553,14 @@ public:
|
|||
std::vector<SystemStatusPdr> mPdr;
|
||||
std::vector<SystemStatusNavData> mNavData;
|
||||
|
||||
// from SM debug NMEA
|
||||
std::vector<SystemStatusPositionFailure> mPositionFailure;
|
||||
|
||||
// from dataitems observer
|
||||
std::vector<SystemStatusGpsState> mGpsState;
|
||||
std::vector<SystemStatusNetworkInfo> mNetworkInfo;
|
||||
std::vector<SystemStatusTac> mTac;
|
||||
std::vector<SystemStatusMccMnc> mMccMnc;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -424,7 +596,13 @@ private:
|
|||
|
||||
static const uint32_t maxPositionFailure = 5;
|
||||
|
||||
static const uint32_t maxGpsState = 5;
|
||||
static const uint32_t maxNetworkInfo = 5;
|
||||
static const uint32_t maxTac = 5;
|
||||
static const uint32_t maxMccMnc = 5;
|
||||
|
||||
SystemStatusReports mCache;
|
||||
bool mConnected;
|
||||
|
||||
bool setLocation(const UlpLocation& location);
|
||||
|
||||
|
@ -443,6 +621,8 @@ private:
|
|||
|
||||
bool setPositionFailure(const SystemStatusPQWS1& nmea);
|
||||
|
||||
bool setNetworkInfo(IDataItemCore* dataitem);
|
||||
|
||||
public:
|
||||
// Static methods
|
||||
static SystemStatus* getInstance(const MsgTask* msgTask);
|
||||
|
@ -451,9 +631,11 @@ public:
|
|||
|
||||
// Helpers
|
||||
bool eventPosition(const UlpLocation& location,const GpsLocationExtended& locationEx);
|
||||
bool eventDataItemNotify(IDataItemCore* dataitem);
|
||||
bool setNmeaString(const char *data, uint32_t len);
|
||||
bool getReport(SystemStatusReports& reports, bool isLatestonly = false) const;
|
||||
bool setDefaultReport(void);
|
||||
bool eventConnectionStatus(bool connected, uint8_t type);
|
||||
};
|
||||
|
||||
} // namespace loc_core
|
||||
|
|
|
@ -28,47 +28,23 @@
|
|||
*/
|
||||
#define LOG_TAG "LocSvc_SystemStatusOsObserver"
|
||||
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <pthread.h>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
#include <MsgTask.h>
|
||||
#include <SystemStatus.h>
|
||||
#include <SystemStatusOsObserver.h>
|
||||
|
||||
#include <DataItemId.h>
|
||||
#include <IDataItemCore.h>
|
||||
#include <IClientIndex.h>
|
||||
#include <IDataItemIndex.h>
|
||||
#include <IndexFactory.h>
|
||||
|
||||
#include <DataItemsFactoryProxy.h>
|
||||
|
||||
#include <platform_lib_log_util.h>
|
||||
|
||||
namespace loc_core
|
||||
{
|
||||
#define BREAK_IF_ZERO(ERR,X) if(0==(X)) {result = (ERR); break;}
|
||||
#define BREAK_IF_NON_ZERO(ERR,X) if(0!=(X)) {result = (ERR); break;}
|
||||
|
||||
SystemStatusOsObserver::SystemStatusOsObserver(const MsgTask* msgTask) :
|
||||
mAddress("SystemStatusOsObserver"),
|
||||
mClientIndex(IndexFactory<IDataItemObserver*, DataItemId> :: createClientIndex()),
|
||||
mDataItemIndex(IndexFactory<IDataItemObserver*, DataItemId> :: createDataItemIndex())
|
||||
{
|
||||
int result = -1;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
BREAK_IF_ZERO (1, mClientIndex);
|
||||
BREAK_IF_ZERO (2, mDataItemIndex);
|
||||
mContext.mMsgTask = msgTask;
|
||||
result = 0;
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
|
||||
SystemStatusOsObserver::~SystemStatusOsObserver()
|
||||
|
@ -77,410 +53,394 @@ SystemStatusOsObserver :: ~SystemStatusOsObserver ()
|
|||
DataItemsFactoryProxy::closeDataItemLibraryHandle();
|
||||
|
||||
// Destroy cache
|
||||
map <DataItemId, IDataItemCore *> :: iterator citer = mDataItemCache.begin ();
|
||||
for (; citer != mDataItemCache.end (); ++citer) {
|
||||
if (citer->second != NULL) { delete citer->second; }
|
||||
for (auto each : mDataItemCache) {
|
||||
if (nullptr != each.second) {
|
||||
delete each.second;
|
||||
}
|
||||
}
|
||||
|
||||
mDataItemCache.clear();
|
||||
delete mClientIndex;
|
||||
delete mDataItemIndex;
|
||||
mClientIndex = NULL;
|
||||
mDataItemIndex = NULL;
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver::setSubscriptionObj(IDataItemSubscription* subscriptionObj)
|
||||
{
|
||||
mContext.mSubscriptionObj = subscriptionObj;
|
||||
|
||||
LOC_LOGD("Request cache size - Subscribe:%zu RequestData:%zu",
|
||||
mSubscribeReqCache.size(), mReqDataCache.size());
|
||||
|
||||
// we have received the subscription object. process cached requests
|
||||
// process - subscribe request cache
|
||||
for (auto each : mSubscribeReqCache) {
|
||||
subscribe(each.second, each.first);
|
||||
}
|
||||
// process - requestData request cache
|
||||
for (auto each : mReqDataCache) {
|
||||
requestData(each.second, each.first);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to cache requests subscribe and requestData till subscription obj is obtained
|
||||
void SystemStatusOsObserver::cacheObserverRequest(ObserverReqCache& reqCache,
|
||||
const list<DataItemId>& l, IDataItemObserver* client)
|
||||
{
|
||||
ObserverReqCache::iterator dicIter = reqCache.find(client);
|
||||
if (dicIter != reqCache.end()) {
|
||||
// found
|
||||
list<DataItemId> difference(0);
|
||||
set_difference(l.begin(), l.end(),
|
||||
dicIter->second.begin(), dicIter->second.end(),
|
||||
inserter(difference, difference.begin()));
|
||||
if (!difference.empty()) {
|
||||
difference.sort();
|
||||
dicIter->second.merge(difference);
|
||||
dicIter->second.unique();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// not found
|
||||
reqCache[client] = l;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
Message proc
|
||||
IDataItemSubscription Overrides
|
||||
******************************************************************************/
|
||||
void SystemStatusOsObserver :: HandleSubscribeReq :: proc () const {
|
||||
void SystemStatusOsObserver::subscribe(
|
||||
const list<DataItemId>& l, IDataItemObserver* client)
|
||||
{
|
||||
if (nullptr == mContext.mSubscriptionObj) {
|
||||
LOC_LOGD("%s]: Subscription object is NULL. Caching requests", __func__);
|
||||
cacheObserverRequest(mSubscribeReqCache, l, client);
|
||||
return;
|
||||
}
|
||||
|
||||
struct HandleSubscribeReq : public LocMsg {
|
||||
HandleSubscribeReq(SystemStatusOsObserver* parent,
|
||||
const list<DataItemId>& l, IDataItemObserver* client) :
|
||||
mParent(parent), mClient(client), mDataItemList(l) {}
|
||||
virtual ~HandleSubscribeReq() {}
|
||||
void proc() const {
|
||||
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mDataItemList.empty()) {
|
||||
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
|
||||
result = 0;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
//mDataItemList.sort ();
|
||||
|
||||
// Handle First Response
|
||||
list <DataItemId> pendingFirstResponseList;
|
||||
this->mParent->mClientIndex->add (this->mClient, mDataItemList, pendingFirstResponseList);
|
||||
list<DataItemId> pendingFirstResponseList(0);
|
||||
mParent->mClientIndex->add(mClient, mDataItemList, pendingFirstResponseList);
|
||||
|
||||
// Do not send first response for only pendingFirstResponseList,
|
||||
// instead send for all the data items (present in the cache) that
|
||||
// have been subscribed for each time.
|
||||
this->mParent->sendFirstResponse (mDataItemList, this->mClient);
|
||||
mParent->sendFirstResponse(mDataItemList, mClient);
|
||||
|
||||
list<DataItemId> yetToSubscribeDataItemsList(0);
|
||||
mParent->mDataItemIndex->add(mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
|
||||
list <DataItemId> yetToSubscribeDataItemsList;
|
||||
this->mParent->mDataItemIndex->add (this->mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
// Send subscription list to framework
|
||||
if (!yetToSubscribeDataItemsList.empty()) {
|
||||
this->mParent->mContext.mSubscriptionObj->subscribe
|
||||
(
|
||||
yetToSubscribeDataItemsList,
|
||||
this->mParent
|
||||
);
|
||||
LOC_LOGD ("Subscribe Request sent to framework for the following data items");
|
||||
this->mParent->logMe (yetToSubscribeDataItemsList);
|
||||
mParent->mContext.mSubscriptionObj->subscribe(yetToSubscribeDataItemsList, mParent);
|
||||
LOC_LOGD("Subscribe Request sent to framework for the following");
|
||||
mParent->logMe(yetToSubscribeDataItemsList);
|
||||
}
|
||||
}
|
||||
SystemStatusOsObserver* mParent;
|
||||
IDataItemObserver* mClient;
|
||||
const list<DataItemId> mDataItemList;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(new (nothrow) HandleSubscribeReq(this, l, client));
|
||||
}
|
||||
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
void SystemStatusOsObserver::updateSubscription(
|
||||
const list<DataItemId>& l, IDataItemObserver* client)
|
||||
{
|
||||
if (nullptr == mContext.mSubscriptionObj) {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleUpdateSubscriptionReq :: proc () const {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
struct HandleUpdateSubscriptionReq : public LocMsg {
|
||||
HandleUpdateSubscriptionReq(SystemStatusOsObserver* parent,
|
||||
const list<DataItemId>& l, IDataItemObserver* client) :
|
||||
mParent(parent), mClient(client), mDataItemList(l) {}
|
||||
virtual ~HandleUpdateSubscriptionReq() {}
|
||||
void proc() const {
|
||||
if (mDataItemList.empty()) {
|
||||
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
|
||||
result = 0;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
//mDataItemList.sort ();
|
||||
list <DataItemId> currentlySubscribedList;
|
||||
this->mParent->mClientIndex->getSubscribedList (this->mClient, currentlySubscribedList);
|
||||
list <DataItemId> removeDataItemList;
|
||||
|
||||
list<DataItemId> currentlySubscribedList(0);
|
||||
mParent->mClientIndex->getSubscribedList(mClient, currentlySubscribedList);
|
||||
|
||||
list<DataItemId> removeDataItemList(0);
|
||||
set_difference(currentlySubscribedList.begin(), currentlySubscribedList.end(),
|
||||
mDataItemList.begin(), mDataItemList.end(),
|
||||
inserter(removeDataItemList,removeDataItemList.begin()));
|
||||
// Handle First Response
|
||||
list <DataItemId> pendingFirstResponseList;
|
||||
this->mParent->mClientIndex->add (this->mClient, mDataItemList, pendingFirstResponseList);
|
||||
// Send First Response
|
||||
this->mParent->sendFirstResponse (pendingFirstResponseList, this->mClient);
|
||||
|
||||
list <DataItemId> yetToSubscribeDataItemsList;
|
||||
this->mParent->mDataItemIndex->add (this->mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
// Handle First Response
|
||||
list<DataItemId> pendingFirstResponseList(0);
|
||||
mParent->mClientIndex->add(mClient, mDataItemList, pendingFirstResponseList);
|
||||
|
||||
// Send First Response
|
||||
mParent->sendFirstResponse(pendingFirstResponseList, mClient);
|
||||
|
||||
list<DataItemId> yetToSubscribeDataItemsList(0);
|
||||
mParent->mDataItemIndex->add(
|
||||
mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
|
||||
// Send subscription list to framework
|
||||
if (!yetToSubscribeDataItemsList.empty()) {
|
||||
this->mParent->mContext.mSubscriptionObj->subscribe
|
||||
(
|
||||
yetToSubscribeDataItemsList,
|
||||
this->mParent
|
||||
);
|
||||
LOC_LOGD ("Subscribe Request sent to framework for the following data items");
|
||||
this->mParent->logMe (yetToSubscribeDataItemsList);
|
||||
mParent->mContext.mSubscriptionObj->subscribe(
|
||||
yetToSubscribeDataItemsList, mParent);
|
||||
LOC_LOGD("Subscribe Request sent to framework for the following");
|
||||
mParent->logMe(yetToSubscribeDataItemsList);
|
||||
}
|
||||
|
||||
list <DataItemId> unsubscribeList;
|
||||
list <DataItemId> unused;
|
||||
this->mParent->mClientIndex->remove (this->mClient, removeDataItemList, unused);
|
||||
list<DataItemId> unsubscribeList(0);
|
||||
list<DataItemId> unused(0);
|
||||
mParent->mClientIndex->remove(mClient, removeDataItemList, unused);
|
||||
|
||||
if (!this->mParent->mClientIndex->isSubscribedClient (this->mClient)) {
|
||||
this->mParent->mDataItemIndex->remove (list <IDataItemObserver *> (1,this->mClient), unsubscribeList);
|
||||
if (!mParent->mClientIndex->isSubscribedClient(mClient)) {
|
||||
mParent->mDataItemIndex->remove(
|
||||
list<IDataItemObserver*> (1,mClient), unsubscribeList);
|
||||
}
|
||||
if (!unsubscribeList.empty()) {
|
||||
// Send unsubscribe to framework
|
||||
this->mParent->mContext.mSubscriptionObj->unsubscribe
|
||||
(
|
||||
unsubscribeList,
|
||||
this->mParent
|
||||
);
|
||||
LOC_LOGD ("Unsubscribe Request sent to framework for the following data items");
|
||||
this->mParent->logMe (unsubscribeList);
|
||||
mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent);
|
||||
LOC_LOGD("Unsubscribe Request sent to framework for the following");
|
||||
mParent->logMe(unsubscribeList);
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
SystemStatusOsObserver* mParent;
|
||||
IDataItemObserver* mClient;
|
||||
const list<DataItemId> mDataItemList;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(new (nothrow) HandleUpdateSubscriptionReq(this, l, client));
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleRequestData :: proc () const {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
void SystemStatusOsObserver::requestData(
|
||||
const list<DataItemId>& l, IDataItemObserver* client)
|
||||
{
|
||||
if (nullptr == mContext.mSubscriptionObj) {
|
||||
LOC_LOGD("%s]: Subscription object is NULL. Caching requests", __func__);
|
||||
cacheObserverRequest(mReqDataCache, l, client);
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
struct HandleRequestData : public LocMsg {
|
||||
HandleRequestData(SystemStatusOsObserver* parent,
|
||||
const list<DataItemId>& l, IDataItemObserver* client) :
|
||||
mParent(parent), mClient(client), mDataItemList(l) {}
|
||||
virtual ~HandleRequestData() {}
|
||||
void proc() const {
|
||||
if (mDataItemList.empty()) {
|
||||
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
|
||||
result = 0;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
//mDataItemList.sort ();
|
||||
list <DataItemId> yetToSubscribeDataItemsList;
|
||||
this->mParent->mClientIndex->add (this->mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
this->mParent->mDataItemIndex->add (this->mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
|
||||
list<DataItemId> yetToSubscribeDataItemsList(0);
|
||||
mParent->mClientIndex->add(
|
||||
mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
mParent->mDataItemIndex->add(
|
||||
mClient, mDataItemList, yetToSubscribeDataItemsList);
|
||||
|
||||
// Send subscription list to framework
|
||||
if (!mDataItemList.empty()) {
|
||||
this->mParent->mContext.mSubscriptionObj->requestData
|
||||
(
|
||||
mDataItemList,
|
||||
this->mParent
|
||||
);
|
||||
LOC_LOGD ("Subscribe Request sent to framework for the following data items");
|
||||
this->mParent->logMe (yetToSubscribeDataItemsList);
|
||||
mParent->mContext.mSubscriptionObj->requestData(mDataItemList, mParent);
|
||||
LOC_LOGD("Subscribe Request sent to framework for the following");
|
||||
mParent->logMe(yetToSubscribeDataItemsList);
|
||||
}
|
||||
}
|
||||
SystemStatusOsObserver* mParent;
|
||||
IDataItemObserver* mClient;
|
||||
const list<DataItemId> mDataItemList;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(new (nothrow) HandleRequestData(this, l, client));
|
||||
}
|
||||
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
void SystemStatusOsObserver::unsubscribe(
|
||||
const list<DataItemId>& l, IDataItemObserver* client)
|
||||
{
|
||||
if (nullptr == mContext.mSubscriptionObj) {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleUnsubscribeReq :: proc () const {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
struct HandleUnsubscribeReq : public LocMsg {
|
||||
HandleUnsubscribeReq(SystemStatusOsObserver* parent,
|
||||
const list<DataItemId>& l, IDataItemObserver* client) :
|
||||
mParent(parent), mClient(client), mDataItemList(l) {}
|
||||
virtual ~HandleUnsubscribeReq() {}
|
||||
void proc() const {
|
||||
if (mDataItemList.empty()) {
|
||||
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
|
||||
result = 0;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
//mDataItemList.sort ();
|
||||
list <DataItemId> unsubscribeList;
|
||||
list <DataItemId> unused;
|
||||
this->mParent->mClientIndex->remove (this->mClient, mDataItemList, unused);
|
||||
|
||||
list <DataItemId> :: const_iterator it = mDataItemList.begin ();
|
||||
for (; it != mDataItemList.end (); ++it) {
|
||||
list <IDataItemObserver *> clientListSubs;
|
||||
list <IDataItemObserver *> clientListOut;
|
||||
this->mParent->mDataItemIndex->remove ((*it),
|
||||
list <IDataItemObserver *> (1,this->mClient), clientListOut);
|
||||
list<DataItemId> unsubscribeList(0);
|
||||
list<DataItemId> unused(0);
|
||||
mParent->mClientIndex->remove(mClient, mDataItemList, unused);
|
||||
|
||||
for (auto each : mDataItemList) {
|
||||
list<IDataItemObserver*> clientListSubs(0);
|
||||
list<IDataItemObserver*> clientListOut(0);
|
||||
mParent->mDataItemIndex->remove(
|
||||
each, list<IDataItemObserver*> (1,mClient), clientListOut);
|
||||
// check if there are any other subscribed client for this data item id
|
||||
this->mParent->mDataItemIndex->getListOfSubscribedClients ( (*it), clientListSubs);
|
||||
mParent->mDataItemIndex->getListOfSubscribedClients(each, clientListSubs);
|
||||
if (clientListSubs.empty())
|
||||
{
|
||||
LOC_LOGD ("Client list subscribed is empty for dataitem - %d",(*it));
|
||||
unsubscribeList.push_back((*it));
|
||||
LOC_LOGD("Client list subscribed is empty for dataitem - %d", each);
|
||||
unsubscribeList.push_back(each);
|
||||
}
|
||||
}
|
||||
|
||||
if (!unsubscribeList.empty()) {
|
||||
// Send unsubscribe to framework
|
||||
this->mParent->mContext.mSubscriptionObj->unsubscribe
|
||||
(
|
||||
unsubscribeList,
|
||||
this->mParent
|
||||
);
|
||||
mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent);
|
||||
LOC_LOGD("Unsubscribe Request sent to framework for the following data items");
|
||||
this->mParent->logMe (unsubscribeList);
|
||||
mParent->logMe(unsubscribeList);
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
SystemStatusOsObserver* mParent;
|
||||
IDataItemObserver* mClient;
|
||||
const list<DataItemId> mDataItemList;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(new (nothrow) HandleUnsubscribeReq(this, l, client));
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleUnsubscribeAllReq :: proc () const {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
list <IDataItemObserver *> clients (1, this->mClient);
|
||||
list <DataItemId> unsubscribeList;
|
||||
BREAK_IF_NON_ZERO (2, this->mParent->mClientIndex->remove (this->mClient));
|
||||
void SystemStatusOsObserver::unsubscribeAll(IDataItemObserver* client)
|
||||
{
|
||||
if (nullptr == mContext.mSubscriptionObj) {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
struct HandleUnsubscribeAllReq : public LocMsg {
|
||||
HandleUnsubscribeAllReq(SystemStatusOsObserver* parent,
|
||||
IDataItemObserver* client) :
|
||||
mParent(parent), mClient(client) {}
|
||||
virtual ~HandleUnsubscribeAllReq() {}
|
||||
void proc() const {
|
||||
list<IDataItemObserver*> clients(1, mClient);
|
||||
list<DataItemId> unsubscribeList(0);
|
||||
if(0 == mParent->mClientIndex->remove(mClient)) {
|
||||
return;
|
||||
}
|
||||
mParent->mDataItemIndex->remove(clients, unsubscribeList);
|
||||
|
||||
this->mParent->mDataItemIndex->remove (clients, unsubscribeList);
|
||||
if (!unsubscribeList.empty()) {
|
||||
// Send unsubscribe to framework
|
||||
this->mParent->mContext.mSubscriptionObj->unsubscribe
|
||||
(
|
||||
unsubscribeList,
|
||||
this->mParent
|
||||
);
|
||||
mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent);
|
||||
LOC_LOGD("Unsubscribe Request sent to framework for the following data items");
|
||||
this->mParent->logMe (unsubscribeList);
|
||||
mParent->logMe(unsubscribeList);
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
SystemStatusOsObserver* mParent;
|
||||
IDataItemObserver* mClient;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(new (nothrow) HandleUnsubscribeAllReq(this, client));
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleNotify :: getListOfClients
|
||||
(const list <DataItemId> & dlist, list <IDataItemObserver *> & clients ) const {
|
||||
/******************************************************************************
|
||||
IDataItemObserver Overrides
|
||||
******************************************************************************/
|
||||
void SystemStatusOsObserver::notify(const list<IDataItemCore*>& dlist)
|
||||
{
|
||||
list<IDataItemCore*> dataItemList(0);
|
||||
|
||||
list <DataItemId> :: const_iterator it = dlist.begin ();
|
||||
for (; it != dlist.end (); ++it) {
|
||||
list <IDataItemObserver *> clientList;
|
||||
this->mParent->mDataItemIndex->getListOfSubscribedClients ( (*it), clientList);
|
||||
list <IDataItemObserver *> :: iterator citer = clientList.begin ();
|
||||
for (; citer != clientList.end (); ++citer) {
|
||||
clients.push_back (*citer);
|
||||
}
|
||||
clientList.clear ();
|
||||
}
|
||||
// remove duplicates
|
||||
clients.unique ();
|
||||
for (auto each : dlist) {
|
||||
string dv;
|
||||
each->stringify(dv);
|
||||
LOC_LOGD("notify: DataItem In Value:%s", dv.c_str());
|
||||
|
||||
IDataItemCore* di = DataItemsFactoryProxy::createNewDataItem(each->getId());
|
||||
if (nullptr == di) {
|
||||
LOC_LOGE("Unable to create dataitem:%d", each->getId());
|
||||
return;
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleNotify :: proc () const {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
// Copy contents into the newly created data item
|
||||
di->copy(each);
|
||||
dataItemList.push_back(di);
|
||||
// Request systemstatus to record this dataitem in its cache
|
||||
SystemStatus* systemstatus = SystemStatus::getInstance(mContext.mMsgTask);
|
||||
if(nullptr != systemstatus) {
|
||||
systemstatus->eventDataItemNotify(di);
|
||||
}
|
||||
}
|
||||
|
||||
struct HandleNotify : public LocMsg {
|
||||
HandleNotify(SystemStatusOsObserver* parent, const list<IDataItemCore*>& l) :
|
||||
mParent(parent), mDList(l) {}
|
||||
virtual ~HandleNotify() {
|
||||
for (auto each : mDList) {
|
||||
delete each;
|
||||
}
|
||||
}
|
||||
void proc() const {
|
||||
// Update Cache with received data items and prepare
|
||||
// list of data items to be sent.
|
||||
list <IDataItemCore *> :: const_iterator it = mDList.begin ();
|
||||
list <DataItemId> dataItemIdsToBeSent;
|
||||
for (; it != mDList.end (); ++it) {
|
||||
list<DataItemId> dataItemIdsToBeSent(0);
|
||||
for (auto item : mDList) {
|
||||
bool dataItemUpdated = false;
|
||||
this->mParent->updateCache (*it, dataItemUpdated);
|
||||
mParent->updateCache(item, dataItemUpdated);
|
||||
if (dataItemUpdated) {
|
||||
dataItemIdsToBeSent.push_back ( (*it)->getId ());
|
||||
dataItemIdsToBeSent.push_back(item->getId());
|
||||
}
|
||||
}
|
||||
|
||||
list <IDataItemObserver *> clientList;
|
||||
this->getListOfClients (dataItemIdsToBeSent, clientList);
|
||||
list <IDataItemObserver *> :: iterator citer = clientList.begin ();
|
||||
// Send data item to all subscribed clients
|
||||
LOC_LOGD ("LocTech-Label :: SystemStatusOsObserver :: Data Items Out");
|
||||
for (; citer != clientList.end (); ++citer) {
|
||||
do {
|
||||
list <DataItemId> dataItemIdsSubscribedByThisClient;
|
||||
list <DataItemId> dataItemIdsToBeSentForThisClient;
|
||||
this->mParent->mClientIndex->getSubscribedList (*citer, dataItemIdsSubscribedByThisClient);
|
||||
list<IDataItemObserver*> clientList(0);
|
||||
for (auto each : dataItemIdsToBeSent) {
|
||||
list<IDataItemObserver*> clients(0);
|
||||
mParent->mDataItemIndex->getListOfSubscribedClients(each, clients);
|
||||
for (auto each_cient: clients) {
|
||||
clientList.push_back(each_cient);
|
||||
}
|
||||
}
|
||||
clientList.unique();
|
||||
|
||||
for (auto client : clientList) {
|
||||
list<DataItemId> dataItemIdsSubscribedByThisClient(0);
|
||||
list<DataItemId> dataItemIdsToBeSentForThisClient(0);
|
||||
mParent->mClientIndex->getSubscribedList(
|
||||
client, dataItemIdsSubscribedByThisClient);
|
||||
dataItemIdsSubscribedByThisClient.sort();
|
||||
dataItemIdsToBeSent.sort();
|
||||
|
||||
set_intersection(dataItemIdsToBeSent.begin(),
|
||||
dataItemIdsToBeSent.end(),
|
||||
dataItemIdsSubscribedByThisClient.begin(),
|
||||
dataItemIdsSubscribedByThisClient.end(),
|
||||
inserter(dataItemIdsToBeSentForThisClient,
|
||||
dataItemIdsToBeSentForThisClient.begin()));
|
||||
BREAK_IF_NON_ZERO (4,this->mParent->sendCachedDataItems (dataItemIdsToBeSentForThisClient, *citer));
|
||||
|
||||
mParent->sendCachedDataItems(dataItemIdsToBeSentForThisClient, client);
|
||||
dataItemIdsSubscribedByThisClient.clear();
|
||||
dataItemIdsToBeSentForThisClient.clear();
|
||||
} while (0);
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleTurnOn :: proc () const {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
// Send action turn on to framework
|
||||
this->mParent->mContext.mFrameworkActionReqObj->turnOn(mDataItemId, mTimeOut);
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: HandleTurnOff :: proc () const {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
// Send action turn off to framework
|
||||
this->mParent->mContext.mFrameworkActionReqObj->turnOff(mDataItemId);
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
IDataItemSubscription Overrides
|
||||
******************************************************************************/
|
||||
void SystemStatusOsObserver :: subscribe (const list <DataItemId> & l, IDataItemObserver * client) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mContext.mSubscriptionObj != NULL) {
|
||||
HandleSubscribeReq * msg = new (nothrow) HandleSubscribeReq (this, l, client);
|
||||
mContext.mMsgTask->sendMsg (msg);
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
result = 1;
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: updateSubscription (const list <DataItemId> & l, IDataItemObserver * client) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mContext.mSubscriptionObj != NULL) {
|
||||
mContext.mMsgTask->sendMsg (new (nothrow) HandleUpdateSubscriptionReq (this, l, client));
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
result = 1;
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: requestData (const list <DataItemId> & l, IDataItemObserver * client) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mContext.mSubscriptionObj != NULL) {
|
||||
mContext.mMsgTask->sendMsg (new (nothrow) HandleRequestData (this, l, client));
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
result = 1;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: unsubscribe (const list <DataItemId> & l, IDataItemObserver * client) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mContext.mSubscriptionObj != NULL) {
|
||||
mContext.mMsgTask->sendMsg (new (nothrow) HandleUnsubscribeReq (this, l, client));
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
result = 1;
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: unsubscribeAll (IDataItemObserver * client) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mContext.mSubscriptionObj != NULL) {
|
||||
mContext.mMsgTask->sendMsg (new (nothrow) HandleUnsubscribeAllReq (this, client));
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
|
||||
result = 1;
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d",result);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
IDataItemObserver Overrides
|
||||
******************************************************************************/
|
||||
void SystemStatusOsObserver::getName(string & name) {
|
||||
name = mAddress;
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver::notify(const std::list <IDataItemCore *> & dlist) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
list <IDataItemCore *> :: const_iterator it = dlist.begin ();
|
||||
list <IDataItemCore *> dataItemList;
|
||||
list <DataItemId> ids;
|
||||
LOC_LOGD("LocTech-Label :: SystemStatusOsObserver :: Data Items In");
|
||||
for (; it != dlist.end (); ++it) {
|
||||
if (*it != NULL) {
|
||||
string dv;
|
||||
(*it)->stringify(dv);
|
||||
LOC_LOGD("LocTech-Value :: Data Item Value: %s", dv.c_str ());
|
||||
IDataItemCore * dataitem = DataItemsFactoryProxy::createNewDataItem((*it)->getId());
|
||||
BREAK_IF_ZERO (2, dataitem);
|
||||
// Copy contents into the newly created data item
|
||||
dataitem->copy(*it);
|
||||
dataItemList.push_back(dataitem);
|
||||
ids.push_back((*it)->getId());
|
||||
}
|
||||
}
|
||||
SystemStatusOsObserver* mParent;
|
||||
const list<IDataItemCore*> mDList;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(new (nothrow) HandleNotify(this, dataItemList));
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
IFrameworkActionReq Overrides
|
||||
******************************************************************************/
|
||||
void SystemStatusOsObserver :: turnOn (DataItemId dit, int timeOut) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mContext.mFrameworkActionReqObj != NULL) {
|
||||
void SystemStatusOsObserver::turnOn(DataItemId dit, int timeOut)
|
||||
{
|
||||
if (nullptr == mContext.mFrameworkActionReqObj) {
|
||||
LOC_LOGE("%s:%d]: Framework action request object is NULL", __func__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if data item exists in mActiveRequestCount
|
||||
map<DataItemId, int>::iterator citer = mActiveRequestCount.find(dit);
|
||||
if (citer == mActiveRequestCount.end()) {
|
||||
|
@ -489,157 +449,144 @@ void SystemStatusOsObserver :: turnOn (DataItemId dit, int timeOut) {
|
|||
pair<DataItemId, int> cpair(dit, 1);
|
||||
mActiveRequestCount.insert(cpair);
|
||||
LOC_LOGD("Sending turnOn request");
|
||||
|
||||
// Send action turn on to framework
|
||||
mContext.mMsgTask->sendMsg (new (nothrow) HandleTurnOn (this, dit, timeOut));
|
||||
} else {
|
||||
// Found in map, update reference count
|
||||
citer->second++;
|
||||
LOC_LOGD("HandleTurnOn - Data item:%d Num_refs:%d",dit,citer->second);
|
||||
struct HandleTurnOnMsg : public LocMsg {
|
||||
HandleTurnOnMsg(IFrameworkActionReq* framework,
|
||||
DataItemId dit, int timeOut) :
|
||||
mFrameworkActionReqObj(framework), mDataItemId(dit), mTimeOut(timeOut) {}
|
||||
virtual ~HandleTurnOnMsg() {}
|
||||
void proc() const {
|
||||
mFrameworkActionReqObj->turnOn(mDataItemId, mTimeOut);
|
||||
}
|
||||
IFrameworkActionReq* mFrameworkActionReqObj;
|
||||
DataItemId mDataItemId;
|
||||
int mTimeOut;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(new (nothrow) HandleTurnOnMsg(this, dit, timeOut));
|
||||
}
|
||||
else {
|
||||
// Found in map, update reference count
|
||||
citer->second++;
|
||||
LOC_LOGD("turnOn - Data item:%d Num_refs:%d", dit, citer->second);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver::turnOff(DataItemId dit)
|
||||
{
|
||||
if (nullptr == mContext.mFrameworkActionReqObj) {
|
||||
LOC_LOGE("%s:%d]: Framework action request object is NULL", __func__, __LINE__);
|
||||
result = 1;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
return;
|
||||
}
|
||||
|
||||
void SystemStatusOsObserver :: turnOff (DataItemId dit) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
if (mContext.mFrameworkActionReqObj != NULL) {
|
||||
// Check if data item exists in mActiveRequestCount
|
||||
map<DataItemId, int>::iterator citer = mActiveRequestCount.find(dit);
|
||||
if (citer != mActiveRequestCount.end()) {
|
||||
// found
|
||||
citer->second--;
|
||||
LOC_LOGD("HandleTurnOff - Data item:%d Remaining Num_refs:%d",dit,citer->second);
|
||||
|
||||
LOC_LOGD("turnOff - Data item:%d Remaining:%d", dit, citer->second);
|
||||
if(citer->second == 0) {
|
||||
LOC_LOGD("Sending turnOff request");
|
||||
// if this was last reference, remove item from map and turn off module
|
||||
mActiveRequestCount.erase(citer);
|
||||
|
||||
// Send action turn off to framework
|
||||
mContext.mMsgTask->sendMsg (new (nothrow) HandleTurnOff (this, dit));
|
||||
struct HandleTurnOffMsg : public LocMsg {
|
||||
HandleTurnOffMsg(IFrameworkActionReq* framework, DataItemId dit) :
|
||||
mFrameworkActionReqObj(framework), mDataItemId(dit) {}
|
||||
virtual ~HandleTurnOffMsg() {}
|
||||
void proc() const {
|
||||
mFrameworkActionReqObj->turnOff(mDataItemId);
|
||||
}
|
||||
} else {
|
||||
// Not found in map
|
||||
LOC_LOGD ("Data item id %d not found in FrameworkModuleMap",dit);
|
||||
IFrameworkActionReq* mFrameworkActionReqObj;
|
||||
DataItemId mDataItemId;
|
||||
};
|
||||
mContext.mMsgTask->sendMsg(
|
||||
new (nothrow) HandleTurnOffMsg(mContext.mFrameworkActionReqObj, dit));
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: Framework action request object is NULL", __func__, __LINE__);
|
||||
result = 1;
|
||||
}
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
Helpers
|
||||
******************************************************************************/
|
||||
void SystemStatusOsObserver :: logMe (const list <DataItemId> & l) {
|
||||
list <DataItemId> :: const_iterator it = l.begin ();
|
||||
for (;it != l.end (); ++it) {
|
||||
LOC_LOGD ("DataItem %d",*it);
|
||||
}
|
||||
}
|
||||
|
||||
int SystemStatusOsObserver :: sendFirstResponse (const list <DataItemId> & l, IDataItemObserver * to) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
void SystemStatusOsObserver::sendFirstResponse(
|
||||
const list<DataItemId>& l, IDataItemObserver* to)
|
||||
{
|
||||
if (l.empty()) {
|
||||
LOC_LOGV("list is empty. Nothing to do. Exiting");
|
||||
result = 0;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
string clientName;
|
||||
to->getName(clientName);
|
||||
LOC_LOGD ("First response sent for the following data items To Client: %s", clientName.c_str());
|
||||
list<IDataItemCore*> dataItems(0);
|
||||
|
||||
list <IDataItemCore *> dataItems;
|
||||
list <DataItemId> :: const_iterator diditer = l.begin ();
|
||||
for (; diditer != l.end (); ++diditer) {
|
||||
map <DataItemId, IDataItemCore*> :: const_iterator citer = mDataItemCache.find (*diditer);
|
||||
for (auto each : l) {
|
||||
map<DataItemId, IDataItemCore*>::const_iterator citer = mDataItemCache.find(each);
|
||||
if (citer != mDataItemCache.end()) {
|
||||
string dv;
|
||||
IDataItemCore * di = citer->second;
|
||||
di->stringify (dv);
|
||||
LOC_LOGD ("LocTech-Value :: Data Item: %s", dv.c_str ());
|
||||
citer->second->stringify(dv);
|
||||
LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str());
|
||||
dataItems.push_back(citer->second);
|
||||
}
|
||||
}
|
||||
if (dataItems.empty()) {
|
||||
LOC_LOGV("No items to notify. Nothing to do. Exiting");
|
||||
result = 0;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
// Notify Client
|
||||
to->notify(dataItems);
|
||||
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int SystemStatusOsObserver :: sendCachedDataItems (const list <DataItemId> & l, IDataItemObserver * to) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
list <IDataItemCore *> dataItems;
|
||||
list <DataItemId> :: const_iterator it = l.begin ();
|
||||
void SystemStatusOsObserver::sendCachedDataItems(
|
||||
const list<DataItemId>& l, IDataItemObserver* to)
|
||||
{
|
||||
string clientName;
|
||||
to->getName(clientName);
|
||||
LOC_LOGD ("LocTech-Value :: To Client: %s", clientName.c_str ());
|
||||
for (; it != l.end (); ++it) {
|
||||
list<IDataItemCore*> dataItems(0);
|
||||
|
||||
for (auto each : l) {
|
||||
string dv;
|
||||
IDataItemCore * di = this->mDataItemCache [ (*it) ];
|
||||
IDataItemCore* di = mDataItemCache[each];
|
||||
di->stringify(dv);
|
||||
LOC_LOGI("LocTech-Value :: Data Item: %s >> %s", dv.c_str(), clientName.c_str());
|
||||
LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str());
|
||||
dataItems.push_back(di);
|
||||
}
|
||||
|
||||
to->notify(dataItems);
|
||||
|
||||
} while (0);
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int SystemStatusOsObserver :: updateCache (IDataItemCore * d, bool &dataItemUpdated) {
|
||||
int result = 0;
|
||||
ENTRY_LOG ();
|
||||
do {
|
||||
BREAK_IF_ZERO (1, d);
|
||||
void SystemStatusOsObserver::updateCache(IDataItemCore* d, bool& dataItemUpdated)
|
||||
{
|
||||
if (nullptr == d) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if data item exists in cache
|
||||
map <DataItemId, IDataItemCore*> :: iterator citer = mDataItemCache.find (d->getId ());
|
||||
map<DataItemId, IDataItemCore*>::iterator citer =
|
||||
mDataItemCache.find(d->getId());
|
||||
if (citer == mDataItemCache.end()) {
|
||||
// New data item; not found in cache
|
||||
IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem(d->getId());
|
||||
BREAK_IF_ZERO (2, dataitem);
|
||||
if (nullptr == dataitem) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy the contents of the data item
|
||||
dataitem->copy(d);
|
||||
pair<DataItemId, IDataItemCore*> cpair(d->getId(), dataitem);
|
||||
// Insert in mDataItemCache
|
||||
mDataItemCache.insert(cpair);
|
||||
dataItemUpdated = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Found in cache; Update cache if necessary
|
||||
BREAK_IF_NON_ZERO(3, citer->second->copy (d, &dataItemUpdated));
|
||||
if(0 == citer->second->copy(d, &dataItemUpdated)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (dataItemUpdated) {
|
||||
LOC_LOGV("DataItem:%d updated:%d", d->getId(), dataItemUpdated);
|
||||
}
|
||||
} while (0);
|
||||
|
||||
EXIT_LOG_WITH_ERROR ("%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace loc_core
|
||||
|
|
|
@ -29,31 +29,29 @@
|
|||
#ifndef __SYSTEM_STATUS_OSOBSERVER__
|
||||
#define __SYSTEM_STATUS_OSOBSERVER__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <new>
|
||||
#include <vector>
|
||||
#include <platform_lib_log_util.h>
|
||||
#include <DataItemId.h>
|
||||
|
||||
#include <MsgTask.h>
|
||||
#include <DataItemId.h>
|
||||
#include <IOsObserver.h>
|
||||
#include <platform_lib_log_util.h>
|
||||
|
||||
namespace loc_core
|
||||
{
|
||||
|
||||
/******************************************************************************
|
||||
SystemStatusOsObserver
|
||||
******************************************************************************/
|
||||
using namespace std;
|
||||
|
||||
// Forward Declarations
|
||||
class IDataItemCore;
|
||||
|
||||
template <typename CT, typename DIT>
|
||||
class IClientIndex;
|
||||
|
||||
template <typename CT, typename DIT>
|
||||
class IDataItemIndex;
|
||||
template<typename CT, typename DIT> class IClientIndex;
|
||||
template<typename CT, typename DIT> class IDataItemIndex;
|
||||
|
||||
struct SystemContext {
|
||||
IDataItemSubscription* mSubscriptionObj;
|
||||
|
@ -66,6 +64,8 @@ struct SystemContext {
|
|||
mMsgTask(NULL) {}
|
||||
};
|
||||
|
||||
typedef map<IDataItemObserver*, list<DataItemId>> ObserverReqCache;
|
||||
|
||||
// Clients wanting to get data from OS/Framework would need to
|
||||
// subscribe with OSObserver using IDataItemSubscription interface.
|
||||
// Such clients would need to implement IDataItemObserver interface
|
||||
|
@ -80,40 +80,31 @@ public:
|
|||
~SystemStatusOsObserver();
|
||||
|
||||
// To set the subscription object
|
||||
inline void setSubscriptionObj(IDataItemSubscription *subscriptionObj) {
|
||||
mContext.mSubscriptionObj = subscriptionObj;
|
||||
};
|
||||
virtual void setSubscriptionObj(IDataItemSubscription* subscriptionObj);
|
||||
|
||||
// To set the framework action request object
|
||||
inline void setFrameworkActionReqObj(IFrameworkActionReq* frameworkActionReqObj) {
|
||||
mContext.mFrameworkActionReqObj = frameworkActionReqObj;
|
||||
}
|
||||
|
||||
// IDataItemObserver Overrides
|
||||
virtual void getName (string & name);
|
||||
virtual void notify (const std::list <IDataItemCore *> & dlist);
|
||||
|
||||
// IDataItemSubscription Overrides
|
||||
virtual void subscribe (const std :: list <DataItemId> & l, IDataItemObserver * client);
|
||||
virtual void updateSubscription
|
||||
(
|
||||
const std :: list <DataItemId> & l,
|
||||
IDataItemObserver * client
|
||||
);
|
||||
virtual void requestData
|
||||
(
|
||||
const std :: list <DataItemId> & l,
|
||||
IDataItemObserver * client
|
||||
);
|
||||
virtual void unsubscribe (const std :: list <DataItemId> & l, IDataItemObserver * client);
|
||||
virtual void subscribe(const list<DataItemId>& l, IDataItemObserver* client);
|
||||
virtual void updateSubscription(const list<DataItemId>& l, IDataItemObserver* client);
|
||||
virtual void requestData(const list<DataItemId>& l, IDataItemObserver* client);
|
||||
virtual void unsubscribe(const list<DataItemId>& l, IDataItemObserver* client);
|
||||
virtual void unsubscribeAll(IDataItemObserver* client);
|
||||
|
||||
// IDataItemObserver Overrides
|
||||
virtual void notify(const list<IDataItemCore*>& dlist);
|
||||
inline virtual void getName(string& name) {
|
||||
name = mAddress;
|
||||
}
|
||||
|
||||
// IFrameworkActionReq Overrides
|
||||
virtual void turnOn(DataItemId dit, int timeOut = 0);
|
||||
virtual void turnOff(DataItemId dit);
|
||||
|
||||
private:
|
||||
|
||||
SystemContext mContext;
|
||||
const string mAddress;
|
||||
IClientIndex<IDataItemObserver*, DataItemId>* mClientIndex;
|
||||
|
@ -121,211 +112,22 @@ private:
|
|||
map<DataItemId, IDataItemCore*> mDataItemCache;
|
||||
map<DataItemId, int> mActiveRequestCount;
|
||||
|
||||
// Nested types
|
||||
// Messages
|
||||
struct HandleMsgBase : public LocMsg {
|
||||
HandleMsgBase (SystemStatusOsObserver * parent);
|
||||
virtual ~HandleMsgBase ();
|
||||
// Data members
|
||||
SystemStatusOsObserver * mParent;
|
||||
};
|
||||
// Cache the subscribe and requestData till subscription obj is obtained
|
||||
ObserverReqCache mSubscribeReqCache;
|
||||
ObserverReqCache mReqDataCache;
|
||||
void cacheObserverRequest(ObserverReqCache& reqCache,
|
||||
const list<DataItemId>& l, IDataItemObserver* client);
|
||||
|
||||
// Helpers
|
||||
int sendFirstResponse
|
||||
(
|
||||
const list <DataItemId> & l,
|
||||
IDataItemObserver * to
|
||||
);
|
||||
|
||||
int sendCachedDataItems
|
||||
(
|
||||
const list <DataItemId> & l,
|
||||
IDataItemObserver * to
|
||||
);
|
||||
|
||||
int updateCache (IDataItemCore * d, bool &dataItemUpdated);
|
||||
void logMe (const list <DataItemId> & l);
|
||||
|
||||
// Messages
|
||||
struct HandleClientMsg : public LocMsg {
|
||||
HandleClientMsg (SystemStatusOsObserver * parent, IDataItemObserver * client);
|
||||
virtual ~HandleClientMsg ();
|
||||
// Data Members
|
||||
SystemStatusOsObserver * mParent;
|
||||
IDataItemObserver * mClient;
|
||||
};
|
||||
|
||||
struct HandleSubscribeReq : public HandleClientMsg {
|
||||
HandleSubscribeReq (SystemStatusOsObserver * parent,
|
||||
const list <DataItemId> & l,
|
||||
IDataItemObserver * client);
|
||||
virtual ~HandleSubscribeReq ();
|
||||
void proc () const;
|
||||
// Data members
|
||||
const list <DataItemId> mDataItemList;
|
||||
};
|
||||
|
||||
struct HandleUpdateSubscriptionReq : public HandleClientMsg {
|
||||
HandleUpdateSubscriptionReq (SystemStatusOsObserver * parent,
|
||||
const list <DataItemId> & l,
|
||||
IDataItemObserver * client);
|
||||
virtual ~HandleUpdateSubscriptionReq ();
|
||||
void proc () const;
|
||||
// Data members
|
||||
const list <DataItemId> mDataItemList;
|
||||
};
|
||||
|
||||
struct HandleRequestData : public HandleClientMsg {
|
||||
HandleRequestData (SystemStatusOsObserver * parent,
|
||||
const list <DataItemId> & l,
|
||||
IDataItemObserver * client);
|
||||
virtual ~HandleRequestData ();
|
||||
void proc () const;
|
||||
const list <DataItemId> mDataItemList;
|
||||
};
|
||||
|
||||
struct HandleUnsubscribeReq : public HandleClientMsg {
|
||||
HandleUnsubscribeReq (SystemStatusOsObserver * parent,
|
||||
const list <DataItemId> & l,
|
||||
IDataItemObserver * client);
|
||||
virtual ~HandleUnsubscribeReq ();
|
||||
void proc () const;
|
||||
// Data members
|
||||
const list <DataItemId> mDataItemList;
|
||||
};
|
||||
|
||||
struct HandleUnsubscribeAllReq : public HandleClientMsg {
|
||||
HandleUnsubscribeAllReq
|
||||
(
|
||||
SystemStatusOsObserver * parent,
|
||||
IDataItemObserver * client
|
||||
);
|
||||
virtual ~HandleUnsubscribeAllReq ();
|
||||
void proc () const;
|
||||
};
|
||||
|
||||
struct HandleNotify : public HandleMsgBase {
|
||||
HandleNotify (SystemStatusOsObserver * parent, list <IDataItemCore *> dlist);
|
||||
virtual ~HandleNotify ();
|
||||
void getListOfClients
|
||||
(
|
||||
const list <DataItemId> & dlist,
|
||||
list <IDataItemObserver *> & clients
|
||||
) const;
|
||||
void proc () const;
|
||||
// Data members
|
||||
list <IDataItemCore *> mDList;
|
||||
};
|
||||
|
||||
struct HandleTurnOn : public HandleMsgBase {
|
||||
HandleTurnOn (SystemStatusOsObserver * parent,
|
||||
const DataItemId dit,
|
||||
const int timeOut);
|
||||
virtual ~HandleTurnOn ();
|
||||
void proc () const;
|
||||
// Data members
|
||||
DataItemId mDataItemId;
|
||||
int mTimeOut;
|
||||
};
|
||||
|
||||
struct HandleTurnOff : public HandleMsgBase {
|
||||
HandleTurnOff (SystemStatusOsObserver * parent,const DataItemId dit);
|
||||
virtual ~HandleTurnOff ();
|
||||
void proc () const;
|
||||
// Data members
|
||||
DataItemId mDataItemId;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
Messages
|
||||
******************************************************************************/
|
||||
// Ctors
|
||||
inline SystemStatusOsObserver :: HandleMsgBase :: HandleMsgBase (SystemStatusOsObserver * parent)
|
||||
:
|
||||
mParent (parent)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleClientMsg :: HandleClientMsg
|
||||
(
|
||||
SystemStatusOsObserver * parent,
|
||||
IDataItemObserver * client
|
||||
)
|
||||
:
|
||||
mParent (parent),
|
||||
mClient (client)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleSubscribeReq :: HandleSubscribeReq
|
||||
(SystemStatusOsObserver * parent, const list <DataItemId> & l, IDataItemObserver * client)
|
||||
:
|
||||
HandleClientMsg (parent, client), mDataItemList (l)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleUpdateSubscriptionReq :: HandleUpdateSubscriptionReq
|
||||
(SystemStatusOsObserver * parent, const list <DataItemId> & l, IDataItemObserver * client)
|
||||
:
|
||||
HandleClientMsg (parent, client), mDataItemList (l)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleRequestData :: HandleRequestData
|
||||
(SystemStatusOsObserver * parent, const list <DataItemId> & l, IDataItemObserver * client)
|
||||
:
|
||||
HandleClientMsg (parent, client), mDataItemList (l)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleUnsubscribeReq :: HandleUnsubscribeReq
|
||||
(SystemStatusOsObserver * parent, const list <DataItemId> & l, IDataItemObserver * client)
|
||||
:
|
||||
HandleClientMsg (parent, client), mDataItemList (l)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleUnsubscribeAllReq :: HandleUnsubscribeAllReq
|
||||
(SystemStatusOsObserver * parent, IDataItemObserver * client)
|
||||
:
|
||||
HandleClientMsg (parent, client)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleNotify :: HandleNotify
|
||||
(SystemStatusOsObserver * parent, list <IDataItemCore *> dlist)
|
||||
:
|
||||
HandleMsgBase (parent), mDList (dlist)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleTurnOn :: HandleTurnOn
|
||||
(SystemStatusOsObserver * parent, const DataItemId dit,const int timeOut)
|
||||
:
|
||||
HandleMsgBase (parent), mDataItemId (dit), mTimeOut (timeOut)
|
||||
{}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleTurnOff :: HandleTurnOff
|
||||
(SystemStatusOsObserver * parent, const DataItemId dit)
|
||||
:
|
||||
HandleMsgBase (parent), mDataItemId (dit)
|
||||
{}
|
||||
|
||||
// Dtors
|
||||
inline SystemStatusOsObserver :: HandleMsgBase :: ~HandleMsgBase () {}
|
||||
inline SystemStatusOsObserver :: HandleClientMsg :: ~HandleClientMsg () {}
|
||||
inline SystemStatusOsObserver :: HandleSubscribeReq :: ~HandleSubscribeReq () {}
|
||||
inline SystemStatusOsObserver :: HandleUpdateSubscriptionReq :: ~HandleUpdateSubscriptionReq() {}
|
||||
inline SystemStatusOsObserver :: HandleRequestData :: ~HandleRequestData() {}
|
||||
inline SystemStatusOsObserver :: HandleUnsubscribeReq :: ~HandleUnsubscribeReq () {}
|
||||
inline SystemStatusOsObserver :: HandleUnsubscribeAllReq :: ~HandleUnsubscribeAllReq () {}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleNotify :: ~HandleNotify () {
|
||||
list <IDataItemCore *> :: iterator it = mDList.begin ();
|
||||
for (; it != mDList.end (); ++it) {
|
||||
delete *it;
|
||||
*it = NULL;
|
||||
void sendFirstResponse(const list<DataItemId>& l, IDataItemObserver* to);
|
||||
void sendCachedDataItems(const list<DataItemId>& l, IDataItemObserver* to);
|
||||
void updateCache(IDataItemCore* d, bool& dataItemUpdated);
|
||||
inline void logMe(const list<DataItemId>& l) {
|
||||
for (auto id : l) {
|
||||
LOC_LOGD("DataItem %d", id);
|
||||
}
|
||||
}
|
||||
|
||||
inline SystemStatusOsObserver :: HandleTurnOn :: ~HandleTurnOn () {}
|
||||
inline SystemStatusOsObserver :: HandleTurnOff :: ~HandleTurnOff () {}
|
||||
|
||||
};
|
||||
|
||||
} // namespace loc_core
|
||||
|
||||
|
|
|
@ -67,7 +67,8 @@ GnssAdapter::GnssAdapter() :
|
|||
mAgpsManager(),
|
||||
mAgpsCbInfo(),
|
||||
mSystemStatus(SystemStatus::getInstance(mMsgTask)),
|
||||
mServerUrl("")
|
||||
mServerUrl(""),
|
||||
mXtraObserver(mSystemStatus->getOsObserver(), mMsgTask)
|
||||
{
|
||||
LOC_LOGD("%s]: Constructor %p", __func__, this);
|
||||
mUlpPositionMode.mode = LOC_POSITION_MODE_INVALID;
|
||||
|
|
|
@ -106,11 +106,11 @@ class GnssAdapter : public LocAdapterBase {
|
|||
// This must be initialized via initAgps()
|
||||
AgpsManager mAgpsManager;
|
||||
AgpsCbInfo mAgpsCbInfo;
|
||||
XtraSystemStatusObserver mXtraObserver;
|
||||
|
||||
/* === SystemStatus ===================================================================== */
|
||||
SystemStatus* mSystemStatus;
|
||||
std::string mServerUrl;
|
||||
XtraSystemStatusObserver mXtraObserver;
|
||||
|
||||
/*==== CONVERSION ===================================================================*/
|
||||
static void convertOptions(LocPosMode& out, const LocationOptions& options);
|
||||
|
@ -282,10 +282,6 @@ public:
|
|||
void injectLocationCommand(double latitude, double longitude, float accuracy);
|
||||
void injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty);
|
||||
|
||||
inline void updateConnectionStatusCommand(bool connected, uint8_t type) {
|
||||
mXtraObserver.updateConnectionStatus(connected, type);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //GNSS_ADAPTER_H
|
||||
|
|
|
@ -45,40 +45,55 @@
|
|||
#include <sstream>
|
||||
#include <XtraSystemStatusObserver.h>
|
||||
#include <LocAdapterBase.h>
|
||||
#include <DataItemId.h>
|
||||
#include <DataItemsFactoryProxy.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace loc_core;
|
||||
|
||||
#define XTRA_HAL_SOCKET_NAME "/data/vendor/location/xtra/socket_hal_xtra"
|
||||
|
||||
bool XtraSystemStatusObserver::updateLockStatus(uint32_t lock) {
|
||||
std::stringstream ss;
|
||||
stringstream ss;
|
||||
ss << "gpslock";
|
||||
ss << " " << lock;
|
||||
ss << "\n"; // append seperator
|
||||
return ( sendEvent(ss) );
|
||||
}
|
||||
|
||||
bool XtraSystemStatusObserver::updateConnectionStatus(bool connected, uint8_t type) {
|
||||
std::stringstream ss;
|
||||
bool XtraSystemStatusObserver::updateConnectionStatus(bool connected, uint32_t type) {
|
||||
stringstream ss;
|
||||
ss << "connection";
|
||||
ss << " " << (connected ? "1" : "0");
|
||||
ss << " " << (int)type;
|
||||
ss << "\n"; // append seperator
|
||||
return ( sendEvent(ss) );
|
||||
}
|
||||
bool XtraSystemStatusObserver::updateTac(const string& tac) {
|
||||
stringstream ss;
|
||||
ss << "tac";
|
||||
ss << " " << tac.c_str();
|
||||
ss << "\n"; // append seperator
|
||||
return ( sendEvent(ss) );
|
||||
}
|
||||
|
||||
bool XtraSystemStatusObserver::sendEvent(std::stringstream& event) {
|
||||
bool XtraSystemStatusObserver::updateMccMnc(const string& mccmnc) {
|
||||
stringstream ss;
|
||||
ss << "mncmcc";
|
||||
ss << " " << mccmnc.c_str();
|
||||
ss << "\n"; // append seperator
|
||||
return ( sendEvent(ss) );
|
||||
}
|
||||
|
||||
bool XtraSystemStatusObserver::sendEvent(const stringstream& event) {
|
||||
int socketFd = createSocket();
|
||||
if (socketFd < 0) {
|
||||
LOC_LOGe("XTRA unreachable. sending failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& data = event.str();
|
||||
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) {
|
||||
|
@ -125,3 +140,95 @@ void XtraSystemStatusObserver::closeSocket(const int socketFd) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XtraSystemStatusObserver::subscribe(bool yes)
|
||||
{
|
||||
// Subscription data list
|
||||
list<DataItemId> subItemIdList;
|
||||
subItemIdList.push_back(NETWORKINFO_DATA_ITEM_ID);
|
||||
subItemIdList.push_back(MCCMNC_DATA_ITEM_ID);
|
||||
|
||||
if (yes) {
|
||||
mSystemStatusObsrvr->subscribe(subItemIdList, this);
|
||||
|
||||
list<DataItemId> reqItemIdList;
|
||||
reqItemIdList.push_back(TAC_DATA_ITEM_ID);
|
||||
|
||||
mSystemStatusObsrvr->requestData(reqItemIdList, this);
|
||||
|
||||
} else {
|
||||
mSystemStatusObsrvr->unsubscribe(subItemIdList, this);
|
||||
}
|
||||
}
|
||||
|
||||
// IDataItemObserver overrides
|
||||
void XtraSystemStatusObserver::getName(string& name)
|
||||
{
|
||||
name = "XtraSystemStatusObserver";
|
||||
}
|
||||
|
||||
void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
|
||||
{
|
||||
struct handleOsObserverUpdateMsg : public LocMsg {
|
||||
XtraSystemStatusObserver* mXtraSysStatObj;
|
||||
list <IDataItemCore*> mDataItemList;
|
||||
|
||||
inline handleOsObserverUpdateMsg(XtraSystemStatusObserver* xtraSysStatObs,
|
||||
const list<IDataItemCore*>& dataItemList) :
|
||||
mXtraSysStatObj(xtraSysStatObs) {
|
||||
for (auto eachItem : dataItemList) {
|
||||
IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem(
|
||||
eachItem->getId());
|
||||
if (NULL == dataitem) {
|
||||
break;
|
||||
}
|
||||
// Copy the contents of the data item
|
||||
dataitem->copy(eachItem);
|
||||
|
||||
mDataItemList.push_back(dataitem);
|
||||
}
|
||||
}
|
||||
|
||||
inline ~handleOsObserverUpdateMsg() {
|
||||
for (auto each : mDataItemList) {
|
||||
delete each;
|
||||
}
|
||||
}
|
||||
|
||||
inline void proc() const {
|
||||
for (auto each : mDataItemList) {
|
||||
switch (each->getId())
|
||||
{
|
||||
case NETWORKINFO_DATA_ITEM_ID:
|
||||
{
|
||||
SystemStatusNetworkInfo* networkInfo =
|
||||
reinterpret_cast<SystemStatusNetworkInfo*>(each);
|
||||
mXtraSysStatObj->updateConnectionStatus(networkInfo->mConnected,
|
||||
networkInfo->mType);
|
||||
}
|
||||
break;
|
||||
|
||||
case TAC_DATA_ITEM_ID:
|
||||
{
|
||||
SystemStatusTac* tac = reinterpret_cast<SystemStatusTac*>(each);
|
||||
mXtraSysStatObj->updateTac(tac->mValue);
|
||||
}
|
||||
break;
|
||||
|
||||
case MCCMNC_DATA_ITEM_ID:
|
||||
{
|
||||
SystemStatusMccMnc* mccmnc = reinterpret_cast<SystemStatusMccMnc*>(each);
|
||||
mXtraSysStatObj->updateMccMnc(mccmnc->mValue);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
mMsgTask->sendMsg(new (nothrow) handleOsObserverUpdateMsg(this, dlist));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,25 +29,42 @@
|
|||
#ifndef XTRA_SYSTEM_STATUS_OBS_H
|
||||
#define XTRA_SYSTEM_STATUS_OBS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cinttypes>
|
||||
#include <MsgTask.h>
|
||||
|
||||
using namespace std;
|
||||
using loc_core::IOsObserver;
|
||||
using loc_core::IDataItemObserver;
|
||||
using loc_core::IDataItemCore;
|
||||
|
||||
|
||||
class XtraSystemStatusObserver {
|
||||
class XtraSystemStatusObserver : public IDataItemObserver {
|
||||
public :
|
||||
// constructor & destructor
|
||||
XtraSystemStatusObserver() {
|
||||
inline XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask):
|
||||
mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask) {
|
||||
subscribe(true);
|
||||
}
|
||||
inline XtraSystemStatusObserver() {};
|
||||
inline virtual ~XtraSystemStatusObserver() { subscribe(false); }
|
||||
|
||||
virtual ~XtraSystemStatusObserver() {
|
||||
}
|
||||
// IDataItemObserver overrides
|
||||
inline virtual void getName(string& name);
|
||||
virtual void notify(const list<IDataItemCore*>& dlist);
|
||||
|
||||
bool updateLockStatus(uint32_t lock);
|
||||
bool updateConnectionStatus(bool connected, uint8_t type);
|
||||
bool updateConnectionStatus(bool connected, uint32_t type);
|
||||
bool updateTac(const string& tac);
|
||||
bool updateMccMnc(const string& mccmnc);
|
||||
inline const MsgTask* getMsgTask() { return mMsgTask; }
|
||||
void subscribe(bool yes);
|
||||
|
||||
private:
|
||||
int createSocket();
|
||||
void closeSocket(const int32_t socketFd);
|
||||
bool sendEvent(std::stringstream& event);
|
||||
bool sendEvent(const stringstream& event);
|
||||
IOsObserver* mSystemStatusObsrvr;
|
||||
const MsgTask* mMsgTask;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -253,6 +253,6 @@ static void getDebugReport(GnssDebugReport& report) {
|
|||
|
||||
static void updateConnectionStatus(bool connected, uint8_t type) {
|
||||
if (NULL != gGnssAdapter) {
|
||||
gGnssAdapter->updateConnectionStatusCommand(connected, type);
|
||||
gGnssAdapter->getSystemStatus()->eventConnectionStatus(connected, type);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue