15 const auto& cmd = args[0];
19 encoder.
write(models);
21 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
27 bool called_by_event =
false) {
29 const auto& cmd = args[0];
30 const size_t model_id = std::atoi(args[1].c_str());
35 auto it = std::find_if(models.begin(), models.end(), [&](
const ma_model_t& m) { return m.id == model_id; });
36 if (it == models.end()) {
41 #if MA_USE_FILESYSTEM_POSIX
42 ret =
static_resource->engine->load(
static_cast<const char*
>(it->addr));
46 if (ret !=
MA_OK) [[unlikely]]
51 if (!called_by_event) {
63 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
72 if (!transport || !*transport) {
81 std::vector<std::string> args{
"INIT@MODEL", std::to_string(
static_cast<int>(model_id))};
87 const auto& cmd = args[0];
92 auto it = std::find_if(
93 models.begin(), models.end(), [&](
const ma_model_t& m) { return m.id == static_resource->current_model_id; });
94 if (it == models.end()) {
99 if (it != models.end()) {
100 std::vector<ma_model_t> model{*it};
101 encoder.
write(model);
104 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
Definition: ma_codec_base.h:14
virtual ma_err_t end()=0
Encoder type for end.
virtual const void * data() const =0
Encoder type for get data.
virtual ma_err_t begin()=0
Encoder type for begin.
virtual ma_err_t write(const std::string &key, int8_t value)=0
Encoder type for write int8_t value.
virtual const size_t size() const =0
Encoder type for get size.
Definition: ma_transport.h:12
virtual size_t send(const char *data, size_t length) noexcept=0
#define MA_LOGD(TAG,...)
Definition: ma_debug.h:79
#define MA_ASSERT(expr)
Definition: ma_debug.h:119
#define MA_TAG
Definition: ma_debug.h:9
#define MA_STORAGE_KEY_MODEL_ID
Definition: ma_definations.h:19
@ MA_MSG_TYPE_RESP
Definition: ma_types.h:252
ma_err_t
Definition: ma_types.h:21
@ MA_ENOENT
Definition: ma_types.h:33
@ MA_OK
Definition: ma_types.h:23
Definition: ma_model_classifier.cpp:5
Definition: algorithm.hpp:11
void configureModel(const std::vector< std::string > &args, Transport &transport, Encoder &encoder, bool called_by_event=false)
Definition: model.hpp:24
void initDefaultModel(Encoder &encoder)
Definition: model.hpp:66
void getModelInfo(const std::vector< std::string > &args, Transport &transport, Encoder &encoder)
Definition: model.hpp:85
void getAvailableModels(const std::vector< std::string > &args, Transport &transport, Encoder &encoder)
Definition: model.hpp:13
#define static_resource
Definition: resource.hpp:64
Definition: ma_types.h:289