1865 |
return successResult(pNote ? EVENT_STATUS_NOTE_QUEUE : EVENT_STATUS_INACTIVE); |
return successResult(pNote ? EVENT_STATUS_NOTE_QUEUE : EVENT_STATUS_INACTIVE); |
1866 |
} |
} |
1867 |
|
|
1868 |
|
// callback_status() function |
1869 |
|
|
1870 |
|
InstrumentScriptVMFunction_callback_status::InstrumentScriptVMFunction_callback_status(InstrumentScriptVM* parent) |
1871 |
|
: m_vm(parent) |
1872 |
|
{ |
1873 |
|
} |
1874 |
|
|
1875 |
|
VMFnResult* InstrumentScriptVMFunction_callback_status::exec(VMFnArgs* args) { |
1876 |
|
const script_callback_id_t id = args->arg(0)->asInt()->evalInt(); |
1877 |
|
if (!id) { |
1878 |
|
wrnMsg("callback_status(): callback ID for argument 1 may not be zero"); |
1879 |
|
return successResult(); |
1880 |
|
} |
1881 |
|
|
1882 |
|
AbstractEngineChannel* pEngineChannel = |
1883 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
1884 |
|
|
1885 |
|
RTList<ScriptEvent>::Iterator itCallback = pEngineChannel->ScriptCallbackByID(id); |
1886 |
|
if (!itCallback) |
1887 |
|
return successResult(CALLBACK_STATUS_TERMINATED); |
1888 |
|
|
1889 |
|
return successResult( |
1890 |
|
(m_vm->m_event->execCtx == itCallback->execCtx) ? |
1891 |
|
CALLBACK_STATUS_RUNNING : CALLBACK_STATUS_QUEUE |
1892 |
|
); |
1893 |
|
} |
1894 |
|
|
1895 |
// wait() function (overrides core wait() implementation) |
// wait() function (overrides core wait() implementation) |
1896 |
|
|
1897 |
InstrumentScriptVMFunction_wait::InstrumentScriptVMFunction_wait(InstrumentScriptVM* parent) |
InstrumentScriptVMFunction_wait::InstrumentScriptVMFunction_wait(InstrumentScriptVM* parent) |
1938 |
return successResult(); |
return successResult(); |
1939 |
} |
} |
1940 |
|
|
1941 |
|
// abort() function |
1942 |
|
|
1943 |
|
InstrumentScriptVMFunction_abort::InstrumentScriptVMFunction_abort(InstrumentScriptVM* parent) |
1944 |
|
: m_vm(parent) |
1945 |
|
{ |
1946 |
|
} |
1947 |
|
|
1948 |
|
VMFnResult* InstrumentScriptVMFunction_abort::exec(VMFnArgs* args) { |
1949 |
|
const script_callback_id_t id = args->arg(0)->asInt()->evalInt(); |
1950 |
|
if (!id) { |
1951 |
|
wrnMsg("abort(): callback ID for argument 1 may not be zero"); |
1952 |
|
return successResult(); |
1953 |
|
} |
1954 |
|
|
1955 |
|
AbstractEngineChannel* pEngineChannel = |
1956 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
1957 |
|
|
1958 |
|
RTList<ScriptEvent>::Iterator itCallback = pEngineChannel->ScriptCallbackByID(id); |
1959 |
|
if (!itCallback) return successResult(); // ignore if callback is i.e. not alive anymore |
1960 |
|
|
1961 |
|
itCallback->execCtx->signalAbort(); |
1962 |
|
|
1963 |
|
return successResult(); |
1964 |
|
} |
1965 |
|
|
1966 |
|
// fork() function |
1967 |
|
|
1968 |
|
InstrumentScriptVMFunction_fork::InstrumentScriptVMFunction_fork(InstrumentScriptVM* parent) |
1969 |
|
: m_vm(parent) |
1970 |
|
{ |
1971 |
|
} |
1972 |
|
|
1973 |
|
VMFnResult* InstrumentScriptVMFunction_fork::exec(VMFnArgs* args) { |
1974 |
|
// check if this is actually the parent going to fork, or rather one of |
1975 |
|
// the children which is already forked |
1976 |
|
if (m_vm->m_event->forkIndex != 0) { // this is the entry point for a child ... |
1977 |
|
int forkResult = m_vm->m_event->forkIndex; |
1978 |
|
// reset so that this child may i.e. also call fork() later on |
1979 |
|
m_vm->m_event->forkIndex = 0; |
1980 |
|
return successResult(forkResult); |
1981 |
|
} |
1982 |
|
|
1983 |
|
// if we are here, then this is the parent, so we must fork this parent |
1984 |
|
|
1985 |
|
const int n = |
1986 |
|
(args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : 1; |
1987 |
|
const bool bAutoAbort = |
1988 |
|
(args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : true; |
1989 |
|
|
1990 |
|
if (m_vm->m_event->countChildHandlers() + n > MAX_FORK_PER_SCRIPT_HANDLER) { |
1991 |
|
wrnMsg("fork(): requested amount would exceed allowed limit per event handler"); |
1992 |
|
return successResult(-1); |
1993 |
|
} |
1994 |
|
|
1995 |
|
AbstractEngineChannel* pEngineChannel = |
1996 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
1997 |
|
|
1998 |
|
if (!pEngineChannel->hasFreeScriptCallbacks(n)) { |
1999 |
|
wrnMsg("fork(): global limit of event handlers exceeded"); |
2000 |
|
return successResult(-1); |
2001 |
|
} |
2002 |
|
|
2003 |
|
for (int iChild = 0; iChild < n; ++iChild) { |
2004 |
|
RTList<ScriptEvent>::Iterator itChild = |
2005 |
|
pEngineChannel->forkScriptCallback(m_vm->m_event, bAutoAbort); |
2006 |
|
if (!itChild) { // should never happen, otherwise its a bug ... |
2007 |
|
errMsg("fork(): internal error while allocating child"); |
2008 |
|
return errorResult(-1); // terminate script |
2009 |
|
} |
2010 |
|
// since both parent, as well all child script execution instances |
2011 |
|
// all land in this exect() method, the following is (more or less) |
2012 |
|
// the only feature that lets us distinguish the parent and |
2013 |
|
// respective children from each other in this exect() method |
2014 |
|
itChild->forkIndex = iChild + 1; |
2015 |
|
} |
2016 |
|
|
2017 |
|
return successResult(0); |
2018 |
|
} |
2019 |
|
|
2020 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |