aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2021-01-04 22:16:43 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2021-01-04 22:16:43 +0100
commit71dc2855de65455f6da91f3de9e8ef47120f0a17 (patch)
tree20ab89178797baf0843c06d080389727591c43f5
parentd8277ff504b29199c5c14026d825af11a86c1583 (diff)
downloadvm.lv2-71dc2855de65455f6da91f3de9e8ef47120f0a17.tar.xz
Squashed 'props.lv2/' changes from 95d12eb3..e142214b
e142214b use state:freePath, copy atom:Path files from tmpfs. git-subtree-dir: props.lv2 git-subtree-split: e142214bbd6f55721d3179a476afe8692dcad063
-rw-r--r--VERSION2
-rw-r--r--props.h99
2 files changed, 93 insertions, 8 deletions
diff --git a/VERSION b/VERSION
index c64f02b..a63a9fe 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.153
+0.1.159
diff --git a/props.h b/props.h
index 1d1cb64..0ea0396 100644
--- a/props.h
+++ b/props.h
@@ -899,11 +899,58 @@ props_unmap(props_t *props, LV2_URID property)
return NULL;
}
+static inline int
+_copy_file(const char *to, const char *from)
+{
+ FILE *dst = NULL;
+ FILE *src = NULL;
+ int ch;
+
+ dst = fopen(to, "wb");
+ if(!dst)
+ {
+ return 1;
+ }
+
+ src = fopen(from, "rb");
+ if(!src)
+ {
+ fclose(dst);
+
+ return 1;
+ }
+
+ while( (ch = fgetc(src)) != EOF)
+ {
+ fputc(ch, dst);
+ }
+
+ fclose(dst);
+ fclose(src);
+
+ return 0;
+}
+
+static inline void
+_free_path(const LV2_State_Free_Path *free_path, char *path)
+{
+ if(free_path && free_path->free_path)
+ {
+ free_path->free_path(free_path->handle, path);
+ }
+ else
+ {
+ free(path);
+ }
+}
+
static inline LV2_State_Status
props_save(props_t *props, LV2_State_Store_Function store,
LV2_State_Handle state, uint32_t flags, const LV2_Feature *const *features)
{
const LV2_State_Map_Path *map_path = NULL;
+ const LV2_State_Make_Path *make_path = NULL;
+ const LV2_State_Free_Path *free_path = NULL;
// set POD flag if not already set by host
flags |= LV2_STATE_IS_POD;
@@ -913,7 +960,14 @@ props_save(props_t *props, LV2_State_Store_Function store,
if(!strcmp(features[i]->URI, LV2_STATE__mapPath))
{
map_path = features[i]->data;
- break;
+ }
+ else if(!strcmp(features[i]->URI, LV2_STATE__makePath))
+ {
+ make_path = features[i]->data;
+ }
+ else if(!strcmp(features[i]->URI, LV2_STATE__freePath))
+ {
+ free_path = features[i]->data;
}
}
@@ -935,18 +989,41 @@ props_save(props_t *props, LV2_State_Store_Function store,
_props_impl_unlock(impl, PROP_STATE_NONE);
- if( map_path && (impl->type == props->urid.atom_path) )
+ if( map_path && map_path->abstract_path
+ && (impl->type == props->urid.atom_path) )
{
- const char *path = strstr(body, "file://")
+ const char *path = strstr(body, "file://") == body
? (char *)body + 7 // skip "file://"
: (char *)body;
- char *abstract = map_path->abstract_path(map_path->handle, path);
+
+ char *abstract = NULL;
+
+ if( make_path && make_path->path
+ && (strstr(path, "/tmp") == path) )
+ {
+ char *absolute = make_path->path(make_path->handle, basename(path));
+
+ if(absolute)
+ {
+ if(_copy_file(absolute, path) == 0)
+ {
+ abstract = map_path->abstract_path(map_path->handle, absolute);
+ }
+
+ _free_path(free_path, absolute);
+ }
+ }
+ else
+ {
+ abstract = map_path->abstract_path(map_path->handle, path);
+ }
+
if(abstract)
{
const uint32_t sz = strlen(abstract) + 1;
store(state, impl->property, abstract, sz, impl->type, flags);
- free(abstract);
+ _free_path(free_path, abstract);
}
}
else // !Path
@@ -967,11 +1044,18 @@ props_restore(props_t *props, LV2_State_Retrieve_Function retrieve,
const LV2_Feature *const *features)
{
const LV2_State_Map_Path *map_path = NULL;
+ const LV2_State_Free_Path *free_path = NULL;
for(unsigned i = 0; features[i]; i++)
{
if(!strcmp(features[i]->URI, LV2_STATE__mapPath))
+ {
map_path = features[i]->data;
+ }
+ if(!strcmp(features[i]->URI, LV2_STATE__freePath))
+ {
+ free_path = features[i]->data;
+ }
}
for(unsigned i = 0; i < props->nimpls; i++)
@@ -990,7 +1074,8 @@ props_restore(props_t *props, LV2_State_Retrieve_Function retrieve,
&& (type == impl->type)
&& ( (impl->def->max_size == 0) || (size <= impl->def->max_size) ) )
{
- if(map_path && (type == props->urid.atom_path) )
+ if( map_path && map_path->absolute_path
+ && (type == props->urid.atom_path) )
{
char *absolute = map_path->absolute_path(map_path->handle, body);
if(absolute)
@@ -1004,7 +1089,7 @@ props_restore(props_t *props, LV2_State_Retrieve_Function retrieve,
_props_impl_unlock(impl, PROP_STATE_RESTORE);
- free(absolute);
+ _free_path(free_path, absolute);
}
}
else // !Path