BatchingAdapter.cpp 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /* Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are
  5. * met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above
  9. * copyright notice, this list of conditions and the following
  10. * disclaimer in the documentation and/or other materials provided
  11. * with the distribution.
  12. * * Neither the name of The Linux Foundation, nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  20. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  23. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  26. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. */
  29. #define LOG_NDEBUG 0
  30. #define LOG_TAG "LocSvc_BatchingAdapter"
  31. #include <loc_pla.h>
  32. #include <log_util.h>
  33. #include <LocContext.h>
  34. #include <BatchingAdapter.h>
  35. using namespace loc_core;
  36. BatchingAdapter::BatchingAdapter() :
  37. LocAdapterBase(0,
  38. LocContext::getLocContext(LocContext::mLocationHalName),
  39. false, nullptr, true),
  40. mOngoingTripDistance(0),
  41. mOngoingTripTBFInterval(0),
  42. mTripWithOngoingTBFDropped(false),
  43. mTripWithOngoingTripDistanceDropped(false),
  44. mSystemPowerState(POWER_STATE_UNKNOWN),
  45. mBatchingTimeout(0),
  46. mBatchingAccuracy(1),
  47. mBatchSize(0),
  48. mTripBatchSize(0)
  49. {
  50. LOC_LOGD("%s]: Constructor", __func__);
  51. readConfigCommand();
  52. setConfigCommand();
  53. // at last step, let us inform adapater base that we are done
  54. // with initialization, e.g.: ready to process handleEngineUpEvent
  55. doneInit();
  56. }
  57. void
  58. BatchingAdapter::readConfigCommand()
  59. {
  60. LOC_LOGD("%s]: ", __func__);
  61. struct MsgReadConfig : public LocMsg {
  62. BatchingAdapter& mAdapter;
  63. inline MsgReadConfig(BatchingAdapter& adapter) :
  64. LocMsg(),
  65. mAdapter(adapter) {}
  66. inline virtual void proc() const {
  67. uint32_t batchingTimeout = 0;
  68. uint32_t batchingAccuracy = 0;
  69. uint32_t batchSize = 0;
  70. uint32_t tripBatchSize = 0;
  71. static const loc_param_s_type batching_conf_param_table[] =
  72. {
  73. {"BATCH_SIZE", &batchSize, NULL, 'n'},
  74. {"OUTDOOR_TRIP_BATCH_SIZE", &tripBatchSize, NULL, 'n'},
  75. {"BATCH_SESSION_TIMEOUT", &batchingTimeout, NULL, 'n'},
  76. {"ACCURACY", &batchingAccuracy, NULL, 'n'},
  77. };
  78. UTIL_READ_CONF(LOC_PATH_BATCHING_CONF, batching_conf_param_table);
  79. LOC_LOGD("%s]: batchSize %u tripBatchSize %u batchingAccuracy %u batchingTimeout %u ",
  80. __func__, batchSize, tripBatchSize, batchingAccuracy, batchingTimeout);
  81. mAdapter.setBatchSize(batchSize);
  82. mAdapter.setTripBatchSize(tripBatchSize);
  83. mAdapter.setBatchingTimeout(batchingTimeout);
  84. mAdapter.setBatchingAccuracy(batchingAccuracy);
  85. }
  86. };
  87. sendMsg(new MsgReadConfig(*this));
  88. }
  89. void
  90. BatchingAdapter::setConfigCommand()
  91. {
  92. LOC_LOGD("%s]: ", __func__);
  93. struct MsgSetConfig : public LocMsg {
  94. BatchingAdapter& mAdapter;
  95. LocApiBase& mApi;
  96. inline MsgSetConfig(BatchingAdapter& adapter,
  97. LocApiBase& api) :
  98. LocMsg(),
  99. mAdapter(adapter),
  100. mApi(api) {}
  101. inline virtual void proc() const {
  102. mApi.setBatchSize(mAdapter.getBatchSize());
  103. mApi.setTripBatchSize(mAdapter.getTripBatchSize());
  104. }
  105. };
  106. sendMsg(new MsgSetConfig(*this, *mLocApi));
  107. }
  108. void
  109. BatchingAdapter::stopClientSessions(LocationAPI* client, bool eraseSession)
  110. {
  111. LOC_LOGD("%s]: client %p", __func__, client);
  112. typedef struct pairKeyBatchMode {
  113. LocationAPI* client;
  114. uint32_t id;
  115. BatchingMode batchingMode;
  116. inline pairKeyBatchMode(LocationAPI* _client, uint32_t _id, BatchingMode _bMode) :
  117. client(_client), id(_id), batchingMode(_bMode) {}
  118. } pairKeyBatchMode;
  119. std::vector<pairKeyBatchMode> vBatchingClient;
  120. for (auto it : mBatchingSessions) {
  121. if (client == it.first.client) {
  122. vBatchingClient.emplace_back(it.first.client, it.first.id, it.second.batchingMode);
  123. }
  124. }
  125. for (auto keyBatchingMode : vBatchingClient) {
  126. if (keyBatchingMode.batchingMode != BATCHING_MODE_TRIP) {
  127. stopBatching(keyBatchingMode.client, keyBatchingMode.id, eraseSession);
  128. } else {
  129. stopTripBatchingMultiplex(keyBatchingMode.client, keyBatchingMode.id, eraseSession);
  130. }
  131. }
  132. }
  133. void
  134. BatchingAdapter::updateClientsEventMask()
  135. {
  136. LOC_API_ADAPTER_EVENT_MASK_T mask = 0;
  137. for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
  138. // we don't register LOC_API_ADAPTER_BIT_BATCH_FULL until we
  139. // start batching with ROUTINE or TRIP option
  140. if (it->second.batchingCb != nullptr) {
  141. mask |= LOC_API_ADAPTER_BIT_BATCH_STATUS;
  142. }
  143. }
  144. if (autoReportBatchingSessionsCount() > 0) {
  145. mask |= LOC_API_ADAPTER_BIT_BATCH_FULL;
  146. }
  147. updateEvtMask(mask, LOC_REGISTRATION_MASK_SET);
  148. }
  149. void
  150. BatchingAdapter::handleEngineUpEvent()
  151. {
  152. struct MsgSSREvent : public LocMsg {
  153. BatchingAdapter& mAdapter;
  154. LocApiBase& mApi;
  155. inline MsgSSREvent(BatchingAdapter& adapter,
  156. LocApiBase& api) :
  157. LocMsg(),
  158. mAdapter(adapter),
  159. mApi(api) {}
  160. virtual void proc() const {
  161. mAdapter.setEngineCapabilitiesKnown(true);
  162. mAdapter.broadcastCapabilities(mAdapter.getCapabilities());
  163. mApi.setBatchSize(mAdapter.getBatchSize());
  164. mApi.setTripBatchSize(mAdapter.getTripBatchSize());
  165. if ((POWER_STATE_SUSPEND != mAdapter.mSystemPowerState) &&
  166. POWER_STATE_SHUTDOWN != mAdapter.mSystemPowerState) {
  167. mAdapter.restartSessions();
  168. }
  169. for (auto msg: mAdapter.mPendingMsgs) {
  170. mAdapter.sendMsg(msg);
  171. }
  172. mAdapter.mPendingMsgs.clear();
  173. }
  174. };
  175. sendMsg(new MsgSSREvent(*this, *mLocApi));
  176. }
  177. void
  178. BatchingAdapter::restartSessions()
  179. {
  180. LOC_LOGD("%s]: ", __func__);
  181. if (autoReportBatchingSessionsCount() > 0) {
  182. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  183. LOC_REGISTRATION_MASK_ENABLED);
  184. }
  185. for (auto it = mBatchingSessions.begin();
  186. it != mBatchingSessions.end(); ++it) {
  187. if (it->second.batchingMode != BATCHING_MODE_TRIP) {
  188. mLocApi->startBatching(it->first.id, it->second,
  189. getBatchingAccuracy(), getBatchingTimeout(),
  190. new LocApiResponse(*getContext(),
  191. [] (LocationError /*err*/) {}));
  192. }
  193. }
  194. if (mTripSessions.size() > 0) {
  195. // restart outdoor trip batching session if any.
  196. mOngoingTripDistance = 0;
  197. mOngoingTripTBFInterval = 0;
  198. // record the min trip distance and min tbf interval of all ongoing sessions
  199. for (auto tripSession : mTripSessions) {
  200. TripSessionStatus &tripSessStatus = tripSession.second;
  201. if ((0 == mOngoingTripDistance) ||
  202. (mOngoingTripDistance >
  203. (tripSessStatus.tripDistance - tripSessStatus.accumulatedDistanceThisTrip))) {
  204. mOngoingTripDistance = tripSessStatus.tripDistance -
  205. tripSessStatus.accumulatedDistanceThisTrip;
  206. }
  207. if ((0 == mOngoingTripTBFInterval) ||
  208. (mOngoingTripTBFInterval > tripSessStatus.tripTBFInterval)) {
  209. mOngoingTripTBFInterval = tripSessStatus.tripTBFInterval;
  210. }
  211. // reset the accumulatedDistanceOngoingBatch for each session
  212. tripSessStatus.accumulatedDistanceOngoingBatch = 0;
  213. }
  214. mLocApi->startOutdoorTripBatching(mOngoingTripDistance, mOngoingTripTBFInterval,
  215. getBatchingTimeout(), new LocApiResponse(*getContext(), [this] (LocationError err) {
  216. if (LOCATION_ERROR_SUCCESS != err) {
  217. mOngoingTripDistance = 0;
  218. mOngoingTripTBFInterval = 0;
  219. }
  220. printTripReport();
  221. }));
  222. }
  223. }
  224. bool
  225. BatchingAdapter::hasBatchingCallback(LocationAPI* client)
  226. {
  227. auto it = mClientData.find(client);
  228. return (it != mClientData.end() && it->second.batchingCb);
  229. }
  230. bool
  231. BatchingAdapter::isBatchingSession(LocationAPI* client, uint32_t sessionId)
  232. {
  233. LocationSessionKey key(client, sessionId);
  234. return (mBatchingSessions.find(key) != mBatchingSessions.end());
  235. }
  236. bool
  237. BatchingAdapter::isTripSession(uint32_t sessionId) {
  238. return (mTripSessions.find(sessionId) != mTripSessions.end());
  239. }
  240. void
  241. BatchingAdapter::saveBatchingSession(LocationAPI* client, uint32_t sessionId,
  242. const BatchingOptions& batchingOptions)
  243. {
  244. LocationSessionKey key(client, sessionId);
  245. mBatchingSessions[key] = batchingOptions;
  246. }
  247. void
  248. BatchingAdapter::eraseBatchingSession(LocationAPI* client, uint32_t sessionId)
  249. {
  250. LocationSessionKey key(client, sessionId);
  251. auto it = mBatchingSessions.find(key);
  252. if (it != mBatchingSessions.end()) {
  253. mBatchingSessions.erase(it);
  254. }
  255. }
  256. void
  257. BatchingAdapter::reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId)
  258. {
  259. LOC_LOGD("%s]: client %p id %u err %u", __func__, client, sessionId, err);
  260. auto it = mClientData.find(client);
  261. if (it != mClientData.end() &&
  262. it->second.responseCb != nullptr) {
  263. it->second.responseCb(err, sessionId);
  264. } else {
  265. LOC_LOGE("%s]: client %p id %u not found in data", __func__, client, sessionId);
  266. }
  267. }
  268. uint32_t
  269. BatchingAdapter::autoReportBatchingSessionsCount()
  270. {
  271. uint32_t count = 0;
  272. for (auto batchingSession: mBatchingSessions) {
  273. if (batchingSession.second.batchingMode != BATCHING_MODE_NO_AUTO_REPORT) {
  274. count++;
  275. }
  276. }
  277. count += mTripSessions.size();
  278. return count;
  279. }
  280. uint32_t
  281. BatchingAdapter::startBatchingCommand(
  282. LocationAPI* client, BatchingOptions& batchOptions)
  283. {
  284. uint32_t sessionId = generateSessionId();
  285. LOC_LOGD("%s]: client %p id %u minInterval %u minDistance %u mode %u Batching Mode %d",
  286. __func__, client, sessionId, batchOptions.minInterval, batchOptions.minDistance,
  287. batchOptions.mode,batchOptions.batchingMode);
  288. struct MsgStartBatching : public LocMsg {
  289. BatchingAdapter& mAdapter;
  290. LocApiBase& mApi;
  291. LocationAPI* mClient;
  292. uint32_t mSessionId;
  293. BatchingOptions mBatchingOptions;
  294. inline MsgStartBatching(BatchingAdapter& adapter,
  295. LocApiBase& api,
  296. LocationAPI* client,
  297. uint32_t sessionId,
  298. BatchingOptions batchOptions) :
  299. LocMsg(),
  300. mAdapter(adapter),
  301. mApi(api),
  302. mClient(client),
  303. mSessionId(sessionId),
  304. mBatchingOptions(batchOptions) {}
  305. inline virtual void proc() const {
  306. if (!mAdapter.isEngineCapabilitiesKnown()) {
  307. mAdapter.mPendingMsgs.push_back(new MsgStartBatching(*this));
  308. return;
  309. }
  310. LocationError err = LOCATION_ERROR_SUCCESS;
  311. if (!mAdapter.hasBatchingCallback(mClient)) {
  312. err = LOCATION_ERROR_CALLBACK_MISSING;
  313. } else if (0 == mBatchingOptions.size) {
  314. err = LOCATION_ERROR_INVALID_PARAMETER;
  315. } else if (!ContextBase::isMessageSupported(
  316. LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)) {
  317. err = LOCATION_ERROR_NOT_SUPPORTED;
  318. }
  319. if (LOCATION_ERROR_SUCCESS == err) {
  320. if (mBatchingOptions.batchingMode == BATCHING_MODE_ROUTINE ||
  321. mBatchingOptions.batchingMode == BATCHING_MODE_NO_AUTO_REPORT) {
  322. mAdapter.startBatching(mClient, mSessionId, mBatchingOptions);
  323. } else if (mBatchingOptions.batchingMode == BATCHING_MODE_TRIP) {
  324. mAdapter.startTripBatchingMultiplex(mClient, mSessionId, mBatchingOptions);
  325. } else {
  326. mAdapter.reportResponse(mClient, LOCATION_ERROR_INVALID_PARAMETER, mSessionId);
  327. }
  328. }
  329. }
  330. };
  331. sendMsg(new MsgStartBatching(*this, *mLocApi, client, sessionId, batchOptions));
  332. return sessionId;
  333. }
  334. void
  335. BatchingAdapter::startBatching(LocationAPI* client, uint32_t sessionId,
  336. const BatchingOptions& batchingOptions)
  337. {
  338. if (batchingOptions.batchingMode != BATCHING_MODE_NO_AUTO_REPORT &&
  339. 0 == autoReportBatchingSessionsCount()) {
  340. // if there is currenty no batching sessions interested in batch full event, then this
  341. // new session will need to register for batch full event
  342. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  343. LOC_REGISTRATION_MASK_ENABLED);
  344. }
  345. // Assume start will be OK, remove session if not
  346. saveBatchingSession(client, sessionId, batchingOptions);
  347. mLocApi->startBatching(sessionId, batchingOptions, getBatchingAccuracy(), getBatchingTimeout(),
  348. new LocApiResponse(*getContext(),
  349. [this, client, sessionId, batchingOptions] (LocationError err) {
  350. if (LOCATION_ERROR_SUCCESS != err) {
  351. eraseBatchingSession(client, sessionId);
  352. }
  353. if (LOCATION_ERROR_SUCCESS != err &&
  354. batchingOptions.batchingMode != BATCHING_MODE_NO_AUTO_REPORT &&
  355. 0 == autoReportBatchingSessionsCount()) {
  356. // if we fail to start batching and we have already registered batch full event
  357. // we need to undo that since no sessions are now interested in batch full event
  358. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  359. LOC_REGISTRATION_MASK_DISABLED);
  360. }
  361. reportResponse(client, err, sessionId);
  362. }));
  363. }
  364. void
  365. BatchingAdapter::updateBatchingOptionsCommand(LocationAPI* client, uint32_t id,
  366. BatchingOptions& batchOptions)
  367. {
  368. LOC_LOGD("%s]: client %p id %u minInterval %u minDistance %u mode %u batchMode %u",
  369. __func__, client, id, batchOptions.minInterval,
  370. batchOptions.minDistance, batchOptions.mode,
  371. batchOptions.batchingMode);
  372. struct MsgUpdateBatching : public LocMsg {
  373. BatchingAdapter& mAdapter;
  374. LocApiBase& mApi;
  375. LocationAPI* mClient;
  376. uint32_t mSessionId;
  377. BatchingOptions mBatchOptions;
  378. inline MsgUpdateBatching(BatchingAdapter& adapter,
  379. LocApiBase& api,
  380. LocationAPI* client,
  381. uint32_t sessionId,
  382. BatchingOptions batchOptions) :
  383. LocMsg(),
  384. mAdapter(adapter),
  385. mApi(api),
  386. mClient(client),
  387. mSessionId(sessionId),
  388. mBatchOptions(batchOptions) {}
  389. inline virtual void proc() const {
  390. if (!mAdapter.isEngineCapabilitiesKnown()) {
  391. mAdapter.mPendingMsgs.push_back(new MsgUpdateBatching(*this));
  392. return;
  393. }
  394. LocationError err = LOCATION_ERROR_SUCCESS;
  395. if (!mAdapter.isBatchingSession(mClient, mSessionId)) {
  396. err = LOCATION_ERROR_ID_UNKNOWN;
  397. } else if ((0 == mBatchOptions.size) ||
  398. (mBatchOptions.batchingMode > BATCHING_MODE_NO_AUTO_REPORT)) {
  399. err = LOCATION_ERROR_INVALID_PARAMETER;
  400. }
  401. if (LOCATION_ERROR_SUCCESS == err) {
  402. if (!mAdapter.isTripSession(mSessionId)) {
  403. mAdapter.stopBatching(mClient, mSessionId, true, mBatchOptions);
  404. } else {
  405. mAdapter.stopTripBatchingMultiplex(mClient, mSessionId, true, mBatchOptions);
  406. }
  407. }
  408. }
  409. };
  410. sendMsg(new MsgUpdateBatching(*this, *mLocApi, client, id, batchOptions));
  411. }
  412. void
  413. BatchingAdapter::stopBatchingCommand(LocationAPI* client, uint32_t id)
  414. {
  415. LOC_LOGD("%s]: client %p id %u", __func__, client, id);
  416. struct MsgStopBatching : public LocMsg {
  417. BatchingAdapter& mAdapter;
  418. LocApiBase& mApi;
  419. LocationAPI* mClient;
  420. uint32_t mSessionId;
  421. inline MsgStopBatching(BatchingAdapter& adapter,
  422. LocApiBase& api,
  423. LocationAPI* client,
  424. uint32_t sessionId) :
  425. LocMsg(),
  426. mAdapter(adapter),
  427. mApi(api),
  428. mClient(client),
  429. mSessionId(sessionId) {}
  430. inline virtual void proc() const {
  431. if (!mAdapter.isEngineCapabilitiesKnown()) {
  432. mAdapter.mPendingMsgs.push_back(new MsgStopBatching(*this));
  433. return;
  434. }
  435. LocationError err = LOCATION_ERROR_SUCCESS;
  436. if (!mAdapter.isBatchingSession(mClient, mSessionId)) {
  437. err = LOCATION_ERROR_ID_UNKNOWN;
  438. }
  439. if (LOCATION_ERROR_SUCCESS == err) {
  440. if (mAdapter.isTripSession(mSessionId)) {
  441. mAdapter.stopTripBatchingMultiplex(mClient, mSessionId);
  442. } else {
  443. mAdapter.stopBatching(mClient, mSessionId);
  444. }
  445. }
  446. }
  447. };
  448. sendMsg(new MsgStopBatching(*this, *mLocApi, client, id));
  449. }
  450. void
  451. BatchingAdapter::stopBatching(LocationAPI* client, uint32_t sessionId, bool restartNeeded,
  452. const BatchingOptions& batchOptions, bool eraseSession)
  453. {
  454. LocationSessionKey key(client, sessionId);
  455. auto it = mBatchingSessions.find(key);
  456. if (it != mBatchingSessions.end()) {
  457. auto flpOptions = it->second;
  458. // Assume stop will be OK, restore session if not
  459. if (eraseSession)
  460. eraseBatchingSession(client, sessionId);
  461. mLocApi->stopBatching(sessionId,
  462. new LocApiResponse(*getContext(),
  463. [this, client, sessionId, flpOptions, restartNeeded, batchOptions, eraseSession]
  464. (LocationError err) {
  465. if (LOCATION_ERROR_SUCCESS != err) {
  466. if (eraseSession)
  467. saveBatchingSession(client, sessionId, batchOptions);
  468. } else {
  469. // if stopBatching is success, unregister for batch full event if this was the last
  470. // batching session that is interested in batch full event
  471. if (0 == autoReportBatchingSessionsCount() &&
  472. flpOptions.batchingMode != BATCHING_MODE_NO_AUTO_REPORT) {
  473. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  474. LOC_REGISTRATION_MASK_DISABLED);
  475. }
  476. if (restartNeeded) {
  477. if (batchOptions.batchingMode == BATCHING_MODE_ROUTINE ||
  478. batchOptions.batchingMode == BATCHING_MODE_NO_AUTO_REPORT) {
  479. startBatching(client, sessionId, batchOptions);
  480. } else if (batchOptions.batchingMode == BATCHING_MODE_TRIP) {
  481. startTripBatchingMultiplex(client, sessionId, batchOptions);
  482. }
  483. }
  484. }
  485. reportResponse(client, err, sessionId);
  486. }));
  487. }
  488. }
  489. void
  490. BatchingAdapter::getBatchedLocationsCommand(LocationAPI* client, uint32_t id, size_t count)
  491. {
  492. LOC_LOGD("%s]: client %p id %u count %zu", __func__, client, id, count);
  493. struct MsgGetBatchedLocations : public LocMsg {
  494. BatchingAdapter& mAdapter;
  495. LocApiBase& mApi;
  496. LocationAPI* mClient;
  497. uint32_t mSessionId;
  498. size_t mCount;
  499. inline MsgGetBatchedLocations(BatchingAdapter& adapter,
  500. LocApiBase& api,
  501. LocationAPI* client,
  502. uint32_t sessionId,
  503. size_t count) :
  504. LocMsg(),
  505. mAdapter(adapter),
  506. mApi(api),
  507. mClient(client),
  508. mSessionId(sessionId),
  509. mCount(count) {}
  510. inline virtual void proc() const {
  511. if (!mAdapter.isEngineCapabilitiesKnown()) {
  512. mAdapter.mPendingMsgs.push_back(new MsgGetBatchedLocations(*this));
  513. return;
  514. }
  515. LocationError err = LOCATION_ERROR_SUCCESS;
  516. if (!mAdapter.hasBatchingCallback(mClient)) {
  517. err = LOCATION_ERROR_CALLBACK_MISSING;
  518. } else if (!mAdapter.isBatchingSession(mClient, mSessionId)) {
  519. err = LOCATION_ERROR_ID_UNKNOWN;
  520. }
  521. if (LOCATION_ERROR_SUCCESS == err) {
  522. if (mAdapter.isTripSession(mSessionId)) {
  523. mApi.getBatchedTripLocations(mCount, 0,
  524. new LocApiResponse(*mAdapter.getContext(),
  525. [&mAdapter = mAdapter, mSessionId = mSessionId,
  526. mClient = mClient] (LocationError err) {
  527. mAdapter.reportResponse(mClient, err, mSessionId);
  528. }));
  529. } else {
  530. mApi.getBatchedLocations(mCount, new LocApiResponse(*mAdapter.getContext(),
  531. [&mAdapter = mAdapter, mSessionId = mSessionId,
  532. mClient = mClient] (LocationError err) {
  533. mAdapter.reportResponse(mClient, err, mSessionId);
  534. }));
  535. }
  536. } else {
  537. mAdapter.reportResponse(mClient, err, mSessionId);
  538. }
  539. }
  540. };
  541. sendMsg(new MsgGetBatchedLocations(*this, *mLocApi, client, id, count));
  542. }
  543. void
  544. BatchingAdapter::reportLocationsEvent(const Location* locations, size_t count,
  545. BatchingMode batchingMode)
  546. {
  547. LOC_LOGD("%s]: count %zu batchMode %d", __func__, count, batchingMode);
  548. struct MsgReportLocations : public LocMsg {
  549. BatchingAdapter& mAdapter;
  550. Location* mLocations;
  551. size_t mCount;
  552. BatchingMode mBatchingMode;
  553. inline MsgReportLocations(BatchingAdapter& adapter,
  554. const Location* locations,
  555. size_t count,
  556. BatchingMode batchingMode) :
  557. LocMsg(),
  558. mAdapter(adapter),
  559. mLocations(new Location[count]),
  560. mCount(count),
  561. mBatchingMode(batchingMode)
  562. {
  563. if (nullptr == mLocations) {
  564. LOC_LOGE("%s]: new failed to allocate mLocations", __func__);
  565. return;
  566. }
  567. for (size_t i=0; i < mCount; ++i) {
  568. mLocations[i] = locations[i];
  569. }
  570. }
  571. inline virtual ~MsgReportLocations() {
  572. if (nullptr != mLocations)
  573. delete[] mLocations;
  574. }
  575. inline virtual void proc() const {
  576. mAdapter.reportLocations(mLocations, mCount, mBatchingMode);
  577. }
  578. };
  579. sendMsg(new MsgReportLocations(*this, locations, count, batchingMode));
  580. }
  581. void
  582. BatchingAdapter::reportLocations(Location* locations, size_t count, BatchingMode batchingMode)
  583. {
  584. BatchingOptions batchOptions = {sizeof(BatchingOptions), batchingMode};
  585. for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
  586. if (nullptr != it->second.batchingCb) {
  587. it->second.batchingCb(count, locations, batchOptions);
  588. }
  589. }
  590. }
  591. void
  592. BatchingAdapter::reportCompletedTripsEvent(uint32_t accumulated_distance)
  593. {
  594. struct MsgReportCompletedTrips : public LocMsg {
  595. BatchingAdapter& mAdapter;
  596. uint32_t mAccumulatedDistance;
  597. inline MsgReportCompletedTrips(BatchingAdapter& adapter,
  598. uint32_t accumulated_distance) :
  599. LocMsg(),
  600. mAdapter(adapter),
  601. mAccumulatedDistance(accumulated_distance)
  602. {
  603. }
  604. inline virtual ~MsgReportCompletedTrips() {
  605. }
  606. inline virtual void proc() const {
  607. // Check if any trips are completed
  608. std::list<uint32_t> completedTripsList;
  609. completedTripsList.clear();
  610. for(auto itt = mAdapter.mTripSessions.begin(); itt != mAdapter.mTripSessions.end();)
  611. {
  612. TripSessionStatus &tripSession = itt->second;
  613. tripSession.accumulatedDistanceThisTrip =
  614. tripSession.accumulatedDistanceOnTripRestart
  615. + (mAccumulatedDistance - tripSession.accumulatedDistanceOngoingBatch);
  616. if (tripSession.tripDistance <= tripSession.accumulatedDistanceThisTrip) {
  617. // trip is completed
  618. completedTripsList.push_back(itt->first);
  619. itt = mAdapter.mTripSessions.erase(itt);
  620. if (tripSession.tripTBFInterval == mAdapter.mOngoingTripTBFInterval) {
  621. // trip with ongoing TBF interval is completed
  622. mAdapter.mTripWithOngoingTBFDropped = true;
  623. }
  624. if (tripSession.tripDistance == mAdapter.mOngoingTripDistance) {
  625. // trip with ongoing trip distance is completed
  626. mAdapter.mTripWithOngoingTripDistanceDropped = true;
  627. }
  628. } else {
  629. itt++;
  630. }
  631. }
  632. if (completedTripsList.size() > 0) {
  633. mAdapter.reportBatchStatusChange(BATCHING_STATUS_TRIP_COMPLETED,
  634. completedTripsList);
  635. mAdapter.restartTripBatching(false, mAccumulatedDistance, 0);
  636. } else {
  637. mAdapter.printTripReport();
  638. }
  639. }
  640. };
  641. LOC_LOGD("%s]: Accumulated Distance so far: %u",
  642. __func__, accumulated_distance);
  643. sendMsg(new MsgReportCompletedTrips(*this, accumulated_distance));
  644. }
  645. void
  646. BatchingAdapter::reportBatchStatusChange(BatchingStatus batchStatus,
  647. std::list<uint32_t> & completedTripsList)
  648. {
  649. BatchingStatusInfo batchStatusInfo =
  650. {sizeof(BatchingStatusInfo), batchStatus};
  651. for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
  652. if (nullptr != it->second.batchingStatusCb) {
  653. it->second.batchingStatusCb(batchStatusInfo, completedTripsList);
  654. }
  655. }
  656. }
  657. void
  658. BatchingAdapter::reportBatchStatusChangeEvent(BatchingStatus batchStatus)
  659. {
  660. struct MsgReportBatchStatus : public LocMsg {
  661. BatchingAdapter& mAdapter;
  662. BatchingStatus mBatchStatus;
  663. inline MsgReportBatchStatus(BatchingAdapter& adapter,
  664. BatchingStatus batchStatus) :
  665. LocMsg(),
  666. mAdapter(adapter),
  667. mBatchStatus(batchStatus)
  668. {
  669. }
  670. inline virtual ~MsgReportBatchStatus() {
  671. }
  672. inline virtual void proc() const {
  673. std::list<uint32_t> tempList;
  674. tempList.clear();
  675. mAdapter.reportBatchStatusChange(mBatchStatus, tempList);
  676. }
  677. };
  678. sendMsg(new MsgReportBatchStatus(*this, batchStatus));
  679. }
  680. void
  681. BatchingAdapter::startTripBatchingMultiplex(LocationAPI* client, uint32_t sessionId,
  682. const BatchingOptions& batchingOptions)
  683. {
  684. if (mTripSessions.size() == 0) {
  685. // if there is currenty no batching sessions interested in batch full event, then this
  686. // new session will need to register for batch full event
  687. if (0 == autoReportBatchingSessionsCount()) {
  688. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  689. LOC_REGISTRATION_MASK_ENABLED);
  690. }
  691. // Assume start will be OK, remove session if not
  692. saveBatchingSession(client, sessionId, batchingOptions);
  693. mTripSessions[sessionId] = { 0, 0, 0, batchingOptions.minDistance,
  694. batchingOptions.minInterval};
  695. mLocApi->startOutdoorTripBatching(batchingOptions.minDistance,
  696. batchingOptions.minInterval, getBatchingTimeout(), new LocApiResponse(*getContext(),
  697. [this, client, sessionId, batchingOptions] (LocationError err) {
  698. if (err == LOCATION_ERROR_SUCCESS) {
  699. mOngoingTripDistance = batchingOptions.minDistance;
  700. mOngoingTripTBFInterval = batchingOptions.minInterval;
  701. LOC_LOGD("%s] New Trip started ...", __func__);
  702. printTripReport();
  703. } else {
  704. eraseBatchingSession(client, sessionId);
  705. mTripSessions.erase(sessionId);
  706. // if we fail to start batching and we have already registered batch full event
  707. // we need to undo that since no sessions are now interested in batch full event
  708. if (0 == autoReportBatchingSessionsCount()) {
  709. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  710. LOC_REGISTRATION_MASK_DISABLED);
  711. }
  712. }
  713. reportResponse(client, err, sessionId);
  714. }));
  715. } else {
  716. // query accumulated distance
  717. mLocApi->queryAccumulatedTripDistance(
  718. new LocApiResponseData<LocApiBatchData>(*getContext(),
  719. [this, batchingOptions, sessionId, client]
  720. (LocationError err, LocApiBatchData data) {
  721. uint32_t accumulatedDistanceOngoingBatch = 0;
  722. uint32_t numOfBatchedPositions = 0;
  723. uint32_t ongoingTripDistance = mOngoingTripDistance;
  724. uint32_t ongoingTripInterval = mOngoingTripTBFInterval;
  725. bool needsRestart = false;
  726. // check if TBF of new session is lesser than ongoing TBF interval
  727. if (ongoingTripInterval > batchingOptions.minInterval) {
  728. ongoingTripInterval = batchingOptions.minInterval;
  729. needsRestart = true;
  730. }
  731. accumulatedDistanceOngoingBatch = data.accumulatedDistance;
  732. numOfBatchedPositions = data.numOfBatchedPositions;
  733. TripSessionStatus newTripSession = { accumulatedDistanceOngoingBatch, 0, 0,
  734. batchingOptions.minDistance,
  735. batchingOptions.minInterval};
  736. if (err != LOCATION_ERROR_SUCCESS) {
  737. // unable to query accumulated distance, assume remaining distance in
  738. // ongoing batch is mongoingTripDistance.
  739. if (batchingOptions.minDistance < ongoingTripDistance) {
  740. ongoingTripDistance = batchingOptions.minDistance;
  741. needsRestart = true;
  742. }
  743. } else {
  744. // compute the remaining distance
  745. uint32_t ongoing_trip_remaining_distance = ongoingTripDistance -
  746. accumulatedDistanceOngoingBatch;
  747. // check if new trip distance is lesser than the ongoing batch remaining distance
  748. if (batchingOptions.minDistance < ongoing_trip_remaining_distance) {
  749. ongoingTripDistance = batchingOptions.minDistance;
  750. needsRestart = true;
  751. } else if (needsRestart == true) {
  752. // needsRestart is anyways true , may be because of lesser TBF of new session.
  753. ongoingTripDistance = ongoing_trip_remaining_distance;
  754. }
  755. mTripSessions[sessionId] = newTripSession;
  756. LOC_LOGD("%s] New Trip started ...", __func__);
  757. printTripReport();
  758. }
  759. if (needsRestart) {
  760. mOngoingTripDistance = ongoingTripDistance;
  761. mOngoingTripTBFInterval = ongoingTripInterval;
  762. // reset the accumulatedDistanceOngoingBatch for each session,
  763. // and record the total accumulated distance so far for the session.
  764. for (auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) {
  765. TripSessionStatus &tripSessStatus = itt->second;
  766. tripSessStatus.accumulatedDistanceOngoingBatch = 0;
  767. tripSessStatus.accumulatedDistanceOnTripRestart =
  768. tripSessStatus.accumulatedDistanceThisTrip;
  769. }
  770. mLocApi->reStartOutdoorTripBatching(ongoingTripDistance, ongoingTripInterval,
  771. getBatchingTimeout(), new LocApiResponse(*getContext(),
  772. [this, client, sessionId] (LocationError err) {
  773. if (err != LOCATION_ERROR_SUCCESS) {
  774. LOC_LOGE("%s] New Trip restart failed!", __func__);
  775. }
  776. reportResponse(client, err, sessionId);
  777. }));
  778. } else {
  779. reportResponse(client, LOCATION_ERROR_SUCCESS, sessionId);
  780. }
  781. }));
  782. }
  783. }
  784. void
  785. BatchingAdapter::stopTripBatchingMultiplex(LocationAPI* client, uint32_t sessionId,
  786. bool restartNeeded, const BatchingOptions& batchOptions, bool eraseSession)
  787. {
  788. LocationError err = LOCATION_ERROR_SUCCESS;
  789. if (mTripSessions.size() == 1) {
  790. mLocApi->stopOutdoorTripBatching(true, new LocApiResponse(*getContext(),
  791. [this, restartNeeded, client, sessionId, batchOptions, eraseSession]
  792. (LocationError err) {
  793. if (LOCATION_ERROR_SUCCESS == err) {
  794. // if stopOutdoorTripBatching is success, unregister for batch full event if this
  795. // was the last batching session that is interested in batch full event
  796. if (1 == autoReportBatchingSessionsCount()) {
  797. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  798. LOC_REGISTRATION_MASK_DISABLED);
  799. }
  800. }
  801. stopTripBatchingMultiplexCommon(err, client, sessionId, restartNeeded,
  802. batchOptions, eraseSession);
  803. }));
  804. return;
  805. }
  806. stopTripBatchingMultiplexCommon(err, client, sessionId, restartNeeded,
  807. batchOptions, eraseSession);
  808. }
  809. void
  810. BatchingAdapter::stopTripBatchingMultiplexCommon(LocationError err, LocationAPI* client,
  811. uint32_t sessionId, bool restartNeeded, const BatchingOptions& batchOptions,
  812. bool eraseSession)
  813. {
  814. auto itt = mTripSessions.find(sessionId);
  815. TripSessionStatus tripSess = itt->second;
  816. if (tripSess.tripTBFInterval == mOngoingTripTBFInterval) {
  817. // trip with ongoing trip interval is stopped
  818. mTripWithOngoingTBFDropped = true;
  819. }
  820. if (tripSess.tripDistance == mOngoingTripDistance) {
  821. // trip with ongoing trip distance is stopped
  822. mTripWithOngoingTripDistanceDropped = true;
  823. }
  824. if (eraseSession)
  825. mTripSessions.erase(sessionId);
  826. if (mTripSessions.size() == 0) {
  827. mOngoingTripDistance = 0;
  828. mOngoingTripTBFInterval = 0;
  829. } else {
  830. restartTripBatching(true);
  831. }
  832. if (restartNeeded) {
  833. eraseBatchingSession(client, sessionId);
  834. if (batchOptions.batchingMode == BATCHING_MODE_ROUTINE ||
  835. batchOptions.batchingMode == BATCHING_MODE_NO_AUTO_REPORT) {
  836. startBatching(client, sessionId, batchOptions);
  837. } else if (batchOptions.batchingMode == BATCHING_MODE_TRIP) {
  838. startTripBatchingMultiplex(client, sessionId, batchOptions);
  839. }
  840. }
  841. reportResponse(client, err, sessionId);
  842. }
  843. void
  844. BatchingAdapter::restartTripBatching(bool queryAccumulatedDistance, uint32_t accDist,
  845. uint32_t numbatchedPos)
  846. {
  847. // does batch need restart with new trip distance / TBF interval
  848. uint32_t minRemainingDistance = 0;
  849. uint32_t minTBFInterval = 0;
  850. // if no more trips left, stop the ongoing trip
  851. if (mTripSessions.size() == 0) {
  852. mLocApi->stopOutdoorTripBatching(true, new LocApiResponse(*getContext(),
  853. [] (LocationError /*err*/) {}));
  854. mOngoingTripDistance = 0;
  855. mOngoingTripTBFInterval = 0;
  856. // unregister for batch full event if there are no more
  857. // batching session that is interested in batch full event
  858. if (0 == autoReportBatchingSessionsCount()) {
  859. updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL,
  860. LOC_REGISTRATION_MASK_DISABLED);
  861. }
  862. return;
  863. }
  864. // record the min trip distance and min tbf interval of all ongoing sessions
  865. for (auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) {
  866. TripSessionStatus tripSessStatus = itt->second;
  867. if ((minRemainingDistance == 0) ||
  868. (minRemainingDistance > (tripSessStatus.tripDistance
  869. - tripSessStatus.accumulatedDistanceThisTrip))) {
  870. minRemainingDistance = tripSessStatus.tripDistance -
  871. tripSessStatus.accumulatedDistanceThisTrip;
  872. }
  873. if ((minTBFInterval == 0) ||
  874. (minTBFInterval > tripSessStatus.tripTBFInterval)) {
  875. minTBFInterval = tripSessStatus.tripTBFInterval;
  876. }
  877. }
  878. mLocApi->queryAccumulatedTripDistance(
  879. new LocApiResponseData<LocApiBatchData>(*getContext(),
  880. [this, queryAccumulatedDistance, minRemainingDistance, minTBFInterval, accDist,
  881. numbatchedPos] (LocationError /*err*/, LocApiBatchData data) {
  882. bool needsRestart = false;
  883. uint32_t ongoingTripDistance = mOngoingTripDistance;
  884. uint32_t ongoingTripInterval = mOngoingTripTBFInterval;
  885. uint32_t accumulatedDistance = accDist;
  886. uint32_t numOfBatchedPositions = numbatchedPos;
  887. if (queryAccumulatedDistance) {
  888. accumulatedDistance = data.accumulatedDistance;
  889. numOfBatchedPositions = data.numOfBatchedPositions;
  890. }
  891. if ((!mTripWithOngoingTripDistanceDropped) &&
  892. (ongoingTripDistance - accumulatedDistance != 0)) {
  893. // if ongoing trip is already not completed still,
  894. // check the min distance against the remaining distance
  895. if (minRemainingDistance <
  896. (ongoingTripDistance - accumulatedDistance)) {
  897. ongoingTripDistance = minRemainingDistance;
  898. needsRestart = true;
  899. }
  900. } else if (minRemainingDistance != 0) {
  901. // else if ongoing trip is already completed / dropped,
  902. // use the minRemainingDistance of ongoing sessions
  903. ongoingTripDistance = minRemainingDistance;
  904. needsRestart = true;
  905. }
  906. if ((minTBFInterval < ongoingTripInterval) ||
  907. ((minTBFInterval != ongoingTripInterval) &&
  908. (mTripWithOngoingTBFDropped))) {
  909. ongoingTripInterval = minTBFInterval;
  910. needsRestart = true;
  911. }
  912. if (needsRestart) {
  913. mLocApi->reStartOutdoorTripBatching(ongoingTripDistance, ongoingTripInterval,
  914. getBatchingTimeout(), new LocApiResponse(*getContext(),
  915. [this, accumulatedDistance, ongoingTripDistance, ongoingTripInterval]
  916. (LocationError err) {
  917. if (err == LOCATION_ERROR_SUCCESS) {
  918. for(auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) {
  919. TripSessionStatus &tripSessStatus = itt->second;
  920. tripSessStatus.accumulatedDistanceThisTrip =
  921. tripSessStatus.accumulatedDistanceOnTripRestart +
  922. (accumulatedDistance -
  923. tripSessStatus.accumulatedDistanceOngoingBatch);
  924. tripSessStatus.accumulatedDistanceOngoingBatch = 0;
  925. tripSessStatus.accumulatedDistanceOnTripRestart =
  926. tripSessStatus.accumulatedDistanceThisTrip;
  927. }
  928. mOngoingTripDistance = ongoingTripDistance;
  929. mOngoingTripTBFInterval = ongoingTripInterval;
  930. }
  931. }));
  932. }
  933. }));
  934. }
  935. void
  936. BatchingAdapter::updateSystemPowerStateCommand(PowerStateType powerState)
  937. {
  938. LOC_LOGD("%s]: powerState: %d", __func__, powerState);
  939. struct MsgUpdateSystemPowerState : public LocMsg {
  940. BatchingAdapter& mAdapter;
  941. PowerStateType mPowerState;
  942. inline MsgUpdateSystemPowerState(BatchingAdapter& adapter,
  943. PowerStateType powerState) :
  944. mAdapter(adapter),
  945. mPowerState(powerState) {}
  946. inline virtual void proc() const {
  947. mAdapter.updateSystemPowerState(mPowerState);
  948. }
  949. };
  950. sendMsg(new MsgUpdateSystemPowerState(*this, powerState));
  951. }
  952. void
  953. BatchingAdapter::suspendBatchingSessions()
  954. {
  955. for (auto it = mBatchingSessions.begin(); it != mBatchingSessions.end(); ++it) {
  956. LocationSessionKey key(it->first);
  957. stopClientSessions(key.client, false);
  958. }
  959. }
  960. void
  961. BatchingAdapter::updateSystemPowerState(PowerStateType systemPowerState)
  962. {
  963. if (POWER_STATE_UNKNOWN != systemPowerState) {
  964. mSystemPowerState = systemPowerState;
  965. /*Manage active GNSS sessions based on power event*/
  966. switch (systemPowerState){
  967. case POWER_STATE_SUSPEND:
  968. case POWER_STATE_SHUTDOWN:
  969. suspendBatchingSessions();
  970. LOC_LOGd("Suspending all Batching session -- powerState: %d", systemPowerState);
  971. break;
  972. case POWER_STATE_RESUME:
  973. restartSessions();
  974. LOC_LOGd("Re-starting all Batching session -- powerState: %d", systemPowerState);
  975. break;
  976. default:
  977. break;
  978. } // switch
  979. }
  980. }
  981. void
  982. BatchingAdapter::printTripReport()
  983. {
  984. IF_LOC_LOGD {
  985. LOC_LOGD("Ongoing Trip Distance = %u, Ongoing Trip TBF Interval = %u",
  986. mOngoingTripDistance, mOngoingTripTBFInterval);
  987. for (auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) {
  988. TripSessionStatus tripSessStatus = itt->second;
  989. LOC_LOGD("tripDistance:%u tripTBFInterval:%u"
  990. " trip accumulated Distance:%u"
  991. " trip accumualted distance ongoing batch:%u"
  992. " trip accumulated distance on trip restart %u \r\n",
  993. tripSessStatus.tripDistance, tripSessStatus.tripTBFInterval,
  994. tripSessStatus.accumulatedDistanceThisTrip,
  995. tripSessStatus.accumulatedDistanceOngoingBatch,
  996. tripSessStatus.accumulatedDistanceOnTripRestart);
  997. }
  998. }
  999. }