1 /*
2  *  API - Imagecache related calls
3  *
4  *  Copyright (C) 2013 Adam Sutton
5  *
6  *  This program is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; withm even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "tvheadend.h"
21 #include "channels.h"
22 #include "access.h"
23 #include "api.h"
24 #include "imagecache.h"
25 
26 #if ENABLE_IMAGECACHE
27 
28 static int
api_imagecache_clean(access_t * perm,void * opaque,const char * op,htsmsg_t * args,htsmsg_t ** resp)29 api_imagecache_clean
30   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
31 {
32   int b;
33   if (htsmsg_get_bool(args, "clean", &b))
34     return EINVAL;
35   if (b) {
36     pthread_mutex_lock(&global_lock);
37     imagecache_clean();
38     pthread_mutex_unlock(&global_lock);
39   }
40   return 0;
41 }
42 
43 static int
api_imagecache_trigger(access_t * perm,void * opaque,const char * op,htsmsg_t * args,htsmsg_t ** resp)44 api_imagecache_trigger
45   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
46 {
47   int b;
48   if (htsmsg_get_bool(args, "trigger", &b))
49     return EINVAL;
50   if (b) {
51     pthread_mutex_lock(&global_lock);
52     imagecache_trigger();
53     pthread_mutex_unlock(&global_lock);
54   }
55   return 0;
56 }
57 
58 void
api_imagecache_init(void)59 api_imagecache_init ( void )
60 {
61   static api_hook_t ah[] = {
62     { "imagecache/config/load",    ACCESS_ADMIN, api_idnode_load_simple, &imagecache_conf },
63     { "imagecache/config/save",    ACCESS_ADMIN, api_idnode_save_simple, &imagecache_conf },
64     { "imagecache/config/clean"  , ACCESS_ADMIN, api_imagecache_clean, NULL },
65     { "imagecache/config/trigger", ACCESS_ADMIN, api_imagecache_trigger, NULL },
66     { NULL },
67   };
68 
69   api_register_all(ah);
70 }
71 
72 #else /* ENABLE_IMAGECACHE */
73 
74 void
api_imagecache_init(void)75 api_imagecache_init ( void )
76 {
77 }
78 
79 #endif
80