libUPnP  1.6.17
Data Structures | Files | Defines | Typedefs | Enumerations | Functions | Variables
Sample Code

Data Structures

struct  cmdloop_commands
struct  tv_service
struct  TvDevice
struct  TvDeviceNode
struct  TvService

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

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_NodeListSampleUtil_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,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 TvDeviceNodeGlobalDeviceList = 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, void *Event, void *Cookie)
void TvCtrlPointVerifyTimeouts (int incr)
 Checks the advertisement each device in the global device list.
void * TvCtrlPointTimerLoop (void *args)
int TvCtrlPointStart (print_string printFunctionPtr, 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)

Contro Point Sample API

const char * TvServiceName []
const char * TvVarName [2][4]
char TvVarCount []
struct TvDeviceNodeGlobalDeviceList
ithread_mutex_t DeviceListMutex
UpnpClient_Handle ctrlpt_handle
void TvCtrlPointPrintHelp (void)
#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_SUCCESS   0
#define TV_ERROR   (-1)
#define TV_WARNING   1
#define TV_MAXVARS   TV_PICTURE_VARCOUNT

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 (struct Upnp_Subscription_Request *sr_event)
 Called during a subscription request callback.
int TvDeviceHandleGetVarRequest (struct Upnp_State_Var_Request *cgv_event)
 Called during a get variable request callback.
int TvDeviceHandleActionRequest (struct Upnp_Action_Request *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, IN 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 (IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT const char **errorString)
int TvDeviceIncreaseTint (IN IXML_Document *in, OUT IXML_Document **out, OUT const char **errorString)
int TvDeviceDecreaseTint (IN IXML_Document *in, OUT IXML_Document **out, OUT const char **errorString)
int TvDeviceSetContrast (IN IXML_Document *in, OUT IXML_Document **out, OUT const char **errorString)
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,void *Event,void *Cookie)
 The callback handler registered with the SDK while registering root device.
int TvDeviceStart (char *ip_address,unsigned short port,const char *desc_doc_name,const char *web_dir_path,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
#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

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
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.
#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 Documentation

#define MAX_BRIGHTNESS   10

Brightness constants

#define MAX_BRIGHTNESS   10

Brightness constants

Referenced by IncrementBrightness(), and TvDeviceSetBrightness().

#define MAX_CHANNEL   100

Channel constants

#define MAX_CHANNEL   100

Channel constants

Referenced by TvDeviceSetChannel().

#define MAX_COLOR   10

Color constants

#define MAX_COLOR   10

Color constants

Referenced by IncrementColor(), and TvDeviceSetColor().

#define MAX_CONTRAST   10

Contrast constants

#define MAX_CONTRAST   10

Contrast constants

#define MAX_TINT   10

Tint constants

#define MAX_TINT   10

Tint constants

Referenced by TvDeviceSetTint().

#define MAX_VOLUME   10

Volume constants

#define MAX_VOLUME   10

Volume constants

Referenced by IncrementVolume(), and TvDeviceSetVolume().

#define POWER_ON   1

Power constants

#define POWER_ON   1

Power constants

Referenced by TvDevicePowerOn(), and TvDeviceSetPower().

#define TV_CONTROL_CHANNEL   1

Index of channel variable

Referenced by TvDeviceSetChannel().

#define TV_CONTROL_POWER   0

Index of power variable

Referenced by TvDeviceHandleActionRequest(), and TvDeviceSetPower().

#define TV_CONTROL_VARCOUNT   3

Number of control variables

Referenced by SetServiceTable().

#define TV_CONTROL_VOLUME   2

Index of volume variable

Referenced by IncrementVolume(), and TvDeviceSetVolume().

#define TV_MAX_VAL_LEN   5
#define TV_MAXACTIONS   12

Max actions

Referenced by TvDeviceHandleActionRequest().

This should be the maximum VARCOUNT from above

#define TV_PICTURE_BRIGHTNESS   3

Index of brightness variable

Referenced by IncrementBrightness(), and TvDeviceSetBrightness().

#define TV_PICTURE_COLOR   0

Index of color variable

Referenced by IncrementColor(), and TvDeviceSetColor().

#define TV_PICTURE_CONTRAST   2

Index of contrast variable

Referenced by IncrementContrast().

#define TV_PICTURE_TINT   1

Index of tint variable

Referenced by TvDeviceSetTint().

#define TV_PICTURE_VARCOUNT   4

Number of picture variables

Referenced by SetServiceTable().

#define TV_SERVICE_CONTROL   0
#define TV_SERVICE_PICTURE   1
#define TV_SERVICE_SERVCOUNT   2

Typedef Documentation

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.

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.


Enumeration Type Documentation

Tags for valid commands issued at the command prompt.


Function Documentation

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().

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]incrThe increment by which to change the brightness.
[in]inaction request document.
[out]outaction result document.
[out]errorStringerrorString (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().

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]incrThe increment by which to change the volume.
[in]inAction request document.
[out]outAction result document.
[out]errorStringError 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().

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]incrThe increment by which to change the volume.
[in]inAction request document.
[out]outAction result document.
[out]errorStringError string in case action was unsuccessful.

