samples: More code reorganization.

(cherry picked from commit ef0aa38958)
This commit is contained in:
Marcelo Roberto Jimenez 2010-11-18 12:02:38 -02:00
parent b3fdad3988
commit f088f94803
10 changed files with 1058 additions and 1360 deletions

View File

@ -9,67 +9,6 @@
* \file * \file
*/ */
#ifdef ALLOC_CMD_LINE
/*! Tags for valid commands issued at the command prompt. */
enum cmdloop_tvcmds {
PRTHELP = 0,
PRTFULLHELP,
POWON,
POWOFF,
SETCHAN,
SETVOL,
SETCOL,
SETTINT,
SETCONT,
SETBRT,
CTRLACTION,
PICTACTION,
CTRLGETVAR,
PICTGETVAR,
PRTDEV,
LSTDEV,
REFRESH,
EXITCMD
};
/*! Data structure for parsing commands from the command line. */
struct cmdloop_commands {
/* 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 */
static struct cmdloop_commands cmdloop_cmdlist[] = {
{"Help", PRTHELP, 1, ""},
{"HelpFull", PRTFULLHELP, 1, ""},
{"ListDev", LSTDEV, 1, ""},
{"Refresh", REFRESH, 1, ""},
{"PrintDev", PRTDEV, 2, "<devnum>"},
{"PowerOn", POWON, 2, "<devnum>"},
{"PowerOff", POWOFF, 2, "<devnum>"},
{"SetChannel", SETCHAN, 3, "<devnum> <channel (int)>"},
{"SetVolume", SETVOL, 3, "<devnum> <volume (int)>"},
{"SetColor", SETCOL, 3, "<devnum> <color (int)>"},
{"SetTint", SETTINT, 3, "<devnum> <tint (int)>"},
{"SetContrast", SETCONT, 3, "<devnum> <contrast (int)>"},
{"SetBrightness", SETBRT, 3, "<devnum> <brightness (int)>"},
{"CtrlAction", CTRLACTION, 2, "<devnum> <action (string)>"},
{"PictAction", PICTACTION, 2, "<devnum> <action (string)>"},
{"CtrlGetVar", CTRLGETVAR, 2, "<devnum> <varname (string)>"},
{"PictGetVar", PICTGETVAR, 2, "<devnum> <varname (string)>"},
{"Exit", EXITCMD, 1, ""}
};
#else /* ALLOC_CMD_LINE */
#endif /* ALLOC_CMD_LINE */
#ifdef ALLOC_COMMON_DATA #ifdef ALLOC_COMMON_DATA
/*! Service types for tv services. */ /*! Service types for tv services. */
const char *TvServiceType[] = { const char *TvServiceType[] = {

View File

@ -32,6 +32,10 @@
#include "sample_util.h" #include "sample_util.h"
#define ALLOC_COMMON_DATA
#include "common_data.h"
#include "tv_ctrlpt.h"
#include "tv_device.h"
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>
@ -668,3 +672,15 @@ void SampleUtil_StateUpdate(const char *varName, const char *varValue,
} }
} }
/*!
* \brief Prints a string to standard out.
*/
void linux_print(const char *format, ...)
{
va_list argList;
va_start(argList, format);
vfprintf(stdout, format, argList);
fflush(stdout);
va_end(argList);
}

View File

@ -230,6 +230,16 @@ void SampleUtil_StateUpdate(
/*! [in] . */ /*! [in] . */
eventType type); eventType type);
/*!
* \brief Prints a string to standard out.
*/
void linux_print(const char *format, ...)
#if (__GNUC__ >= 3)
/* This enables printf like format checking by the compiler */
__attribute__((format (__printf__, 1, 2)))
#endif
;
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif /* __cplusplus */ #endif /* __cplusplus */

File diff suppressed because it is too large Load Diff

View File

@ -143,7 +143,23 @@ int TvCtrlPointPrintList(void);
int TvCtrlPointPrintDevice(int); int TvCtrlPointPrintDevice(int);
void TvCtrlPointAddDevice(IXML_Document *, const char *, int); void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString); void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
void TvStateUpdate(char*,int, IXML_Document * , char **);
/*!
* \brief Update a Tv state table. Called when an event is received.
*
* Note: this function is NOT thread save. It must be called from another
* function that has locked the global device list.
**/
void TvStateUpdate(
/*! [in] The UDN of the parent device. */
char *UDN,
/*! [in] The service state table to update. */
int Service,
/*! [out] DOM document representing the XML received with the event. */
IXML_Document *ChangedVariables,
/*! [out] pointer to the state table for the Tv service to update. */
char **State);
void TvCtrlPointHandleEvent(const char *, int, IXML_Document *); void TvCtrlPointHandleEvent(const char *, int, IXML_Document *);
void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int); void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int);
int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *); int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *);
@ -154,6 +170,33 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunction
int TvCtrlPointStop(void); int TvCtrlPointStop(void);
int TvCtrlPointProcessCommand(char *cmdline); int TvCtrlPointProcessCommand(char *cmdline);
/*!
* \brief Print help info for this application.
*/
void TvCtrlPointPrintShortHelp(void);
/*!
* \brief Print long help info for this application.
*/
void TvCtrlPointPrintLongHelp(void);
/*!
* \briefPrint the list of valid command line commands to the user
*/
void TvCtrlPointPrintCommands(void);
/*!
* \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.
*/
void *TvCtrlPointCommandLoop(void *args);
/*!
* \brief
*/
int TvCtrlPointProcessCommand(char *cmdline);
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif #endif

