libUPnP 1.14.19
sample_util.h
Go to the documentation of this file.
1#ifndef SAMPLE_UTIL_H
2#define SAMPLE_UTIL_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
43#ifdef __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46
47#include "config_sample.h"
48#include "ithread.h"
49#include "ixml.h" /* for IXML_Document, IXML_Element */
50#include "upnp.h" /* for Upnp_EventType */
51#include "upnptools.h"
52
53#include <stdlib.h>
54#include <string.h>
55
56#ifdef SAMPLE_UTIL_C
58const char *TvServiceType[] = {"urn:schemas-upnp-org:service:tvcontrol:1",
59 "urn:schemas-upnp-org:service:tvpicture:1"};
60#else /* SAMPLE_UTIL_C */
61extern const char *TvServiceType[];
62#endif /* SAMPLE_UTIL_C */
63
64/* mutex to control displaying of events */
65extern ithread_mutex_t display_mutex;
66
67typedef enum
68{
69 STATE_UPDATE = 0,
70 DEVICE_ADDED = 1,
71 DEVICE_REMOVED = 2,
72 GET_VAR_COMPLETE = 3
73} eventType;
74
84 IXML_Element *element);
85
97 IXML_Document *doc);
98
106 IXML_Document *doc,
108 const char *item);
109
117 IXML_Element *element,
119 const char *item);
120
126 Upnp_EventType S);
127
133 Upnp_EventType EventType,
135 const void *Event);
136
145 IXML_Document *DescDoc,
147 const char *location,
149 const char *serviceType,
151 char **serviceId,
153 char **eventURL,
155 char **controlURL);
156
162typedef void (*print_string)(
164 const char *string,
166 ...)
167#if (__GNUC__ >= 3)
168 /* This enables printf like format checking by the compiler */
169 __attribute__((format(__printf__, 1, 2)))
170#endif
171 ;
172
175
179typedef void (*state_update)(
181 const char *varName,
183 const char *varValue,
185 const char *UDN,
187 eventType type);
188
191
198 print_string print_function);
199
204
218 const char *fmt,
220 ...)
221#if (__GNUC__ >= 3)
222 /* This enables printf like format checking by the compiler */
223 __attribute__((format(__printf__, 1, 2)))
224#endif
225 ;
226
232 state_update update_function);
233
239 const char *varName,
241 const char *varValue,
243 const char *UDN,
245 eventType type);
246
250void linux_print(const char *format, ...)
251#if (__GNUC__ >= 3)
252 /* This enables printf like format checking by the compiler */
253 __attribute__((format(__printf__, 1, 2)))
254#endif
255 ;
256
257#ifdef __cplusplus
258};
259#endif /* __cplusplus */
260
263#endif /* SAMPLE_UTIL_H */
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:603
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:195
IXML_NodeList * SampleUtil_GetFirstServiceList(IXML_Document *doc)
Given a DOM node representing a UPnP Device Description Document, this routine parses the document an...
Definition sample_util.c:116
void SampleUtil_StateUpdate(const char *varName, const char *varValue, const char *UDN, eventType type)
Definition sample_util.c:714
void SampleUtil_PrintEventType(Upnp_EventType S)
Prints a callback event type as a string.
Definition sample_util.c:293
state_update gStateUpdateFun
Definition sample_util.c:59
int SampleUtil_RegisterUpdateFunction(state_update update_function)
Definition sample_util.c:84
int SampleUtil_PrintEvent(Upnp_EventType EventType, const void *Event)
Prints callback event structure details.
Definition sample_util.c:347
int SampleUtil_Print(const char *fmt,...)
Function emulating printf that ultimately calls the registered print function with the formatted stri...
Definition sample_util.c:693
void linux_print(const char *format,...)
Prints a string to standard out.
Definition sample_util.c:727
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,...
Definition sample_util.c:253
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:105
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
print_string gPrintFun
Definition sample_util.c:58
int SampleUtil_Finish()
Releases Resources held by sample util.
Definition sample_util.c:94
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
ithread_mutex_t display_mutex
Definition sample_util.c:62
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:64
Data structure representing the DOM Document.
Definition ixml.h:160
Data structure representing an Element node.
Definition ixml.h:176
Data structure representing a list of nodes.
Definition ixml.h:203