References 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().

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]incrThe increment by which to change the volume.
[in]inAction request document.
[out]outAction result document.
[out]errorStringError 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().

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

Prints a string to standard out.

Referenced by device_main().

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]DescDocThe DOM description document.
[in]locationThe location of the description document.
[in]serviceTypeThe type of service to search for.
[out]serviceIdThe service ID.
[out]eventURLThe event URL for the service.
[out]controlURLThe control URL for the service.

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

Referenced by TvDeviceStateTableInit().

Releases Resources held by sample util.

References display_mutex, gPrintFun, gStateUpdateFun, and UPNP_E_SUCCESS.

Referenced by TvDeviceStop().

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]elementThe DOM node from which to extract the value.

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

Referenced by TvStateUpdate().

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]docThe DOM document from which to extract the value.
[in]itemThe 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(), TvDeviceSetTint(), TvDeviceSetVolume(), and TvDeviceStateTableInit().

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]elementThe DOM element from which to extract the value.
[in]itemThe item to search for.

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

Referenced by SampleUtil_FindAndParseService().

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]docThe 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().

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_functionPrint function to use in SampleUtil_Print.

References display_mutex, gPrintFun, and UPNP_E_SUCCESS.

Referenced by device_main(), TvCtrlPointStart(), and TvDeviceStart().

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]fmtFormat (see printf).

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(), TvDeviceSetPower(), TvDeviceSetTint(), TvDeviceSetVolume(), TvDeviceStart(), TvDeviceStateTableInit(), and TvStateUpdate().

int SampleUtil_PrintEvent ( Upnp_EventType  EventType,
void *  Event 
)

Prints callback event structure details.

Parameters:
[in]EventTypeThe type of callback event.
[in]EventThe callback event structure.

