Skip to content

Commit

Permalink
Merge pull request #774 from SignalK/null_lambda_schema
Browse files Browse the repository at this point in the history
Provide correct ConfigSchema for template classes
  • Loading branch information
mairas authored Oct 15, 2024
2 parents a67abfd + 67dfb39 commit 60bb062
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/sensesp/net/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class HTTPServer : public FileSystemSaveable {
friend esp_err_t call_request_dispatcher(httpd_req_t* req);
};

inline const String ConfigSchema(const HTTPServer& obj) {
return "null";
}

inline bool ConfigRequiresRestart(const HTTPServer& obj) { return true; }

} // namespace sensesp
Expand Down
4 changes: 4 additions & 0 deletions src/sensesp/net/networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ class Networking : public FileSystemSaveable,
std::shared_ptr<LambdaConsumer<WiFiState>> wifi_state_emitter_;
};

inline const String ConfigSchema(const Networking& obj) {
return "null";
}

inline bool ConfigRequiresRestart(const Networking& obj) { return true; }

} // namespace sensesp
Expand Down
4 changes: 4 additions & 0 deletions src/sensesp/signalk/signalk_ws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class SKWSClient : public FileSystemSaveable,
SKWSConnectionState get_connection_state() { return task_connection_state_; }
};

inline const String ConfigSchema(const SKWSClient& obj) {
return "null";
}

inline bool ConfigRequiresRestart(const SKWSClient& obj) { return true; }

} // namespace sensesp
Expand Down
17 changes: 7 additions & 10 deletions src/sensesp/ui/config_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <map>
#include <memory>
#include <vector>
#include <cstddef>

#include "Arduino.h"
#include "ArduinoJson.h"
Expand Down Expand Up @@ -33,23 +34,20 @@ template <>
const char* get_schema_type_string(const bool dummy);

/**
* @brief Template function to provide a configuration schema for a
* ConfigItemT<T>.
* @brief Provide a configuration schema for a
* ConfigItemT<nullptr>.
*
* For this to work, an overload or a specialization of this function must
* be provided for each type T that is used in a ConfigItemT<T>.
*
* @tparam T
* @param obj
* @return const char*
*/
template <typename T>
const String ConfigSchema(const T& obj) {
inline const String ConfigSchema(const std::nullptr_t& obj) {
return "null";
}

template <typename T>
const String ConfigSchema(const std::shared_ptr<T>& obj) {
return ConfigSchema(*obj);
}

template <typename T>
bool ConfigRequiresRestart(const T& obj) {
return false;
Expand Down Expand Up @@ -271,7 +269,6 @@ class ConfigItemT : public ConfigItemBase {
String schema = ConfigSchema(*config_object_);
return schema;
}

};

/**
Expand Down

0 comments on commit 60bb062

Please sign in to comment.