Example #1
0
static PyObject *pyAssertEvent(PyObject *self, PyObject *args) {
    void *handle;
    char *event;
    if (!PyArg_ParseTuple(args, "ls", &handle, &event)) {
        PyErr_SetString(RulesError, "pyAssertEvent Invalid argument");
        return NULL;
    }

    unsigned int result = assertEvent(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 assert event, error code: %d", result)) {
                PyErr_NoMemory();
            } else {
                PyErr_SetString(RulesError, message);
                free(message);
            }
        }
        return NULL;
    }
}
Example #2
0
static VALUE rbAssertEvent(VALUE self, VALUE handle, VALUE event) {
    Check_Type(handle, T_FIXNUM);
    Check_Type(event, T_STRING);

    unsigned int result = assertEvent((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 assert event, error code: %d", result);
        }
    }

    return Qnil;
}