Moved StreamBuf into HapOut as private nested class
This commit is contained in:
parent
117c348708
commit
18c74e6f17
11
src/HAP.cpp
11
src/HAP.cpp
|
|
@ -1152,7 +1152,6 @@ int HAPClient::getStatusURL(){
|
||||||
|
|
||||||
LOG2("\n>>>>>>>>>> %s >>>>>>>>>>\n",client.remoteIP().toString().c_str());
|
LOG2("\n>>>>>>>>>> %s >>>>>>>>>>\n",client.remoteIP().toString().c_str());
|
||||||
|
|
||||||
// hapStream.setHapClient(this).setLogLevel(2);
|
|
||||||
hapOut.setHapClient(this).setLogLevel(2);
|
hapOut.setHapClient(this).setLogLevel(2);
|
||||||
|
|
||||||
hapOut << "HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n";
|
hapOut << "HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n";
|
||||||
|
|
@ -1637,7 +1636,7 @@ void Nonce::inc(){
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
StreamBuffer::StreamBuffer(){
|
HapOut::HapStreamBuffer::HapStreamBuffer(){
|
||||||
|
|
||||||
buffer=(char *)HS_MALLOC(bufSize+1); // add 1 for optional null terminator when printing text
|
buffer=(char *)HS_MALLOC(bufSize+1); // add 1 for optional null terminator when printing text
|
||||||
setp(buffer, buffer+bufSize-1);
|
setp(buffer, buffer+bufSize-1);
|
||||||
|
|
@ -1645,7 +1644,7 @@ StreamBuffer::StreamBuffer(){
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
StreamBuffer::~StreamBuffer(){
|
HapOut::HapStreamBuffer::~HapStreamBuffer(){
|
||||||
|
|
||||||
sync();
|
sync();
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
@ -1653,7 +1652,7 @@ StreamBuffer::~StreamBuffer(){
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
int StreamBuffer::flushBuffer(){
|
int HapOut::HapStreamBuffer::flushBuffer(){
|
||||||
int num=pptr()-pbase();
|
int num=pptr()-pbase();
|
||||||
|
|
||||||
if(logLevel<=homeSpan.getLogLevel()){
|
if(logLevel<=homeSpan.getLogLevel()){
|
||||||
|
|
@ -1673,7 +1672,7 @@ int StreamBuffer::flushBuffer(){
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
StreamBuffer::int_type StreamBuffer::overflow(StreamBuffer::int_type c){
|
std::streambuf::int_type HapOut::HapStreamBuffer::overflow(std::streambuf::int_type c){
|
||||||
|
|
||||||
if(c!=EOF){
|
if(c!=EOF){
|
||||||
*pptr() = c;
|
*pptr() = c;
|
||||||
|
|
@ -1687,7 +1686,7 @@ StreamBuffer::int_type StreamBuffer::overflow(StreamBuffer::int_type c){
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
int StreamBuffer::sync(){
|
int HapOut::HapStreamBuffer::sync(){
|
||||||
|
|
||||||
int_type c=flushBuffer();
|
int_type c=flushBuffer();
|
||||||
|
|
||||||
|
|
|
||||||
55
src/HAP.h
55
src/HAP.h
|
|
@ -180,52 +180,41 @@ struct HAPClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
// StreamBuffer and HapOut Structures
|
// HapOut Structure
|
||||||
|
|
||||||
class HapOut;
|
|
||||||
|
|
||||||
class StreamBuffer : public std::streambuf {
|
|
||||||
|
|
||||||
friend HapOut;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
const size_t bufSize=1024; // max allowed for HAP encrypted records
|
|
||||||
char *buffer;
|
|
||||||
HAPClient *hapClient=NULL;
|
|
||||||
int logLevel=0;
|
|
||||||
boolean enablePrettyPrint=false;
|
|
||||||
|
|
||||||
int flushBuffer() ;
|
|
||||||
int_type overflow(int_type c) override;
|
|
||||||
int sync() override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
StreamBuffer();
|
|
||||||
~StreamBuffer();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class HapOut : public std::ostream {
|
class HapOut : public std::ostream {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
struct HapStreamBuffer : public std::streambuf {
|
||||||
|
|
||||||
|
const size_t bufSize=1024; // max allowed for HAP encrypted records
|
||||||
|
char *buffer;
|
||||||
|
HAPClient *hapClient=NULL;
|
||||||
|
int logLevel=0;
|
||||||
|
boolean enablePrettyPrint=false;
|
||||||
|
|
||||||
StreamBuffer *sBuf;
|
int flushBuffer() ;
|
||||||
|
int_type overflow(int_type c) override;
|
||||||
|
int sync() override;
|
||||||
|
|
||||||
|
HapStreamBuffer();
|
||||||
|
~HapStreamBuffer();
|
||||||
|
};
|
||||||
|
|
||||||
|
HapStreamBuffer hapBuffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HapOut(StreamBuffer *sBuf) : std::ostream(sBuf) {this->sBuf=sBuf;}
|
HapOut() : std::ostream(&hapBuffer){}
|
||||||
|
|
||||||
HapOut& setHapClient(HAPClient *hapClient){sBuf->hapClient=hapClient;return(*this);}
|
HapOut& setHapClient(HAPClient *hapClient){hapBuffer.hapClient=hapClient;return(*this);}
|
||||||
HapOut& setLogLevel(int logLevel){sBuf->logLevel=logLevel;return(*this);}
|
HapOut& setLogLevel(int logLevel){hapBuffer.logLevel=logLevel;return(*this);}
|
||||||
HapOut& prettyPrint(){sBuf->enablePrettyPrint=true;return(*this);}
|
HapOut& prettyPrint(){hapBuffer.enablePrettyPrint=true;return(*this);}
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
// Extern Variables
|
// Extern Variables
|
||||||
|
|
||||||
extern HAPClient **hap;
|
extern HAPClient **hap;
|
||||||
//extern std::ostream hapOut;
|
|
||||||
extern HapOut hapOut;
|
extern HapOut hapOut;
|
||||||
extern StreamBuffer hapStream;
|
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,7 @@ const __attribute__((section(".rodata_custom_desc"))) SpanPartition spanPartitio
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
StreamBuffer hapStream;
|
HapOut hapOut; // Specialized output stream that can both print to serial monitor and encrypt/transmit to HAP Clients with minimal memory usage (global-scope)
|
||||||
HapOut hapOut(&hapStream);
|
|
||||||
|
|
||||||
HAPClient **hap; // HAP Client structure containing HTTP client connections, parsing routines, and state variables (global-scoped variable)
|
HAPClient **hap; // HAP Client structure containing HTTP client connections, parsing routines, and state variables (global-scoped variable)
|
||||||
Span homeSpan; // HAP Attributes database and all related control functions for this Accessory (global-scoped variable)
|
Span homeSpan; // HAP Attributes database and all related control functions for this Accessory (global-scoped variable)
|
||||||
HapCharacteristics hapChars; // Instantiation of all HAP Characteristics (used to create SpanCharacteristics)
|
HapCharacteristics hapChars; // Instantiation of all HAP Characteristics (used to create SpanCharacteristics)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue