// Generated by cpp4r: do not edit by hand
// clang-format off


#include "cpp4r/declarations.hpp"
#include <R_ext/Visibility.h>
#include <cstring>

namespace {
// R_CallMethodDef requires a DL_FUNC (void (*)()), which necessarily
// differs from the real signature of each registered function. A direct
// cast between incompatible function pointer types triggers
// -Wcast-function-type, and CRAN's checks disallow suppressing that with
// compiler pragmas. Reinterpret the pointer by copying its bytes instead:
// this never casts between function pointer types (memcpy's arguments are
// ordinary object pointers to the local function-pointer variables), so it
// is warning-free and portable across the platforms R supports.
template <typename Fn> DL_FUNC cpp4r_to_dl_func(Fn fn) {
  static_assert(sizeof(DL_FUNC) == sizeof(Fn), "function pointer size mismatch");
  DL_FUNC out;
  std::memcpy(&out, &fn, sizeof(out));
  return out;
}
} // namespace

// callback_registry.cpp
void testCallbackOrdering();
extern "C" SEXP _later2_testCallbackOrdering() {
  BEGIN_CPP4R
    testCallbackOrdering();
    return R_NilValue;
  END_CPP4R
}
// debug.cpp
std::string log_level(std::string level);
extern "C" SEXP _later2_log_level(SEXP level) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(log_level(cpp4r::as_cpp<cpp4r::decay_t<std::string>>(level)));
  END_CPP4R
}
// debug.cpp
bool using_ubsan();
extern "C" SEXP _later2_using_ubsan() {
  BEGIN_CPP4R
    return cpp4r::as_sexp(using_ubsan());
  END_CPP4R
}
// fd.cpp
SEXP execLater_fd(SEXP callback, cpp4r::integers readfds, cpp4r::integers writefds, cpp4r::integers exceptfds, SEXP timeoutSecs, cpp4r::integers loop_id);
extern "C" SEXP _later2_execLater_fd(SEXP callback, SEXP readfds, SEXP writefds, SEXP exceptfds, SEXP timeoutSecs, SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(execLater_fd(cpp4r::as_cpp<cpp4r::decay_t<SEXP>>(callback), cpp4r::as_cpp<cpp4r::decay_t<cpp4r::integers>>(readfds), cpp4r::as_cpp<cpp4r::decay_t<cpp4r::integers>>(writefds), cpp4r::as_cpp<cpp4r::decay_t<cpp4r::integers>>(exceptfds), cpp4r::as_cpp<cpp4r::decay_t<SEXP>>(timeoutSecs), cpp4r::as_cpp<cpp4r::decay_t<cpp4r::integers>>(loop_id)));
  END_CPP4R
}
// fd.cpp
bool fd_cancel(SEXP xptr);
extern "C" SEXP _later2_fd_cancel(SEXP xptr) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(fd_cancel(cpp4r::as_cpp<cpp4r::decay_t<SEXP>>(xptr)));
  END_CPP4R
}
// later2.cpp
void setCurrentRegistryId(int id);
extern "C" SEXP _later2_setCurrentRegistryId(SEXP id) {
  BEGIN_CPP4R
    setCurrentRegistryId(cpp4r::as_cpp<cpp4r::decay_t<int>>(id));
    return R_NilValue;
  END_CPP4R
}
// later2.cpp
int getCurrentRegistryId();
extern "C" SEXP _later2_getCurrentRegistryId() {
  BEGIN_CPP4R
    return cpp4r::as_sexp(getCurrentRegistryId());
  END_CPP4R
}
// later2.cpp
bool deleteCallbackRegistry(int loop_id);
extern "C" SEXP _later2_deleteCallbackRegistry(SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(deleteCallbackRegistry(cpp4r::as_cpp<cpp4r::decay_t<int>>(loop_id)));
  END_CPP4R
}
// later2.cpp
bool notifyRRefDeleted(int loop_id);
extern "C" SEXP _later2_notifyRRefDeleted(SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(notifyRRefDeleted(cpp4r::as_cpp<cpp4r::decay_t<int>>(loop_id)));
  END_CPP4R
}
// later2.cpp
void createCallbackRegistry(int id, int parent_id);
extern "C" SEXP _later2_createCallbackRegistry(SEXP id, SEXP parent_id) {
  BEGIN_CPP4R
    createCallbackRegistry(cpp4r::as_cpp<cpp4r::decay_t<int>>(id), cpp4r::as_cpp<cpp4r::decay_t<int>>(parent_id));
    return R_NilValue;
  END_CPP4R
}
// later2.cpp
bool existsCallbackRegistry(int id);
extern "C" SEXP _later2_existsCallbackRegistry(SEXP id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(existsCallbackRegistry(cpp4r::as_cpp<cpp4r::decay_t<int>>(id)));
  END_CPP4R
}
// later2.cpp
cpp4r::sexp list_queue_(int id);
extern "C" SEXP _later2_list_queue_(SEXP id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(list_queue_(cpp4r::as_cpp<cpp4r::decay_t<int>>(id)));
  END_CPP4R
}
// later2.cpp
bool execCallbacks(double timeoutSecs, bool runAll, int loop_id);
extern "C" SEXP _later2_execCallbacks(SEXP timeoutSecs, SEXP runAll, SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(execCallbacks(cpp4r::as_cpp<cpp4r::decay_t<double>>(timeoutSecs), cpp4r::as_cpp<cpp4r::decay_t<bool>>(runAll), cpp4r::as_cpp<cpp4r::decay_t<int>>(loop_id)));
  END_CPP4R
}
// later2.cpp
bool idle(int loop_id);
extern "C" SEXP _later2_idle(SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(idle(cpp4r::as_cpp<cpp4r::decay_t<int>>(loop_id)));
  END_CPP4R
}
// later2.cpp
void ensureInitialized();
extern "C" SEXP _later2_ensureInitialized() {
  BEGIN_CPP4R
    ensureInitialized();
    return R_NilValue;
  END_CPP4R
}
// later2.cpp
std::string execLater(SEXP callback, double delaySecs, int loop_id);
extern "C" SEXP _later2_execLater(SEXP callback, SEXP delaySecs, SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(execLater(cpp4r::as_cpp<cpp4r::decay_t<SEXP>>(callback), cpp4r::as_cpp<cpp4r::decay_t<double>>(delaySecs), cpp4r::as_cpp<cpp4r::decay_t<int>>(loop_id)));
  END_CPP4R
}
// later2.cpp
bool cancel(std::string callback_id_s, int loop_id);
extern "C" SEXP _later2_cancel(SEXP callback_id_s, SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(cancel(cpp4r::as_cpp<cpp4r::decay_t<std::string>>(callback_id_s), cpp4r::as_cpp<cpp4r::decay_t<int>>(loop_id)));
  END_CPP4R
}
// later2.cpp
double nextOpSecs(int loop_id);
extern "C" SEXP _later2_nextOpSecs(SEXP loop_id) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(nextOpSecs(cpp4r::as_cpp<cpp4r::decay_t<int>>(loop_id)));
  END_CPP4R
}
// wref.cpp
SEXP new_weakref(SEXP x);
extern "C" SEXP _later2_new_weakref(SEXP x) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(new_weakref(cpp4r::as_cpp<cpp4r::decay_t<SEXP>>(x)));
  END_CPP4R
}
// wref.cpp
SEXP wref_key(SEXP x);
extern "C" SEXP _later2_wref_key(SEXP x) {
  BEGIN_CPP4R
    return cpp4r::as_sexp(wref_key(cpp4r::as_cpp<cpp4r::decay_t<SEXP>>(x)));
  END_CPP4R
}

