libUPnP 1.8.4
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 "ithread.h"
48#include "ixml.h" /* for IXML_Document, IXML_Element */
49#include "upnp.h" /* for Upnp_EventType */
50#include "upnptools.h"
51
52#include <stdlib.h>
53#include <string.h>
54
55#ifdef SAMPLE_UTIL_C
57 const char *TvServiceType[] = {
58 "urn:schemas-upnp-org:service:tvcontrol:1",
59 "urn:schemas-upnp-org:service:tvpicture:1"
60 };
61#else /* SAMPLE_UTIL_C */
62 extern const char *TvServiceType[];
63#endif /* SAMPLE_UTIL_C */
64
65/* mutex to control displaying of events */
66extern ithread_mutex_t display_mutex;
67
68typedef enum {
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
261#ifdef _WIN32
262 #define snprintf _snprintf
263 #define strcasecmp stricmp
264#endif
265
268#endif /* SAMPLE_UTIL_H */
269
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
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
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:114
void SampleUtil_StateUpdate(const char *varName, const char *varValue, const char *UDN, eventType type)
Definition sample_util.c:655
void SampleUtil_PrintEventType(Upnp_EventType S)
Prints a callback event type as a string.
Definition sample_util.c:263
state_update gStateUpdateFun
Definition sample_util.c:57
int SampleUtil_RegisterUpdateFunction(state_update update_function)
Definition sample_util.c:82
int SampleUtil_PrintEvent(Upnp_EventType EventType, const void *Event)
Prints callback event structure details.
Definition sample_util.c:317
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
void linux_print(const char *format,...)
Prints a string to standard out.
Definition sample_util.c:666
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:230
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
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:56
int SampleUtil_Finish()
Releases Resources held by sample util.
Definition sample_util.c:92
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:60
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
Data structure representing the DOM Document.
Definition ixml.h:198
Data structure representing an Element node.
Definition ixml.h:216
Data structure representing a list of nodes.
Definition ixml.h:246