Changeset c6f00b40 in mainline


Ignore:
Timestamp:
2020-11-01T22:49:05Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ac11ff
Parents:
4df6607
git-author:
Jiri Svoboda <jiri@…> (2020-11-01 22:47:03)
git-committer:
Jiri Svoboda <jiri@…> (2020-11-01 22:49:05)
Message:

Add virtual destructor for UI control

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/uidemo/uidemo.c

    r4df6607 rc6f00b40  
    252252        ui_run(ui);
    253253
    254         ui_fixed_remove(demo.fixed, ui_label_ctl(demo.label));
    255         ui_fixed_remove(demo.fixed, ui_pbutton_ctl(demo.pb1));
    256         ui_fixed_remove(demo.fixed, ui_pbutton_ctl(demo.pb2));
    257 
    258         ui_pbutton_destroy(demo.pb1);
    259         ui_pbutton_destroy(demo.pb2);
    260 
     254        ui_fixed_destroy(demo.fixed);
    261255        ui_window_destroy(window);
    262256        ui_destroy(ui);
  • uspace/lib/ui/include/types/ui/control.h

    r4df6607 rc6f00b40  
    4646/** UI control ops */
    4747typedef struct ui_control_ops {
     48        /** Destroy control */
     49        void (*destroy)(void *);
    4850        /** Paint */
    4951        errno_t (*paint)(void *);
  • uspace/lib/ui/include/ui/control.h

    r4df6607 rc6f00b40  
    4444extern errno_t ui_control_new(ui_control_ops_t *, void *, ui_control_t **);
    4545extern void ui_control_delete(ui_control_t *);
     46extern void ui_control_destroy(ui_control_t *);
    4647extern errno_t ui_control_paint(ui_control_t *);
    4748extern ui_evclaim_t ui_control_pos_event(ui_control_t *, pos_event_t *);
  • uspace/lib/ui/src/control.c

    r4df6607 rc6f00b40  
    6464/** Delete UI control.
    6565 *
     66 * Deletes the base control (not the extended data).
     67 *
    6668 * @param control UI control or @c NULL
    6769 */
     
    7476}
    7577
     78/** Destroy UI control.
     79 *
     80 * Run the virtual control destructor (destroy complete control including
     81 * extended data).
     82 *
     83 * @param control Control
     84 */
     85void ui_control_destroy(ui_control_t *control)
     86{
     87        return control->ops->destroy(control->ext);
     88}
     89
    7690/** Paint UI control.
    7791 *
    78  * @param control Push button
     92 * @param control Control
    7993 * @return EOK on success or an error code
    8094 */
     
    86100/** Deliver position event to UI control.
    87101 *
    88  * @param control Push button
     102 * @param control Control
    89103 * @param pos_event Position event
    90104 * @return @c ui_claimed iff the event is claimed
  • uspace/lib/ui/src/fixed.c

    r4df6607 rc6f00b40  
    6868void ui_fixed_destroy(ui_fixed_t *fixed)
    6969{
     70        ui_fixed_elem_t *elem;
     71        ui_control_t *control;
     72
    7073        if (fixed == NULL)
    7174                return;
    7275
    73         assert(list_empty(&fixed->elem));
     76        elem = ui_fixed_first(fixed);
     77        while (elem != NULL) {
     78                control = elem->control;
     79                ui_fixed_remove(fixed, control);
     80                ui_control_destroy(control);
     81
     82                elem = ui_fixed_first(fixed);
     83        }
     84
    7485        free(fixed);
    7586}
  • uspace/lib/ui/src/label.c

    r4df6607 rc6f00b40  
    4646#include "../private/resource.h"
    4747
     48static void ui_label_ctl_destroy(void *);
    4849static errno_t ui_label_ctl_paint(void *);
    4950static ui_evclaim_t ui_label_ctl_pos_event(void *, pos_event_t *);
     
    5152/** Label control ops */
    5253ui_control_ops_t ui_label_ops = {
     54        .destroy = ui_label_ctl_destroy,
    5355        .paint = ui_label_ctl_paint,
    5456        .pos_event = ui_label_ctl_pos_event
     
    207209}
    208210
    209 /** Paint lable control.
     211/** Destroy label control.
     212 *
     213 * @param arg Argument (ui_label_t *)
     214 */
     215void ui_label_ctl_destroy(void *arg)
     216{
     217        ui_label_t *label = (ui_label_t *) arg;
     218
     219        ui_label_destroy(label);
     220}
     221
     222/** Paint label control.
    210223 *
    211224 * @param arg Argument (ui_label_t *)
  • uspace/lib/ui/src/pbutton.c

    r4df6607 rc6f00b40  
    5454};
    5555
     56static void ui_pbutton_ctl_destroy(void *);
    5657static errno_t ui_pbutton_ctl_paint(void *);
    5758static ui_evclaim_t ui_pbutton_ctl_pos_event(void *, pos_event_t *);
     
    5960/** Push button control ops */
    6061ui_control_ops_t ui_pbutton_ops = {
     62        .destroy = ui_pbutton_ctl_destroy,
    6163        .paint = ui_pbutton_ctl_paint,
    6264        .pos_event = ui_pbutton_ctl_pos_event
     
    418420}
    419421
     422/** Destroy push button control.
     423 *
     424 * @param arg Argument (ui_pbutton_t *)
     425 */
     426void ui_pbutton_ctl_destroy(void *arg)
     427{
     428        ui_pbutton_t *pbutton = (ui_pbutton_t *) arg;
     429
     430        ui_pbutton_destroy(pbutton);
     431}
     432
    420433/** Paint push button control.
    421434 *
  • uspace/lib/ui/test/control.c

    r4df6607 rc6f00b40  
    2121 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    2222 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23 * DATA, OR PROFITS; OR BUSINESS INTvvhhzccgggrERRUPTION) HOWEVER CAUSED AND ON ANY
    2424 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2525 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     
    3939PCUT_TEST_SUITE(control);
    4040
     41static void test_ctl_destroy(void *);
    4142static errno_t test_ctl_paint(void *);
    4243static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    4344
    4445static ui_control_ops_t test_ctl_ops = {
     46        .destroy = test_ctl_destroy,
    4547        .paint = test_ctl_paint,
    4648        .pos_event = test_ctl_pos_event
     
    5355        /** Result code to return */
    5456        errno_t rc;
     57
     58        /** @c true iff destroy was called */
     59        bool destroy;
    5560
    5661        /** @c true iff paint was called */
     
    8085{
    8186        ui_control_delete(NULL);
     87}
     88
     89/** Test sending destroy request to control */
     90PCUT_TEST(destroy)
     91{
     92        ui_control_t *control = NULL;
     93        test_resp_t resp;
     94        errno_t rc;
     95
     96        rc = ui_control_new(&test_ctl_ops, &resp, &control);
     97        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     98        PCUT_ASSERT_NOT_NULL(control);
     99
     100        resp.rc = EOK;
     101        resp.destroy = false;
     102
     103        ui_control_destroy(control);
     104        PCUT_ASSERT_TRUE(resp.destroy);
    82105}
    83106
     
    143166}
    144167
     168static void test_ctl_destroy(void *arg)
     169{
     170        test_resp_t *resp = (test_resp_t *) arg;
     171
     172        resp->destroy = true;
     173}
     174
    145175static errno_t test_ctl_paint(void *arg)
    146176{
  • uspace/lib/ui/test/fixed.c

    r4df6607 rc6f00b40  
    3838PCUT_TEST_SUITE(fixed);
    3939
     40static void test_ctl_destroy(void *);
    4041static errno_t test_ctl_paint(void *);
    4142static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    4243
    4344static ui_control_ops_t test_ctl_ops = {
     45        .destroy = test_ctl_destroy,
    4446        .paint = test_ctl_paint,
    4547        .pos_event = test_ctl_pos_event
     
    5254        /** Result code to return */
    5355        errno_t rc;
    54 
     56        /** @c true iff destroy was called */
     57        bool destroy;
    5558        /** @c true iff paint was called */
    5659        bool paint;
    57 
    5860        /** @c true iff pos_event was called */
    5961        bool pos;
     
    113115
    114116        ui_fixed_destroy(fixed);
     117        ui_control_delete(control);
     118}
     119
     120/** ui_fixed_destroy() delivers destroy request to control */
     121PCUT_TEST(destroy)
     122{
     123        ui_fixed_t *fixed = NULL;
     124        ui_control_t *control;
     125        test_resp_t resp;
     126        errno_t rc;
     127
     128        rc = ui_fixed_create(&fixed);
     129        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     130
     131        rc = ui_control_new(&test_ctl_ops, (void *) &resp, &control);
     132        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     133
     134        rc = ui_fixed_add(fixed, control);
     135        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     136
     137        resp.destroy = false;
     138
     139        ui_fixed_destroy(fixed);
     140        PCUT_ASSERT_TRUE(resp.destroy);
    115141}
    116142
     
    146172        PCUT_ASSERT_TRUE(resp.paint);
    147173
    148         ui_fixed_remove(fixed, control);
    149174        ui_fixed_destroy(fixed);
    150175}
     
    186211        PCUT_ASSERT_INT_EQUALS(resp.pevent.vpos, event.vpos);
    187212
    188         ui_fixed_remove(fixed, control);
    189         ui_fixed_destroy(fixed);
     213        ui_fixed_destroy(fixed);
     214}
     215
     216static void test_ctl_destroy(void *arg)
     217{
     218        test_resp_t *resp = (test_resp_t *) arg;
     219
     220        resp->destroy = true;
    190221}
    191222
Note: See TracChangeset for help on using the changeset viewer.