diff options
-rw-r--r-- | core/config.c | 5 | ||||
-rw-r--r-- | core/core.c | 3 | ||||
-rw-r--r-- | core/plugin.c | 12 | ||||
-rw-r--r-- | midimonster.c | 11 | ||||
-rw-r--r-- | midimonster.h | 9 |
5 files changed, 30 insertions, 10 deletions
diff --git a/core/config.c b/core/config.c index 705f690..b950b25 100644 --- a/core/config.c +++ b/core/config.c @@ -3,7 +3,10 @@ #include <unistd.h> #include <errno.h> #ifndef _WIN32 -#include <limits.h> + #include <limits.h> + #define MM_API __attribute__((visibility ("default"))) +#else + #define MM_API __attribute__((dllexport)) #endif #define BACKEND_NAME "core/cfg" diff --git a/core/core.c b/core/core.c index f9874f7..804ec4e 100644 --- a/core/core.c +++ b/core/core.c @@ -7,6 +7,7 @@ #include <sys/select.h> #define MM_API __attribute__((visibility ("default"))) #else + #include <fcntl.h> #define MM_API __attribute__((dllexport)) #endif @@ -223,7 +224,7 @@ int core_iteration(){ } //run backend processing to collect events - DBGPF("%" PRIsize_t " backend FDs signaled", nfds); + DBGPF("%" PRIsize_t " backend FDs signaled", n); if(backends_handle(n, signaled_fds)){ return 1; } diff --git a/core/plugin.c b/core/plugin.c index ec32760..cd85059 100644 --- a/core/plugin.c +++ b/core/plugin.c @@ -7,12 +7,14 @@ #include <dirent.h> #include "portability.h" #ifdef _WIN32 -#define dlclose FreeLibrary -#define dlsym GetProcAddress -#define dlerror() "Failed" -#define dlopen(lib,ig) LoadLibrary(lib) + #define dlclose FreeLibrary + #define dlsym GetProcAddress + #define dlerror() "Failed" + #define dlopen(lib,ig) LoadLibrary(lib) + #define MM_API __attribute__((dllexport)) #else -#include <dlfcn.h> + #include <dlfcn.h> + #define MM_API __attribute__((visibility ("default"))) #endif #define BACKEND_NAME "core/pl" diff --git a/midimonster.c b/midimonster.c index 5e415e6..d00f116 100644 --- a/midimonster.c +++ b/midimonster.c @@ -1,5 +1,6 @@ #include <string.h> #include <signal.h> +#include <stdarg.h> #ifndef _WIN32 #define MM_API __attribute__((visibility("default"))) #else @@ -13,6 +14,16 @@ volatile static sig_atomic_t shutdown_requested = 0; +MM_API int log_printf(int level, char* module, char* fmt, ...){ + int rv = 0; + va_list args; + va_start(args, fmt); + fprintf(stderr, "%s%s\t", level ? "debug/" : "", module); + rv = vfprintf(stderr, fmt, args); + va_end(args); + return rv; +} + static void signal_handler(int signum){ shutdown_requested = 1; } diff --git a/midimonster.h b/midimonster.h index 64aa1e5..15ce34a 100644 --- a/midimonster.h +++ b/midimonster.h @@ -40,16 +40,19 @@ /* Clamp a value to a range */ #define clamp(val,max,min) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val))) +/* Log function prototype - do not use directly. Use the LOG/LOGPF/DBGPF macros below instead */ +MM_API __attribute__((format(printf, 3, 4))) int log_printf(int level, char* module, char* fmt, ...); + /* Debug messages only compile in when DEBUG is set */ #ifdef DEBUG - #define DBGPF(format, ...) fprintf(stderr, "debug/%s\t" format "\n", (BACKEND_NAME), __VA_ARGS__) + #define DBGPF(format, ...) log_printf(1, (BACKEND_NAME), format "\n", __VA_ARGS__) #else #define DBGPF(format, ...) #endif /* Log messages should be routed through these macros to ensure interoperability with different core implementations */ -#define LOGPF(format, ...) fprintf(stderr, "%s\t" format "\n", (BACKEND_NAME), __VA_ARGS__) -#define LOG(message) fprintf(stderr, "%s\t%s\n", (BACKEND_NAME), (message)) +#define LOGPF(format, ...) log_printf(0, (BACKEND_NAME), format "\n", __VA_ARGS__) +#define LOG(message) log_printf(0, (BACKEND_NAME), message "\n") /* Stop compilation if the build system reports an error */ #ifdef BUILD_ERROR |