Commit 64baedf8 authored by Hanspeter Portner's avatar Hanspeter Portner

manually check file modification state.

* manually check file modification state (simple-ui)
* properly check for errors in libuv calls (simple-ui)
* add dependent option for uv_fs_event support (simple-ui)
* improve logging
* work on mingw cross compilation toolchain recipes
parent db507a26
......@@ -21,7 +21,9 @@ endif()
set(CMAKE_C_FLAGS "-std=gnu11 -Wextra -Wno-unused-parameter -ffast-math -fvisibility=hidden ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-Wshadow -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes ${CMAKE_C_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-z,nodelete ${CMAKE_MODULE_LINKER_FLAGS}")
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-z,nodelete ${CMAKE_MODULE_LINKER_FLAGS}")
endif()
add_definitions("-D_GNU_SOURCE=1") # asprintf
set(MOONY_MAJOR_VERSION 0)
......@@ -40,8 +42,10 @@ include_directories(${LV2_INCLUDE_DIRS})
set(LIBS ${LIBS} ${LV2_LDFLAGS})
# options
include(CMakeDependentOption)
option(BUILD_COMMON_UI "Build common embeddable UI" ON)
option(BUILD_SIMPLE_UI "Build simple external UI" OFF)
cmake_dependent_option(USE_FS_EVENT "Use filesystem notify events" ON "BUILD_SIMPLE_UI" OFF)
if(BUILD_COMMON_UI)
pkg_search_module(ELM REQUIRED elementary>=1.8)
......@@ -81,6 +85,10 @@ else()
endif()
if(BUILD_SIMPLE_UI)
if(USE_FS_EVENT)
add_definitions("-DUSE_FS_EVENT=1")
endif()
pkg_search_module(UV REQUIRED libuv>=1.0)
include_directories(${UV_INCLUDE_DIRS})
set(LIBS_SIMPLE ${LIBS_SIMPLE} ${UV_LDFLAGS})
......
......@@ -16,3 +16,6 @@ set(CMAKE_FIND_ROOT_PATH "/usr/${TOOLCHAIN}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(LIBS_SIMPLE ${LIBS_SIMPLE} "/usr/i686-w64-mingw32/lib/libuv.a")
set(LIBS_SIMPLE ${LIBS_SIMPLE} "-static-libgcc -lws2_32 -lpsapi -liphlpapi -Wl,-Bstatic -lwinpthread -luserenv")
......@@ -90,7 +90,11 @@ _moony_message_send(UI *ui, LV2_URID otype, LV2_URID key,
// trigger update
ui->write_function(ui->controller, ui->control_port, lv2_atom_total_size(&obj->atom),
ui->uris.event_transfer, ui->buf);
if(ui->log)
lv2_log_note(&ui->logger, str && size ? "send code chunk" : "query code chunk");
}
else if(ui->log)
lv2_log_error(&ui->logger, "code chunk too long");
}
static char *
......
......@@ -13,13 +13,13 @@
# along the source as a COPYING file. If not, obtain it from
# http://www.perlfoundation.org/artistic_license_2_0.
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .
@prefix kx: <http://kxstudio.sf.net/ns/lv2ext/external-ui#> .
@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .
@prefix kx: <http://kxstudio.sf.net/ns/lv2ext/external-ui#> .
@prefix moony: <http://open-music-kontrollers.ch/lv2/moony#> .
@prefix moony: <http://open-music-kontrollers.ch/lv2/moony#> .
# to please sord_validate
ui:EoUI
......@@ -36,39 +36,39 @@ moony:c1xc1
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
moony:c2xc2
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
moony:c4xc4
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
# atom in, atom out
......@@ -76,39 +76,39 @@ moony:a1xa1
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
moony:a2xa2
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
moony:a4xa4
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
# control/atom in, control/atom out
......@@ -116,65 +116,65 @@ moony:c1a1xc1a1
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
moony:c2a1xc2a1
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
moony:c4a1xc4a1
a lv2:Plugin ;
lv2:minorVersion @MOONY_MINOR_VERSION@ ;
lv2:microVersion @MOONY_MICRO_VERSION@ ;
lv2:binary <moony@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
lv2:binary <moony@CMAKE_SHARED_MODULE_SUFFIX@> ;
@UI_UI_WRAP@ui:ui moony:ui1_common_ui ;
@KX_UI_WRAP@ui:ui moony:ui3_common_kx ;
@X11_UI_WRAP@ui:ui moony:ui5_common_x11 ;
@EO_UI_WRAP@ui:ui moony:ui6_common_eo ;
@UI_SIMPLE_WRAP@ui:ui moony:ui2_simple_ui ;
@KX_SIMPLE_WRAP@ui:ui moony:ui4_simple_kx ;
rdfs:seeAlso <moony.ttl> .
# Common UI
moony:ui1_common_ui
a ui:UI ;
ui:binary <moony_ui@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
ui:binary <moony_ui@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony.ttl> .
moony:ui3_common_kx
a kx:Widget ;
ui:binary <moony_ui@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
ui:binary <moony_ui@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony.ttl> .
moony:ui5_common_x11
a ui:X11UI ;
ui:binary <moony_ui@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
ui:binary <moony_ui@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony.ttl> .
moony:ui6_common_eo
a ui:EoUI ;
ui:binary <moony_ui@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
ui:binary <moony_ui@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony.ttl> .
# Simple UI
moony:ui2_simple_ui
a ui:UI ;
ui:binary <moony_simple@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
ui:binary <moony_simple@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony.ttl> .
moony:ui4_simple_kx
a kx:Widget ;
ui:binary <moony_simple@CMAKE_SHARED_LIBRARY_SUFFIX@> ;
ui:binary <moony_simple@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony.ttl> .
......@@ -316,24 +316,6 @@ moony_error(moony_t *moony)
lua_pop(L, 1);
}
// strdup fallback for windows
#if defined(_WIN32)
static inline char *
strndup(const char *s, size_t n)
{
char *result;
size_t len = strlen(s);
if(n < len)
len = n;
result = (char *)malloc(len + 1);
if(!result)
return 0;
result[len] = '\0';
return (char *)strncpy(result, s, len);
}
#endif
#define _spin_lock(FLAG) while(atomic_flag_test_and_set_explicit((FLAG), memory_order_acquire)) {}
#define _try_lock(FLAG) !atomic_flag_test_and_set_explicit((FLAG), memory_order_acquire)
#define _unlock(FLAG) atomic_flag_clear_explicit((FLAG), memory_order_release)
......
......@@ -24,8 +24,6 @@
#include <uv.h>
#include <lv2_external_ui.h> // kxstudio external-ui extension
#define USE_FS_EVENT 1 // this is much more efficient than polling
typedef struct _UI UI;
struct _UI {
......@@ -54,6 +52,7 @@ struct _UI {
uv_process_options_t opts;
#if USE_FS_EVENT
uv_fs_event_t fs;
uv_timespec_t mtim;
#else
uv_fs_poll_t pol;
#endif
......@@ -65,9 +64,28 @@ struct _UI {
} kx;
uint8_t buf [0x10000];
char dir [512];
char path [512];
};
static inline void
_err2(UI *ui, const char *from)
{
if(ui->log)
lv2_log_error(&ui->logger, "%s", from);
else
fprintf(stderr, "%s\n", from);
}
static inline void
_err(UI *ui, const char *from, int ret)
{
if(ui->log)
lv2_log_error(&ui->logger, "%s: %s", from, uv_strerror(ret));
else
fprintf(stderr, "%s: %s\n", from, uv_strerror(ret));
}
static void
_moony_message_send(UI *ui, LV2_URID otype, LV2_URID key,
uint32_t size, const char *str)
......@@ -82,8 +100,10 @@ _moony_message_send(UI *ui, LV2_URID otype, LV2_URID key,
ui->write_function(ui->controller, ui->control_port, lv2_atom_total_size(&obj->atom),
ui->uris.event_transfer, ui->buf);
if(ui->log)
lv2_log_note(&ui->logger, "sent message");
lv2_log_note(&ui->logger, str && size ? "send code chunk" : "query code chunk");
}
else if(ui->log)
lv2_log_error(&ui->logger, "code chunk too long");
}
static void
......@@ -119,18 +139,28 @@ _load_chosen(UI *ui, const char *path)
static inline void
_hide(UI *ui)
{
int ret;
#if USE_FS_EVENT
if(uv_is_active((uv_handle_t *)&ui->fs))
uv_fs_event_stop(&ui->fs);
{
if((ret = uv_fs_event_stop(&ui->fs)))
_err(ui, "uv_fs_event_stop", ret);
}
uv_close((uv_handle_t *)&ui->fs, NULL);
#else
if(uv_is_active((uv_handle_t *)&ui->pol))
uv_fs_poll_stop(&ui->pol);
{
if((ret = uv_fs_poll_stop(&ui->pol)))
_err(ui, "uv_fs_poll_stop", ret);
}
uv_close((uv_handle_t *)&ui->pol, NULL);
#endif
if(uv_is_active((uv_handle_t *)&ui->req))
uv_process_kill(&ui->req, SIGKILL);
{
if((ret = uv_process_kill(&ui->req, SIGKILL)))
_err(ui, "uv_process_kill", ret);
}
uv_close((uv_handle_t *)&ui->req, NULL);
uv_stop(&ui->loop);
......@@ -165,16 +195,40 @@ _on_fs_event(uv_fs_event_t *fs, const char *path, int events, int status)
if(events & UV_CHANGE)
{
uv_fs_t req;
int ret;
if((ret = uv_fs_stat(&ui->loop, &req, ui->path, NULL)))
_err(ui, "uv_fs_stat", ret);
else
{
if( (ui->mtim.tv_sec == req.statbuf.st_mtim.tv_sec)
&& (ui->mtim.tv_nsec == req.statbuf.st_mtim.tv_nsec) )
{
// same timestamp as before, e.g. false alarm
return;
}
else
{
ui->mtim.tv_sec = req.statbuf.st_mtim.tv_sec;
ui->mtim.tv_nsec = req.statbuf.st_mtim.tv_nsec;
}
}
_load_chosen(ui, ui->path);
}
if(events & UV_RENAME)
{
int ret;
if(uv_is_active((uv_handle_t *)&ui->fs))
uv_fs_event_stop(&ui->fs);
{
if((ret = uv_fs_event_stop(&ui->fs)))
_err(ui, "uv_fs_event_stop", ret);
}
//restart watcher
uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0);
if((ret = uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0)))
_err(ui, "uv_fs_event_start", ret);
}
}
#else
......@@ -185,6 +239,13 @@ _on_fs_poll(uv_fs_poll_t *pol, int status, const uv_stat_t* prev, const uv_stat_
if(!ui)
return;
if( (prev->st_mtim.tv_sec == curr->st_mtim.tv_sec)
&& (prev->st_mtim.tv_nsec == curr->st_mtim.tv_nsec) )
{
// same timestamp as before, e.g. false alarm
return;
}
_load_chosen(ui, ui->path);
}
#endif
......@@ -201,8 +262,6 @@ _parse_env(char *env, char *path)
char *pch = strtok(env," \t");
while(pch)
{
//printf("%s\n", pch);
args[n++] = pch;
args = realloc(args, (n+1) * sizeof(char *));
if(!args)
......@@ -232,7 +291,7 @@ _show(UI *ui)
#if defined(_WIN32)
const char *command = "START \"Moony\" /WAIT";
#elif defined(__APPLE__)
const char *command = "open -t -n -W --args";
const char *command = "open -nW";
#else // Linux/BSD
//const char *command = "xdg-open";
const char *command = "xterm -e vim";
......@@ -249,32 +308,32 @@ _show(UI *ui)
ui->opts.file = args ? args[0] : NULL;
ui->opts.args = args;
// touch file
FILE *f = fopen(ui->path, "wb");
if(f)
fclose(f);
#if USE_FS_EVENT
if(!uv_is_active((uv_handle_t *)&ui->fs))
uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0);
{
int ret;
if((ret = uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0)))
_err(ui, "uv_fs_event_start", ret);
}
#else
if(!uv_is_active((uv_handle_t *)&ui->pol))
uv_fs_poll_start(&ui->pol, _on_fs_poll, ui->path, 1000); // ms
{
int ret;
if((ret = uv_fs_poll_start(&ui->pol, _on_fs_poll, ui->path, 1000))) // ms
_err(ui, "uv_fs_poll_start", ret);
}
#endif
if(!uv_is_active((uv_handle_t *)&ui->req))
{
int r;
if((r = uv_spawn(&ui->loop, &ui->req, &ui->opts)))
{
if(ui->log)
lv2_log_error(&ui->logger, "%s", uv_strerror(r));
}
else
{
if(ui->log)
lv2_log_note(&ui->logger, "Launched process with ID %d", ui->req.pid);
}
}
else
{
if(ui->log)
lv2_log_warning(&ui->logger, "Process already running with ID %d", ui->req.pid);
int ret;
if((ret = uv_spawn(&ui->loop, &ui->req, &ui->opts)))
_err(ui, "uv_spawn", ret);
}
if(dup)
......@@ -422,19 +481,64 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
ui->write_function = write_function;
ui->controller = controller;
sprintf(ui->path, "%s/moony_XXXXXX.lua", P_tmpdir);
int fd = mkstemps(ui->path, 4);
int ret;
if((ret = uv_loop_init(&ui->loop)))
{
fprintf(stderr, "%s: %s\n", descriptor->URI, uv_strerror(ret));
free(ui);
return NULL;
}
char *tmp_template;
#if defined(_WIN32)
char tmp_dir[MAX_PATH + 1];
GetTempPath(MAX_PATH + 1, tmp_dir);
asprintf(&tmp_template, "%s\\moony_XXXXXX", tmp_dir);
#else
const char *tmp_dir = P_tmpdir;
asprintf(&tmp_template, "%s/moony_XXXXXX", tmp_dir);
#endif
if(!tmp_template)
{
fprintf(stderr, "%s: out of memory\n", descriptor->URI);
free(ui);
return NULL;
}
uv_fs_t req;
if((ret = uv_fs_mkdtemp(&ui->loop, &req, tmp_template, NULL)))
{
fprintf(stderr, "%s: %s\n", descriptor->URI, uv_strerror(ret));
free(ui);
return NULL;
}
sprintf(ui->dir, "%s", req.path);
#if defined(_WIN32)
sprintf(ui->path, "%s\\moony.lua", req.path);
#else
sprintf(ui->path, "%s/moony.lua", req.path);
#endif
uv_fs_req_cleanup(&req); // deallocates req.path
free(tmp_template);
if(ui->log)
{
lv2_log_note(&ui->logger, "dir: %s", ui->dir);
lv2_log_note(&ui->logger, "path: %s", ui->path);
close(fd);
}
_moony_message_send(ui, ui->uris.moony_message, ui->uris.moony_code, 0, NULL);
uv_loop_init(&ui->loop);
#if USE_FS_EVENT
uv_fs_event_init(&ui->loop, &ui->fs);
if((ret = uv_fs_event_init(&ui->loop, &ui->fs)))
_err(ui, "uv_fs_event_init", ret);
#else
uv_fs_poll_init(&ui->loop, &ui->pol);
if((ret = uv_fs_poll_init(&ui->loop, &ui->pol)))
_err(ui, "uv_fs_poll_init", ret);
#endif
return ui;
......@@ -445,6 +549,13 @@ cleanup(LV2UI_Handle handle)
{
UI *ui = handle;
int ret;
uv_fs_t req;
if((ret = uv_fs_unlink(&ui->loop, &req, ui->path, NULL)))
_err(ui, "uv_fs_unlink", ret);
if((ret = uv_fs_rmdir(&ui->loop, &req, ui->dir, NULL)))
_err(ui, "uv_fs_rmdir", ret);
uv_loop_close(&ui->loop);
}
......@@ -475,33 +586,45 @@ port_event(LV2UI_Handle handle, uint32_t port_index, uint32_t buffer_size,
{
const char *str = LV2_ATOM_BODY_CONST(&moony_code->atom);
int ret;
#if USE_FS_EVENT
uv_fs_event_stop(&ui->fs);
if((ret = uv_fs_event_stop(&ui->fs)))
_err(ui, "uv_fs_event_stop", ret);
#else
uv_fs_poll_stop(&ui->pol);
if((ret = uv_fs_poll_stop(&ui->pol)))
_err(ui, "uv_fs_poll_stop", ret);
#endif
FILE *f = fopen(ui->path, "wb");
if(f)
{
fwrite(str, moony_code->atom.size-1, 1, f); //TODO check
if(fwrite(str, moony_code->atom.size-1, 1, f) != 1)
_err2(ui, "fwrite");
fclose(f);
}
else
_err2(ui, "fopen");
#if USE_FS_EVENT
uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0);
if((ret = uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0)))
_err(ui, "uv_fs_event_start", ret);
#else
uv_fs_poll_start(&ui->pol, _on_fs_poll, ui->path, 1000); // ms
if((ret = uv_fs_poll_start(&ui->pol, _on_fs_poll, ui->path, 1000))) // ms
_err(ui, "uv_fs_poll_start", ret);
#endif
}
else if(moony_error)
{
const char *str = LV2_ATOM_BODY_CONST(&moony_error->atom);
int ret;
#if USE_FS_EVENT
uv_fs_event_stop(&ui->fs);
if((ret = uv_fs_event_stop(&ui->fs)))
_err(ui, "uv_fs_event_stop", ret);
#else
uv_fs_poll_stop(&ui->pol);
if((ret = uv_fs_poll_stop(&ui->pol)))
_err(ui, "uv_fs_poll_stop", ret);
#endif
FILE *f = fopen(ui->path, "ab");
......@@ -515,9 +638,11 @@ port_event(LV2UI_Handle handle, uint32_t port_index, uint32_t buffer_size,
}
#if USE_FS_EVENT
uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0);
if((ret = uv_fs_event_start(&ui->fs, _on_fs_event, ui->path, 0)))
_err(ui, "uv_fs_event_start", ret);
#else
uv_fs_poll_start(&ui->pol, _on_fs_poll, ui->path, 1000); // ms
if((ret = uv_fs_poll_start(&ui->pol, _on_fs_poll, ui->path, 1000))) // ms
_err(ui, "uv_fs_poll_start", ret);
#endif
}
}
......
......@@ -15,7 +15,9 @@
* http://www.perlfoundation.org/artistic_license_2_0.
*/
#include <sys/mman.h>
#if !defined(_WIN32)
# include <sys/mman.h>
#endif
#include <assert.h>
#include <moony.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment