// SPDX-License-Identifier: MPL-2.0
#include "devs/devs.h"
#include "devs/apic/lapic.h"
#include "devs/apic/ioapic.h"
#include "std/smp.h"
SH_STATUS sh_devs_query(char *path,sh_devs_RESULT *result) {
  if (path==SH_NULLPTR) return SH_STATUS_INVALID_PARAMETER;
  sh_uint64 path_len=sh_string_len(path);
  if (path_len==0 || path_len>256) return SH_STATUS_INVALID_PARAMETER;
  if (sh_string_compare(path,"$apic/lapic",11)) {
    if (path_len>11) {
      sh_uint64 remaining_text=sh_string_len(path)-sh_string_len("$apic/lapic");
      return sh_lapic_devs_query(sh_string_substring(path,sh_string_len("$apic/lapic"),remaining_text,sh_smp_gs_base()->per_cpu->temp_buffer),result);
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(path,"$apic/ioapic",12)) {
    if (path_len>12) {
      sh_uint64 remaining_text=sh_string_len(path)-sh_string_len("$apic/ioapic");
      return sh_ioapic_devs_query(sh_string_substring(path,sh_string_len("$apic/ioapic"),remaining_text,sh_smp_gs_base()->per_cpu->temp_buffer),result);
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(path,"$tsc",4)) {
    if (path_len>4) {
      sh_uint64 remaining_text=sh_string_len(path)-sh_string_len("$tsc");
      return sh_tsc_devs_query(sh_string_substring(path,sh_string_len("$tsc"),remaining_text,sh_smp_gs_base()->per_cpu->temp_buffer),result);
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(path,"$kernel/conf",12)) {
    if (path_len>12) {
      sh_uint64 remaining_text=sh_string_len(path)-sh_string_len("$kernel/conf");
      return sh_conf_devs_query(sh_string_substring(path,sh_string_len("$kernel/conf"),remaining_text,sh_smp_gs_base()->per_cpu->temp_buffer),result);
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(path,"$memory",7)) {
    if (path_len>7) {
      sh_uint64 remaining_text=sh_string_len(path)-sh_string_len("$memory");
      return sh_memory_devs_query(sh_string_substring(path,sh_string_len("$memory"),remaining_text,sh_smp_gs_base()->per_cpu->temp_buffer),result);
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(path,"$smp/cpu-count",14)) {
    if (path_len==14) {
      result->type=SH_DEVS_VALUE;
      result->value=(sh_uint64)sh_smp_get_cpu_count();
      return SH_STATUS_SUCCESS;
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else {
    return SH_STATUS_NOT_FOUND;
  }
}
