samples: Fix compiler warnings.

This commit is contained in:
Marcelo Roberto Jimenez 2010-11-17 11:54:31 -02:00
parent 4d2f1f7ba6
commit 57b1169850
14 changed files with 897 additions and 1203 deletions

View File

@ -41,7 +41,7 @@ void IxmlPrintf(
void printNodes(IXML_Node *tmpRoot, int depth) void printNodes(IXML_Node *tmpRoot, int depth)
{ {
int i; unsigned long i;
IXML_NodeList *NodeList1; IXML_NodeList *NodeList1;
IXML_Node *ChildNode1; IXML_Node *ChildNode1;
unsigned short NodeType; unsigned short NodeType;

View File

@ -140,7 +140,7 @@ static IXML_NodeList *SampleUtil_GetNthServiceList(
/*! [in] . */ /*! [in] . */
IXML_Document *doc, IXML_Document *doc,
/*! [in] . */ /*! [in] . */
int n) unsigned int n)
{ {
IXML_NodeList *ServiceList = NULL; IXML_NodeList *ServiceList = NULL;
IXML_NodeList *servlistnodelist = NULL; IXML_NodeList *servlistnodelist = NULL;
@ -553,11 +553,11 @@ int SampleUtil_PrintEvent(Upnp_EventType EventType, void *Event)
int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location, int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location,
const char *serviceType, char **serviceId, char **eventURL, char **controlURL) const char *serviceType, char **serviceId, char **eventURL, char **controlURL)
{ {
int i; unsigned int i;
int length; unsigned long length;
int found = 0; int found = 0;
int ret; int ret;
int sindex = 0; unsigned int sindex = 0;
char *tempServiceType = NULL; char *tempServiceType = NULL;
char *baseURL = NULL; char *baseURL = NULL;
const char *base = NULL; const char *base = NULL;
@ -576,7 +576,7 @@ int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location,
/* Top level */ /* Top level */
for (sindex = 0; for (sindex = 0;
(serviceList = SampleUtil_GetNthServiceList(DescDoc , sindex)) != NULL; (serviceList = SampleUtil_GetNthServiceList(DescDoc , sindex)) != NULL;
sindex ++) { sindex++) {
tempServiceType = NULL; tempServiceType = NULL;
relcontrolURL = NULL; relcontrolURL = NULL;
releventURL = NULL; releventURL = NULL;
@ -650,9 +650,8 @@ int SampleUtil_Print(const char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
rc = vsnprintf(buf, MAX_BUF, fmt, ap); rc = vsnprintf(buf, MAX_BUF, fmt, ap);
va_end(ap); va_end(ap);
if (gPrintFun) { if (gPrintFun) {
gPrintFun(buf); gPrintFun("%s", buf);
} }
ithread_mutex_unlock(&display_mutex); ithread_mutex_unlock(&display_mutex);

View File

@ -147,7 +147,14 @@ int SampleUtil_FindAndParseService (
*/ */
typedef void (*print_string)( typedef void (*print_string)(
/*! [in] Format. */ /*! [in] Format. */
const char *string); const char *string,
/*! [in] Arguments. */
...)
#if (__GNUC__ >= 3)
/* This enables printf like format checking by the compiler */
__attribute__((format (__printf__, 1, 2)))
#endif
;
/*! global print function used by sample util */ /*! global print function used by sample util */
extern print_string gPrintFun; extern print_string gPrintFun;

View File

@ -29,394 +29,343 @@
* *
******************************************************************************/ ******************************************************************************/
#include "sample_util.h" #include "sample_util.h"
#include "upnp_tv_ctrlpt.h" #include "upnp_tv_ctrlpt.h"
#include "upnp_tv_device.h" #include "upnp_tv_device.h"
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
/* /*! Tags for valid commands issued at the command prompt. */
Tags for valid commands issued at the command prompt
*/
enum cmdloop_tvcmds { enum cmdloop_tvcmds {
PRTHELP = 0, PRTFULLHELP, POWON, POWOFF, PRTHELP = 0, PRTFULLHELP, POWON, POWOFF,
SETCHAN, SETVOL, SETCOL, SETTINT, SETCONT, SETBRT, SETCHAN, SETVOL, SETCOL, SETTINT, SETCONT, SETBRT,
CTRLACTION, PICTACTION, CTRLGETVAR, PICTGETVAR, CTRLACTION, PICTACTION, CTRLGETVAR, PICTGETVAR,
PRTDEV, LSTDEV, REFRESH, EXITCMD PRTDEV, LSTDEV, REFRESH, EXITCMD
}; };
/* /*! Data structure for parsing commands from the command line. */
Data structure for parsing commands from the command line
*/
struct cmdloop_commands { struct cmdloop_commands {
char *str; /* the string */ /* the string */
int cmdnum; /* the command */ const char *str;
int numargs; /* the number of arguments */ /* the command */
char *args; /* the args */ int cmdnum;
/* the number of arguments */
int numargs;
/* the args */
const char *args;
} cmdloop_commands; } cmdloop_commands;
/* /*! Mappings between command text names, command tag,
Mappings between command text names, command tag, * and required command arguments for command line
and required command arguments for command line * commands */
commands
*/
static struct cmdloop_commands cmdloop_cmdlist[] = { static struct cmdloop_commands cmdloop_cmdlist[] = {
{"Help", PRTHELP, 1, ""}, {"Help", PRTHELP, 1, ""},
{"HelpFull", PRTFULLHELP, 1, ""}, {"HelpFull", PRTFULLHELP, 1, ""},
{"ListDev", LSTDEV, 1, ""}, {"ListDev", LSTDEV, 1, ""},
{"Refresh", REFRESH, 1, ""}, {"Refresh", REFRESH, 1, ""},
{"PrintDev", PRTDEV, 2, "<devnum>"}, {"PrintDev", PRTDEV, 2, "<devnum>"},
{"PowerOn", POWON, 2, "<devnum>"}, {"PowerOn", POWON, 2, "<devnum>"},
{"PowerOff", POWOFF, 2, "<devnum>"}, {"PowerOff", POWOFF, 2, "<devnum>"},
{"SetChannel", SETCHAN, 3, "<devnum> <channel (int)>"}, {"SetChannel", SETCHAN, 3, "<devnum> <channel (int)>"},
{"SetVolume", SETVOL, 3, "<devnum> <volume (int)>"}, {"SetVolume", SETVOL, 3, "<devnum> <volume (int)>"},
{"SetColor", SETCOL, 3, "<devnum> <color (int)>"}, {"SetColor", SETCOL, 3, "<devnum> <color (int)>"},
{"SetTint", SETTINT, 3, "<devnum> <tint (int)>"}, {"SetTint", SETTINT, 3, "<devnum> <tint (int)>"},
{"SetContrast", SETCONT, 3, "<devnum> <contrast (int)>"}, {"SetContrast", SETCONT, 3, "<devnum> <contrast (int)>"},
{"SetBrightness", SETBRT, 3, "<devnum> <brightness (int)>"}, {"SetBrightness", SETBRT, 3, "<devnum> <brightness (int)>"},
{"CtrlAction", CTRLACTION, 2, "<devnum> <action (string)>"}, {"CtrlAction", CTRLACTION, 2, "<devnum> <action (string)>"},
{"PictAction", PICTACTION, 2, "<devnum> <action (string)>"}, {"PictAction", PICTACTION, 2, "<devnum> <action (string)>"},
{"CtrlGetVar", CTRLGETVAR, 2, "<devnum> <varname (string)>"}, {"CtrlGetVar", CTRLGETVAR, 2, "<devnum> <varname (string)>"},
{"PictGetVar", PICTGETVAR, 2, "<devnum> <varname (string)>"}, {"PictGetVar", PICTGETVAR, 2, "<devnum> <varname (string)>"},
{"Exit", EXITCMD, 1, ""} {"Exit", EXITCMD, 1, ""}
}; };
void /*!
linux_print( const char *string ) * \brief Prints a string to standard out.
*/
void linux_print(const char *format, ...)
{ {
puts( string ); va_list argList;
va_start(argList, format);
vfprintf(stdout, format, argList);
fflush(stdout);
va_end(argList);
} }
/******************************************************************************** /*!
* TvCtrlPointPrintHelp * \brief Print help info for this application.
* */
* Description: void TvCtrlPointPrintShortHelp(void)
* Print help info for this application.
********************************************************************************/
void
TvCtrlPointPrintShortHelp( void )
{ {
SampleUtil_Print( "Commands:" ); SampleUtil_Print(
SampleUtil_Print( " Help" ); "Commands:\n"
SampleUtil_Print( " HelpFull" ); " Help\n"
SampleUtil_Print( " ListDev" ); " HelpFull\n"
SampleUtil_Print( " Refresh" ); " ListDev\n"
SampleUtil_Print( " PrintDev <devnum>" ); " Refresh\n"
SampleUtil_Print( " PowerOn <devnum>" ); " PrintDev <devnum>\n"
SampleUtil_Print( " PowerOff <devnum>" ); " PowerOn <devnum>\n"
SampleUtil_Print( " SetChannel <devnum> <channel>" ); " PowerOff <devnum>\n"
SampleUtil_Print( " SetVolume <devnum> <volume>" ); " SetChannel <devnum> <channel>\n"
SampleUtil_Print( " SetColor <devnum> <color>" ); " SetVolume <devnum> <volume>\n"
SampleUtil_Print( " SetTint <devnum> <tint>" ); " SetColor <devnum> <color>\n"
SampleUtil_Print( " SetContrast <devnum> <contrast>" ); " SetTint <devnum> <tint>\n"
SampleUtil_Print( " SetBrightness <devnum> <brightness>" ); " SetContrast <devnum> <contrast>\n"
SampleUtil_Print( " CtrlAction <devnum> <action>" ); " SetBrightness <devnum> <brightness>\n"
SampleUtil_Print( " PictAction <devnum> <action>" ); " CtrlAction <devnum> <action>\n"
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" ); " PictAction <devnum> <action>\n"
SampleUtil_Print( " PictGetVar <devnum> <action>" ); " CtrlGetVar <devnum> <varname>\n"
SampleUtil_Print( " Exit" ); " PictGetVar <devnum> <action>\n"
" Exit\n");
} }
void void TvCtrlPointPrintLongHelp(void)
TvCtrlPointPrintLongHelp( void )
{ {
SampleUtil_Print( "" ); SampleUtil_Print(
SampleUtil_Print( "******************************" ); "\n"
SampleUtil_Print( "* TV Control Point Help Info *" ); "******************************\n"
SampleUtil_Print( "******************************" ); "* TV Control Point Help Info *\n"
SampleUtil_Print( "" ); "******************************\n"
SampleUtil_Print( "This sample control point application automatically searches" ); "\n"
SampleUtil_Print( "for and subscribes to the services of television device emulator" ); "This sample control point application automatically searches\n"
SampleUtil_Print( "devices, described in the tvdevicedesc.xml description document." ); "for and subscribes to the services of television device emulator\n"
SampleUtil_Print( "It also registers itself as a tv device." ); "devices, described in the tvdevicedesc.xml description document.\n"
SampleUtil_Print( "" ); "It also registers itself as a tv device.\n"
SampleUtil_Print( "Commands:" ); "\n"
SampleUtil_Print( " Help" ); "Commands:\n"
SampleUtil_Print( " Print this help info." ); " Help\n"
SampleUtil_Print( " ListDev" ); " Print this help info.\n"
SampleUtil_Print( " Print the current list of TV Device Emulators that this" ); " ListDev\n"
SampleUtil_Print( " control point is aware of. Each device is preceded by a" ); " Print the current list of TV Device Emulators that this\n"
SampleUtil_Print( " device number which corresponds to the devnum argument of" ); " control point is aware of. Each device is preceded by a\n"
SampleUtil_Print( " commands listed below." ); " device number which corresponds to the devnum argument of\n"
SampleUtil_Print( " Refresh" ); " commands listed below.\n"
SampleUtil_Print( " Delete all of the devices from the device list and issue new" ); " Refresh\n"
SampleUtil_Print( " search request to rebuild the list from scratch." ); " Delete all of the devices from the device list and issue new\n"
SampleUtil_Print( " PrintDev <devnum>" ); " search request to rebuild the list from scratch.\n"
SampleUtil_Print( " Print the state table for the device <devnum>." ); " PrintDev <devnum>\n"
SampleUtil_Print( " e.g., 'PrintDev 1' prints the state table for the first" ); " Print the state table for the device <devnum>.\n"
SampleUtil_Print( " device in the device list." ); " e.g., 'PrintDev 1' prints the state table for the first\n"
SampleUtil_Print( " PowerOn <devnum>" ); " device in the device list.\n"
SampleUtil_Print( " Sends the PowerOn action to the Control Service of" ); " PowerOn <devnum>\n"
SampleUtil_Print( " device <devnum>." ); " Sends the PowerOn action to the Control Service of\n"
SampleUtil_Print( " PowerOff <devnum>" ); " device <devnum>.\n"
SampleUtil_Print( " Sends the PowerOff action to the Control Service of" ); " PowerOff <devnum>\n"
SampleUtil_Print( " device <devnum>." ); " Sends the PowerOff action to the Control Service of\n"
SampleUtil_Print( " SetChannel <devnum> <channel>" ); " device <devnum>.\n"
SampleUtil_Print( " Sends the SetChannel action to the Control Service of" ); " SetChannel <devnum> <channel>\n"
SampleUtil_Print( " device <devnum>, requesting the channel to be changed" ); " Sends the SetChannel action to the Control Service of\n"
SampleUtil_Print( " to <channel>." ); " device <devnum>, requesting the channel to be changed\n"
SampleUtil_Print( " SetVolume <devnum> <volume>" ); " to <channel>.\n"
SampleUtil_Print( " Sends the SetVolume action to the Control Service of" ); " SetVolume <devnum> <volume>\n"
SampleUtil_Print( " device <devnum>, requesting the volume to be changed" ); " Sends the SetVolume action to the Control Service of\n"
SampleUtil_Print( " to <volume>." ); " device <devnum>, requesting the volume to be changed\n"
SampleUtil_Print( " SetColor <devnum> <color>" ); " to <volume>.\n"
SampleUtil_Print( " Sends the SetColor action to the Control Service of" ); " SetColor <devnum> <color>\n"
SampleUtil_Print( " device <devnum>, requesting the color to be changed" ); " Sends the SetColor action to the Control Service of\n"
SampleUtil_Print( " to <color>." ); " device <devnum>, requesting the color to be changed\n"
SampleUtil_Print( " SetTint <devnum> <tint>" ); " to <color>.\n"
SampleUtil_Print( " Sends the SetTint action to the Control Service of" ); " SetTint <devnum> <tint>\n"
SampleUtil_Print( " device <devnum>, requesting the tint to be changed" ); " Sends the SetTint action to the Control Service of\n"
SampleUtil_Print( " to <tint>." ); " device <devnum>, requesting the tint to be changed\n"
SampleUtil_Print( " SetContrast <devnum> <contrast>" ); " to <tint>.\n"
SampleUtil_Print( " Sends the SetContrast action to the Control Service of" ); " SetContrast <devnum> <contrast>\n"
SampleUtil_Print( " device <devnum>, requesting the contrast to be changed" ); " Sends the SetContrast action to the Control Service of\n"
SampleUtil_Print( " to <contrast>." ); " device <devnum>, requesting the contrast to be changed\n"
SampleUtil_Print( " SetBrightness <devnum> <brightness>" ); " to <contrast>.\n"
SampleUtil_Print( " Sends the SetBrightness action to the Control Service of" ); " SetBrightness <devnum> <brightness>\n"
SampleUtil_Print( " device <devnum>, requesting the brightness to be changed" ); " Sends the SetBrightness action to the Control Service of\n"
SampleUtil_Print( " to <brightness>." ); " device <devnum>, requesting the brightness to be changed\n"
SampleUtil_Print( " CtrlAction <devnum> <action>" ); " to <brightness>.\n"
SampleUtil_Print( " Sends an action request specified by the string <action>" ); " CtrlAction <devnum> <action>\n"
SampleUtil_Print( " to the Control Service of device <devnum>. This command" ); " Sends an action request specified by the string <action>\n"
SampleUtil_Print( " only works for actions that have no arguments." ); " to the Control Service of device <devnum>. This command\n"
SampleUtil_Print( " (e.g., \"CtrlAction 1 IncreaseChannel\")" ); " only works for actions that have no arguments.\n"
SampleUtil_Print( " PictAction <devnum> <action>" ); " (e.g., \"CtrlAction 1 IncreaseChannel\")\n"
SampleUtil_Print( " Sends an action request specified by the string <action>" ); " PictAction <devnum> <action>\n"
SampleUtil_Print( " to the Picture Service of device <devnum>. This command" ); " Sends an action request specified by the string <action>\n"
SampleUtil_Print( " only works for actions that have no arguments." ); " to the Picture Service of device <devnum>. This command\n"
SampleUtil_Print( " (e.g., \"PictAction 1 DecreaseContrast\")" ); " only works for actions that have no arguments.\n"
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" ); " (e.g., \"PictAction 1 DecreaseContrast\")\n"
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" ); " CtrlGetVar <devnum> <varname>\n"
SampleUtil_Print( " from the Control Service of device <devnum>." ); " Requests the value of a variable specified by the string <varname>\n"
SampleUtil_Print( " (e.g., \"CtrlGetVar 1 Volume\")" ); " from the Control Service of device <devnum>.\n"
SampleUtil_Print( " PictGetVar <devnum> <action>" ); " (e.g., \"CtrlGetVar 1 Volume\")\n"
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" ); " PictGetVar <devnum> <action>\n"
SampleUtil_Print( " from the Picture Service of device <devnum>." ); " Requests the value of a variable specified by the string <varname>\n"
SampleUtil_Print( " (e.g., \"PictGetVar 1 Tint\")" ); " from the Picture Service of device <devnum>.\n"
SampleUtil_Print( " Exit" ); " (e.g., \"PictGetVar 1 Tint\")\n"
SampleUtil_Print( " Exits the control point application." ); " Exit\n"
" Exits the control point application.\n");
} }
/******************************************************************************** /*!
* TvCtrlPointPrintCommands * \briefPrint the list of valid command line commands to the user
* */
* Description: void TvCtrlPointPrintCommands()
* Print the list of valid command line commands to the user
*
* Parameters:
* None
*
********************************************************************************/
void
TvCtrlPointPrintCommands()
{ {
int i; int i;
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands ); int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
SampleUtil_Print( "Valid Commands:" ); SampleUtil_Print("Valid Commands:\n");
for( i = 0; i < numofcmds; i++ ) { for (i = 0; i < numofcmds; ++i) {
SampleUtil_Print( " %-14s %s", cmdloop_cmdlist[i].str, SampleUtil_Print(" %-14s %s\n",
cmdloop_cmdlist[i].args ); cmdloop_cmdlist[i].str, cmdloop_cmdlist[i].args);
} }
SampleUtil_Print( "" ); SampleUtil_Print("\n");
} }
/******************************************************************************** /*!
* TvCtrlPointCommandLoop * \brief Function that receives commands from the user at the command prompt
* * during the lifetime of the device, and calls the appropriate
* Description: * functions for those commands.
* Function that receives commands from the user at the command prompt */
* during the lifetime of the control point, and calls the appropriate void *TvCtrlPointCommandLoop(void *args)
* functions for those commands.
*
* Parameters:
* None
*
********************************************************************************/
void *
TvCtrlPointCommandLoop( void *args )
{ {
char cmdline[100]; char cmdline[100];
while( 1 ) { while (1) {
SampleUtil_Print( "\n>> " ); SampleUtil_Print("\n>> ");
fgets( cmdline, 100, stdin ); fgets(cmdline, 100, stdin);
TvCtrlPointProcessCommand( cmdline ); TvCtrlPointProcessCommand(cmdline);
} }
return NULL; return NULL;
args = args;
} }
int int TvCtrlPointProcessCommand(char *cmdline)
TvCtrlPointProcessCommand( char *cmdline )
{ {
char cmd[100]; char cmd[100];
char strarg[100]; char strarg[100];
int arg_val_err = -99999; int arg_val_err = -99999;
int arg1 = arg_val_err; int arg1 = arg_val_err;
int arg2 = arg_val_err; int arg2 = arg_val_err;
int cmdnum = -1; int cmdnum = -1;
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands ); int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
int cmdfound = 0; int cmdfound = 0;
int i, int i;
rc; int rc;
int invalidargs = 0; int invalidargs = 0;
int validargs; int validargs;
validargs = sscanf( cmdline, "%s %d %d", cmd, &arg1, &arg2 ); validargs = sscanf(cmdline, "%s %d %d", cmd, &arg1, &arg2);
for (i = 0; i < numofcmds; ++i) {
if (strcasecmp(cmd, cmdloop_cmdlist[i].str ) == 0) {
cmdnum = cmdloop_cmdlist[i].cmdnum;
cmdfound++;
if (validargs != cmdloop_cmdlist[i].numargs)
invalidargs++;
break;
}
}
if (!cmdfound) {
SampleUtil_Print("Command not found; try 'Help'\n");
return TV_SUCCESS;
}
if (invalidargs) {
SampleUtil_Print("Invalid arguments; try 'Help'\n");
return TV_SUCCESS;
}
switch (cmdnum) {
case PRTHELP:
TvCtrlPointPrintShortHelp();
break;
case PRTFULLHELP:
TvCtrlPointPrintLongHelp();
break;
case POWON:
TvCtrlPointSendPowerOn(arg1);
break;
case POWOFF:
TvCtrlPointSendPowerOff(arg1);
break;
case SETCHAN:
TvCtrlPointSendSetChannel(arg1, arg2);
break;
case SETVOL:
TvCtrlPointSendSetVolume(arg1, arg2);
break;
case SETCOL:
TvCtrlPointSendSetColor(arg1, arg2);
break;
case SETTINT:
TvCtrlPointSendSetTint(arg1, arg2);
break;
case SETCONT:
TvCtrlPointSendSetContrast(arg1, arg2);
break;
case SETBRT:
TvCtrlPointSendSetBrightness(arg1, arg2);
break;
case CTRLACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_CONTROL, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case PICTACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_PICTURE, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case CTRLGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_CONTROL, arg1, strarg);
else
invalidargs++;
break;
case PICTGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_PICTURE, arg1, strarg);
else
invalidargs++;
break;
case PRTDEV:
TvCtrlPointPrintDevice(arg1);
break;
case LSTDEV:
TvCtrlPointPrintList();
break;
case REFRESH:
TvCtrlPointRefresh();
break;
case EXITCMD:
rc = TvCtrlPointStop();
exit(rc);
break;
default:
SampleUtil_Print("Command not implemented; see 'Help'\n");
break;
}
if(invalidargs)
SampleUtil_Print("Invalid args in command; see 'Help'\n");
for( i = 0; i < numofcmds; i++ ) { return TV_SUCCESS;
if( strcasecmp( cmd, cmdloop_cmdlist[i].str ) == 0 ) {
cmdnum = cmdloop_cmdlist[i].cmdnum;
cmdfound++;
if( validargs != cmdloop_cmdlist[i].numargs )
invalidargs++;
break;
}
}
if( !cmdfound ) {
SampleUtil_Print( "Command not found; try 'Help'" );
return TV_SUCCESS;
}
if( invalidargs ) {
SampleUtil_Print( "Invalid arguments; try 'Help'" );
return TV_SUCCESS;
}
switch ( cmdnum ) {
case PRTHELP:
TvCtrlPointPrintShortHelp();
break;
case PRTFULLHELP:
TvCtrlPointPrintLongHelp();
break;
case POWON:
TvCtrlPointSendPowerOn( arg1 );
break;
case POWOFF:
TvCtrlPointSendPowerOff( arg1 );
break;
case SETCHAN:
TvCtrlPointSendSetChannel( arg1, arg2 );
break;
case SETVOL:
TvCtrlPointSendSetVolume( arg1, arg2 );
break;
case SETCOL:
TvCtrlPointSendSetColor( arg1, arg2 );
break;
case SETTINT:
TvCtrlPointSendSetTint( arg1, arg2 );
break;
case SETCONT:
TvCtrlPointSendSetContrast( arg1, arg2 );
break;
case SETBRT:
TvCtrlPointSendSetBrightness( arg1, arg2 );
break;
case CTRLACTION:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointSendAction( TV_SERVICE_CONTROL, arg1, strarg,
NULL, NULL, 0 );
else
invalidargs++;
break;
case PICTACTION:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointSendAction( TV_SERVICE_PICTURE, arg1, strarg,
NULL, NULL, 0 );
else
invalidargs++;
break;
case CTRLGETVAR:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointGetVar( TV_SERVICE_CONTROL, arg1, strarg );
else
invalidargs++;
break;
case PICTGETVAR:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointGetVar( TV_SERVICE_PICTURE, arg1, strarg );
else
invalidargs++;
break;
case PRTDEV:
TvCtrlPointPrintDevice( arg1 );
break;
case LSTDEV:
TvCtrlPointPrintList();
break;
case REFRESH:
TvCtrlPointRefresh();
break;
case EXITCMD:
rc = TvCtrlPointStop();
exit( rc );
break;
default:
SampleUtil_Print( "Command not implemented; see 'Help'" );
break;
}
if( invalidargs )
SampleUtil_Print( "Invalid args in command; see 'Help'" );
return TV_SUCCESS;
} }
int int device_main(int argc, char **argv)
device_main( int argc, char **argv )
{ {
unsigned int portTemp = 0; unsigned int portTemp = 0;
char *ip_address = NULL, char *ip_address = NULL,
*desc_doc_name = NULL, *desc_doc_name = NULL,
*web_dir_path = NULL; *web_dir_path = NULL;
unsigned int port = 0; unsigned short port = 0;
int i = 0; int i = 0;
SampleUtil_Initialize( linux_print ); SampleUtil_Initialize(linux_print);
/* Parse options */ /* Parse options */
for( i = 1; i < argc; i++ ) { for( i = 1; i < argc; i++ ) {
if( strcmp( argv[i], "-ip" ) == 0 ) { if( strcmp( argv[i], "-ip" ) == 0 ) {
@ -428,64 +377,57 @@ device_main( int argc, char **argv )
} else if( strcmp( argv[i], "-webdir" ) == 0 ) { } else if( strcmp( argv[i], "-webdir" ) == 0 ) {
web_dir_path = argv[++i]; web_dir_path = argv[++i];
} else if( strcmp( argv[i], "-help" ) == 0 ) { } else if( strcmp( argv[i], "-help" ) == 0 ) {
SampleUtil_Print( "Usage: %s -ip ipaddress -port port" SampleUtil_Print(
" -desc desc_doc_name -webdir web_dir_path" "Usage: %s -ip ipaddress -port port\n"
" -help (this message)\n", argv[0] ); " -desc desc_doc_name -webdir web_dir_path\n"
SampleUtil_Print( "\tipaddress: IP address of the device" " -help (this message)\n\n", argv[0]);
" (must match desc. doc)\n" ); SampleUtil_Print(
SampleUtil_Print( "\t\te.g.: 192.168.0.4\n" ); "\tipaddress:\tIP address of the device (must match desc. doc)\n"
SampleUtil_Print( "\tport: Port number to use for " "\t\te.g.: 192.168.0.4\n\n"
"receiving UPnP messages (must match desc. doc)\n" ); "\tport:\tPort number to use for receiving UPnP messages (must match desc. doc)\n"
SampleUtil_Print( "\t\te.g.: 5431\n" ); "\t\te.g.: 5431\n\n"
SampleUtil_Print "\tdesc_doc_name: name of device description document\n"
( "\tdesc_doc_name: name of device description document\n" ); "\t\te.g.: tvcombodesc.xml\n\n"
SampleUtil_Print( "\t\te.g.: tvcombodesc.xml\n" ); "\tweb_dir_path: Filesystem path where web files related to the device are stored\n"
SampleUtil_Print "\t\te.g.: /upnp/sample/web\n\n");
( "\tweb_dir_path: Filesystem path where web files " return 1;
"related to the device are stored\n" );
SampleUtil_Print( "\t\te.g.: /upnp/sample/web\n" );
return 1;
} }
} }
port = (unsigned short)portTemp;
port = ( unsigned short )portTemp; return TvDeviceStart(ip_address, port, desc_doc_name, web_dir_path, linux_print);
return TvDeviceStart( ip_address, port, desc_doc_name, web_dir_path, linux_print );
} }
int main( int argc, char **argv ) int main(int argc, char **argv)
{ {
int rc; int rc;
ithread_t cmdloop_thread; ithread_t cmdloop_thread;
#ifdef WIN32 #ifdef WIN32
#else #else
int sig; int sig;
sigset_t sigs_to_catch; sigset_t sigs_to_catch;
#endif #endif
int code; int code;
device_main(argc, argv);
rc = TvCtrlPointStart( linux_print, NULL );
if( rc != TV_SUCCESS ) {
SampleUtil_Print( "Error starting UPnP TV Control Point" );
return rc;
}
/* start a command loop thread */
code = ithread_create( &cmdloop_thread, NULL, TvCtrlPointCommandLoop, NULL );
device_main(argc, argv);
rc = TvCtrlPointStart(linux_print, NULL);
if (rc != TV_SUCCESS) {
SampleUtil_Print("Error starting UPnP TV Control Point\n");
return rc;
}
/* start a command loop thread */
code = ithread_create(&cmdloop_thread, NULL, TvCtrlPointCommandLoop, NULL);
#ifdef WIN32 #ifdef WIN32
ithread_join(cmdloop_thread, NULL); ithread_join(cmdloop_thread, NULL);
#else #else
/* /* Catch Ctrl-C and properly shutdown */
Catch Ctrl-C and properly shutdown sigemptyset(&sigs_to_catch);
*/ sigaddset(&sigs_to_catch, SIGINT);
sigemptyset( &sigs_to_catch ); sigwait(&sigs_to_catch, &sig);
sigaddset( &sigs_to_catch, SIGINT ); SampleUtil_Print("Shutting down on signal %d...\n", sig);
sigwait( &sigs_to_catch, &sig );
SampleUtil_Print( "Shutting down on signal %d...\n", sig );
#endif #endif
TvDeviceStop(); TvDeviceStop();
rc = TvCtrlPointStop(); rc = TvCtrlPointStop();
return rc;
return rc;
} }

View File

@ -47,8 +47,7 @@ ithread_mutex_t DeviceListMutex;
UpnpClient_Handle ctrlpt_handle = -1; UpnpClient_Handle ctrlpt_handle = -1;
const char TvDeviceType[] = "urn:schemas-upnp-org:device:tvdevice:1"; const char TvDeviceType[] = "urn:schemas-upnp-org:device:tvdevice:1";
const char *TvServiceType[] = const char *TvServiceType[] = {
{
"urn:schemas-upnp-org:service:tvcontrol:1", "urn:schemas-upnp-org:service:tvcontrol:1",
"urn:schemas-upnp-org:service:tvpicture:1" "urn:schemas-upnp-org:service:tvpicture:1"
}; };
@ -95,7 +94,7 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
var; var;
if( NULL == node ) { if( NULL == node ) {
SampleUtil_Print( "ERROR: TvCtrlPointDeleteNode: Node is empty" ); SampleUtil_Print("ERROR: TvCtrlPointDeleteNode: Node is empty\n");
return TV_ERROR; return TV_ERROR;
} }
@ -108,12 +107,12 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
node->device.TvService[service].SID ); node->device.TvService[service].SID );
if( UPNP_E_SUCCESS == rc ) { if( UPNP_E_SUCCESS == rc ) {
SampleUtil_Print SampleUtil_Print
( "Unsubscribed from Tv %s EventURL with SID=%s", ( "Unsubscribed from Tv %s EventURL with SID=%s\n",
TvServiceName[service], TvServiceName[service],
node->device.TvService[service].SID ); node->device.TvService[service].SID );
} else { } else {
SampleUtil_Print SampleUtil_Print
( "Error unsubscribing to Tv %s EventURL -- %d", ( "Error unsubscribing to Tv %s EventURL -- %d\n",
TvServiceName[service], rc ); TvServiceName[service], rc );
} }
} }
@ -153,8 +152,7 @@ int TvCtrlPointRemoveDevice(const char *UDN)
curdevnode = GlobalDeviceList; curdevnode = GlobalDeviceList;
if( !curdevnode ) { if( !curdevnode ) {
SampleUtil_Print SampleUtil_Print("WARNING: TvCtrlPointRemoveDevice: Device list empty\n");
( "WARNING: TvCtrlPointRemoveDevice: Device list empty" );
} else { } else {
if( 0 == strcmp( curdevnode->device.UDN, UDN ) ) { if( 0 == strcmp( curdevnode->device.UDN, UDN ) ) {
GlobalDeviceList = curdevnode->next; GlobalDeviceList = curdevnode->next;
@ -237,7 +235,7 @@ TvCtrlPointRefresh( void )
*/ */
rc = UpnpSearchAsync( ctrlpt_handle, 5, TvDeviceType, NULL ); rc = UpnpSearchAsync( ctrlpt_handle, 5, TvDeviceType, NULL );
if( UPNP_E_SUCCESS != rc ) { if( UPNP_E_SUCCESS != rc ) {
SampleUtil_Print( "Error sending search request%d", rc ); SampleUtil_Print("Error sending search request%d\n", rc);
return TV_ERROR; return TV_ERROR;
} }
@ -257,10 +255,7 @@ TvCtrlPointRefresh( void )
* varname -- The name of the variable to request. * varname -- The name of the variable to request.
* *
********************************************************************************/ ********************************************************************************/
int int TvCtrlPointGetVar(int service, int devnum, const char *varname)
TvCtrlPointGetVar( int service,
int devnum,
char *varname )
{ {
struct TvDeviceNode *devnode; struct TvDeviceNode *devnode;
int rc; int rc;
@ -277,8 +272,7 @@ TvCtrlPointGetVar( int service,
TvCtrlPointCallbackEventHandler, TvCtrlPointCallbackEventHandler,
NULL ); NULL );
if( rc != UPNP_E_SUCCESS ) { if( rc != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print("Error in UpnpGetServiceVarStatusAsync -- %d\n", rc);
( "Error in UpnpGetServiceVarStatusAsync -- %d", rc );
rc = TV_ERROR; rc = TV_ERROR;
} }
} }
@ -346,13 +340,13 @@ TvCtrlPointGetBrightness( int devnum )
* param_count -- The number of parameters * param_count -- The number of parameters
* *
********************************************************************************/ ********************************************************************************/
int int TvCtrlPointSendAction(
TvCtrlPointSendAction( int service, int service,
int devnum, int devnum,
char *actionname, const char *actionname,
char **param_name, const char **param_name,
char **param_val, char **param_val,
int param_count ) int param_count)
{ {
struct TvDeviceNode *devnode; struct TvDeviceNode *devnode;
IXML_Document *actionNode = NULL; IXML_Document *actionNode = NULL;
@ -373,8 +367,7 @@ TvCtrlPointSendAction( int service,
( &actionNode, actionname, TvServiceType[service], ( &actionNode, actionname, TvServiceType[service],
param_name[param], param_name[param],
param_val[param] ) != UPNP_E_SUCCESS ) { param_val[param] ) != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print("ERROR: TvCtrlPointSendAction: Trying to add action param\n");
( "ERROR: TvCtrlPointSendAction: Trying to add action param" );
/*return -1; // TBD - BAD! leaves mutex locked */ /*return -1; // TBD - BAD! leaves mutex locked */
} }
} }
@ -387,7 +380,7 @@ TvCtrlPointSendAction( int service,
TvCtrlPointCallbackEventHandler, NULL ); TvCtrlPointCallbackEventHandler, NULL );
if( rc != UPNP_E_SUCCESS ) { if( rc != UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error in UpnpSendActionAsync -- %d", rc ); SampleUtil_Print( "Error in UpnpSendActionAsync -- %d\n", rc );
rc = TV_ERROR; rc = TV_ERROR;
} }
} }
@ -416,8 +409,8 @@ TvCtrlPointSendAction( int service,
int int
TvCtrlPointSendActionNumericArg( int devnum, TvCtrlPointSendActionNumericArg( int devnum,
int service, int service,
char *actionName, const char *actionName,
char *paramName, const char *paramName,
int paramValue ) int paramValue )
{ {
char param_val_a[50]; char param_val_a[50];
@ -525,7 +518,7 @@ TvCtrlPointGetDevice( int devnum,
} }
if( !tmpdevnode ) { if( !tmpdevnode ) {
SampleUtil_Print( "Error finding TvDevice number -- %d", devnum ); SampleUtil_Print( "Error finding TvDevice number -- %d\n", devnum );
return TV_ERROR; return TV_ERROR;
} }
@ -551,13 +544,13 @@ TvCtrlPointPrintList()
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
SampleUtil_Print( "TvCtrlPointPrintList:" ); SampleUtil_Print("TvCtrlPointPrintList:\n");
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
SampleUtil_Print( " %3d -- %s", ++i, tmpdevnode->device.UDN ); SampleUtil_Print( " %3d -- %s\n", ++i, tmpdevnode->device.UDN );
tmpdevnode = tmpdevnode->next; tmpdevnode = tmpdevnode->next;
} }
SampleUtil_Print( "" ); SampleUtil_Print("\n");
ithread_mutex_unlock( &DeviceListMutex ); ithread_mutex_unlock( &DeviceListMutex );
return TV_SUCCESS; return TV_SUCCESS;
@ -585,15 +578,13 @@ TvCtrlPointPrintDevice( int devnum )
char spacer[15]; char spacer[15];
if( devnum <= 0 ) { if( devnum <= 0 ) {
SampleUtil_Print SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d\n", devnum);
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d",
devnum );
return TV_ERROR; return TV_ERROR;
} }
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
SampleUtil_Print( "TvCtrlPointPrintDevice:" ); SampleUtil_Print("TvCtrlPointPrintDevice:\n");
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
i++; i++;
@ -603,57 +594,35 @@ TvCtrlPointPrintDevice( int devnum )
} }
if( !tmpdevnode ) { if( !tmpdevnode ) {
SampleUtil_Print SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d\n", devnum, i);
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d",
devnum, i );
} else { } else {
SampleUtil_Print( " TvDevice -- %d", devnum ); SampleUtil_Print(" TvDevice -- %d\n", devnum);
SampleUtil_Print( " | " ); SampleUtil_Print(" | \n");
SampleUtil_Print( " +- UDN = %s", SampleUtil_Print(" +- UDN = %s\n" , tmpdevnode->device.UDN);
tmpdevnode->device.UDN ); SampleUtil_Print(" +- DescDocURL = %s\n", tmpdevnode->device.DescDocURL);
SampleUtil_Print( " +- DescDocURL = %s", SampleUtil_Print(" +- FriendlyName = %s\n", tmpdevnode->device.FriendlyName);
tmpdevnode->device.DescDocURL ); SampleUtil_Print(" +- PresURL = %s\n", tmpdevnode->device.PresURL);
SampleUtil_Print( " +- FriendlyName = %s", SampleUtil_Print(" +- Adver. TimeOut = %d\n", tmpdevnode->device.AdvrTimeOut);
tmpdevnode->device.FriendlyName );
SampleUtil_Print( " +- PresURL = %s",
tmpdevnode->device.PresURL );
SampleUtil_Print( " +- Adver. TimeOut = %d",
tmpdevnode->device.AdvrTimeOut );
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( service < TV_SERVICE_SERVCOUNT - 1 ) if(service < TV_SERVICE_SERVCOUNT - 1)
sprintf( spacer, " | " ); sprintf(spacer, " | ");
else else
sprintf( spacer, " " ); sprintf(spacer, " ");
SampleUtil_Print( " | " ); SampleUtil_Print(" | ");
SampleUtil_Print( " +- Tv %s Service", SampleUtil_Print(" +- Tv %s Service", TvServiceName[service]);
TvServiceName[service] ); SampleUtil_Print("%s+- ServiceId = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceId);
SampleUtil_Print( "%s+- ServiceId = %s", spacer, SampleUtil_Print("%s+- ServiceType = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceType);
tmpdevnode->device.TvService[service]. SampleUtil_Print("%s+- EventURL = %s\n", spacer, tmpdevnode->device.TvService[service].EventURL);
ServiceId ); SampleUtil_Print("%s+- ControlURL = %s\n", spacer, tmpdevnode->device.TvService[service].ControlURL);
SampleUtil_Print( "%s+- ServiceType = %s", spacer, SampleUtil_Print("%s+- SID = %s\n", spacer, tmpdevnode->device.TvService[service].SID);
tmpdevnode->device.TvService[service]. SampleUtil_Print("%s+- ServiceStateTable", spacer);
ServiceType );
SampleUtil_Print( "%s+- EventURL = %s", spacer,
tmpdevnode->device.TvService[service].
EventURL );
SampleUtil_Print( "%s+- ControlURL = %s", spacer,
tmpdevnode->device.TvService[service].
ControlURL );
SampleUtil_Print( "%s+- SID = %s", spacer,
tmpdevnode->device.TvService[service].SID );
SampleUtil_Print( "%s+- ServiceStateTable", spacer );
for( var = 0; var < TvVarCount[service]; var++ ) { for( var = 0; var < TvVarCount[service]; var++ ) {
SampleUtil_Print( "%s +- %-10s = %s", spacer, SampleUtil_Print("%s +- %-10s = %s\n", spacer, TvVarName[service][var],
TvVarName[service][var], tmpdevnode->device.TvService[service].VariableStrVal[var]);
tmpdevnode->device.TvService[service].
VariableStrVal[var] );
} }
} }
} }
SampleUtil_Print("\n");
SampleUtil_Print( "" );
ithread_mutex_unlock( &DeviceListMutex ); ithread_mutex_unlock( &DeviceListMutex );
return TV_SUCCESS; return TV_SUCCESS;
@ -711,11 +680,10 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
( baseURL ? baseURL : location ), relURL, presURL); ( baseURL ? baseURL : location ), relURL, presURL);
if( UPNP_E_SUCCESS != ret ) if( UPNP_E_SUCCESS != ret )
SampleUtil_Print( "Error generating presURL from %s + %s", baseURL, SampleUtil_Print( "Error generating presURL from %s + %s\n", baseURL, relURL );
relURL );
if( strcmp( deviceType, TvDeviceType ) == 0 ) { if( strcmp( deviceType, TvDeviceType ) == 0 ) {
SampleUtil_Print( "Found Tv device" ); SampleUtil_Print("Found Tv device\n");
/* Check if this device is already in the list */ /* Check if this device is already in the list */
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
@ -733,45 +701,29 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
tmpdevnode->device.AdvrTimeOut = expires; tmpdevnode->device.AdvrTimeOut = expires;
} else { } else {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( SampleUtil_FindAndParseService if( SampleUtil_FindAndParseService(DescDoc, location, TvServiceType[service],
( DescDoc, location, TvServiceType[service],
&serviceId[service], &eventURL[service], &serviceId[service], &eventURL[service],
&controlURL[service] ) ) { &controlURL[service])) {
SampleUtil_Print( "Subscribing to EventURL %s...", SampleUtil_Print("Subscribing to EventURL %s...\n", eventURL[service]);
eventURL[service] ); ret = UpnpSubscribe(ctrlpt_handle, eventURL[service],
&TimeOut[service], eventSID[service]);
ret =
UpnpSubscribe( ctrlpt_handle, eventURL[service],
&TimeOut[service],
eventSID[service] );
if( ret == UPNP_E_SUCCESS ) { if( ret == UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print("Subscribed to EventURL with SID=%s\n", eventSID[service]);
( "Subscribed to EventURL with SID=%s",
eventSID[service] );
} else { } else {
SampleUtil_Print SampleUtil_Print("Error Subscribing to EventURL -- %d\n", ret);
( "Error Subscribing to EventURL -- %d", ret ); strcpy(eventSID[service], "");
strcpy( eventSID[service], "" );
} }
} else { } else {
SampleUtil_Print( "Error: Could not find Service: %s", SampleUtil_Print("Error: Could not find Service: %s\n", TvServiceType[service]);
TvServiceType[service] );
} }
} }
/* Create a new device node */
/* deviceNode = (struct TvDeviceNode *)malloc(sizeof(struct TvDeviceNode));
Create a new device node
*/
deviceNode =
( struct TvDeviceNode * )
malloc( sizeof( struct TvDeviceNode ) );
strcpy( deviceNode->device.UDN, UDN ); strcpy( deviceNode->device.UDN, UDN );
strcpy( deviceNode->device.DescDocURL, location ); strcpy( deviceNode->device.DescDocURL, location );
strcpy( deviceNode->device.FriendlyName, friendlyName ); strcpy( deviceNode->device.FriendlyName, friendlyName );
strcpy( deviceNode->device.PresURL, presURL ); strcpy( deviceNode->device.PresURL, presURL );
deviceNode->device.AdvrTimeOut = expires; deviceNode->device.AdvrTimeOut = expires;
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
strcpy( deviceNode->device.TvService[service].ServiceId, strcpy( deviceNode->device.TvService[service].ServiceId,
serviceId[service] ); serviceId[service] );
@ -783,7 +735,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
eventURL[service] ); eventURL[service] );
strcpy( deviceNode->device.TvService[service].SID, strcpy( deviceNode->device.TvService[service].SID,
eventSID[service] ); eventSID[service] );
for( var = 0; var < TvVarCount[service]; var++ ) { for( var = 0; var < TvVarCount[service]; var++ ) {
deviceNode->device.TvService[service]. deviceNode->device.TvService[service].
VariableStrVal[var] = VariableStrVal[var] =
@ -792,12 +743,9 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
VariableStrVal[var], "" ); VariableStrVal[var], "" );
} }
} }
deviceNode->next = NULL; deviceNode->next = NULL;
/* Insert the new device node in the list */ /* Insert the new device node in the list */
if( ( tmpdevnode = GlobalDeviceList ) ) { if( ( tmpdevnode = GlobalDeviceList ) ) {
while( tmpdevnode ) { while( tmpdevnode ) {
if( tmpdevnode->next ) { if( tmpdevnode->next ) {
tmpdevnode = tmpdevnode->next; tmpdevnode = tmpdevnode->next;
@ -809,10 +757,8 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
} else { } else {
GlobalDeviceList = deviceNode; GlobalDeviceList = deviceNode;
} }
/*Notify New Device Added */ /*Notify New Device Added */
SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN, SampleUtil_StateUpdate(NULL, NULL, deviceNode->device.UDN, DEVICE_ADDED);
DEVICE_ADDED );
} }
} }
@ -828,7 +774,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
free( baseURL ); free( baseURL );
if( relURL ) if( relURL )
free( relURL ); free( relURL );
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( serviceId[service] ) if( serviceId[service] )
free( serviceId[service] ); free( serviceId[service] );
@ -872,33 +817,23 @@ TvStateUpdate( char *UDN,
j; j;
char *tmpstate = NULL; char *tmpstate = NULL;
SampleUtil_Print( "Tv State Update (service %d): ", Service ); SampleUtil_Print( "Tv State Update (service %d):\n", Service );
/* Find all of the e:property tags in the document */
/* properties = ixmlDocument_getElementsByTagName(
Find all of the e:property tags in the document ChangedVariables, "e:property" );
*/
properties =
ixmlDocument_getElementsByTagName( ChangedVariables,
"e:property" );
if( NULL != properties ) { if( NULL != properties ) {
length = ixmlNodeList_length( properties ); length = ixmlNodeList_length( properties );
for( i = 0; i < length; i++ ) { /* Loop through each property change found */ for( i = 0; i < length; i++ ) { /* Loop through each property change found */
property = property =
( IXML_Element * ) ixmlNodeList_item( properties, i ); ( IXML_Element * ) ixmlNodeList_item( properties, i );
/* For each variable name in the state table, check if this
/* * is a corresponding property change */
For each variable name in the state table, check if this
is a corresponding property change
*/
for( j = 0; j < TvVarCount[Service]; j++ ) { for( j = 0; j < TvVarCount[Service]; j++ ) {
variables = variables =
ixmlElement_getElementsByTagName( property, ixmlElement_getElementsByTagName( property,
TvVarName[Service] TvVarName[Service]
[j] ); [j] );
/* If a match is found, extract the value, and update the state table */
/*
If a match is found, extract the value, and update the state table
*/
if( variables ) { if( variables ) {
length1 = ixmlNodeList_length( variables ); length1 = ixmlNodeList_length( variables );
if( length1 ) { if( length1 ) {
@ -909,21 +844,16 @@ TvStateUpdate( char *UDN,
if( tmpstate ) { if( tmpstate ) {
strcpy( State[j], tmpstate ); strcpy( State[j], tmpstate );
SampleUtil_Print SampleUtil_Print(" Variable Name: %s New Value:'%s'\n", TvVarName[Service][j], State[j] );
( " Variable Name: %s New Value:'%s'",
TvVarName[Service][j], State[j] );
} }
if( tmpstate ) if( tmpstate )
free( tmpstate ); free( tmpstate );
tmpstate = NULL; tmpstate = NULL;
} }
ixmlNodeList_free( variables ); ixmlNodeList_free( variables );
variables = NULL; variables = NULL;
} }
} }
} }
ixmlNodeList_free( properties ); ixmlNodeList_free( properties );
} }
@ -956,7 +886,7 @@ void TvCtrlPointHandleEvent(
while (tmpdevnode) { while (tmpdevnode) {
for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) { for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) {
if (strcmp(tmpdevnode->device.TvService[service].SID, sid) == 0) { if (strcmp(tmpdevnode->device.TvService[service].SID, sid) == 0) {
SampleUtil_Print("Received Tv %s Event: %d for SID %s", SampleUtil_Print("Received Tv %s Event: %d for SID %s\n",
TvServiceName[service], TvServiceName[service],
evntkey, evntkey,
sid); sid);
@ -1001,13 +931,10 @@ void TvCtrlPointHandleSubscribeUpdate(
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( strcmp if( strcmp
( tmpdevnode->device.TvService[service].EventURL, ( tmpdevnode->device.TvService[service].EventURL,
eventURL ) == 0 ) { eventURL ) == 0 ) {
SampleUtil_Print SampleUtil_Print("Received Tv %s Event Renewal for eventURL %s\n", TvServiceName[service], eventURL );
( "Received Tv %s Event Renewal for eventURL %s",
TvServiceName[service], eventURL );
strcpy( tmpdevnode->device.TvService[service].SID, sid ); strcpy( tmpdevnode->device.TvService[service].SID, sid );
break; break;
} }
@ -1075,14 +1002,14 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Discovery Callback -- %d", errCode); "Error in Discovery Callback -- %d\n", errCode);
} }
location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event)); location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event));
errCode = UpnpDownloadXmlDoc(location, &DescDoc); errCode = UpnpDownloadXmlDoc(location, &DescDoc);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error obtaining device description from %s -- error = %d", "Error obtaining device description from %s -- error = %d\n",
location, errCode); location, errCode);
} else { } else {
TvCtrlPointAddDevice( TvCtrlPointAddDevice(
@ -1105,11 +1032,11 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Discovery ByeBye Callback -- %d", errCode); "Error in Discovery ByeBye Callback -- %d\n", errCode);
} }
SampleUtil_Print("Received ByeBye for Device: %s", deviceId); SampleUtil_Print("Received ByeBye for Device: %s\n", deviceId);
TvCtrlPointRemoveDevice(deviceId); TvCtrlPointRemoveDevice(deviceId);
SampleUtil_Print("After byebye:"); SampleUtil_Print("After byebye:\n");
TvCtrlPointPrintList(); TvCtrlPointPrintList();
break; break;
} }
@ -1119,7 +1046,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
int errCode = UpnpActionComplete_get_ErrCode(a_event); int errCode = UpnpActionComplete_get_ErrCode(a_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Action Complete Callback -- %d", "Error in Action Complete Callback -- %d\n",
errCode); errCode);
} }
/* No need for any processing here, just print out results. /* No need for any processing here, just print out results.
@ -1131,7 +1058,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
int errCode = UpnpStateVarComplete_get_ErrCode(sv_event); int errCode = UpnpStateVarComplete_get_ErrCode(sv_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Get Var Complete Callback -- %d", errCode); "Error in Get Var Complete Callback -- %d\n", errCode);
} else { } else {
TvCtrlPointHandleGetVar( TvCtrlPointHandleGetVar(
UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)), UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)),
@ -1157,7 +1084,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
errCode = UpnpEventSubscribe_get_ErrCode(es_event); errCode = UpnpEventSubscribe_get_ErrCode(es_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Event Subscribe Callback -- %d", errCode); "Error in Event Subscribe Callback -- %d\n", errCode);
} else { } else {
TvCtrlPointHandleSubscribeUpdate( TvCtrlPointHandleSubscribeUpdate(
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)), UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
@ -1178,13 +1105,13 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
&TimeOut, &TimeOut,
newSID); newSID);
if (errCode == UPNP_E_SUCCESS) { if (errCode == UPNP_E_SUCCESS) {
SampleUtil_Print("Subscribed to EventURL with SID=%s", newSID); SampleUtil_Print("Subscribed to EventURL with SID=%s\n", newSID);
TvCtrlPointHandleSubscribeUpdate( TvCtrlPointHandleSubscribeUpdate(
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)), UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
newSID, newSID,
TimeOut); TimeOut);
} else { } else {
SampleUtil_Print("Error Subscribing to EventURL -- %d", errCode); SampleUtil_Print("Error Subscribing to EventURL -- %d\n", errCode);
} }
break; break;
} }
@ -1254,18 +1181,14 @@ TvCtrlPointVerifyTimeouts( int incr )
ret = UpnpSearchAsync( ctrlpt_handle, incr, ret = UpnpSearchAsync( ctrlpt_handle, incr,
curdevnode->device.UDN, NULL ); curdevnode->device.UDN, NULL );
if( ret != UPNP_E_SUCCESS ) if( ret != UPNP_E_SUCCESS )
SampleUtil_Print SampleUtil_Print("Error sending search request for Device UDN: %s -- err = %d\n",
( "Error sending search request for Device UDN: %s -- err = %d",
curdevnode->device.UDN, ret ); curdevnode->device.UDN, ret );
} }
prevdevnode = curdevnode; prevdevnode = curdevnode;
curdevnode = curdevnode->next; curdevnode = curdevnode->next;
} }
} }
ithread_mutex_unlock( &DeviceListMutex ); ithread_mutex_unlock( &DeviceListMutex );
} }
/******************************************************************************** /********************************************************************************
@ -1327,7 +1250,7 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
rc = UpnpInit(ip_address, port); rc = UpnpInit(ip_address, port);
if (rc != UPNP_E_SUCCESS) { if (rc != UPNP_E_SUCCESS) {
SampleUtil_Print("WinCEStart: UpnpInit() Error: %d", rc); SampleUtil_Print("WinCEStart: UpnpInit() Error: %d\n", rc);
/* /*
UpnpFinish(); UpnpFinish();
return TV_ERROR; return TV_ERROR;
@ -1345,18 +1268,17 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
"\tipaddress = %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address ? ip_address : "{NULL}", ip_address ? ip_address : "{NULL}",
port); port);
SampleUtil_Print("Registering Control Point\n");
SampleUtil_Print("Registering Control Point");
rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler, rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler,
&ctrlpt_handle, &ctrlpt_handle); &ctrlpt_handle, &ctrlpt_handle);
if (rc != UPNP_E_SUCCESS) { if (rc != UPNP_E_SUCCESS) {
SampleUtil_Print( "Error registering CP: %d", rc ); SampleUtil_Print( "Error registering CP: %d\n", rc );
UpnpFinish(); UpnpFinish();
return TV_ERROR; return TV_ERROR;
} }
SampleUtil_Print("Control Point Registered"); SampleUtil_Print("Control Point Registered\n");
TvCtrlPointRefresh(); TvCtrlPointRefresh();

View File

@ -128,8 +128,8 @@ int TvCtrlPointRemoveAll(void);
int TvCtrlPointRefresh(void); int TvCtrlPointRefresh(void);
int TvCtrlPointSendAction(int, int, char *, char **, char **, int); int TvCtrlPointSendAction(int, int, const char *, const char **, char **, int);
int TvCtrlPointSendActionNumericArg(int devnum, int service, char *actionName, char *paramName, int paramValue); int TvCtrlPointSendActionNumericArg(int devnum, int service, const char *actionName, const char *paramName, int paramValue);
int TvCtrlPointSendPowerOn(int devnum); int TvCtrlPointSendPowerOn(int devnum);
int TvCtrlPointSendPowerOff(int devnum); int TvCtrlPointSendPowerOff(int devnum);
int TvCtrlPointSendSetChannel(int, int); int TvCtrlPointSendSetChannel(int, int);
@ -139,7 +139,7 @@ int TvCtrlPointSendSetTint(int, int);
int TvCtrlPointSendSetContrast(int, int); int TvCtrlPointSendSetContrast(int, int);
int TvCtrlPointSendSetBrightness(int, int); int TvCtrlPointSendSetBrightness(int, int);
int TvCtrlPointGetVar(int, int, char*); int TvCtrlPointGetVar(int, int, const char *);
int TvCtrlPointGetPower(int devnum); int TvCtrlPointGetPower(int devnum);
int TvCtrlPointGetChannel(int); int TvCtrlPointGetChannel(int);
int TvCtrlPointGetVolume(int); int TvCtrlPointGetVolume(int);
@ -168,5 +168,5 @@ int TvCtrlPointProcessCommand(char *cmdline);
}; };
#endif #endif
#endif /*UPNP_TV_CTRLPT_H */ #endif /* UPNP_TV_CTRLPT_H */

