CLastChannel: fix narrowing conversion warnings in lastchannel.cpp

- Changed _LastCh.timestamp to int64_t for compatibility with tv.tv_sec.
- Updated store method to cast tv.tv_sec to int64_t, preventing warnings.
- Ensured timestamp calculations use int64_t for consistency.

This shoold resolve compilation warnings and improve platform independence.
This commit is contained in:
2024-07-04 16:08:36 +02:00
parent c1fa8595de
commit d533372aa8
2 changed files with 11 additions and 11 deletions

View File

@@ -39,35 +39,36 @@ void CLastChannel::clear (void)
// -- Store only if channel != last channel and time store delay is large enough // -- Store only if channel != last channel and time store delay is large enough
// forceStoreToLastChannels default to false // forceStoreToLastChannels default to false
void CLastChannel::store (t_channel_id channel_id) void CLastChannel::store(t_channel_id channel_id)
{ {
struct timeval tv; struct timeval tv;
unsigned long lastTimestamp(0); int64_t lastTimestamp(0);
unsigned long timeDiff; int64_t timeDiff;
std::list<_LastCh>::iterator It; std::list<_LastCh>::iterator It;
gettimeofday (&tv, NULL); gettimeofday(&tv, NULL);
if (!this->lastChannels.empty()) if (!this->lastChannels.empty())
lastTimestamp = this->lastChannels.front().timestamp; lastTimestamp = this->lastChannels.front().timestamp;
timeDiff = tv.tv_sec - lastTimestamp; timeDiff = tv.tv_sec - lastTimestamp;
/* prev zap time was less than treshhold, remove prev channel */ /* prev zap time was less than threshold, remove prev channel */
if(!this->lastChannels.empty() && (timeDiff <= secs_diff_before_store)) if (!this->lastChannels.empty() && (timeDiff <= secs_diff_before_store))
this->lastChannels.pop_front(); this->lastChannels.pop_front();
/* push new channel to the head */ /* push new channel to the head */
_LastCh newChannel = {/*channel,*/ channel_id, tv.tv_sec, CNeutrinoApp::getInstance()->GetChannelMode()}; _LastCh newChannel = {/*channel,*/ channel_id, static_cast<int64_t>(tv.tv_sec), CNeutrinoApp::getInstance()->GetChannelMode()};
this->lastChannels.push_front(newChannel); this->lastChannels.push_front(newChannel);
/* this zap time was more than treshhold, it will stay, remove last in the list */ /* this zap time was more than threshold, it will stay, remove last in the list */
if ((timeDiff > secs_diff_before_store) && (this->lastChannels.size() > this->maxSize)) if ((timeDiff > secs_diff_before_store) && (this->lastChannels.size() > this->maxSize))
this->lastChannels.pop_back(); this->lastChannels.pop_back();
/* remove this channel at other than 0 position */ /* remove this channel at other than 0 position */
if(this->lastChannels.size() > 1) { if (this->lastChannels.size() > 1)
{
It = this->lastChannels.begin(); It = this->lastChannels.begin();
++It; ++It;
for (; It != this->lastChannels.end(); ++It) for (; It != this->lastChannels.end(); ++It)

View File

@@ -27,12 +27,11 @@ nicht gespeichert werden.
class CLastChannel class CLastChannel
{ {
private: private:
struct _LastCh struct _LastCh
{ {
t_channel_id channel_id; t_channel_id channel_id;
long int timestamp; int64_t timestamp;
int channel_mode; int channel_mode;
}; };