@@ -94,42 +94,38 @@ BLECharacteristic& BLECharacteristic::operator= (const BLECharacteristic& rhs)
94
94
return *this ;
95
95
}
96
96
97
- BLECharacteristic::BLECharacteristic (const BLECharacteristic& rhs)
98
- {
99
- unsigned char *_value = (unsigned char *)malloc (rhs._value_size );
100
- if (_value)
101
- {
102
- memcpy (_value, rhs._value , rhs._value_size );
103
- _value_size = rhs._value_size ;
104
- memcpy (_uuid_cstr, rhs._uuid_cstr , sizeof (_uuid_cstr));
105
- _properties = rhs._properties ;
106
- _event_handlers = rhs._event_handlers ;
107
- _internal = rhs._internal ;
108
- _bledev = BLEDevice (&rhs._bledev );
109
- }
110
- }
111
-
112
- BLECharacteristic& BLECharacteristic::operator = (const BLECharacteristic& rhs)
97
+ BLECharacteristic::BLECharacteristic (const BLECharacteristic& rhs):
98
+ _value(NULL ),
99
+ _event_handlers(NULL )
113
100
{
114
- if (this != &rhs)
101
+ _chrc_local_imp = NULL ; // Not copy
102
+ _value_size = rhs._value_size ;
103
+ _internal = rhs._internal ;
104
+ _bledev = BLEDevice (&rhs._bledev );
105
+ memcpy (_uuid_cstr, rhs._uuid_cstr , sizeof (_uuid_cstr));
106
+ _properties = rhs._properties ;
107
+
108
+ if (rhs._internal == NULL )
115
109
{
116
- if (_value)
110
+ if (rhs. _value != NULL )
117
111
{
118
- free (_value);
112
+ _value = (unsigned char *)malloc (rhs._value_size );
113
+ if (NULL != _value)
114
+ {
115
+ memcpy (_value, rhs._value , rhs._value_size );
116
+ }
117
+
119
118
}
120
- _value = ( unsigned char *) malloc (rhs. _value_size );
121
- if (_value )
119
+
120
+ if (rhs. _event_handlers != NULL )
122
121
{
123
- memcpy (_value, rhs._value , rhs._value_size );
124
- _value_size = rhs._value_size ;
125
- memcpy (_uuid_cstr, rhs._uuid_cstr , sizeof (_uuid_cstr));
126
- _properties = rhs._properties ;
127
- _event_handlers = rhs._event_handlers ;
128
- _internal = rhs._internal ;
129
- _bledev = BLEDevice (&rhs._bledev );
122
+ _event_handlers = (BLECharacteristicEventHandler*)malloc (sizeof (BLECharacteristicEventHandler) * BLECharacteristicEventLast);
123
+
124
+ if (NULL != _event_handlers)
125
+ memcpy (_event_handlers, rhs._event_handlers , (sizeof (BLECharacteristicEventHandler) * BLECharacteristicEventLast));
130
126
}
131
127
}
132
- return *this ;
128
+ // return *this;
133
129
}
134
130
135
131
BLECharacteristic::~BLECharacteristic ()
@@ -194,6 +190,50 @@ BLECharacteristic::operator bool() const
194
190
return (strlen (_uuid_cstr) > 3 );
195
191
}
196
192
193
+ BLECharacteristic& BLECharacteristic::operator = (const BLECharacteristic& chrc)
194
+ {
195
+ if (this != &chrc)
196
+ {
197
+ memcpy (_uuid_cstr, chrc._uuid_cstr , sizeof (_uuid_cstr));
198
+ _bledev.setAddress (*chrc._bledev .bt_le_address ());
199
+ _internal = chrc._internal ;
200
+ _chrc_local_imp = NULL ; // Not copy
201
+ _properties = chrc._properties ;
202
+
203
+ if (_value_size < chrc._value_size )
204
+ {
205
+ _value_size = chrc._value_size ;
206
+ if (NULL != _value)
207
+ {
208
+ free (_value);
209
+ _value = NULL ;
210
+ }
211
+ }
212
+
213
+ if (_internal == NULL )
214
+ {
215
+ if (chrc._value != NULL )
216
+ {
217
+ if (NULL == _value)
218
+ _value = (unsigned char *) malloc (_value_size);
219
+
220
+ if (NULL != _value)
221
+ memcpy (_value, chrc._value , chrc._value_size );
222
+ }
223
+
224
+ if (chrc._event_handlers != NULL )
225
+ {
226
+ if (NULL == _event_handlers)
227
+ _event_handlers = (BLECharacteristicEventHandler*)malloc (sizeof (BLECharacteristicEventHandler) * BLECharacteristicEventLast);
228
+
229
+ if (NULL != _event_handlers)
230
+ memcpy (_event_handlers, chrc._event_handlers , (sizeof (BLECharacteristicEventHandler) * BLECharacteristicEventLast));
231
+ }
232
+
233
+ }
234
+ }
235
+ return *this ;
236
+ }
197
237
198
238
byte BLECharacteristic::operator [] (int offset) const
199
239
{
0 commit comments