| 1 |
#------------------------------------------------------------------------- |
| 2 |
# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 |
# Licensed under the MIT License. See License.txt in the project root for |
| 4 |
# license information. |
| 5 |
#-------------------------------------------------------------------------- |
| 6 |
|
| 7 |
# Python imports |
| 8 |
import logging |
| 9 |
|
| 10 |
# C imports |
| 11 |
cimport c_async_operation |
| 12 |
|
| 13 |
|
| 14 |
_logger = logging.getLogger(__name__) |
| 15 |
|
| 16 |
|
| 17 |
cdef class AsyncOperation(StructBase): |
| 18 |
|
| 19 |
cdef c_async_operation.ASYNC_OPERATION_HANDLE _c_value |
| 20 |
|
| 21 |
def __cinit__(self): |
| 22 |
pass |
| 23 |
|
| 24 |
cdef _create(self): |
| 25 |
if <void*>self._c_value is NULL: |
| 26 |
self._memory_error() |
| 27 |
|
| 28 |
cpdef destroy(self): |
| 29 |
if <void*>self._c_value is not NULL: |
| 30 |
_logger.debug("Destroying AsyncOperation") |
| 31 |
c_async_operation.async_operation_destroy(self._c_value) |
| 32 |
self._c_value = <c_async_operation.ASYNC_OPERATION_HANDLE>NULL |
| 33 |
|
| 34 |
cdef wrap(self, c_async_operation.ASYNC_OPERATION_HANDLE value): |
| 35 |
self.destroy() |
| 36 |
self._c_value = value |
| 37 |
self._create() |
| 38 |
|
| 39 |
cpdef cancel(self): |
| 40 |
if c_async_operation.async_operation_cancel(self._c_value) != 0: |
| 41 |
self._value_error() |