Sample Code

## Files

file | sample_util.c
file | sample_util.h
file | tv_ctrlpt.c
file | tv_ctrlpt.h
file | tv_device.c
file | tv_device.h

## Data Structures

struct | cmdloop_commands
struct | tv_service
struct | TvDevice
struct | TvDeviceNode
struct | TvService

## Typedefs

typedef void(* | print_string) (const char *string,...)
| Prototype for displaying strings. All printing done by the device, control point, and sample util, ultimately use this to display strings to the user.
typedef void(* | state_update) (const char *varName, const char *varValue, const char *UDN, eventType type)
| Prototype for passing back state changes.

## Enumerations

enum | eventType { STATE_UPDATE = 0 , DEVICE_ADDED = 1 , DEVICE_REMOVED = 2 , GET_VAR_COMPLETE = 3 }

## Functions

int | SampleUtil_Initialize ( print_string print_function)
| Initializes the sample util. Must be called before any sample util functions. May be called multiple times.
int | SampleUtil_RegisterUpdateFunction ( state_update update_function)
int | SampleUtil_Finish ()
| Releases Resources held by sample util.
char * | SampleUtil_GetElementValue ( IXML_Element *element)
| Given a DOM node such as <Channel>11</Channel>, this routine extracts the value (e.g., 11) from the node and returns it as a string. The string must be freed by the caller using free.
IXML_NodeList * | SampleUtil_GetFirstServiceList ( IXML_Document *doc)
| Given a DOM node representing a UPnP Device Description Document, this routine parses the document and finds the first service list (i.e., the service list for the root device). The service list is returned as a DOM node list. The NodeList must be freed using NodeList_free.
char * | SampleUtil_GetFirstDocumentItem ( IXML_Document *doc, const char *item)
| Given a document node, this routine searches for the first element named by the input string item, and returns its value as a string. String must be freed by caller using free.
char * | SampleUtil_GetFirstElementItem ( IXML_Element *element, const char *item)
| Given a DOM element, this routine searches for the first element named by the input string item, and returns its value as a string. The string must be freed using free.
void | SampleUtil_PrintEventType ( Upnp_EventType S)
| Prints a callback event type as a string.
int | SampleUtil_PrintEvent ( Upnp_EventType EventType, const void *Event)
| Prints callback event structure details.
int | SampleUtil_FindAndParseService ( IXML_Document *DescDoc, const char *location, const char *serviceType, char **serviceId, char **eventURL, char **controlURL)
| This routine finds the first occurance of a service in a DOM representation of a description document and parses it. Note that this function currently assumes that the eventURL and controlURL values in the service definitions are full URLs. Relative URLs are not handled here.
int | SampleUtil_Print ( const char *fmt, ...)
| Function emulating printf that ultimately calls the registered print function with the formatted string.
void | SampleUtil_StateUpdate ( const char *varName, const char *varValue, const char *UDN, eventType type)
void | linux_print (const char *format,...)
| Prints a string to standard out.

## Variables

static int | initialize_init = 1
static int | initialize_register = 1
print_string | gPrintFun = NULL
state_update | gStateUpdateFun = NULL
ithread_mutex_t | display_mutex
const char * | TvServiceType []
ithread_mutex_t | display_mutex
print_string | gPrintFun
state_update | gStateUpdateFun

## Control Point Sample Module

enum | cmdloop_tvcmds { PRTHELP = 0 , PRTFULLHELP , POWON , POWOFF , SETCHAN , SETVOL , SETCOL , SETTINT , SETCONT , SETBRT , CTRLACTION , PICTACTION , CTRLGETVAR , PICTGETVAR , PRTDEV , LSTDEV , REFRESH , EXITCMD }
ithread_mutex_t | DeviceListMutex
UpnpClient_Handle | ctrlpt_handle = -1
const char | TvDeviceType [] = "urn:schemas-upnp-org:device:tvdevice:1"
const char * | TvServiceName [] = {"Control", "Picture"}
const char * | TvVarName [2][4]
char | TvVarCount [2]
int | default_timeout = 1801
struct TvDeviceNode * | GlobalDeviceList = NULL
static int | TvCtrlPointTimerLoopRun = 1
| Function that runs in its own thread and monitors advertisement and subscription timeouts for devices in the global device list.
struct cmdloop_commands | cmdloop_commands
static struct cmdloop_commands | cmdloop_cmdlist []
int | TvCtrlPointDeleteNode (struct TvDeviceNode *node)
int | TvCtrlPointRemoveDevice (const char *UDN)
int | TvCtrlPointRemoveAll (void)
int | TvCtrlPointRefresh (void)
int | TvCtrlPointGetVar (int service, int devnum, const char *varname)
int | TvCtrlPointGetPower (int devnum)
int | TvCtrlPointGetChannel (int devnum)
int | TvCtrlPointGetVolume (int devnum)
int | TvCtrlPointGetColor (int devnum)
int | TvCtrlPointGetTint (int devnum)
int | TvCtrlPointGetContrast (int devnum)
int | TvCtrlPointGetBrightness (int devnum)
int | TvCtrlPointSendAction (int service, int devnum, const char *actionname, const char **param_name, char **param_val, int param_count)
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 devnum, int channel)
int | TvCtrlPointSendSetVolume (int devnum, int volume)
int | TvCtrlPointSendSetColor (int devnum, int color)
int | TvCtrlPointSendSetTint (int devnum, int tint)
int | TvCtrlPointSendSetContrast (int devnum, int contrast)
int | TvCtrlPointSendSetBrightness (int devnum, int brightness)
int | TvCtrlPointGetDevice (int devnum, struct TvDeviceNode **devnode)
int | TvCtrlPointPrintList ()
int | TvCtrlPointPrintDevice (int devnum)
void | TvCtrlPointAddDevice (IXML_Document *DescDoc, const char *location, int expires)
void | TvStateUpdate ( char *UDN, int Service, IXML_Document *ChangedVariables, char **State)
| Update a Tv state table. Called when an event is received.
void | TvCtrlPointHandleEvent (const char *sid, int evntkey, IXML_Document *changes)
void | TvCtrlPointHandleSubscribeUpdate (const char *eventURL, const Upnp_SID sid, int timeout)
void | TvCtrlPointHandleGetVar (const char *controlURL, const char *varName, const DOMString varValue)
int | TvCtrlPointCallbackEventHandler (Upnp_EventType EventType, const void *Event, void *Cookie)
void | TvCtrlPointVerifyTimeouts ( int incr)
| Checks the advertisement each device in the global device list.
void * | TvCtrlPointTimerLoop (void *args)
int | TvCtrlPointStart (char *iface, state_update updateFunctionPtr, int combo)
| Call this function to initialize the UPnP library and start the TV Control Point. This function creates a timer thread and provides a callback handler to process any UPnP events that are received.
int | TvCtrlPointStop (void)
void | TvCtrlPointPrintShortHelp (void)
| Print help info for this application.
void | TvCtrlPointPrintLongHelp (void)
| Print long help info for this application.
void | TvCtrlPointPrintCommands (void)
void * | TvCtrlPointCommandLoop (void *args)
| 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.
int | TvCtrlPointProcessCommand (char *cmdline)

## Device Sample API

