コード例 #1
0
ファイル: rules.c プロジェクト: sethdford/rules
static PyObject *pyRetractEvent(PyObject *self, PyObject *args) {
    void *handle;
    char *event;
    if (!PyArg_ParseTuple(args, "ls", &handle, &event)) {
        PyErr_SetString(RulesError, "pyRetractEvent Invalid argument");
        return NULL;
    }

    unsigned int result = retractEvent(handle, event);
    if (result == RULES_OK) {
        return Py_BuildValue("i", 1);    
    } else if (result == ERR_EVENT_NOT_HANDLED) {
        return Py_BuildValue("i", 0);    
    } else {
        if (result == ERR_OUT_OF_MEMORY) {
            PyErr_NoMemory();
        } else { 
            char *message;
            if (asprintf(&message, "Could not retract event, error code: %d", result)) {
                PyErr_NoMemory();
            } else {
                PyErr_SetString(RulesError, message);
                free(message);
            }
        }
        return NULL;
    }
}
コード例 #2
0
ファイル: rules.c プロジェクト: sureddy/rules
static VALUE rbRetractEvent(VALUE self, VALUE handle, VALUE event) {
    Check_Type(handle, T_FIXNUM);
    Check_Type(event, T_STRING);

    unsigned int result = retractEvent((void *)FIX2LONG(handle), RSTRING_PTR(event));
    if (result == RULES_OK) {
        return INT2FIX(1);    
    } else if (result == ERR_EVENT_NOT_HANDLED) {
        return INT2FIX(0);    
    } else {
        if (result == ERR_OUT_OF_MEMORY) {
            rb_raise(rb_eNoMemError, "Out of memory");
        } else { 
            rb_raise(rb_eException, "Could not retract event, error code: %d", result);
        }
    }

    return Qnil;
}