return ((epg_object_t*)a)->id - ((epg_object_t*)b)->id;
}
-#if TODO_NOT_NEEDED
-static int _ptr_cmp ( const void *a, const void *b )
-{
- return a - b;
-}
-#endif
-
static int _ebc_win_cmp ( const void *a, const void *b )
{
if ( ((epg_broadcast_t*)a)->start < ((epg_broadcast_t*)b)->start ) return -1;
return ret;
}
-/* **************************************************************************
- * Testing/Debug
- * *************************************************************************/
-
-#if 0
-static void _epg_dump ( void )
-{
- epg_object_t *eo;
- epg_brand_t *eb;
- epg_season_t *es;
- epg_episode_t *ee;
- epg_channel_t *ec;
- epg_broadcast_t *ebc;
- printf("dump epg\n");
-
- /* Go down the brand/season/episode */
- RB_FOREACH(eo, &epg_brands, glink) {
- eb = (epg_brand_t*)eo;
- printf("BRAND: %p %s\n", eb, eb->_.uri);
- RB_FOREACH(es, &eb->seasons, blink) {
- printf(" SEASON: %p %s %d\n", es, es->_.uri, es->number);
- RB_FOREACH(ee, &es->episodes, slink) {
- printf(" EPISODE: %p %s %d\n", ee, ee->_.uri, ee->number);
- }
- }
- RB_FOREACH(ee, &eb->episodes, blink) {
- if ( !ee->season ) printf(" EPISODE: %p %s %d\n", ee, ee->_.uri, ee->number);
- }
- }
- RB_FOREACH(eo, &epg_seasons, glink) {
- es = (epg_season_t*)eo;
- if ( !es->brand ) {
- printf("SEASON: %p %s %d\n", es, es->_.uri, es->number);
- RB_FOREACH(ee, &es->episodes, slink) {
- printf(" EPISODE: %p %s %d\n", ee, ee->_.uri, ee->number);
- }
- }
- }
- RB_FOREACH(eo, &epg_episodes, glink) {
- ee = (epg_episode_t*)eo;
- if ( !ee->brand && !ee->season ) {
- printf("EPISODE: %p %s %d\n", ee, ee->_.uri, ee->number);
- }
- }
- RB_FOREACH(eo, &epg_channels, glink) {
- ec = (epg_channel_t*)eo;
- printf("CHANNEL: %s\n", ec->_.uri);
- RB_FOREACH(eo, &ec->schedule, glink) {
- ebc = (epg_broadcast_t*)eo;
- if ( ebc->episode ) {
- printf(" BROADCAST: %s @ %ld to %ld\n", ebc->episode->_.uri,
- ebc->start, ebc->stop);
- }
- }
- }
-}
-#endif
-
/* **************************************************************************
* Setup / Update
* *************************************************************************/
void epg_save ( void )
{
- // TODO: skip unref'd objects?
int fd;
epg_object_t *eo, *ec;
{
assert(eo->refcount>0); // Sanity!
eo->refcount--;
- printf("putref(%lu) = %d\n", eo->id, eo->refcount);
- // TODO: do this here or defer to the epg_updated call?
if (!eo->refcount) eo->destroy(eo);
}
}
skel->uri = (char*)uri;
skel->id = _epg_object_idx;
- // TODO: need to add function pointers
eo = _epg_object_find(create, &save2, tree, &skel, _uri_cmp);
if (save2) {
( uint64_t id, epg_object_tree_t *tree )
{
epg_object_t *eo;
- if (!tree) return NULL; // TODO: use a global list?
+ if (!tree) return NULL;
RB_FOREACH(eo, tree, glink) {
if ( eo->id == id ) return eo;
}
static void _epg_brand_destroy ( epg_object_t *eo )
{
- printf("_epg_brand_destroy(%lu, %s)\n", eo->id, eo->uri);
epg_brand_t *eb = (epg_brand_t*)eo;
if (RB_FIRST(&eb->seasons)) {
tvhlog(LOG_CRIT, "epg", "attempt to destroy brand with seasons");
int epg_brand_set_season_count ( epg_brand_t *brand, uint16_t count )
{
- // TODO: could set only if less?
int save = 0;
if ( !brand || !count ) return 0;
if ( brand->season_count != count ) {
static void _epg_season_destroy ( epg_object_t *eo )
{
- printf("_epg_season_destroy(%lu, %s)\n", eo->id, eo->uri);
epg_season_t *es = (epg_season_t*)eo;
if (RB_FIRST(&es->episodes)) {
tvhlog(LOG_CRIT, "epg", "attempt to destory season with episodes");
{
int save = 0;
if ( !season || !count ) return 0;
- // TODO: should we only update if number is larger
if ( season->episode_count != count ) {
season->episode_count = count;
save = 1;
static void _epg_episode_destroy ( epg_object_t *eo )
{
- printf("_epg_episode_destroy(%lu, %s)\n", eo->id, eo->uri);
epg_episode_t *ee = (epg_episode_t*)eo;
if (RB_FIRST(&ee->broadcasts)) {
tvhlog(LOG_CRIT, "epg", "attempt to destroy episode with broadcasts");
static void _epg_broadcast_destroy ( epg_object_t *eo )
{
- printf("_epg_broadcast_destroy(%lu)\n", eo->id);
epg_broadcast_t *ebc = (epg_broadcast_t*)eo;
_epg_object_destroy(eo, NULL);
if (ebc->episode) {
/* Clear now/next */
cur = ec->now;
ec->now = ec->next = NULL;
-#if 0
- printf("dispatch_clock = %lu\n", dispatch_clock);
- RB_FOREACH(eo, &ec->schedule, glink) {
- ebc = (epg_broadcast_t*)eo;
- printf("entry %lu @ %lu to %lu\n", eo->id, ebc->start, ebc->stop);
- }
-#endif
/* Check events */
while ( (eo = RB_FIRST(&ec->schedule)) ) {
static void _epg_channel_destroy ( epg_object_t *eo )
{
- printf("_epg_channel_destroy(%lu, %s)\n", eo->id, eo->uri);
epg_channel_t *ec = (epg_channel_t*)eo;
if (ec->channel) {
tvhlog(LOG_CRIT, "epg", "attempt to destroy mapped channel");