typedef int(* | upnp_action) (IXML_Document *request, IXML_Document **out, const char **errorString)
| Prototype for all actions. For each action that a service implements, there is a corresponding function with this prototype.
struct TvService | tv_service_table []
UpnpDevice_Handle | device_handle
ithread_mutex_t | TVDevMutex
#define | TV_SERVICE_SERVCOUNT 2
#define | TV_SERVICE_CONTROL 0
#define | TV_SERVICE_PICTURE 1
#define | TV_CONTROL_VARCOUNT 3
#define | TV_CONTROL_POWER 0
#define | TV_CONTROL_CHANNEL 1
#define | TV_CONTROL_VOLUME 2
#define | TV_PICTURE_VARCOUNT 4
#define | TV_PICTURE_COLOR 0
#define | TV_PICTURE_TINT 1
#define | TV_PICTURE_CONTRAST 2
#define | TV_PICTURE_BRIGHTNESS 3
#define | TV_MAX_VAL_LEN 5
#define | TV_MAXVARS TV_PICTURE_VARCOUNT
#define | MAX_COLOR 10
#define | MIN_COLOR 1
#define | MAX_BRIGHTNESS 10
#define | MIN_BRIGHTNESS 1
#define | POWER_ON 1
#define | POWER_OFF 0
#define | MAX_TINT 10
#define | MIN_TINT 1
#define | MAX_VOLUME 10
#define | MIN_VOLUME 1
#define | MAX_CONTRAST 10
#define | MIN_CONTRAST 1
#define | MAX_CHANNEL 100
#define | MIN_CHANNEL 1
#define | MAX_COLOR 10
#define | MIN_COLOR 1
#define | MAX_BRIGHTNESS 10
#define | MIN_BRIGHTNESS 1
#define | POWER_ON 1
#define | POWER_OFF 0
#define | MAX_TINT 10
#define | MIN_TINT 1
#define | MAX_VOLUME 10
#define | MIN_VOLUME 1
#define | MAX_CONTRAST 10
#define | MIN_CONTRAST 1
#define | MAX_CHANNEL 100
#define | MIN_CHANNEL 1
#define | TV_SERVICE_SERVCOUNT 2
#define | TV_SERVICE_CONTROL 0
#define | TV_SERVICE_PICTURE 1
#define | TV_CONTROL_VARCOUNT 3
#define | TV_CONTROL_POWER 0
#define | TV_CONTROL_CHANNEL 1
#define | TV_CONTROL_VOLUME 2
#define | TV_PICTURE_VARCOUNT 4
#define | TV_PICTURE_COLOR 0
#define | TV_PICTURE_TINT 1
#define | TV_PICTURE_CONTRAST 2
#define | TV_PICTURE_BRIGHTNESS 3
#define | TV_MAX_VAL_LEN 5
#define | TV_MAXACTIONS 12
#define | TV_MAXVARS TV_PICTURE_VARCOUNT
#define | IP_MODE_IPV4 1
#define | IP_MODE_IPV6_LLA 2
#define | IP_MODE_IPV6_ULA_GUA 3

## Contro Point Sample API

const char * | TvServiceName []
const char * | TvVarName [2][4]
char | TvVarCount []
struct TvDeviceNode * | GlobalDeviceList
ithread_mutex_t | DeviceListMutex
UpnpClient_Handle | ctrlpt_handle
void | TvCtrlPointPrintHelp (void)
#define | TV_SUCCESS 0
#define | TV_ERROR (-1)
#define | TV_WARNING 1

## Device Sample Module

const char * | tvc_varname [] = {"Power", "Channel", "Volume"}
char | tvc_varval [3][5]
const char * | tvc_varval_def [] = {"1", "1", "5"}
const char * | tvp_varname [] = {"Color", "Tint", "Contrast", "Brightness"}
char | tvp_varval [4][5]
const char * | tvp_varval_def [] = {"5", "5", "5", "5"}
int | default_advr_expire = 100
struct TvService | tv_service_table [2]
UpnpDevice_Handle | device_handle = -1
ithread_mutex_t | TVDevMutex
static int | SetServiceTable (int serviceType, const char *UDN, const char *serviceId, const char *serviceTypeS, struct TvService *out)
| Initializes the service table for the specified service.
int | SetActionTable ( int serviceType, struct TvService *out)
| Initializes the action table for the specified service.
int | TvDeviceStateTableInit ( char *DescDocURL)
| Initialize the device state table for this TvDevice, pulling identifier info from the description Document.
int | TvDeviceHandleSubscriptionRequest ( const UpnpSubscriptionRequest *sr_event)
| Called during a subscription request callback.
int | TvDeviceHandleGetVarRequest ( UpnpStateVarRequest *cgv_event)
| Called during a get variable request callback.
int | TvDeviceHandleActionRequest ( UpnpActionRequest *ca_event)
| Called during an action request callback.
int | TvDeviceSetServiceTableVar ( unsigned int service, int variable, char *value)
| Update the TvDevice service state table, and notify all subscribed control points of the updated state.
static int | TvDeviceSetPower (int on)
| Turn the power on/off, update the TvDevice control service state table, and notify all subscribed control points of the updated state.
int | TvDevicePowerOn ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Turn the power on.
int | TvDevicePowerOff ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Turn the power off.
int | TvDeviceSetChannel ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Change the channel, update the TvDevice control service state table, and notify all subscribed control points of the updated state.
int | IncrementChannel (int incr, IXML_Document *in, IXML_Document **out, const char **errorString)
int | TvDeviceDecreaseChannel ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Decrease the channel.
int | TvDeviceIncreaseChannel ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Increase the channel.
int | TvDeviceSetVolume ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Change the volume, update the TvDevice control service state table, and notify all subscribed control points of the updated state.
static int | IncrementVolume (int incr, IXML_Document *in, IXML_Document **out, const char **errorString)
| Increment the volume. Read the current volume from the state table, add the increment, and then change the volume.
int | TvDeviceIncreaseVolume ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Increase the volume.
int | TvDeviceDecreaseVolume ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Decrease the volume.
int | TvDeviceSetColor ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Change the color, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.
static int | IncrementColor (int incr, IXML_Document *in, IXML_Document **out, const char **errorString)
| Increment the color. Read the current color from the state table, add the increment, and then change the color.
int | TvDeviceDecreaseColor ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Decrease the color.
int | TvDeviceIncreaseColor ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Increase the color.
int | TvDeviceSetTint ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Change the tint, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.
int | IncrementTint (int incr, IXML_Document *in, IXML_Document **out, const char **errorString)
int | TvDeviceIncreaseTint ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Increase tint.
int | TvDeviceDecreaseTint ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Decrease tint.
int | TvDeviceSetContrast ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Change the contrast, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.
static int | IncrementContrast (int incr, IXML_Document *in, IXML_Document **out, const char **errorString)
| Increment the contrast. Read the current contrast from the state table, add the increment, and then change the contrast.
int | TvDeviceIncreaseContrast ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Increase the contrast.
int | TvDeviceDecreaseContrast ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Decrease the contrast.
int | TvDeviceSetBrightness ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Change the brightness, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.
static int | IncrementBrightness (int incr, IXML_Document *in, IXML_Document **out, const char **errorString)
| Increment the brightness. Read the current brightness from the state table, add the increment, and then change the brightness.
int | TvDeviceIncreaseBrightness ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Increase brightnesss.
int | TvDeviceDecreaseBrightness ( IXML_Document *in, IXML_Document **out, const char **errorString)
| Decrease brightnesss.
int | TvDeviceCallbackEventHandler ( Upnp_EventType, const void *Event, void *Cookie)
| The callback handler registered with the SDK while registering root device.
int | TvDeviceStart ( char *iface, unsigned short port, const char *desc_doc_name, const char *web_dir_path, int ip_mode, print_string pfun, int combo)
| Initializes the UPnP Sdk, registers the device, and sends out advertisements.
int | TvDeviceStop (void)
| Stops the device. Uninitializes the sdk.
void * | TvDeviceCommandLoop (void *args)
| 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.
int | device_main (int argc, char *argv[])
| Main entry point for tv device application.
#define | DEFAULT_WEB_DIR "./web"
#define | DESC_URL_SIZE 200

## Detailed Description

## Macro Definition Documentation

## MAX_BRIGHTNESS [1/2]

#define MAX_BRIGHTNESS 10

Brightness constants

## MAX_BRIGHTNESS [2/2]

#define MAX_BRIGHTNESS 10

Brightness constants

