rename win32 irq allocation calls to prevent conflicts with AROS kernel API calls.
[AROS.git] / arch / all-mingw32 / filesys / emul_handler / emul_handler_native.c
blobd3f29a6d441c2159a763ad1426449a200d206ead
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Host-side hepler code for Windows emul.handler
6 Lang: english
7 */
9 #define _WIN32_IE 0x0500
10 #include <windows.h>
11 #include <shlobj.h>
13 #include <stdio.h>
14 #include <aros/irq.h>
16 #include "emul_host.h"
18 #define DWINAPI(x) /* WinAPI calls debug */
19 #define DASYNC(x) /* Asynchronous I/O thread debug */
21 HMODULE kernel_lib;
22 void (*CauseIRQ)(unsigned char irq, void *data);
24 /*********************************************************************************************/
26 unsigned long __declspec(dllexport) __aros EmulGetHome(const char *name, char *home)
28 HRESULT res;
30 /* TODO: currently username is ignored, however we should acquire an access token for it */
31 DWINAPI(printf("[EmulHandler] SHGetFolderPath()\n"));
33 res = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_DEFAULT, home);
34 return res ? ERROR_FILE_NOT_FOUND : 0;
37 static DWORD WINAPI EmulThread(struct AsyncReaderControl *emsg)
39 BOOL res;
41 DASYNC(printf("[EmulHandler I/O] Thread started, handle 0x%08lX, host handle 0x%08lX, host ID %lu\n", THandle, THandle->handle, THandle->id));
42 for (;;)
44 WaitForSingleObject(emsg->CmdEvent, INFINITE);
45 DASYNC(printf("[EmulHandler I/O] Got command: 0xu\n", emsg->cmd));
46 switch(emsg->cmd)
48 case ASYNC_CMD_SHUTDOWN:
49 DASYNC(printf("[EmulHandler I/O] shutting down thread\n"));
50 return 0;
52 case ASYNC_CMD_READ:
53 DASYNC(printf("[EmulHandler I/O] READ %lu bytes at 0x%p, file 0x%p\n", emsg->len, emsg->addr, emsg->fh));
54 DWORD actual;
55 res = ReadFile(emsg->fh, emsg->addr, emsg->len, &actual, NULL);
56 emsg->actual = actual;
57 emsg->error = res ? 0 : GetLastError();
58 DASYNC(printf("[EmulHandler I/O] %lu bytes transferred, result %ld, error %lu\n", emsg->actual, res, emsg->error));
59 KrnCauseSystemIRQ(emsg->IrqNum);
64 struct AsyncReaderControl ControlStruct;
66 struct AsyncReaderControl * __declspec(dllexport) __aros Emul_Init_Native(void)
68 HANDLE thread;
69 DWORD id;
70 long irq;
72 irq = KrnAllocSystemIRQ();
73 if (irq != -1)
75 ControlStruct.IrqNum = irq;
76 ControlStruct.CmdEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
77 if (ControlStruct.CmdEvent)
79 thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)EmulThread, &ControlStruct, 0, &id);
80 if (thread)
82 CloseHandle(thread);
83 return &ControlStruct;
85 CloseHandle(ControlStruct.CmdEvent);
88 return NULL;