References Upnp_Action_Request::ActionName, Upnp_Action_Request::ActionRequest, Upnp_Action_Complete::ActionRequest, Upnp_Action_Request::ActionResult, Upnp_Action_Complete::ActionResult, Upnp_Event::ChangedVariables, Upnp_Action_Complete::CtrlUrl, Upnp_State_Var_Complete::CtrlUrl, Upnp_State_Var_Request::CurrentVal, Upnp_State_Var_Complete::CurrentVal, Upnp_Discovery::DeviceId, Upnp_Discovery::DeviceType, Upnp_Action_Request::DevUDN, Upnp_State_Var_Request::DevUDN, display_mutex, Upnp_Action_Request::ErrCode, Upnp_Action_Complete::ErrCode, Upnp_State_Var_Request::ErrCode, Upnp_State_Var_Complete::ErrCode, Upnp_Discovery::ErrCode, Upnp_Event_Subscribe::ErrCode, Upnp_Action_Request::ErrStr, Upnp_State_Var_Request::ErrStr, Upnp_Event::EventKey, Upnp_Discovery::Expires, Upnp_Discovery::Ext, ixmlFreeDOMString(), ixmlPrintNode(), Upnp_Discovery::Location, Upnp_Discovery::Os, Upnp_Event_Subscribe::PublisherUrl, SampleUtil_Print(), SampleUtil_PrintEventType(), Upnp_Action_Request::ServiceID, Upnp_State_Var_Request::ServiceID, Upnp_Subscription_Request::ServiceId, Upnp_Discovery::ServiceType, Upnp_Discovery::ServiceVer, Upnp_Event::Sid, Upnp_Event_Subscribe::Sid, Upnp_Subscription_Request::Sid, Upnp_State_Var_Request::StateVarName, Upnp_State_Var_Complete::StateVarName, Upnp_Event_Subscribe::TimeOut, Upnp_Subscription_Request::UDN, 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, and UpnpGetErrorMessage().

Referenced by TvDeviceCallbackEventHandler().

void SampleUtil_PrintEventType ( Upnp_EventType  S)
Parameters:
[in]update_function.

References gStateUpdateFun, and UPNP_E_SUCCESS.

Referenced by TvCtrlPointStart().

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.

int SetActionTable ( int  serviceType,
struct TvService out 
)
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]serviceTypeone of TV_SERVICE_CONTROL or, TV_SERVICE_PICTURE.
[in]UDNUDN of device containing service.
[in]serviceIdserviceId of service.
[in]serviceTypeSservice type (as specified in Description Document) .
[in,out]outservice 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().

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().

void TvCtrlPointPrintCommands ( void  )

the list of valid command line commands to the user

References cmdloop_cmdlist, and SampleUtil_Print().

void TvCtrlPointPrintLongHelp ( void  )

Print long help info for this application.

References SampleUtil_Print().

void TvCtrlPointPrintShortHelp ( void  )

Print help info for this application.

References SampleUtil_Print().

int TvCtrlPointStart ( print_string  printFunctionPtr,
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_Initialize(), SampleUtil_Print(), SampleUtil_RegisterUpdateFunction(), UPNP_E_SUCCESS, UpnpFinish(), UpnpGetServerIpAddress(), UpnpGetServerPort(), UpnpInit(), and UpnpRegisterClient().

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]incrThe increment to subtract from the timeouts each time the function is called.

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

int TvDeviceCallbackEventHandler ( Upnp_EventType  ,
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]EventTypeThe type of callback event.
[in]EventData structure containing event data.
[in]CookieOptional 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().

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().

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

Decrease brightnesss.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementBrightness().

Referenced by SetActionTable().

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

Decrease the channel.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

Referenced by SetActionTable().

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

Decrease the color.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementColor().

Referenced by SetActionTable().

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

Decrease the contrast.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementContrast().

Referenced by SetActionTable().

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

Decrease tint.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

Referenced by SetActionTable().

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

Decrease the volume.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementVolume().

Referenced by SetActionTable().

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_eventThe control get variable request event structure.

References Upnp_State_Var_Request::CurrentVal, Upnp_State_Var_Request::DevUDN, Upnp_State_Var_Request::ErrCode, Upnp_State_Var_Request::ErrStr, ixmlCloneDOMString(), SampleUtil_Print(), TvService::ServiceId, Upnp_State_Var_Request::ServiceID, Upnp_State_Var_Request::StateVarName, TV_SERVICE_SERVCOUNT, tv_service_table, TVDevMutex, TvService::UDN, UPNP_E_SUCCESS, TvService::VariableCount, TvService::VariableName, and TvService::VariableStrVal.

Referenced by TvDeviceCallbackEventHandler().

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_eventThe subscription request event structure.

