| 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 |
import copy |
| 10 |
|
| 11 |
# C imports |
| 12 |
cimport c_amqp_definitions |
| 13 |
cimport c_amqpvalue |
| 14 |
|
| 15 |
|
| 16 |
_logger = logging.getLogger(__name__) |
| 17 |
|
| 18 |
|
| 19 |
cpdef create_source(): |
| 20 |
source = cSource() |
| 21 |
return source |
| 22 |
|
| 23 |
|
| 24 |
cdef source_factory(c_amqp_definitions.SOURCE_HANDLE c_source): |
| 25 |
source = cSource() |
| 26 |
source.wrap(c_source) |
| 27 |
return source |
| 28 |
|
| 29 |
|
| 30 |
cdef class cSource(StructBase): |
| 31 |
|
| 32 |
cdef c_amqp_definitions.SOURCE_HANDLE _c_value |
| 33 |
|
| 34 |
def __cinit__(self): |
| 35 |
self._c_value = c_amqp_definitions.source_create() |
| 36 |
self._validate() |
| 37 |
|
| 38 |
def __dealloc__(self): |
| 39 |
_logger.debug("Deallocating cSource") |
| 40 |
self.destroy() |
| 41 |
|
| 42 |
cdef _validate(self): |
| 43 |
if <void*>self._c_value is NULL: |
| 44 |
self._memory_error() |
| 45 |
|
| 46 |
cpdef destroy(self): |
| 47 |
if <void*>self._c_value is not NULL: |
| 48 |
_logger.debug("Destroying cSource") |
| 49 |
c_amqp_definitions.source_destroy(self._c_value) |
| 50 |
self._c_value = <c_amqp_definitions.SOURCE_HANDLE>NULL |
| 51 |
|
| 52 |
cdef wrap(self, c_amqp_definitions.SOURCE_HANDLE value): |
| 53 |
self.destroy() |
| 54 |
self._c_value = value |
| 55 |
self._validate() |
| 56 |
|
| 57 |
@property |
| 58 |
def value(self): |
| 59 |
cdef c_amqpvalue.AMQP_VALUE _value |
| 60 |
_value = c_amqp_definitions.amqpvalue_create_source(self._c_value) |
| 61 |
if <void*>_value == NULL: |
| 62 |
self._null_error("Failed to create source.") |
| 63 |
return value_factory(_value) |
| 64 |
|
| 65 |
@property |
| 66 |
def address(self): |
| 67 |
cdef c_amqpvalue.AMQP_VALUE _value |
| 68 |
cdef c_amqpvalue.AMQP_VALUE cloned |
| 69 |
if c_amqp_definitions.source_get_address(self._c_value, &_value) != 0: |
| 70 |
self._value_error("Failed to get source address") |
| 71 |
if <void*>_value == NULL: |
| 72 |
return None |
| 73 |
cloned = c_amqpvalue.amqpvalue_clone(_value) |
| 74 |
if <void*>cloned == NULL: |
| 75 |
return None |
| 76 |
return value_factory(cloned).value |
| 77 |
|
| 78 |
@address.setter |
| 79 |
def address(self, AMQPValue value): |
| 80 |
if c_amqp_definitions.source_set_address(self._c_value, <c_amqpvalue.AMQP_VALUE>value._c_value) != 0: |
| 81 |
self._value_error("Failed to set source address") |
| 82 |
|
| 83 |
@property |
| 84 |
def durable(self): |
| 85 |
cdef c_amqp_definitions.terminus_durability _value |
| 86 |
if c_amqp_definitions.source_get_durable(self._c_value, &_value) != 0: |
| 87 |
self._value_error("Failed to get source durable") |
| 88 |
if <void*>_value == NULL: |
| 89 |
return None |
| 90 |
return _value |
| 91 |
|
| 92 |
@durable.setter |
| 93 |
def durable(self, c_amqp_definitions.terminus_durability value): |
| 94 |
if c_amqp_definitions.source_set_durable(self._c_value, value) != 0: |
| 95 |
self._value_error("Failed to set source durable") |
| 96 |
|
| 97 |
@property |
| 98 |
def expiry_policy(self): |
| 99 |
cdef c_amqp_definitions.terminus_expiry_policy _value |
| 100 |
if c_amqp_definitions.source_get_expiry_policy(self._c_value, &_value) != 0: |
| 101 |
self._value_error("Failed to get source expiry_policy") |
| 102 |
if <void*>_value == NULL: |
| 103 |
return None |
| 104 |
return _value |
| 105 |
|
| 106 |
@expiry_policy.setter |
| 107 |
def expiry_policy(self, c_amqp_definitions.terminus_expiry_policy value): |
| 108 |
if c_amqp_definitions.source_set_expiry_policy(self._c_value, value) != 0: |
| 109 |
self._value_error("Failed to set source expiry_policy") |
| 110 |
|
| 111 |
@property |
| 112 |
def timeout(self): |
| 113 |
cdef c_amqp_definitions.seconds _value |
| 114 |
if c_amqp_definitions.source_get_timeout(self._c_value, &_value) != 0: |
| 115 |
self._value_error("Failed to get source timeout") |
| 116 |
if <void*>_value == NULL: |
| 117 |
return None |
| 118 |
return _value |
| 119 |
|
| 120 |
@timeout.setter |
| 121 |
def timeout(self, c_amqp_definitions.seconds value): |
| 122 |
if c_amqp_definitions.source_set_timeout(self._c_value, value) != 0: |
| 123 |
self._value_error("Failed to set source timeout") |
| 124 |
|
| 125 |
@property |
| 126 |
def dynamic(self): |
| 127 |
cdef bint _value |
| 128 |
if c_amqp_definitions.source_get_dynamic(self._c_value, &_value) != 0: |
| 129 |
self._value_error("Failed to get source dynamic") |
| 130 |
if <void*>_value == NULL: |
| 131 |
return None |
| 132 |
return _value |
| 133 |
|
| 134 |
@dynamic.setter |
| 135 |
def dynamic(self, bint value): |
| 136 |
if c_amqp_definitions.source_set_dynamic(self._c_value, value) != 0: |
| 137 |
self._value_error("Failed to set source dynamic") |
| 138 |
|
| 139 |
@property |
| 140 |
def dynamic_node_properties(self): |
| 141 |
cdef c_amqp_definitions.node_properties _value |
| 142 |
if c_amqp_definitions.source_get_dynamic_node_properties(self._c_value, &_value) != 0: |
| 143 |
self._value_error("Failed to get source dynamic_node_properties") |
| 144 |
if <void*>_value == NULL: |
| 145 |
return None |
| 146 |
return annotations_factory(_value) |
| 147 |
|
| 148 |
@dynamic_node_properties.setter |
| 149 |
def dynamic_node_properties(self, cFields value): |
| 150 |
if c_amqp_definitions.source_set_dynamic_node_properties(self._c_value, <c_amqp_definitions.node_properties>value._c_value) != 0: |
| 151 |
self._value_error("Failed to set source dynamic_node_properties") |
| 152 |
|
| 153 |
@property |
| 154 |
def distribution_mode(self): |
| 155 |
cdef const char* _value |
| 156 |
if c_amqp_definitions.source_get_distribution_mode(self._c_value, &_value) != 0: |
| 157 |
self._value_error("Failed to get source distribution_mode") |
| 158 |
if <void*>_value == NULL: |
| 159 |
return None |
| 160 |
return _value |
| 161 |
|
| 162 |
@distribution_mode.setter |
| 163 |
def distribution_mode(self, const char* value): |
| 164 |
if c_amqp_definitions.source_set_distribution_mode(self._c_value, value) != 0: |
| 165 |
self._value_error("Failed to set source distribution_mode") |
| 166 |
|
| 167 |
@property |
| 168 |
def filter_set(self): |
| 169 |
cdef c_amqp_definitions.filter_set _value |
| 170 |
cdef c_amqp_definitions.filter_set clone |
| 171 |
if c_amqp_definitions.source_get_filter(self._c_value, &_value) != 0: |
| 172 |
self._value_error("Failed to get source filter_set") |
| 173 |
if <void*>_value == NULL: |
| 174 |
return None |
| 175 |
cloned = c_amqpvalue.amqpvalue_clone(_value) |
| 176 |
if <void*>cloned == NULL: |
| 177 |
return None |
| 178 |
return value_factory(cloned) |
| 179 |
|
| 180 |
@filter_set.setter |
| 181 |
def filter_set(self, AMQPValue value): |
| 182 |
if c_amqp_definitions.source_set_filter(self._c_value, <c_amqp_definitions.filter_set>value._c_value) != 0: |
| 183 |
self._value_error("Failed to set source filter_set") |