10#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
14#ifdef USE_API_USER_DEFINED_ACTIONS
25#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
41 UserServiceBase(
const char *name,
const std::array<
const char *,
sizeof...(Ts)> &arg_names,
53 msg.
args.init(
sizeof...(Ts));
54 for (
size_t i = 0; i <
sizeof...(Ts); i++) {
55 auto &arg = msg.
args.emplace_back();
56 arg.type = arg_types[i];
63 if (req.
key != this->key_)
65 if (req.
args.size() !=
sizeof...(Ts))
67#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
70 this->
execute_(req.
args, 0,
false, std::make_index_sequence<
sizeof...(Ts)>{});
75#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
77 if (req.
key != this->key_)
79 if (req.
args.size() !=
sizeof...(Ts))
88 template<
typename ArgsContainer,
size_t... S>
89 void execute_(
const ArgsContainer &
args,
uint32_t call_id,
bool return_response, std::index_sequence<S...> ) {
115 msg.
args.init(
sizeof...(Ts));
116 for (
size_t i = 0; i <
sizeof...(Ts); i++) {
117 auto &arg = msg.
args.emplace_back();
118 arg.type = arg_types[i];
125 if (req.
key != this->key_)
127 if (req.
args.size() !=
sizeof...(Ts))
129#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
132 this->
execute_(req.
args, 0,
false, std::make_index_sequence<
sizeof...(Ts)>{});
137#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
140 if (req.
key != this->key_)
142 if (req.
args.size() !=
sizeof...(Ts))
151 template<
typename ArgsContainer,
size_t... S>
166template<
typename... Ts>
171 :
UserServiceBase<Ts...>(name, arg_names, enums::SUPPORTS_RESPONSE_NONE) {}
178template<
typename... Ts>
180 public Trigger<uint32_t, bool, Ts...> {
183 :
UserServiceBase<Ts...>(name, arg_names, enums::SUPPORTS_RESPONSE_OPTIONAL) {}
187 this->trigger(call_id, return_response,
x...);
192template<
typename... Ts>
194 public Trigger<uint32_t, Ts...> {
197 :
UserServiceBase<Ts...>(name, arg_names, enums::SUPPORTS_RESPONSE_ONLY) {}
204template<
typename... Ts>
206 public Trigger<uint32_t, Ts...> {
209 :
UserServiceBase<Ts...>(name, arg_names, enums::SUPPORTS_RESPONSE_STATUS) {}
218#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
233#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
234 void set_data(std::function<
void(Ts..., JsonObject)> &&func) {
240 void play(
const Ts &...
x)
override {
242 auto args = std::make_tuple(
x...);
248#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
253 if constexpr (
sizeof...(Ts) >= 2) {
254 if constexpr (std::is_same_v<std::tuple_element_t<1, std::tuple<Ts...>>,
bool>) {
256 bool return_response = std::get<1>(
args);
257 if (!return_response) {
270 reinterpret_cast<const uint8_t *
>(json_buf.data()), json_buf.
size());
281#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
294 void play(
const Ts &...
x)
override {
296 auto args = std::make_tuple(
x...);
StringRef is a reference to a string owned by something else.
constexpr size_type size() const
Function-pointer-only templatable storage (4 bytes on 32-bit).
Primary TemplatableValue: stores either a constant value or a function pointer.
void play(const Ts &...x) override
TemplatableFn< bool, Ts... > success_
void set_success(V success)
void set_data(std::function< void(Ts..., JsonObject)> &&func)
void set_error_message(V error)
void set_is_optional_mode(bool is_optional)
APIRespondAction(APIServer *parent)
std::function< void(Ts..., JsonObject)> json_builder_
TemplatableValue< std::string, Ts... > error_message_
void send_action_response(uint32_t action_call_id, bool success, StringRef error_message)
void unregister_active_action_call(uint32_t action_call_id)
APIUnregisterServiceCallAction(APIServer *parent)
void play(const Ts &...x) override
FixedVector< ExecuteServiceArgument > args
enums::SupportsResponseType supports_response
FixedVector< ListEntitiesServicesArgument > args
bool execute_service(const ExecuteServiceRequest &req, uint32_t action_call_id) override
void execute_(const ArgsContainer &args, uint32_t call_id, bool return_response, std::index_sequence< S... >)
enums::SupportsResponseType supports_response_
virtual void execute(uint32_t call_id, bool return_response, Ts... x)=0
std::array< const char *, sizeof...(Ts)> arg_names_
ListEntitiesServicesResponse encode_list_service_response() override
bool execute_service(const ExecuteServiceRequest &req) override
UserServiceBase(const char *name, const std::array< const char *, sizeof...(Ts)> &arg_names, enums::SupportsResponseType supports_response=enums::SUPPORTS_RESPONSE_NONE)
virtual ListEntitiesServicesResponse encode_list_service_response()=0
virtual bool execute_service(const ExecuteServiceRequest &req, uint32_t action_call_id)=0
virtual bool execute_service(const ExecuteServiceRequest &req)=0
UserServiceDynamic(std::string name, const std::array< std::string, sizeof...(Ts)> &arg_names)
bool execute_service(const ExecuteServiceRequest &req) override
void execute_(const ArgsContainer &args, uint32_t call_id, bool return_response, std::index_sequence< S... >)
bool execute_service(const ExecuteServiceRequest &req, uint32_t action_call_id) override
ListEntitiesServicesResponse encode_list_service_response() override
std::array< std::string, sizeof...(Ts)> arg_names_
virtual void execute(uint32_t call_id, bool return_response, Ts... x)=0
UserServiceTrigger(const char *name, const std::array< const char *, sizeof...(Ts)> &arg_names)
void execute(uint32_t, bool, Ts... x) override
void execute(uint32_t call_id, bool return_response, Ts... x) override
UserServiceTrigger(const char *name, const std::array< const char *, sizeof...(Ts)> &arg_names)
void execute(uint32_t call_id, bool, Ts... x) override
UserServiceTrigger(const char *name, const std::array< const char *, sizeof...(Ts)> &arg_names)
UserServiceTrigger(const char *name, const std::array< const char *, sizeof...(Ts)> &arg_names)
void execute(uint32_t call_id, bool, Ts... x) override
Builder class for creating JSON documents without lambdas.
SerializationBuffer serialize()
Serialize the JSON document to a SerializationBuffer (stack-first allocation) Uses 512-byte stack buf...
enums::ServiceArgType to_service_arg_type()
T get_execute_arg_value(const ExecuteServiceArgument &arg)
const char int const __FlashStringHelper va_list args
uint32_t fnv1_hash(const char *str)
Calculate a FNV-1 hash of str.