[PVR] added a unique id for each timer, valid as long as xbmc isn't reset
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 13 Feb 2014 00:05:04 +0000 (01:05 +0100)
committermontellese <montellese@xbmc.org>
Thu, 27 Feb 2014 19:01:32 +0000 (20:01 +0100)
xbmc/pvr/timers/PVRTimerInfoTag.cpp
xbmc/pvr/timers/PVRTimerInfoTag.h
xbmc/pvr/timers/PVRTimers.cpp
xbmc/pvr/timers/PVRTimers.h

index 92721c3..61ff9c3 100644 (file)
@@ -64,6 +64,7 @@ CPVRTimerInfoTag::CPVRTimerInfoTag(void)
   m_StopTime           = m_StartTime;
   m_state              = PVR_TIMER_STATE_SCHEDULED;
   m_FirstDay.SetValid(false);
+  m_iTimerId           = 0;
 }
 
 CPVRTimerInfoTag::CPVRTimerInfoTag(const PVR_TIMER &timer, CPVRChannelPtr channel, unsigned int iClientId)
@@ -93,6 +94,7 @@ CPVRTimerInfoTag::CPVRTimerInfoTag(const PVR_TIMER &timer, CPVRChannelPtr channe
   m_bIsRadio           = channel && channel->IsRadio();
   m_state              = timer.state;
   m_strFileNameAndPath = StringUtils::Format("pvr://client%i/timers/%i", m_iClientId, m_iClientIndex);
+  m_iTimerId           = 0;
 
   UpdateSummary();
 }
@@ -123,7 +125,8 @@ bool CPVRTimerInfoTag::operator ==(const CPVRTimerInfoTag& right) const
           m_iClientId          == right.m_iClientId &&
           m_iMarginStart       == right.m_iMarginStart &&
           m_iMarginEnd         == right.m_iMarginEnd &&
-          m_state              == right.m_state);
+          m_state              == right.m_state &&
+          m_iTimerId           == right.m_iTimerId);
 }
 
 CPVRTimerInfoTag &CPVRTimerInfoTag::operator=(const CPVRTimerInfoTag &orig)
@@ -148,6 +151,7 @@ CPVRTimerInfoTag &CPVRTimerInfoTag::operator=(const CPVRTimerInfoTag &orig)
   m_iMarginEnd         = orig.m_iMarginEnd;
   m_state              = orig.m_state;
   m_iChannelNumber     = orig.m_iChannelNumber;
+  m_iTimerId           = orig.m_iTimerId;
 
   return *this;
 }
index 576228e..06e6887 100644 (file)
@@ -173,6 +173,7 @@ namespace PVR
     CStdString            m_strFileNameAndPath; /*!< @brief filename is only for reference */
     int                   m_iChannelNumber;     /*!< @brief integer value of the channel number */
     bool                  m_bIsRadio;           /*!< @brief is radio channel if set */
+    unsigned int          m_iTimerId;           /*!< @brief id that won't change as long as XBMC is running */
 
     CPVRChannelPtr        m_channel;
     unsigned int          m_iMarginStart;       /*!< @brief (optional) if set, the backend starts the recording iMarginStart minutes before startTime. */
index eb8dcfc..d8935ec 100644 (file)
@@ -41,6 +41,7 @@ using namespace EPG;
 CPVRTimers::CPVRTimers(void)
 {
   m_bIsUpdating = false;
+  m_iLastId     = 0;
 }
 
 CPVRTimers::~CPVRTimers(void)
@@ -151,6 +152,7 @@ bool CPVRTimers::UpdateEntries(const CPVRTimers &timers)
           addEntry = itr->second;
         }
 
+        newTimer->m_iTimerId = ++m_iLastId;
         addEntry->push_back(newTimer);
         UpdateEpgEvent(newTimer);
         bChanged = true;
@@ -285,6 +287,7 @@ bool CPVRTimers::UpdateFromClient(const CPVRTimerInfoTag &timer)
     {
       addEntry = itr->second;
     }
+    tag->m_iTimerId = ++m_iLastId;
     addEntry->push_back(tag);
   }
 
@@ -741,3 +744,32 @@ void CPVRTimers::UpdateChannels(void)
       (*timerIt)->UpdateChannel();
   }
 }
+
+void CPVRTimers::GetAll(CFileItemList& items) const
+{
+  CFileItemPtr item;
+  CSingleLock lock(m_critSection);
+  for (map<CDateTime, vector<CPVRTimerInfoTagPtr>* >::const_iterator it = m_tags.begin(); it != m_tags.end(); it++)
+  {
+    for (vector<CPVRTimerInfoTagPtr>::const_iterator timerIt = it->second->begin(); timerIt != it->second->end(); timerIt++)
+    {
+      item.reset(new CFileItem(**timerIt));
+      items.Add(item);
+    }
+  }
+}
+
+CPVRTimerInfoTagPtr CPVRTimers::GetById(unsigned int iTimerId) const
+{
+  CPVRTimerInfoTagPtr item;
+  CSingleLock lock(m_critSection);
+  for (map<CDateTime, vector<CPVRTimerInfoTagPtr>* >::const_iterator it = m_tags.begin(); !item && it != m_tags.end(); it++)
+  {
+    for (vector<CPVRTimerInfoTagPtr>::const_iterator timerIt = it->second->begin(); !item && timerIt != it->second->end(); timerIt++)
+    {
+      if ((*timerIt)->m_iTimerId == iTimerId)
+        item = *timerIt;
+    }
+  }
+  return item;
+}
index b9a7d42..cc9c793 100644 (file)
@@ -68,6 +68,12 @@ namespace PVR
     std::vector<CFileItemPtr> GetActiveTimers(void) const;
 
     /*!
+     * Get all timers
+     * @param items The list to add the timers to
+     */
+    void GetAll(CFileItemList& items) const;
+
+    /*!
      * @return True when there is at least one timer that is active (states scheduled or recording), false otherwise.
      */
     bool HasActiveTimers(void) const;
@@ -166,6 +172,13 @@ namespace PVR
 
     void Notify(const Observable &obs, const ObservableMessage msg);
 
+    /*!
+     * Get a timer tag given it's unique ID
+     * @param iTimerId The ID to find
+     * @return The tag, or an empty one when not found
+     */
+    CPVRTimerInfoTagPtr GetById(unsigned int iTimerId) const;
+
   private:
     void Unload(void);
     void UpdateEpgEvent(CPVRTimerInfoTagPtr timer);
@@ -175,5 +188,6 @@ namespace PVR
     CCriticalSection                                        m_critSection;
     bool                                                    m_bIsUpdating;
     std::map<CDateTime, std::vector<CPVRTimerInfoTagPtr>* > m_tags;
+    unsigned int                                            m_iLastId;
   };
 }