Example #1
0
HPEXPORT int HPCALL hpcables_cable_close(cable_handle * handle) {
    int res;
    if (handle != NULL) {
        do {
            int (*close) (cable_handle *);

            DO_BASIC_HANDLE_CHECKS()

            close = handle->fncts->close;
            if (close != NULL) {
                handle->busy = 1;
                res = (*close)(handle);
                if (res == ERR_SUCCESS) {
                    handle->open = 0;
                    hpcables_info("%s: close succeeded", __FUNCTION__);
                }
                else {
                    hpcables_error("%s: close failed", __FUNCTION__);
                }
                handle->busy = 0;
            }
            else {
                res = ERR_CABLE_INVALID_FNCTS;
                hpcables_error("%s: fncts->close is NULL", __FUNCTION__);
            }
        } while (0);
    }
    else {
        res = ERR_INVALID_HANDLE;
        hpcables_error("%s: handle is NULL", __FUNCTION__);
    }
    return res;
}
Example #2
0
HPEXPORT int HPCALL hpcables_exit(void) {
    int res;
    hid_exit();
    res = ERR_SUCCESS;
    hpcables_info(_("%s: exit succeeded"), __FUNCTION__);
    return res;
}
Example #3
0
HPEXPORT int HPCALL hpcables_options_set_read_timeout(cable_handle * handle, int read_timeout) {
    int res;
    if (handle != NULL) {
        do {
            int (*set_read_timeout) (cable_handle *, int);

            DO_BASIC_HANDLE_CHECKS2()

            set_read_timeout = handle->fncts->set_read_timeout;
            if (set_read_timeout != NULL) {
                handle->busy = 1;
                res = (*set_read_timeout)(handle, read_timeout);
                if (res == ERR_SUCCESS) {
                    hpcables_info("%s: set_read_timeout succeeded", __FUNCTION__);
                }
                else {
                    hpcables_error("%s: set_read_timeout failed", __FUNCTION__);
                }
                handle->busy = 0;
            }
            else {
                res = ERR_CABLE_INVALID_FNCTS;
                hpcables_error("%s: fncts->set_read_timeout is NULL", __FUNCTION__);
            }
        } while (0);
    }
    else {
        res = ERR_INVALID_HANDLE;
        hpcables_error("%s: handle is NULL", __FUNCTION__);
    }
    return res;
}
Example #4
0
HPEXPORT int HPCALL hpcables_handle_display(cable_handle * handle) {
    int res;
    if (handle != NULL) {
        hpcables_info("Link cable handle details:");
        hpcables_info("\tmodel: %s", hpcables_model_to_string(handle->model));
        hpcables_info("\tread_timeout: %d", handle->read_timeout);
        hpcables_info("\topen: %d", handle->open);
        hpcables_info("\tbusy: %d", handle->busy);
        res = ERR_SUCCESS;
    }
    else {
        res = ERR_INVALID_HANDLE;
        hpcables_error("%s: handle is NULL", __FUNCTION__);
    }

    return res;
}
Example #5
0
HPEXPORT int HPCALL hpcables_init(void (*log_callback)(const char *format, va_list args)) {
    int res;

    // TODO: when (if) libhpcables is split from libhpfiles, copy and adjust locale setting code from hpcalcs.c.

    hpcables_log_set_callback(log_callback);
    hpcables_info(_("hpcables library version %s compiled on %s"), hpcables_version_get(), __DATE__ " " __TIME__);

    res = hid_init();
    if (res == 0) {
        res = ERR_SUCCESS;
        hpcables_info(_("%s: init succeeded"), __FUNCTION__);
    }
    else {
        res = ERR_LIBRARY_INIT;
        hpcables_error(_("%s: init failed"), __FUNCTION__);
    }

    return res;
}
Example #6
0
HPEXPORT int HPCALL hpcables_handle_del(cable_handle * handle) {
    int res;
    if (handle != NULL) {
        free(handle->handle);
        handle->handle = NULL;

        free(handle);
        handle = NULL;
        res = ERR_SUCCESS;
        hpcables_info("%s: handle deletion succeeded", __FUNCTION__);
    }
    else {
        res = ERR_INVALID_HANDLE;
        hpcables_error("%s: handle is NULL", __FUNCTION__);
    }

    return res;
}
Example #7
0
HPEXPORT cable_handle * HPCALL hpcables_handle_new(cable_model model) {
    cable_handle * handle = NULL;
    if (model < CABLE_MAX) {
        handle = (cable_handle *)calloc(1, sizeof(*handle));

        if (handle != NULL) {
            handle->model = model;
            handle->handle = NULL;
            handle->fncts = hpcables_all_cables[model];
            hpcables_info("%s: handle allocation succeeded", __FUNCTION__);
        }
        else {
            hpcables_error("%s: handle allocation failed", __FUNCTION__);
        }
    }
    else {
        hpcables_error("%s: invalid model", __FUNCTION__);
    }

    return handle;
}
Example #8
0
HPEXPORT int HPCALL hpcables_cable_open(cable_handle * handle) {
    int res;
    if (handle != NULL) {
        do {
            int (*open) (cable_handle *);

            if (handle->open) {
                res = ERR_CABLE_OPEN;
                hpcables_error("%s: cable already open", __FUNCTION__);
                break;
            }
            DO_BASIC_HANDLE_CHECKS2()

            open = handle->fncts->open;
            if (open != NULL) {
                handle->busy = 1;
                res = (*open)(handle);
                if (res == ERR_SUCCESS) {
                    handle->open = 1;
                    hpcables_info("%s: open succeeded", __FUNCTION__);
                }
                else {
                    hpcables_error("%s: open failed", __FUNCTION__);
                }
                handle->busy = 0;
            }
            else {
                res = ERR_CABLE_INVALID_FNCTS;
                hpcables_error("%s: fncts->open is NULL", __FUNCTION__);
            }
        } while (0);
    }
    else {
        res = ERR_INVALID_HANDLE;
        hpcables_error("%s: handle is NULL", __FUNCTION__);
    }
    return res;
}
Example #9
0
File: error.c Project: AHelper/hplp
HPEXPORT int HPCALL hplibs_error_get(int number, char **message) {
    int err = number;
    char *s = NULL;

    if (message != NULL) {
        // Skip ERR_SUCCESS.
        if (number > ERR_HPLIBS_GENERIC_FIRST && number <= ERR_HPLIBS_GENERIC_LAST) {
            switch (number) {
                case ERR_MALLOC:
                    *message = strdup(_("Failed to allocate memory"));
                    break;
                case ERR_INVALID_HANDLE:
                    *message = strdup(_("Invalid handle pointer"));
                    break;
                case ERR_INVALID_PARAMETER:
                    *message = strdup(_("Invalid function parameter"));
                    break;
                case ERR_INVALID_MODEL:
                    *message = strdup(_("Invalid model"));
                    break;
                case ERR_LIBRARY_INIT:
                    *message = strdup(_("Problem initializing the library"));
                    break;
                default:
                    *message = strdup(_("<Unknown error code>"));
                    break;
            }
            return 0;
        }
        else {
            // Retrieve the error message.
            err = hpfiles_error_get(err, &s);
            if (err) {
                free(s);
                err = hpcables_error_get(err, &s);
                if (err) {
                    free(s);
                    err = hpcalcs_error_get(err, &s);
                    if (err) {
                        free(s);
                        err = hpopers_error_get(err, &s);
                        if (err) {
                            // next level: not a libhp* error.
                            free(s);
                            s = NULL;
                        }
                        else {
                            hpopers_info("%s\n", s);
                        }
                    }
                    else {
                        hpcalcs_info("%s\n", s);
                    }
                }
                else {
                    hpcables_info("%s\n", s);
                }
            }
            else {
                hpfiles_info("%s\n", s);
            }

            *message = s;
        }
    }
    else {
        hpcalcs_error("%s: message is NULL", __FUNCTION__);
        return number;
    }

    return number;
}