vdr  2.2.0
svdrpdemo.c
Go to the documentation of this file.
1 /*
2  * svdrpdemo.c: A plugin for the Video Disk Recorder
3  *
4  * See the README file for copyright information and how to reach the author.
5  *
6  * $Id: svdrpdemo.c 3.2 2015/02/17 13:13:29 kls Exp $
7  */
8 
9 #include <vdr/plugin.h>
10 
11 static const char *VERSION = "2.2.0";
12 static const char *DESCRIPTION = "How to add SVDRP support to a plugin";
13 
14 class cPluginSvdrpdemo : public cPlugin {
15 private:
16  // Add any member variables or functions you may need here.
17 public:
18  virtual const char *Version(void) { return VERSION; }
19  virtual const char *Description(void) { return DESCRIPTION; }
20  virtual const char **SVDRPHelpPages(void);
21  virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
22  };
23 
25 {
26  static const char *HelpPages[] = {
27  "DATE\n"
28  " Print the current date.",
29  "TIME [ raw ]\n"
30  " Print the current time.\n"
31  " If the optional keyword 'raw' is given, the result will be the\n"
32  " raw time_t data.",
33  NULL
34  };
35  return HelpPages;
36 }
37 
38 cString cPluginSvdrpdemo::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
39 {
40  if (strcasecmp(Command, "DATE") == 0) {
41  // we use the default reply code here
42  return DateString(time(NULL));
43  }
44  else if (strcasecmp(Command, "TIME") == 0) {
45  ReplyCode = 901;
46  if (*Option) {
47  if (strcasecmp(Option, "RAW") == 0)
48  return cString::sprintf("%ld\nThis is the number of seconds since the epoch\nand a demo of a multi-line reply", time(NULL));
49  else {
50  ReplyCode = 504;
51  return cString::sprintf("Unknown option: \"%s\"", Option);
52  }
53  }
54  return TimeString(time(NULL));
55  }
56  return NULL;
57 }
58 
59 VDRPLUGINCREATOR(cPluginSvdrpdemo); // Don't touch this!
virtual const char ** SVDRPHelpPages(void)
Definition: svdrpdemo.c:24
const char * HelpPages[]
Definition: svdrp.c:184
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition: tools.c:1080
Definition: plugin.h:20
virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
Definition: svdrpdemo.c:38
static const char * VERSION
Definition: svdrpdemo.c:11
static const char * DESCRIPTION
Definition: svdrpdemo.c:12
virtual const char * Version(void)
Definition: svdrpdemo.c:18
cString TimeString(time_t t)
Converts the given time to a string of the form "hh:mm".
Definition: tools.c:1186
virtual const char * Description(void)
Definition: svdrpdemo.c:19
Definition: tools.h:168
VDRPLUGINCREATOR(cPluginSvdrpdemo)
cString DateString(time_t t)
Converts the given time to a string of the form "www dd.mm.yyyy".
Definition: tools.c:1166