Skip to content

Commit 54016b1

Browse files
committed
Add RegisterEventSource and DeregisterEventSource in _winapi
1 parent ec4021c commit 54016b1

File tree

7 files changed

+240
-1
lines changed

7 files changed

+240
-1
lines changed

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ struct _Py_global_strings {
740740
STRUCT_FOR_ID(sock)
741741
STRUCT_FOR_ID(sort)
742742
STRUCT_FOR_ID(source)
743+
STRUCT_FOR_ID(source_name)
743744
STRUCT_FOR_ID(source_traceback)
744745
STRUCT_FOR_ID(spam)
745746
STRUCT_FOR_ID(src)
@@ -799,6 +800,7 @@ struct _Py_global_strings {
799800
STRUCT_FOR_ID(tzinfo)
800801
STRUCT_FOR_ID(tzname)
801802
STRUCT_FOR_ID(uid)
803+
STRUCT_FOR_ID(unc_server_name)
802804
STRUCT_FOR_ID(unlink)
803805
STRUCT_FOR_ID(unraisablehook)
804806
STRUCT_FOR_ID(updates)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_winapi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,17 @@ def test_namedpipe(self):
156156
pipe2.write(b'testdata')
157157
pipe2.flush()
158158
self.assertEqual((b'testdata', 8), _winapi.PeekNamedPipe(pipe, 8)[:2])
159+
160+
def test_event_source_registration(self):
161+
source_name = "PythonTestEventSource"
162+
163+
handle = _winapi.RegisterEventSource(None, source_name)
164+
self.assertNotEqual(handle, _winapi.INVALID_HANDLE_VALUE)
165+
166+
_winapi.DeregisterEventSource(handle)
167+
168+
with self.assertRaises(OSError):
169+
_winapi.RegisterEventSource(None, "")
170+
171+
with self.assertRaises(OSError):
172+
_winapi.DeregisterEventSource(_winapi.INVALID_HANDLE_VALUE)

Modules/_winapi.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,58 @@ _winapi_CopyFile2_impl(PyObject *module, LPCWSTR existing_file_name,
29772977
Py_RETURN_NONE;
29782978
}
29792979

2980+
/*[clinic input]
2981+
_winapi.RegisterEventSource -> HANDLE
2982+
2983+
unc_server_name: LPCWSTR(accept={str, NoneType})
2984+
The UNC name of the server on which the event source should be registered.
2985+
If NULL, registers the event source on the local computer.
2986+
source_name: LPCWSTR
2987+
The name of the event source to register.
2988+
[clinic start generated code]*/
2989+
2990+
static HANDLE
2991+
_winapi_RegisterEventSource_impl(PyObject *module, LPCWSTR unc_server_name,
2992+
LPCWSTR source_name)
2993+
/*[clinic end generated code: output=e376c8950a89ae8f input=ee83ab132b89b99c]*/
2994+
{
2995+
HANDLE handle;
2996+
2997+
Py_BEGIN_ALLOW_THREADS
2998+
handle = RegisterEventSource(unc_server_name, source_name);
2999+
Py_END_ALLOW_THREADS
3000+
3001+
if (handle == NULL) {
3002+
PyErr_SetFromWindowsErr(0);
3003+
return INVALID_HANDLE_VALUE;
3004+
}
3005+
3006+
return handle;
3007+
}
3008+
3009+
/*[clinic input]
3010+
_winapi.DeregisterEventSource
3011+
3012+
handle: HANDLE
3013+
The handle to the event log to be deregistered.
3014+
[clinic start generated code]*/
3015+
3016+
static PyObject *
3017+
_winapi_DeregisterEventSource_impl(PyObject *module, HANDLE handle)
3018+
/*[clinic end generated code: output=7387ff34c7358bce input=07d42083b03ba7b0]*/
3019+
{
3020+
BOOL success;
3021+
3022+
Py_BEGIN_ALLOW_THREADS
3023+
success = DeregisterEventSource(handle);
3024+
Py_END_ALLOW_THREADS
3025+
3026+
if (!success)
3027+
return PyErr_SetFromWindowsErr(0);
3028+
3029+
Py_RETURN_NONE;
3030+
}
3031+
29803032

29813033
static PyMethodDef winapi_functions[] = {
29823034
_WINAPI_CLOSEHANDLE_METHODDEF
@@ -2989,6 +3041,7 @@ static PyMethodDef winapi_functions[] = {
29893041
_WINAPI_CREATEPIPE_METHODDEF
29903042
_WINAPI_CREATEPROCESS_METHODDEF
29913043
_WINAPI_CREATEJUNCTION_METHODDEF
3044+
_WINAPI_DEREGISTEREVENTSOURCE_METHODDEF
29923045
_WINAPI_DUPLICATEHANDLE_METHODDEF
29933046
_WINAPI_EXITPROCESS_METHODDEF
29943047
_WINAPI_GETCURRENTPROCESS_METHODDEF
@@ -3005,6 +3058,7 @@ static PyMethodDef winapi_functions[] = {
30053058
_WINAPI_OPENMUTEXW_METHODDEF
30063059
_WINAPI_OPENPROCESS_METHODDEF
30073060
_WINAPI_PEEKNAMEDPIPE_METHODDEF
3061+
_WINAPI_REGISTEREVENTSOURCE_METHODDEF
30083062
_WINAPI_LCMAPSTRINGEX_METHODDEF
30093063
_WINAPI_READFILE_METHODDEF
30103064
_WINAPI_RELEASEMUTEX_METHODDEF

Modules/clinic/_winapi.c.h

Lines changed: 158 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)