libUPnP  1.8.4
tv_ctrlpt.h
Go to the documentation of this file.
1 #ifndef UPNP_TV_CTRLPT_H
2 #define UPNP_TV_CTRLPT_H
3 
4 /**************************************************************************
5  *
6  * Copyright (c) 2000-2003 Intel Corporation
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * - Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * - Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * - Neither name of Intel Corporation nor the names of its contributors
18  * may be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
25  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
29  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  **************************************************************************/
34 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #include "sample_util.h"
52 
53 #include "upnp.h"
54 #include "UpnpString.h"
55 #include "upnptools.h"
56 
57 #include <signal.h>
58 #include <stdarg.h>
59 #include <stdio.h>
60 
61 #define TV_SERVICE_SERVCOUNT 2
62 #define TV_SERVICE_CONTROL 0
63 #define TV_SERVICE_PICTURE 1
64 
65 #define TV_CONTROL_VARCOUNT 3
66 #define TV_CONTROL_POWER 0
67 #define TV_CONTROL_CHANNEL 1
68 #define TV_CONTROL_VOLUME 2
69 
70 #define TV_PICTURE_VARCOUNT 4
71 #define TV_PICTURE_COLOR 0
72 #define TV_PICTURE_TINT 1
73 #define TV_PICTURE_CONTRAST 2
74 #define TV_PICTURE_BRIGHTNESS 3
75 
76 #define TV_MAX_VAL_LEN 5
77 
78 #define TV_SUCCESS 0
79 #define TV_ERROR (-1)
80 #define TV_WARNING 1
81 
82 /* This should be the maximum VARCOUNT from above */
83 #define TV_MAXVARS TV_PICTURE_VARCOUNT
84 
85 extern const char *TvServiceName[];
86 extern const char *TvVarName[TV_SERVICE_SERVCOUNT][TV_MAXVARS];
87 extern char TvVarCount[];
88 
89 struct tv_service {
90  char ServiceId[NAME_SIZE];
91  char ServiceType[NAME_SIZE];
92  char *VariableStrVal[TV_MAXVARS];
93  char EventURL[NAME_SIZE];
94  char ControlURL[NAME_SIZE];
95  char SID[NAME_SIZE];
96 };
97 
98 extern struct TvDeviceNode *GlobalDeviceList;
99 
100 struct TvDevice {
101  char UDN[250];
102  char DescDocURL[250];
103  char FriendlyName[250];
104  char PresURL[250];
105  int AdvrTimeOut;
107 };
108 
109 struct TvDeviceNode {
110  struct TvDevice device;
111  struct TvDeviceNode *next;
112 };
113 
114 extern ithread_mutex_t DeviceListMutex;
115 
116 extern UpnpClient_Handle ctrlpt_handle;
117 
118 void TvCtrlPointPrintHelp(void);
119 int TvCtrlPointDeleteNode(struct TvDeviceNode *);
120 int TvCtrlPointRemoveDevice(const char *);
121 int TvCtrlPointRemoveAll(void);
122 int TvCtrlPointRefresh(void);
123 
124 int TvCtrlPointSendAction(int, int, const char *, const char **, char **, int);
125 int TvCtrlPointSendActionNumericArg(int devnum, int service, const char *actionName, const char *paramName, int paramValue);
126 int TvCtrlPointSendPowerOn(int devnum);
127 int TvCtrlPointSendPowerOff(int devnum);
128 int TvCtrlPointSendSetChannel(int, int);
129 int TvCtrlPointSendSetVolume(int, int);
130 int TvCtrlPointSendSetColor(int, int);
131 int TvCtrlPointSendSetTint(int, int);
132 int TvCtrlPointSendSetContrast(int, int);
133 int TvCtrlPointSendSetBrightness(int, int);
134 
135 int TvCtrlPointGetVar(int, int, const char *);
136 int TvCtrlPointGetPower(int devnum);
137 int TvCtrlPointGetChannel(int);
138 int TvCtrlPointGetVolume(int);
139 int TvCtrlPointGetColor(int);
140 int TvCtrlPointGetTint(int);
141 int TvCtrlPointGetContrast(int);
142 int TvCtrlPointGetBrightness(int);
143 
144 int TvCtrlPointGetDevice(int, struct TvDeviceNode **);
145 int TvCtrlPointPrintList(void);
146 int TvCtrlPointPrintDevice(int);
147 void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
148 void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
149 
156 void TvStateUpdate(
158  char *UDN,
160  int Service,
162  IXML_Document *ChangedVariables,
164  char **State);
165 
166 void TvCtrlPointHandleEvent(const char *, int, IXML_Document *);
167 void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int);
168 int TvCtrlPointCallbackEventHandler(Upnp_EventType, const void *, void *);
169 
181  int incr);
182 
183 void TvCtrlPointPrintCommands(void);
184 void* TvCtrlPointCommandLoop(void *);
185 int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionPtr, int combo);
186 int TvCtrlPointStop(void);
187 int TvCtrlPointProcessCommand(char *cmdline);
188 
192 void TvCtrlPointPrintShortHelp(void);
193 
197 void TvCtrlPointPrintLongHelp(void);
198 
202 void TvCtrlPointPrintCommands(void);
203 
209 void *TvCtrlPointCommandLoop(void *args);
210 
214 int TvCtrlPointProcessCommand(char *cmdline);
215 
216 #ifdef __cplusplus
217 };
218 #endif
219 
220 
225 #endif /* UPNP_TV_CTRLPT_H */
tv_ctrlpt.h
ixmlNodeList_free
EXPORT_SPEC void ixmlNodeList_free(IXML_NodeList *nList)
Frees a NodeList object.
Definition: nodeList.c:143
UPNP_EVENT_SUBSCRIPTION_REQUEST
@ UPNP_EVENT_SUBSCRIPTION_REQUEST
Definition: Callback.h:83
UPNP_DISCOVERY_SEARCH_RESULT
@ UPNP_DISCOVERY_SEARCH_RESULT
Definition: Callback.h:63
UPNP_CONTROL_ACTION_REQUEST
@ UPNP_CONTROL_ACTION_REQUEST
Definition: Callback.h:25
TvDeviceNode
Definition: tv_ctrlpt.h:109
TV_MAXVARS
#define TV_MAXVARS
Definition: tv_device.h:133
SampleUtil_PrintEvent
int SampleUtil_PrintEvent(Upnp_EventType EventType, const void *Event)
Prints callback event structure details.
Definition: sample_util.c:317
Upnp_SID
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition: upnp.h:445
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,...
Definition: sample_util.c:192
UpnpDownloadXmlDoc
int UpnpDownloadXmlDoc(const char *url, IXML_Document **xmlDoc)
Downloads an XML document specified in a URL.
Definition: upnpapi.c:3190
UPNP_CONTROL_GET_VAR_REQUEST
@ UPNP_CONTROL_GET_VAR_REQUEST
Definition: Callback.h:36
UpnpClient_Handle
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition: upnp.h:426
UPNP_EVENT_RENEWAL_COMPLETE
@ UPNP_EVENT_RENEWAL_COMPLETE
Definition: Callback.h:93
UpnpGetServiceVarStatusAsync
int UpnpGetServiceVarStatusAsync(UpnpClient_Handle Hnd, const char *ActionURL, const char *VarName, Upnp_FunPtr Fun, const void *Cookie)
Queries the state of a variable of a service, generating a callback when the operation is complete.
Definition: upnpapi.c:2873
print_string
void(* print_string)(const char *string,...)
Prototype for displaying strings. All printing done by the device, control point, and sample util,...
Definition: sample_util.h:162
UPNP_EVENT_UNSUBSCRIBE_COMPLETE
@ UPNP_EVENT_UNSUBSCRIBE_COMPLETE
Definition: Callback.h:103
UpnpRegisterClient
int UpnpRegisterClient(Upnp_FunPtr Callback, const void *Cookie, UpnpClient_Handle *Hnd)
Registers a control point application with the UPnP Library.
Definition: upnpapi.c:1308
_IXML_Document
Data structure representing the DOM Document.
Definition: ixml.h:198
UPNP_EVENT_SUBSCRIPTION_EXPIRED
@ UPNP_EVENT_SUBSCRIPTION_EXPIRED
Definition: Callback.h:115
TvService::VariableStrVal
char * VariableStrVal[4]
Definition: tv_device.h:164
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 ...
Definition: sample_util.c:62
UpnpGetServerPort
unsigned short UpnpGetServerPort(void)
Returns the internal server IPv4 UPnP listening port.
Definition: upnpapi.c:659
TV_SERVICE_SERVCOUNT
#define TV_SERVICE_SERVCOUNT
Definition: tv_device.h:91
TvCtrlPointPrintLongHelp
void TvCtrlPointPrintLongHelp(void)
Print long help info for this application.
Definition: tv_ctrlpt.c:1307
state_update
void(* state_update)(const char *varName, const char *varValue, const char *UDN, eventType type)
Prototype for passing back state changes.
Definition: sample_util.h:179
tv_service
Definition: tv_ctrlpt.h:89
cmdloop_cmdlist
static struct cmdloop_commands cmdloop_cmdlist[]
Definition: tv_ctrlpt.c:1424
TvStateUpdate
void TvStateUpdate(char *UDN, int Service, IXML_Document *ChangedVariables, char **State)
Update a Tv state table. Called when an event is received.
Definition: tv_ctrlpt.c:811
TV_CONTROL_VARCOUNT
#define TV_CONTROL_VARCOUNT
Definition: tv_device.h:100
UPNP_DISCOVERY_SEARCH_TIMEOUT
@ UPNP_DISCOVERY_SEARCH_TIMEOUT
Definition: Callback.h:68
SampleUtil_GetElementValue
char * SampleUtil_GetElementValue(IXML_Element *element)
Given a DOM node such as <Channel>11</Channel>, this routine extracts the value (e....
Definition: sample_util.c:103
cmdloop_tvcmds
cmdloop_tvcmds
Definition: tv_ctrlpt.c:1388
UpnpInit2
int UpnpInit2(const char *IfName, unsigned short DestPort)
Initializes the Linux SDK for UPnP Devices (IPv4 or IPv6).
Definition: upnpapi.c:460
UPNP_E_SUCCESS
#define UPNP_E_SUCCESS
The operation completed successfully.
Definition: upnp.h:97
UPNP_EVENT_RECEIVED
@ UPNP_EVENT_RECEIVED
Definition: Callback.h:88
upnp.h
UpnpUnSubscribe
int UpnpUnSubscribe(UpnpClient_Handle Hnd, const Upnp_SID SubsId)
Removes the subscription of a control point from a service previously subscribed to using UpnpSubscri...
Definition: upnpapi.c:2035
TvCtrlPointStart
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 creat...
Definition: tv_ctrlpt.c:1216
UPNP_CONTROL_GET_VAR_COMPLETE
@ UPNP_CONTROL_GET_VAR_COMPLETE
Definition: Callback.h:41
TvVarName
const char * TvVarName[2][4]
Definition: tv_ctrlpt.c:67
ixmlDocument_free
EXPORT_SPEC void ixmlDocument_free(IXML_Document *doc)
Frees a Document object and all Nodes associated with it.
Definition: document.c:54
UpnpActionComplete
struct s_UpnpActionComplete UpnpActionComplete
Definition: TemplateInclude.h:136
TvCtrlPointTimerLoopRun
static int TvCtrlPointTimerLoopRun
Function that runs in its own thread and monitors advertisement and subscription timeouts for devices...
Definition: tv_ctrlpt.c:1194
UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE
@ UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE
Definition: Callback.h:57
SampleUtil_RegisterUpdateFunction
int SampleUtil_RegisterUpdateFunction(state_update update_function)
Definition: sample_util.c:82
ixmlNodeList_item
EXPORT_SPEC IXML_Node * ixmlNodeList_item(IXML_NodeList *nList, unsigned long index)
Retrieves a Node from a NodeList specified by a numerical index.
Definition: nodeList.c:54
UpnpMakeAction
EXPORT_SPEC IXML_Document * UpnpMakeAction(const char *ActionName, const char *ServType, int NumArg, const char *Arg,...)
Creates an action request packet based on its input parameters (status variable name and value pair).
Definition: upnptools.c:351
TvServiceName
const char * TvServiceName[]
Definition: tv_ctrlpt.c:61
UpnpString_get_String
const char * UpnpString_get_String(const UpnpString *p)
Returns the pointer to char.
Definition: UpnpString.c:159
UpnpSubscribe
int UpnpSubscribe(UpnpClient_Handle Hnd, const char *PublisherUrl, int *TimeOut, Upnp_SID SubsId)
Registers a control point to receive event notifications from another device.
Definition: upnpapi.c:1964
UpnpActionComplete_get_ErrCode
int UpnpActionComplete_get_ErrCode(const UpnpActionComplete *p)
TV_SERVICE_PICTURE
#define TV_SERVICE_PICTURE
Definition: tv_device.h:97
UpnpSendActionAsync
int UpnpSendActionAsync(UpnpClient_Handle Hnd, const char *ActionURL, const char *ServiceType, const char *DevUDN, IXML_Document *Action, Upnp_FunPtr Fun, const void *Cookie)
Sends a message to change a state variable in a service, generating a callback when the operation is ...
Definition: upnpapi.c:2656
TvCtrlPointVerifyTimeouts
void TvCtrlPointVerifyTimeouts(int incr)
Checks the advertisement each device in the global device list.
Definition: tv_ctrlpt.c:1144
sample_util.h
TvCtrlPointPrintShortHelp
void TvCtrlPointPrintShortHelp(void)
Print help info for this application.
Definition: tv_ctrlpt.c:1283
SampleUtil_StateUpdate
void SampleUtil_StateUpdate(const char *varName, const char *varValue, const char *UDN, eventType type)
Definition: sample_util.c:655
SampleUtil_Print
int SampleUtil_Print(const char *fmt,...)
Function emulating printf that ultimately calls the registered print function with the formatted stri...
Definition: sample_util.c:634
upnptools.h
cmdloop_commands
Definition: tv_ctrlpt.c:1410
TvDevice
Definition: tv_ctrlpt.h:100
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...
Definition: sample_util.c:550
UpnpAddToAction
EXPORT_SPEC int UpnpAddToAction(IXML_Document **ActionDoc, const char *ActionName, const char *ServType, const char *ArgName, const char *ArgVal)
Adds the argument in the action request.
Definition: upnptools.c:387
GlobalDeviceList
struct TvDeviceNode * GlobalDeviceList
Definition: tv_ctrlpt.c:82
_IXML_NodeList
Data structure representing a list of nodes.
Definition: ixml.h:246
DOMString
#define DOMString
The type of DOM strings.
Definition: ixml.h:59
UpnpGetServerIpAddress
char * UpnpGetServerIpAddress(void)
Returns the local IPv4 listening ip address.
Definition: upnpapi.c:679
ixmlDocument_getElementsByTagName
EXPORT_SPEC IXML_NodeList * ixmlDocument_getElementsByTagName(IXML_Document *doc, const char *tagName)
Returns a NodeList of all Elements that match the given tag name in the order in which they were enco...
UpnpSearchAsync
int UpnpSearchAsync(UpnpClient_Handle Hnd, int Mx, const char *TTarget_constarget_const, const void *Cookie_const)
Searches for devices matching the given search target.
Definition: upnpapi.c:1757
ixmlNodeList_length
EXPORT_SPEC unsigned long ixmlNodeList_length(IXML_NodeList *nList)
Returns the number of Nodes in a NodeList.
Definition: nodeList.c:128
UPNP_EVENT_SUBSCRIBE_COMPLETE
@ UPNP_EVENT_SUBSCRIBE_COMPLETE
Definition: Callback.h:98
UpnpResolveURL
EXPORT_SPEC int UpnpResolveURL(const char *BaseURL, const char *RelURL, char *AbsURL)
Combines a base URL and a relative URL into a single absolute URL.
Definition: upnptools.c:144
UPNP_CONTROL_ACTION_COMPLETE
@ UPNP_CONTROL_ACTION_COMPLETE
Definition: Callback.h:30
UPNP_DISCOVERY_ADVERTISEMENT_ALIVE
@ UPNP_DISCOVERY_ADVERTISEMENT_ALIVE
Definition: Callback.h:51
TvCtrlPointCommandLoop
void * TvCtrlPointCommandLoop(void *args)
Function that receives commands from the user at the command prompt during the lifetime of the device...
Definition: tv_ctrlpt.c:1458
UpnpString.h
UpnpString object declaration.
default_timeout
int default_timeout
Definition: tv_ctrlpt.c:77
TvCtrlPointPrintCommands
void TvCtrlPointPrintCommands(void)
Definition: tv_ctrlpt.c:1445
_IXML_Element
Data structure representing an Element node.
Definition: ixml.h:216
UPNP_EVENT_AUTORENEWAL_FAILED
@ UPNP_EVENT_AUTORENEWAL_FAILED
Definition: Callback.h:109
TV_SERVICE_CONTROL
#define TV_SERVICE_CONTROL
Definition: tv_device.h:94
UpnpFinish
int UpnpFinish(void)
Initializes the OpenSSL library, and the OpenSSL context for use with pupnp.
Definition: upnpapi.c:585
UpnpUnRegisterClient
int UpnpUnRegisterClient(UpnpClient_Handle Hnd)
Unregisters a control point application, unsubscribing all active subscriptions.
Definition: upnpapi.c:1356
TvDeviceType
const char TvDeviceType[]
Definition: tv_ctrlpt.c:58
TV_PICTURE_VARCOUNT
#define TV_PICTURE_VARCOUNT
Definition: tv_device.h:112
TV_MAX_VAL_LEN
#define TV_MAX_VAL_LEN
Definition: tv_device.h:127
DeviceListMutex
ithread_mutex_t DeviceListMutex
Definition: tv_ctrlpt.c:53
TvService
Definition: tv_device.h:154
ixmlElement_getElementsByTagName
EXPORT_SPEC IXML_NodeList * ixmlElement_getElementsByTagName(IXML_Element *element, const char *tagName)
Returns a NodeList of all descendant Elements with a given tag name, in the order in which they are e...
SampleUtil_Finish
int SampleUtil_Finish()
Releases Resources held by sample util.
Definition: sample_util.c:92