vdr
1.7.27
|
00001 /* 00002 * svccli.c: Sample service client plugin 00003 * 00004 * See the README file for copyright information and how to reach the author. 00005 * 00006 * $Id: svccli.c 2.0 2007/08/15 13:18:08 kls Exp $ 00007 */ 00008 00009 #include <stdlib.h> 00010 #include <vdr/interface.h> 00011 #include <vdr/plugin.h> 00012 00013 static const char *VERSION = "0.1.2"; 00014 static const char *DESCRIPTION = "Service demo client"; 00015 static const char *MAINMENUENTRY = "Service demo"; 00016 00017 class cPluginSvcCli : public cPlugin { 00018 public: 00019 virtual const char *Version(void) { return VERSION; } 00020 virtual const char *Description(void) { return DESCRIPTION; } 00021 virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; } 00022 virtual cOsdObject *MainMenuAction(void); 00023 virtual bool Service(const char *Id, void *Data); 00024 }; 00025 00026 struct ReportBoredPlugin_v1_0 { 00027 cPlugin *BoredPlugin; 00028 }; 00029 00030 struct AddService_v1_0 { 00031 int a, b; 00032 int sum; 00033 }; 00034 00035 // --- cPluginSvcCli ---------------------------------------------------------- 00036 00037 cOsdObject *cPluginSvcCli::MainMenuAction(void) 00038 { 00039 char s[128]; 00040 cPlugin *p; 00041 00042 // Inform server plugin that we are bored 00043 // (directed communication) 00044 ReportBoredPlugin_v1_0 rbp; 00045 rbp.BoredPlugin = this; 00046 p = cPluginManager::GetPlugin("svcsvr"); 00047 if (p) 00048 p->Service("ReportBoredPlugin-v1.0", &rbp); 00049 00050 // See if any plugin can add 00051 // (detect capability) 00052 p = cPluginManager::CallFirstService("AddService-v1.0", NULL); 00053 if (p) { 00054 snprintf(s, sizeof(s), "Plugin %s can add", p->Name()); 00055 Interface->Confirm(s); 00056 } 00057 00058 // Perform add 00059 // (use general service) 00060 AddService_v1_0 adds; 00061 adds.a = 1; 00062 adds.b = 1; 00063 if (cPluginManager::CallFirstService("AddService-v1.0", &adds)) { 00064 snprintf(s, sizeof(s), "Plugin thinks that 1+1=%i", adds.sum); 00065 Interface->Confirm(s); 00066 } 00067 00068 // Inform other plugins that we are bored 00069 // (broadcast) 00070 rbp.BoredPlugin = this; 00071 cPluginManager::CallAllServices("ReportBoredPlugin-v1.0", &rbp); 00072 00073 return NULL; 00074 } 00075 00076 bool cPluginSvcCli::Service(const char *Id, void *Data) 00077 { 00078 if (strcmp(Id, "ReportBoredPlugin-v1.0") == 0) { 00079 if (Data) { 00080 ReportBoredPlugin_v1_0 *rbp = (ReportBoredPlugin_v1_0*)Data; 00081 char s[128]; 00082 snprintf(s, sizeof(s), "Plugin %s informed client that it is bored.", rbp->BoredPlugin->Name()); 00083 Interface->Confirm(s); 00084 } 00085 return true; 00086 } 00087 return false; 00088 } 00089 00090 VDRPLUGINCREATOR(cPluginSvcCli); // Don't touch this!