Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
webui/api: add possibility to remove dead services (maintenance butto…
…n in the service grid), fixes #4125
  • Loading branch information
perexg committed Dec 8, 2016
1 parent 0794296 commit 0c506b4
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/api/api_service.c
Expand Up @@ -160,6 +160,19 @@ api_service_streams
return 0;
}

static int
api_service_remove_unseen
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
int days = htsmsg_get_s32_or_default(args, "days", 7);
const char *type = htsmsg_get_str(args, "type");

pthread_mutex_lock(&global_lock);
service_remove_unseen(type, days);
pthread_mutex_unlock(&global_lock);
return 0;
}

void api_service_init ( void )
{
extern const idclass_t service_class;
Expand All @@ -170,6 +183,7 @@ void api_service_init ( void )
{ "service/mapper/status", ACCESS_ADMIN, api_mapper_status, NULL },
{ "service/list", ACCESS_ADMIN, api_idnode_load_by_class, (void*)&service_class },
{ "service/streams", ACCESS_ADMIN, api_service_streams, NULL },
{ "service/removeunseen", ACCESS_ADMIN, api_service_remove_unseen, NULL },
{ NULL },
};

Expand Down
10 changes: 10 additions & 0 deletions src/input/mpegts/mpegts_service.c
Expand Up @@ -736,6 +736,15 @@ mpegts_service_memoryinfo ( service_t *t, int64_t *size )
*size += tvh_strlen(ms->s_dvb_charset);
}

static int
mpegts_service_unseen( service_t *t, const char *type, time_t before )
{
mpegts_service_t *ms = (mpegts_service_t*)t;
int pat = type && strcasecmp(type, "pat") == 0;
if (pat && ms->s_auto != SERVICE_AUTO_PAT_MISSING) return 0;
return ms->s_dvb_last_seen < before;
}

/* **************************************************************************
* Creation/Location
* *************************************************************************/
Expand Down Expand Up @@ -790,6 +799,7 @@ mpegts_service_create0
s->s_mapped = mpegts_service_mapped;
s->s_satip_source = mpegts_service_satip_source;
s->s_memoryinfo = mpegts_service_memoryinfo;
s->s_unseen = mpegts_service_unseen;

pthread_mutex_lock(&s->s_stream_mutex);
service_make_nicename((service_t*)s);
Expand Down
17 changes: 17 additions & 0 deletions src/service.c
Expand Up @@ -2014,6 +2014,23 @@ void service_save ( service_t *t, htsmsg_t *m )
htsmsg_add_msg(m, "stream", list);
}

/**
*
*/
void
service_remove_unseen(const char *type, int days)
{
service_t *s, *sn;
time_t before = gclk() - MAX(days, 5) * 24 * 3600;

lock_assert(&global_lock);
for (s = TAILQ_FIRST(&service_all); s; s = sn) {
sn = TAILQ_NEXT(s, s_all_link);
if (s->s_unseen && s->s_unseen(s, type, before))
service_destroy(s, 1);
}
}

/**
*
*/
Expand Down
4 changes: 4 additions & 0 deletions src/service.h
Expand Up @@ -333,6 +333,8 @@ typedef struct service {

void (*s_memoryinfo)(struct service *t, int64_t *size);

int (*s_unseen)(struct service *t, const char *type, time_t before);

/**
* Channel info
*/
Expand Down Expand Up @@ -619,6 +621,8 @@ void service_load ( service_t *s, htsmsg_t *c );

void service_save ( service_t *s, htsmsg_t *c );

void service_remove_unseen(const char *type, int days);

void sort_elementary_streams(service_t *t);

const char *service_get_channel_name (service_t *s);
Expand Down
44 changes: 43 additions & 1 deletion src/webui/static/app/mpegts.js
Expand Up @@ -271,6 +271,48 @@ tvheadend.services = function(panel, index)
abuttons.map.setText(_('Map All'));
};

var unseencb = function(type) {
tvheadend.Ajax({
url: 'api/service/removeunseen',
params: {
type: type,
},
success: function(d) {
store.reload();
}
});
};

var maintenanceButton = {
name: 'misc',
builder: function() {
var m = new Ext.menu.Menu()
m.add({
name: 'rmunsnpat',
tooltip: _('Remove old services marked as missing in PAT/SDT which were not detected more than 7 days (last seen column)'),
iconCls: 'remove',
text: _('Remove unseen services (PAT/SDT) (7 days+)'),
});
m.add({
name: 'rmunsn',
tooltip: _('Remove old services which were not detected more than 7 days (last seen column)'),
iconCls: 'remove',
text: _('Remove all unseen services (7 days+)'),
});
return new Ext.Toolbar.Button({
tooltip: _('Maintenance operations'),
iconCls: 'wrench',
text: _('Maintenance'),
menu: m,
disabled: false
});
},
callback: {
rmunsnpat: function() { unseencb('pat'); },
rmunsn: function() { unseencb(''); }
}
};

var actions = new Ext.ux.grid.RowActions({
header: _('Details'),
width: 10,
Expand All @@ -293,7 +335,7 @@ tvheadend.services = function(panel, index)
destroy: function() {
}
});
conf.tbar = [mapButton];
conf.tbar = [mapButton, maintenanceButton];
conf.selected = selected;
conf.lcol[1] = actions;
conf.plugins = [actions];
Expand Down

0 comments on commit 0c506b4

Please sign in to comment.