~vcs-imports/lilv/master

« back to all changes in this revision

Viewing changes to src/state.c

  • Committer: David Robillard
  • Date: 2015-10-29 05:03:03 UTC
  • Revision ID: git-v1:07dadda1f5d869164ba177fe30121f0b87ff49cd
Fix long lines

git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5800 a436a847-0d15-0410-975c-d299462d15a1

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        Property*  props;       ///< State properties
63
63
        PortValue* values;      ///< Port values
64
64
        uint32_t   atom_Path;   ///< atom:Path URID
65
 
        uint32_t   num_props;   ///< Number of state properties
66
 
        uint32_t   num_values;  ///< Number of port values
 
65
        uint32_t   n_props;     ///< Number of state properties
 
66
        uint32_t   n_values;    ///< Number of port values
67
67
};
68
68
 
69
69
static int
108
108
{
109
109
        if (value) {
110
110
                state->values = (PortValue*)realloc(
111
 
                        state->values, (++state->num_values) * sizeof(PortValue));
112
 
                PortValue* pv = &state->values[state->num_values - 1];
 
111
                        state->values, (++state->n_values) * sizeof(PortValue));
 
112
                PortValue* pv = &state->values[state->n_values - 1];
113
113
                pv->symbol = lilv_strdup(port_symbol);
114
114
                pv->value  = malloc(size);
115
115
                pv->size   = size;
141
141
{
142
142
        LilvState* const state = (LilvState*)handle;
143
143
        state->props = (Property*)realloc(
144
 
                state->props, (++state->num_props) * sizeof(Property));
145
 
        Property* const prop = &state->props[state->num_props - 1];
 
144
                state->props, (++state->n_props) * sizeof(Property));
 
145
        Property* const prop = &state->props[state->n_props - 1];
146
146
 
147
147
        if ((flags & LV2_STATE_IS_POD) || type == state->atom_Path) {
148
148
                prop->value = malloc(size);
170
170
        const LilvState* const state      = (LilvState*)handle;
171
171
        const Property         search_key = { NULL, 0, key, 0, 0 };
172
172
        const Property* const  prop       = (Property*)bsearch(
173
 
                &search_key, state->props, state->num_props,
 
173
                &search_key, state->props, state->n_props,
174
174
                sizeof(Property), property_cmp);
175
175
 
176
176
        if (prop) {
390
390
                        LILV_ERRORF("Error saving plugin state: %s\n", state_strerror(st));
391
391
                        free(state->props);
392
392
                        state->props     = NULL;
393
 
                        state->num_props = 0;
 
393
                        state->n_props = 0;
394
394
                } else {
395
 
                        qsort(state->props, state->num_props, sizeof(Property), property_cmp);
 
395
                        qsort(state->props, state->n_props, sizeof(Property), property_cmp);
396
396
                }
397
397
        }
398
398
 
399
 
        qsort(state->values, state->num_values, sizeof(PortValue), value_cmp);
 
399
        qsort(state->values, state->n_values, sizeof(PortValue), value_cmp);
400
400
 
401
401
        free(sfeatures);
402
402
        return state;
407
407
                            LilvSetPortValueFunc set_value,
408
408
                            void*                user_data)