View File

@ -1437,3 +1437,48 @@ int TvDeviceStart(char *ip_address, unsigned short port,
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
int device_main(int argc, char *argv[])
{
unsigned int portTemp = 0;
char *ip_address = NULL;
char *desc_doc_name = NULL;
char *web_dir_path = NULL;
unsigned short port = 0;
int i = 0;
SampleUtil_Initialize(linux_print);
/* Parse options */
for(i = 1; i < argc; i++) {
if (strcmp(argv[i], "-ip") == 0) {
ip_address = argv[++i];
} else if(strcmp(argv[i], "-port") == 0) {
sscanf(argv[++i], "%u", &portTemp);
} else if(strcmp(argv[i], "-desc") == 0) {
desc_doc_name = argv[++i];
} 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"
"\t\te.g.: 192.168.0.4\n"
"\tport: Port number to use for"
" receiving UPnP messages (must match desc. doc)\n"
"\t\te.g.: 5431\n"
"\tdesc_doc_name: name of device description document\n"
"\t\te.g.: tvdevicedesc.xml\n"
"\tweb_dir_path: Filesystem path where web files"
" related to the device are stored\n"
"\t\te.g.: /upnp/sample/tvdevice/web\n");
return 1;
}
}
port = (unsigned short)portTemp;
return TvDeviceStart(ip_address, port, desc_doc_name, web_dir_path,
linux_print, 0);
}

View File

@ -529,6 +529,22 @@ int TvDeviceStart(
/*! [in] Non-zero if called from the combo application. */ /*! [in] Non-zero if called from the combo application. */
int combo); int combo);
/*!
* \brief Main entry point for tv device application.
*
* Initializes and registers with the sdk.
* Initializes the state stables of the service.
* Starts the command loop.
*
* Accepts the following optional arguments:
* \li \c -ip ipaddress
* \li \c -port port
* \li \c -desc desc_doc_name
* \li \c -webdir web_dir_path"
* \li \c -help
*/
int device_main(int argc, char *argv[]);
/*! /*!
* \brief Stops the device. Uninitializes the sdk. * \brief Stops the device. Uninitializes the sdk.
*/ */

View File

