Esempio n. 1
0
// This is called right before the plugin library is removed from memory.
DFhackCExport command_result plugin_shutdown(color_ostream & out)
{
    CoreSuspender suspend;
    enabled = false;
    check_enabled(out); // delete the AI if it was enabled.
    return CR_OK;
}
Esempio n. 2
0
DFhackCExport command_result plugin_onupdate(color_ostream & out)
{
    if (!check_enabled(out))
        return CR_OK;

    events.onupdate(out);
    return CR_OK;
}
Esempio n. 3
0
MAV_SEVERITY AP_Arming::check_severity(const enum AP_Arming::ArmingChecks check) const
{
    // A check value of ARMING_CHECK_NONE means that the check is always run
    if (check_enabled(check) || check == ARMING_CHECK_NONE) {
        return MAV_SEVERITY_CRITICAL;
    }
    return MAV_SEVERITY_DEBUG; // technically should be NOTICE, but will annoy users at that level
}
Esempio n. 4
0
DFhackCExport command_result plugin_onstatechange(color_ostream & out, state_change_event event)
{
    if (!check_enabled(out))
        return CR_OK;

    events.onstatechange(out, event);
    return CR_OK;
}
Esempio n. 5
0
/*
  check base system operations
 */
bool AP_Arming::system_checks(bool report)
{
    if (check_enabled(ARMING_CHECK_SYSTEM)) {
        if (!hal.storage->healthy()) {
            check_failed(ARMING_CHECK_SYSTEM, report, "Param storage failed");
        }
    }
    return true;
}
Esempio n. 6
0
void video_sound_update(video_render_config_t *config, const BYTE *src,
                      unsigned int width, unsigned int height,
                      unsigned int xs, unsigned int ys,
                      unsigned int pitchs, viewport_t *viewport)
{
    const SDWORD *c1 = config->color_tables.ytablel;
    const SDWORD *c2 = config->color_tables.ytableh;
    unsigned int x, y;
    const BYTE *tmpsrc;
    float lum;
    int chipnum = get_chip_num(config);

    chip[chipnum].enabled = config->video_resources.audioleak;
    if (!check_enabled()) {
        video_sound.chip_enabled = 0;
        return;
    }
    video_sound.chip_enabled = 1;

    chip[chipnum].firstline = viewport->first_line;
    chip[chipnum].lastline = viewport->last_line;
    DBG(("video_sound_update (firstline:%d lastline:%d w:%d h:%d xs:%d ys:%d)", 
         chip[chipnum].firstline, chip[chipnum].lastline, width, height, xs, ys));

    width /= (config->doublesizex + 1);
    /* height /= (config->doublesizey + 1); */

    /* width += xs; */
    ys = chip[chipnum].firstline;
    height = chip[chipnum].lastline - chip[chipnum].firstline;

    src += (pitchs * ys) + xs;

    for (y = 0; y < height; y++) {
        lum = 0;
        tmpsrc = src;
        for (x = 0; x < width; x++) {
            lum += (c1[*tmpsrc] << 2) + c2[*tmpsrc] + 0x00010000;
            tmpsrc++;
        }
        chip[chipnum].lumas[ys] = lum / (float)width;
        src += pitchs;
        ys++;
    }
    lum = 0;
    for (y = chip[chipnum].firstline; y < chip[chipnum].lastline; y++) {
        lum += chip[chipnum].lumas[y];
    }
    chip[chipnum].avglum = lum / (float)height;
}
Esempio n. 7
0
Variant f_geoip_time_zone_by_country_and_region(CStrRef country_code, CStrRef region_code /* = null */) {
  check_enabled();

  if (country_code.empty()) {
    raise_warning("You need to specify at least the country code.");
    return false;
  }

  const char *timezone = GeoIP_time_zone_by_country_and_region(country_code.data(), region_code.data());
  if (timezone == NULL) {
    return false;
  }

  return String(timezone, CopyString);
}
Esempio n. 8
0
Variant f_geoip_region_name_by_code(CStrRef country_code, CStrRef region_code) {
  check_enabled();

  if (country_code.empty() || region_code.empty()) {
    raise_warning("You need to specify the country and region codes.");
    return false;
  }

  const char *region_name = GeoIP_region_name_by_code(country_code.data(), region_code.data());
  if (region_name == NULL) {
    return false;
  }

  return String(region_name, CopyString);
}
Esempio n. 9
0
/*
  check base system operations
 */
