samples: Fix compiler warnings.
This commit is contained in:
parent
4d2f1f7ba6
commit
57b1169850
@ -41,7 +41,7 @@ void IxmlPrintf(
|
||||
|
||||
void printNodes(IXML_Node *tmpRoot, int depth)
|
||||
{
|
||||
int i;
|
||||
unsigned long i;
|
||||
IXML_NodeList *NodeList1;
|
||||
IXML_Node *ChildNode1;
|
||||
unsigned short NodeType;
|
||||
|
@ -140,7 +140,7 @@ static IXML_NodeList *SampleUtil_GetNthServiceList(
|
||||
/*! [in] . */
|
||||
IXML_Document *doc,
|
||||
/*! [in] . */
|
||||
int n)
|
||||
unsigned int n)
|
||||
{
|
||||
IXML_NodeList *ServiceList = 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,
|
||||
const char *serviceType, char **serviceId, char **eventURL, char **controlURL)
|
||||
{
|
||||
int i;
|
||||
int length;
|
||||
unsigned int i;
|
||||
unsigned long length;
|
||||
int found = 0;
|
||||
int ret;
|
||||
int sindex = 0;
|
||||
unsigned int sindex = 0;
|
||||
char *tempServiceType = NULL;
|
||||
char *baseURL = NULL;
|
||||
const char *base = NULL;
|
||||
@ -576,7 +576,7 @@ int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location,
|
||||
/* Top level */
|
||||
for (sindex = 0;
|
||||
(serviceList = SampleUtil_GetNthServiceList(DescDoc , sindex)) != NULL;
|
||||
sindex ++) {
|
||||
sindex++) {
|
||||
tempServiceType = NULL;
|
||||
relcontrolURL = NULL;
|
||||
releventURL = NULL;
|
||||
@ -650,9 +650,8 @@ int SampleUtil_Print(const char *fmt, ...)
|
||||
va_start(ap, fmt);
|
||||
rc = vsnprintf(buf, MAX_BUF, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (gPrintFun) {
|
||||
gPrintFun(buf);
|
||||
gPrintFun("%s", buf);
|
||||
}
|
||||
|
||||
ithread_mutex_unlock(&display_mutex);
|
||||
|
@ -147,7 +147,14 @@ int SampleUtil_FindAndParseService (
|
||||
*/
|
||||
typedef void (*print_string)(
|
||||
/*! [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 */
|
||||
extern print_string gPrintFun;
|
||||
|
@ -29,18 +29,15 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "sample_util.h"
|
||||
#include "upnp_tv_ctrlpt.h"
|
||||
#include "upnp_tv_device.h"
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.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 {
|
||||
PRTHELP = 0, PRTFULLHELP, POWON, POWOFF,
|
||||
SETCHAN, SETVOL, SETCOL, SETTINT, SETCONT, SETBRT,
|
||||
@ -48,21 +45,21 @@ enum cmdloop_tvcmds {
|
||||
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 {
|
||||
char *str; /* the string */
|
||||
int cmdnum; /* the command */
|
||||
int numargs; /* the number of arguments */
|
||||
char *args; /* the args */
|
||||
/* the string */
|
||||
const char *str;
|
||||
/* the command */
|
||||
int cmdnum;
|
||||
/* the number of arguments */
|
||||
int numargs;
|
||||
/* the args */
|
||||
const char *args;
|
||||
} cmdloop_commands;
|
||||
|
||||
/*
|
||||
Mappings between command text names, command tag,
|
||||
and required command arguments for command line
|
||||
commands
|
||||
*/
|
||||
/*! Mappings between command text names, command tag,
|
||||
* and required command arguments for command line
|
||||
* commands */
|
||||
static struct cmdloop_commands cmdloop_cmdlist[] = {
|
||||
{"Help", PRTHELP, 1, ""},
|
||||
{"HelpFull", PRTFULLHELP, 1, ""},
|
||||
@ -84,174 +81,161 @@ static struct cmdloop_commands cmdloop_cmdlist[] = {
|
||||
{"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
|
||||
*
|
||||
* Description:
|
||||
* Print help info for this application.
|
||||
********************************************************************************/
|
||||
void
|
||||
TvCtrlPointPrintShortHelp( void )
|
||||
/*!
|
||||
* \brief Print help info for this application.
|
||||
*/
|
||||
void TvCtrlPointPrintShortHelp(void)
|
||||
{
|
||||
SampleUtil_Print( "Commands:" );
|
||||
SampleUtil_Print( " Help" );
|
||||
SampleUtil_Print( " HelpFull" );
|
||||
SampleUtil_Print( " ListDev" );
|
||||
SampleUtil_Print( " Refresh" );
|
||||
SampleUtil_Print( " PrintDev <devnum>" );
|
||||
SampleUtil_Print( " PowerOn <devnum>" );
|
||||
SampleUtil_Print( " PowerOff <devnum>" );
|
||||
SampleUtil_Print( " SetChannel <devnum> <channel>" );
|
||||
SampleUtil_Print( " SetVolume <devnum> <volume>" );
|
||||
SampleUtil_Print( " SetColor <devnum> <color>" );
|
||||
SampleUtil_Print( " SetTint <devnum> <tint>" );
|
||||
SampleUtil_Print( " SetContrast <devnum> <contrast>" );
|
||||
SampleUtil_Print( " SetBrightness <devnum> <brightness>" );
|
||||
SampleUtil_Print( " CtrlAction <devnum> <action>" );
|
||||
SampleUtil_Print( " PictAction <devnum> <action>" );
|
||||
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" );
|
||||
SampleUtil_Print( " PictGetVar <devnum> <action>" );
|
||||
SampleUtil_Print( " Exit" );
|
||||
SampleUtil_Print(
|
||||
"Commands:\n"
|
||||
" Help\n"
|
||||
" HelpFull\n"
|
||||
" ListDev\n"
|
||||
" Refresh\n"
|
||||
" PrintDev <devnum>\n"
|
||||
" PowerOn <devnum>\n"
|
||||
" PowerOff <devnum>\n"
|
||||
" SetChannel <devnum> <channel>\n"
|
||||
" SetVolume <devnum> <volume>\n"
|
||||
" SetColor <devnum> <color>\n"
|
||||
" SetTint <devnum> <tint>\n"
|
||||
" SetContrast <devnum> <contrast>\n"
|
||||
" SetBrightness <devnum> <brightness>\n"
|
||||
" CtrlAction <devnum> <action>\n"
|
||||
" PictAction <devnum> <action>\n"
|
||||
" CtrlGetVar <devnum> <varname>\n"
|
||||
" PictGetVar <devnum> <action>\n"
|
||||
" Exit\n");
|
||||
}
|
||||
|
||||
void
|
||||
TvCtrlPointPrintLongHelp( void )
|
||||
void TvCtrlPointPrintLongHelp(void)
|
||||
{
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print( "******************************" );
|
||||
SampleUtil_Print( "* TV Control Point Help Info *" );
|
||||
SampleUtil_Print( "******************************" );
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print( "This sample control point application automatically searches" );
|
||||
SampleUtil_Print( "for and subscribes to the services of television device emulator" );
|
||||
SampleUtil_Print( "devices, described in the tvdevicedesc.xml description document." );
|
||||
SampleUtil_Print( "It also registers itself as a tv device." );
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print( "Commands:" );
|
||||
SampleUtil_Print( " Help" );
|
||||
SampleUtil_Print( " Print this help info." );
|
||||
SampleUtil_Print( " ListDev" );
|
||||
SampleUtil_Print( " Print the current list of TV Device Emulators that this" );
|
||||
SampleUtil_Print( " control point is aware of. Each device is preceded by a" );
|
||||
SampleUtil_Print( " device number which corresponds to the devnum argument of" );
|
||||
SampleUtil_Print( " commands listed below." );
|
||||
SampleUtil_Print( " Refresh" );
|
||||
SampleUtil_Print( " Delete all of the devices from the device list and issue new" );
|
||||
SampleUtil_Print( " search request to rebuild the list from scratch." );
|
||||
SampleUtil_Print( " PrintDev <devnum>" );
|
||||
SampleUtil_Print( " Print the state table for the device <devnum>." );
|
||||
SampleUtil_Print( " e.g., 'PrintDev 1' prints the state table for the first" );
|
||||
SampleUtil_Print( " device in the device list." );
|
||||
SampleUtil_Print( " PowerOn <devnum>" );
|
||||
SampleUtil_Print( " Sends the PowerOn action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>." );
|
||||
SampleUtil_Print( " PowerOff <devnum>" );
|
||||
SampleUtil_Print( " Sends the PowerOff action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>." );
|
||||
SampleUtil_Print( " SetChannel <devnum> <channel>" );
|
||||
SampleUtil_Print( " Sends the SetChannel action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the channel to be changed" );
|
||||
SampleUtil_Print( " to <channel>." );
|
||||
SampleUtil_Print( " SetVolume <devnum> <volume>" );
|
||||
SampleUtil_Print( " Sends the SetVolume action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the volume to be changed" );
|
||||
SampleUtil_Print( " to <volume>." );
|
||||
SampleUtil_Print( " SetColor <devnum> <color>" );
|
||||
SampleUtil_Print( " Sends the SetColor action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the color to be changed" );
|
||||
SampleUtil_Print( " to <color>." );
|
||||
SampleUtil_Print( " SetTint <devnum> <tint>" );
|
||||
SampleUtil_Print( " Sends the SetTint action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the tint to be changed" );
|
||||
SampleUtil_Print( " to <tint>." );
|
||||
SampleUtil_Print( " SetContrast <devnum> <contrast>" );
|
||||
SampleUtil_Print( " Sends the SetContrast action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the contrast to be changed" );
|
||||
SampleUtil_Print( " to <contrast>." );
|
||||
SampleUtil_Print( " SetBrightness <devnum> <brightness>" );
|
||||
SampleUtil_Print( " Sends the SetBrightness action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the brightness to be changed" );
|
||||
SampleUtil_Print( " to <brightness>." );
|
||||
SampleUtil_Print( " CtrlAction <devnum> <action>" );
|
||||
SampleUtil_Print( " Sends an action request specified by the string <action>" );
|
||||
SampleUtil_Print( " to the Control Service of device <devnum>. This command" );
|
||||
SampleUtil_Print( " only works for actions that have no arguments." );
|
||||
SampleUtil_Print( " (e.g., \"CtrlAction 1 IncreaseChannel\")" );
|
||||
SampleUtil_Print( " PictAction <devnum> <action>" );
|
||||
SampleUtil_Print( " Sends an action request specified by the string <action>" );
|
||||
SampleUtil_Print( " to the Picture Service of device <devnum>. This command" );
|
||||
SampleUtil_Print( " only works for actions that have no arguments." );
|
||||
SampleUtil_Print( " (e.g., \"PictAction 1 DecreaseContrast\")" );
|
||||
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" );
|
||||
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" );
|
||||
SampleUtil_Print( " from the Control Service of device <devnum>." );
|
||||
SampleUtil_Print( " (e.g., \"CtrlGetVar 1 Volume\")" );
|
||||
SampleUtil_Print( " PictGetVar <devnum> <action>" );
|
||||
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" );
|
||||
SampleUtil_Print( " from the Picture Service of device <devnum>." );
|
||||
SampleUtil_Print( " (e.g., \"PictGetVar 1 Tint\")" );
|
||||
SampleUtil_Print( " Exit" );
|
||||
SampleUtil_Print( " Exits the control point application." );
|
||||
SampleUtil_Print(
|
||||
"\n"
|
||||
"******************************\n"
|
||||
"* TV Control Point Help Info *\n"
|
||||
"******************************\n"
|
||||
"\n"
|
||||
"This sample control point application automatically searches\n"
|
||||
"for and subscribes to the services of television device emulator\n"
|
||||
"devices, described in the tvdevicedesc.xml description document.\n"
|
||||
"It also registers itself as a tv device.\n"
|
||||
"\n"
|
||||
"Commands:\n"
|
||||
" Help\n"
|
||||
" Print this help info.\n"
|
||||
" ListDev\n"
|
||||
" Print the current list of TV Device Emulators that this\n"
|
||||
" control point is aware of. Each device is preceded by a\n"
|
||||
" device number which corresponds to the devnum argument of\n"
|
||||
" commands listed below.\n"
|
||||
" Refresh\n"
|
||||
" Delete all of the devices from the device list and issue new\n"
|
||||
" search request to rebuild the list from scratch.\n"
|
||||
" PrintDev <devnum>\n"
|
||||
" Print the state table for the device <devnum>.\n"
|
||||
" e.g., 'PrintDev 1' prints the state table for the first\n"
|
||||
" device in the device list.\n"
|
||||
" PowerOn <devnum>\n"
|
||||
" Sends the PowerOn action to the Control Service of\n"
|
||||
" device <devnum>.\n"
|
||||
" PowerOff <devnum>\n"
|
||||
" Sends the PowerOff action to the Control Service of\n"
|
||||
" device <devnum>.\n"
|
||||
" SetChannel <devnum> <channel>\n"
|
||||
" Sends the SetChannel action to the Control Service of\n"
|
||||
" device <devnum>, requesting the channel to be changed\n"
|
||||
" to <channel>.\n"
|
||||
" SetVolume <devnum> <volume>\n"
|
||||
" Sends the SetVolume action to the Control Service of\n"
|
||||
" device <devnum>, requesting the volume to be changed\n"
|
||||
" to <volume>.\n"
|
||||
" SetColor <devnum> <color>\n"
|
||||
" Sends the SetColor action to the Control Service of\n"
|
||||
" device <devnum>, requesting the color to be changed\n"
|
||||
" to <color>.\n"
|
||||
" SetTint <devnum> <tint>\n"
|
||||
" Sends the SetTint action to the Control Service of\n"
|
||||
" device <devnum>, requesting the tint to be changed\n"
|
||||
" to <tint>.\n"
|
||||
" SetContrast <devnum> <contrast>\n"
|
||||
" Sends the SetContrast action to the Control Service of\n"
|
||||
" device <devnum>, requesting the contrast to be changed\n"
|
||||
" to <contrast>.\n"
|
||||
" SetBrightness <devnum> <brightness>\n"
|
||||
" Sends the SetBrightness action to the Control Service of\n"
|
||||
" device <devnum>, requesting the brightness to be changed\n"
|
||||
" to <brightness>.\n"
|
||||
" CtrlAction <devnum> <action>\n"
|
||||
" Sends an action request specified by the string <action>\n"
|
||||
" to the Control Service of device <devnum>. This command\n"
|
||||
" only works for actions that have no arguments.\n"
|
||||
" (e.g., \"CtrlAction 1 IncreaseChannel\")\n"
|
||||
" PictAction <devnum> <action>\n"
|
||||
" Sends an action request specified by the string <action>\n"
|
||||
" to the Picture Service of device <devnum>. This command\n"
|
||||
" only works for actions that have no arguments.\n"
|
||||
" (e.g., \"PictAction 1 DecreaseContrast\")\n"
|
||||
" CtrlGetVar <devnum> <varname>\n"
|
||||
" Requests the value of a variable specified by the string <varname>\n"
|
||||
" from the Control Service of device <devnum>.\n"
|
||||
" (e.g., \"CtrlGetVar 1 Volume\")\n"
|
||||
" PictGetVar <devnum> <action>\n"
|
||||
" Requests the value of a variable specified by the string <varname>\n"
|
||||
" from the Picture Service of device <devnum>.\n"
|
||||
" (e.g., \"PictGetVar 1 Tint\")\n"
|
||||
" Exit\n"
|
||||
" Exits the control point application.\n");
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* TvCtrlPointPrintCommands
|
||||
*
|
||||
* Description:
|
||||
* Print the list of valid command line commands to the user
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
********************************************************************************/
|
||||
void
|
||||
TvCtrlPointPrintCommands()
|
||||
/*!
|
||||
* \briefPrint the list of valid command line commands to the user
|
||||
*/
|
||||
void TvCtrlPointPrintCommands()
|
||||
{
|
||||
int i;
|
||||
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands );
|
||||
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
|
||||
|
||||
SampleUtil_Print( "Valid Commands:" );
|
||||
for( i = 0; i < numofcmds; i++ ) {
|
||||
SampleUtil_Print( " %-14s %s", cmdloop_cmdlist[i].str,
|
||||
cmdloop_cmdlist[i].args );
|
||||
SampleUtil_Print("Valid Commands:\n");
|
||||
for (i = 0; i < numofcmds; ++i) {
|
||||
SampleUtil_Print(" %-14s %s\n",
|
||||
cmdloop_cmdlist[i].str, cmdloop_cmdlist[i].args);
|
||||
}
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print("\n");
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* TvCtrlPointCommandLoop
|
||||
*
|
||||
* Description:
|
||||
* Function that receives commands from the user at the command prompt
|
||||
* during the lifetime of the control point, and calls the appropriate
|
||||
/*!
|
||||
* \brief Function that receives commands from the user at the command prompt
|
||||
* during the lifetime of the device, and calls the appropriate
|
||||
* functions for those commands.
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
********************************************************************************/
|
||||
void *
|
||||
TvCtrlPointCommandLoop( void *args )
|
||||
*/
|
||||
void *TvCtrlPointCommandLoop(void *args)
|
||||
{
|
||||
char cmdline[100];
|
||||
|
||||
while( 1 ) {
|
||||
SampleUtil_Print( "\n>> " );
|
||||
fgets( cmdline, 100, stdin );
|
||||
TvCtrlPointProcessCommand( cmdline );
|
||||
while (1) {
|
||||
SampleUtil_Print("\n>> ");
|
||||
fgets(cmdline, 100, stdin);
|
||||
TvCtrlPointProcessCommand(cmdline);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
args = args;
|
||||
}
|
||||
|
||||
int
|
||||
TvCtrlPointProcessCommand( char *cmdline )
|
||||
int TvCtrlPointProcessCommand(char *cmdline)
|
||||
{
|
||||
char cmd[100];
|
||||
char strarg[100];
|
||||
@ -259,164 +243,129 @@ TvCtrlPointProcessCommand( char *cmdline )
|
||||
int arg1 = arg_val_err;
|
||||
int arg2 = arg_val_err;
|
||||
int cmdnum = -1;
|
||||
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands );
|
||||
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
|
||||
int cmdfound = 0;
|
||||
int i,
|
||||
rc;
|
||||
int i;
|
||||
int rc;
|
||||
int invalidargs = 0;
|
||||
int validargs;
|
||||
|
||||
validargs = sscanf( cmdline, "%s %d %d", cmd, &arg1, &arg2 );
|
||||
|
||||
for( i = 0; i < numofcmds; i++ ) {
|
||||
if( strcasecmp( cmd, cmdloop_cmdlist[i].str ) == 0 ) {
|
||||
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 )
|
||||
if (validargs != cmdloop_cmdlist[i].numargs)
|
||||
invalidargs++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !cmdfound ) {
|
||||
SampleUtil_Print( "Command not found; try 'Help'" );
|
||||
if (!cmdfound) {
|
||||
SampleUtil_Print("Command not found; try 'Help'\n");
|
||||
return TV_SUCCESS;
|
||||
}
|
||||
|
||||
if( invalidargs ) {
|
||||
SampleUtil_Print( "Invalid arguments; try 'Help'" );
|
||||
if (invalidargs) {
|
||||
SampleUtil_Print("Invalid arguments; try 'Help'\n");
|
||||
return TV_SUCCESS;
|
||||
}
|
||||
|
||||
switch ( cmdnum ) {
|
||||
switch (cmdnum) {
|
||||
case PRTHELP:
|
||||
TvCtrlPointPrintShortHelp();
|
||||
break;
|
||||
|
||||
case PRTFULLHELP:
|
||||
TvCtrlPointPrintLongHelp();
|
||||
break;
|
||||
|
||||
case POWON:
|
||||
TvCtrlPointSendPowerOn( arg1 );
|
||||
TvCtrlPointSendPowerOn(arg1);
|
||||
break;
|
||||
|
||||
case POWOFF:
|
||||
TvCtrlPointSendPowerOff( arg1 );
|
||||
TvCtrlPointSendPowerOff(arg1);
|
||||
break;
|
||||
|
||||
case SETCHAN:
|
||||
TvCtrlPointSendSetChannel( arg1, arg2 );
|
||||
TvCtrlPointSendSetChannel(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETVOL:
|
||||
TvCtrlPointSendSetVolume( arg1, arg2 );
|
||||
TvCtrlPointSendSetVolume(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETCOL:
|
||||
TvCtrlPointSendSetColor( arg1, arg2 );
|
||||
TvCtrlPointSendSetColor(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETTINT:
|
||||
TvCtrlPointSendSetTint( arg1, arg2 );
|
||||
TvCtrlPointSendSetTint(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETCONT:
|
||||
TvCtrlPointSendSetContrast( arg1, arg2 );
|
||||
TvCtrlPointSendSetContrast(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETBRT:
|
||||
TvCtrlPointSendSetBrightness( arg1, arg2 );
|
||||
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 );
|
||||
/* 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( 3 == validargs )
|
||||
TvCtrlPointSendAction( TV_SERVICE_PICTURE, arg1, strarg,
|
||||
NULL, NULL, 0 );
|
||||
/* 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( 3 == validargs )
|
||||
TvCtrlPointGetVar( TV_SERVICE_CONTROL, arg1, strarg );
|
||||
/* 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( 3 == validargs )
|
||||
TvCtrlPointGetVar( TV_SERVICE_PICTURE, arg1, strarg );
|
||||
/* 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 );
|
||||
TvCtrlPointPrintDevice(arg1);
|
||||
break;
|
||||
|
||||
case LSTDEV:
|
||||
TvCtrlPointPrintList();
|
||||
break;
|
||||
|
||||
case REFRESH:
|
||||
TvCtrlPointRefresh();
|
||||
break;
|
||||
|
||||
case EXITCMD:
|
||||
rc = TvCtrlPointStop();
|
||||
exit( rc );
|
||||
exit(rc);
|
||||
break;
|
||||
|
||||
default:
|
||||
SampleUtil_Print( "Command not implemented; see 'Help'" );
|
||||
SampleUtil_Print("Command not implemented; see 'Help'\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if( invalidargs )
|
||||
SampleUtil_Print( "Invalid args in command; see 'Help'" );
|
||||
if(invalidargs)
|
||||
SampleUtil_Print("Invalid args in command; see 'Help'\n");
|
||||
|
||||
return TV_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
device_main( int argc, char **argv )
|
||||
int device_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
unsigned int portTemp = 0;
|
||||
char *ip_address = NULL,
|
||||
*desc_doc_name = NULL,
|
||||
*web_dir_path = NULL;
|
||||
unsigned int port = 0;
|
||||
|
||||
unsigned short port = 0;
|
||||
int i = 0;
|
||||
|
||||
SampleUtil_Initialize( linux_print );
|
||||
|
||||
SampleUtil_Initialize(linux_print);
|
||||
/* Parse options */
|
||||
for( i = 1; i < argc; i++ ) {
|
||||
if( strcmp( argv[i], "-ip" ) == 0 ) {
|
||||
@ -428,32 +377,27 @@ device_main( int argc, char **argv )
|
||||
} else if( strcmp( argv[i], "-webdir" ) == 0 ) {
|
||||
web_dir_path = argv[++i];
|
||||
} else if( strcmp( argv[i], "-help" ) == 0 ) {
|
||||
SampleUtil_Print( "Usage: %s -ip ipaddress -port port"
|
||||
" -desc desc_doc_name -webdir web_dir_path"
|
||||
" -help (this message)\n", argv[0] );
|
||||
SampleUtil_Print( "\tipaddress: IP address of the device"
|
||||
" (must match desc. doc)\n" );
|
||||
SampleUtil_Print( "\t\te.g.: 192.168.0.4\n" );
|
||||
SampleUtil_Print( "\tport: Port number to use for "
|
||||
"receiving UPnP messages (must match desc. doc)\n" );
|
||||
SampleUtil_Print( "\t\te.g.: 5431\n" );
|
||||
SampleUtil_Print
|
||||
( "\tdesc_doc_name: name of device description document\n" );
|
||||
SampleUtil_Print( "\t\te.g.: tvcombodesc.xml\n" );
|
||||
SampleUtil_Print
|
||||
( "\tweb_dir_path: Filesystem path where web files "
|
||||
"related to the device are stored\n" );
|
||||
SampleUtil_Print( "\t\te.g.: /upnp/sample/web\n" );
|
||||
SampleUtil_Print(
|
||||
"Usage: %s -ip ipaddress -port port\n"
|
||||
" -desc desc_doc_name -webdir web_dir_path\n"
|
||||
" -help (this message)\n\n", argv[0]);
|
||||
SampleUtil_Print(
|
||||
"\tipaddress:\tIP address of the device (must match desc. doc)\n"
|
||||
"\t\te.g.: 192.168.0.4\n\n"
|
||||
"\tport:\tPort number to use for receiving UPnP messages (must match desc. doc)\n"
|
||||
"\t\te.g.: 5431\n\n"
|
||||
"\tdesc_doc_name: name of device description document\n"
|
||||
"\t\te.g.: tvcombodesc.xml\n\n"
|
||||
"\tweb_dir_path: Filesystem path where web files related to the device are stored\n"
|
||||
"\t\te.g.: /upnp/sample/web\n\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
port = ( unsigned short )portTemp;
|
||||
|
||||
return TvDeviceStart( ip_address, port, desc_doc_name, web_dir_path, linux_print );
|
||||
port = (unsigned short)portTemp;
|
||||
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;
|
||||
ithread_t cmdloop_thread;
|
||||
@ -465,27 +409,25 @@ int main( int argc, char **argv )
|
||||
int code;
|
||||
|
||||
device_main(argc, argv);
|
||||
rc = TvCtrlPointStart( linux_print, NULL );
|
||||
if( rc != TV_SUCCESS ) {
|
||||
SampleUtil_Print( "Error starting UPnP TV Control Point" );
|
||||
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 );
|
||||
|
||||
code = ithread_create(&cmdloop_thread, NULL, TvCtrlPointCommandLoop, NULL);
|
||||
#ifdef WIN32
|
||||
ithread_join(cmdloop_thread, NULL);
|
||||
#else
|
||||
/*
|
||||
Catch Ctrl-C and properly shutdown
|
||||
*/
|
||||
sigemptyset( &sigs_to_catch );
|
||||
sigaddset( &sigs_to_catch, SIGINT );
|
||||
sigwait( &sigs_to_catch, &sig );
|
||||
|
||||
SampleUtil_Print( "Shutting down on signal %d...\n", sig );
|
||||
/* Catch Ctrl-C and properly shutdown */
|
||||
sigemptyset(&sigs_to_catch);
|
||||
sigaddset(&sigs_to_catch, SIGINT);
|
||||
sigwait(&sigs_to_catch, &sig);
|
||||
SampleUtil_Print("Shutting down on signal %d...\n", sig);
|
||||
#endif
|
||||
TvDeviceStop();
|
||||
rc = TvCtrlPointStop();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,7 @@ ithread_mutex_t DeviceListMutex;
|
||||
UpnpClient_Handle ctrlpt_handle = -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:tvpicture:1"
|
||||
};
|
||||
@ -95,7 +94,7 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
|
||||
var;
|
||||
|
||||
if( NULL == node ) {
|
||||
SampleUtil_Print( "ERROR: TvCtrlPointDeleteNode: Node is empty" );
|
||||
SampleUtil_Print("ERROR: TvCtrlPointDeleteNode: Node is empty\n");
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
@ -108,12 +107,12 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
|
||||
node->device.TvService[service].SID );
|
||||
if( UPNP_E_SUCCESS == rc ) {
|
||||
SampleUtil_Print
|
||||
( "Unsubscribed from Tv %s EventURL with SID=%s",
|
||||
( "Unsubscribed from Tv %s EventURL with SID=%s\n",
|
||||
TvServiceName[service],
|
||||
node->device.TvService[service].SID );
|
||||
} else {
|
||||
SampleUtil_Print
|
||||
( "Error unsubscribing to Tv %s EventURL -- %d",
|
||||
( "Error unsubscribing to Tv %s EventURL -- %d\n",
|
||||
TvServiceName[service], rc );
|
||||
}
|
||||
}
|
||||
@ -153,8 +152,7 @@ int TvCtrlPointRemoveDevice(const char *UDN)
|
||||
|
||||
curdevnode = GlobalDeviceList;
|
||||
if( !curdevnode ) {
|
||||
SampleUtil_Print
|
||||
( "WARNING: TvCtrlPointRemoveDevice: Device list empty" );
|
||||
SampleUtil_Print("WARNING: TvCtrlPointRemoveDevice: Device list empty\n");
|
||||
} else {
|
||||
if( 0 == strcmp( curdevnode->device.UDN, UDN ) ) {
|
||||
GlobalDeviceList = curdevnode->next;
|
||||
@ -237,7 +235,7 @@ TvCtrlPointRefresh( void )
|
||||
*/
|
||||
rc = UpnpSearchAsync( ctrlpt_handle, 5, TvDeviceType, NULL );
|
||||
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;
|
||||
}
|
||||
|
||||
@ -257,10 +255,7 @@ TvCtrlPointRefresh( void )
|
||||
* varname -- The name of the variable to request.
|
||||
*
|
||||
********************************************************************************/
|
||||
int
|
||||
TvCtrlPointGetVar( int service,
|
||||
int devnum,
|
||||
char *varname )
|
||||
int TvCtrlPointGetVar(int service, int devnum, const char *varname)
|
||||
{
|
||||
struct TvDeviceNode *devnode;
|
||||
int rc;
|
||||
@ -277,8 +272,7 @@ TvCtrlPointGetVar( int service,
|
||||
TvCtrlPointCallbackEventHandler,
|
||||
NULL );
|
||||
if( rc != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Error in UpnpGetServiceVarStatusAsync -- %d", rc );
|
||||
SampleUtil_Print("Error in UpnpGetServiceVarStatusAsync -- %d\n", rc);
|
||||
rc = TV_ERROR;
|
||||
}
|
||||
}
|
||||
@ -346,13 +340,13 @@ TvCtrlPointGetBrightness( int devnum )
|
||||
* param_count -- The number of parameters
|
||||
*
|
||||
********************************************************************************/
|
||||
int
|
||||
TvCtrlPointSendAction( int service,
|
||||
int TvCtrlPointSendAction(
|
||||
int service,
|
||||
int devnum,
|
||||
char *actionname,
|
||||
char **param_name,
|
||||
const char *actionname,
|
||||
const char **param_name,
|
||||
char **param_val,
|
||||
int param_count )
|
||||
int param_count)
|
||||
{
|
||||
struct TvDeviceNode *devnode;
|
||||
IXML_Document *actionNode = NULL;
|
||||
@ -373,8 +367,7 @@ TvCtrlPointSendAction( int service,
|
||||
( &actionNode, actionname, TvServiceType[service],
|
||||
param_name[param],
|
||||
param_val[param] ) != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "ERROR: TvCtrlPointSendAction: Trying to add action param" );
|
||||
SampleUtil_Print("ERROR: TvCtrlPointSendAction: Trying to add action param\n");
|
||||
/*return -1; // TBD - BAD! leaves mutex locked */
|
||||
}
|
||||
}
|
||||
@ -387,7 +380,7 @@ TvCtrlPointSendAction( int service,
|
||||
TvCtrlPointCallbackEventHandler, NULL );
|
||||
|
||||
if( rc != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error in UpnpSendActionAsync -- %d", rc );
|
||||
SampleUtil_Print( "Error in UpnpSendActionAsync -- %d\n", rc );
|
||||
rc = TV_ERROR;
|
||||
}
|
||||
}
|
||||
@ -416,8 +409,8 @@ TvCtrlPointSendAction( int service,
|
||||
int
|
||||
TvCtrlPointSendActionNumericArg( int devnum,
|
||||
int service,
|
||||
char *actionName,
|
||||
char *paramName,
|
||||
const char *actionName,
|
||||
const char *paramName,
|
||||
int paramValue )
|
||||
{
|
||||
char param_val_a[50];
|
||||
@ -525,7 +518,7 @@ TvCtrlPointGetDevice( int devnum,
|
||||
}
|
||||
|
||||
if( !tmpdevnode ) {
|
||||
SampleUtil_Print( "Error finding TvDevice number -- %d", devnum );
|
||||
SampleUtil_Print( "Error finding TvDevice number -- %d\n", devnum );
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
@ -551,13 +544,13 @@ TvCtrlPointPrintList()
|
||||
|
||||
ithread_mutex_lock( &DeviceListMutex );
|
||||
|
||||
SampleUtil_Print( "TvCtrlPointPrintList:" );
|
||||
SampleUtil_Print("TvCtrlPointPrintList:\n");
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
while( tmpdevnode ) {
|
||||
SampleUtil_Print( " %3d -- %s", ++i, tmpdevnode->device.UDN );
|
||||
SampleUtil_Print( " %3d -- %s\n", ++i, tmpdevnode->device.UDN );
|
||||
tmpdevnode = tmpdevnode->next;
|
||||
}
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print("\n");
|
||||
ithread_mutex_unlock( &DeviceListMutex );
|
||||
|
||||
return TV_SUCCESS;
|
||||
@ -585,15 +578,13 @@ TvCtrlPointPrintDevice( int devnum )
|
||||
char spacer[15];
|
||||
|
||||
if( devnum <= 0 ) {
|
||||
SampleUtil_Print
|
||||
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d",
|
||||
devnum );
|
||||
SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d\n", devnum);
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
ithread_mutex_lock( &DeviceListMutex );
|
||||
|
||||
SampleUtil_Print( "TvCtrlPointPrintDevice:" );
|
||||
SampleUtil_Print("TvCtrlPointPrintDevice:\n");
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
while( tmpdevnode ) {
|
||||
i++;
|
||||
@ -603,57 +594,35 @@ TvCtrlPointPrintDevice( int devnum )
|
||||
}
|
||||
|
||||
if( !tmpdevnode ) {
|
||||
SampleUtil_Print
|
||||
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d",
|
||||
devnum, i );
|
||||
SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d\n", devnum, i);
|
||||
} else {
|
||||
SampleUtil_Print( " TvDevice -- %d", devnum );
|
||||
SampleUtil_Print( " | " );
|
||||
SampleUtil_Print( " +- UDN = %s",
|
||||
tmpdevnode->device.UDN );
|
||||
SampleUtil_Print( " +- DescDocURL = %s",
|
||||
tmpdevnode->device.DescDocURL );
|
||||
SampleUtil_Print( " +- FriendlyName = %s",
|
||||
tmpdevnode->device.FriendlyName );
|
||||
SampleUtil_Print( " +- PresURL = %s",
|
||||
tmpdevnode->device.PresURL );
|
||||
SampleUtil_Print( " +- Adver. TimeOut = %d",
|
||||
tmpdevnode->device.AdvrTimeOut );
|
||||
|
||||
SampleUtil_Print(" TvDevice -- %d\n", devnum);
|
||||
SampleUtil_Print(" | \n");
|
||||
SampleUtil_Print(" +- UDN = %s\n" , tmpdevnode->device.UDN);
|
||||
SampleUtil_Print(" +- DescDocURL = %s\n", tmpdevnode->device.DescDocURL);
|
||||
SampleUtil_Print(" +- FriendlyName = %s\n", tmpdevnode->device.FriendlyName);
|
||||
SampleUtil_Print(" +- PresURL = %s\n", tmpdevnode->device.PresURL);
|
||||
SampleUtil_Print(" +- Adver. TimeOut = %d\n", tmpdevnode->device.AdvrTimeOut);
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
if( service < TV_SERVICE_SERVCOUNT - 1 )
|
||||
sprintf( spacer, " | " );
|
||||
if(service < TV_SERVICE_SERVCOUNT - 1)
|
||||
sprintf(spacer, " | ");
|
||||
else
|
||||
sprintf( spacer, " " );
|
||||
SampleUtil_Print( " | " );
|
||||
SampleUtil_Print( " +- Tv %s Service",
|
||||
TvServiceName[service] );
|
||||
SampleUtil_Print( "%s+- ServiceId = %s", spacer,
|
||||
tmpdevnode->device.TvService[service].
|
||||
ServiceId );
|
||||
SampleUtil_Print( "%s+- ServiceType = %s", spacer,
|
||||
tmpdevnode->device.TvService[service].
|
||||
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 );
|
||||
|
||||
sprintf(spacer, " ");
|
||||
SampleUtil_Print(" | ");
|
||||
SampleUtil_Print(" +- Tv %s Service", TvServiceName[service]);
|
||||
SampleUtil_Print("%s+- ServiceId = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceId);
|
||||
SampleUtil_Print("%s+- ServiceType = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceType);
|
||||
SampleUtil_Print("%s+- EventURL = %s\n", spacer, tmpdevnode->device.TvService[service].EventURL);
|
||||
SampleUtil_Print("%s+- ControlURL = %s\n", spacer, tmpdevnode->device.TvService[service].ControlURL);
|
||||
SampleUtil_Print("%s+- SID = %s\n", spacer, tmpdevnode->device.TvService[service].SID);
|
||||
SampleUtil_Print("%s+- ServiceStateTable", spacer);
|
||||
for( var = 0; var < TvVarCount[service]; var++ ) {
|
||||
SampleUtil_Print( "%s +- %-10s = %s", spacer,
|
||||
TvVarName[service][var],
|
||||
tmpdevnode->device.TvService[service].
|
||||
VariableStrVal[var] );
|
||||
SampleUtil_Print("%s +- %-10s = %s\n", spacer, TvVarName[service][var],
|
||||
tmpdevnode->device.TvService[service].VariableStrVal[var]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print("\n");
|
||||
ithread_mutex_unlock( &DeviceListMutex );
|
||||
|
||||
return TV_SUCCESS;
|
||||
@ -711,11 +680,10 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
( baseURL ? baseURL : location ), relURL, presURL);
|
||||
|
||||
if( UPNP_E_SUCCESS != ret )
|
||||
SampleUtil_Print( "Error generating presURL from %s + %s", baseURL,
|
||||
relURL );
|
||||
SampleUtil_Print( "Error generating presURL from %s + %s\n", baseURL, relURL );
|
||||
|
||||
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 */
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
@ -733,45 +701,29 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
tmpdevnode->device.AdvrTimeOut = expires;
|
||||
} else {
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
if( SampleUtil_FindAndParseService
|
||||
( DescDoc, location, TvServiceType[service],
|
||||
if( SampleUtil_FindAndParseService(DescDoc, location, TvServiceType[service],
|
||||
&serviceId[service], &eventURL[service],
|
||||
&controlURL[service] ) ) {
|
||||
SampleUtil_Print( "Subscribing to EventURL %s...",
|
||||
eventURL[service] );
|
||||
|
||||
ret =
|
||||
UpnpSubscribe( ctrlpt_handle, eventURL[service],
|
||||
&TimeOut[service],
|
||||
eventSID[service] );
|
||||
|
||||
&controlURL[service])) {
|
||||
SampleUtil_Print("Subscribing to EventURL %s...\n", eventURL[service]);
|
||||
ret = UpnpSubscribe(ctrlpt_handle, eventURL[service],
|
||||
&TimeOut[service], eventSID[service]);
|
||||
if( ret == UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Subscribed to EventURL with SID=%s",
|
||||
eventSID[service] );
|
||||
SampleUtil_Print("Subscribed to EventURL with SID=%s\n", eventSID[service]);
|
||||
} else {
|
||||
SampleUtil_Print
|
||||
( "Error Subscribing to EventURL -- %d", ret );
|
||||
strcpy( eventSID[service], "" );
|
||||
SampleUtil_Print("Error Subscribing to EventURL -- %d\n", ret);
|
||||
strcpy(eventSID[service], "");
|
||||
}
|
||||
} else {
|
||||
SampleUtil_Print( "Error: Could not find Service: %s",
|
||||
TvServiceType[service] );
|
||||
SampleUtil_Print("Error: Could not find Service: %s\n", 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.DescDocURL, location );
|
||||
strcpy( deviceNode->device.FriendlyName, friendlyName );
|
||||
strcpy( deviceNode->device.PresURL, presURL );
|
||||
deviceNode->device.AdvrTimeOut = expires;
|
||||
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
strcpy( deviceNode->device.TvService[service].ServiceId,
|
||||
serviceId[service] );
|
||||
@ -783,7 +735,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
eventURL[service] );
|
||||
strcpy( deviceNode->device.TvService[service].SID,
|
||||
eventSID[service] );
|
||||
|
||||
for( var = 0; var < TvVarCount[service]; var++ ) {
|
||||
deviceNode->device.TvService[service].
|
||||
VariableStrVal[var] =
|
||||
@ -792,12 +743,9 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
VariableStrVal[var], "" );
|
||||
}
|
||||
}
|
||||
|
||||
deviceNode->next = NULL;
|
||||
|
||||
/* Insert the new device node in the list */
|
||||
if( ( tmpdevnode = GlobalDeviceList ) ) {
|
||||
|
||||
while( tmpdevnode ) {
|
||||
if( tmpdevnode->next ) {
|
||||
tmpdevnode = tmpdevnode->next;
|
||||
@ -809,10 +757,8 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
} else {
|
||||
GlobalDeviceList = deviceNode;
|
||||
}
|
||||
|
||||
/*Notify New Device Added */
|
||||
SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN,
|
||||
DEVICE_ADDED );
|
||||
SampleUtil_StateUpdate(NULL, NULL, deviceNode->device.UDN, DEVICE_ADDED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -828,7 +774,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
free( baseURL );
|
||||
if( relURL )
|
||||
free( relURL );
|
||||
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
if( serviceId[service] )
|
||||
free( serviceId[service] );
|
||||
@ -872,33 +817,23 @@ TvStateUpdate( char *UDN,
|
||||
j;
|
||||
char *tmpstate = NULL;
|
||||
|
||||
SampleUtil_Print( "Tv State Update (service %d): ", Service );
|
||||
|
||||
/*
|
||||
Find all of the e:property tags in the document
|
||||
*/
|
||||
properties =
|
||||
ixmlDocument_getElementsByTagName( ChangedVariables,
|
||||
"e:property" );
|
||||
SampleUtil_Print( "Tv State Update (service %d):\n", Service );
|
||||
/* Find all of the e:property tags in the document */
|
||||
properties = ixmlDocument_getElementsByTagName(
|
||||
ChangedVariables, "e:property" );
|
||||
if( NULL != properties ) {
|
||||
length = ixmlNodeList_length( properties );
|
||||
for( i = 0; i < length; i++ ) { /* Loop through each property change found */
|
||||
property =
|
||||
( 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++ ) {
|
||||
variables =
|
||||
ixmlElement_getElementsByTagName( property,
|
||||
TvVarName[Service]
|
||||
[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 ) {
|
||||
length1 = ixmlNodeList_length( variables );
|
||||
if( length1 ) {
|
||||
@ -909,21 +844,16 @@ TvStateUpdate( char *UDN,
|
||||
|
||||
if( tmpstate ) {
|
||||
strcpy( State[j], tmpstate );
|
||||
SampleUtil_Print
|
||||
( " Variable Name: %s New Value:'%s'",
|
||||
TvVarName[Service][j], State[j] );
|
||||
SampleUtil_Print(" Variable Name: %s New Value:'%s'\n", TvVarName[Service][j], State[j] );
|
||||
}
|
||||
|
||||
if( tmpstate )
|
||||
free( tmpstate );
|
||||
tmpstate = NULL;
|
||||
}
|
||||
|
||||
ixmlNodeList_free( variables );
|
||||
variables = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ixmlNodeList_free( properties );
|
||||
}
|
||||
@ -956,7 +886,7 @@ void TvCtrlPointHandleEvent(
|
||||
while (tmpdevnode) {
|
||||
for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) {
|
||||
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],
|
||||
evntkey,
|
||||
sid);
|
||||
@ -1001,13 +931,10 @@ void TvCtrlPointHandleSubscribeUpdate(
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
while( tmpdevnode ) {
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
|
||||
if( strcmp
|
||||
( tmpdevnode->device.TvService[service].EventURL,
|
||||
eventURL ) == 0 ) {
|
||||
SampleUtil_Print
|
||||
( "Received Tv %s Event Renewal for eventURL %s",
|
||||
TvServiceName[service], eventURL );
|
||||
SampleUtil_Print("Received Tv %s Event Renewal for eventURL %s\n", TvServiceName[service], eventURL );
|
||||
strcpy( tmpdevnode->device.TvService[service].SID, sid );
|
||||
break;
|
||||
}
|
||||
@ -1075,14 +1002,14 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Discovery Callback -- %d", errCode);
|
||||
"Error in Discovery Callback -- %d\n", errCode);
|
||||
}
|
||||
|
||||
location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event));
|
||||
errCode = UpnpDownloadXmlDoc(location, &DescDoc);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error obtaining device description from %s -- error = %d",
|
||||
"Error obtaining device description from %s -- error = %d\n",
|
||||
location, errCode);
|
||||
} else {
|
||||
TvCtrlPointAddDevice(
|
||||
@ -1105,11 +1032,11 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
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);
|
||||
SampleUtil_Print("After byebye:");
|
||||
SampleUtil_Print("After byebye:\n");
|
||||
TvCtrlPointPrintList();
|
||||
break;
|
||||
}
|
||||
@ -1119,7 +1046,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
int errCode = UpnpActionComplete_get_ErrCode(a_event);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Action Complete Callback -- %d",
|
||||
"Error in Action Complete Callback -- %d\n",
|
||||
errCode);
|
||||
}
|
||||
/* 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);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Get Var Complete Callback -- %d", errCode);
|
||||
"Error in Get Var Complete Callback -- %d\n", errCode);
|
||||
} else {
|
||||
TvCtrlPointHandleGetVar(
|
||||
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);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Event Subscribe Callback -- %d", errCode);
|
||||
"Error in Event Subscribe Callback -- %d\n", errCode);
|
||||
} else {
|
||||
TvCtrlPointHandleSubscribeUpdate(
|
||||
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
|
||||
@ -1178,13 +1105,13 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
&TimeOut,
|
||||
newSID);
|
||||
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(
|
||||
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
|
||||
newSID,
|
||||
TimeOut);
|
||||
} else {
|
||||
SampleUtil_Print("Error Subscribing to EventURL -- %d", errCode);
|
||||
SampleUtil_Print("Error Subscribing to EventURL -- %d\n", errCode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1254,18 +1181,14 @@ TvCtrlPointVerifyTimeouts( int incr )
|
||||
ret = UpnpSearchAsync( ctrlpt_handle, incr,
|
||||
curdevnode->device.UDN, NULL );
|
||||
if( ret != UPNP_E_SUCCESS )
|
||||
SampleUtil_Print
|
||||
( "Error sending search request for Device UDN: %s -- err = %d",
|
||||
SampleUtil_Print("Error sending search request for Device UDN: %s -- err = %d\n",
|
||||
curdevnode->device.UDN, ret );
|
||||
}
|
||||
|
||||
prevdevnode = curdevnode;
|
||||
curdevnode = curdevnode->next;
|
||||
}
|
||||
|
||||
}
|
||||
ithread_mutex_unlock( &DeviceListMutex );
|
||||
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
@ -1327,7 +1250,7 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
|
||||
|
||||
rc = UpnpInit(ip_address, port);
|
||||
if (rc != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print("WinCEStart: UpnpInit() Error: %d", rc);
|
||||
SampleUtil_Print("WinCEStart: UpnpInit() Error: %d\n", rc);
|
||||
/*
|
||||
UpnpFinish();
|
||||
return TV_ERROR;
|
||||
@ -1345,18 +1268,17 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
|
||||
"\tipaddress = %s port = %u\n",
|
||||
ip_address ? ip_address : "{NULL}",
|
||||
port);
|
||||
|
||||
SampleUtil_Print("Registering Control Point");
|
||||
SampleUtil_Print("Registering Control Point\n");
|
||||
rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler,
|
||||
&ctrlpt_handle, &ctrlpt_handle);
|
||||
if (rc != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print( "Error registering CP: %d", rc );
|
||||
SampleUtil_Print( "Error registering CP: %d\n", rc );
|
||||
UpnpFinish();
|
||||
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
SampleUtil_Print("Control Point Registered");
|
||||
SampleUtil_Print("Control Point Registered\n");
|
||||
|
||||
TvCtrlPointRefresh();
|
||||
|
||||
|
@ -128,8 +128,8 @@ int TvCtrlPointRemoveAll(void);
|
||||
int TvCtrlPointRefresh(void);
|
||||
|
||||
|
||||
int TvCtrlPointSendAction(int, int, char *, char **, char **, int);
|
||||
int TvCtrlPointSendActionNumericArg(int devnum, int service, char *actionName, char *paramName, int paramValue);
|
||||
int TvCtrlPointSendAction(int, int, const char *, const char **, char **, int);
|
||||
int TvCtrlPointSendActionNumericArg(int devnum, int service, const char *actionName, const char *paramName, int paramValue);
|
||||
int TvCtrlPointSendPowerOn(int devnum);
|
||||
int TvCtrlPointSendPowerOff(int devnum);
|
||||
int TvCtrlPointSendSetChannel(int, int);
|
||||
@ -139,7 +139,7 @@ int TvCtrlPointSendSetTint(int, int);
|
||||
int TvCtrlPointSendSetContrast(int, int);
|
||||
int TvCtrlPointSendSetBrightness(int, int);
|
||||
|
||||
int TvCtrlPointGetVar(int, int, char*);
|
||||
int TvCtrlPointGetVar(int, int, const char *);
|
||||
int TvCtrlPointGetPower(int devnum);
|
||||
int TvCtrlPointGetChannel(int);
|
||||
int TvCtrlPointGetVolume(int);
|
||||
@ -168,5 +168,5 @@ int TvCtrlPointProcessCommand(char *cmdline);
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /*UPNP_TV_CTRLPT_H */
|
||||
#endif /* UPNP_TV_CTRLPT_H */
|
||||
|
||||
|
@ -113,7 +113,7 @@ static int SetServiceTable(
|
||||
/*! [in,out] service containing table to be set. */
|
||||
INOUT struct TvService *out)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
int i = 0;
|
||||
|
||||
strcpy( out->UDN, UDN );
|
||||
strcpy( out->ServiceId, serviceId );
|
||||
@ -357,7 +357,7 @@ int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *sr_event)
|
||||
int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *cgv_event)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
int j = 0;
|
||||
int getvar_succeeded = 0;
|
||||
|
||||
UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
|
||||
@ -479,8 +479,7 @@ int TvDeviceHandleActionRequest(UpnpActionRequest *ca_event)
|
||||
return UpnpActionRequest_get_ErrCode(ca_event);
|
||||
}
|
||||
|
||||
int TvDeviceSetServiceTableVar(unsigned int service, unsigned int variable,
|
||||
char *value)
|
||||
int TvDeviceSetServiceTableVar(unsigned int service, int variable, char *value)
|
||||
{
|
||||
/*IXML_Document *PropSet= NULL; */
|
||||
|
||||
@ -720,9 +719,7 @@ int TvDeviceSetVolume(IXML_Document *in, IXML_Document **out, const char **error
|
||||
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,
|
||||
TV_CONTROL_VOLUME, value ) ) {
|
||||
@ -783,9 +780,7 @@ static int IncrementVolume(
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the channel goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
sprintf( value, "%d", newvolume );
|
||||
|
||||
@ -836,9 +831,7 @@ int TvDeviceSetColor(IXML_Document *in, IXML_Document **out, const char **errorS
|
||||
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,
|
||||
TV_PICTURE_COLOR, value ) ) {
|
||||
@ -898,9 +891,7 @@ static int IncrementColor(
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the channel goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
sprintf( value, "%d", newcolor );
|
||||
|
||||
@ -952,9 +943,7 @@ int TvDeviceSetTint(IXML_Document *in, IXML_Document **out, const char **errorSt
|
||||
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,
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the channel goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the volume goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
|
||||
TV_PICTURE_CONTRAST, value ) ) {
|
||||
|
@ -169,7 +169,7 @@ struct TvService {
|
||||
/*! . */
|
||||
upnp_action actions[TV_MAXACTIONS];
|
||||
/*! . */
|
||||
unsigned int VariableCount;
|
||||
int VariableCount;
|
||||
};
|
||||
|
||||
/*! Array of service structures */
|
||||
@ -271,7 +271,7 @@ int TvDeviceSetServiceTableVar(
|
||||
/*! [in] The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL,
|
||||
* TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT,
|
||||
* TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS). */
|
||||
unsigned int variable,
|
||||
int variable,
|
||||
/*! [in] The string representation of the new value. */
|
||||
char *value);
|
||||
|
||||
|
@ -29,17 +29,14 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "sample_util.h"
|
||||
#include "upnp_tv_ctrlpt.h"
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.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 {
|
||||
PRTHELP = 0, PRTFULLHELP, POWON, POWOFF,
|
||||
SETCHAN, SETVOL, SETCOL, SETTINT, SETCONT, SETBRT,
|
||||
@ -47,21 +44,21 @@ enum cmdloop_tvcmds {
|
||||
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 {
|
||||
char *str; /* the string */
|
||||
int cmdnum; /* the command */
|
||||
int numargs; /* the number of arguments */
|
||||
char *args; /* the args */
|
||||
/* the string */
|
||||
const char *str;
|
||||
/* the command */
|
||||
int cmdnum;
|
||||
/* the number of arguments */
|
||||
int numargs;
|
||||
/* the args */
|
||||
const char *args;
|
||||
} cmdloop_commands;
|
||||
|
||||
/*
|
||||
Mappings between command text names, command tag,
|
||||
and required command arguments for command line
|
||||
commands
|
||||
*/
|
||||
/*! Mappings between command text names, command tag,
|
||||
* and required command arguments for command line
|
||||
* commands */
|
||||
static struct cmdloop_commands cmdloop_cmdlist[] = {
|
||||
{"Help", PRTHELP, 1, ""},
|
||||
{"HelpFull", PRTFULLHELP, 1, ""},
|
||||
@ -83,173 +80,161 @@ static struct cmdloop_commands cmdloop_cmdlist[] = {
|
||||
{"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
|
||||
*
|
||||
* Description:
|
||||
* Print help info for this application.
|
||||
********************************************************************************/
|
||||
void
|
||||
TvCtrlPointPrintShortHelp( void )
|
||||
/*!
|
||||
* \brief Print help info for this application.
|
||||
*/
|
||||
void TvCtrlPointPrintShortHelp(void)
|
||||
{
|
||||
SampleUtil_Print( "Commands:" );
|
||||
SampleUtil_Print( " Help" );
|
||||
SampleUtil_Print( " HelpFull" );
|
||||
SampleUtil_Print( " ListDev" );
|
||||
SampleUtil_Print( " Refresh" );
|
||||
SampleUtil_Print( " PrintDev <devnum>" );
|
||||
SampleUtil_Print( " PowerOn <devnum>" );
|
||||
SampleUtil_Print( " PowerOff <devnum>" );
|
||||
SampleUtil_Print( " SetChannel <devnum> <channel>" );
|
||||
SampleUtil_Print( " SetVolume <devnum> <volume>" );
|
||||
SampleUtil_Print( " SetColor <devnum> <color>" );
|
||||
SampleUtil_Print( " SetTint <devnum> <tint>" );
|
||||
SampleUtil_Print( " SetContrast <devnum> <contrast>" );
|
||||
SampleUtil_Print( " SetBrightness <devnum> <brightness>" );
|
||||
SampleUtil_Print( " CtrlAction <devnum> <action>" );
|
||||
SampleUtil_Print( " PictAction <devnum> <action>" );
|
||||
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" );
|
||||
SampleUtil_Print( " PictGetVar <devnum> <action>" );
|
||||
SampleUtil_Print( " Exit" );
|
||||
SampleUtil_Print(
|
||||
"Commands:\n"
|
||||
" Help\n"
|
||||
" HelpFull\n"
|
||||
" ListDev\n"
|
||||
" Refresh\n"
|
||||
" PrintDev <devnum>\n"
|
||||
" PowerOn <devnum>\n"
|
||||
" PowerOff <devnum>\n"
|
||||
" SetChannel <devnum> <channel>\n"
|
||||
" SetVolume <devnum> <volume>\n"
|
||||
" SetColor <devnum> <color>\n"
|
||||
" SetTint <devnum> <tint>\n"
|
||||
" SetContrast <devnum> <contrast>\n"
|
||||
" SetBrightness <devnum> <brightness>\n"
|
||||
" CtrlAction <devnum> <action>\n"
|
||||
" PictAction <devnum> <action>\n"
|
||||
" CtrlGetVar <devnum> <varname>\n"
|
||||
" PictGetVar <devnum> <action>\n"
|
||||
" Exit\n");
|
||||
}
|
||||
|
||||
void
|
||||
TvCtrlPointPrintLongHelp( void )
|
||||
void TvCtrlPointPrintLongHelp(void)
|
||||
{
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print( "******************************" );
|
||||
SampleUtil_Print( "* TV Control Point Help Info *" );
|
||||
SampleUtil_Print( "******************************" );
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print( "This sample control point application automatically searches" );
|
||||
SampleUtil_Print( "for and subscribes to the services of television device emulator" );
|
||||
SampleUtil_Print( "devices, described in the tvdevicedesc.xml description document." );
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print( "Commands:" );
|
||||
SampleUtil_Print( " Help" );
|
||||
SampleUtil_Print( " Print this help info." );
|
||||
SampleUtil_Print( " ListDev" );
|
||||
SampleUtil_Print( " Print the current list of TV Device Emulators that this" );
|
||||
SampleUtil_Print( " control point is aware of. Each device is preceded by a" );
|
||||
SampleUtil_Print( " device number which corresponds to the devnum argument of" );
|
||||
SampleUtil_Print( " commands listed below." );
|
||||
SampleUtil_Print( " Refresh" );
|
||||
SampleUtil_Print( " Delete all of the devices from the device list and issue new" );
|
||||
SampleUtil_Print( " search request to rebuild the list from scratch." );
|
||||
SampleUtil_Print( " PrintDev <devnum>" );
|
||||
SampleUtil_Print( " Print the state table for the device <devnum>." );
|
||||
SampleUtil_Print( " e.g., 'PrintDev 1' prints the state table for the first" );
|
||||
SampleUtil_Print( " device in the device list." );
|
||||
SampleUtil_Print( " PowerOn <devnum>" );
|
||||
SampleUtil_Print( " Sends the PowerOn action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>." );
|
||||
SampleUtil_Print( " PowerOff <devnum>" );
|
||||
SampleUtil_Print( " Sends the PowerOff action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>." );
|
||||
SampleUtil_Print( " SetChannel <devnum> <channel>" );
|
||||
SampleUtil_Print( " Sends the SetChannel action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the channel to be changed" );
|
||||
SampleUtil_Print( " to <channel>." );
|
||||
SampleUtil_Print( " SetVolume <devnum> <volume>" );
|
||||
SampleUtil_Print( " Sends the SetVolume action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the volume to be changed" );
|
||||
SampleUtil_Print( " to <volume>." );
|
||||
SampleUtil_Print( " SetColor <devnum> <color>" );
|
||||
SampleUtil_Print( " Sends the SetColor action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the color to be changed" );
|
||||
SampleUtil_Print( " to <color>." );
|
||||
SampleUtil_Print( " SetTint <devnum> <tint>" );
|
||||
SampleUtil_Print( " Sends the SetTint action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the tint to be changed" );
|
||||
SampleUtil_Print( " to <tint>." );
|
||||
SampleUtil_Print( " SetContrast <devnum> <contrast>" );
|
||||
SampleUtil_Print( " Sends the SetContrast action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the contrast to be changed" );
|
||||
SampleUtil_Print( " to <contrast>." );
|
||||
SampleUtil_Print( " SetBrightness <devnum> <brightness>" );
|
||||
SampleUtil_Print( " Sends the SetBrightness action to the Control Service of" );
|
||||
SampleUtil_Print( " device <devnum>, requesting the brightness to be changed" );
|
||||
SampleUtil_Print( " to <brightness>." );
|
||||
SampleUtil_Print( " CtrlAction <devnum> <action>" );
|
||||
SampleUtil_Print( " Sends an action request specified by the string <action>" );
|
||||
SampleUtil_Print( " to the Control Service of device <devnum>. This command" );
|
||||
SampleUtil_Print( " only works for actions that have no arguments." );
|
||||
SampleUtil_Print( " (e.g., \"CtrlAction 1 IncreaseChannel\")" );
|
||||
SampleUtil_Print( " PictAction <devnum> <action>" );
|
||||
SampleUtil_Print( " Sends an action request specified by the string <action>" );
|
||||
SampleUtil_Print( " to the Picture Service of device <devnum>. This command" );
|
||||
SampleUtil_Print( " only works for actions that have no arguments." );
|
||||
SampleUtil_Print( " (e.g., \"PictAction 1 DecreaseContrast\")" );
|
||||
SampleUtil_Print( " CtrlGetVar <devnum> <varname>" );
|
||||
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" );
|
||||
SampleUtil_Print( " from the Control Service of device <devnum>." );
|
||||
SampleUtil_Print( " (e.g., \"CtrlGetVar 1 Volume\")" );
|
||||
SampleUtil_Print( " PictGetVar <devnum> <action>" );
|
||||
SampleUtil_Print( " Requests the value of a variable specified by the string <varname>" );
|
||||
SampleUtil_Print( " from the Picture Service of device <devnum>." );
|
||||
SampleUtil_Print( " (e.g., \"PictGetVar 1 Tint\")" );
|
||||
SampleUtil_Print( " Exit" );
|
||||
SampleUtil_Print( " Exits the control point application." );
|
||||
SampleUtil_Print(
|
||||
"\n"
|
||||
"******************************\n"
|
||||
"* TV Control Point Help Info *\n"
|
||||
"******************************\n"
|
||||
"\n"
|
||||
"This sample control point application automatically searches\n"
|
||||
"for and subscribes to the services of television device emulator\n"
|
||||
"devices, described in the tvdevicedesc.xml description document.\n"
|
||||
"It also registers itself as a tv device.\n"
|
||||
"\n"
|
||||
"Commands:\n"
|
||||
" Help\n"
|
||||
" Print this help info.\n"
|
||||
" ListDev\n"
|
||||
" Print the current list of TV Device Emulators that this\n"
|
||||
" control point is aware of. Each device is preceded by a\n"
|
||||
" device number which corresponds to the devnum argument of\n"
|
||||
" commands listed below.\n"
|
||||
" Refresh\n"
|
||||
" Delete all of the devices from the device list and issue new\n"
|
||||
" search request to rebuild the list from scratch.\n"
|
||||
" PrintDev <devnum>\n"
|
||||
" Print the state table for the device <devnum>.\n"
|
||||
" e.g., 'PrintDev 1' prints the state table for the first\n"
|
||||
" device in the device list.\n"
|
||||
" PowerOn <devnum>\n"
|
||||
" Sends the PowerOn action to the Control Service of\n"
|
||||
" device <devnum>.\n"
|
||||
" PowerOff <devnum>\n"
|
||||
" Sends the PowerOff action to the Control Service of\n"
|
||||
" device <devnum>.\n"
|
||||
" SetChannel <devnum> <channel>\n"
|
||||
" Sends the SetChannel action to the Control Service of\n"
|
||||
" device <devnum>, requesting the channel to be changed\n"
|
||||
" to <channel>.\n"
|
||||
" SetVolume <devnum> <volume>\n"
|
||||
" Sends the SetVolume action to the Control Service of\n"
|
||||
" device <devnum>, requesting the volume to be changed\n"
|
||||
" to <volume>.\n"
|
||||
" SetColor <devnum> <color>\n"
|
||||
" Sends the SetColor action to the Control Service of\n"
|
||||
" device <devnum>, requesting the color to be changed\n"
|
||||
" to <color>.\n"
|
||||
" SetTint <devnum> <tint>\n"
|
||||
" Sends the SetTint action to the Control Service of\n"
|
||||
" device <devnum>, requesting the tint to be changed\n"
|
||||
" to <tint>.\n"
|
||||
" SetContrast <devnum> <contrast>\n"
|
||||
" Sends the SetContrast action to the Control Service of\n"
|
||||
" device <devnum>, requesting the contrast to be changed\n"
|
||||
" to <contrast>.\n"
|
||||
" SetBrightness <devnum> <brightness>\n"
|
||||
" Sends the SetBrightness action to the Control Service of\n"
|
||||
" device <devnum>, requesting the brightness to be changed\n"
|
||||
" to <brightness>.\n"
|
||||
" CtrlAction <devnum> <action>\n"
|
||||
" Sends an action request specified by the string <action>\n"
|
||||
" to the Control Service of device <devnum>. This command\n"
|
||||
" only works for actions that have no arguments.\n"
|
||||
" (e.g., \"CtrlAction 1 IncreaseChannel\")\n"
|
||||
" PictAction <devnum> <action>\n"
|
||||
" Sends an action request specified by the string <action>\n"
|
||||
" to the Picture Service of device <devnum>. This command\n"
|
||||
" only works for actions that have no arguments.\n"
|
||||
" (e.g., \"PictAction 1 DecreaseContrast\")\n"
|
||||
" CtrlGetVar <devnum> <varname>\n"
|
||||
" Requests the value of a variable specified by the string <varname>\n"
|
||||
" from the Control Service of device <devnum>.\n"
|
||||
" (e.g., \"CtrlGetVar 1 Volume\")\n"
|
||||
" PictGetVar <devnum> <action>\n"
|
||||
" Requests the value of a variable specified by the string <varname>\n"
|
||||
" from the Picture Service of device <devnum>.\n"
|
||||
" (e.g., \"PictGetVar 1 Tint\")\n"
|
||||
" Exit\n"
|
||||
" Exits the control point application.\n");
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* TvCtrlPointPrintCommands
|
||||
*
|
||||
* Description:
|
||||
* Print the list of valid command line commands to the user
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
********************************************************************************/
|
||||
void
|
||||
TvCtrlPointPrintCommands()
|
||||
/*!
|
||||
* \briefPrint the list of valid command line commands to the user
|
||||
*/
|
||||
void TvCtrlPointPrintCommands()
|
||||
{
|
||||
int i;
|
||||
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands );
|
||||
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
|
||||
|
||||
SampleUtil_Print( "Valid Commands:" );
|
||||
for( i = 0; i < numofcmds; i++ ) {
|
||||
SampleUtil_Print( " %-14s %s", cmdloop_cmdlist[i].str,
|
||||
cmdloop_cmdlist[i].args );
|
||||
SampleUtil_Print("Valid Commands:\n");
|
||||
for (i = 0; i < numofcmds; ++i) {
|
||||
SampleUtil_Print(" %-14s %s\n",
|
||||
cmdloop_cmdlist[i].str, cmdloop_cmdlist[i].args);
|
||||
}
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print("\n");
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* TvCtrlPointCommandLoop
|
||||
*
|
||||
* Description:
|
||||
* Function that receives commands from the user at the command prompt
|
||||
* during the lifetime of the control point, and calls the appropriate
|
||||
/*!
|
||||
* \brief Function that receives commands from the user at the command prompt
|
||||
* during the lifetime of the device, and calls the appropriate
|
||||
* functions for those commands.
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
********************************************************************************/
|
||||
void *
|
||||
TvCtrlPointCommandLoop( void *args )
|
||||
*/
|
||||
void *TvCtrlPointCommandLoop(void *args)
|
||||
{
|
||||
char cmdline[100];
|
||||
|
||||
while( 1 ) {
|
||||
SampleUtil_Print( "\n>> " );
|
||||
fgets( cmdline, 100, stdin );
|
||||
TvCtrlPointProcessCommand( cmdline );
|
||||
while (1) {
|
||||
SampleUtil_Print("\n>> ");
|
||||
fgets(cmdline, 100, stdin);
|
||||
TvCtrlPointProcessCommand(cmdline);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
args = args;
|
||||
}
|
||||
|
||||
int
|
||||
TvCtrlPointProcessCommand( char *cmdline )
|
||||
int TvCtrlPointProcessCommand(char *cmdline)
|
||||
{
|
||||
char cmd[100];
|
||||
char strarg[100];
|
||||
@ -257,151 +242,120 @@ TvCtrlPointProcessCommand( char *cmdline )
|
||||
int arg1 = arg_val_err;
|
||||
int arg2 = arg_val_err;
|
||||
int cmdnum = -1;
|
||||
int numofcmds = sizeof( cmdloop_cmdlist ) / sizeof( cmdloop_commands );
|
||||
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
|
||||
int cmdfound = 0;
|
||||
int i,
|
||||
rc;
|
||||
int i;
|
||||
int rc;
|
||||
int invalidargs = 0;
|
||||
int validargs;
|
||||
|
||||
validargs = sscanf( cmdline, "%s %d %d", cmd, &arg1, &arg2 );
|
||||
|
||||
for( i = 0; i < numofcmds; i++ ) {
|
||||
if( strcasecmp( cmd, cmdloop_cmdlist[i].str ) == 0 ) {
|
||||
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 )
|
||||
if (validargs != cmdloop_cmdlist[i].numargs)
|
||||
invalidargs++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !cmdfound ) {
|
||||
SampleUtil_Print( "Command not found; try 'Help'" );
|
||||
if (!cmdfound) {
|
||||
SampleUtil_Print("Command not found; try 'Help'\n");
|
||||
return TV_SUCCESS;
|
||||
}
|
||||
|
||||
if( invalidargs ) {
|
||||
SampleUtil_Print( "Invalid arguments; try 'Help'" );
|
||||
if (invalidargs) {
|
||||
SampleUtil_Print("Invalid arguments; try 'Help'\n");
|
||||
return TV_SUCCESS;
|
||||
}
|
||||
|
||||
switch ( cmdnum ) {
|
||||
switch (cmdnum) {
|
||||
case PRTHELP:
|
||||
TvCtrlPointPrintShortHelp();
|
||||
break;
|
||||
|
||||
case PRTFULLHELP:
|
||||
TvCtrlPointPrintLongHelp();
|
||||
break;
|
||||
|
||||
case POWON:
|
||||
TvCtrlPointSendPowerOn( arg1 );
|
||||
TvCtrlPointSendPowerOn(arg1);
|
||||
break;
|
||||
|
||||
case POWOFF:
|
||||
TvCtrlPointSendPowerOff( arg1 );
|
||||
TvCtrlPointSendPowerOff(arg1);
|
||||
break;
|
||||
|
||||
case SETCHAN:
|
||||
TvCtrlPointSendSetChannel( arg1, arg2 );
|
||||
TvCtrlPointSendSetChannel(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETVOL:
|
||||
TvCtrlPointSendSetVolume( arg1, arg2 );
|
||||
TvCtrlPointSendSetVolume(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETCOL:
|
||||
TvCtrlPointSendSetColor( arg1, arg2 );
|
||||
TvCtrlPointSendSetColor(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETTINT:
|
||||
TvCtrlPointSendSetTint( arg1, arg2 );
|
||||
TvCtrlPointSendSetTint(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETCONT:
|
||||
TvCtrlPointSendSetContrast( arg1, arg2 );
|
||||
TvCtrlPointSendSetContrast(arg1, arg2);
|
||||
break;
|
||||
|
||||
case SETBRT:
|
||||
TvCtrlPointSendSetBrightness( arg1, arg2 );
|
||||
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 );
|
||||
/* 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( 3 == validargs )
|
||||
TvCtrlPointSendAction( TV_SERVICE_PICTURE, arg1, strarg,
|
||||
NULL, NULL, 0 );
|
||||
/* 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( 3 == validargs )
|
||||
TvCtrlPointGetVar( TV_SERVICE_CONTROL, arg1, strarg );
|
||||
/* 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( 3 == validargs )
|
||||
TvCtrlPointGetVar( TV_SERVICE_PICTURE, arg1, strarg );
|
||||
/* 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 );
|
||||
TvCtrlPointPrintDevice(arg1);
|
||||
break;
|
||||
|
||||
case LSTDEV:
|
||||
TvCtrlPointPrintList();
|
||||
break;
|
||||
|
||||
case REFRESH:
|
||||
TvCtrlPointRefresh();
|
||||
break;
|
||||
|
||||
case EXITCMD:
|
||||
rc = TvCtrlPointStop();
|
||||
exit( rc );
|
||||
exit(rc);
|
||||
break;
|
||||
|
||||
default:
|
||||
SampleUtil_Print( "Command not implemented; see 'Help'" );
|
||||
SampleUtil_Print("Command not implemented; see 'Help'\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if( invalidargs )
|
||||
SampleUtil_Print( "Invalid args in command; see 'Help'" );
|
||||
if(invalidargs)
|
||||
SampleUtil_Print("Invalid args in command; see 'Help'\n");
|
||||
|
||||
return TV_SUCCESS;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
ithread_t cmdloop_thread;
|
||||
@ -412,30 +366,26 @@ int main( int argc, char **argv )
|
||||
#endif
|
||||
int code;
|
||||
|
||||
|
||||
rc = TvCtrlPointStart( linux_print, NULL );
|
||||
if( rc != TV_SUCCESS ) {
|
||||
SampleUtil_Print( "Error starting UPnP TV Control Point" );
|
||||
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 );
|
||||
|
||||
code = ithread_create(&cmdloop_thread, NULL, TvCtrlPointCommandLoop, NULL);
|
||||
#ifdef WIN32
|
||||
ithread_join(cmdloop_thread, NULL);
|
||||
#else
|
||||
/*
|
||||
Catch Ctrl-C and properly shutdown
|
||||
*/
|
||||
sigemptyset( &sigs_to_catch );
|
||||
sigaddset( &sigs_to_catch, SIGINT );
|
||||
sigwait( &sigs_to_catch, &sig );
|
||||
|
||||
SampleUtil_Print( "Shutting down on signal %d...\n", sig );
|
||||
/* Catch Ctrl-C and properly shutdown */
|
||||
sigemptyset(&sigs_to_catch);
|
||||
sigaddset(&sigs_to_catch, SIGINT);
|
||||
sigwait(&sigs_to_catch, &sig);
|
||||
SampleUtil_Print("Shutting down on signal %d...\n", sig);
|
||||
#endif
|
||||
|
||||
rc = TvCtrlPointStop();
|
||||
|
||||
return rc;
|
||||
argc = argc;
|
||||
argv = argv;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
|
||||
var;
|
||||
|
||||
if( NULL == node ) {
|
||||
SampleUtil_Print( "ERROR: TvCtrlPointDeleteNode: Node is empty" );
|
||||
SampleUtil_Print("ERROR: TvCtrlPointDeleteNode: Node is empty\n");
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
@ -107,12 +107,12 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
|
||||
node->device.TvService[service].SID );
|
||||
if( UPNP_E_SUCCESS == rc ) {
|
||||
SampleUtil_Print
|
||||
( "Unsubscribed from Tv %s EventURL with SID=%s",
|
||||
( "Unsubscribed from Tv %s EventURL with SID=%s\n",
|
||||
TvServiceName[service],
|
||||
node->device.TvService[service].SID );
|
||||
} else {
|
||||
SampleUtil_Print
|
||||
( "Error unsubscribing to Tv %s EventURL -- %d",
|
||||
( "Error unsubscribing to Tv %s EventURL -- %d\n",
|
||||
TvServiceName[service], rc );
|
||||
}
|
||||
}
|
||||
@ -152,8 +152,7 @@ int TvCtrlPointRemoveDevice(const char *UDN)
|
||||
|
||||
curdevnode = GlobalDeviceList;
|
||||
if( !curdevnode ) {
|
||||
SampleUtil_Print
|
||||
( "WARNING: TvCtrlPointRemoveDevice: Device list empty" );
|
||||
SampleUtil_Print("WARNING: TvCtrlPointRemoveDevice: Device list empty\n");
|
||||
} else {
|
||||
if( 0 == strcmp( curdevnode->device.UDN, UDN ) ) {
|
||||
GlobalDeviceList = curdevnode->next;
|
||||
@ -236,7 +235,7 @@ TvCtrlPointRefresh( void )
|
||||
*/
|
||||
rc = UpnpSearchAsync( ctrlpt_handle, 5, TvDeviceType, NULL );
|
||||
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;
|
||||
}
|
||||
|
||||
@ -256,10 +255,7 @@ TvCtrlPointRefresh( void )
|
||||
* varname -- The name of the variable to request.
|
||||
*
|
||||
********************************************************************************/
|
||||
int
|
||||
TvCtrlPointGetVar( int service,
|
||||
int devnum,
|
||||
char *varname )
|
||||
int TvCtrlPointGetVar(int service, int devnum, const char *varname)
|
||||
{
|
||||
struct TvDeviceNode *devnode;
|
||||
int rc;
|
||||
@ -276,8 +272,7 @@ TvCtrlPointGetVar( int service,
|
||||
TvCtrlPointCallbackEventHandler,
|
||||
NULL );
|
||||
if( rc != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Error in UpnpGetServiceVarStatusAsync -- %d", rc );
|
||||
SampleUtil_Print("Error in UpnpGetServiceVarStatusAsync -- %d\n", rc);
|
||||
rc = TV_ERROR;
|
||||
}
|
||||
}
|
||||
@ -345,13 +340,13 @@ TvCtrlPointGetBrightness( int devnum )
|
||||
* param_count -- The number of parameters
|
||||
*
|
||||
********************************************************************************/
|
||||
int
|
||||
TvCtrlPointSendAction( int service,
|
||||
int TvCtrlPointSendAction(
|
||||
int service,
|
||||
int devnum,
|
||||
char *actionname,
|
||||
char **param_name,
|
||||
const char *actionname,
|
||||
const char **param_name,
|
||||
char **param_val,
|
||||
int param_count )
|
||||
int param_count)
|
||||
{
|
||||
struct TvDeviceNode *devnode;
|
||||
IXML_Document *actionNode = NULL;
|
||||
@ -372,8 +367,7 @@ TvCtrlPointSendAction( int service,
|
||||
( &actionNode, actionname, TvServiceType[service],
|
||||
param_name[param],
|
||||
param_val[param] ) != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "ERROR: TvCtrlPointSendAction: Trying to add action param" );
|
||||
SampleUtil_Print("ERROR: TvCtrlPointSendAction: Trying to add action param\n");
|
||||
/*return -1; // TBD - BAD! leaves mutex locked */
|
||||
}
|
||||
}
|
||||
@ -386,7 +380,7 @@ TvCtrlPointSendAction( int service,
|
||||
TvCtrlPointCallbackEventHandler, NULL );
|
||||
|
||||
if( rc != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error in UpnpSendActionAsync -- %d", rc );
|
||||
SampleUtil_Print( "Error in UpnpSendActionAsync -- %d\n", rc );
|
||||
rc = TV_ERROR;
|
||||
}
|
||||
}
|
||||
@ -415,8 +409,8 @@ TvCtrlPointSendAction( int service,
|
||||
int
|
||||
TvCtrlPointSendActionNumericArg( int devnum,
|
||||
int service,
|
||||
char *actionName,
|
||||
char *paramName,
|
||||
const char *actionName,
|
||||
const char *paramName,
|
||||
int paramValue )
|
||||
{
|
||||
char param_val_a[50];
|
||||
@ -524,7 +518,7 @@ TvCtrlPointGetDevice( int devnum,
|
||||
}
|
||||
|
||||
if( !tmpdevnode ) {
|
||||
SampleUtil_Print( "Error finding TvDevice number -- %d", devnum );
|
||||
SampleUtil_Print( "Error finding TvDevice number -- %d\n", devnum );
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
@ -550,13 +544,13 @@ TvCtrlPointPrintList()
|
||||
|
||||
ithread_mutex_lock( &DeviceListMutex );
|
||||
|
||||
SampleUtil_Print( "TvCtrlPointPrintList:" );
|
||||
SampleUtil_Print("TvCtrlPointPrintList:\n");
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
while( tmpdevnode ) {
|
||||
SampleUtil_Print( " %3d -- %s", ++i, tmpdevnode->device.UDN );
|
||||
SampleUtil_Print( " %3d -- %s\n", ++i, tmpdevnode->device.UDN );
|
||||
tmpdevnode = tmpdevnode->next;
|
||||
}
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print("\n");
|
||||
ithread_mutex_unlock( &DeviceListMutex );
|
||||
|
||||
return TV_SUCCESS;
|
||||
@ -584,15 +578,13 @@ TvCtrlPointPrintDevice( int devnum )
|
||||
char spacer[15];
|
||||
|
||||
if( devnum <= 0 ) {
|
||||
SampleUtil_Print
|
||||
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d",
|
||||
devnum );
|
||||
SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d\n", devnum);
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
ithread_mutex_lock( &DeviceListMutex );
|
||||
|
||||
SampleUtil_Print( "TvCtrlPointPrintDevice:" );
|
||||
SampleUtil_Print("TvCtrlPointPrintDevice:\n");
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
while( tmpdevnode ) {
|
||||
i++;
|
||||
@ -602,57 +594,35 @@ TvCtrlPointPrintDevice( int devnum )
|
||||
}
|
||||
|
||||
if( !tmpdevnode ) {
|
||||
SampleUtil_Print
|
||||
( "Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d",
|
||||
devnum, i );
|
||||
SampleUtil_Print("Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d\n", devnum, i);
|
||||
} else {
|
||||
SampleUtil_Print( " TvDevice -- %d", devnum );
|
||||
SampleUtil_Print( " | " );
|
||||
SampleUtil_Print( " +- UDN = %s",
|
||||
tmpdevnode->device.UDN );
|
||||
SampleUtil_Print( " +- DescDocURL = %s",
|
||||
tmpdevnode->device.DescDocURL );
|
||||
SampleUtil_Print( " +- FriendlyName = %s",
|
||||
tmpdevnode->device.FriendlyName );
|
||||
SampleUtil_Print( " +- PresURL = %s",
|
||||
tmpdevnode->device.PresURL );
|
||||
SampleUtil_Print( " +- Adver. TimeOut = %d",
|
||||
tmpdevnode->device.AdvrTimeOut );
|
||||
|
||||
SampleUtil_Print(" TvDevice -- %d\n", devnum);
|
||||
SampleUtil_Print(" | \n");
|
||||
SampleUtil_Print(" +- UDN = %s\n" , tmpdevnode->device.UDN);
|
||||
SampleUtil_Print(" +- DescDocURL = %s\n", tmpdevnode->device.DescDocURL);
|
||||
SampleUtil_Print(" +- FriendlyName = %s\n", tmpdevnode->device.FriendlyName);
|
||||
SampleUtil_Print(" +- PresURL = %s\n", tmpdevnode->device.PresURL);
|
||||
SampleUtil_Print(" +- Adver. TimeOut = %d\n", tmpdevnode->device.AdvrTimeOut);
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
if( service < TV_SERVICE_SERVCOUNT - 1 )
|
||||
sprintf( spacer, " | " );
|
||||
if(service < TV_SERVICE_SERVCOUNT - 1)
|
||||
sprintf(spacer, " | ");
|
||||
else
|
||||
sprintf( spacer, " " );
|
||||
SampleUtil_Print( " | " );
|
||||
SampleUtil_Print( " +- Tv %s Service",
|
||||
TvServiceName[service] );
|
||||
SampleUtil_Print( "%s+- ServiceId = %s", spacer,
|
||||
tmpdevnode->device.TvService[service].
|
||||
ServiceId );
|
||||
SampleUtil_Print( "%s+- ServiceType = %s", spacer,
|
||||
tmpdevnode->device.TvService[service].
|
||||
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 );
|
||||
|
||||
sprintf(spacer, " ");
|
||||
SampleUtil_Print(" | ");
|
||||
SampleUtil_Print(" +- Tv %s Service", TvServiceName[service]);
|
||||
SampleUtil_Print("%s+- ServiceId = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceId);
|
||||
SampleUtil_Print("%s+- ServiceType = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceType);
|
||||
SampleUtil_Print("%s+- EventURL = %s\n", spacer, tmpdevnode->device.TvService[service].EventURL);
|
||||
SampleUtil_Print("%s+- ControlURL = %s\n", spacer, tmpdevnode->device.TvService[service].ControlURL);
|
||||
SampleUtil_Print("%s+- SID = %s\n", spacer, tmpdevnode->device.TvService[service].SID);
|
||||
SampleUtil_Print("%s+- ServiceStateTable", spacer);
|
||||
for( var = 0; var < TvVarCount[service]; var++ ) {
|
||||
SampleUtil_Print( "%s +- %-10s = %s", spacer,
|
||||
TvVarName[service][var],
|
||||
tmpdevnode->device.TvService[service].
|
||||
VariableStrVal[var] );
|
||||
SampleUtil_Print("%s +- %-10s = %s\n", spacer, TvVarName[service][var],
|
||||
tmpdevnode->device.TvService[service].VariableStrVal[var]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SampleUtil_Print( "" );
|
||||
SampleUtil_Print("\n");
|
||||
ithread_mutex_unlock( &DeviceListMutex );
|
||||
|
||||
return TV_SUCCESS;
|
||||
@ -710,11 +680,10 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
( baseURL ? baseURL : location ), relURL, presURL);
|
||||
|
||||
if( UPNP_E_SUCCESS != ret )
|
||||
SampleUtil_Print( "Error generating presURL from %s + %s", baseURL,
|
||||
relURL );
|
||||
SampleUtil_Print( "Error generating presURL from %s + %s\n", baseURL, relURL );
|
||||
|
||||
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 */
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
@ -732,45 +701,29 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
tmpdevnode->device.AdvrTimeOut = expires;
|
||||
} else {
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
if( SampleUtil_FindAndParseService
|
||||
( DescDoc, location, TvServiceType[service],
|
||||
if( SampleUtil_FindAndParseService(DescDoc, location, TvServiceType[service],
|
||||
&serviceId[service], &eventURL[service],
|
||||
&controlURL[service] ) ) {
|
||||
SampleUtil_Print( "Subscribing to EventURL %s...",
|
||||
eventURL[service] );
|
||||
|
||||
ret =
|
||||
UpnpSubscribe( ctrlpt_handle, eventURL[service],
|
||||
&TimeOut[service],
|
||||
eventSID[service] );
|
||||
|
||||
&controlURL[service])) {
|
||||
SampleUtil_Print("Subscribing to EventURL %s...\n", eventURL[service]);
|
||||
ret = UpnpSubscribe(ctrlpt_handle, eventURL[service],
|
||||
&TimeOut[service], eventSID[service]);
|
||||
if( ret == UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Subscribed to EventURL with SID=%s",
|
||||
eventSID[service] );
|
||||
SampleUtil_Print("Subscribed to EventURL with SID=%s\n", eventSID[service]);
|
||||
} else {
|
||||
SampleUtil_Print
|
||||
( "Error Subscribing to EventURL -- %d", ret );
|
||||
strcpy( eventSID[service], "" );
|
||||
SampleUtil_Print("Error Subscribing to EventURL -- %d\n", ret);
|
||||
strcpy(eventSID[service], "");
|
||||
}
|
||||
} else {
|
||||
SampleUtil_Print( "Error: Could not find Service: %s",
|
||||
TvServiceType[service] );
|
||||
SampleUtil_Print("Error: Could not find Service: %s\n", 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.DescDocURL, location );
|
||||
strcpy( deviceNode->device.FriendlyName, friendlyName );
|
||||
strcpy( deviceNode->device.PresURL, presURL );
|
||||
deviceNode->device.AdvrTimeOut = expires;
|
||||
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
strcpy( deviceNode->device.TvService[service].ServiceId,
|
||||
serviceId[service] );
|
||||
@ -782,7 +735,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
eventURL[service] );
|
||||
strcpy( deviceNode->device.TvService[service].SID,
|
||||
eventSID[service] );
|
||||
|
||||
for( var = 0; var < TvVarCount[service]; var++ ) {
|
||||
deviceNode->device.TvService[service].
|
||||
VariableStrVal[var] =
|
||||
@ -791,12 +743,9 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
VariableStrVal[var], "" );
|
||||
}
|
||||
}
|
||||
|
||||
deviceNode->next = NULL;
|
||||
|
||||
/* Insert the new device node in the list */
|
||||
if( ( tmpdevnode = GlobalDeviceList ) ) {
|
||||
|
||||
while( tmpdevnode ) {
|
||||
if( tmpdevnode->next ) {
|
||||
tmpdevnode = tmpdevnode->next;
|
||||
@ -808,10 +757,8 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
} else {
|
||||
GlobalDeviceList = deviceNode;
|
||||
}
|
||||
|
||||
/*Notify New Device Added */
|
||||
SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN,
|
||||
DEVICE_ADDED );
|
||||
SampleUtil_StateUpdate(NULL, NULL, deviceNode->device.UDN, DEVICE_ADDED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -827,7 +774,6 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
|
||||
free( baseURL );
|
||||
if( relURL )
|
||||
free( relURL );
|
||||
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
if( serviceId[service] )
|
||||
free( serviceId[service] );
|
||||
@ -871,33 +817,23 @@ TvStateUpdate( char *UDN,
|
||||
j;
|
||||
char *tmpstate = NULL;
|
||||
|
||||
SampleUtil_Print( "Tv State Update (service %d): ", Service );
|
||||
|
||||
/*
|
||||
Find all of the e:property tags in the document
|
||||
*/
|
||||
properties =
|
||||
ixmlDocument_getElementsByTagName( ChangedVariables,
|
||||
"e:property" );
|
||||
SampleUtil_Print( "Tv State Update (service %d):\n", Service );
|
||||
/* Find all of the e:property tags in the document */
|
||||
properties = ixmlDocument_getElementsByTagName(
|
||||
ChangedVariables, "e:property" );
|
||||
if( NULL != properties ) {
|
||||
length = ixmlNodeList_length( properties );
|
||||
for( i = 0; i < length; i++ ) { /* Loop through each property change found */
|
||||
property =
|
||||
( 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++ ) {
|
||||
variables =
|
||||
ixmlElement_getElementsByTagName( property,
|
||||
TvVarName[Service]
|
||||
[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 ) {
|
||||
length1 = ixmlNodeList_length( variables );
|
||||
if( length1 ) {
|
||||
@ -908,21 +844,16 @@ TvStateUpdate( char *UDN,
|
||||
|
||||
if( tmpstate ) {
|
||||
strcpy( State[j], tmpstate );
|
||||
SampleUtil_Print
|
||||
( " Variable Name: %s New Value:'%s'",
|
||||
TvVarName[Service][j], State[j] );
|
||||
SampleUtil_Print(" Variable Name: %s New Value:'%s'\n", TvVarName[Service][j], State[j] );
|
||||
}
|
||||
|
||||
if( tmpstate )
|
||||
free( tmpstate );
|
||||
tmpstate = NULL;
|
||||
}
|
||||
|
||||
ixmlNodeList_free( variables );
|
||||
variables = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ixmlNodeList_free( properties );
|
||||
}
|
||||
@ -955,7 +886,7 @@ void TvCtrlPointHandleEvent(
|
||||
while (tmpdevnode) {
|
||||
for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) {
|
||||
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],
|
||||
evntkey,
|
||||
sid);
|
||||
@ -1000,13 +931,10 @@ void TvCtrlPointHandleSubscribeUpdate(
|
||||
tmpdevnode = GlobalDeviceList;
|
||||
while( tmpdevnode ) {
|
||||
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
|
||||
|
||||
if( strcmp
|
||||
( tmpdevnode->device.TvService[service].EventURL,
|
||||
eventURL ) == 0 ) {
|
||||
SampleUtil_Print
|
||||
( "Received Tv %s Event Renewal for eventURL %s",
|
||||
TvServiceName[service], eventURL );
|
||||
SampleUtil_Print("Received Tv %s Event Renewal for eventURL %s\n", TvServiceName[service], eventURL );
|
||||
strcpy( tmpdevnode->device.TvService[service].SID, sid );
|
||||
break;
|
||||
}
|
||||
@ -1074,14 +1002,14 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Discovery Callback -- %d", errCode);
|
||||
"Error in Discovery Callback -- %d\n", errCode);
|
||||
}
|
||||
|
||||
location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event));
|
||||
errCode = UpnpDownloadXmlDoc(location, &DescDoc);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error obtaining device description from %s -- error = %d",
|
||||
"Error obtaining device description from %s -- error = %d\n",
|
||||
location, errCode);
|
||||
} else {
|
||||
TvCtrlPointAddDevice(
|
||||
@ -1104,11 +1032,11 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
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);
|
||||
SampleUtil_Print("After byebye:");
|
||||
SampleUtil_Print("After byebye:\n");
|
||||
TvCtrlPointPrintList();
|
||||
break;
|
||||
}
|
||||
@ -1117,8 +1045,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
UpnpActionComplete *a_event = (UpnpActionComplete *)Event;
|
||||
int errCode = UpnpActionComplete_get_ErrCode(a_event);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Action Complete Callback -- %d",
|
||||
SampleUtil_Print("Error in Action Complete Callback -- %d\n",
|
||||
errCode);
|
||||
}
|
||||
/* 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);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Get Var Complete Callback -- %d", errCode);
|
||||
"Error in Get Var Complete Callback -- %d\n", errCode);
|
||||
} else {
|
||||
TvCtrlPointHandleGetVar(
|
||||
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);
|
||||
if (errCode != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print(
|
||||
"Error in Event Subscribe Callback -- %d", errCode);
|
||||
"Error in Event Subscribe Callback -- %d\n", errCode);
|
||||
} else {
|
||||
TvCtrlPointHandleSubscribeUpdate(
|
||||
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
|
||||
@ -1177,13 +1104,13 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
|
||||
&TimeOut,
|
||||
newSID);
|
||||
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(
|
||||
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
|
||||
newSID,
|
||||
TimeOut);
|
||||
} else {
|
||||
SampleUtil_Print("Error Subscribing to EventURL -- %d", errCode);
|
||||
SampleUtil_Print("Error Subscribing to EventURL -- %d\n", errCode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1253,18 +1180,14 @@ TvCtrlPointVerifyTimeouts( int incr )
|
||||
ret = UpnpSearchAsync( ctrlpt_handle, incr,
|
||||
curdevnode->device.UDN, NULL );
|
||||
if( ret != UPNP_E_SUCCESS )
|
||||
SampleUtil_Print
|
||||
( "Error sending search request for Device UDN: %s -- err = %d",
|
||||
SampleUtil_Print("Error sending search request for Device UDN: %s -- err = %d\n",
|
||||
curdevnode->device.UDN, ret );
|
||||
}
|
||||
|
||||
prevdevnode = curdevnode;
|
||||
curdevnode = curdevnode->next;
|
||||
}
|
||||
|
||||
}
|
||||
ithread_mutex_unlock( &DeviceListMutex );
|
||||
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
@ -1326,7 +1249,7 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
|
||||
|
||||
rc = UpnpInit(ip_address, port);
|
||||
if (rc != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print("WinCEStart: UpnpInit() Error: %d", rc);
|
||||
SampleUtil_Print("WinCEStart: UpnpInit() Error: %d\n", rc);
|
||||
UpnpFinish();
|
||||
return TV_ERROR;
|
||||
}
|
||||
@ -1342,18 +1265,17 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
|
||||
"\tipaddress = %s port = %u\n",
|
||||
ip_address ? ip_address : "{NULL}",
|
||||
port);
|
||||
|
||||
SampleUtil_Print("Registering Control Point");
|
||||
SampleUtil_Print("Registering Control Point\n");
|
||||
rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler,
|
||||
&ctrlpt_handle, &ctrlpt_handle);
|
||||
if (rc != UPNP_E_SUCCESS) {
|
||||
SampleUtil_Print( "Error registering CP: %d", rc );
|
||||
SampleUtil_Print( "Error registering CP: %d\n", rc );
|
||||
UpnpFinish();
|
||||
|
||||
return TV_ERROR;
|
||||
}
|
||||
|
||||
SampleUtil_Print("Control Point Registered");
|
||||
SampleUtil_Print("Control Point Registered\n");
|
||||
|
||||
TvCtrlPointRefresh();
|
||||
|
||||
|
@ -128,8 +128,8 @@ int TvCtrlPointRemoveAll(void);
|
||||
int TvCtrlPointRefresh(void);
|
||||
|
||||
|
||||
int TvCtrlPointSendAction(int, int, char *, char **, char **, int);
|
||||
int TvCtrlPointSendActionNumericArg(int devnum, int service, char *actionName, char *paramName, int paramValue);
|
||||
int TvCtrlPointSendAction(int, int, const char *, const char **, char **, int);
|
||||
int TvCtrlPointSendActionNumericArg(int devnum, int service, const char *actionName, const char *paramName, int paramValue);
|
||||
int TvCtrlPointSendPowerOn(int devnum);
|
||||
int TvCtrlPointSendPowerOff(int devnum);
|
||||
int TvCtrlPointSendSetChannel(int, int);
|
||||
@ -139,7 +139,7 @@ int TvCtrlPointSendSetTint(int, int);
|
||||
int TvCtrlPointSendSetContrast(int, int);
|
||||
int TvCtrlPointSendSetBrightness(int, int);
|
||||
|
||||
int TvCtrlPointGetVar(int, int, char*);
|
||||
int TvCtrlPointGetVar(int, int, const char *);
|
||||
int TvCtrlPointGetPower(int devnum);
|
||||
int TvCtrlPointGetChannel(int);
|
||||
int TvCtrlPointGetVolume(int);
|
||||
@ -168,4 +168,5 @@ int TvCtrlPointProcessCommand(char *cmdline);
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif //UPNP_TV_CTRLPT_H
|
||||
#endif /* UPNP_TV_CTRLPT_H */
|
||||
|
||||
|
@ -34,69 +34,56 @@
|
||||
#include "upnp_tv_device.h"
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* linux_print
|
||||
*
|
||||
* Description:
|
||||
* Prints a string to standard out.
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
*****************************************************************************/
|
||||
void
|
||||
linux_print( const char *string )
|
||||
/*!
|
||||
* \brief Prints a string to standard out.
|
||||
*/
|
||||
void linux_print(const char *format, ...)
|
||||
{
|
||||
printf( "%s", string );
|
||||
va_list argList;
|
||||
va_start(argList, format);
|
||||
vfprintf(stdout, format, argList);
|
||||
fflush(stdout);
|
||||
va_end(argList);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* TvDeviceCommandLoop
|
||||
*
|
||||
* Description:
|
||||
* Function that receives commands from the user at the command prompt
|
||||
/*!
|
||||
* \brief Function that receives commands from the user at the command prompt
|
||||
* during the lifetime of the device, and calls the appropriate
|
||||
* functions for those commands. Only one command, exit, is currently
|
||||
* defined.
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
*****************************************************************************/
|
||||
void *
|
||||
TvDeviceCommandLoop( void *args )
|
||||
*/
|
||||
void *TvDeviceCommandLoop(void *args)
|
||||
{
|
||||
int stoploop = 0;
|
||||
char cmdline[100];
|
||||
char cmd[100];
|
||||
|
||||
while( !stoploop ) {
|
||||
while (!stoploop) {
|
||||
sprintf( cmdline, " " );
|
||||
sprintf( cmd, " " );
|
||||
|
||||
SampleUtil_Print( "\n>> " );
|
||||
|
||||
SampleUtil_Print("\n>> ");
|
||||
/* Get a command line */
|
||||
fgets( cmdline, 100, stdin );
|
||||
|
||||
sscanf( cmdline, "%s", cmd );
|
||||
|
||||
if( strcasecmp( cmd, "exit" ) == 0 ) {
|
||||
SampleUtil_Print( "Shutting down...\n" );
|
||||
fgets(cmdline, 100, stdin);
|
||||
sscanf(cmdline, "%s", cmd);
|
||||
if( strcasecmp(cmd, "exit") == 0) {
|
||||
SampleUtil_Print("Shutting down...\n");
|
||||
TvDeviceStop();
|
||||
exit( 0 );
|
||||
exit(0);
|
||||
} else {
|
||||
SampleUtil_Print( "\n Unknown command: %s\n\n", cmd );
|
||||
SampleUtil_Print( " Valid Commands:\n" );
|
||||
SampleUtil_Print( " Exit\n\n" );
|
||||
SampleUtil_Print("\n Unknown command: %s\n\n", cmd);
|
||||
SampleUtil_Print(" Valid Commands:\n");
|
||||
SampleUtil_Print(" Exit\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
char *ip_address = NULL,
|
||||
*desc_doc_name = NULL,
|
||||
@ -136,11 +122,10 @@ int main( IN int argc, IN char **argv )
|
||||
sigset_t sigs_to_catch;
|
||||
#endif
|
||||
int code;
|
||||
unsigned int port = 0;
|
||||
unsigned short port = 0;
|
||||
int i = 0;
|
||||
|
||||
SampleUtil_Initialize( linux_print );
|
||||
|
||||
SampleUtil_Initialize(linux_print);
|
||||
/* Parse options */
|
||||
for( i = 1; i < argc; i++ ) {
|
||||
if( strcmp( argv[i], "-ip" ) == 0 ) {
|
||||
@ -171,20 +156,16 @@ int main( IN int argc, IN char **argv )
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
port = ( unsigned short )portTemp;
|
||||
|
||||
TvDeviceStart( ip_address, port, desc_doc_name, web_dir_path, linux_print );
|
||||
port = (unsigned short)portTemp;
|
||||
TvDeviceStart(ip_address, port, desc_doc_name, web_dir_path, linux_print);
|
||||
|
||||
/* start a command loop thread */
|
||||
code = ithread_create( &cmdloop_thread, NULL, TvDeviceCommandLoop, NULL );
|
||||
code = ithread_create(&cmdloop_thread, NULL, TvDeviceCommandLoop, NULL);
|
||||
|
||||
#ifdef WIN32
|
||||
ithread_join(cmdloop_thread, NULL);
|
||||
#else
|
||||
/*
|
||||
Catch Ctrl-C and properly shutdown
|
||||
*/
|
||||
/* Catch Ctrl-C and properly shutdown */
|
||||
sigemptyset( &sigs_to_catch );
|
||||
sigaddset( &sigs_to_catch, SIGINT );
|
||||
sigwait( &sigs_to_catch, &sig );
|
||||
|
@ -116,7 +116,7 @@ static int SetServiceTable(
|
||||
/*! [in,out] service containing table to be set. */
|
||||
INOUT struct TvService *out)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
int i = 0;
|
||||
|
||||
strcpy( out->UDN, UDN );
|
||||
strcpy( out->ServiceId, serviceId );
|
||||
@ -360,7 +360,7 @@ int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *sr_event)
|
||||
int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *cgv_event)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
int j = 0;
|
||||
int getvar_succeeded = 0;
|
||||
|
||||
UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
|
||||
@ -482,8 +482,7 @@ int TvDeviceHandleActionRequest(UpnpActionRequest *ca_event)
|
||||
return UpnpActionRequest_get_ErrCode(ca_event);
|
||||
}
|
||||
|
||||
int TvDeviceSetServiceTableVar(unsigned int service, unsigned int variable,
|
||||
char *value)
|
||||
int TvDeviceSetServiceTableVar(unsigned int service, int variable, char *value)
|
||||
{
|
||||
/*IXML_Document *PropSet= NULL; */
|
||||
|
||||
@ -723,9 +722,7 @@ int TvDeviceSetVolume(IXML_Document *in, IXML_Document **out, const char **error
|
||||
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,
|
||||
TV_CONTROL_VOLUME, value ) ) {
|
||||
@ -786,9 +783,7 @@ static int IncrementVolume(
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the channel goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
sprintf( value, "%d", newvolume );
|
||||
|
||||
@ -839,9 +834,7 @@ int TvDeviceSetColor(IXML_Document *in, IXML_Document **out, const char **errorS
|
||||
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,
|
||||
TV_PICTURE_COLOR, value ) ) {
|
||||
@ -901,9 +894,7 @@ static int IncrementColor(
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the channel goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
sprintf( value, "%d", newcolor );
|
||||
|
||||
@ -955,9 +946,7 @@ int TvDeviceSetTint(IXML_Document *in, IXML_Document **out, const char **errorSt
|
||||
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,
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the channel goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
Vendor-specific code to set the volume goes here
|
||||
*/
|
||||
/* Vendor-specific code to set the volume goes here. */
|
||||
|
||||
if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,
|
||||
TV_PICTURE_CONTRAST, value ) ) {
|
||||
|
@ -169,7 +169,7 @@ struct TvService {
|
||||
/*! . */
|
||||
upnp_action actions[TV_MAXACTIONS];
|
||||
/*! . */
|
||||
unsigned int VariableCount;
|
||||
int VariableCount;
|
||||
};
|
||||
|
||||
/*! Array of service structures */
|
||||
@ -271,7 +271,7 @@ int TvDeviceSetServiceTableVar(
|
||||
/*! [in] The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL,
|
||||
* TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT,
|
||||
* TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS). */
|
||||
unsigned int variable,
|
||||
int variable,
|
||||
/*! [in] The string representation of the new value. */
|
||||
char *value);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user