luat_airui_components.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "luat_base.h"
  2. #include "luat_airui.h"
  3. #include "luat_mem.h"
  4. #define LUAT_LOG_TAG "airui"
  5. #include "luat_log.h"
  6. extern airui_parser_t airui_top_parsers[];
  7. int luat_airui_load_components(luat_airui_ctx_t* ctx, void *args, size_t tok_count) {
  8. jsmntok_t *tok = (jsmntok_t *)args;
  9. if (tok->type != JSMN_OBJECT) {
  10. LLOGE("json must be a map!!");
  11. return -4;
  12. }
  13. jsmntok_t *top = tok;
  14. size_t cur = 0;
  15. // 遍历数据,测试用
  16. #if 0
  17. for (size_t i = 0; i < tok_count; i++)
  18. {
  19. LLOGD("tok\t%d\t%d\t%d\t%d\t%d", i, tok[i].type, tok[i].start, tok[i].end, tok[i].size);
  20. }
  21. #endif
  22. LLOGD("top size %d", top->size);
  23. if (top->size < 3) {
  24. LLOGE("not a good ui data. top size < 3");
  25. return -5;
  26. }
  27. airui_parser_t* parser = airui_top_parsers;
  28. while (parser->cb != NULL)
  29. {
  30. int pos = jsmn_find_by_key(ctx->data, parser->name, tok, cur);
  31. if (pos > 0) {
  32. parser->cb(ctx, tok, pos);
  33. }
  34. else {
  35. LLOGD("parser key not found %s", parser->name);
  36. }
  37. parser ++;
  38. }
  39. return 0;
  40. }