## MAX_CHANNEL [1/2]

#define MAX_CHANNEL 100

Channel constants

## MAX_CHANNEL [2/2]

#define MAX_CHANNEL 100

Channel constants

## MAX_COLOR [1/2]

#define MAX_COLOR 10

Color constants

## MAX_COLOR [2/2]

#define MAX_COLOR 10

Color constants

## MAX_CONTRAST [1/2]

#define MAX_CONTRAST 10

Contrast constants

## MAX_CONTRAST [2/2]

#define MAX_CONTRAST 10

Contrast constants

## MAX_TINT [1/2]

#define MAX_TINT 10

Tint constants

## MAX_TINT [2/2]

#define MAX_TINT 10

Tint constants

## MAX_VOLUME [1/2]

#define MAX_VOLUME 10

Volume constants

## MAX_VOLUME [2/2]

#define MAX_VOLUME 10

Volume constants

## POWER_ON [1/2]

#define POWER_ON 1

Power constants

## POWER_ON [2/2]

#define POWER_ON 1

Power constants

## TV_CONTROL_CHANNEL [1/2]

#define TV_CONTROL_CHANNEL 1

Index of channel variable

## TV_CONTROL_CHANNEL [2/2]

#define TV_CONTROL_CHANNEL 1

Index of channel variable

## TV_CONTROL_POWER [1/2]

#define TV_CONTROL_POWER 0

Index of power variable

## TV_CONTROL_POWER [2/2]

#define TV_CONTROL_POWER 0

Index of power variable

## TV_CONTROL_VARCOUNT [1/2]

#define TV_CONTROL_VARCOUNT 3

Number of control variables

## TV_CONTROL_VARCOUNT [2/2]

#define TV_CONTROL_VARCOUNT 3

Number of control variables

## TV_CONTROL_VOLUME [1/2]

#define TV_CONTROL_VOLUME 2

Index of volume variable

## TV_CONTROL_VOLUME [2/2]

#define TV_CONTROL_VOLUME 2

Index of volume variable

## TV_MAX_VAL_LEN [1/2]

#define TV_MAX_VAL_LEN 5

Max value length

## TV_MAX_VAL_LEN [2/2]

#define TV_MAX_VAL_LEN 5

Max value length

## TV_MAXACTIONS

#define TV_MAXACTIONS 12

Max actions

## TV_MAXVARS [1/2]

#define TV_MAXVARS TV_PICTURE_VARCOUNT

This should be the maximum VARCOUNT from above

## TV_MAXVARS [2/2]

#define TV_MAXVARS TV_PICTURE_VARCOUNT

This should be the maximum VARCOUNT from above

## TV_PICTURE_BRIGHTNESS [1/2]

#define TV_PICTURE_BRIGHTNESS 3

Index of brightness variable

## TV_PICTURE_BRIGHTNESS [2/2]

#define TV_PICTURE_BRIGHTNESS 3

Index of brightness variable

## TV_PICTURE_COLOR [1/2]

#define TV_PICTURE_COLOR 0

Index of color variable

## TV_PICTURE_COLOR [2/2]

#define TV_PICTURE_COLOR 0

Index of color variable

## TV_PICTURE_CONTRAST [1/2]

#define TV_PICTURE_CONTRAST 2

Index of contrast variable

## TV_PICTURE_CONTRAST [2/2]

#define TV_PICTURE_CONTRAST 2

Index of contrast variable

## TV_PICTURE_TINT [1/2]

#define TV_PICTURE_TINT 1

Index of tint variable

## TV_PICTURE_TINT [2/2]

#define TV_PICTURE_TINT 1

Index of tint variable

## TV_PICTURE_VARCOUNT [1/2]

#define TV_PICTURE_VARCOUNT 4

Number of picture variables

## TV_PICTURE_VARCOUNT [2/2]

#define TV_PICTURE_VARCOUNT 4

Number of picture variables

## TV_SERVICE_CONTROL [1/2]

#define TV_SERVICE_CONTROL 0

Index of control service

## TV_SERVICE_CONTROL [2/2]

#define TV_SERVICE_CONTROL 0

Index of control service

## TV_SERVICE_PICTURE [1/2]

#define TV_SERVICE_PICTURE 1

Index of picture service

## TV_SERVICE_PICTURE [2/2]

#define TV_SERVICE_PICTURE 1

Index of picture service

## TV_SERVICE_SERVCOUNT [1/2]

#define TV_SERVICE_SERVCOUNT 2

Number of services.

## TV_SERVICE_SERVCOUNT [2/2]

#define TV_SERVICE_SERVCOUNT 2

Number of services.

## Typedef Documentation

## print_string

typedef void(* print_string) ( const char *string, ...)

Prototype for displaying strings. All printing done by the device, control point, and sample util, ultimately use this to display strings to the user.

Parameters

  [in] | string | Format.
  [in] | ... | Arguments.

## state_update

typedef void(* state_update) ( const char *varName, const char *varValue, const char *UDN, eventType type)

Prototype for passing back state changes.

Parameters

  [in] | varName | .
  [in] | varValue | .
  [in] | UDN | .
  [in] | type | .

## upnp_action

typedef int(* upnp_action) ( IXML_Document *request, IXML_Document **out, const char **errorString)

Prototype for all actions. For each action that a service implements, there is a corresponding function with this prototype.

Pointers to these functions, along with action names, are stored in the service table. When an action request comes in the action name is matched, and the appropriate function is called. Each function returns UPNP_E_SUCCESS, on success, and a nonzero error code on failure.

Parameters

  [in] | request | Document of action request.
  [out] | out | Action result.
  [out] | errorString | Error string in case action was unsuccessful.

## Enumeration Type Documentation

## cmdloop_tvcmds

enum cmdloop_tvcmds

Tags for valid commands issued at the command prompt.

## Function Documentation

## device_main()

int device_main | ( | int | argc,
|  | char * | argv[]
| ) |  |

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:

- `-ip` ipaddress
- `-port` port
- `-desc` desc_doc_name
- `-webdir` web_dir_path
- `-help`

References linux_print(), SampleUtil_Initialize(), SampleUtil_Print(), and TvDeviceStart().

## IncrementBrightness()

