Added getSize() to HapOut and changed default behavior to NEVER output anything
Note: getSize() must be called before flush(), which resets byte counter
This commit is contained in:
parent
18c74e6f17
commit
83924a6bdf
23
src/HAP.cpp
23
src/HAP.cpp
|
|
@ -1638,7 +1638,7 @@ void Nonce::inc(){
|
||||||
|
|
||||||
HapOut::HapStreamBuffer::HapStreamBuffer(){
|
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 adding null terminator when printing text
|
||||||
setp(buffer, buffer+bufSize-1);
|
setp(buffer, buffer+bufSize-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1652,9 +1652,12 @@ HapOut::HapStreamBuffer::~HapStreamBuffer(){
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
int HapOut::HapStreamBuffer::flushBuffer(){
|
void HapOut::HapStreamBuffer::flushBuffer(){
|
||||||
|
|
||||||
int num=pptr()-pbase();
|
int num=pptr()-pbase();
|
||||||
|
|
||||||
|
byteCount+=num;
|
||||||
|
|
||||||
if(logLevel<=homeSpan.getLogLevel()){
|
if(logLevel<=homeSpan.getLogLevel()){
|
||||||
buffer[num]='\0';
|
buffer[num]='\0';
|
||||||
Serial.print(buffer);
|
Serial.print(buffer);
|
||||||
|
|
@ -1662,12 +1665,10 @@ int HapOut::HapStreamBuffer::flushBuffer(){
|
||||||
|
|
||||||
if(hapClient!=NULL){
|
if(hapClient!=NULL){
|
||||||
hapClient->client.write(buffer,num);
|
hapClient->client.write(buffer,num);
|
||||||
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1);
|
|
||||||
|
|
||||||
pbump(-num);
|
pbump(-num);
|
||||||
return(num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
@ -1679,8 +1680,7 @@ std::streambuf::int_type HapOut::HapStreamBuffer::overflow(std::streambuf::int_t
|
||||||
pbump(1);
|
pbump(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flushBuffer()==EOF)
|
flushBuffer();
|
||||||
return(EOF);
|
|
||||||
return(c);
|
return(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1688,14 +1688,13 @@ std::streambuf::int_type HapOut::HapStreamBuffer::overflow(std::streambuf::int_t
|
||||||
|
|
||||||
int HapOut::HapStreamBuffer::sync(){
|
int HapOut::HapStreamBuffer::sync(){
|
||||||
|
|
||||||
int_type c=flushBuffer();
|
flushBuffer();
|
||||||
|
|
||||||
enablePrettyPrint=false;
|
logLevel=255;
|
||||||
logLevel=0;
|
|
||||||
hapClient=NULL;
|
hapClient=NULL;
|
||||||
|
enablePrettyPrint=false;
|
||||||
|
byteCount=0;
|
||||||
|
|
||||||
if(c==EOF)
|
|
||||||
return(-1);
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
10
src/HAP.h
10
src/HAP.h
|
|
@ -191,12 +191,14 @@ class HapOut : public std::ostream {
|
||||||
const size_t bufSize=1024; // max allowed for HAP encrypted records
|
const size_t bufSize=1024; // max allowed for HAP encrypted records
|
||||||
char *buffer;
|
char *buffer;
|
||||||
HAPClient *hapClient=NULL;
|
HAPClient *hapClient=NULL;
|
||||||
int logLevel=0;
|
int logLevel=255; // default is NOT to print anything
|
||||||
boolean enablePrettyPrint=false;
|
boolean enablePrettyPrint=false;
|
||||||
|
size_t byteCount=0;
|
||||||
|
|
||||||
int flushBuffer() ;
|
void flushBuffer();
|
||||||
int_type overflow(int_type c) override;
|
int_type overflow(int_type c) override;
|
||||||
int sync() override;
|
int sync() override;
|
||||||
|
size_t getSize(){return(byteCount+pptr()-pbase());}
|
||||||
|
|
||||||
HapStreamBuffer();
|
HapStreamBuffer();
|
||||||
~HapStreamBuffer();
|
~HapStreamBuffer();
|
||||||
|
|
@ -210,7 +212,9 @@ class HapOut : public std::ostream {
|
||||||
|
|
||||||
HapOut& setHapClient(HAPClient *hapClient){hapBuffer.hapClient=hapClient;return(*this);}
|
HapOut& setHapClient(HAPClient *hapClient){hapBuffer.hapClient=hapClient;return(*this);}
|
||||||
HapOut& setLogLevel(int logLevel){hapBuffer.logLevel=logLevel;return(*this);}
|
HapOut& setLogLevel(int logLevel){hapBuffer.logLevel=logLevel;return(*this);}
|
||||||
HapOut& prettyPrint(){hapBuffer.enablePrettyPrint=true;return(*this);}
|
HapOut& prettyPrint(){hapBuffer.enablePrettyPrint=true;hapBuffer.logLevel=0;return(*this);}
|
||||||
|
|
||||||
|
size_t getSize(){return(hapBuffer.getSize());}
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue