conhost: Add initial main loop implementation.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
76037ffbee
commit
e24ba09f8f
|
@ -16,18 +16,137 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <ntstatus.h>
|
||||
#define WIN32_NO_STATUS
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winuser.h>
|
||||
#include <winternl.h>
|
||||
|
||||
#include "wine/debug.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(conhost);
|
||||
|
||||
int __cdecl wmain(int argc, WCHAR *argv[])
|
||||
struct console
|
||||
{
|
||||
int i;
|
||||
HANDLE server; /* console server handle */
|
||||
};
|
||||
|
||||
WINE_FIXME("stub:");
|
||||
for (i = 0; i < argc; i++)
|
||||
WINE_FIXME(" %s", wine_dbgstr_w(argv[i]));
|
||||
WINE_FIXME("\n");
|
||||
static int main_loop( struct console *console, HANDLE signal )
|
||||
{
|
||||
HANDLE signal_event = NULL;
|
||||
HANDLE wait_handles[2];
|
||||
unsigned int wait_cnt = 0;
|
||||
unsigned short signal_id;
|
||||
IO_STATUS_BLOCK signal_io;
|
||||
NTSTATUS status;
|
||||
DWORD res;
|
||||
|
||||
if (signal)
|
||||
{
|
||||
if (!(signal_event = CreateEventW( NULL, TRUE, FALSE, NULL ))) return 1;
|
||||
status = NtReadFile( signal, signal_event, NULL, NULL, &signal_io, &signal_id,
|
||||
sizeof(signal_id), NULL, NULL );
|
||||
if (status && status != STATUS_PENDING) return 1;
|
||||
}
|
||||
|
||||
wait_handles[wait_cnt++] = console->server;
|
||||
if (signal) wait_handles[wait_cnt++] = signal_event;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
res = WaitForMultipleObjects( wait_cnt, wait_handles, FALSE, INFINITE );
|
||||
|
||||
switch (res)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
FIXME( "console ioctls not yet implemented\n" );
|
||||
return 1;
|
||||
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
if (signal_io.Status || signal_io.Information != sizeof(signal_id))
|
||||
{
|
||||
TRACE( "signaled quit\n" );
|
||||
return 0;
|
||||
}
|
||||
FIXME( "unimplemented signal %x\n", signal_id );
|
||||
status = NtReadFile( signal, signal_event, NULL, NULL, &signal_io, &signal_id,
|
||||
sizeof(signal_id), NULL, NULL );
|
||||
if (status && status != STATUS_PENDING) return 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
TRACE( "wait failed, quit\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __cdecl wmain(int argc, WCHAR *argv[])
|
||||
{
|
||||
int headless = 0, i, width = 80, height = 150;
|
||||
HANDLE signal = NULL;
|
||||
WCHAR *end;
|
||||
|
||||
static struct console console;
|
||||
|
||||
for (i = 0; i < argc; i++) TRACE("%s ", wine_dbgstr_w(argv[i]));
|
||||
TRACE("\n");
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (!wcscmp( argv[i], L"--headless"))
|
||||
{
|
||||
headless = 1;
|
||||
continue;
|
||||
}
|
||||
if (!wcscmp( argv[i], L"--width" ))
|
||||
{
|
||||
if (++i == argc) return 1;
|
||||
width = wcstol( argv[i], &end, 0 );
|
||||
if (!width || width > 0xffff || *end) return 1;
|
||||
continue;
|
||||
}
|
||||
if (!wcscmp( argv[i], L"--height" ))
|
||||
{
|
||||
if (++i == argc) return 1;
|
||||
height = wcstol( argv[i], &end, 0 );
|
||||
if (!height || height > 0xffff || *end) return 1;
|
||||
continue;
|
||||
}
|
||||
if (!wcscmp( argv[i], L"--signal" ))
|
||||
{
|
||||
if (++i == argc) return 1;
|
||||
signal = ULongToHandle( wcstol( argv[i], &end, 0 ));
|
||||
if (*end) return 1;
|
||||
continue;
|
||||
}
|
||||
if (!wcscmp( argv[i], L"--server" ))
|
||||
{
|
||||
if (++i == argc) return 1;
|
||||
console.server = ULongToHandle( wcstol( argv[i], &end, 0 ));
|
||||
if (*end) return 1;
|
||||
continue;
|
||||
}
|
||||
FIXME( "unknown option %s\n", debugstr_w(argv[i]) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!headless)
|
||||
{
|
||||
FIXME( "windowed mode not supported\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!console.server)
|
||||
{
|
||||
ERR( "no server handle\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
return main_loop( &console, signal );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue