Skip to content

Commit

Permalink
Merge pull request zephyrproject-rtos#7 from jimmy-huang/master
Browse files Browse the repository at this point in the history
[BLE] Ignore undefined callback functions if not set
  • Loading branch information
poussa authored Jun 29, 2016
2 parents af152c0 + 5ea41a1 commit e061a69
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions src/zjs_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,47 +591,27 @@ bool zjs_ble_parse_characteristic(jerry_object_t *chrc_obj,

jerry_value_t v_func;
v_func = jerry_get_object_field_value(chrc_obj, "onReadRequest");
if (!jerry_value_is_error(v_func)) {
if (!jerry_value_is_function(v_func)) {
PRINT("onReadRequest callback is not a function\n");
return false;
}
if (jerry_value_is_function(v_func)) {
chrc->read_cb.zjs_cb.js_callback = jerry_acquire_object(jerry_get_object_value(v_func));
}

v_func = jerry_get_object_field_value(chrc_obj, "onWriteRequest");
if (!jerry_value_is_error(v_func)) {
if (!jerry_value_is_function(v_func)) {
PRINT("onWriteRequest callback is not a function\n");
return false;
}
if (jerry_value_is_function(v_func)) {
chrc->write_cb.zjs_cb.js_callback = jerry_acquire_object(jerry_get_object_value(v_func));
}

v_func = jerry_get_object_field_value(chrc_obj, "onSubscribe");
if (!jerry_value_is_error(v_func)) {
if (!jerry_value_is_function(v_func)) {
PRINT("onSubscribe callback is not a function\n");
return false;
}
if (jerry_value_is_function(v_func)) {
chrc->subscribe_cb.zjs_cb.js_callback = jerry_acquire_object(jerry_get_object_value(v_func));
}

v_func = jerry_get_object_field_value(chrc_obj, "onUnsubscribe");
if (!jerry_value_is_error(v_func)) {
if (!jerry_value_is_function(v_func)) {
PRINT("onUnsubscribe callback is not a function\n");
return false;
}
if (jerry_value_is_function(v_func)) {
chrc->unsubscribe_cb.zjs_cb.js_callback = jerry_acquire_object(jerry_get_object_value(v_func));
}

v_func = jerry_get_object_field_value(chrc_obj, "onNotify");
if (!jerry_value_is_error(v_func)) {
if (!jerry_value_is_function(v_func)) {
PRINT("onNotify callback is not a function\n");
return false;
}
if (jerry_value_is_function(v_func)) {
chrc->notify_cb.zjs_cb.js_callback = jerry_acquire_object(jerry_get_object_value(v_func));
}

Expand Down

0 comments on commit e061a69

Please sign in to comment.