static int IncrementBrightness | ( | int | incr,
|  | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

static

Increment the brightness. Read the current brightness from the state table, add the increment, and then change the brightness.

Parameters

  [in] | incr | The increment by which to change the brightness.
  [in] | in | action request document.
  [out] | out | action result document.
  [out] | errorString | errorString (in case action was unsuccessful).

References MAX_BRIGHTNESS, SampleUtil_Print(), TV_MAX_VAL_LEN, TV_PICTURE_BRIGHTNESS, TV_SERVICE_PICTURE, tv_service_table, TvDeviceSetServiceTableVar(), TVDevMutex, UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, UpnpAddToActionResponse(), and TvService::VariableStrVal.

Referenced by TvDeviceDecreaseBrightness(), and TvDeviceIncreaseBrightness().

## IncrementColor()

static int IncrementColor | ( | int | incr,
|  | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

static

Increment the color. Read the current color from the state table, add the increment, and then change the color.

Parameters

  [in] | incr | The increment by which to change the volume.
  [in] | in | Action request document.
  [out] | out | Action result document.
  [out] | errorString | Error string in case action was unsuccessful.

References MAX_COLOR, SampleUtil_Print(), TV_MAX_VAL_LEN, TV_PICTURE_COLOR, TV_SERVICE_PICTURE, tv_service_table, TvDeviceSetServiceTableVar(), TVDevMutex, UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, UpnpAddToActionResponse(), and TvService::VariableStrVal.

Referenced by TvDeviceDecreaseColor(), and TvDeviceIncreaseColor().

## IncrementContrast()

static int IncrementContrast | ( | int | incr,
|  | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

static

Increment the contrast. Read the current contrast from the state table, add the increment, and then change the contrast.

Parameters

  [in] | incr | The increment by which to change the volume.
  [in] | in | Action request document.
  [out] | out | Action result document.
  [out] | errorString | Error string in case action was unsuccessful.

References MAX_CONTRAST, SampleUtil_Print(), TV_MAX_VAL_LEN, TV_PICTURE_CONTRAST, TV_SERVICE_PICTURE, tv_service_table, TvDeviceSetServiceTableVar(), TVDevMutex, UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, UpnpAddToActionResponse(), and TvService::VariableStrVal.

Referenced by TvDeviceDecreaseContrast(), and TvDeviceIncreaseContrast().

## IncrementVolume()

static int IncrementVolume | ( | int | incr,
|  | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

static

Increment the volume. Read the current volume from the state table, add the increment, and then change the volume.

Parameters

  [in] | incr | The increment by which to change the volume.
  [in] | in | Action request document.
  [out] | out | Action result document.
  [out] | errorString | Error string in case action was unsuccessful.

References MAX_VOLUME, SampleUtil_Print(), TV_CONTROL_VOLUME, TV_MAX_VAL_LEN, TV_SERVICE_CONTROL, tv_service_table, TvDeviceSetServiceTableVar(), TVDevMutex, UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, UpnpAddToActionResponse(), and TvService::VariableStrVal.

Referenced by TvDeviceDecreaseVolume(), and TvDeviceIncreaseVolume().

## linux_print()

void linux_print | ( | const char * | format,
|  |  | ...
| ) |  |

Prints a string to standard out.

Referenced by device_main().

## SampleUtil_FindAndParseService()

int SampleUtil_FindAndParseService | ( | IXML_Document * | DescDoc,
|  | const char * | location,
|  | const char * | serviceType,
|  | char ** | serviceId,
|  | char ** | eventURL,
|  | char ** | controlURL
| ) |  |

This routine finds the first occurance of a service in a DOM representation of a description document and parses it. Note that this function currently assumes that the eventURL and controlURL values in the service definitions are full URLs. Relative URLs are not handled here.

Parameters

  [in] | DescDoc | The DOM description document.
  [in] | location | The location of the description document.
  [in] | serviceType | The type of service to search for.
  [out] | serviceId | The service ID.
  [out] | eventURL | The event URL for the service.
  [out] | controlURL | The control URL for the service.

References ixmlNodeList_free(), ixmlNodeList_item(), ixmlNodeList_length(), SampleUtil_GetFirstDocumentItem(), SampleUtil_GetFirstElementItem(), SampleUtil_GetFirstServiceList(), SampleUtil_Print(), UPNP_E_SUCCESS, and UpnpResolveURL2().

Referenced by TvDeviceStateTableInit().

## SampleUtil_Finish()

int SampleUtil_Finish | ( |  | ) |

Releases Resources held by sample util.

References display_mutex, gPrintFun, gStateUpdateFun, and UPNP_E_SUCCESS.

Referenced by TvDeviceStop().

## SampleUtil_GetElementValue()

char * SampleUtil_GetElementValue | ( | IXML_Element * | element | ) |

Given a DOM node such as <Channel>11</Channel>, this routine extracts the value (e.g., 11) from the node and returns it as a string. The string must be freed by the caller using free.

Returns
  The DOM node as a string.

Parameters

  [in] | element | The DOM node from which to extract the value.

References ixmlNode_getFirstChild(), ixmlNode_getNodeType(), and ixmlNode_getNodeValue().

Referenced by TvStateUpdate().

## SampleUtil_GetFirstDocumentItem()

char * SampleUtil_GetFirstDocumentItem | ( | IXML_Document * | doc,
|  | const char * | item
| ) |  |

Given a document node, this routine searches for the first element named by the input string item, and returns its value as a string. String must be freed by caller using free.

Parameters

  [in] | doc | The DOM document from which to extract the value.
  [in] | item | The item to search for.

References ixmlDocument_getElementsByTagName(), ixmlNode_getFirstChild(), ixmlNode_getNodeValue(), ixmlNodeList_free(), ixmlNodeList_item(), and SampleUtil_Print().

Referenced by SampleUtil_FindAndParseService(), TvDeviceSetBrightness(), TvDeviceSetChannel(), TvDeviceSetColor(), TvDeviceSetContrast(), TvDeviceSetTint(), TvDeviceSetVolume(), and TvDeviceStateTableInit().

## SampleUtil_GetFirstElementItem()

char * SampleUtil_GetFirstElementItem | ( | IXML_Element * | element,
|  | const char * | item
| ) |  |

Given a DOM element, this routine searches for the first element named by the input string item, and returns its value as a string. The string must be freed using free.

Parameters

  [in] | element | The DOM element from which to extract the value.
  [in] | item | The item to search for.

References ixmlElement_getElementsByTagName(), ixmlNode_getFirstChild(), ixmlNode_getNodeValue(), ixmlNodeList_free(), ixmlNodeList_item(), and SampleUtil_Print().

Referenced by SampleUtil_FindAndParseService().

## SampleUtil_GetFirstServiceList()

IXML_NodeList * SampleUtil_GetFirstServiceList | ( | IXML_Document * | doc | ) |

Given a DOM node representing a UPnP Device Description Document, this routine parses the document and finds the first service list (i.e., the service list for the root device). The service list is returned as a DOM node list. The NodeList must be freed using NodeList_free.

Returns
  The service list is returned as a DOM node list.

Parameters

  [in] | doc | The DOM node from which to extract the service list.

References ixmlDocument_getElementsByTagName(), ixmlElement_getElementsByTagName(), ixmlNodeList_free(), ixmlNodeList_item(), and ixmlNodeList_length().

Referenced by SampleUtil_FindAndParseService().

## SampleUtil_Initialize()

int SampleUtil_Initialize | ( | print_string | print_function | ) |

Initializes the sample util. Must be called before any sample util functions. May be called multiple times.

Parameters

  [in] | print_function | Print function to use in SampleUtil_Print.

References display_mutex, gPrintFun, and UPNP_E_SUCCESS.

Referenced by device_main(), and TvDeviceStart().

## SampleUtil_Print()

int SampleUtil_Print | ( | const char * | fmt,
|  |  | ...
| ) |  |

Function emulating printf that ultimately calls the registered print function with the formatted string.

Provides platform-specific print functionality. This function should be called when you want to print content suitable for console output (i.e., in a large text box or on a screen). If your device/operating system is not supported here, you should add a port.

Returns
  The same as printf.

Parameters

  [in] | fmt | Format (see printf).
  [in] | ... | Format data.

References display_mutex, and gPrintFun.

Referenced by device_main(), IncrementBrightness(), IncrementColor(), IncrementContrast(), IncrementVolume(), SampleUtil_FindAndParseService(), SampleUtil_GetFirstDocumentItem(), SampleUtil_GetFirstElementItem(), SampleUtil_PrintEvent(), SampleUtil_PrintEventType(), TvCtrlPointCommandLoop(), TvCtrlPointPrintCommands(), TvCtrlPointPrintLongHelp(), TvCtrlPointPrintShortHelp(), TvCtrlPointStart(), TvCtrlPointVerifyTimeouts(), TvDeviceCallbackEventHandler(), TvDeviceCommandLoop(), TvDeviceHandleGetVarRequest(), TvDeviceSetBrightness(), TvDeviceSetChannel(), TvDeviceSetColor(), TvDeviceSetContrast(), TvDeviceSetPower(), TvDeviceSetTint(), TvDeviceSetVolume(), TvDeviceStart(), TvDeviceStateTableInit(), and TvStateUpdate().

## SampleUtil_PrintEvent()

int SampleUtil_PrintEvent | ( | Upnp_EventType | EventType,
|  | const void * | Event
| ) |  |

Prints callback event structure details.

Parameters

  [in] | EventType | The type of callback event.
  [in] | Event | The callback event structure.

References display_mutex, ixmlFreeDOMString(), ixmlPrintNode(), SampleUtil_Print(), SampleUtil_PrintEventType(), UPNP_CONTROL_ACTION_COMPLETE, UPNP_CONTROL_ACTION_REQUEST, UPNP_CONTROL_GET_VAR_COMPLETE, UPNP_CONTROL_GET_VAR_REQUEST, UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE, UPNP_DISCOVERY_SEARCH_RESULT, UPNP_DISCOVERY_SEARCH_TIMEOUT, UPNP_EVENT_AUTORENEWAL_FAILED, UPNP_EVENT_RECEIVED, UPNP_EVENT_RENEWAL_COMPLETE, UPNP_EVENT_SUBSCRIBE_COMPLETE, UPNP_EVENT_SUBSCRIPTION_EXPIRED, UPNP_EVENT_SUBSCRIPTION_REQUEST, UPNP_EVENT_UNSUBSCRIBE_COMPLETE, UpnpActionComplete_get_ActionRequest(), UpnpActionComplete_get_ActionResult(), UpnpActionComplete_get_CtrlUrl(), UpnpActionComplete_get_ErrCode(), UpnpActionRequest_get_ActionName(), UpnpActionRequest_get_ActionRequest(), UpnpActionRequest_get_ActionResult(), UpnpActionRequest_get_DevUDN(), UpnpActionRequest_get_ErrCode(), UpnpActionRequest_get_ErrStr(), UpnpActionRequest_get_ServiceID(), UpnpDiscovery_get_Date(), UpnpDiscovery_get_DeviceID(), UpnpDiscovery_get_DeviceType(), UpnpDiscovery_get_ErrCode(), UpnpDiscovery_get_Expires(), UpnpDiscovery_get_Ext(), UpnpDiscovery_get_Location(), UpnpDiscovery_get_Os(), UpnpDiscovery_get_ServiceType(), UpnpDiscovery_get_ServiceVer(), UpnpEvent_get_ChangedVariables(), UpnpEvent_get_EventKey(), UpnpEvent_get_SID(), UpnpEventSubscribe_get_ErrCode(), UpnpEventSubscribe_get_PublisherUrl(), UpnpEventSubscribe_get_SID(), UpnpEventSubscribe_get_TimeOut(), UpnpStateVarComplete_get_CtrlUrl(), UpnpStateVarComplete_get_CurrentVal(), UpnpStateVarComplete_get_ErrCode(), UpnpStateVarComplete_get_StateVarName(), UpnpStateVarRequest_get_CurrentVal(), UpnpStateVarRequest_get_DevUDN(), UpnpStateVarRequest_get_ErrCode(), UpnpStateVarRequest_get_ErrStr(), UpnpStateVarRequest_get_ServiceID(), UpnpStateVarRequest_get_StateVarName(), UpnpString_get_String(), UpnpSubscriptionRequest_get_ServiceId(), UpnpSubscriptionRequest_get_SID(), and UpnpSubscriptionRequest_get_UDN().

Referenced by TvDeviceCallbackEventHandler().

## SampleUtil_PrintEventType()

void SampleUtil_PrintEventType | ( | Upnp_EventType | S | ) |

Prints a callback event type as a string.

Parameters

  [in] | S | The callback event.

References SampleUtil_Print(), UPNP_CONTROL_ACTION_COMPLETE, UPNP_CONTROL_ACTION_REQUEST, UPNP_CONTROL_GET_VAR_COMPLETE, UPNP_CONTROL_GET_VAR_REQUEST, UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE, UPNP_DISCOVERY_SEARCH_RESULT, UPNP_DISCOVERY_SEARCH_TIMEOUT, UPNP_EVENT_AUTORENEWAL_FAILED, UPNP_EVENT_RECEIVED, UPNP_EVENT_RENEWAL_COMPLETE, UPNP_EVENT_SUBSCRIBE_COMPLETE, UPNP_EVENT_SUBSCRIPTION_EXPIRED, UPNP_EVENT_SUBSCRIPTION_REQUEST, and UPNP_EVENT_UNSUBSCRIBE_COMPLETE.

Referenced by SampleUtil_PrintEvent().

## SampleUtil_RegisterUpdateFunction()

int SampleUtil_RegisterUpdateFunction | ( | state_update | update_function | ) |

Parameters

  [in] | update_function | .

References gStateUpdateFun, and UPNP_E_SUCCESS.

Referenced by TvCtrlPointStart().

## SampleUtil_StateUpdate()

void SampleUtil_StateUpdate | ( | const char * | varName,
|  | const char * | varValue,
|  | const char * | UDN,
|  | eventType | type
| ) |  |

Parameters

  [in] | varName | .
  [in] | varValue | .
  [in] | UDN | .
  [in] | type | .

References gStateUpdateFun.

## SetActionTable()

int SetActionTable | ( | int | serviceType,
|  | struct TvService * | out
| ) |  |

Initializes the action table for the specified service.

Note that knowledge of the service description is assumed. Action names are hardcoded.

Parameters

  [in] | serviceType | one of TV_SERVICE_CONTROL or, TV_SERVICE_PICTURE.
  [in,out] | out | service containing action table to set.

References TvService::ActionNames, TvService::actions, TV_SERVICE_CONTROL, TV_SERVICE_PICTURE, TvDeviceDecreaseBrightness(), TvDeviceDecreaseChannel(), TvDeviceDecreaseColor(), TvDeviceDecreaseContrast(), TvDeviceDecreaseTint(), TvDeviceDecreaseVolume(), TvDeviceIncreaseBrightness(), TvDeviceIncreaseChannel(), TvDeviceIncreaseColor(), TvDeviceIncreaseContrast(), TvDeviceIncreaseTint(), TvDeviceIncreaseVolume(), TvDevicePowerOff(), TvDevicePowerOn(), TvDeviceSetBrightness(), TvDeviceSetChannel(), TvDeviceSetColor(), TvDeviceSetContrast(), TvDeviceSetTint(), and TvDeviceSetVolume().

Referenced by SetServiceTable().

## SetServiceTable()

static int SetServiceTable | ( | int | serviceType,
|  | const char * | UDN,
|  | const char * | serviceId,
|  | const char * | serviceTypeS,
|  | struct TvService * | out
| ) |  |

static

Initializes the service table for the specified service.

Parameters

  [in] | serviceType | one of TV_SERVICE_CONTROL or, TV_SERVICE_PICTURE.
  [in] | UDN | UDN of device containing service.
  [in] | serviceId | serviceId of service.
  [in] | serviceTypeS | service type (as specified in Description Document) .
  [in,out] | out | service containing table to be set.

References TvService::ServiceId, TvService::ServiceType, SetActionTable(), TV_CONTROL_VARCOUNT, TV_PICTURE_VARCOUNT, TV_SERVICE_CONTROL, TV_SERVICE_PICTURE, tv_service_table, tvc_varname, tvp_varname, TvService::UDN, TvService::VariableCount, TvService::VariableName, and TvService::VariableStrVal.

Referenced by TvDeviceStateTableInit().

## TvCtrlPointCommandLoop()

void * TvCtrlPointCommandLoop | ( | void * | args | ) |

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.

References SampleUtil_Print().

## TvCtrlPointPrintCommands()

void TvCtrlPointPrintCommands | ( | void |  | ) |

\briefPrint the list of valid command line commands to the user

References cmdloop_cmdlist, and SampleUtil_Print().

## TvCtrlPointPrintLongHelp()

void TvCtrlPointPrintLongHelp | ( | void |  | ) |

Print long help info for this application.

References SampleUtil_Print().

## TvCtrlPointPrintShortHelp()

void TvCtrlPointPrintShortHelp | ( | void |  | ) |

Print help info for this application.

References SampleUtil_Print().

## TvCtrlPointStart()

int TvCtrlPointStart | ( | char * | iface,
|  | state_update | updateFunctionPtr,
|  | int | combo
| ) |  |

Call this function to initialize the UPnP library and start the TV Control Point. This function creates a timer thread and provides a callback handler to process any UPnP events that are received.

Returns
  TV_SUCCESS if everything went well, else TV_ERROR.

References DeviceListMutex, SampleUtil_Print(), SampleUtil_RegisterUpdateFunction(), UPNP_E_SUCCESS, UpnpFinish(), UpnpGetServerIp6Address(), UpnpGetServerIpAddress(), UpnpGetServerPort(), UpnpGetServerPort6(), UpnpGetServerUlaGuaIp6Address(), UpnpGetServerUlaGuaPort6(), UpnpInit2(), and UpnpRegisterClient().

## TvCtrlPointVerifyTimeouts()

void TvCtrlPointVerifyTimeouts | ( | int | incr | ) |

Checks the advertisement each device in the global device list.

If an advertisement expires, the device is removed from the list.

If an advertisement is about to expire, a search request is sent for that device.

Parameters

  [in] | incr | The increment to subtract from the timeouts each time the function is called.

References DeviceListMutex, GlobalDeviceList, SampleUtil_Print(), UPNP_E_SUCCESS, and UpnpSearchAsync().

## TvDeviceCallbackEventHandler()

int TvDeviceCallbackEventHandler | ( | Upnp_EventType | ,
|  | const void * | Event,
|  | void * | Cookie
| ) |  |

The callback handler registered with the SDK while registering root device.

Dispatches the request to the appropriate procedure based on the value of EventType. The four requests handled by the device are:

- 1) Event Subscription requests.
- 2) Get Variable requests.
- 3) Action requests.

Parameters

  [in] | EventType | The type of callback event.
  [in] | Event | Data structure containing event data.
  [in] | Cookie | Optional data specified during callback registration.

References SampleUtil_Print(), SampleUtil_PrintEvent(), TvDeviceHandleActionRequest(), TvDeviceHandleGetVarRequest(), TvDeviceHandleSubscriptionRequest(), UPNP_CONTROL_ACTION_COMPLETE, UPNP_CONTROL_ACTION_REQUEST, UPNP_CONTROL_GET_VAR_COMPLETE, UPNP_CONTROL_GET_VAR_REQUEST, UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE, UPNP_DISCOVERY_SEARCH_RESULT, UPNP_DISCOVERY_SEARCH_TIMEOUT, UPNP_EVENT_RECEIVED, UPNP_EVENT_RENEWAL_COMPLETE, UPNP_EVENT_SUBSCRIBE_COMPLETE, UPNP_EVENT_SUBSCRIPTION_REQUEST, and UPNP_EVENT_UNSUBSCRIBE_COMPLETE.

Referenced by TvDeviceStart().

## TvDeviceCommandLoop()

void * TvDeviceCommandLoop | ( | void * | args | ) |

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.

References SampleUtil_Print(), and TvDeviceStop().

## TvDeviceDecreaseBrightness()

int TvDeviceDecreaseBrightness | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Decrease brightnesss.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementBrightness().

Referenced by SetActionTable().

## TvDeviceDecreaseChannel()

int TvDeviceDecreaseChannel | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Decrease the channel.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

Referenced by SetActionTable().

## TvDeviceDecreaseColor()

int TvDeviceDecreaseColor | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Decrease the color.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementColor().

Referenced by SetActionTable().

## TvDeviceDecreaseContrast()

int TvDeviceDecreaseContrast | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Decrease the contrast.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementContrast().

Referenced by SetActionTable().

## TvDeviceDecreaseTint()

int TvDeviceDecreaseTint | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Decrease tint.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

Referenced by SetActionTable().

## TvDeviceDecreaseVolume()

int TvDeviceDecreaseVolume | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Decrease the volume.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementVolume().

Referenced by SetActionTable().

## TvDeviceHandleActionRequest()

int TvDeviceHandleActionRequest | ( | UpnpActionRequest * | ca_event | ) |

Called during an action request callback.

If the request is for this device and either its control service or picture service, then perform the action and respond.

Parameters

  [in,out] | ca_event | The control action request event structure.

References TvService::ActionNames, TvService::actions, TvService::ServiceId, TV_CONTROL_POWER, TV_MAXACTIONS, TV_SERVICE_CONTROL, TV_SERVICE_PICTURE, tv_service_table, TvService::UDN, UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, UpnpActionRequest_get_ActionName(), UpnpActionRequest_get_ActionRequest(), UpnpActionRequest_get_DevUDN(), UpnpActionRequest_get_ErrCode(), UpnpActionRequest_get_ServiceID(), UpnpActionRequest_set_ActionResult(), UpnpActionRequest_set_ErrCode(), UpnpActionRequest_strcpy_ErrStr(), UpnpString_get_String(), and TvService::VariableStrVal.

Referenced by TvDeviceCallbackEventHandler().

## TvDeviceHandleGetVarRequest()

int TvDeviceHandleGetVarRequest | ( | UpnpStateVarRequest * | cgv_event | ) |

Called during a get variable request callback.

If the request is for this device and either its control service or picture service, then respond with the variable value.

Parameters

  [in,out] | cgv_event | The control get variable request event structure.

References SampleUtil_Print(), TvService::ServiceId, TV_SERVICE_SERVCOUNT, tv_service_table, TVDevMutex, TvService::UDN, UPNP_E_SUCCESS, UpnpStateVarRequest_get_DevUDN(), UpnpStateVarRequest_get_ErrCode(), UpnpStateVarRequest_get_ServiceID(), UpnpStateVarRequest_get_StateVarName(), UpnpStateVarRequest_set_CurrentVal(), UpnpStateVarRequest_set_ErrCode(), UpnpStateVarRequest_strcpy_ErrStr(), UpnpString_get_String(), TvService::VariableCount, TvService::VariableName, and TvService::VariableStrVal.

Referenced by TvDeviceCallbackEventHandler().

## TvDeviceHandleSubscriptionRequest()

int TvDeviceHandleSubscriptionRequest | ( | const UpnpSubscriptionRequest * | sr_event | ) |

Called during a subscription request callback.

If the subscription request is for this device and either its control service or picture service, then accept it.

Parameters

  [in] | sr_event | The subscription request event structure.

References device_handle, TvService::ServiceId, TV_SERVICE_SERVCOUNT, tv_service_table, TVDevMutex, TvService::UDN, UpnpAcceptSubscription(), UpnpAcceptSubscriptionExt(), UpnpAddToPropertySet(), UpnpString_get_String(), UpnpSubscriptionRequest_get_ServiceId(), UpnpSubscriptionRequest_get_SID_cstr(), UpnpSubscriptionRequest_get_UDN_cstr(), TvService::VariableCount, TvService::VariableName, and TvService::VariableStrVal.

Referenced by TvDeviceCallbackEventHandler().

## TvDeviceIncreaseBrightness()

int TvDeviceIncreaseBrightness | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Increase brightnesss.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementBrightness().

Referenced by SetActionTable().

## TvDeviceIncreaseChannel()

int TvDeviceIncreaseChannel | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Increase the channel.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

Referenced by SetActionTable().

## TvDeviceIncreaseColor()

int TvDeviceIncreaseColor | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Increase the color.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementColor().

Referenced by SetActionTable().

## TvDeviceIncreaseContrast()

int TvDeviceIncreaseContrast | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Increase the contrast.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementContrast().

Referenced by SetActionTable().

## TvDeviceIncreaseTint()

int TvDeviceIncreaseTint | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Increase tint.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

Referenced by SetActionTable().

## TvDeviceIncreaseVolume()

int TvDeviceIncreaseVolume | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Increase the volume.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References IncrementVolume().

Referenced by SetActionTable().

## TvDevicePowerOff()

int TvDevicePowerOff | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Turn the power off.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References TV_SERVICE_CONTROL, TvDeviceSetPower(), UPNP_E_INTERNAL_ERROR, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDevicePowerOn()

int TvDevicePowerOn | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Turn the power on.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References POWER_ON, TV_SERVICE_CONTROL, TvDeviceSetPower(), UPNP_E_INTERNAL_ERROR, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDeviceSetBrightness()

int TvDeviceSetBrightness | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Change the brightness, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References MAX_BRIGHTNESS, SampleUtil_GetFirstDocumentItem(), SampleUtil_Print(), TV_PICTURE_BRIGHTNESS, TV_SERVICE_PICTURE, TvDeviceSetServiceTableVar(), UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDeviceSetChannel()

int TvDeviceSetChannel | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Change the channel, update the TvDevice control service state table, and notify all subscribed control points of the updated state.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References MAX_CHANNEL, SampleUtil_GetFirstDocumentItem(), SampleUtil_Print(), TV_CONTROL_CHANNEL, TV_SERVICE_CONTROL, TvDeviceSetServiceTableVar(), UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDeviceSetColor()

int TvDeviceSetColor | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Change the color, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References MAX_COLOR, SampleUtil_GetFirstDocumentItem(), SampleUtil_Print(), TV_PICTURE_COLOR, TV_SERVICE_PICTURE, TvDeviceSetServiceTableVar(), UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDeviceSetContrast()

int TvDeviceSetContrast | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Change the contrast, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References MAX_CONTRAST, SampleUtil_GetFirstDocumentItem(), SampleUtil_Print(), TV_PICTURE_CONTRAST, TV_SERVICE_PICTURE, TvDeviceSetServiceTableVar(), UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDeviceSetPower()

static int TvDeviceSetPower | ( | int | on | ) |

static

Turn the power on/off, update the TvDevice control service state table, and notify all subscribed control points of the updated state.

Parameters

  [in] | on | If 1, turn power on. If 0, turn power off.

References POWER_ON, SampleUtil_Print(), TV_CONTROL_POWER, TV_MAX_VAL_LEN, TV_SERVICE_CONTROL, and TvDeviceSetServiceTableVar().

Referenced by TvDevicePowerOff(), and TvDevicePowerOn().

## TvDeviceSetServiceTableVar()

int TvDeviceSetServiceTableVar | ( | unsigned int | service,
|  | int | variable,
|  | char * | value
| ) |  |

Update the TvDevice service state table, and notify all subscribed control points of the updated state.

Note that since this function blocks on the mutex TVDevMutex, to avoid a hang this function should not be called within any other function that currently has this mutex locked.

Parameters

  [in] | service | The service number (TV_SERVICE_CONTROL or TV_SERVICE_PICTURE).
  [in] | variable | 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).
  [in] | value | The string representation of the new value.

