sample_util.h
Go to the documentation of this file.
#ifndef SAMPLE_UTIL_H
#define SAMPLE_UTIL_H
/*******************************************************************************
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "config_sample.h"
#include "ithread.h"
#include "ixml.h" /* for IXML_Document, IXML_Element */
#include "upnp.h" /* for Upnp_EventType */
#include "upnptools.h"
#include <stdlib.h>
#include <string.h>
#ifdef SAMPLE_UTIL_C
const char *TvServiceType[] = {"urn:schemas-upnp-org:service:tvcontrol:1",
"urn:schemas-upnp-org:service:tvpicture:1"};
#else /* SAMPLE_UTIL_C */
extern const char *TvServiceType[];
#endif /* SAMPLE_UTIL_C */
/* mutex to control displaying of events */
extern ithread_mutex_t display_mutex;
typedef enum
{
STATE_UPDATE = 0,
DEVICE_ADDED = 1,
DEVICE_REMOVED = 2,
GET_VAR_COMPLETE = 3
} eventType;
char *SampleUtil_GetElementValue(
IXML_Element *element);
IXML_NodeList *SampleUtil_GetFirstServiceList(
IXML_Document *doc);
char *SampleUtil_GetFirstDocumentItem(
IXML_Document *doc,
const char *item);
char *SampleUtil_GetFirstElementItem(
IXML_Element *element,
const char *item);
void SampleUtil_PrintEventType(
Upnp_EventType S);
int SampleUtil_PrintEvent(
Upnp_EventType EventType,
const void *Event);
int SampleUtil_FindAndParseService(
IXML_Document *DescDoc,
const char *location,
const char *serviceType,
char **serviceId,
char **eventURL,
char **controlURL);
typedef void (*print_string)(
const char *string,
...)
#if (__GNUC__ >= 3)
/* This enables printf like format checking by the compiler */
__attribute__((format(__printf__, 1, 2)))
#endif
;
extern print_string gPrintFun;
typedef void (*state_update)(
const char *varName,
const char *varValue,
const char *UDN,
eventType type);
extern state_update gStateUpdateFun;
int SampleUtil_Initialize(
print_string print_function);
int SampleUtil_Finish();
int SampleUtil_Print(
const char *fmt,
...)
#if (__GNUC__ >= 3)
/* This enables printf like format checking by the compiler */
__attribute__((format(__printf__, 1, 2)))
#endif
;
int SampleUtil_RegisterUpdateFunction(
state_update update_function);
void SampleUtil_StateUpdate(
const char *varName,
const char *varValue,
const char *UDN,
eventType type);
void linux_print(const char *format, ...)
#if (__GNUC__ >= 3)
/* This enables printf like format checking by the compiler */
__attribute__((format(__printf__, 1, 2)))
#endif
;
#ifdef __cplusplus
};
#endif /* __cplusplus */
#endif /* SAMPLE_UTIL_H */
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:603
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:195
SampleUtil_GetFirstServiceList
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
SampleUtil_StateUpdate
void SampleUtil_StateUpdate(const char *varName, const char *varValue, const char *UDN, eventType type)
Definition sample_util.c:714
SampleUtil_PrintEventType
void SampleUtil_PrintEventType(Upnp_EventType S)
Prints a callback event type as a string.
Definition sample_util.c:293
gStateUpdateFun
state_update gStateUpdateFun
Definition sample_util.c:59
SampleUtil_RegisterUpdateFunction
int SampleUtil_RegisterUpdateFunction(state_update update_function)
Definition sample_util.c:84
SampleUtil_PrintEvent
int SampleUtil_PrintEvent(Upnp_EventType EventType, const void *Event)
Prints callback event structure details.
Definition sample_util.c:347
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:693
linux_print
void linux_print(const char *format,...)
Prints a string to standard out.
Definition sample_util.c:727
SampleUtil_GetFirstElementItem
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
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:105
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
gPrintFun
print_string gPrintFun
Definition sample_util.c:58
SampleUtil_Finish
int SampleUtil_Finish()
Releases Resources held by sample util.
Definition sample_util.c:94
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
display_mutex
ithread_mutex_t display_mutex
Definition sample_util.c:62
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:64
ithread.h
ixml.h
_IXML_Document
Data structure representing the DOM Document.
Definition ixml.h:160
_IXML_Element
Data structure representing an Element node.
Definition ixml.h:176
_IXML_NodeList
Data structure representing a list of nodes.
Definition ixml.h:203
upnp.h
upnptools.h