Arduino DLNA Server
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::XMLPrinter Struct Reference

Functions to efficiently output XML. XML data contains a lot of redundancy so it is more memory efficient to generate the data instead of using a predefined XML document. More...

#include <XMLPrinter.h>

Public Member Functions

 XMLPrinter ()=default
 Default constructor.
 
 XMLPrinter (Print &output)
 Constructor with output.
 
void setOutput (Print &output)
 Defines the output Print object.
 
size_t printXMLHeader ()
 Prints the XML header.
 
size_t printNode (XMLNode node)
 Prints an XML node from XMLNode struct.
 
size_t printNode (const char *node, XMLNode child, const char *attributes=nullptr)
 Prints an XML node with a single child.
 
size_t printNode (const char *node, Vector< XMLNode > children, const char *attributes=nullptr)
 Prints an XML node with multiple children.
 
size_t printNode (const char *node, const char *txt=nullptr, const char *attributes=nullptr)
 Prints an XML node with text content.
 
size_t printNode (const char *node, int txt, const char *attributes=nullptr)
 Prints an XML node with integer content.
 
size_t printNode (const char *node, std::function< size_t(void)> callback, const char *attributes=nullptr)
 Prints an XML node using a callback for content.
 
size_t printNode (const char *node, std::function< size_t(void *)> callback, void *ref, const char *attributes=nullptr)
 Prints an XML node using a callback that receives a context pointer.
 
size_t printNode (const char *node, size_t(*callback)(void *), void *ref, const char *attributes=nullptr)
 Prints an XML node using a plain function pointer that receives a context pointer.
 
size_t printNode (const char *node, std::function< size_t(Print &, void *)> callback, void *ref, const char *attributes=nullptr)
 Prints an XML node using a callback that receives the Print& and a context pointer.
 
size_t printNode (const char *node, size_t(*callback)(Print &, void *), void *ref, const char *attributes=nullptr)
 Prints an XML node using a plain function pointer that receives Print& and a context pointer.
 
size_t printf (const char *fmt,...)
 printf-style helper that formats into an internal buffer and writes to the configured Print output.
 
size_t printArgument (const char *name, const char *direction, const char *relatedStateVariable=nullptr)
 Helper to print a UPnP <argument> element with name, direction and optional relatedStateVariable.
 
size_t printStateVariable (const char *name, const char *dataType, bool sendEvents=false, std::function< void()> extra=nullptr)
 Helper to print a UPnP <stateVariable> element with name, dataType and optional sendEvents attribute and inner content callback.
 
size_t printNodeBegin (const char *node, const char *attributes=nullptr, const char *ns=nullptr)
 Prints the beginning of an XML node.
 
size_t printNodeBeginNl (const char *node, const char *attributes=nullptr, const char *ns=nullptr)
 Prints the beginning of an XML node and a newline.
 
size_t printNodeEnd (const char *node, const char *ns=nullptr)
 Prints the end of an XML node.
 
void clear ()
 

Protected Member Functions

size_t println (const char *txt)
 
size_t printChildren (Vector< XMLNode > &children)
 

Protected Attributes

Print * p_out = &Serial
 

Detailed Description

Functions to efficiently output XML. XML data contains a lot of redundancy so it is more memory efficient to generate the data instead of using a predefined XML document.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ XMLPrinter() [1/2]

tiny_dlna::XMLPrinter::XMLPrinter ( )
default

Default constructor.

◆ XMLPrinter() [2/2]

tiny_dlna::XMLPrinter::XMLPrinter ( Print &  output)
inline

Constructor with output.

Parameters
outputReference to Print object for output

Member Function Documentation

◆ clear()

void tiny_dlna::XMLPrinter::clear ( )
inline

◆ printArgument()

size_t tiny_dlna::XMLPrinter::printArgument ( const char *  name,
const char *  direction,
const char *  relatedStateVariable = nullptr 
)
inline

Helper to print a UPnP <argument> element with name, direction and optional relatedStateVariable.

Parameters
nameArgument name
directionArgument direction
relatedStateVariableOptional related state variable
Returns
Number of bytes written

◆ printChildren()

size_t tiny_dlna::XMLPrinter::printChildren ( Vector< XMLNode > &  children)
inlineprotected

◆ printf()

size_t tiny_dlna::XMLPrinter::printf ( const char *  fmt,
  ... 
)
inline

printf-style helper that formats into an internal buffer and writes to the configured Print output.

Parameters
fmtFormat string
...Variable arguments
Returns
Number of bytes written

