Exemplo n.º 1
0
static PyObject*
py_reactor_del(PyObject* self, PyObject* args)
{
    int n;
    if (!PyArg_ParseTuple(args, "i:reactor_del", &n)) {
        return NULL;
    }
    int iok = reactor_del(n);
    if (iok < 0) {
        return reportError(iok);
    }
    return Py_BuildValue("i",0);
}
Exemplo n.º 2
0
Arquivo: reactor.c Projeto: elly/elib
int reactor_run(struct reactor *r) {
	struct epoll_event evts[16];
	int n;
	int i;
	struct socket *s;

	n = epoll_wait(r->epfd, evts, sizeof(evts) / sizeof(evts[0]), -1);
	if (n < 0)
		return n;
	for (i = 0; i < n; i++) {
		s = evts[i].data.ptr;
		if ((evts[i].events & EPOLLIN) && s->read)
			s->read(s);
		if ((evts[i].events & EPOLLOUT) && s->write)
			s->write(s);
		if (evts[i].events & (EPOLLRDHUP | EPOLLERR | EPOLLHUP)) {
			if (s->close)
				s->close(s);
			reactor_del(r, s);
		}
	}
	return 0;
}
void reactormethods(int nlhs, mxArray* plhs[],
                    int nrhs, const mxArray* prhs[])
{
    int iok = 0, n;
    int job = getInt(prhs[1]);
    int i = getInt(prhs[2]);
    double r = Undef;
    double v = Undef;
    if (nrhs > 3) {
        v = getDouble(prhs[3]);
    }

    // constructor
    if (job == 0) {
        n = reactor_new(i);
        plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
        double* h = mxGetPr(plhs[0]);
        *h = double(n);
        if (n < 0) {
            reportError();
        }
        return;
    }

    // options that do not return a value
    if (job < 20) {
        switch (job) {
        case 1:
            iok = reactor_del(i);
            break;
        case 2:
            iok = reactor_copy(i);
            break;
        case 4:
            iok = reactor_setInitialVolume(i, v);
            break;
        case 6:
            iok = reactor_setThermoMgr(i, int(v));
            break;
        case 7:
            iok = reactor_setKineticsMgr(i, int(v));
            break;
        case 8:
            iok = reactor_setChemistry(i, bool(v));
            break;
        case 9:
            iok = reactor_setEnergy(i, int(v));
            break;
        case 10:
            iok = flowReactor_setMassFlowRate(i, v);
            break;
        default:
            mexErrMsgTxt("unknown job parameter");
        }
        plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
        double* h = mxGetPr(plhs[0]);
        *h = double(iok);
        if (iok < 0) {
            reportError();
        }
        return;
    } else if (job < 40) {
        // options that return a value of type 'double'
        switch (job) {
        case 23:
            r = reactor_mass(i);
            break;
        case 24:
            r = reactor_volume(i);
            break;
        case 25:
            r = reactor_density(i);
            break;
        case 26:
            r = reactor_temperature(i);
            break;
        case 27:
            r = reactor_enthalpy_mass(i);
            break;
        case 28:
            r = reactor_intEnergy_mass(i);
            break;
        case 29:
            r = reactor_pressure(i);
            break;
        case 30:
            r = reactor_massFraction(i, int(v));
            break;
        default:
            mexErrMsgTxt("unknown job parameter");
        }
        plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
        double* h = mxGetPr(plhs[0]);
        *h = r;
        if (r == DERR) {
            reportError();
        }
        return;
    }
}