References device_handle, TvService::ServiceId, TV_MAX_VAL_LEN, TV_SERVICE_SERVCOUNT, tv_service_table, TVDevMutex, TvService::UDN, UpnpCreatePropertySet(), UpnpNotify(), UpnpNotifyExt(), TvService::VariableCount, TvService::VariableName, and TvService::VariableStrVal.

Referenced by IncrementBrightness(), IncrementColor(), IncrementContrast(), IncrementVolume(), TvDeviceSetBrightness(), TvDeviceSetChannel(), TvDeviceSetColor(), TvDeviceSetContrast(), TvDeviceSetPower(), TvDeviceSetTint(), and TvDeviceSetVolume().

## TvDeviceSetTint()

int TvDeviceSetTint | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Change the tint, update the TvDevice picture service state table, and notify all subscribed control points of the updated state.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References MAX_TINT, SampleUtil_GetFirstDocumentItem(), SampleUtil_Print(), TV_PICTURE_TINT, TV_SERVICE_PICTURE, TvDeviceSetServiceTableVar(), UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDeviceSetVolume()

int TvDeviceSetVolume | ( | IXML_Document * | in,
|  | IXML_Document ** | out,
|  | const char ** | errorString
| ) |  |

Change the volume, update the TvDevice control service state table, and notify all subscribed control points of the updated state.

Parameters

  [in] | in | Document of action request.
  [in] | out | Action result.
  [out] | errorString | ErrorString in case action was unsuccessful.

References MAX_VOLUME, SampleUtil_GetFirstDocumentItem(), SampleUtil_Print(), TV_CONTROL_VOLUME, TV_SERVICE_CONTROL, TvDeviceSetServiceTableVar(), UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, and UpnpAddToActionResponse().

Referenced by SetActionTable().

## TvDeviceStart()

int TvDeviceStart | ( | char * | iface,
|  | unsigned short | port,
|  | const char * | desc_doc_name,
|  | const char * | web_dir_path,
|  | int | ip_mode,
|  | print_string | pfun,
|  | int | combo
| ) |  |

Initializes the UPnP Sdk, registers the device, and sends out advertisements.

Parameters

  [in] | iface | interface to initialize the sdk (may be NULL) if null, then the first non null interface is used.
  [in] | port | port number to initialize the sdk (may be 0) if zero, then a random number is used.
  [in] | desc_doc_name | name of description document. may be NULL. Default is tvdevicedesc.xml.
  [in] | web_dir_path | path of web directory. may be NULL. Default is ./web (for Linux) or ../tvdevice/web.
  [in] | ip_mode | IP mode: IP_MODE_IPV4, IP_MODE_IPV6_LLA or IP_MODE_IPV6_ULA_GUA. Default is IP_MODE_IPV4.
  [in] | pfun | print function to use.
  [in] | combo | Non-zero if called from the combo application.

References default_advr_expire, device_handle, SampleUtil_Initialize(), SampleUtil_Print(), TvDeviceCallbackEventHandler(), TvDeviceStateTableInit(), TVDevMutex, UPNP_E_INTERNAL_ERROR, UPNP_E_SUCCESS, UpnpFinish(), UpnpGetServerIp6Address(), UpnpGetServerIpAddress(), UpnpGetServerPort(), UpnpGetServerPort6(), UpnpGetServerUlaGuaIp6Address(), UpnpGetServerUlaGuaPort6(), UpnpInit2(), UpnpInitLog(), UpnpRegisterRootDevice3(), UpnpSendAdvertisement(), UpnpSetLogFileNames(), UpnpSetLogLevel(), and UpnpSetWebServerRootDir().

Referenced by device_main().

## TvDeviceStateTableInit()

int TvDeviceStateTableInit | ( | char * | DescDocURL | ) |

Initialize the device state table for this TvDevice, pulling identifier info from the description Document.

Note that knowledge of the service description is assumed. State table variables and default values are currently hardcoded in this file rather than being read from service description documents.

Parameters

  [in] | DescDocURL | The description document URL.

References ixmlDocument_free(), SampleUtil_FindAndParseService(), SampleUtil_GetFirstDocumentItem(), SampleUtil_Print(), SetServiceTable(), TV_SERVICE_CONTROL, TV_SERVICE_PICTURE, tv_service_table, UPNP_E_INVALID_DESC, UPNP_E_SUCCESS, and UpnpDownloadXmlDoc().

Referenced by TvDeviceStart().

## TvDeviceStop()

int TvDeviceStop | ( | void |  | ) |

Stops the device. Uninitializes the sdk.

References device_handle, SampleUtil_Finish(), TVDevMutex, UPNP_E_SUCCESS, UpnpFinish(), and UpnpUnRegisterRootDevice().

Referenced by TvDeviceCommandLoop().

## TvStateUpdate()

void TvStateUpdate | ( | char * | UDN,
|  | int | Service,
|  | IXML_Document * | ChangedVariables,
|  | char ** | State
| ) |  |

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.

Parameters

  [in] | UDN | The UDN of the parent device.
  [in] | Service | The service state table to update.
  [out] | ChangedVariables | DOM document representing the XML received with the event.
  [out] | State | pointer to the state table for the Tv service to update.