View File

@ -113,7 +113,7 @@ static int SetServiceTable(
/*! [in,out] service containing table to be set. */ /*! [in,out] service containing table to be set. */
INOUT struct TvService *out) INOUT struct TvService *out)
{ {
unsigned int i = 0; int i = 0;
strcpy( out->UDN, UDN ); strcpy( out->UDN, UDN );
strcpy( out->ServiceId, serviceId ); strcpy( out->ServiceId, serviceId );
@ -357,7 +357,7 @@ int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *sr_event)
int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *cgv_event) int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *cgv_event)
{ {
unsigned int i = 0; unsigned int i = 0;
unsigned int j = 0; int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL); UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
@ -479,8 +479,7 @@ int TvDeviceHandleActionRequest(UpnpActionRequest *ca_event)
return UpnpActionRequest_get_ErrCode(ca_event); return UpnpActionRequest_get_ErrCode(ca_event);
} }
int TvDeviceSetServiceTableVar(unsigned int service, unsigned int variable, int TvDeviceSetServiceTableVar(unsigned int service, int variable, char *value)
char *value)
{ {
/*IXML_Document *PropSet= NULL; */ /*IXML_Document *PropSet= NULL; */
@ -720,9 +719,7 @@ int TvDeviceSetVolume(IXML_Document *in, IXML_Document **out, const char **error
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, if( TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL,
TV_CONTROL_VOLUME, value ) ) { TV_CONTROL_VOLUME, value ) ) {
@ -783,9 +780,7 @@ static int IncrementVolume(
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the channel goes here
*/
sprintf( value, "%d", newvolume ); sprintf( value, "%d", newvolume );
@ -836,9 +831,7 @@ int TvDeviceSetColor(IXML_Document *in, IXML_Document **out, const char **errorS
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE, if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
TV_PICTURE_COLOR, value ) ) { TV_PICTURE_COLOR, value ) ) {
@ -898,9 +891,7 @@ static int IncrementColor(
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the channel goes here
*/
sprintf( value, "%d", newcolor ); sprintf( value, "%d", newcolor );
@ -952,9 +943,7 @@ int TvDeviceSetTint(IXML_Document *in, IXML_Document **out, const char **errorSt
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE, if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
TV_PICTURE_TINT, value ) ) { TV_PICTURE_TINT, value ) ) {
@ -1016,9 +1005,7 @@ int IncrementTint(IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OU
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the channel goes here
*/
sprintf( value, "%d", newtint ); sprintf( value, "%d", newtint );
@ -1115,9 +1102,7 @@ TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT const ch
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE, if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
TV_PICTURE_CONTRAST, value ) ) { TV_PICTURE_CONTRAST, value ) ) {

View File

@ -169,7 +169,7 @@ struct TvService {
/*! . */ /*! . */
upnp_action actions[TV_MAXACTIONS]; upnp_action actions[TV_MAXACTIONS];
/*! . */ /*! . */
unsigned int VariableCount; int VariableCount;
}; };
/*! Array of service structures */ /*! Array of service structures */
@ -271,7 +271,7 @@ int TvDeviceSetServiceTableVar(
/*! [in] The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL, /*! [in] The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL,
* TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT, * TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT,
* TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS). */ * TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS). */
unsigned int variable, int variable,
/*! [in] The string representation of the new value. */ /*! [in] The string representation of the new value. */
char *value); char *value);