@ -29,334 +29,15 @@
* *
******************************************************************************/ ******************************************************************************/
#define ALLOC_CMD_LINE
#define ALLOC_COMMON_DATA
#include "common_data.h" #include "common_data.h"
#include "sample_util.h" #include "sample_util.h"
#include "tv_ctrlpt.h" #include "tv_ctrlpt.h"
#include "tv_device.h" #include "tv_device.h"
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
/*! int main(int argc, char *argv[])
* \brief Prints a string to standard out.
*/
void linux_print(const char *format, ...)
{
va_list argList;
va_start(argList, format);
vfprintf(stdout, format, argList);
fflush(stdout);
va_end(argList);
}
/*!
* \brief Print help info for this application.
*/
void TvCtrlPointPrintShortHelp(void)
{
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)
{
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");
}
/*!
* \briefPrint the list of valid command line commands to the user
*/
void TvCtrlPointPrintCommands()
{
int i;
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
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("\n");
}
/*!
* \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.
*/
void *TvCtrlPointCommandLoop(void *args)
{
char cmdline[100];
while (1) {
SampleUtil_Print("\n>> ");
fgets(cmdline, 100, stdin);
TvCtrlPointProcessCommand(cmdline);
}
return NULL;
args = args;
}
int TvCtrlPointProcessCommand(char *cmdline)
{
char cmd[100];
char strarg[100];
int arg_val_err = -99999;
int arg1 = arg_val_err;
int arg2 = arg_val_err;
int cmdnum = -1;
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
int cmdfound = 0;
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) {
cmdnum = cmdloop_cmdlist[i].cmdnum;
cmdfound++;
if (validargs != cmdloop_cmdlist[i].numargs)
invalidargs++;
break;
}
}
if (!cmdfound) {
SampleUtil_Print("Command not found; try 'Help'\n");
return TV_SUCCESS;
}
if (invalidargs) {
SampleUtil_Print("Invalid arguments; try 'Help'\n");
return TV_SUCCESS;
}
switch (cmdnum) {
case PRTHELP:
TvCtrlPointPrintShortHelp();
break;
case PRTFULLHELP:
TvCtrlPointPrintLongHelp();
break;
case POWON:
TvCtrlPointSendPowerOn(arg1);
break;
case POWOFF:
TvCtrlPointSendPowerOff(arg1);
break;
case SETCHAN:
TvCtrlPointSendSetChannel(arg1, arg2);
break;
case SETVOL:
TvCtrlPointSendSetVolume(arg1, arg2);
break;
case SETCOL:
TvCtrlPointSendSetColor(arg1, arg2);
break;
case SETTINT:
TvCtrlPointSendSetTint(arg1, arg2);
break;
case SETCONT:
TvCtrlPointSendSetContrast(arg1, arg2);
break;
case SETBRT:
TvCtrlPointSendSetBrightness(arg1, arg2);
break;
case CTRLACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_CONTROL, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case PICTACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_PICTURE, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case CTRLGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_CONTROL, arg1, strarg);
else
invalidargs++;
break;
case PICTGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_PICTURE, arg1, strarg);
else
invalidargs++;
break;
case PRTDEV:
TvCtrlPointPrintDevice(arg1);
break;
case LSTDEV:
TvCtrlPointPrintList();
break;
case REFRESH:
TvCtrlPointRefresh();
break;
case EXITCMD:
rc = TvCtrlPointStop();
exit(rc);
break;
default:
SampleUtil_Print("Command not implemented; see 'Help'\n");
break;
}
if(invalidargs)
SampleUtil_Print("Invalid args in command; see 'Help'\n");
return TV_SUCCESS;
}
int device_main(int argc, char **argv)
{
unsigned int portTemp = 0;
char *ip_address = NULL,
*desc_doc_name = NULL,
*web_dir_path = NULL;
unsigned short port = 0;
int i = 0;
SampleUtil_Initialize(linux_print);
/* Parse options */
for( i = 1; i < argc; i++ ) {
if( strcmp( argv[i], "-ip" ) == 0 ) {
ip_address = argv[++i];
} else if( strcmp( argv[i], "-port" ) == 0 ) {
sscanf( argv[++i], "%u", &portTemp );
} else if( strcmp( argv[i], "-desc" ) == 0 ) {
desc_doc_name = argv[++i];
} 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\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, 1);
}
int main(int argc, char **argv)
{ {
int rc; int rc;
ithread_t cmdloop_thread; ithread_t cmdloop_thread;

View File

@ -29,8 +29,6 @@
* *
******************************************************************************/ ******************************************************************************/
#define ALLOC_CMD_LINE
#define ALLOC_COMMON_DATA
#include "common_data.h" #include "common_data.h"
#include "sample_util.h" #include "sample_util.h"
#include "tv_ctrlpt.h" #include "tv_ctrlpt.h"
@ -39,281 +37,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
/*!
* \brief Prints a string to standard out.
*/
void linux_print(const char *format, ...)
{
va_list argList;
va_start(argList, format);
vfprintf(stdout, format, argList);
fflush(stdout);
va_end(argList);
}
/*!
* \brief Print help info for this application.
*/
void TvCtrlPointPrintShortHelp(void)
{
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)
{
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");
}
/*!
* \briefPrint the list of valid command line commands to the user
*/
void TvCtrlPointPrintCommands()
{
int i;
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
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("\n");
}
/*!
* \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.
*/
void *TvCtrlPointCommandLoop(void *args)
{
char cmdline[100];
while (1) {
SampleUtil_Print("\n>> ");
fgets(cmdline, 100, stdin);
TvCtrlPointProcessCommand(cmdline);
}
return NULL;
args = args;
}
int TvCtrlPointProcessCommand(char *cmdline)
{
char cmd[100];
char strarg[100];
int arg_val_err = -99999;
int arg1 = arg_val_err;
int arg2 = arg_val_err;
int cmdnum = -1;
int numofcmds = (sizeof cmdloop_cmdlist) / sizeof (cmdloop_commands);
int cmdfound = 0;
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) {
cmdnum = cmdloop_cmdlist[i].cmdnum;
cmdfound++;
if (validargs != cmdloop_cmdlist[i].numargs)
invalidargs++;
break;
}
}
if (!cmdfound) {
SampleUtil_Print("Command not found; try 'Help'\n");
return TV_SUCCESS;
}
if (invalidargs) {
SampleUtil_Print("Invalid arguments; try 'Help'\n");
return TV_SUCCESS;
}
switch (cmdnum) {
case PRTHELP:
TvCtrlPointPrintShortHelp();
break;
case PRTFULLHELP:
TvCtrlPointPrintLongHelp();
break;
case POWON:
TvCtrlPointSendPowerOn(arg1);
break;
case POWOFF:
TvCtrlPointSendPowerOff(arg1);
break;
case SETCHAN:
TvCtrlPointSendSetChannel(arg1, arg2);
break;
case SETVOL:
TvCtrlPointSendSetVolume(arg1, arg2);
break;
case SETCOL:
TvCtrlPointSendSetColor(arg1, arg2);
break;
case SETTINT:
TvCtrlPointSendSetTint(arg1, arg2);
break;
case SETCONT:
TvCtrlPointSendSetContrast(arg1, arg2);
break;
case SETBRT:
TvCtrlPointSendSetBrightness(arg1, arg2);
break;
case CTRLACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_CONTROL, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case PICTACTION:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointSendAction(TV_SERVICE_PICTURE, arg1, strarg,
NULL, NULL, 0);
else
invalidargs++;
break;
case CTRLGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_CONTROL, arg1, strarg);
else
invalidargs++;
break;
case PICTGETVAR:
/* re-parse commandline since second arg is string. */
validargs = sscanf(cmdline, "%s %d %s", cmd, &arg1, strarg);
if (validargs == 3)
TvCtrlPointGetVar(TV_SERVICE_PICTURE, arg1, strarg);
else
invalidargs++;
break;
case PRTDEV:
TvCtrlPointPrintDevice(arg1);
break;
case LSTDEV:
TvCtrlPointPrintList();
break;
case REFRESH:
TvCtrlPointRefresh();
break;
case EXITCMD:
rc = TvCtrlPointStop();
exit(rc);
break;
default:
SampleUtil_Print("Command not implemented; see 'Help'\n");
break;
}
if(invalidargs)
SampleUtil_Print("Invalid args in command; see 'Help'\n");
return TV_SUCCESS;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int rc; int rc;

