/*
 * svccli.c: Sample service client plugin
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: svccli.c 1.1 2005/08/21 10:44:29 kls Exp $
 */

#include <stdlib.h>
#include <vdr/interface.h>
#include <vdr/plugin.h>

static const char *VERSION        = "0.0.1";
static const char *DESCRIPTION    = "Radiotext demo client";
static const char *MAINMENUENTRY  = "Radiotext on Console-Output";

class cPluginSvcCli : public cPlugin {
public:
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return DESCRIPTION; }
  virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
  virtual cOsdObject *MainMenuAction(void);
  };

struct RadioTextService_v1_0 {
  int rds_info;
  int rds_pty;
  char *rds_text;
  char *rds_title;
  char *rds_artist;
  struct tm *title_start;
};

// --- cPluginSvcCli ----------------------------------------------------------

cOsdObject *cPluginSvcCli::MainMenuAction(void)
{
  cPlugin *p;

  // (detect capability)
  p = cPluginManager::CallFirstService("RadioTextService-v1.0", NULL);
  if (p) {
     printf("\n--- Plugin '%s' have Radiotext ---\n", p->Name());
     }
  // (use general service)
  RadioTextService_v1_0 rtext;
  if (cPluginManager::CallFirstService("RadioTextService-v1.0", &rtext)) {
     if (rtext.rds_info > 0) {
        printf("Program-Type : %d\n", rtext.rds_pty);
        printf("Radiotext    : %s\n", rtext.rds_text);
	if (rtext.rds_info == 2) {
    	    printf("RTplus-Title : %s\n", rtext.rds_title);
    	    printf("RTplus-Artist: %s\n", rtext.rds_artist);
    	    printf("Title Start  : %02d:%02d:%02d\n", rtext.title_start->tm_hour, rtext.title_start->tm_min, rtext.title_start->tm_sec);
	    }
	}
     else
        printf("Radiotext not available (yet)\n");
     }

  return NULL;
}

VDRPLUGINCREATOR(cPluginSvcCli); // Don't touch this!
