}
+
+/**
+ *
+ */
+static void
+epg_event_destroy(event_t *e)
+{
+ if(e->e_content_type != NULL)
+ LIST_REMOVE(e, e_content_type_link);
+
+ free((void *)e->e_title);
+ free((void *)e->e_desc);
+ LIST_REMOVE(e, e_global_link);
+ free(e);
+}
+
+/**
+ *
+ */
+static void
+epg_event_unref(event_t *e)
+{
+ if(e->e_refcount > 1) {
+ e->e_refcount--;
+ return;
+ }
+ assert(e->e_refcount == 1);
+ epg_event_destroy(e);
+}
+
+/**
+ *
+ */
+static void
+epg_remove_event_from_channel(channel_t *ch, event_t *e)
+{
+ int wasfirst = e == RB_FIRST(&ch->ch_epg_events);
+ event_t *n = RB_NEXT(e, e_channel_link);
+
+ assert(e->e_channel == ch);
+
+ RB_REMOVE(&ch->ch_epg_events, e, e_channel_link);
+ e->e_channel = NULL;
+ epg_event_unref(e);
+
+ if(ch->ch_epg_current == e) {
+ epg_set_current(ch, NULL);
+
+ if(n != NULL)
+ gtimer_arm_abs(&ch->ch_epg_timer_current, epg_ch_check_current_event,
+ ch, n->e_start);
+ }
+
+ if(wasfirst && (e = RB_FIRST(&ch->ch_epg_events)) != NULL) {
+ gtimer_arm_abs(&ch->ch_epg_timer_head, epg_expire_event_from_channel,
+ ch, e->e_stop);
+ }
+}
+
+
/**
*
*/
event_t *
-epg_event_create(channel_t *ch, time_t start, time_t stop)
+epg_event_create(channel_t *ch, time_t start, time_t stop, int dvb_id)
{
static event_t *skel;
- event_t *e;
+ event_t *e, *p, *n;
static int tally;
if((stop - start) > 11 * 3600)
e->e_id = ++tally;
e->e_stop = stop;
+ e->e_dvb_id = dvb_id;
LIST_INSERT_HEAD(&epg_hash[e->e_id & EPG_GLOBAL_HASH_MASK], e,
e_global_link);
printf("Event %s on %s extended stop time\n", e->e_title,
e->e_channel->ch_name);
printf("Previous %s", ctime(&e->e_stop));
- printf(" New %s", ctime(&stop));
+ printf(" New %s", ctime(&stop));
#endif
e->e_stop = stop;
epg_event_changed(e);
}
}
}
+
+
+ if(dvb_id != -1) {
+ /* Erase any close events with the same DVB event id */
+
+ if((p = RB_PREV(e, e_channel_link)) != NULL) {
+ if(p->e_dvb_id == dvb_id) {
+ epg_remove_event_from_channel(ch, p);
+ } else if((p = RB_PREV(p, e_channel_link)) != NULL) {
+ if(p->e_dvb_id == dvb_id)
+ epg_remove_event_from_channel(ch, p);
+ }
+ }
+
+ if((n = RB_NEXT(e, e_channel_link)) != NULL) {
+ if(n->e_dvb_id == dvb_id) {
+ epg_remove_event_from_channel(ch, n);
+ } else if((n = RB_NEXT(n, e_channel_link)) != NULL) {
+ if(n->e_dvb_id == dvb_id)
+ epg_remove_event_from_channel(ch, n);
+ }
+ }
+ }
return e;
}
}
-/**
- *
- */
-static void
-epg_event_destroy(event_t *e)
-{
- if(e->e_content_type != NULL)
- LIST_REMOVE(e, e_content_type_link);
-
- free((void *)e->e_title);
- free((void *)e->e_desc);
- LIST_REMOVE(e, e_global_link);
- free(e);
-}
-
-/**
- *
- */
-static void
-epg_event_unref(event_t *e)
-{
- if(e->e_refcount > 1) {
- e->e_refcount--;
- return;
- }
- assert(e->e_refcount == 1);
- epg_event_destroy(e);
-}
-
-/**
- *
- */
-static void
-epg_remove_event_from_channel(channel_t *ch, event_t *e)
-{
- int wasfirst = e == RB_FIRST(&ch->ch_epg_events);
- event_t *n = RB_NEXT(e, e_channel_link);
-
- assert(e->e_channel == ch);
-
- RB_REMOVE(&ch->ch_epg_events, e, e_channel_link);
- e->e_channel = NULL;
- epg_event_unref(e);
-
- if(ch->ch_epg_current == e) {
- epg_set_current(ch, NULL);
-
- if(n != NULL)
- gtimer_arm_abs(&ch->ch_epg_timer_current, epg_ch_check_current_event,
- ch, n->e_start);
- }
-
- if(wasfirst && (e = RB_FIRST(&ch->ch_epg_events)) != NULL) {
- gtimer_arm_abs(&ch->ch_epg_timer_head, epg_expire_event_from_channel,
- ch, e->e_stop);
- }
-}
-
/**
*