View File

@ -29,7 +29,6 @@
* *
******************************************************************************/ ******************************************************************************/
#define ALLOC_COMMON_DATA
#include "common_data.h" #include "common_data.h"
#include "sample_util.h" #include "sample_util.h"
#include "tv_device.h" #include "tv_device.h"
@ -37,18 +36,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
/*!
* \brief Prints a string to standard out.
*/
void linux_print(const char *format, ...)
{
va_list argList;
va_start(argList, format);
vfprintf(stdout, format, argList);
fflush(stdout);
va_end(argList);
}
/*! /*!
* \brief 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 * during the lifetime of the device, and calls the appropriate
@ -85,26 +72,8 @@ void *TvDeviceCommandLoop(void *args)
args = args; args = args;
} }
/*!
* \brief Main entry point for tv device application.
*
* Initializes and registers with the sdk.
* Initializes the state stables of the service.
* Starts the command loop.
*
* Accepts the following optional arguments:
* \li \c -ip ipaddress
* \li \c -port port
* \li \c -desc desc_doc_name
* \li \c -webdir web_dir_path"
* \li \c -help
*/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
unsigned int portTemp = 0;
char *ip_address = NULL;
char *desc_doc_name = NULL;
char *web_dir_path = NULL;
int rc; int rc;
ithread_t cmdloop_thread; ithread_t cmdloop_thread;
#ifdef WIN32 #ifdef WIN32
@ -113,43 +82,8 @@ int main(int argc, char *argv[])
sigset_t sigs_to_catch; sigset_t sigs_to_catch;
#endif #endif
int code; int code;
unsigned short port = 0;
int i = 0;
SampleUtil_Initialize(linux_print); device_main(argc, argv);
/* Parse options */
for(i = 1; i < argc; i++) {
if (strcmp(argv[i], "-ip") == 0) {
ip_address = argv[++i];
} else if(strcmp(argv[i], "-port") == 0) {
sscanf(argv[++i], "%u", &portTemp);
} else if(strcmp(argv[i], "-desc") == 0) {
desc_doc_name = argv[++i];
} 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"
"\t\te.g.: 192.168.0.4\n"
"\tport: Port number to use for"
" receiving UPnP messages (must match desc. doc)\n"
"\t\te.g.: 5431\n"
"\tdesc_doc_name: name of device description document\n"
"\t\te.g.: tvdevicedesc.xml\n"
"\tweb_dir_path: Filesystem path where web files"
" related to the device are stored\n"
"\t\te.g.: /upnp/sample/tvdevice/web\n");
return 1;
}
}
port = (unsigned short)portTemp;
TvDeviceStart(ip_address, port, desc_doc_name, web_dir_path,
linux_print, 0);
/* start a command loop thread */ /* start a command loop thread */
code = ithread_create(&cmdloop_thread, NULL, TvDeviceCommandLoop, NULL); code = ithread_create(&cmdloop_thread, NULL, TvDeviceCommandLoop, NULL);
#ifdef WIN32 #ifdef WIN32