api: add support for creating device after device start up#608
api: add support for creating device after device start up#608Danielius1922 wants to merge 1 commit intomasterfrom
Conversation
|
🎉 Thank you for your code contribution! To guarantee the change/addition is conformant to the OCF Specification, we would like to ask you to execute OCF Conformance Testing of your change ☝️ when your work is ready to be reviewed. ℹ️ To verify your latest change (5bf1f87), label this PR with |
5bf1f87 to
8318832
Compare
8318832 to
de7f098
Compare
|
| if (index > device_count) { | ||
| OC_ERR("designated device index (%" PRIu32 | ||
| ") is bigger than current number of all devices", | ||
| device_count); | ||
| return NULL; | ||
| } | ||
| if (index < device_count) { | ||
| OC_ERR("cannot replace existing device (%" PRIu32 ")", device_count); | ||
| return NULL; | ||
| } |
There was a problem hiding this comment.
This checks are weird against then name of oc_core_add_or_update_device_at_index
Is it just allows you append the device?
| size_t device_count = oc_core_get_num_devices(); | ||
| assert(device_index == device_count - 1); | ||
| if (need_realloc) { | ||
| oc_swupdate_t *sw = | ||
| (oc_swupdate_t *)realloc(g_sw, device_count * sizeof(oc_swupdate_t)); | ||
| if (sw == NULL) { | ||
| oc_abort("Insufficient memory"); | ||
| } | ||
| g_sw = sw; |
| } | ||
| } | ||
|
|
||
| #ifdef OC_HAS_FEATURE_DEVICE_ADD |
| #define OC_HAS_FEATURE_PUSH | ||
| #endif | ||
|
|
||
| #if defined(OC_SERVER) && defined(OC_CLIENT) && defined(OC_DYNAMIC_ALLOCATION) |
There was a problem hiding this comment.
Is it his required to have OC_DYNAMIC_ALLOCATION ?
| if (needs_realloc) { | ||
| size_t device_count = oc_core_get_num_devices(); | ||
| assert(device_index == device_count - 1); | ||
| oc_sec_sdi_t *sdi = | ||
| (oc_sec_sdi_t *)realloc(g_sdi, device_count * sizeof(oc_sec_sdi_t)); | ||
| if (sdi == NULL) { | ||
| oc_abort("Insufficient memory"); | ||
| } | ||
| g_sdi = sdi; | ||
| } else { | ||
| sec_sdi_free(&g_sdi[device_index]); | ||
| } | ||
| #endif /* OC_DYNAMIC_ALLOCATION */ | ||
| memset(&g_sdi[device_index], 0, sizeof(oc_sec_sdi_t)); |
There was a problem hiding this comment.
I saw same pattern at lot's places -> is it possible to move it to generic function ?
void
oc_instantiate_object_at_index(void** array, item_size size_t, index size_t, bool needs_realloc)




No description provided.