Exemplo n.º 1
0
int flom_handle_set_resource_name(flom_handle_t *handle, const char *value)
{
    FLOM_TRACE(("flom_handle_set_resource_name: "
                "old value='%s', new value='%s'\n",
                STRORNULL(flom_config_get_resource_name(handle->config)),
                STRORNULL(value)));
    return flom_config_set_resource_name(handle->config, (const gchar *)value);
}
Exemplo n.º 2
0
int flom_handle_set_resource_name(flom_handle_t *handle, const char *value)
{
    FLOM_TRACE(("flom_handle_set_resource_name: "
                "old value='%s', new value='%s'\n",
                STRORNULL(flom_config_get_resource_name(handle->config)),
                STRORNULL(value)));
    switch (handle->state) {
        case FLOM_HANDLE_STATE_INIT:
        case FLOM_HANDLE_STATE_DISCONNECTED:
        case FLOM_HANDLE_STATE_CONNECTED:
            flom_config_set_resource_name(handle->config,
                                          (const gchar *)value);
            break;
        default:
            FLOM_TRACE(("flom_handle_set_resource_name: state %d " \
                        "is not compatible with set operation\n",
                        handle->state));
            return FLOM_RC_API_IMMUTABLE_HANDLE;
    } /* switch (handle->state) */
    return FLOM_RC_OK;
}
Exemplo n.º 3
0
const char *flom_handle_get_resource_name(const flom_handle_t *handle)
{
    FLOM_TRACE(("flom_handle_get_resource_name: value='%s'\n",
                STRORNULL(flom_config_get_resource_name(handle->config))));
    return (const char *)flom_config_get_resource_name(handle->config);
}
Exemplo n.º 4
0
/**
 * This is a private library function, not exposed in the interface, that's
 * used both by @ref flom_handle_unlock and by
 * @ref flom_handle_unlock_rollback .
 * See above functions for more details.
 * @param handle (Input/Output): a valid object handle
 * @param rollback: a boolean value, TRUE means the state of the transactional
 *        resource must be backed out
 * @return a reason code
 */
int flom_handle_unlock_internal(flom_handle_t *handle, int rollback)
{
    enum Exception { NULL_OBJECT
                     , API_INVALID_SEQUENCE
                     , OBJ_CORRUPTED
                     , CLIENT_UNLOCK_ERROR
                     , CLIENT_DISCONNECT_ERROR
                     , RESOURCE_IS_NOT_TRANSACTIONAL
                     , NONE } excp;
    int ret_cod = FLOM_RC_INTERNAL_ERROR;
    
    /* check flom library is initialized */
    if (FLOM_RC_OK != (ret_cod = flom_init_check()))
        return ret_cod;
    
    FLOM_TRACE(("flom_handle_unlock_internal: rollback=%d\n", rollback));
    TRY {
        flom_conn_t *conn = NULL;
        int ignored_rollback = FALSE;
        
        /* check handle is not NULL */
        if (NULL == handle)
            THROW(NULL_OBJECT);
        /* cast and retrieve conn fron the proxy object */
        conn = (flom_conn_t *)handle->conn;
        /* check handle state */
        if (FLOM_HANDLE_STATE_LOCKED != handle->state &&
            FLOM_HANDLE_STATE_CONNECTED != handle->state) {
            FLOM_TRACE(("flom_handle_unlock_internal: handle->state=%d\n",
                        handle->state));
            THROW(API_INVALID_SEQUENCE);
        }
        /* check the connection data pointer is not NULL (we can't be sure
           it's a valid pointer) */
        if (NULL == handle->conn)
            THROW(OBJ_CORRUPTED);
        /* check transactionality */
        if (rollback) {
            int transactional = flom_rsrc_get_transactional(
                flom_config_get_resource_name(handle->config));
            if (!transactional) {
                FLOM_TRACE(("flom_handle_unlock_internal: asked rollback for "
                            "a non transactional resource ('%s'), "
                            "ignoring...\n",
                            STRORNULL(flom_config_get_resource_name(
                                          handle->config))));
                ignored_rollback = TRUE;
                /* overwrite rollback parameter */
                rollback = FALSE;
            }
        }
        if (FLOM_HANDLE_STATE_LOCKED == handle->state) {
            /* lock release */
            if (FLOM_RC_OK != (ret_cod = flom_client_unlock(
                                   handle->config, conn, rollback)))
                THROW(CLIENT_UNLOCK_ERROR);
            /* state update */
            handle->state = FLOM_HANDLE_STATE_CONNECTED;
        } else {
            FLOM_TRACE(("flom_handle_unlock_internal: resource already "
                        "unlocked (%d), skipping...\n", handle->state));
        }
        /* gracefully disconnect from daemon */
        if (FLOM_RC_OK != (ret_cod = flom_client_disconnect(conn)))
            THROW(CLIENT_DISCONNECT_ERROR);
        /* free locked element name is allocated */
        g_free(handle->locked_element);
        handle->locked_element = NULL;
        /* state update */
        handle->state = FLOM_HANDLE_STATE_DISCONNECTED;

        if (ignored_rollback)
            THROW(RESOURCE_IS_NOT_TRANSACTIONAL);
        
        THROW(NONE);
    } CATCH {
        switch (excp) {
            case NULL_OBJECT:
                ret_cod = FLOM_RC_NULL_OBJECT;
                break;
            case API_INVALID_SEQUENCE:
                ret_cod = FLOM_RC_API_INVALID_SEQUENCE;
                break;
            case OBJ_CORRUPTED:
                ret_cod = FLOM_RC_OBJ_CORRUPTED;
                break;
            case CLIENT_UNLOCK_ERROR:
            case CLIENT_DISCONNECT_ERROR:
                break;
            case NONE:
                ret_cod = FLOM_RC_OK;
                break;
            case RESOURCE_IS_NOT_TRANSACTIONAL:
                ret_cod = FLOM_RC_RESOURCE_IS_NOT_TRANSACTIONAL;
                break;
            default:
                ret_cod = FLOM_RC_INTERNAL_ERROR;
        } /* switch (excp) */
    } /* TRY-CATCH */
    FLOM_TRACE(("flom_handle_unlock_internal/excp=%d/"
                "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
    return ret_cod;
}