Skip to content

Commit 406f5ac

Browse files
authored
Merge pull request #1 from xieqi/master
fix KW issue for class BLEDescriptor, BLECharacteristic and port.c
2 parents d84bb1c + 3c9d16b commit 406f5ac

File tree

6 files changed

+119
-11
lines changed

6 files changed

+119
-11
lines changed

libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,44 @@ BLECharacteristic::BLECharacteristic(BLECharacteristicImp *characteristicImp,
5050
_value_size = characteristicImp->valueSize();
5151
}
5252

53+
BLECharacteristic::BLECharacteristic(const BLECharacteristic& rhs)
54+
{
55+
unsigned char *_value = (unsigned char*)malloc(rhs._value_size);
56+
if (_value)
57+
{
58+
memcpy(_value, rhs._value, rhs._value_size);
59+
_value_size = rhs._value_size;
60+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
61+
_properties = rhs._properties;
62+
_event_handlers = rhs._event_handlers;
63+
_internal = rhs._internal;
64+
_bledev = BLEDevice(&rhs._bledev);
65+
}
66+
}
67+
68+
BLECharacteristic& BLECharacteristic::operator= (const BLECharacteristic& rhs)
69+
{
70+
if (this != &rhs)
71+
{
72+
if (_value)
73+
{
74+
free(_value);
75+
}
76+
_value = (unsigned char*)malloc(rhs._value_size);
77+
if (_value)
78+
{
79+
memcpy(_value, rhs._value, rhs._value_size);
80+
_value_size = rhs._value_size;
81+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
82+
_properties = rhs._properties;
83+
_event_handlers = rhs._event_handlers;
84+
_internal = rhs._internal;
85+
_bledev = BLEDevice(&rhs._bledev);
86+
}
87+
}
88+
return *this;
89+
}
90+
5391
BLECharacteristic::~BLECharacteristic()
5492
{
5593
if (_value)

libraries/BLE/src/BLECharacteristic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class BLECharacteristic: public BLEAttributeWithValue
8484
unsigned char properties,
8585
const char* value);
8686

87+
BLECharacteristic(const BLECharacteristic&);
88+
89+
BLECharacteristic& operator=(const BLECharacteristic&);
90+
8791
virtual ~BLECharacteristic();
8892

