From 814d751e715f20219485e74ecd5525eb2e4b7e36 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 27 Sep 2020 14:51:31 -0500 Subject: [PATCH] Created SpanService::setPrimary() and setHidden() These optional methods can be "chained" when instantiating a new SpanService to configure the Service as Primary or Hidden (or both). This alleviates the need to ServiceType to be propogated through the Service constructor. Next Up: Eliminate ServiceType construct and update Examples to use setPrimary instead. --- src/HomeSpan.cpp | 14 ++++++++++++++ src/HomeSpan.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 10319b8..af81875 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -933,6 +933,20 @@ SpanService::SpanService(const char *type, ServiceType mod){ /////////////////////////////// +SpanService *SpanService::setPrimary(){ + primary=true; + return(this); +} + +/////////////////////////////// + +SpanService *SpanService::setHidden(){ + hidden=true; + return(this); +} + +/////////////////////////////// + int SpanService::sprintfAttributes(char *cBuf){ int nBytes=0; diff --git a/src/HomeSpan.h b/src/HomeSpan.h index c8f1d13..9e066d7 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -115,6 +115,9 @@ struct SpanService{ SpanService(const char *type, ServiceType mod=ServiceType::Regular); + SpanService *setPrimary(); // sets the Service Type to be primary and returns pointer to self + SpanService *setHidden(); // sets the Service Type to be hidden and returns pointer to self + int sprintfAttributes(char *cBuf); // prints Service JSON records into buf; return number of characters printed, excluding null terminator virtual StatusCode update() {return(StatusCode::OK);} // update Service and return final statusCode based on updated Characteristics - should be overridden by DEVICE-SPECIFIC Services virtual void event(){} // event generation for Services that create their own events and need to notify HomeKit of a new Characteristic value(s)