View File

@ -29,413 +29,363 @@
* *
******************************************************************************/ ******************************************************************************/
#include "sample_util.h" #include "sample_util.h"
#include "upnp_tv_ctrlpt.h" #include "upnp_tv_ctrlpt.h"
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
/* /*! Tags for valid commands issued at the command prompt. */
Tags for valid commands issued at the command prompt
*/
enum cmdloop_tvcmds { enum cmdloop_tvcmds {
PRTHELP = 0, PRTFULLHELP, POWON, POWOFF, PRTHELP = 0, PRTFULLHELP, POWON, POWOFF,
SETCHAN, SETVOL, SETCOL, SETTINT, SETCONT, SETBRT, SETCHAN, SETVOL, SETCOL, SETTINT, SETCONT, SETBRT,
CTRLACTION, PICTACTION, CTRLGETVAR, PICTGETVAR, CTRLACTION, PICTACTION, CTRLGETVAR, PICTGETVAR,
PRTDEV, LSTDEV, REFRESH, EXITCMD PRTDEV, LSTDEV, REFRESH, EXITCMD
}; };
/* /*! Data structure for parsing commands from the command line. */
Data structure for parsing commands from the command line
*/
struct cmdloop_commands { struct cmdloop_commands {
char *str; /* the string */ /* the string */
int cmdnum; /* the command */ const char *str;
int numargs; /* the number of arguments */ /* the command */
char *args; /* the args */ int cmdnum;
/* the number of arguments */
int numargs;
/* the args */
const char *args;
} cmdloop_commands; } cmdloop_commands;
/* /*! Mappings between command text names, command tag,
Mappings between command text names, command tag, * and required command arguments for command line
and required command arguments for command line * commands */
commands
*/
static struct cmdloop_commands cmdloop_cmdlist[] = { static struct cmdloop_commands cmdloop_cmdlist[] = {
{"Help", PRTHELP, 1, ""}, {"Help", PRTHELP, 1, ""},
{"HelpFull", PRTFULLHELP, 1, ""}, {"HelpFull", PRTFULLHELP, 1, ""},
{"ListDev", LSTDEV, 1, ""}, {"ListDev", LSTDEV, 1, ""},
{"Refresh", REFRESH, 1, ""}, {"Refresh", REFRESH, 1, ""},
{"PrintDev", PRTDEV, 2, "<devnum>"}, {"PrintDev", PRTDEV, 2, "<devnum>"},
{"PowerOn", POWON, 2, "<devnum>"}, {"PowerOn", POWON, 2, "<devnum>"},
{"PowerOff", POWOFF, 2, "<devnum>"}, {"PowerOff", POWOFF, 2, "<devnum>"},
{"SetChannel", SETCHAN, 3, "<devnum> <channel (int)>"}, {"SetChannel", SETCHAN, 3, "<devnum> <channel (int)>"},
{"SetVolume", SETVOL, 3, "<devnum> <volume (int)>"}, {"SetVolume", SETVOL, 3, "<devnum> <volume (int)>"},
{"SetColor", SETCOL, 3, "<devnum> <color (int)>"}, {"SetColor", SETCOL, 3, "<devnum> <color (int)>"},
{"SetTint", SETTINT, 3, "<devnum> <tint (int)>"}, {"SetTint", SETTINT, 3, "<devnum> <tint (int)>"},
{"SetContrast", SETCONT, 3, "<devnum> <contrast (int)>"}, {"SetContrast", SETCONT, 3, "<devnum> <contrast (int)>"},
{"SetBrightness", SETBRT, 3, "<devnum> <brightness (int)>"}, {"SetBrightness", SETBRT, 3, "<devnum> <brightness (int)>"},
{"CtrlAction", CTRLACTION, 2, "<devnum> <action (string)>"}, {"CtrlAction", CTRLACTION, 2, "<devnum> <action (string)>"},
{"PictAction", PICTACTION, 2, "<devnum> <action (string)>"}, {"PictAction", PICTACTION, 2, "<devnum> <action (string)>"},
{"CtrlGetVar", CTRLGETVAR, 2, "<devnum> <varname (string)>"}, {"CtrlGetVar", CTRLGETVAR, 2, "<devnum> <varname (string)>"},
{"PictGetVar", PICTGETVAR, 2, "<devnum> <varname (string)>"}, {"PictGetVar", PICTGETVAR, 2, "<devnum> <varname (string)>"},
{"Exit", EXITCMD, 1, ""} {"Exit", EXITCMD, 1, ""}
}; };
void /*!
linux_print( const char *string ) * \brief Prints a string to standard out.
*/
void linux_print(const char *format, ...)
{ {
puts( string ); va_list argList;
va_start(argList, format);
vfprintf(stdout, format, argList);
fflush(stdout);
va_end(argList);
} }
/******************************************************************************** /*!
* TvCtrlPointPrintHelp * \brief Print help info for this application.
* */
* Description: void TvCtrlPointPrintShortHelp(void)
* Print help info for this application.
********************************************************************************/
void
TvCtrlPointPrintShortHelp( void )
{ {
SampleUtil_Print( "Commands:" ); SampleUtil_Print(
SampleUtil_Print( " Help" ); "Commands:\n"
SampleUtil_Print( " HelpFull" ); " Help\n"
SampleUtil_Print( " ListDev" ); " HelpFull\n"
SampleUtil_Print( " Refresh" ); " ListDev\n"
SampleUtil_Print( " PrintDev <devnum>" ); " Refresh\n"
SampleUtil_Print( " PowerOn <devnum>" ); " PrintDev <devnum>\n"
SampleUtil_Print( " PowerOff <devnum>" ); " PowerOn <devnum>\n"
SampleUtil_Print( " SetChannel <devnum> <channel>" ); " PowerOff <devnum>\n"
SampleUtil_Print( " SetVolume <devnum> <volume>" ); " SetChannel <devnum> <channel>\n"
SampleUtil_Print( " SetColor <devnum> <color>" ); " SetVolume <devnum> <volume>\n"
SampleUtil_Print( " SetTint <devnum> <tint>" ); " SetColor <devnum> <color>\n"
SampleUtil_Print( " SetContrast <devnum> <contrast>" ); " SetTint <devnum> <tint>\n"
SampleUtil_Print( " SetBrightness <devnum> <brightness>" ); " SetContrast <devnum> <contrast>\n"
SampleUtil_Print( " CtrlAction <devnum> <action>" ); " SetBrightness <devnum> <brightness>\n"
SampleUtil_Print( " PictAction <devnum> <action>" ); " CtrlAction <devnum> <action>\n"
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" ); " PictAction <devnum> <action>\n"
SampleUtil_Print( " PictGetVar <devnum> <action>" ); " CtrlGetVar <devnum> <varname>\n"
SampleUtil_Print( " Exit" ); " PictGetVar <devnum> <action>\n"
" Exit\n");
} }
void void TvCtrlPointPrintLongHelp(void)
TvCtrlPointPrintLongHelp( void )
{ {
SampleUtil_Print( "" ); SampleUtil_Print(
SampleUtil_Print( "******************************" ); "\n"
SampleUtil_Print( "* TV Control Point Help Info *" ); "******************************\n"
SampleUtil_Print( "******************************" ); "* TV Control Point Help Info *\n"
SampleUtil_Print( "" ); "******************************\n"
SampleUtil_Print( "This sample control point application automatically searches" ); "\n"
SampleUtil_Print( "for and subscribes to the services of television device emulator" ); "This sample control point application automatically searches\n"
SampleUtil_Print( "devices, described in the tvdevicedesc.xml description document." ); "for and subscribes to the services of television device emulator\n"
SampleUtil_Print( "" ); "devices, described in the tvdevicedesc.xml description document.\n"
SampleUtil_Print( "Commands:" ); "It also registers itself as a tv device.\n"
SampleUtil_Print( " Help" ); "\n"
SampleUtil_Print( " Print this help info." ); "Commands:\n"
SampleUtil_Print( " ListDev" ); " Help\n"
SampleUtil_Print( " Print the current list of TV Device Emulators that this" ); " Print this help info.\n"
SampleUtil_Print( " control point is aware of. Each device is preceded by a" ); " ListDev\n"
SampleUtil_Print( " device number which corresponds to the devnum argument of" ); " Print the current list of TV Device Emulators that this\n"
SampleUtil_Print( " commands listed below." ); " control point is aware of. Each device is preceded by a\n"
SampleUtil_Print( " Refresh" ); " device number which corresponds to the devnum argument of\n"
SampleUtil_Print( " Delete all of the devices from the device list and issue new" ); " commands listed below.\n"
SampleUtil_Print( " search request to rebuild the list from scratch." ); " Refresh\n"
SampleUtil_Print( " PrintDev <devnum>" ); " Delete all of the devices from the device list and issue new\n"
SampleUtil_Print( " Print the state table for the device <devnum>." ); " search request to rebuild the list from scratch.\n"
SampleUtil_Print( " e.g., 'PrintDev 1' prints the state table for the first" ); " PrintDev <devnum>\n"
SampleUtil_Print( " device in the device list." ); " Print the state table for the device <devnum>.\n"
SampleUtil_Print( " PowerOn <devnum>" ); " e.g., 'PrintDev 1' prints the state table for the first\n"
SampleUtil_Print( " Sends the PowerOn action to the Control Service of" ); " device in the device list.\n"
SampleUtil_Print( " device <devnum>." ); " PowerOn <devnum>\n"
SampleUtil_Print( " PowerOff <devnum>" ); " Sends the PowerOn action to the Control Service of\n"
SampleUtil_Print( " Sends the PowerOff action to the Control Service of" ); " device <devnum>.\n"
SampleUtil_Print( " device <devnum>." ); " PowerOff <devnum>\n"
SampleUtil_Print( " SetChannel <devnum> <channel>" ); " Sends the PowerOff action to the Control Service of\n"
SampleUtil_Print( " Sends the SetChannel action to the Control Service of" ); " device <devnum>.\n"
SampleUtil_Print( " device <devnum>, requesting the channel to be changed" ); " SetChannel <devnum> <channel>\n"
SampleUtil_Print( " to <channel>." ); " Sends the SetChannel action to the Control Service of\n"
SampleUtil_Print( " SetVolume <devnum> <volume>" ); " device <devnum>, requesting the channel to be changed\n"
SampleUtil_Print( " Sends the SetVolume action to the Control Service of" ); " to <channel>.\n"
SampleUtil_Print( " device <devnum>, requesting the volume to be changed" ); " SetVolume <devnum> <volume>\n"
SampleUtil_Print( " to <volume>." ); " Sends the SetVolume action to the Control Service of\n"
SampleUtil_Print( " SetColor <devnum> <color>" ); " device <devnum>, requesting the volume to be changed\n"
SampleUtil_Print( " Sends the SetColor action to the Control Service of" ); " to <volume>.\n"
SampleUtil_Print( " device <devnum>, requesting the color to be changed" ); " SetColor <devnum> <color>\n"
SampleUtil_Print( " to <color>." ); " Sends the SetColor action to the Control Service of\n"
SampleUtil_Print( " SetTint <devnum> <tint>" ); " device <devnum>, requesting the color to be changed\n"
SampleUtil_Print( " Sends the SetTint action to the Control Service of" ); " to <color>.\n"
SampleUtil_Print( " device <devnum>, requesting the tint to be changed" ); " SetTint <devnum> <tint>\n"
SampleUtil_Print( " to <tint>." ); " Sends the SetTint action to the Control Service of\n"
SampleUtil_Print( " SetContrast <devnum> <contrast>" ); " device <devnum>, requesting the tint to be changed\n"
SampleUtil_Print( " Sends the SetContrast action to the Control Service of" ); " to <tint>.\n"
SampleUtil_Print( " device <devnum>, requesting the contrast to be changed" ); " SetContrast <devnum> <contrast>\n"
SampleUtil_Print( " to <contrast>." ); " Sends the SetContrast action to the Control Service of\n"
SampleUtil_Print( " SetBrightness <devnum> <brightness>" ); " device <devnum>, requesting the contrast to be changed\n"
SampleUtil_Print( " Sends the SetBrightness action to the Control Service of" ); " to <contrast>.\n"
SampleUtil_Print( " device <devnum>, requesting the brightness to be changed" ); " SetBrightness <devnum> <brightness>\n"
SampleUtil_Print( " to <brightness>." ); " Sends the SetBrightness action to the Control Service of\n"
SampleUtil_Print( " CtrlAction <devnum> <action>" ); " device <devnum>, requesting the brightness to be changed\n"
SampleUtil_Print( " Sends an action request specified by the string <action>" ); " to <brightness>.\n"
SampleUtil_Print( " to the Control Service of device <devnum>. This command" ); " CtrlAction <devnum> <action>\n"
SampleUtil_Print( " only works for actions that have no arguments." ); " Sends an action request specified by the string <action>\n"
SampleUtil_Print( " (e.g., \"CtrlAction 1 IncreaseChannel\")" ); " to the Control Service of device <devnum>. This command\n"
SampleUtil_Print( " PictAction <devnum> <action>" ); " only works for actions that have no arguments.\n"
SampleUtil_Print( " Sends an action request specified by the string <action>" ); " (e.g., \"CtrlAction 1 IncreaseChannel\")\n"
SampleUtil_Print( " to the Picture Service of device <devnum>. This command" ); " PictAction <devnum> <action>\n"
SampleUtil_Print( " only works for actions that have no arguments." ); " Sends an action request specified by the string <action>\n"
SampleUtil_Print( " (e.g., \"PictAction 1 DecreaseContrast\")" ); " to the Picture Service of device <devnum>. This command\n"
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" ); " only works for actions that have no arguments.\n"
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" ); " (e.g., \"PictAction 1 DecreaseContrast\")\n"
SampleUtil_Print( " from the Control Service of device <devnum>." ); " CtrlGetVar <devnum> <varname>\n"
SampleUtil_Print( " (e.g., \"CtrlGetVar 1 Volume\")" ); " Requests the value of a variable specified by the string <varname>\n"
SampleUtil_Print( " PictGetVar <devnum> <action>" ); " from the Control Service of device <devnum>.\n"
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" ); " (e.g., \"CtrlGetVar 1 Volume\")\n"
SampleUtil_Print( " from the Picture Service of device <devnum>." ); " PictGetVar <devnum> <action>\n"
SampleUtil_Print( " (e.g., \"PictGetVar 1 Tint\")" ); " Requests the value of a variable specified by the string <varname>\n"
SampleUtil_Print( " Exit" ); " from the Picture Service of device <devnum>.\n"
SampleUtil_Print( " Exits the control point application." ); " (e.g., \"PictGetVar 1 Tint\")\n"
" Exit\n"
" Exits the control point application.\n");
} }
/******************************************************************************** /*!
* TvCtrlPointPrintCommands * \briefPrint the list of valid command line commands to the user
* */
* Description: void TvCtrlPointPrintCommands()
* Print the list of valid command line commands to the user
*
* Parameters:
* None
*
********************************************************************************/
void
TvCtrlPointPrintCommands()
{ {
int i; int i;
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands ); int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
SampleUtil_Print( "Valid Commands:" ); SampleUtil_Print("Valid Commands:\n");
for( i = 0; i < numofcmds; i++ ) { for (i = 0; i < numofcmds; ++i) {
SampleUtil_Print( " %-14s %s", cmdloop_cmdlist[i].str, SampleUtil_Print(" %-14s %s\n",
cmdloop_cmdlist[i].args ); cmdloop_cmdlist[i].str, cmdloop_cmdlist[i].args);
} }
SampleUtil_Print( "" ); SampleUtil_Print("\n");
} }
/******************************************************************************** /*!
* TvCtrlPointCommandLoop * \brief Function that receives commands from the user at the command prompt
* * during the lifetime of the device, and calls the appropriate
* Description: * functions for those commands.
* Function that receives commands from the user at the command prompt */
* during the lifetime of the control point, and calls the appropriate void *TvCtrlPointCommandLoop(void *args)
* functions for those commands.
*
* Parameters:
* None
*
********************************************************************************/
void *
TvCtrlPointCommandLoop( void *args )
{ {
char cmdline[100]; char cmdline[100];
while( 1 ) { while (1) {
SampleUtil_Print( "\n>> " ); SampleUtil_Print("\n>> ");
fgets( cmdline, 100, stdin ); fgets(cmdline, 100, stdin);
TvCtrlPointProcessCommand( cmdline ); TvCtrlPointProcessCommand(cmdline);
} }
return NULL; return NULL;
args = args;
} }
int int TvCtrlPointProcessCommand(char *cmdline)
TvCtrlPointProcessCommand( char *cmdline )
{ {
char cmd[100]; char cmd[100];
char strarg[100]; char strarg[100];
int arg_val_err = -99999; int arg_val_err = -99999;
int arg1 = arg_val_err; int arg1 = arg_val_err;
int arg2 = arg_val_err; int arg2 = arg_val_err;
int cmdnum = -1; int cmdnum = -1;
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands ); int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
int cmdfound = 0; int cmdfound = 0;
int i, int i;
rc; int rc;
int invalidargs = 0; int invalidargs = 0;
int validargs; int validargs;
validargs = sscanf( cmdline, "%s %d %d", cmd, &arg1, &arg2 ); validargs = sscanf(cmdline, "%s %d %d", cmd, &arg1, &arg2);
for (i = 0; i < numofcmds; ++i) {
if (strcasecmp(cmd, cmdloop_cmdlist[i].str ) == 0) {
cmdnum = cmdloop_cmdlist[i].cmdnum;
cmdfound++;
if (validargs != cmdloop_cmdlist[i].numargs)
invalidargs++;
break;
}
}
if (!cmdfound) {
SampleUtil_Print("Command not found; try 'Help'\n");
return TV_SUCCESS;
}
if (invalidargs) {
SampleUtil_Print("Invalid arguments; try 'Help'\n");
return TV_SUCCESS;
}
switch (cmdnum) {
case PRTHELP:
TvCtrlPointPrintShortHelp();
break;
case PRTFULLHELP:
TvCtrlPointPrintLongHelp();
break;
case POWON:
TvCtrlPointSendPowerOn(arg1);
break;
case POWOFF:
TvCtrlPointSendPowerOff(arg1);
break;
case SETCHAN:
TvCtrlPointSendSetChannel(arg1, arg2);
break;
case SETVOL:
TvCtrlPointSendSetVolume(arg1, arg2);
break;
case SETCOL:
TvCtrlPointSendSetColor(arg1, arg2);
break;
case SETTINT:
TvCtrlPointSendSetTint(arg1, arg2);
break;
case SETCONT:
TvCtrlPointSendSetContrast(arg1, arg2);
break;
case SETBRT:
TvCtrlPointSendSetBrightness(arg1, arg2);
break;
case CTRLACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_CONTROL, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case PICTACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_PICTURE, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case CTRLGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_CONTROL, arg1, strarg);
else
invalidargs++;
break;
case PICTGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_PICTURE, arg1, strarg);
else
invalidargs++;
break;
case PRTDEV:
TvCtrlPointPrintDevice(arg1);
break;
case LSTDEV:
TvCtrlPointPrintList();
break;
case REFRESH:
TvCtrlPointRefresh();
break;
case EXITCMD:
rc = TvCtrlPointStop();
exit(rc);
break;
default:
SampleUtil_Print("Command not implemented; see 'Help'\n");
break;
}
if(invalidargs)
SampleUtil_Print("Invalid args in command; see 'Help'\n");
for( i = 0; i < numofcmds; i++ ) { return TV_SUCCESS;
if( strcasecmp( cmd, cmdloop_cmdlist[i].str ) == 0 ) {
cmdnum = cmdloop_cmdlist[i].cmdnum;
cmdfound++;
if( validargs != cmdloop_cmdlist[i].numargs )
invalidargs++;
break;
}
}
if( !cmdfound ) {
SampleUtil_Print( "Command not found; try 'Help'" );
return TV_SUCCESS;
}
if( invalidargs ) {
SampleUtil_Print( "Invalid arguments; try 'Help'" );
return TV_SUCCESS;
}
switch ( cmdnum ) {
case PRTHELP:
TvCtrlPointPrintShortHelp();
break;
case PRTFULLHELP:
TvCtrlPointPrintLongHelp();
break;
case POWON:
TvCtrlPointSendPowerOn( arg1 );
break;
case POWOFF:
TvCtrlPointSendPowerOff( arg1 );
break;
case SETCHAN:
TvCtrlPointSendSetChannel( arg1, arg2 );
break;
case SETVOL:
TvCtrlPointSendSetVolume( arg1, arg2 );
break;
case SETCOL:
TvCtrlPointSendSetColor( arg1, arg2 );
break;
case SETTINT:
TvCtrlPointSendSetTint( arg1, arg2 );
break;
case SETCONT:
TvCtrlPointSendSetContrast( arg1, arg2 );
break;
case SETBRT:
TvCtrlPointSendSetBrightness( arg1, arg2 );
break;
case CTRLACTION:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointSendAction( TV_SERVICE_CONTROL, arg1, strarg,
NULL, NULL, 0 );
else
invalidargs++;
break;
case PICTACTION:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointSendAction( TV_SERVICE_PICTURE, arg1, strarg,
NULL, NULL, 0 );
else
invalidargs++;
break;
case CTRLGETVAR:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointGetVar( TV_SERVICE_CONTROL, arg1, strarg );
else
invalidargs++;
break;
case PICTGETVAR:
/*
re-parse commandline since second arg is string
*/
validargs = sscanf( cmdline, "%s %d %s", cmd, &arg1, strarg );
if( 3 == validargs )
TvCtrlPointGetVar( TV_SERVICE_PICTURE, arg1, strarg );
else
invalidargs++;
break;
case PRTDEV:
TvCtrlPointPrintDevice( arg1 );
break;
case LSTDEV:
TvCtrlPointPrintList();
break;
case REFRESH:
TvCtrlPointRefresh();
break;
case EXITCMD:
rc = TvCtrlPointStop();
exit( rc );
break;
default:
SampleUtil_Print( "Command not implemented; see 'Help'" );
break;
}
if( invalidargs )
SampleUtil_Print( "Invalid args in command; see 'Help'" );
return TV_SUCCESS;
} }
int main( int argc, char **argv ) int main(int argc, char **argv)
{ {
int rc; int rc;
ithread_t cmdloop_thread; ithread_t cmdloop_thread;
#ifdef WIN32 #ifdef WIN32
#else #else
int sig; int sig;
sigset_t sigs_to_catch; sigset_t sigs_to_catch;
#endif #endif
int code; int code;
rc = TvCtrlPointStart( linux_print, NULL );
if( rc != TV_SUCCESS ) {
SampleUtil_Print( "Error starting UPnP TV Control Point" );
return rc;
}
/* start a command loop thread */
code = ithread_create( &cmdloop_thread, NULL, TvCtrlPointCommandLoop, NULL );
rc = TvCtrlPointStart(linux_print, NULL);
if (rc != TV_SUCCESS) {
SampleUtil_Print("Error starting UPnP TV Control Point\n");
return rc;
}
/* start a command loop thread */
code = ithread_create(&cmdloop_thread, NULL, TvCtrlPointCommandLoop, NULL);
#ifdef WIN32 #ifdef WIN32
ithread_join(cmdloop_thread, NULL); ithread_join(cmdloop_thread, NULL);
#else #else
/* /* Catch Ctrl-C and properly shutdown */
Catch Ctrl-C and properly shutdown sigemptyset(&sigs_to_catch);
*/ sigaddset(&sigs_to_catch, SIGINT);
sigemptyset( &sigs_to_catch ); sigwait(&sigs_to_catch, &sig);
sigaddset( &sigs_to_catch, SIGINT ); SampleUtil_Print("Shutting down on signal %d...\n", sig);
sigwait( &sigs_to_catch, &sig );
SampleUtil_Print( "Shutting down on signal %d...\n", sig );
#endif #endif
rc = TvCtrlPointStop();
rc = TvCtrlPointStop(); return rc;
argc = argc;
return rc; argv = argv;
} }

View File

@ -94,7 +94,7 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
var; var;
if( NULL == node ) { if( NULL == node ) {
SampleUtil_Print( "ERROR: TvCtrlPointDeleteNode: Node is empty" ); SampleUtil_Print("ERROR: TvCtrlPointDeleteNode: Node is empty\n");
return TV_ERROR; return TV_ERROR;
} }
@ -107,12 +107,12 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
node->device.TvService[service].SID ); node->device.TvService[service].SID );
if( UPNP_E_SUCCESS == rc ) { if( UPNP_E_SUCCESS == rc ) {
SampleUtil_Print SampleUtil_Print
( "Unsubscribed from Tv %s EventURL with SID=%s", ( "Unsubscribed from Tv %s EventURL with SID=%s\n",
TvServiceName[service], TvServiceName[service],
node->device.TvService[service].SID ); node->device.TvService[service].SID );
} else { } else {
SampleUtil_Print SampleUtil_Print
( "Error unsubscribing to Tv %s EventURL -- %d", ( "Error unsubscribing to Tv %s EventURL -- %d\n",
TvServiceName[service], rc ); TvServiceName[service], rc );
} }
} }
@ -152,8 +152,7 @@ int TvCtrlPointRemoveDevice(const char *UDN)
curdevnode = GlobalDeviceList; curdevnode = GlobalDeviceList;
if( !curdevnode ) { if( !curdevnode ) {
SampleUtil_Print SampleUtil_Print("WARNING: TvCtrlPointRemoveDevice: Device list empty\n");
( "WARNING: TvCtrlPointRemoveDevice: Device list empty" );
} else { } else {
if( 0 == strcmp( curdevnode->device.UDN, UDN ) ) { if( 0 == strcmp( curdevnode->device.UDN, UDN ) ) {
GlobalDeviceList = curdevnode->next; GlobalDeviceList = curdevnode->next;
@ -236,7 +235,7 @@ TvCtrlPointRefresh( void )
*/ */
rc = UpnpSearchAsync( ctrlpt_handle, 5, TvDeviceType, NULL ); rc = UpnpSearchAsync( ctrlpt_handle, 5, TvDeviceType, NULL );
if( UPNP_E_SUCCESS != rc ) { if( UPNP_E_SUCCESS != rc ) {
SampleUtil_Print( "Error sending search request%d", rc ); SampleUtil_Print("Error sending search request%d\n", rc);
return TV_ERROR; return TV_ERROR;
} }
@ -256,10 +255,7 @@ TvCtrlPointRefresh( void )
* varname -- The name of the variable to request. * varname -- The name of the variable to request.
* *
********************************************************************************/ ********************************************************************************/
int int TvCtrlPointGetVar(int service, int devnum, const char *varname)
TvCtrlPointGetVar( int service,
int devnum,
char *varname )
{ {
struct TvDeviceNode *devnode; struct TvDeviceNode *devnode;
int rc; int rc;
@ -276,8 +272,7 @@ TvCtrlPointGetVar( int service,
TvCtrlPointCallbackEventHandler, TvCtrlPointCallbackEventHandler,
NULL ); NULL );
if( rc != UPNP_E_SUCCESS ) { if( rc != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print("Error in UpnpGetServiceVarStatusAsync -- %d\n", rc);
( "Error in UpnpGetServiceVarStatusAsync -- %d", rc );
rc = TV_ERROR; rc = TV_ERROR;
} }
} }
@ -345,13 +340,13 @@ TvCtrlPointGetBrightness( int devnum )
* param_count -- The number of parameters * param_count -- The number of parameters
* *
********************************************************************************/ ********************************************************************************/
int int TvCtrlPointSendAction(
TvCtrlPointSendAction( int service, int service,
int devnum, int devnum,
char *actionname, const char *actionname,
char **param_name, const char **param_name,
char **param_val, char **param_val,
int param_count ) int param_count)
{ {
struct TvDeviceNode *devnode; struct TvDeviceNode *devnode;
IXML_Document *actionNode = NULL; IXML_Document *actionNode = NULL;
@ -372,8 +367,7 @@ TvCtrlPointSendAction( int service,
( &actionNode, actionname, TvServiceType[service], ( &actionNode, actionname, TvServiceType[service],
param_name[param], param_name[param],
param_val[param] ) != UPNP_E_SUCCESS ) { param_val[param] ) != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print("ERROR: TvCtrlPointSendAction: Trying to add action param\n");
( "ERROR: TvCtrlPointSendAction: Trying to add action param" );
/*return -1; // TBD - BAD! leaves mutex locked */ /*return -1; // TBD - BAD! leaves mutex locked */
} }
} }
@ -386,7 +380,7 @@ TvCtrlPointSendAction( int service,
TvCtrlPointCallbackEventHandler, NULL ); TvCtrlPointCallbackEventHandler, NULL );
if( rc != UPNP_E_SUCCESS ) { if( rc != UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error in UpnpSendActionAsync -- %d", rc ); SampleUtil_Print( "Error in UpnpSendActionAsync -- %d\n", rc );
rc = TV_ERROR; rc = TV_ERROR;
} }
} }
@ -415,8 +409,8 @@ TvCtrlPointSendAction( int service,
int int
TvCtrlPointSendActionNumericArg( int devnum, TvCtrlPointSendActionNumericArg( int devnum,
int service, int service,
char *actionName, const char *actionName,
char *paramName, const char *paramName,
int paramValue ) int paramValue )
{ {
char param_val_a[50]; char param_val_a[50];
@ -524,7 +518,7 @@ TvCtrlPointGetDevice( int devnum,
} }
if( !tmpdevnode ) { if( !tmpdevnode ) {
SampleUtil_Print( "Error finding TvDevice number -- %d", devnum ); SampleUtil_Print( "Error finding TvDevice number -- %d\n", devnum );
return TV_ERROR; return TV_ERROR;
} }
@ -550,13 +544,13 @@ TvCtrlPointPrintList()
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
SampleUtil_Print( "TvCtrlPointPrintList:" ); SampleUtil_Print("TvCtrlPointPrintList:\n");
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
SampleUtil_Print( " %3d -- %s", ++i, tmpdevnode->device.UDN ); SampleUtil_Print( " %3d -- %s\n", ++i, tmpdevnode->device.UDN );
tmpdevnode = tmpdevnode->next; tmpdevnode = tmpdevnode->next;
} }
SampleUtil_Print( "" ); SampleUtil_Print("\n");
ithread_mutex_unlock( &DeviceListMutex ); ithread_mutex_unlock( &DeviceListMutex );
return TV_SUCCESS; return TV_SUCCESS;
@ -584,15 +578,13 @@ TvCtrlPointPrintDevice( int devnum )
char spacer[15]; char spacer[15];
if( devnum <= 0 ) { if( devnum <= 0 ) {
SampleUtil_Print SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d\n", devnum);
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d",
devnum );
return TV_ERROR; return TV_ERROR;
} }
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
SampleUtil_Print( "TvCtrlPointPrintDevice:" ); SampleUtil_Print("TvCtrlPointPrintDevice:\n");
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
i++; i++;
@ -602,57 +594,35 @@ TvCtrlPointPrintDevice( int devnum )
} }
if( !tmpdevnode ) { if( !tmpdevnode ) {
SampleUtil_Print SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d\n", devnum, i);
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d",
devnum, i );
} else { } else {
SampleUtil_Print( " TvDevice -- %d", devnum ); SampleUtil_Print(" TvDevice -- %d\n", devnum);
SampleUtil_Print( " | " ); SampleUtil_Print(" | \n");
SampleUtil_Print( " +- UDN = %s", SampleUtil_Print(" +- UDN = %s\n" , tmpdevnode->device.UDN);
tmpdevnode->device.UDN ); SampleUtil_Print(" +- DescDocURL = %s\n", tmpdevnode->device.DescDocURL);
SampleUtil_Print( " +- DescDocURL = %s", SampleUtil_Print(" +- FriendlyName = %s\n", tmpdevnode->device.FriendlyName);
tmpdevnode->device.DescDocURL ); SampleUtil_Print(" +- PresURL = %s\n", tmpdevnode->device.PresURL);
SampleUtil_Print( " +- FriendlyName = %s", SampleUtil_Print(" +- Adver. TimeOut = %d\n", tmpdevnode->device.AdvrTimeOut);
tmpdevnode->device.FriendlyName );
SampleUtil_Print( " +- PresURL = %s",
tmpdevnode->device.PresURL );
SampleUtil_Print( " +- Adver. TimeOut = %d",
tmpdevnode->device.AdvrTimeOut );
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( service < TV_SERVICE_SERVCOUNT - 1 ) if(service < TV_SERVICE_SERVCOUNT - 1)
sprintf( spacer, " | " ); sprintf(spacer, " | ");
else else
sprintf( spacer, " " ); sprintf(spacer, " ");
SampleUtil_Print( " | " ); SampleUtil_Print(" | ");
SampleUtil_Print( " +- Tv %s Service", SampleUtil_Print(" +- Tv %s Service", TvServiceName[service]);
TvServiceName[service] ); SampleUtil_Print("%s+- ServiceId = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceId);
SampleUtil_Print( "%s+- ServiceId = %s", spacer, SampleUtil_Print("%s+- ServiceType = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceType);
tmpdevnode->device.TvService[service]. SampleUtil_Print("%s+- EventURL = %s\n", spacer, tmpdevnode->device.TvService[service].EventURL);
ServiceId ); SampleUtil_Print("%s+- ControlURL = %s\n", spacer, tmpdevnode->device.TvService[service].ControlURL);
SampleUtil_Print( "%s+- ServiceType = %s", spacer, SampleUtil_Print("%s+- SID = %s\n", spacer, tmpdevnode->device.TvService[service].SID);
tmpdevnode->device.TvService[service]. SampleUtil_Print("%s+- ServiceStateTable", spacer);
ServiceType );
SampleUtil_Print( "%s+- EventURL = %s", spacer,
tmpdevnode->device.TvService[service].
EventURL );
SampleUtil_Print( "%s+- ControlURL = %s", spacer,
tmpdevnode->device.TvService[service].
ControlURL );
SampleUtil_Print( "%s+- SID = %s", spacer,
tmpdevnode->device.TvService[service].SID );
SampleUtil_Print( "%s+- ServiceStateTable", spacer );
for( var = 0; var < TvVarCount[service]; var++ ) { for( var = 0; var < TvVarCount[service]; var++ ) {
SampleUtil_Print( "%s +- %-10s = %s", spacer, SampleUtil_Print("%s +- %-10s = %s\n", spacer, TvVarName[service][var],
TvVarName[service][var], tmpdevnode->device.TvService[service].VariableStrVal[var]);
tmpdevnode->device.TvService[service].
VariableStrVal[var] );
} }
} }
} }
SampleUtil_Print("\n");
SampleUtil_Print( "" );
ithread_mutex_unlock( &DeviceListMutex ); ithread_mutex_unlock( &DeviceListMutex );
return TV_SUCCESS; return TV_SUCCESS;
@ -710,11 +680,10 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
( baseURL ? baseURL : location ), relURL, presURL); ( baseURL ? baseURL : location ), relURL, presURL);
if( UPNP_E_SUCCESS != ret ) if( UPNP_E_SUCCESS != ret )
SampleUtil_Print( "Error generating presURL from %s + %s", baseURL, SampleUtil_Print( "Error generating presURL from %s + %s\n", baseURL, relURL );
relURL );
if( strcmp( deviceType, TvDeviceType ) == 0 ) { if( strcmp( deviceType, TvDeviceType ) == 0 ) {
SampleUtil_Print( "Found Tv device" ); SampleUtil_Print("Found Tv device\n");
/* Check if this device is already in the list */ /* Check if this device is already in the list */
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
@ -732,45 +701,29 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
tmpdevnode->device.AdvrTimeOut = expires; tmpdevnode->device.AdvrTimeOut = expires;
} else { } else {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( SampleUtil_FindAndParseService if( SampleUtil_FindAndParseService(DescDoc, location, TvServiceType[service],
( DescDoc, location, TvServiceType[service],
&serviceId[service], &eventURL[service], &serviceId[service], &eventURL[service],
&controlURL[service] ) ) { &controlURL[service])) {
SampleUtil_Print( "Subscribing to EventURL %s...", SampleUtil_Print("Subscribing to EventURL %s...\n", eventURL[service]);
eventURL[service] ); ret = UpnpSubscribe(ctrlpt_handle, eventURL[service],
&TimeOut[service], eventSID[service]);
ret =
UpnpSubscribe( ctrlpt_handle, eventURL[service],
&TimeOut[service],
eventSID[service] );
if( ret == UPNP_E_SUCCESS ) { if( ret == UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print("Subscribed to EventURL with SID=%s\n", eventSID[service]);
( "Subscribed to EventURL with SID=%s",
eventSID[service] );
} else { } else {
SampleUtil_Print SampleUtil_Print("Error Subscribing to EventURL -- %d\n", ret);
( "Error Subscribing to EventURL -- %d", ret ); strcpy(eventSID[service], "");
strcpy( eventSID[service], "" );
} }
} else { } else {
SampleUtil_Print( "Error: Could not find Service: %s", SampleUtil_Print("Error: Could not find Service: %s\n", TvServiceType[service]);
TvServiceType[service] );
} }
} }
/* Create a new device node */
/* deviceNode = (struct TvDeviceNode *)malloc(sizeof(struct TvDeviceNode));
Create a new device node
*/
deviceNode =
( struct TvDeviceNode * )
malloc( sizeof( struct TvDeviceNode ) );
strcpy( deviceNode->device.UDN, UDN ); strcpy( deviceNode->device.UDN, UDN );
strcpy( deviceNode->device.DescDocURL, location ); strcpy( deviceNode->device.DescDocURL, location );
strcpy( deviceNode->device.FriendlyName, friendlyName ); strcpy( deviceNode->device.FriendlyName, friendlyName );
strcpy( deviceNode->device.PresURL, presURL ); strcpy( deviceNode->device.PresURL, presURL );
deviceNode->device.AdvrTimeOut = expires; deviceNode->device.AdvrTimeOut = expires;
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
strcpy( deviceNode->device.TvService[service].ServiceId, strcpy( deviceNode->device.TvService[service].ServiceId,
serviceId[service] ); serviceId[service] );
@ -782,7 +735,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
eventURL[service] ); eventURL[service] );
strcpy( deviceNode->device.TvService[service].SID, strcpy( deviceNode->device.TvService[service].SID,
eventSID[service] ); eventSID[service] );
for( var = 0; var < TvVarCount[service]; var++ ) { for( var = 0; var < TvVarCount[service]; var++ ) {
deviceNode->device.TvService[service]. deviceNode->device.TvService[service].
VariableStrVal[var] = VariableStrVal[var] =
@ -791,12 +743,9 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
VariableStrVal[var], "" ); VariableStrVal[var], "" );
} }
} }
deviceNode->next = NULL; deviceNode->next = NULL;
/* Insert the new device node in the list */ /* Insert the new device node in the list */
if( ( tmpdevnode = GlobalDeviceList ) ) { if( ( tmpdevnode = GlobalDeviceList ) ) {
while( tmpdevnode ) { while( tmpdevnode ) {
if( tmpdevnode->next ) { if( tmpdevnode->next ) {
tmpdevnode = tmpdevnode->next; tmpdevnode = tmpdevnode->next;
@ -808,10 +757,8 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
} else { } else {
GlobalDeviceList = deviceNode; GlobalDeviceList = deviceNode;
} }
/*Notify New Device Added */ /*Notify New Device Added */
SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN, SampleUtil_StateUpdate(NULL, NULL, deviceNode->device.UDN, DEVICE_ADDED);
DEVICE_ADDED );
} }
} }
@ -827,7 +774,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
free( baseURL ); free( baseURL );
if( relURL ) if( relURL )
free( relURL ); free( relURL );
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( serviceId[service] ) if( serviceId[service] )
free( serviceId[service] ); free( serviceId[service] );
@ -871,33 +817,23 @@ TvStateUpdate( char *UDN,
j; j;
char *tmpstate = NULL; char *tmpstate = NULL;
SampleUtil_Print( "Tv State Update (service %d): ", Service ); SampleUtil_Print( "Tv State Update (service %d):\n", Service );
/* Find all of the e:property tags in the document */
/* properties = ixmlDocument_getElementsByTagName(
Find all of the e:property tags in the document ChangedVariables, "e:property" );
*/
properties =
ixmlDocument_getElementsByTagName( ChangedVariables,
"e:property" );
if( NULL != properties ) { if( NULL != properties ) {
length = ixmlNodeList_length( properties ); length = ixmlNodeList_length( properties );
for( i = 0; i < length; i++ ) { /* Loop through each property change found */ for( i = 0; i < length; i++ ) { /* Loop through each property change found */
property = property =
( IXML_Element * ) ixmlNodeList_item( properties, i ); ( IXML_Element * ) ixmlNodeList_item( properties, i );
/* For each variable name in the state table, check if this
/* * is a corresponding property change */
For each variable name in the state table, check if this
is a corresponding property change
*/
for( j = 0; j < TvVarCount[Service]; j++ ) { for( j = 0; j < TvVarCount[Service]; j++ ) {
variables = variables =
ixmlElement_getElementsByTagName( property, ixmlElement_getElementsByTagName( property,
TvVarName[Service] TvVarName[Service]
[j] ); [j] );
/* If a match is found, extract the value, and update the state table */
/*
If a match is found, extract the value, and update the state table
*/
if( variables ) { if( variables ) {
length1 = ixmlNodeList_length( variables ); length1 = ixmlNodeList_length( variables );
if( length1 ) { if( length1 ) {
@ -908,21 +844,16 @@ TvStateUpdate( char *UDN,
if( tmpstate ) { if( tmpstate ) {
strcpy( State[j], tmpstate ); strcpy( State[j], tmpstate );
SampleUtil_Print SampleUtil_Print(" Variable Name: %s New Value:'%s'\n", TvVarName[Service][j], State[j] );
( " Variable Name: %s New Value:'%s'",
TvVarName[Service][j], State[j] );
} }
if( tmpstate ) if( tmpstate )
free( tmpstate ); free( tmpstate );
tmpstate = NULL; tmpstate = NULL;
} }
ixmlNodeList_free( variables ); ixmlNodeList_free( variables );
variables = NULL; variables = NULL;
} }
} }
} }
ixmlNodeList_free( properties ); ixmlNodeList_free( properties );
} }
@ -955,7 +886,7 @@ void TvCtrlPointHandleEvent(
while (tmpdevnode) { while (tmpdevnode) {
for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) { for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) {
if (strcmp(tmpdevnode->device.TvService[service].SID, sid) == 0) { if (strcmp(tmpdevnode->device.TvService[service].SID, sid) == 0) {
SampleUtil_Print("Received Tv %s Event: %d for SID %s", SampleUtil_Print("Received Tv %s Event: %d for SID %s\n",
TvServiceName[service], TvServiceName[service],
evntkey, evntkey,
sid); sid);
@ -1000,13 +931,10 @@ void TvCtrlPointHandleSubscribeUpdate(
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( strcmp if( strcmp
( tmpdevnode->device.TvService[service].EventURL, ( tmpdevnode->device.TvService[service].EventURL,
eventURL ) == 0 ) { eventURL ) == 0 ) {
SampleUtil_Print SampleUtil_Print("Received Tv %s Event Renewal for eventURL %s\n", TvServiceName[service], eventURL );
( "Received Tv %s Event Renewal for eventURL %s",
TvServiceName[service], eventURL );
strcpy( tmpdevnode->device.TvService[service].SID, sid ); strcpy( tmpdevnode->device.TvService[service].SID, sid );
break; break;
} }
@ -1074,14 +1002,14 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Discovery Callback -- %d", errCode); "Error in Discovery Callback -- %d\n", errCode);
} }
location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event)); location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event));
errCode = UpnpDownloadXmlDoc(location, &DescDoc); errCode = UpnpDownloadXmlDoc(location, &DescDoc);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error obtaining device description from %s -- error = %d", "Error obtaining device description from %s -- error = %d\n",
location, errCode); location, errCode);
} else { } else {
TvCtrlPointAddDevice( TvCtrlPointAddDevice(
@ -1104,11 +1032,11 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Discovery ByeBye Callback -- %d", errCode); "Error in Discovery ByeBye Callback -- %d\n", errCode);
} }
SampleUtil_Print("Received ByeBye for Device: %s", deviceId); SampleUtil_Print("Received ByeBye for Device: %s\n", deviceId);
TvCtrlPointRemoveDevice(deviceId); TvCtrlPointRemoveDevice(deviceId);
SampleUtil_Print("After byebye:"); SampleUtil_Print("After byebye:\n");
TvCtrlPointPrintList(); TvCtrlPointPrintList();
break; break;
} }
@ -1117,8 +1045,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
UpnpActionComplete *a_event = (UpnpActionComplete *)Event; UpnpActionComplete *a_event = (UpnpActionComplete *)Event;
int errCode = UpnpActionComplete_get_ErrCode(a_event); int errCode = UpnpActionComplete_get_ErrCode(a_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print("Error in Action Complete Callback -- %d\n",
"Error in Action Complete Callback -- %d",
errCode); errCode);
} }
/* No need for any processing here, just print out results. /* No need for any processing here, just print out results.
@ -1130,7 +1057,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
int errCode = UpnpStateVarComplete_get_ErrCode(sv_event); int errCode = UpnpStateVarComplete_get_ErrCode(sv_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Get Var Complete Callback -- %d", errCode); "Error in Get Var Complete Callback -- %d\n", errCode);
} else { } else {
TvCtrlPointHandleGetVar( TvCtrlPointHandleGetVar(
UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)), UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)),
@ -1156,7 +1083,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
errCode = UpnpEventSubscribe_get_ErrCode(es_event); errCode = UpnpEventSubscribe_get_ErrCode(es_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Event Subscribe Callback -- %d", errCode); "Error in Event Subscribe Callback -- %d\n", errCode);
} else { } else {
TvCtrlPointHandleSubscribeUpdate( TvCtrlPointHandleSubscribeUpdate(
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)), UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
@ -1177,13 +1104,13 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
&TimeOut, &TimeOut,
newSID); newSID);
if (errCode == UPNP_E_SUCCESS) { if (errCode == UPNP_E_SUCCESS) {
SampleUtil_Print("Subscribed to EventURL with SID=%s", newSID); SampleUtil_Print("Subscribed to EventURL with SID=%s\n", newSID);
TvCtrlPointHandleSubscribeUpdate( TvCtrlPointHandleSubscribeUpdate(
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)), UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
newSID, newSID,
TimeOut); TimeOut);
} else { } else {
SampleUtil_Print("Error Subscribing to EventURL -- %d", errCode); SampleUtil_Print("Error Subscribing to EventURL -- %d\n", errCode);
} }
break; break;
} }
@ -1253,18 +1180,14 @@ TvCtrlPointVerifyTimeouts( int incr )
ret = UpnpSearchAsync( ctrlpt_handle, incr, ret = UpnpSearchAsync( ctrlpt_handle, incr,
curdevnode->device.UDN, NULL ); curdevnode->device.UDN, NULL );
if( ret != UPNP_E_SUCCESS ) if( ret != UPNP_E_SUCCESS )
SampleUtil_Print SampleUtil_Print("Error sending search request for Device UDN: %s -- err = %d\n",
( "Error sending search request for Device UDN: %s -- err = %d",
curdevnode->device.UDN, ret ); curdevnode->device.UDN, ret );
} }
prevdevnode = curdevnode; prevdevnode = curdevnode;
curdevnode = curdevnode->next; curdevnode = curdevnode->next;
} }
} }
ithread_mutex_unlock( &DeviceListMutex ); ithread_mutex_unlock( &DeviceListMutex );
} }
/******************************************************************************** /********************************************************************************
@ -1326,7 +1249,7 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
rc = UpnpInit(ip_address, port); rc = UpnpInit(ip_address, port);
if (rc != UPNP_E_SUCCESS) { if (rc != UPNP_E_SUCCESS) {
SampleUtil_Print("WinCEStart: UpnpInit() Error: %d", rc); SampleUtil_Print("WinCEStart: UpnpInit() Error: %d\n", rc);
UpnpFinish(); UpnpFinish();
return TV_ERROR; return TV_ERROR;
} }
@ -1342,18 +1265,17 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
"\tipaddress = %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address ? ip_address : "{NULL}", ip_address ? ip_address : "{NULL}",
port); port);
SampleUtil_Print("Registering Control Point\n");
SampleUtil_Print("Registering Control Point");
rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler, rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler,
&ctrlpt_handle, &ctrlpt_handle); &ctrlpt_handle, &ctrlpt_handle);
if (rc != UPNP_E_SUCCESS) { if (rc != UPNP_E_SUCCESS) {
SampleUtil_Print( "Error registering CP: %d", rc ); SampleUtil_Print( "Error registering CP: %d\n", rc );
UpnpFinish(); UpnpFinish();
return TV_ERROR; return TV_ERROR;
} }
SampleUtil_Print("Control Point Registered"); SampleUtil_Print("Control Point Registered\n");
TvCtrlPointRefresh(); TvCtrlPointRefresh();

View File

@ -128,8 +128,8 @@ int TvCtrlPointRemoveAll(void);
int TvCtrlPointRefresh(void); int TvCtrlPointRefresh(void);
int TvCtrlPointSendAction(int, int, char *, char **, char **, int); int TvCtrlPointSendAction(int, int, const char *, const char **, char **, int);
int TvCtrlPointSendActionNumericArg(int devnum, int service, char *actionName, char *paramName, int paramValue); int TvCtrlPointSendActionNumericArg(int devnum, int service, const char *actionName, const char *paramName, int paramValue);
int TvCtrlPointSendPowerOn(int devnum); int TvCtrlPointSendPowerOn(int devnum);
int TvCtrlPointSendPowerOff(int devnum); int TvCtrlPointSendPowerOff(int devnum);
int TvCtrlPointSendSetChannel(int, int); int TvCtrlPointSendSetChannel(int, int);
@ -139,7 +139,7 @@ int TvCtrlPointSendSetTint(int, int);
int TvCtrlPointSendSetContrast(int, int); int TvCtrlPointSendSetContrast(int, int);
int TvCtrlPointSendSetBrightness(int, int); int TvCtrlPointSendSetBrightness(int, int);
int TvCtrlPointGetVar(int, int, char*); int TvCtrlPointGetVar(int, int, const char *);
int TvCtrlPointGetPower(int devnum); int TvCtrlPointGetPower(int devnum);
int TvCtrlPointGetChannel(int); int TvCtrlPointGetChannel(int);
int TvCtrlPointGetVolume(int); int TvCtrlPointGetVolume(int);
@ -168,4 +168,5 @@ int TvCtrlPointProcessCommand(char *cmdline);
}; };
#endif #endif
#endif //UPNP_TV_CTRLPT_H #endif /* UPNP_TV_CTRLPT_H */

