-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Milestone
Description
The framework should provide .copy() and .clone() methods on every Sensor objects, to make it easier to create new instances with similar properties. Similar means, when cloning an instance, everything except the callbacks should be copied, and the Context should be explicitly set (== clone-to-context).
clonewill invokenewinternally => suitable for duplicating statically alloc'd objectscopywill invokeiniinternally => suitable for duplicating dynamically alloc'd objects
Example: Create 1 Manager; 3 Contexts; and 3 LED objects, each of which handles the same LED hardware (connected to the 3rd pin).
kb_Manager *manager;
kb_rpi2_Context *context1,
*context2,
*context3;
kb_sensors_LED *kb_led1,
*kb_led2; // this is dynamic
MyLED my_led; // this is static
kb_Manager_new(&manager);
kb_rpi2_Context_new(&context1, manager);
kb_rpi2_Context_new(&context2, manager);
kb_rpi2_Context_new(&context3, manager);
kb_sensors_LED_new(&kb_led1, context1, kb_rpi2_PIN3);
kb_sensors_LED_clone(kb_led1, &kb_led2, context2);
kb_sensors_LED_copy(kb_led1, (kb_sensors_LED *)&my_led, context3);
// now after the 'casted' copy, we should set special values to MyLED if needed..
// now we can work with the same LED hardware in the 3 contexts separately