@@ -92,14 +92,14 @@ Connector::Connector(Context& context, std::shared_ptr<FilesystemAdapter> filesy
9292 if (txNrPivot == std::numeric_limits<unsigned int >::max ()) {
9393 txNrPivot = parsedTxNr;
9494 txNrBegin = parsedTxNr;
95- txNrBack = (parsedTxNr + 1 ) % MAX_TX_CNT;
95+ txNrEnd = (parsedTxNr + 1 ) % MAX_TX_CNT;
9696 return 0 ;
9797 }
9898
9999 if ((parsedTxNr + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT < MAX_TX_CNT / 2 ) {
100100 // parsedTxNr is after pivot point
101- if ((parsedTxNr + 1 + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT > (txNrBack + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT) {
102- txNrBack = (parsedTxNr + 1 ) % MAX_TX_CNT;
101+ if ((parsedTxNr + 1 + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT > (txNrEnd + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT) {
102+ txNrEnd = (parsedTxNr + 1 ) % MAX_TX_CNT;
103103 }
104104 } else if ((txNrPivot + MAX_TX_CNT - parsedTxNr) % MAX_TX_CNT < MAX_TX_CNT / 2 ) {
105105 // parsedTxNr is before pivot point
@@ -108,16 +108,16 @@ Connector::Connector(Context& context, std::shared_ptr<FilesystemAdapter> filesy
108108 }
109109 }
110110
111- MO_DBG_DEBUG (" found %s%u.jsn - Internal range from %u to %u (exclusive)" , txFnamePrefix, parsedTxNr, txNrBegin, txNrBack );
111+ MO_DBG_DEBUG (" found %s%u.jsn - Internal range from %u to %u (exclusive)" , txFnamePrefix, parsedTxNr, txNrBegin, txNrEnd );
112112 }
113113 return 0 ;
114114 });
115115
116- MO_DBG_DEBUG (" found %u transactions for connector %u. Internal range from %u to %u (exclusive)" , (txNrBack + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT, connectorId, txNrBegin, txNrBack );
116+ MO_DBG_DEBUG (" found %u transactions for connector %u. Internal range from %u to %u (exclusive)" , (txNrEnd + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT, connectorId, txNrBegin, txNrEnd );
117117 txNrFront = txNrBegin;
118118
119119 if (model.getTransactionStore ()) {
120- unsigned int txNrLatest = (txNrBack + MAX_TX_CNT - 1 ) % MAX_TX_CNT; // txNr of the most recent tx on flash
120+ unsigned int txNrLatest = (txNrEnd + MAX_TX_CNT - 1 ) % MAX_TX_CNT; // txNr of the most recent tx on flash
121121 transaction = model.getTransactionStore ()->getTransaction (connectorId, txNrLatest); // returns nullptr if txNrLatest does not exist on flash
122122 } else {
123123 MO_DBG_ERR (" must initialize TxStore before Connector" );
@@ -263,26 +263,26 @@ void Connector::loop() {
263263 }
264264
265265 if (removed) {
266- if (txNrFront == txNrBack ) {
266+ if (txNrFront == txNrEnd ) {
267267 txNrFront = transaction->getTxNr ();
268268 }
269- txNrBack = transaction->getTxNr (); // roll back creation of last tx entry
269+ txNrEnd = transaction->getTxNr (); // roll back creation of last tx entry
270270 }
271271
272272 MO_DBG_DEBUG (" collect aborted or silent transaction %u-%u %s" , connectorId, transaction->getTxNr (), removed ? " " : " failure" );
273- MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrBack =%u" , txNrBegin, txNrFront, txNrBack );
273+ MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrEnd =%u" , txNrBegin, txNrFront, txNrEnd );
274274 transaction = nullptr ;
275275 }
276276
277277 if (transaction && transaction->isAborted ()) {
278278 MO_DBG_DEBUG (" collect aborted transaction %u-%u" , connectorId, transaction->getTxNr ());
279- MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrBack =%u" , txNrBegin, txNrFront, txNrBack );
279+ MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrEnd =%u" , txNrBegin, txNrFront, txNrEnd );
280280 transaction = nullptr ;
281281 }
282282
283283 if (transaction && transaction->getStopSync ().isRequested ()) {
284284 MO_DBG_DEBUG (" collect obsolete transaction %u-%u" , connectorId, transaction->getTxNr ());
285- MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrBack =%u" , txNrBegin, txNrFront, txNrBack );
285+ MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrEnd =%u" , txNrBegin, txNrFront, txNrEnd );
286286 transaction = nullptr ;
287287 }
288288
@@ -550,8 +550,8 @@ std::shared_ptr<Transaction> Connector::allocateTransaction() {
550550 std::shared_ptr<Transaction> tx;
551551
552552 // clean possible aborted tx
553- unsigned int txr = txNrBack ;
554- unsigned int txSize = (txNrBack + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT;
553+ unsigned int txr = txNrEnd ;
554+ unsigned int txSize = (txNrEnd + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT;
555555 for (unsigned int i = 0 ; i < txSize; i++) {
556556 txr = (txr + MAX_TX_CNT - 1 ) % MAX_TX_CNT; // decrement by 1
557557
@@ -567,10 +567,10 @@ std::shared_ptr<Transaction> Connector::allocateTransaction() {
567567 removed &= model.getTransactionStore ()->remove (connectorId, txr);
568568 }
569569 if (removed) {
570- if (txNrFront == txNrBack ) {
570+ if (txNrFront == txNrEnd ) {
571571 txNrFront = txr;
572572 }
573- txNrBack = txr;
573+ txNrEnd = txr;
574574 MO_DBG_WARN (" deleted dangling silent or aborted tx for new transaction" );
575575 } else {
576576 MO_DBG_ERR (" memory corruption" );
@@ -582,18 +582,18 @@ std::shared_ptr<Transaction> Connector::allocateTransaction() {
582582 }
583583 }
584584
585- txSize = (txNrBack + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT; // refresh after cleaning txs
585+ txSize = (txNrEnd + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT; // refresh after cleaning txs
586586
587587 // try to create new transaction
588588 if (txSize < MO_TXRECORD_SIZE) {
589- tx = model.getTransactionStore ()->createTransaction (connectorId, txNrBack );
589+ tx = model.getTransactionStore ()->createTransaction (connectorId, txNrEnd );
590590 }
591591
592592 if (!tx) {
593593 // could not create transaction - now, try to replace tx history entry
594594
595595 unsigned int txl = txNrBegin;
596- txSize = (txNrBack + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT;
596+ txSize = (txNrEnd + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT;
597597
598598 for (unsigned int i = 0 ; i < txSize; i++) {
599599
@@ -621,9 +621,9 @@ std::shared_ptr<Transaction> Connector::allocateTransaction() {
621621 txNrFront = txNrBegin;
622622 }
623623 MO_DBG_DEBUG (" deleted tx history entry for new transaction" );
624- MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrBack =%u" , txNrBegin, txNrFront, txNrBack );
624+ MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrEnd =%u" , txNrBegin, txNrFront, txNrEnd );
625625
626- tx = model.getTransactionStore ()->createTransaction (connectorId, txNrBack );
626+ tx = model.getTransactionStore ()->createTransaction (connectorId, txNrEnd );
627627 } else {
628628 MO_DBG_ERR (" memory corruption" );
629629 break ;
@@ -643,7 +643,7 @@ std::shared_ptr<Transaction> Connector::allocateTransaction() {
643643 // couldn't create normal transaction -> check if to start charging without real transaction
644644 if (silentOfflineTransactionsBool && silentOfflineTransactionsBool->getBool ()) {
645645 // try to handle charging session without sending StartTx or StopTx to the server
646- tx = model.getTransactionStore ()->createTransaction (connectorId, txNrBack , true );
646+ tx = model.getTransactionStore ()->createTransaction (connectorId, txNrEnd , true );
647647
648648 if (tx) {
649649 MO_DBG_DEBUG (" created silent transaction" );
@@ -661,9 +661,9 @@ std::shared_ptr<Transaction> Connector::allocateTransaction() {
661661 }
662662
663663 if (tx) {
664- txNrBack = (txNrBack + 1 ) % MAX_TX_CNT;
665- MO_DBG_DEBUG (" advance txNrBack %u-%u" , connectorId, txNrBack );
666- MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrBack =%u" , txNrBegin, txNrFront, txNrBack );
664+ txNrEnd = (txNrEnd + 1 ) % MAX_TX_CNT;
665+ MO_DBG_DEBUG (" advance txNrEnd %u-%u" , connectorId, txNrEnd );
666+ MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrEnd =%u" , txNrBegin, txNrFront, txNrEnd );
667667 }
668668
669669 return tx;
@@ -1083,12 +1083,12 @@ unsigned int Connector::getFrontRequestOpNr() {
10831083 * Advance front transaction?
10841084 */
10851085
1086- unsigned int txSize = (txNrBack + MAX_TX_CNT - txNrFront) % MAX_TX_CNT;
1086+ unsigned int txSize = (txNrEnd + MAX_TX_CNT - txNrFront) % MAX_TX_CNT;
10871087
10881088 if (transactionFront && txSize == 0 ) {
10891089 // catch edge case where txBack has been rolled back and txFront was equal to txBack
10901090 MO_DBG_DEBUG (" collect front transaction %u-%u after tx rollback" , connectorId, transactionFront->getTxNr ());
1091- MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrBack =%u" , txNrBegin, txNrFront, txNrBack );
1091+ MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrEnd =%u" , txNrBegin, txNrFront, txNrEnd );
10921092 transactionFront = nullptr ;
10931093 }
10941094
@@ -1110,7 +1110,7 @@ unsigned int Connector::getFrontRequestOpNr() {
11101110 MO_DBG_DEBUG (" collect front transaction %u-%u" , connectorId, transactionFront->getTxNr ());
11111111 transactionFront = nullptr ;
11121112 txNrFront = (txNrFront + 1 ) % MAX_TX_CNT;
1113- MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrBack =%u" , txNrBegin, txNrFront, txNrBack );
1113+ MO_DBG_VERBOSE (" txNrBegin=%u, txNrFront=%u, txNrEnd =%u" , txNrBegin, txNrFront, txNrEnd );
11141114 } else {
11151115 // front is accurate. Done here
11161116 break ;
@@ -1166,7 +1166,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
11661166 }
11671167
11681168 Timestamp nextAttempt = transactionFront->getStartSync ().getAttemptTime () +
1169- transactionFront->getStartSync ().getAttemptNr () * transactionMessageRetryIntervalInt->getInt ();
1169+ transactionFront->getStartSync ().getAttemptNr () * std::max ( 0 , transactionMessageRetryIntervalInt->getInt () );
11701170
11711171 if (nextAttempt > model.getClock ().now ()) {
11721172 return nullptr ;
@@ -1223,7 +1223,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12231223 }
12241224
12251225 Timestamp nextAttempt = transactionFront->getStopSync ().getAttemptTime () +
1226- transactionFront->getStopSync ().getAttemptNr () * transactionMessageRetryIntervalInt->getInt ();
1226+ transactionFront->getStopSync ().getAttemptNr () * std::max ( 0 , transactionMessageRetryIntervalInt->getInt () );
12271227
12281228 if (nextAttempt > model.getClock ().now ()) {
12291229 return nullptr ;
@@ -1270,3 +1270,15 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12701270
12711271 return nullptr ;
12721272}
1273+
1274+ unsigned int Connector::getTxNrBeginHistory () {
1275+ return txNrBegin;
1276+ }
1277+
1278+ unsigned int Connector::getTxNrFront () {
1279+ return txNrFront;
1280+ }
1281+
1282+ unsigned int Connector::getTxNrEnd () {
1283+ return txNrEnd;
1284+ }
0 commit comments