2006-10-24 15:26:33 +02:00
|
|
|
/*
|
2012-12-17 01:06:52 +01:00
|
|
|
* MACDRV initialization code
|
2006-10-24 15:26:33 +02:00
|
|
|
*
|
|
|
|
* Copyright 1998 Patrik Stridvall
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2013-01-07 21:44:36 +01:00
|
|
|
* Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
|
2006-10-24 15:26:33 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-01-07 21:44:36 +01:00
|
|
|
#include "macdrv.h"
|
2013-01-21 07:07:58 +01:00
|
|
|
#include "wine/server.h"
|
2013-01-07 21:44:36 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(macdrv);
|
2006-10-24 15:26:33 +02:00
|
|
|
|
|
|
|
|
2013-01-21 07:07:58 +01:00
|
|
|
DWORD thread_data_tls_index = TLS_OUT_OF_INDEXES;
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* process_attach
|
|
|
|
*/
|
|
|
|
static BOOL process_attach(void)
|
|
|
|
{
|
2013-01-21 07:08:12 +01:00
|
|
|
assert(NUM_EVENT_TYPES <= sizeof(macdrv_event_mask) * 8);
|
|
|
|
|
2013-01-21 07:07:58 +01:00
|
|
|
if ((thread_data_tls_index = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;
|
|
|
|
|
|
|
|
macdrv_err_on = ERR_ON(macdrv);
|
2013-01-27 23:19:33 +01:00
|
|
|
if (macdrv_start_cocoa_app(GetTickCount64()))
|
2013-01-21 07:07:58 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to start Cocoa app main loop\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* thread_detach
|
|
|
|
*/
|
|
|
|
static void thread_detach(void)
|
|
|
|
{
|
|
|
|
struct macdrv_thread_data *data = macdrv_thread_data();
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
macdrv_destroy_event_queue(data->queue);
|
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-24 15:26:33 +02:00
|
|
|
/***********************************************************************
|
2013-01-21 07:07:58 +01:00
|
|
|
* set_queue_display_fd
|
|
|
|
*
|
|
|
|
* Store the event queue fd into the message queue
|
2006-10-24 15:26:33 +02:00
|
|
|
*/
|
2013-01-21 07:07:58 +01:00
|
|
|
static void set_queue_display_fd(int fd)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (wine_server_fd_to_handle(fd, GENERIC_READ | SYNCHRONIZE, 0, &handle))
|
|
|
|
{
|
|
|
|
MESSAGE("macdrv: Can't allocate handle for event queue fd\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
SERVER_START_REQ(set_queue_fd)
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle(handle);
|
|
|
|
ret = wine_server_call(req);
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
MESSAGE("macdrv: Can't store handle for event queue fd\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
CloseHandle(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* macdrv_init_thread_data
|
|
|
|
*/
|
|
|
|
struct macdrv_thread_data *macdrv_init_thread_data(void)
|
|
|
|
{
|
|
|
|
struct macdrv_thread_data *data = macdrv_thread_data();
|
|
|
|
|
|
|
|
if (data) return data;
|
|
|
|
|
|
|
|
if (!(data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
|
|
|
|
{
|
|
|
|
ERR("could not create data\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(data->queue = macdrv_create_event_queue()))
|
|
|
|
{
|
|
|
|
ERR("macdrv: Can't create event queue.\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_queue_display_fd(macdrv_get_event_queue_fd(data->queue));
|
|
|
|
TlsSetValue(thread_data_tls_index, data);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllMain
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
|
2006-10-24 15:26:33 +02:00
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
switch(reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2013-01-21 07:07:58 +01:00
|
|
|
ret = process_attach();
|
2006-10-24 15:26:33 +02:00
|
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
2013-01-21 07:07:58 +01:00
|
|
|
thread_detach();
|
2006-10-24 15:26:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|