409
409
{
410
 
        for (uint32_t i = 0; i < state->num_values; ++i) {
 
410
        for (uint32_t i = 0; i < state->n_values; ++i) {
411
411
                const PortValue* val = &state->values[i];
412
412
                set_value(val->symbol, user_data, val->value, val->size, val->type);
413
413
        }
430
430
                (LilvState*)state, abstract_path, absolute_path };
431
431
        LV2_Feature map_feature = { LV2_STATE__mapPath, &map_path };
432
432
 
433
 
        const LV2_Feature** sfeatures = add_features(features, &map_feature, NULL);
434
 
 
435
 
        const LV2_Descriptor*      desc  = instance ? instance->lv2_descriptor : NULL;
436
 
        const LV2_State_Interface* iface = (desc && desc->extension_data)
437
 
                ? (const LV2_State_Interface*)desc->extension_data(LV2_STATE__interface)
438
 
                : NULL;
439
 
 
440
 
        if (iface) {
441
 
                iface->restore(instance->lv2_handle, retrieve_callback,
442
 
                               (LV2_State_Handle)state, flags, sfeatures);
 
433
        if (instance) {
 
434
                const LV2_Descriptor* desc = instance->lv2_descriptor;
 
435
                if (desc->extension_data) {
 
436
                        const LV2_State_Interface* iface = (const LV2_State_Interface*)
 
437
                                desc->extension_data(LV2_STATE__interface);
 
438
 
 
439
                        const LV2_Feature** sfeatures = add_features(
 
440
                                features, &map_feature, NULL);
 
441
 
 
442
                        iface->restore(instance->lv2_handle, retrieve_callback,
 
443
                                       (LV2_State_Handle)state, flags, sfeatures);
 
444
 
 
445
                        free(sfeatures);
 
446
                }
443
447
        }
444
448
 
445
 
        free(sfeatures);
446
449
 
447
450
        if (set_value) {
448
451
                lilv_state_emit_port_values(state, set_value, user_data);
548
551
        if (state_node) {
549
552
                SordIter* props = sord_search(model, state_node, 0, 0, 0);
550
553
                FOREACH_MATCH(props) {
551
 
                        const SordNode* p = sord_iter_get_node(props, SORD_PREDICATE);
552
 
                        const SordNode* o = sord_iter_get_node(props, SORD_OBJECT);
 
554
                        const SordNode* p   = sord_iter_get_node(props, SORD_PREDICATE);
 
555
                        const SordNode* o   = sord_iter_get_node(props, SORD_OBJECT);
 
556
                        const char*     key = (const char*)sord_node_get_string(p);
553
557
 
554
558
                        chunk.len = 0;
555
559
                        lv2_atom_forge_set_sink(
560
564
                        uint32_t        flags = LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE;
561
565
                        Property        prop  = { NULL, 0, 0, 0, flags };
562
566
 
563
 
                        prop.key   = map->map(map->handle, (const char*)sord_node_get_string(p));
 
567
                        prop.key   = map->map(map->handle, pred);
564
568
                        prop.type  = atom->type;
565
569
                        prop.size  = atom->size;
566
570
                        prop.value = malloc(atom->size);
571
575
 
572
576
                        if (prop.value) {
573
577
                                state->props = (Property*)realloc(
574
 
                                        state->props, (++state->num_props) * sizeof(Property));
575
 
                                state->props[state->num_props - 1] = prop;
 
578
                                        state->props, (++state->n_props) * sizeof(Property));
 
579
                                state->props[state->n_props - 1] = prop;
576
580
                        }
577
581
                }
578
582
                sord_iter_free(props);
583
587
        free((void*)chunk.buf);
584
588
        sratom_free(sratom);
585
589
 
586
 
        qsort(state->props, state->num_props, sizeof(Property), property_cmp);
587
 
        qsort(state->values, state->num_values, sizeof(PortValue), value_cmp);
 
590
        qsort(state->props, state->n_props, sizeof(Property), property_cmp);
 
591
        qsort(state->values, state->n_values, sizeof(PortValue), value_cmp);
588
592
 
589
593
        return state;
590
594
}
700
704
 
701
705
        SerdWriter* writer = serd_writer_new(
702
706
                SERD_TURTLE,
703
 
                (SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED),
 
707
                (SerdStyle)(SERD_STYLE_RESOLVED |
 
708
                            SERD_STYLE_ABBREVIATED|
 
709
                            SERD_STYLE_CURIED),
704
710
                env,
705
711
                &base_uri,
706
712
                sink,
906
912
        sratom_set_pretty_numbers(sratom, true);
907
913
 
908
914
        // Write port values
909
 
        for (uint32_t i = 0; i < state->num_values; ++i) {
 
915
        for (uint32_t i = 0; i < state->n_values; ++i) {
910
916
                PortValue* const value = &state->values[i];
911
917
 
912
918
                const SerdNode port = serd_node_from_string(
937
943
        // Write properties
938
944
        const SerdNode state_node = serd_node_from_string(SERD_BLANK,
939
945
                                                          USTR("2state"));
940
 
        if (state->num_props > 0) {
 
946
        if (state->n_props > 0) {
941
947
                p = serd_node_from_string(SERD_URI, USTR(LV2_STATE__state));
942
948
                serd_writer_write_statement(writer, SERD_ANON_O_BEGIN, NULL,
943
949
                                            &subject, &p, &state_node, NULL, NULL);
944
950
        }
945
 
        for (uint32_t i = 0; i < state->num_props; ++i) {
 
951
        for (uint32_t i = 0; i < state->n_props; ++i) {
946
952
                Property*   prop = &state->props[i];
947
953
                const char* key  = unmap->unmap(unmap->handle, prop->key);
948
954
 
958
964
                                     &state_node, &p, prop->type, prop->size, prop->value);
959
965
                }
960
966
        }
961
 
        if (state->num_props > 0) {
 
967
        if (state->n_props > 0) {
962
968
                serd_writer_end_anon(writer, &state_node);
963
969
        }
964
970
 
1116
1122
                model, state->uri->node, world->uris.rdfs_seeAlso, NULL, NULL);
1117
1123
        if (file) {
1118
1124
                // Remove state file
1119
 
                char* file_path = lilv_file_uri_parse(
 
1125
                char* path = lilv_file_uri_parse(
1120
1126
                        (const char*)sord_node_get_string(file), NULL);
1121
 
                if (unlink(file_path)) {
1122
 
                        LILV_ERRORF("Failed to remove %s (%s)\n", file_path, strerror(errno));
 
1127
                if (unlink(path)) {
 
1128
                        LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno));
1123
1129
                }
1124
 
                lilv_free(file_path);
 
1130
                lilv_free(path);
1125
1131
        }
1126
1132
 
1127
1133
        // Remove any existing manifest entries for this state
1162
1168
lilv_state_free(LilvState* state)
1163
1169
{
1164
1170
        if (state) {
1165
 
                for (uint32_t i = 0; i < state->num_props; ++i) {
 
1171
                for (uint32_t i = 0; i < state->n_props; ++i) {
1166
1172
                        free(state->props[i].value);
1167
1173
                }
1168
 
                for (uint32_t i = 0; i < state->num_values; ++i) {
 
1174
                for (uint32_t i = 0; i < state->n_values; ++i) {
1169
1175
                        free(state->values[i].value);
1170
1176
                        free(state->values[i].symbol);
1171
1177
                }
1191
1197
            || (a->label && !b->label)
1192
1198
            || (b->label && !a->label)
1193
1199
            || (a->label && b->label && strcmp(a->label, b->label))
1194
 
            || a->num_props != b->num_props
1195
 
            || a->num_values != b->num_values) {
 
1200
            || a->n_props != b->n_props
 
1201
            || a->n_values != b->n_values) {
1196
1202
                return false;
1197
1203
        }
1198
1204
 
1199
 
        for (uint32_t i = 0; i < a->num_values; ++i) {
 
1205
        for (uint32_t i = 0; i < a->n_values; ++i) {
1200
1206
                PortValue* const av = &a->values[i];
1201
1207
                PortValue* const bv = &b->values[i];
1202
1208
                if (av->size != bv->size || av->type != bv->type
1206
1212
                }
1207
1213
        }
1208
1214
 
1209
 
        for (uint32_t i = 0; i < a->num_props; ++i) {
 
1215
        for (uint32_t i = 0; i < a->n_props; ++i) {
1210
1216
                Property* const ap = &a->props[i];
1211
1217
                Property* const bp = &b->props[i];
1212
1218
                if (ap->key != bp->key
1230
1236
LILV_API unsigned
1231
1237
lilv_state_get_num_properties(const LilvState* state)
1232
1238
{
1233
 
        return state->num_props;
 
1239
        return state->n_props;
1234
1240
}
1235
1241
 
1236
1242
LILV_API const LilvNode*