References ixmlDocument_getElementsByTagName(), ixmlElement_getElementsByTagName(), ixmlNodeList_free(), ixmlNodeList_item(), ixmlNodeList_length(), SampleUtil_GetElementValue(), SampleUtil_Print(), and TvVarName.

## Variable Documentation

## cmdloop_cmdlist

struct cmdloop_commands cmdloop_cmdlist[]

static

Initial value:
= {{"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, ""}}

Mappings between command text names, command tag, and required command arguments for command line commands

Referenced by TvCtrlPointPrintCommands().

## default_advr_expire

int default_advr_expire = 100

The amount of time (in seconds) before advertisements will expire.

Referenced by TvDeviceStart().

## default_timeout

int default_timeout = 1801

Timeout to request during subscriptions

## device_handle [1/2]

UpnpDevice_Handle device_handle = -1

Device handle supplied by UPnP SDK.

Referenced by gena_process_subscription_renewal_request(), gena_process_subscription_request(), gena_process_unsubscribe_request(), genaInitNotify(), genaInitNotifyExt(), genaNotifyAll(), genaNotifyAllExt(), genaUnregisterDevice(), TvDeviceHandleSubscriptionRequest(), TvDeviceSetServiceTableVar(), TvDeviceStart(), TvDeviceStop(), and UpnpFinish().

## device_handle [2/2]

UpnpDevice_Handle device_handle

extern

Device handle returned from sdk

Device handle supplied by UPnP SDK.

Referenced by gena_process_subscription_renewal_request(), gena_process_subscription_request(), gena_process_unsubscribe_request(), genaInitNotify(), genaInitNotifyExt(), genaNotifyAll(), genaNotifyAllExt(), genaUnregisterDevice(), TvDeviceHandleSubscriptionRequest(), TvDeviceSetServiceTableVar(), TvDeviceStart(), TvDeviceStop(), and UpnpFinish().

## DeviceListMutex [1/2]

ithread_mutex_t DeviceListMutex

Mutex for protecting the global device list in a multi-threaded, asynchronous environment. All functions should lock this mutex before reading or writing the device list.

Referenced by TvCtrlPointStart(), and TvCtrlPointVerifyTimeouts().

## DeviceListMutex [2/2]

ithread_mutex_t DeviceListMutex

extern

Mutex for protecting the global device list in a multi-threaded, asynchronous environment. All functions should lock this mutex before reading or writing the device list.

Referenced by TvCtrlPointStart(), and TvCtrlPointVerifyTimeouts().

## display_mutex [1/2]

ithread_mutex_t display_mutex

mutex to control displaying of events

Referenced by SampleUtil_Finish(), SampleUtil_Initialize(), SampleUtil_Print(), and SampleUtil_PrintEvent().

## display_mutex [2/2]

ithread_mutex_t display_mutex

extern

mutex to control displaying of events

Referenced by SampleUtil_Finish(), SampleUtil_Initialize(), SampleUtil_Print(), and SampleUtil_PrintEvent().

## GlobalDeviceList [1/2]

struct TvDeviceNode* GlobalDeviceList = NULL

The first node in the global device list, or NULL if empty

Referenced by TvCtrlPointVerifyTimeouts().

## GlobalDeviceList [2/2]

struct TvDeviceNode* GlobalDeviceList

extern

The first node in the global device list, or NULL if empty

Referenced by TvCtrlPointVerifyTimeouts().

## gPrintFun [1/2]

print_string gPrintFun = NULL

Function pointers to use for displaying formatted strings. Set on Initialization of device.

Referenced by SampleUtil_Finish(), SampleUtil_Initialize(), and SampleUtil_Print().

## gPrintFun [2/2]

print_string gPrintFun

extern

global print function used by sample util

Function pointers to use for displaying formatted strings. Set on Initialization of device.

Referenced by SampleUtil_Finish(), SampleUtil_Initialize(), and SampleUtil_Print().

## gStateUpdateFun [1/2]

state_update gStateUpdateFun = NULL

global state update function used by smaple util

Referenced by SampleUtil_Finish(), SampleUtil_RegisterUpdateFunction(), and SampleUtil_StateUpdate().

## gStateUpdateFun [2/2]

state_update gStateUpdateFun

extern

global state update function used by smaple util

Referenced by SampleUtil_Finish(), SampleUtil_RegisterUpdateFunction(), and SampleUtil_StateUpdate().

## tv_service_table [1/2]

struct TvService tv_service_table[2]

Global structure for storing the state table for this device.

Referenced by IncrementBrightness(), IncrementColor(), IncrementContrast(), IncrementVolume(), SetServiceTable(), TvDeviceHandleActionRequest(), TvDeviceHandleGetVarRequest(), TvDeviceHandleSubscriptionRequest(), TvDeviceSetServiceTableVar(), and TvDeviceStateTableInit().

## tv_service_table [2/2]

struct TvService tv_service_table[]

extern

Array of service structures

Global structure for storing the state table for this device.

Referenced by IncrementBrightness(), IncrementColor(), IncrementContrast(), IncrementVolume(), SetServiceTable(), TvDeviceHandleActionRequest(), TvDeviceHandleGetVarRequest(), TvDeviceHandleSubscriptionRequest(), TvDeviceSetServiceTableVar(), and TvDeviceStateTableInit().

## tvc_varname

const char* tvc_varname[] = {"Power", "Channel", "Volume"}

Global arrays for storing Tv Control Service variable names, values, and defaults.

Referenced by SetServiceTable().

## TvCtrlPointTimerLoopRun

int TvCtrlPointTimerLoopRun = 1

static

Function that runs in its own thread and monitors advertisement and subscription timeouts for devices in the global device list.

## TvDeviceType

const char TvDeviceType[] = "urn:schemas-upnp-org:device:tvdevice:1"

Device type for tv device.

## TVDevMutex [1/2]

ithread_mutex_t TVDevMutex

Mutex for protecting the global state table data in a multi-threaded, asynchronous environment. All functions should lock this mutex before reading or writing the state table data.

Referenced by IncrementBrightness(), IncrementColor(), IncrementContrast(), IncrementVolume(), TvDeviceHandleGetVarRequest(), TvDeviceHandleSubscriptionRequest(), TvDeviceSetServiceTableVar(), TvDeviceStart(), and TvDeviceStop().

## TVDevMutex [2/2]

ithread_mutex_t TVDevMutex

extern

Mutex for protecting the global state table data in a multi-threaded, asynchronous environment. All functions should lock this mutex before reading or writing the state table data.

Referenced by IncrementBrightness(), IncrementColor(), IncrementContrast(), IncrementVolume(), TvDeviceHandleGetVarRequest(), TvDeviceHandleSubscriptionRequest(), TvDeviceSetServiceTableVar(), TvDeviceStart(), and TvDeviceStop().

## tvp_varname

const char* tvp_varname[] = {"Color", "Tint", "Contrast", "Brightness"}

Global arrays for storing Tv Picture Service variable names, values, and defaults.

Referenced by SetServiceTable().

## TvServiceName [1/2]

const char* TvServiceName[] = {"Control", "Picture"}

Service names.

## TvServiceName [2/2]

const char* TvServiceName[]

extern

Service names.

## TvVarCount

char TvVarCount[2]

Initial value:
= {
3 , 4 }

## TvVarName [1/2]

const char* TvVarName[2][ 4]

Initial value:
= {
{"Power", "Channel", "Volume", ""},
{"Color", "Tint", "Contrast", "Brightness"}}

Global arrays for storing variable names and counts for TvControl and TvPicture services

Referenced by TvStateUpdate().

## TvVarName [2/2]

const char* TvVarName[2][ 4]

extern

Global arrays for storing variable names and counts for TvControl and TvPicture services

Referenced by TvStateUpdate().