ddraw: Move the wined3d_texture_update_desc() call into ddraw_surface_create_wined3d_...
[wine.git] / dlls / windows.gaming.input / event_handlers.c
blobb9b061e3362e66db74515d385c7aeba5d884ba6a
1 /* WinRT Windows.Gaming.Input implementation
3 * Copyright 2022 RĂ©mi Bernon for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "private.h"
22 static CRITICAL_SECTION handlers_cs;
23 static CRITICAL_SECTION_DEBUG handlers_cs_debug =
25 0, 0, &handlers_cs,
26 { &handlers_cs_debug.ProcessLocksList, &handlers_cs_debug.ProcessLocksList },
27 0, 0, { (DWORD_PTR)(__FILE__ ": handlers_cs") }
29 static CRITICAL_SECTION handlers_cs = { &handlers_cs_debug, -1, 0, 0, 0, 0 };
30 static EventRegistrationToken next_token = {.value = 1};
32 struct handler_entry
34 struct list entry;
35 EventRegistrationToken token;
36 IEventHandler_IInspectable *handler;
39 HRESULT event_handlers_append( struct list *list, IEventHandler_IInspectable *handler, EventRegistrationToken *token )
41 struct handler_entry *entry;
43 if (!(entry = calloc( 1, sizeof(*entry) ))) return E_OUTOFMEMORY;
44 IEventHandler_IInspectable_AddRef( (entry->handler = handler) );
46 EnterCriticalSection( &handlers_cs );
48 *token = entry->token = next_token;
49 next_token.value++;
50 list_add_tail( list, &entry->entry );
52 LeaveCriticalSection( &handlers_cs );
54 return S_OK;
57 HRESULT event_handlers_remove( struct list *list, EventRegistrationToken *token )
59 struct handler_entry *entry;
60 BOOL found = FALSE;
62 EnterCriticalSection( &handlers_cs );
64 LIST_FOR_EACH_ENTRY( entry, list, struct handler_entry, entry )
65 if ((found = !memcmp( &entry->token, token, sizeof(*token) ))) break;
66 if (found) list_remove( &entry->entry );
68 LeaveCriticalSection( &handlers_cs );
70 if (found)
72 IEventHandler_IInspectable_Release( entry->handler );
73 free( entry );
76 return S_OK;
79 void event_handlers_notify( struct list *list, IInspectable *element )
81 struct handler_entry *entry;
83 EnterCriticalSection( &handlers_cs );
85 LIST_FOR_EACH_ENTRY( entry, list, struct handler_entry, entry )
86 IEventHandler_IInspectable_Invoke( entry->handler, NULL, element );
88 LeaveCriticalSection( &handlers_cs );