◆ println()

size_t tiny_dlna::XMLPrinter::println ( const char *  txt)
inlineprotected

◆ printNode() [1/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
const char *  txt = nullptr,
const char *  attributes = nullptr 
)
inline

Prints an XML node with text content.

Parameters
nodeName of the node
txtText content
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [2/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
int  txt,
const char *  attributes = nullptr 
)
inline

Prints an XML node with integer content.

Parameters
nodeName of the node
txtInteger value
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [3/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
size_t(*)(Print &, void *)  callback,
void *  ref,
const char *  attributes = nullptr 
)
inline

Prints an XML node using a plain function pointer that receives Print& and a context pointer.

◆ printNode() [4/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
size_t(*)(void *)  callback,
void *  ref,
const char *  attributes = nullptr 
)
inline

Prints an XML node using a plain function pointer that receives a context pointer.

Parameters
nodeName of the node
callbackFunction pointer to generate content, takes a void* context
refContext pointer passed through to the callback
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [5/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
std::function< size_t(Print &, void *)>  callback,
void *  ref,
const char *  attributes = nullptr 
)
inline

Prints an XML node using a callback that receives the Print& and a context pointer.

Parameters
nodeName of the node
callbackFunction to generate content, takes Print& and void* context
refContext pointer passed through to the callback
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [6/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
std::function< size_t(void *)>  callback,
void *  ref,
const char *  attributes = nullptr 
)
inline

Prints an XML node using a callback that receives a context pointer.

Parameters
nodeName of the node
callbackFunction to generate content, takes a void* context
refContext pointer passed through to the callback
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [7/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
std::function< size_t(void)>  callback,
const char *  attributes = nullptr 
)
inline

Prints an XML node using a callback for content.

Parameters
nodeName of the node
callbackFunction to generate content
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [8/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
Vector< XMLNode children,
const char *  attributes = nullptr 
)
inline

Prints an XML node with multiple children.

Parameters
nodeName of the node
childrenVector of child XMLNodes
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [9/10]

size_t tiny_dlna::XMLPrinter::printNode ( const char *  node,
XMLNode  child,
const char *  attributes = nullptr 
)
inline

Prints an XML node with a single child.

Parameters
nodeName of the node
childChild XMLNode
attributesOptional attributes
Returns
Number of bytes written

◆ printNode() [10/10]

size_t tiny_dlna::XMLPrinter::printNode ( XMLNode  node)
inline

Prints an XML node from XMLNode struct.

Parameters
nodeXMLNode struct
Returns
Number of bytes written

◆ printNodeBegin()

size_t tiny_dlna::XMLPrinter::printNodeBegin ( const char *  node,
const char *  attributes = nullptr,
const char *  ns = nullptr 
)
inline

Prints the beginning of an XML node.

Parameters
nodeName of the node
attributesOptional attributes
nsOptional namespace
Returns
Number of bytes written

◆ printNodeBeginNl()

size_t tiny_dlna::XMLPrinter::printNodeBeginNl ( const char *  node,
const char *  attributes = nullptr,
const char *  ns = nullptr 
)
inline

Prints the beginning of an XML node and a newline.

Parameters
nodeName of the node
attributesOptional attributes
nsOptional namespace
Returns
Number of bytes written

◆ printNodeEnd()

size_t tiny_dlna::XMLPrinter::printNodeEnd ( const char *  node,
const char *  ns = nullptr 
)
inline

Prints the end of an XML node.

Parameters
nodeName of the node
nsOptional namespace
Returns
Number of bytes written

◆ printStateVariable()

size_t tiny_dlna::XMLPrinter::printStateVariable ( const char *  name,
const char *  dataType,
bool  sendEvents = false,
std::function< void()>  extra = nullptr 
)
inline

Helper to print a UPnP <stateVariable> element with name, dataType and optional sendEvents attribute and inner content callback.

Parameters
nameState variable name
dataTypeState variable data type
sendEventsWhether to send events
extraOptional callback for extra content
Returns
Number of bytes written

◆ printXMLHeader()

size_t tiny_dlna::XMLPrinter::printXMLHeader ( )
inline

Prints the XML header.

Returns
Number of bytes written

◆ setOutput()

void tiny_dlna::XMLPrinter::setOutput ( Print &  output)
inline

Defines the output Print object.

Parameters
outputReference to Print object

Member Data Documentation

◆ p_out

Print* tiny_dlna::XMLPrinter::p_out = &Serial
protected

The documentation for this struct was generated from the following file: