fix lookupEvent.. now we can query previous and next event
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 4 Jan 2006 23:18:09 +0000 (23:18 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 4 Jan 2006 23:18:09 +0000 (23:18 +0000)
lib/dvb/epgcache.cpp
lib/dvb/epgcache.h

index 60eee05..13b0bf2 100644 (file)
@@ -1004,7 +1004,7 @@ void eEPGCache::channel_data::readData( const __u8 *data)
        }
 }
 
-RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eventData *&result )
+RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eventData *&result, int direction)
 // if t == -1 we search the current event...
 {
        singleLock s(cache_lock);
@@ -1016,20 +1016,24 @@ RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, co
        {
                if (t==-1)
                        t = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
-               timeMap::iterator i = It->second.second.lower_bound(t);  // find > or equal
+               timeMap::iterator i = direction <= 0 ? It->second.second.lower_bound(t) :  // find > or equal
+                       It->second.second.upper_bound(t); // just >
                if ( i != It->second.second.end() )
                {
-                       if ( i->second->getStartTime() != t )
+                       if ( direction < 0 || (direction == 0 && i->second->getStartTime() > t) )
                        {
                                timeMap::iterator x = i;
                                --x;
                                if ( x != It->second.second.end() )
                                {
                                        time_t start_time = x->second->getStartTime();
-                                       if (t < start_time)
-                                               return -1;
-                                       if (t > (start_time+x->second->getDuration()))
-                                               return -1;
+                                       if (direction >= 0)
+                                       {
+                                               if (t < start_time)
+                                                       return -1;
+                                               if (t > (start_time+x->second->getDuration()))
+                                                       return -1;
+                                       }
                                        i = x;
                                }
                                else
@@ -1042,31 +1046,31 @@ RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, co
        return -1;
 }
 
-RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eit_event_struct *&result )
+RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eit_event_struct *&result, int direction)
 {
        singleLock s(cache_lock);
        const eventData *data=0;
-       RESULT ret = lookupEventTime(service, t, data);
+       RESULT ret = lookupEventTime(service, t, data, direction);
        if ( !ret && data )
                result = data->get();
        return ret;
 }
 
-RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, Event *& result )
+RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, Event *& result, int direction)
 {
        singleLock s(cache_lock);
        const eventData *data=0;
-       RESULT ret = lookupEventTime(service, t, data);
+       RESULT ret = lookupEventTime(service, t, data, direction);
        if ( !ret && data )
                result = new Event((uint8_t*)data->get());
        return ret;
 }
 
-RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, ePtr<eServiceEvent> &result )
+RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, ePtr<eServiceEvent> &result, int direction)
 {
        singleLock s(cache_lock);
        const eventData *data=0;
-       RESULT ret = lookupEventTime(service, t, data);
+       RESULT ret = lookupEventTime(service, t, data, direction);
        if ( !ret && data )
        {
                Event ev((uint8_t*)data->get());
@@ -1391,7 +1395,7 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc)
                                        }
                                        case 1:
                                                type=PyInt_AsLong(entry);
-                                               if (type < 0 || type > 1)
+                                               if (type < -1 || type > 2)
                                                {
                                                        eDebug("unknown type %d", type);
                                                        continue;
@@ -1454,10 +1458,10 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc)
                                ePtr<eServiceEvent> ptr;
                                if (stime)
                                {
-                                       if (type == 0)
-                                               lookupEventTime(ref, stime, ptr);
-                                       else // type == 1
+                                       if (type == 2)
                                                lookupEventId(ref, event_id, ptr);
+                                       else
+                                               lookupEventTime(ref, stime, ptr, type);
                                }
                                PyObject *ret = handleEvent(ptr, dest_list, argstring, argcount, service, nowTime, service_name, convertFunc, convertFuncArgs);
                                if (ret)
index 487f409..d88beca 100644 (file)
@@ -241,19 +241,19 @@ public:
        // eventData's are plain entrys out of the cache.. it's not safe to use them after cache unlock
        // but its faster in use... its not allowed to delete this pointers via delete or free..
        SWIG_VOID(RESULT) lookupEventId(const eServiceReference &service, int event_id, const eventData *&SWIG_OUTPUT);
-       SWIG_VOID(RESULT) lookupEventTime(const eServiceReference &service, time_t, const eventData *&SWIG_OUTPUT);
+       SWIG_VOID(RESULT) lookupEventTime(const eServiceReference &service, time_t, const eventData *&SWIG_OUTPUT, int direction=0);
        SWIG_VOID(RESULT) getNextTimeEntry(const eventData *&SWIG_OUTPUT);
 
        // eit_event_struct's are plain dvb eit_events .. it's not safe to use them after cache unlock
        // its not allowed to delete this pointers via delete or free..
        RESULT lookupEventId(const eServiceReference &service, int event_id, const eit_event_struct *&);
-       RESULT lookupEventTime(const eServiceReference &service, time_t , const eit_event_struct *&);
+       RESULT lookupEventTime(const eServiceReference &service, time_t , const eit_event_struct *&, int direction=0);
        RESULT getNextTimeEntry(const eit_event_struct *&);
 
        // Event's are parsed epg events.. it's safe to use them after cache unlock
        // after use this Events must be deleted (memleaks)
        RESULT lookupEventId(const eServiceReference &service, int event_id, Event* &);
-       RESULT lookupEventTime(const eServiceReference &service, time_t, Event* &);
+       RESULT lookupEventTime(const eServiceReference &service, time_t, Event* &, int direction=0);
        RESULT getNextTimeEntry(Event *&);
 #endif
        PyObject *lookupEvent(PyObject *list, PyObject *convertFunc=NULL);
@@ -261,7 +261,7 @@ public:
        // eServiceEvent are parsed epg events.. it's safe to use them after cache unlock
        // for use from python ( members: m_start_time, m_duration, m_short_description, m_extended_description )
        SWIG_VOID(RESULT) lookupEventId(const eServiceReference &service, int event_id, ePtr<eServiceEvent> &SWIG_OUTPUT);
-       SWIG_VOID(RESULT) lookupEventTime(const eServiceReference &service, time_t, ePtr<eServiceEvent> &SWIG_OUTPUT);
+       SWIG_VOID(RESULT) lookupEventTime(const eServiceReference &service, time_t, ePtr<eServiceEvent> &SWIG_OUTPUT, int direction=0);
        SWIG_VOID(RESULT) getNextTimeEntry(ePtr<eServiceEvent> &SWIG_OUTPUT);
 };