useDynLib("BiocParallel", .registration = TRUE)

import(methods)

importFrom(stats, setNames, terms, runif)

importFrom(utils, capture.output, find, head, tail, relist,
           setTxtProgressBar, txtProgressBar)
importFrom(parallel, nextRNGStream, nextRNGSubStream)

importFrom(codetools, findGlobals)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 classes
###

exportClass(
    BiocParallelParam,
    MulticoreParam,
    SnowParam,
    DoparParam,
    SerialParam,
    BatchJobsParam,
    BatchtoolsParam,
    BPValidate
)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export non-generic functions
###

export(
    MulticoreParam, SnowParam, DoparParam, SerialParam, BatchJobsParam,
    BatchtoolsParam,

    ## register
    register, registered, bpparam,

    ## accessor
    bpnworkers,

    ## error handlers
    bptry,

    ## accessor for the errors
    bpresult,

    ## helpers
    bploop,                             # worker, manager loops
    multicoreWorkers, snowWorkers,
    batchtoolsWorkers, batchtoolsCluster, batchtoolsRegistryargs,
    batchtoolsTemplate,
    bpvalidate, bpok, bperrorTypes,
    bprunMPIslave,
    bprunMPIworker,

    ## iteration
    bpiterateAlong,

    ## ipcmutex
    ipcid, ipcremove, ipclock, ipctrylock, ipcunlock, ipclocked,
    ipcyield, ipcvalue, ipcreset,

    bpoptions, .registerOption
)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 generics and methods defined in BiocParallel
###

export(
    bplapply, bpvec, bpvectorize, bpmapply, bpaggregate, bpiterate,

    ## bp-controls
    bpworkers, "bpworkers<-", bpbackend, "bpbackend<-",
    bptasks, "bptasks<-", bpjobname, "bpjobname<-",
    bpstart, bpstop, bpisup,
    bpstopOnError, "bpstopOnError<-",
    bpprogressbar, "bpprogressbar<-", bpRNGseed, "bpRNGseed<-",
    bptimeout, "bptimeout<-", bpexportglobals, "bpexportglobals<-",
    bpexportvariables, "bpexportvariables<-",
    bpforceGC, "bpforceGC<-",
    bpfallback, "bpfallback<-",
    bplog, "bplog<-", bplogdir, "bplogdir<-",
    bpthreshold, "bpthreshold<-", bpresultdir, "bpresultdir<-",

    ## schedule
    bpschedule
)

### Same list as above.
exportMethods(
    bplapply, bpvec, bpvectorize, bpmapply, bpaggregate, bpiterate,

    ## bp-controls
    bpworkers, "bpworkers<-", bpbackend, "bpbackend<-",
    bptasks, "bptasks<-", bpjobname, "bpjobname<-",
    bpstart, bpstop, bpisup,
    bpstopOnError, "bpstopOnError<-",
    bpprogressbar, "bpprogressbar<-", bpRNGseed, "bpRNGseed<-",
    bptimeout, "bptimeout<-", bplog, "bplog<-", bplogdir, "bplogdir<-",
    bpthreshold, "bpthreshold<-", bpresultdir, "bpresultdir<-",

    ## schedule
    bpschedule
)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 methods for generics not defined in BiocParallel
###

exportMethods(
    show
)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S3 methods
###

S3method(print, remote_error)
S3method(print, bplist_error)

S3method(bploop, lapply)
S3method(bploop, iterate)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export 'developer' API for extending BiocParallelParam
###

export(
    .BiocParallelParam_prototype, .prototype_update, .prettyPath,
    .send_to, .recv_any, .send, .recv, .close, .send_all, .recv_all,
    .bpstart_impl, .bpstop_impl, .bpworker_impl,
    .bplapply_impl, .bpiterate_impl,
    .error_worker_comm,
    .manager, .manager_send, .manager_recv,
    .manager_send_all, .manager_recv_all,
    .manager_capacity,
    .manager_flush, .manager_cleanup,
    .task_const, .task_dynamic, .task_remake
)