References device_handle, TvService::ServiceId, Upnp_Subscription_Request::ServiceId, Upnp_Subscription_Request::Sid, TV_SERVICE_SERVCOUNT, tv_service_table, TVDevMutex, TvService::UDN, Upnp_Subscription_Request::UDN, UpnpAcceptSubscription(), UpnpAcceptSubscriptionExt(), UpnpAddToPropertySet(), TvService::VariableCount, TvService::VariableName, and TvService::VariableStrVal.

Referenced by TvDeviceCallbackEventHandler().

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

Increase brightnesss.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementBrightness().

Referenced by SetActionTable().

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

Increase the channel.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

Referenced by SetActionTable().

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

Increase the color.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementColor().

Referenced by SetActionTable().

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

Increase the contrast.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementContrast().

Referenced by SetActionTable().

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

Increase tint.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

Referenced by SetActionTable().

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

Increase the volume.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

References IncrementVolume().

Referenced by SetActionTable().

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

Turn the power off.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

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

Referenced by SetActionTable().

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

Turn the power on.

Parameters:
[in]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

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

Referenced by SetActionTable().

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]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString 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().

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]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString 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().

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]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString 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().

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]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString in case action was unsuccessful.

Referenced by SetActionTable().

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]onIf 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().

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]serviceThe service number (TV_SERVICE_CONTROL or TV_SERVICE_PICTURE).
[in]variableThe 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]valueThe 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(), TvDeviceSetPower(), TvDeviceSetTint(), and TvDeviceSetVolume().

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]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString 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().

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]inDocument of action request.
[in]outAction result.
[out]errorStringErrorString 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().

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

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

Parameters:
[in]ip_addressip address to initialize the sdk (may be NULL) if null, then the first non null loopback address is used.
[in]portport number to initialize the sdk (may be 0) if zero, then a random number is used.
[in]desc_doc_namename of description document. may be NULL. Default is tvdevicedesc.xml.
[in]web_dir_pathpath of web directory. may be NULL. Default is ./web (for Linux) or ../tvdevice/web.
[in]pfunprint function to use.
[in]comboNon-zero if called from the combo application.

References default_advr_expire, device_handle, SampleUtil_Initialize(), SampleUtil_Print(), TvDeviceCallbackEventHandler(), TvDeviceStateTableInit(), TVDevMutex, UPNP_E_SUCCESS, UpnpFinish(), UpnpGetServerIpAddress(), UpnpGetServerPort(), UpnpInit(), UpnpRegisterRootDevice(), UpnpSendAdvertisement(), and UpnpSetWebServerRootDir().

Referenced by device_main().

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]DescDocURLThe 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().

int TvDeviceStop ( void  )

Stops the device. Uninitializes the sdk.

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

Referenced by TvDeviceCommandLoop().

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]UDNThe UDN of the parent device.
[in]ServiceThe service state table to update.
[out]ChangedVariablesDOM document representing the XML received with the event.
[out]Statepointer 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

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().

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

Referenced by TvDeviceStart().

int default_timeout = 1801

Timeout to request during subscriptions

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().

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().

ithread_mutex_t display_mutex

mutex to control displaying of events

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

ithread_mutex_t display_mutex

mutex to control displaying of events

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

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

Referenced by TvCtrlPointVerifyTimeouts().

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

Referenced by TvCtrlPointVerifyTimeouts().

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

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

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().

global state update function used by smaple util

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

global state update function used by smaple util

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

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

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

Referenced by SetServiceTable().

int TvCtrlPointTimerLoopRun = 1 [static]

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

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

Device type for tv device.

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().

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().

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

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

Referenced by SetServiceTable().

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

Service names.

const char* TvServiceName[]

Service names.

char TvVarCount[2]
Initial value:
    {  3 ,  4  }
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().

const char* TvVarName[2][4]

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

Referenced by TvStateUpdate().