-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: add support for creating device after device start up #608
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef OC_DYNAMIC_ALLOCATION
@@ -77,6 +77,32 @@ oc_sec_acl_init(void) | |||
} | |||
} | |||
|
|||
#ifdef OC_HAS_FEATURE_DEVICE_ADD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef OC_DYNAMIC_ALLOCATION
@@ -39,6 +39,10 @@ | |||
#define OC_HAS_FEATURE_PUSH | |||
#endif | |||
|
|||
#if defined(OC_SERVER) && defined(OC_CLIENT) && defined(OC_DYNAMIC_ALLOCATION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.