View File

@ -34,69 +34,56 @@
#include "upnp_tv_device.h" #include "upnp_tv_device.h"
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
/****************************************************************************** /*!
* linux_print * \brief Prints a string to standard out.
* */
* Description: void linux_print(const char *format, ...)
* Prints a string to standard out.
*
* Parameters:
* None
*
*****************************************************************************/
void
linux_print( const char *string )
{ {
printf( "%s", string ); va_list argList;
va_start(argList, format);
vfprintf(stdout, format, argList);
fflush(stdout);
va_end(argList);
} }
/****************************************************************************** /*!
* TvDeviceCommandLoop * \brief Function that receives commands from the user at the command prompt
* * during the lifetime of the device, and calls the appropriate
* Description: * functions for those commands. Only one command, exit, is currently
* Function that receives commands from the user at the command prompt * defined.
* during the lifetime of the device, and calls the appropriate */
* functions for those commands. Only one command, exit, is currently void *TvDeviceCommandLoop(void *args)
* defined.
*
* Parameters:
* None
*
*****************************************************************************/
void *
TvDeviceCommandLoop( void *args )
{ {
int stoploop = 0; int stoploop = 0;
char cmdline[100]; char cmdline[100];
char cmd[100]; char cmd[100];
while( !stoploop ) { while (!stoploop) {
sprintf( cmdline, " " ); sprintf( cmdline, " " );
sprintf( cmd, " " ); sprintf( cmd, " " );
SampleUtil_Print( "\n>> " ); SampleUtil_Print("\n>> ");
/* Get a command line */ /* Get a command line */
fgets( cmdline, 100, stdin ); fgets(cmdline, 100, stdin);
sscanf(cmdline, "%s", cmd);
sscanf( cmdline, "%s", cmd ); if( strcasecmp(cmd, "exit") == 0) {
SampleUtil_Print("Shutting down...\n");
if( strcasecmp( cmd, "exit" ) == 0 ) {
SampleUtil_Print( "Shutting down...\n" );
TvDeviceStop(); TvDeviceStop();
exit( 0 ); exit(0);
} else { } else {
SampleUtil_Print( "\n Unknown command: %s\n\n", cmd ); SampleUtil_Print("\n Unknown command: %s\n\n", cmd);
SampleUtil_Print( " Valid Commands:\n" ); SampleUtil_Print(" Valid Commands:\n");
SampleUtil_Print( " Exit\n\n" ); SampleUtil_Print(" Exit\n\n");
} }
} }
return NULL; return NULL;
args = args;
} }
/****************************************************************************** /******************************************************************************
@ -121,9 +108,8 @@ TvDeviceCommandLoop( void *args )
* *
* *
*****************************************************************************/ *****************************************************************************/
int main( IN int argc, IN char **argv ) int main(int argc, char **argv)
{ {
unsigned int portTemp = 0; unsigned int portTemp = 0;
char *ip_address = NULL, char *ip_address = NULL,
*desc_doc_name = NULL, *desc_doc_name = NULL,
@ -136,11 +122,10 @@ int main( IN int argc, IN char **argv )
sigset_t sigs_to_catch; sigset_t sigs_to_catch;
#endif #endif
int code; int code;
unsigned int port = 0; unsigned short port = 0;
int i = 0; int i = 0;
SampleUtil_Initialize( linux_print ); SampleUtil_Initialize(linux_print);
/* Parse options */ /* Parse options */
for( i = 1; i < argc; i++ ) { for( i = 1; i < argc; i++ ) {
if( strcmp( argv[i], "-ip" ) == 0 ) { if( strcmp( argv[i], "-ip" ) == 0 ) {
@ -171,20 +156,16 @@ int main( IN int argc, IN char **argv )
return 1; return 1;
} }
} }
port = (unsigned short)portTemp;
port = ( unsigned short )portTemp; TvDeviceStart(ip_address, port, desc_doc_name, web_dir_path, linux_print);
TvDeviceStart( ip_address, port, desc_doc_name, web_dir_path, linux_print );
/* start a command loop thread */ /* start a command loop thread */
code = ithread_create( &cmdloop_thread, NULL, TvDeviceCommandLoop, NULL ); code = ithread_create(&cmdloop_thread, NULL, TvDeviceCommandLoop, NULL);
#ifdef WIN32 #ifdef WIN32
ithread_join(cmdloop_thread, NULL); ithread_join(cmdloop_thread, NULL);
#else #else
/* /* Catch Ctrl-C and properly shutdown */
Catch Ctrl-C and properly shutdown
*/
sigemptyset( &sigs_to_catch ); sigemptyset( &sigs_to_catch );
sigaddset( &sigs_to_catch, SIGINT ); sigaddset( &sigs_to_catch, SIGINT );
sigwait( &sigs_to_catch, &sig ); sigwait( &sigs_to_catch, &sig );

View File

@ -116,7 +116,7 @@ static int SetServiceTable(
/*! [in,out] service containing table to be set. */ /*! [in,out] service containing table to be set. */
INOUT struct TvService *out) INOUT struct TvService *out)
{ {
unsigned int i = 0; int i = 0;
strcpy( out->UDN, UDN ); strcpy( out->UDN, UDN );
strcpy( out->ServiceId, serviceId ); strcpy( out->ServiceId, serviceId );
@ -360,7 +360,7 @@ int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *sr_event)
int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *cgv_event) int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *cgv_event)
{ {
unsigned int i = 0; unsigned int i = 0;
unsigned int j = 0; int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL); UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
@ -482,8 +482,7 @@ int TvDeviceHandleActionRequest(UpnpActionRequest *ca_event)
return UpnpActionRequest_get_ErrCode(ca_event); return UpnpActionRequest_get_ErrCode(ca_event);
} }
int TvDeviceSetServiceTableVar(unsigned int service, unsigned int variable, int TvDeviceSetServiceTableVar(unsigned int service, int variable, char *value)
char *value)
{ {
/*IXML_Document *PropSet= NULL; */ /*IXML_Document *PropSet= NULL; */
@ -723,9 +722,7 @@ int TvDeviceSetVolume(IXML_Document *in, IXML_Document **out, const char **error
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, if( TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL,
TV_CONTROL_VOLUME, value ) ) { TV_CONTROL_VOLUME, value ) ) {
@ -786,9 +783,7 @@ static int IncrementVolume(
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the channel goes here
*/
sprintf( value, "%d", newvolume ); sprintf( value, "%d", newvolume );
@ -839,9 +834,7 @@ int TvDeviceSetColor(IXML_Document *in, IXML_Document **out, const char **errorS
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE, if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
TV_PICTURE_COLOR, value ) ) { TV_PICTURE_COLOR, value ) ) {
@ -901,9 +894,7 @@ static int IncrementColor(
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the channel goes here
*/
sprintf( value, "%d", newcolor ); sprintf( value, "%d", newcolor );
@ -955,9 +946,7 @@ int TvDeviceSetTint(IXML_Document *in, IXML_Document **out, const char **errorSt
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE, if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
TV_PICTURE_TINT, value ) ) { TV_PICTURE_TINT, value ) ) {
@ -1019,9 +1008,7 @@ int IncrementTint(IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OU
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the channel goes here
*/
sprintf( value, "%d", newtint ); sprintf( value, "%d", newtint );
@ -1118,9 +1105,7 @@ TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT const ch
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* /* Vendor-specific code to set the volume goes here. */
Vendor-specific code to set the volume goes here
*/
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE, if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
TV_PICTURE_CONTRAST, value ) ) { TV_PICTURE_CONTRAST, value ) ) {

View File

@ -169,7 +169,7 @@ struct TvService {
/*! . */ /*! . */
upnp_action actions[TV_MAXACTIONS]; upnp_action actions[TV_MAXACTIONS];
/*! . */ /*! . */
unsigned int VariableCount; int VariableCount;
}; };
/*! Array of service structures */ /*! Array of service structures */
@ -271,7 +271,7 @@ int TvDeviceSetServiceTableVar(
/*! [in] The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL, /*! [in] The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL,
* TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT, * TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT,
* TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS). */ * TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS). */
unsigned int variable, int variable,
/*! [in] The string representation of the new value. */ /*! [in] The string representation of the new value. */
char *value); char *value);