aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-06-30 17:22:15 -0700
committerChris Robinson <[email protected]>2017-06-30 17:22:15 -0700
commit32bda7b94c95f4f83a5c329c415d4dc14e099c03 (patch)
treeaccb1899ceefb4d42157855518b2774bf8c7e77a
parent77e317609b3a879a8fb3970ecc7d347c09a7a528 (diff)
Add tracing capabilities to the router
-rw-r--r--router/alc.c1
-rw-r--r--router/router.c52
-rw-r--r--router/router.h25
3 files changed, 74 insertions, 4 deletions
diff --git a/router/alc.c b/router/alc.c
index 8f095fec..c5840154 100644
--- a/router/alc.c
+++ b/router/alc.c
@@ -279,6 +279,7 @@ static void AppendDeviceList(EnumeratedList *list, const ALCchar *names, ALint i
return;
while(*name_end)
{
+ TRACE("Enumerated \"%s\", driver %d\n", name_end, idx);
count++;
name_end += strlen(name_end)+1;
}
diff --git a/router/router.c b/router/router.c
index 5dc1e43b..9522814d 100644
--- a/router/router.c
+++ b/router/router.c
@@ -18,16 +18,42 @@ static int DriverListSizeMax = 0;
almtx_t EnumerationLock;
almtx_t ContextSwitchLock;
+enum LogLevel LogLevel = LogLevel_Error;
+FILE *LogFile;
+
static void LoadDriverList(void);
BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reserved))
{
+ const char *str;
int i;
switch(reason)
{
case DLL_PROCESS_ATTACH:
+ LogFile = stderr;
+ str = getenv("ALROUTER_LOGFILE");
+ if(str && *str != '\0')
+ {
+ FILE *f = fopen(str, "w");
+ if(f == NULL)
+ ERR("Could not open log file: %s\n", str);
+ else
+ LogFile = f;
+ }
+ str = getenv("ALROUTER_LOGLEVEL");
+ if(str && *str != '\0')
+ {
+ char *end = NULL;
+ long l = strtol(str, &end, 0);
+ if(!end || *end != '\0')
+ ERR("Invalid log level value: %s\n", str);
+ else if(l < LogLevel_None || l > LogLevel_Trace)
+ ERR("Log level out of range: %s\n", str);
+ else
+ LogLevel = l;
+ }
LoadDriverList();
almtx_init(&EnumerationLock, almtx_recursive);
almtx_init(&ContextSwitchLock, almtx_plain);
@@ -39,6 +65,7 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
case DLL_PROCESS_DETACH:
ReleaseALC();
+
almtx_destroy(&ContextSwitchLock);
almtx_destroy(&EnumerationLock);
for(i = 0;i < DriverListSize;i++)
@@ -50,6 +77,10 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
DriverList = NULL;
DriverListSize = 0;
DriverListSizeMax = 0;
+
+ if(LogFile && LogFile != stderr)
+ fclose(LogFile);
+ LogFile = NULL;
break;
}
return TRUE;
@@ -70,8 +101,15 @@ static void AddModule(HMODULE module, const WCHAR *name)
for(i = 0;i < DriverListSize;i++)
{
- if(DriverList[i].Module == module || wcscmp(DriverList[i].Name, name) == 0)
+ if(DriverList[i].Module == module)
+ {
+ TRACE("Skipping already-loaded module %p\n", module);
+ FreeLibrary(module);
+ return;
+ }
+ if(wcscmp(DriverList[i].Name, name) == 0)
{
+ TRACE("Skipping similarly-named module %ls\n", name);
FreeLibrary(module);
return;
}
@@ -94,8 +132,7 @@ static void AddModule(HMODULE module, const WCHAR *name)
newdrv.x = CAST_FUNC(newdrv.x) GetProcAddress(module, #x); \
if(!newdrv.x) \
{ \
- fprintf(stderr, "Failed to find entry point for %s in %ls\n", \
- #x, name); \
+ ERR("Failed to find entry point for %s in %ls\n", #x, name); \
err = 1; \
} \
} while(0)
@@ -204,6 +241,8 @@ static void AddModule(HMODULE module, const WCHAR *name)
newdrv.ALCVer = MAKE_ALC_VER(alc_ver[0], alc_ver[1]);
else
newdrv.ALCVer = MAKE_ALC_VER(1, 0);
+ TRACE("Loaded module %p, %ls, ALC %d.%d\n", module, name,
+ newdrv.ALCVer>>8, newdrv.ALCVer&255);
DriverList[DriverListSize++] = newdrv;
}
}
@@ -214,6 +253,7 @@ static void SearchDrivers(WCHAR *path)
WIN32_FIND_DATAW fdata;
HANDLE srchHdl;
+ TRACE("Searching for drivers in %ls...\n", path);
wcsncpy(srchPath, path, MAX_PATH);
wcsncat(srchPath, L"\\*oal.dll", MAX_PATH - lstrlenW(srchPath));
srchHdl = FindFirstFileW(srchPath, &fdata);
@@ -225,9 +265,13 @@ static void SearchDrivers(WCHAR *path)
wcsncpy(srchPath, path, MAX_PATH);
wcsncat(srchPath, L"\\", MAX_PATH - lstrlenW(srchPath));
wcsncat(srchPath, fdata.cFileName, MAX_PATH - lstrlenW(srchPath));
+ TRACE("Found %ls\n", srchPath);
mod = LoadLibraryW(srchPath);
- if(mod) AddModule(mod, fdata.cFileName);
+ if(!mod)
+ WARN("Could not load %ls\n", srchPath);
+ else
+ AddModule(mod, fdata.cFileName);
} while(FindNextFileW(srchHdl, &fdata));
FindClose(srchHdl);
}
diff --git a/router/router.h b/router/router.h
index 1eef017f..7cc94399 100644
--- a/router/router.h
+++ b/router/router.h
@@ -5,6 +5,8 @@
#include <windows.h>
#include <winnt.h>
+#include <stdio.h>
+
#include "AL/alc.h"
#include "AL/al.h"
#include "atomic.h"
@@ -156,4 +158,27 @@ extern almtx_t ContextSwitchLock;
void ReleaseALC(void);
+
+enum LogLevel {
+ LogLevel_None = 0,
+ LogLevel_Error = 1,
+ LogLevel_Warn = 2,
+ LogLevel_Trace = 3,
+};
+extern enum LogLevel LogLevel;
+extern FILE *LogFile;
+
+#define TRACE(...) do { \
+ if(LogLevel >= LogLevel_Trace) \
+ fprintf(LogFile, "AL Router (II): " __VA_ARGS__); \
+} while(0)
+#define WARN(...) do { \
+ if(LogLevel >= LogLevel_Warn) \
+ fprintf(LogFile, "AL Router (WW): " __VA_ARGS__); \
+} while(0)
+#define ERR(...) do { \
+ if(LogLevel >= LogLevel_Error) \
+ fprintf(LogFile, "AL Router (EE): " __VA_ARGS__); \
+} while(0)
+
#endif /* ROUTER_ROUTER_H */