libUPnP  1.14.0
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
44 extern "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
57 
58  const char *TvServiceType[] = {
59  "urn:schemas-upnp-org:service:tvcontrol:1",
60  "urn:schemas-upnp-org:service:tvpicture:1"
61  };
62 #else /* SAMPLE_UTIL_C */
63  extern const char *TvServiceType[];
64 #endif /* SAMPLE_UTIL_C */
65 
66 /* mutex to control displaying of events */
67 extern ithread_mutex_t display_mutex;
68 
69 typedef enum {
70  STATE_UPDATE = 0,
71  DEVICE_ADDED = 1,
72  DEVICE_REMOVED = 2,
73  GET_VAR_COMPLETE = 3
74 } eventType;
75 
85  IXML_Element *element);
86 
98  IXML_Document *doc);
99 
107  IXML_Document *doc,
109  const char *item);
110 
118  IXML_Element *element,
120  const char *item);
121 
127  Upnp_EventType S);
128 
134  Upnp_EventType EventType,
136  const void *Event);
137 
146  IXML_Document *DescDoc,
148  const char *location,
150  const char *serviceType,
152  char **serviceId,
154  char **eventURL,
156  char **controlURL);
157 
163 typedef void (*print_string)(
165  const char *string,
167  ...)
168 #if (__GNUC__ >= 3)
169  /* This enables printf like format checking by the compiler */
170  __attribute__((format (__printf__, 1, 2)))
171 #endif
172 ;
173 
175 extern print_string gPrintFun;
176 
180 typedef void (*state_update)(
182  const char *varName,
184  const char *varValue,
186  const char *UDN,
188  eventType type);
189 
192 
199  print_string print_function);
200 
204 int SampleUtil_Finish();
205 
217 int SampleUtil_Print(
219  const char *fmt,
221  ...)
222 #if (__GNUC__ >= 3)
223  /* This enables printf like format checking by the compiler */
224  __attribute__((format (__printf__, 1, 2)))
225 #endif
226 ;
227 
233  state_update update_function);
234 
240  const char *varName,
242  const char *varValue,
244  const char *UDN,
246  eventType type);
247 
251 void linux_print(const char *format, ...)
252 #if (__GNUC__ >= 3)
253  /* This enables printf like format checking by the compiler */
254  __attribute__((format (__printf__, 1, 2)))
255 #endif
256 ;
257 
258 #ifdef __cplusplus
259 };
260 #endif /* __cplusplus */
261 
262 #ifdef _WIN32
263  #if defined(_MSC_VER) && _MSC_VER < 1900
264  #define snprintf _snprintf
265  #endif
266  #define strcasecmp stricmp
267 #endif
268 
271 #endif /* SAMPLE_UTIL_H */
272 
int SampleUtil_RegisterUpdateFunction(state_update update_function)
Definition: sample_util.c:82
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
print_string gPrintFun
Definition: sample_util.c:56
int SampleUtil_Print(const char *fmt,...)
Function emulating printf that ultimately calls the registered print function with the formatted stri...
Definition: sample_util.c:691
state_update gStateUpdateFun
Definition: sample_util.c:57
void SampleUtil_PrintEventType(Upnp_EventType S)
Prints a callback event type as a string.
Definition: sample_util.c:291
void linux_print(const char *format,...)
Prints a string to standard out.
Definition: sample_util.c:725
char * SampleUtil_GetElementValue(IXML_Element *element)
Given a DOM node such as 11, 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.
Definition: sample_util.c:103
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:601
Data structure representing a list of nodes.
Definition: ixml.h:202
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
int SampleUtil_PrintEvent(Upnp_EventType EventType, const void *Event)
Prints callback event structure details.
Definition: sample_util.c:345
int SampleUtil_Finish()
Releases Resources held by sample util.
Definition: sample_util.c:92
ithread_mutex_t display_mutex
Definition: sample_util.c:60
Data structure representing the DOM Document.
Definition: ixml.h:159
void SampleUtil_StateUpdate(const char *varName, const char *varValue, const char *UDN, eventType type)
Definition: sample_util.c:712
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:163
Data structure representing an Element node.
Definition: ixml.h:175
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:193
void(* state_update)(const char *varName, const char *varValue, const char *UDN, eventType type)
Prototype for passing back state changes.
Definition: sample_util.h:180
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:251