8993
/**

libraries/BLE/src/BLEDescriptor.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,40 @@ BLEDescriptor::BLEDescriptor(const char* uuid,
6666
BLEDescriptor(uuid, (const unsigned char*)value, strlen(value))
6767
{}
6868

69+
BLEDescriptor::BLEDescriptor(const BLEDescriptor& rhs)
70+
{
71+
unsigned char *_value = (unsigned char*)malloc(rhs._value_size);
72+
if (_value)
73+
{
74+
memcpy(_value, rhs._value, rhs._value_size);
75+
_value_size = rhs._value_size;
76+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
77+
_properties = rhs._properties;
78+
_bledev = BLEDevice(&rhs._bledev);
79+
}
80+
}
81+
82+
BLEDescriptor& BLEDescriptor::operator= (const BLEDescriptor& rhs)
83+
{
84+
if (this != &rhs)
85+
{
86+
if (_value)
87+
{
88+
free(_value);
89+
}
90+
_value = (unsigned char*)malloc(rhs._value_size);
91+
if (_value)
92+
{
93+
memcpy(_value, rhs._value, rhs._value_size);
94+
_value_size = rhs._value_size;
95+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
96+
_properties = rhs._properties;
97+
_bledev = BLEDevice(&rhs._bledev);
98+
}
99+
}
100+
return *this;
101+
}
102+
69103
BLEDescriptor::~BLEDescriptor()
70104
{
71105
if (_value)

libraries/BLE/src/BLEDescriptor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class BLEDescriptor
3232
BLEDescriptor(const char* uuid, const char* value); // create a descriptor the specified uuid and string value
3333

3434
BLEDescriptor(BLEDescriptorImp* descriptorImp, const BLEDevice *bleDev);
35+
BLEDescriptor(const BLEDescriptor&);
36+
BLEDescriptor& operator=(const BLEDescriptor&);
3537

3638
virtual ~BLEDescriptor();
3739

libraries/BLE/src/internal/BLEProfileManager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,12 @@ void BLEProfileManager::serviceDiscoverComplete(const BLEDevice &bledevice)
772772
servicePrevImp->setEndHandle(serviceCurImp->startHandle() - 1);
773773
}
774774

775-
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
775+
if (servicePrevImp)
776+
{
777+
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
778+
}
776779
servicePrevImp = serviceCurImp;
777-
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
780+
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
778781
node = node->next;
779782
}
780783
return;

system/libarc32_arduino101/framework/src/infra/port.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ static struct port * get_port(uint16_t port_id)
129129
void port_set_queue(uint16_t port_id, void * queue)
130130
{
131131
struct port * p = get_port(port_id);
132-
p->queue = queue;
132+
if (p)
133+
{
134+
p->queue = queue;
135+
}
133136
}
134137

135138
#ifdef CONFIG_INFRA_IS_MASTER
@@ -176,8 +179,11 @@ uint16_t port_alloc(void *queue)
176179
void port_set_handler(uint16_t port_id, void (*handler)(struct message*, void*), void *param)
177180
{
178181
struct port * port = get_port(port_id);
179-
port->handle_message = handler;
180-
port->handle_param = param;
182+
if (port)
183+
{
184+
port->handle_message = handler;
185+
port->handle_param = param;
186+
}
181187
}
182188

183189
struct message * message_alloc(int size, OS_ERR_TYPE * err)
@@ -193,27 +199,40 @@ struct message * message_alloc(int size, OS_ERR_TYPE * err)
193199
void port_process_message(struct message * msg)
194200
{
195201
struct port * p = get_port(msg->dst_port_id);
196-
if (p->handle_message != NULL) {
202+
if (p && p->handle_message != NULL) {
197203
p->handle_message(msg, p->handle_param);
198204
}
199205
}
200206

201207
void port_set_cpu_id(uint16_t port_id, uint8_t cpu_id)
202208
{
203209
struct port * p = get_port(port_id);
204-
p->cpu_id = cpu_id;
210+
if (p)
211+
{
212+
p->cpu_id = cpu_id;
213+
}
205214
}
206215

207216
void port_set_port_id(uint16_t port_id)
208217
{
209218
struct port * p = get_port(port_id);
210-
p->id = port_id;
219+
if (p)
220+
{
221+
p->id = port_id;
222+
}
211223
}
212224

213225
uint8_t port_get_cpu_id(uint16_t port_id)
214226
{
215227
struct port * p = get_port(port_id);
216-
return p->cpu_id;
228+
if (p)
229+
{
230+
return p->cpu_id;
231+
}
232+
else
233+
{
234+
return 0;
235+
}
217236
}
218237

219238
#ifdef INFRA_MULTI_CPU_SUPPORT
@@ -258,7 +277,7 @@ int port_send_message(struct message * message)
258277
pr_info(LOG_MODULE_MAIN, "Sending message %p to port %p(q:%p) ret: %d", message, port, port->queue, err);
259278
#endif
260279
struct port *src_port = get_port(MESSAGE_SRC(message));
261-
if (src_port->cpu_id == get_cpu_id()) {
280+
if (src_port && src_port->cpu_id == get_cpu_id()) {
262281
/* We bypass the software queue here and process directly
263282
* due to lack of background thread on this implementation
264283
*/
@@ -278,6 +297,10 @@ int port_send_message(struct message * message)
278297
void message_free(struct message * msg)
279298
{
280299
struct port * port = get_port(MESSAGE_SRC(msg));
300+
if (!port)
301+
{
302+
return;
303+
}
281304
pr_debug(LOG_MODULE_MAIN, "free message %p: port %p[%d] this %d id %d",
282305
msg, port, port->cpu_id, get_cpu_id(), MESSAGE_SRC(msg));
283306
if (port->cpu_id == get_cpu_id()) {
@@ -291,8 +314,12 @@ void message_free(struct message * msg)
291314

292315
int port_send_message(struct message * msg)
293316
{
294-
struct port * port = get_port(MESSAGE_DST(msg));
295317
OS_ERR_TYPE err;
318+
struct port * port = get_port(MESSAGE_DST(msg));
319+
if (!port)
320+
{
321+
return E_OS_ERR_NO_MEMORY;
322+
}
296323
if (src_port->cpu_id == get_cpu_id()) {
297324
/* We bypass the software queue here and process directly
298325
* due to lack of background thread on this implementation

0 commit comments

Comments
 (0)