libUPnP  1.6.17
sample_util.h
Go to the documentation of this file.
00001 #ifndef SAMPLE_UTIL_H
00002 #define SAMPLE_UTIL_H
00003 
00004 /*******************************************************************************
00005  *
00006  * Copyright (c) 2000-2003 Intel Corporation 
00007  * All rights reserved. 
00008  *
00009  * Redistribution and use in source and binary forms, with or without 
00010  * modification, are permitted provided that the following conditions are met: 
00011  *
00012  * - Redistributions of source code must retain the above copyright notice, 
00013  * this list of conditions and the following disclaimer. 
00014  * - Redistributions in binary form must reproduce the above copyright notice, 
00015  * this list of conditions and the following disclaimer in the documentation 
00016  * and/or other materials provided with the distribution. 
00017  * - Neither name of Intel Corporation nor the names of its contributors 
00018  * may be used to endorse or promote products derived from this software 
00019  * without specific prior written permission.
00020  * 
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00022  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00023  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00024  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
00025  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00027  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00028  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
00029  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00030  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00031  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  ******************************************************************************/
00034 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif /* __cplusplus */
00046 
00047 #include "ithread.h"
00048 #include "ixml.h" /* for IXML_Document, IXML_Element */
00049 #include "upnp.h" /* for Upnp_EventType */
00050 #include "upnptools.h"
00051 
00052 #include <stdlib.h>
00053 #include <string.h>
00054 
00055 #ifdef SAMPLE_UTIL_C
00056 
00057         const char *TvServiceType[] = {
00058                 "urn:schemas-upnp-org:service:tvcontrol:1",
00059                 "urn:schemas-upnp-org:service:tvpicture:1"
00060         };
00061 #else /* SAMPLE_UTIL_C */
00062         extern const char *TvServiceType[];
00063 #endif /* SAMPLE_UTIL_C */
00064 
00065 /* mutex to control displaying of events */
00066 extern ithread_mutex_t display_mutex;
00067 
00068 typedef enum {
00069         STATE_UPDATE = 0,
00070         DEVICE_ADDED = 1,
00071         DEVICE_REMOVED = 2,
00072         GET_VAR_COMPLETE = 3
00073 } eventType;
00074 
00082 char *SampleUtil_GetElementValue(
00084         IXML_Element *element);
00085 
00095 IXML_NodeList *SampleUtil_GetFirstServiceList(
00097         IXML_Document *doc); 
00098 
00104 char *SampleUtil_GetFirstDocumentItem(
00106         IXML_Document *doc,
00108         const char *item); 
00109 
00115 char *SampleUtil_GetFirstElementItem(
00117         IXML_Element *element,
00119         const char *item); 
00120 
00124 void SampleUtil_PrintEventType(
00126         Upnp_EventType S);
00127 
00131 int SampleUtil_PrintEvent(
00133         Upnp_EventType EventType, 
00135         void *Event);
00136 
00143 int SampleUtil_FindAndParseService (
00145         IXML_Document *DescDoc,
00147         const char *location, 
00149         const char *serviceType,
00151         char **serviceId, 
00153         char **eventURL,
00155         char **controlURL);
00156 
00162 typedef void (*print_string)(
00164         const char *string,
00166         ...)
00167 #if (__GNUC__ >= 3)
00168         /* This enables printf like format checking by the compiler */
00169         __attribute__((format (__printf__, 1, 2)))
00170 #endif
00171 ;
00172 
00174 extern print_string gPrintFun;
00175 
00179 typedef void (*state_update)(
00181         const char *varName,
00183         const char *varValue,
00185         const char *UDN,
00187         eventType type);
00188 
00190 extern state_update gStateUpdateFun;
00191 
00196 int SampleUtil_Initialize(
00198         print_string print_function);
00199 
00203 int SampleUtil_Finish();
00204 
00216 int SampleUtil_Print(
00218         const char *fmt,
00220         ...)
00221 #if (__GNUC__ >= 3)
00222         /* This enables printf like format checking by the compiler */
00223         __attribute__((format (__printf__, 1, 2)))
00224 #endif
00225 ;
00226 
00230 int SampleUtil_RegisterUpdateFunction(
00232         state_update update_function);
00233 
00237 void SampleUtil_StateUpdate(
00239         const char *varName,
00241         const char *varValue,
00243         const char *UDN,
00245         eventType type);
00246 
00250 void linux_print(const char *format, ...)
00251 #if (__GNUC__ >= 3)
00252         /* This enables printf like format checking by the compiler */
00253         __attribute__((format (__printf__, 1, 2)))
00254 #endif
00255 ;
00256 
00257 #ifdef __cplusplus
00258 };
00259 #endif /* __cplusplus */
00260 
00261 #ifdef WIN32
00262         #define snprintf        _snprintf
00263         #define strcasecmp      stricmp
00264 #endif
00265 
00268 #endif /* SAMPLE_UTIL_H */
00269