bool AP_Arming::system_checks(bool report)
{
    if (check_enabled(ARMING_CHECK_SYSTEM)) {
        if (!hal.storage->healthy()) {
            check_failed(ARMING_CHECK_SYSTEM, report, "Param storage failed");
            return false;
        }
    }
    if (AP::internalerror().errors() != 0) {
        check_failed(ARMING_CHECK_NONE, report, "Internal errors detected (0x%x)", AP::internalerror().errors());
        return false;
    }

    return true;
}
Esempio n. 10
0
bool is_db_avail(int64 database, bool log_warning = true) {
  check_enabled();

  if (database < 0 || database >= NUM_DB_TYPES)
  {   
    raise_warning("Database type given is out of bound.");
    return false;
  }   

  if (!RuntimeOption::GeoIPAutoreload && s_geoip->gi[database]) {
    return true;
  }

  if (! GeoIP_db_avail(database)) {
    if (log_warning) raise_warning("Required database not available at %s.", GeoIPDBFileName[database]);
    return false;
  }

  time_t now = time(NULL);

  // Refresh time is 5 seconds, to avoid to stat files all the time
  if (now < s_geoip->db_last_checked[database] + 5) {
    return true;
  }

  // We hit refresh timeout, checking file modification time
  struct stat db_stat;
  stat(GeoIPDBFileName[GEOIP_COUNTRY_EDITION], &db_stat);
  s_geoip->db_last_checked[database] = now;

  if (db_stat.st_mtime <= s_geoip->db_last_modified[database]) {
    return true;
  }

  if (s_geoip->gi[database]) GeoIP_delete(s_geoip->gi[database]);
  s_geoip->gi[database] = GeoIP_open_type(database, s_geoip->open_flags);
  s_geoip->db_last_modified[database] = now;

  Logger::Verbose("Loading %s db",  GeoIPDBFileName[database]);

  if (!s_geoip->gi[database] && log_warning) {
    raise_warning("Required database not available at %s.", GeoIPDBFileName[database]);
  }

  return s_geoip->gi[database] != NULL;
}
Esempio n. 11
0
command_result status_command(color_ostream & out, std::vector<std::string> & args)
{
    if (!args.empty())
    {
        return CR_WRONG_USAGE;
    }

    CoreSuspender suspend;

    if (!check_enabled(out))
    {
        out << "The AI is currently not running. Use enable df-ai to enable the AI.\n";
        return CR_OK;
    }

    AI::write_df(out, dwarfAI->status(), "\n", "\n", DF2CONSOLE);
    return CR_OK;
}
Esempio n. 12
0
void Hook_Shutdown()
{
    if (!lockstep_hooked)
    {
        return;
    }

#ifdef _WIN32
    Remove_Hook((void *)GetTickCount, Real_GetTickCount, (void *)Fake_GetTickCount);
#else
    Remove_Hook((void *)gettimeofday, Real_gettimeofday, (void *)Fake_gettimeofday);
#endif
    Remove_Hook((void *)SDL_GetTicks, Real_SDL_GetTicks, (void *)Fake_SDL_GetTicks);
    LOCKSTEP_DEBUG("unhooked ticks");

    if (BOOST_LIKELY(lockstep_renderer == enabler->renderer))
    {
        enabler->renderer = lockstep_renderer->real_renderer;
    }
    LOCKSTEP_DEBUG("deleting df_ai_renderer");
    delete lockstep_renderer;
    lockstep_renderer = nullptr;

    lockstep_hooked = false;

    if (lockstep_want_shutdown_now)
    {
        if (df::viewscreen *screen = Gui::getCurViewscreen(true))
        {
            screen->breakdown_level = interface_breakdown_types::QUIT;
        }
    }
    else if (disabling_plugin)
    {
        enabled = false;
        disabling_plugin = false;
        check_enabled(Core::getInstance().getConsole());
    }
}
Esempio n. 13
0
bool AP_Arming::can_checks(bool report)
{
#if HAL_WITH_UAVCAN
    if (check_enabled(ARMING_CHECK_SYSTEM)) {
        const char *fail_msg = nullptr;
        uint8_t num_drivers = AP::can().get_num_drivers();

        for (uint8_t i = 0; i < num_drivers; i++) {
            switch (AP::can().get_protocol_type(i)) {
                case AP_BoardConfig_CAN::Protocol_Type_KDECAN: {
// To be replaced with macro saying if KDECAN library is included
#if APM_BUILD_TYPE(APM_BUILD_ArduCopter) || APM_BUILD_TYPE(APM_BUILD_ArduPlane) || APM_BUILD_TYPE(APM_BUILD_ArduSub)
                    AP_KDECAN *ap_kdecan = AP_KDECAN::get_kdecan(i);
                    if (ap_kdecan != nullptr && !ap_kdecan->pre_arm_check(fail_msg)) {
                        if (fail_msg == nullptr) {
                            check_failed(ARMING_CHECK_SYSTEM, report, "KDECAN failed");
                        } else {
                            check_failed(ARMING_CHECK_SYSTEM, report, "%s", fail_msg);
                        }

                        return false;
                    }
                    break;
#else
                    UNUSED_RESULT(fail_msg); // prevent unused variable error
#endif
                }
                case AP_BoardConfig_CAN::Protocol_Type_UAVCAN:
                case AP_BoardConfig_CAN::Protocol_Type_None:
                default:
                    break;
            }
        }
    }
#endif
    return true;
}
Esempio n. 14
0
DFhackCExport command_result plugin_enable(color_ostream & out, bool enable)
{
    enabled = enable;
    check_enabled(out);
    return CR_OK;
}