/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/view.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-10-19 13:58:46 UTC
  • Revision ID: csa@suren.me-20151019135846-nz3f6iobifx06xvq
Support computed (property-based) registers

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include "view.h"
10
10
#include "error.h"
11
11
#include "value.h"
 
12
#include "property.h"
12
13
 
13
14
int pcilib_add_views_custom(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc, pcilib_view_context_t **refs) {
 
15
    int err;
 
16
 
14
17
    size_t i;
15
18
    void *ptr;
16
19
 
25
28
        }
26
29
    }
27
30
 
 
31
    if (!refs) {
 
32
        refs = (pcilib_view_context_t**)alloca(n * sizeof(pcilib_view_context_t*));
 
33
        if (!refs) return PCILIB_ERROR_MEMORY;
 
34
    }
 
35
 
28
36
    if ((ctx->num_views + n + 1) > ctx->alloc_views) {
29
37
        size_t size;
30
38
        pcilib_view_description_t **views;
48
56
 
49
57
        pcilib_view_t view = pcilib_find_view_by_name(ctx, v->name);
50
58
        if (view != PCILIB_VIEW_INVALID) {
 
59
            ctx->views[ctx->num_views + i] = NULL;
51
60
            pcilib_clean_views(ctx, ctx->num_views);
52
61
            pcilib_error("View %s is already defined in the model", v->name);
53
62
            return PCILIB_ERROR_EXIST;
55
64
 
56
65
        cur = (pcilib_view_description_t*)malloc(v->api->description_size);
57
66
        if (!cur) {
 
67
            ctx->views[ctx->num_views + i] = NULL;
58
68
            pcilib_clean_views(ctx, ctx->num_views);
59
69
            return PCILIB_ERROR_MEMORY;
60
70
        }
68
78
 
69
79
        if (!view_ctx) {
70
80
            free(cur);
 
81
            ctx->views[ctx->num_views + i] = NULL;
71
82
            pcilib_clean_views(ctx, ctx->num_views);
72
83
            return PCILIB_ERROR_FAILED;
73
84
        }
85
96
    }
86
97
 
87
98
    ctx->views[ctx->num_views + n] = NULL;
 
99
 
 
100
    err = pcilib_add_registers_from_properties(ctx, n, refs, ctx->views + ctx->num_views);
 
101
    if (err) {
 
102
        pcilib_clean_views(ctx, ctx->num_views);
 
103
        return err;
 
104
    }
 
105
 
88
106
    ctx->num_views += n;
89
107
 
90
108
    return 0;