extern "C" {
static const R_CallMethodDef CallEntries[] = {
    {"_later2_testCallbackOrdering", cpp4r_to_dl_func(&_later2_testCallbackOrdering), 0},
    {"_later2_log_level", cpp4r_to_dl_func(&_later2_log_level), 1},
    {"_later2_using_ubsan", cpp4r_to_dl_func(&_later2_using_ubsan), 0},
    {"_later2_execLater_fd", cpp4r_to_dl_func(&_later2_execLater_fd), 6},
    {"_later2_fd_cancel", cpp4r_to_dl_func(&_later2_fd_cancel), 1},
    {"_later2_setCurrentRegistryId", cpp4r_to_dl_func(&_later2_setCurrentRegistryId), 1},
    {"_later2_getCurrentRegistryId", cpp4r_to_dl_func(&_later2_getCurrentRegistryId), 0},
    {"_later2_deleteCallbackRegistry", cpp4r_to_dl_func(&_later2_deleteCallbackRegistry), 1},
    {"_later2_notifyRRefDeleted", cpp4r_to_dl_func(&_later2_notifyRRefDeleted), 1},
    {"_later2_createCallbackRegistry", cpp4r_to_dl_func(&_later2_createCallbackRegistry), 2},
    {"_later2_existsCallbackRegistry", cpp4r_to_dl_func(&_later2_existsCallbackRegistry), 1},
    {"_later2_list_queue_", cpp4r_to_dl_func(&_later2_list_queue_), 1},
    {"_later2_execCallbacks", cpp4r_to_dl_func(&_later2_execCallbacks), 3},
    {"_later2_idle", cpp4r_to_dl_func(&_later2_idle), 1},
    {"_later2_ensureInitialized", cpp4r_to_dl_func(&_later2_ensureInitialized), 0},
    {"_later2_execLater", cpp4r_to_dl_func(&_later2_execLater), 3},
    {"_later2_cancel", cpp4r_to_dl_func(&_later2_cancel), 2},
    {"_later2_nextOpSecs", cpp4r_to_dl_func(&_later2_nextOpSecs), 1},
    {"_later2_new_weakref", cpp4r_to_dl_func(&_later2_new_weakref), 1},
    {"_later2_wref_key", cpp4r_to_dl_func(&_later2_wref_key), 1},
    {NULL, NULL, 0}
};
}

void later_init(DllInfo * dll);
extern "C" attribute_visible void R_init_later2(DllInfo* dll){
  R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
  R_useDynamicSymbols(dll, FALSE);
  later_init(dll);
  R_forceSymbols(dll, TRUE);
}
