Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/graph/graph.c

    rf9b2cb4c r6d5e378  
    5858visualizer_t *graph_alloc_visualizer(void)
    5959{
    60         return ((visualizer_t *) malloc(sizeof(visualizer_t)));
     60        visualizer_t *vs = (visualizer_t *) malloc(sizeof(visualizer_t));
     61        if (vs == NULL) {
     62                return NULL;
     63        }
     64       
     65        return vs;
    6166}
    6267
     
    6469{
    6570        // TODO
    66         return ((renderer_t *) malloc(sizeof(renderer_t)));
     71        renderer_t *rnd = (renderer_t *) malloc(sizeof(renderer_t));
     72        if (rnd == NULL) {
     73                return NULL;
     74        }
     75
     76        return rnd;
    6777}
    6878
     
    8898int graph_register_visualizer(visualizer_t *vs)
    8999{
     100        int rc = EOK;
     101       
    90102        char node[LOC_NAME_MAXLEN + 1];
    91103        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    92104            namespace_idx, VISUALIZER_NAME, visualizer_idx++);
    93        
     105
    94106        category_id_t cat;
    95         int rc = loc_category_get_id("visualizer", &cat, 0);
    96         if (rc != EOK)
     107        rc = loc_category_get_id("visualizer", &cat, 0);
     108        if (rc != EOK) {
    97109                return rc;
    98        
     110        }
     111
    99112        rc = loc_service_register(node, &vs->reg_svc_handle);
    100         if (rc != EOK)
     113        if (rc != EOK) {
    101114                return rc;
    102        
     115        }
     116
    103117        rc = loc_service_add_to_cat(vs->reg_svc_handle, cat);
    104118        if (rc != EOK) {
     
    106120                return rc;
    107121        }
    108        
     122
    109123        fibril_mutex_lock(&visualizer_list_mtx);
    110124        list_append(&vs->link, &visualizer_list);
    111125        fibril_mutex_unlock(&visualizer_list_mtx);
    112        
     126
    113127        return rc;
    114128}
     
    116130int graph_register_renderer(renderer_t *rnd)
    117131{
     132        int rc = EOK;
     133
    118134        char node[LOC_NAME_MAXLEN + 1];
    119135        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    120136            namespace_idx, RENDERER_NAME, renderer_idx++);
    121        
     137
    122138        category_id_t cat;
    123         int rc = loc_category_get_id("renderer", &cat, 0);
    124         if (rc != EOK)
     139        rc = loc_category_get_id("renderer", &cat, 0);
     140        if (rc != EOK) {
    125141                return rc;
    126        
     142        }
     143
    127144        rc = loc_service_register(node, &rnd->reg_svc_handle);
    128         if (rc != EOK)
     145        if (rc != EOK) {
    129146                return rc;
    130        
     147        }
     148
    131149        rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat);
    132150        if (rc != EOK) {
     
    134152                return rc;
    135153        }
    136        
     154
    137155        fibril_mutex_lock(&renderer_list_mtx);
    138156        list_append(&rnd->link, &renderer_list);
    139157        fibril_mutex_unlock(&renderer_list_mtx);
    140        
     158
    141159        return rc;
    142160}
     
    145163{
    146164        visualizer_t *vs = NULL;
    147        
     165
    148166        fibril_mutex_lock(&visualizer_list_mtx);
    149        
    150         list_foreach(visualizer_list, link, visualizer_t, vcur) {
    151                 if (vcur->reg_svc_handle == handle) {
    152                         vs = vcur;
    153                         break;
    154                 }
    155         }
    156        
     167        list_foreach(visualizer_list, link) {
     168                visualizer_t *cur = list_get_instance(link, visualizer_t, link);
     169                if (cur->reg_svc_handle == handle) {
     170                        vs = cur;
     171                        break;
     172                }
     173        }
    157174        fibril_mutex_unlock(&visualizer_list_mtx);
    158        
     175
    159176        return vs;
    160177}
     
    163180{
    164181        renderer_t *rnd = NULL;
    165        
     182
    166183        fibril_mutex_lock(&renderer_list_mtx);
    167        
    168         list_foreach(renderer_list, link, renderer_t, rcur) {
    169                 if (rcur->reg_svc_handle == handle) {
    170                         rnd = rcur;
    171                         break;
    172                 }
    173         }
    174        
     184        list_foreach(renderer_list, link) {
     185                renderer_t *cur = list_get_instance(link, renderer_t, link);
     186                if (cur->reg_svc_handle == handle) {
     187                        rnd = cur;
     188                        break;
     189                }
     190        }
    175191        fibril_mutex_unlock(&renderer_list_mtx);
    176        
     192
    177193        return rnd;
    178194}
     
    180196int graph_unregister_visualizer(visualizer_t *vs)
    181197{
     198        int rc = EOK;
     199
    182200        fibril_mutex_lock(&visualizer_list_mtx);
    183         int rc = loc_service_unregister(vs->reg_svc_handle);
     201        rc = loc_service_unregister(vs->reg_svc_handle);
    184202        list_remove(&vs->link);
    185203        fibril_mutex_unlock(&visualizer_list_mtx);
    186        
     204
    187205        return rc;
    188206}
     
    190208int graph_unregister_renderer(renderer_t *rnd)
    191209{
     210        int rc = EOK;
     211
    192212        fibril_mutex_lock(&renderer_list_mtx);
    193         int rc = loc_service_unregister(rnd->reg_svc_handle);
     213        rc = loc_service_unregister(rnd->reg_svc_handle);
    194214        list_remove(&rnd->link);
    195215        fibril_mutex_unlock(&renderer_list_mtx);
    196        
     216
    197217        return rc;
    198218}
     
    207227        assert(vs->cells.data == NULL);
    208228        assert(vs->dev_ctx == NULL);
    209        
     229
    210230        free(vs);
    211231}
     
    215235        // TODO
    216236        assert(atomic_get(&rnd->ref_cnt) == 0);
    217        
     237
    218238        free(rnd);
    219239}
     
    224244        int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
    225245        async_exchange_end(exch);
    226        
     246
    227247        return ret;
    228248}
     
    233253        int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
    234254        async_exchange_end(exch);
    235        
     255
    236256        async_hangup(sess);
    237        
     257
    238258        return ret;
    239259}
     
    255275                }
    256276        }
    257        
     277
    258278        /* Driver might also deallocate resources for the current mode. */
    259279        int rc = vs->ops.yield(vs);
    260        
     280
    261281        /* Now that the driver was given a chance to deallocate resources,
    262282         * current mode can be unset. */
    263         if (vs->mode_set)
     283        if (vs->mode_set) {
    264284                vs->mode_set = false;
    265        
     285        }
     286
    266287        async_answer_0(iid, rc);
    267288}
     
    269290static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    270291{
    271         ipc_callid_t callid;
    272         size_t len;
    273        
    274         if (!async_data_read_receive(&callid, &len)) {
    275                 async_answer_0(callid, EREFUSED);
    276                 async_answer_0(iid, EREFUSED);
    277                 return;
    278         }
    279        
    280292        fibril_mutex_lock(&vs->mode_mtx);
    281293        link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
    282        
     294
    283295        if (link != NULL) {
    284296                vslmode_list_element_t *mode_elem =
    285297                    list_get_instance(link, vslmode_list_element_t, link);
    286                
    287                 int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
    288                 async_answer_0(iid, rc);
     298                vslmode_t mode = mode_elem->mode;
     299                fibril_mutex_unlock(&vs->mode_mtx);
     300
     301                ipc_callid_t callid;
     302                size_t len;
     303
     304        if (!async_data_read_receive(&callid, &len)) {
     305                        async_answer_0(iid, EINVAL);
     306                        return;
     307        }
     308        int rc = async_data_read_finalize(callid, &mode, len);
     309                if (rc != EOK) {
     310                        async_answer_0(iid, ENOMEM);
     311                        return;
     312                }
     313
     314                async_answer_0(iid, EOK);
    289315        } else {
    290                 async_answer_0(callid, ENOENT);
    291316                async_answer_0(iid, ENOENT);
    292317        }
    293        
    294         fibril_mutex_unlock(&vs->mode_mtx);
    295318}
    296319
    297320static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    298321{
    299         ipc_callid_t callid;
    300         size_t len;
    301        
    302         if (!async_data_read_receive(&callid, &len)) {
    303                 async_answer_0(callid, EREFUSED);
    304                 async_answer_0(iid, EREFUSED);
    305                 return;
    306         }
    307        
    308322        fibril_mutex_lock(&vs->mode_mtx);
    309323        vslmode_list_element_t *mode_elem = NULL;
    310        
    311         list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
     324        list_foreach(vs->modes, link) {
     325                vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
    312326                if (cur->mode.index == vs->def_mode_idx) {
    313327                        mode_elem = cur;
     
    315329                }
    316330        }
    317        
     331
     332        vslmode_t mode;
    318333        if (mode_elem != NULL) {
    319                 int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
    320                 async_answer_0(iid, rc);
     334                mode = mode_elem->mode;
     335                fibril_mutex_unlock(&vs->mode_mtx);
     336
     337                ipc_callid_t callid;
     338                size_t len;
     339
     340                if (!async_data_read_receive(&callid, &len)) {
     341                        async_answer_0(iid, EINVAL);
     342                        return;
     343                }
     344                int rc = async_data_read_finalize(callid, &mode, len);
     345                if (rc != EOK) {
     346                        async_answer_0(iid, ENOMEM);
     347                        return;
     348                }
     349                async_answer_0(iid, EOK);
    321350        } else {
    322351                fibril_mutex_unlock(&vs->mode_mtx);
    323                 async_answer_0(callid, ENOENT);
    324352                async_answer_0(iid, ENOENT);
    325353        }
    326        
    327         fibril_mutex_unlock(&vs->mode_mtx);
    328354}
    329355
    330356static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    331357{
    332         ipc_callid_t callid;
    333         size_t len;
    334        
    335         if (!async_data_read_receive(&callid, &len)) {
    336                 async_answer_0(callid, EREFUSED);
    337                 async_answer_0(iid, EREFUSED);
    338                 return;
    339         }
    340        
    341358        if (vs->mode_set) {
     359                ipc_callid_t callid;
     360                size_t len;
     361
     362                if (!async_data_read_receive(&callid, &len)) {
     363                        async_answer_0(iid, EINVAL);
     364                        return;
     365                }
    342366                int rc = async_data_read_finalize(callid, &vs->cur_mode, len);
    343                 async_answer_0(iid, rc);
     367                if (rc != EOK) {
     368                        async_answer_0(iid, ENOMEM);
     369                        return;
     370                }
     371
     372                async_answer_0(iid, EOK);
    344373        } else {
    345                 async_answer_0(callid, ENOENT);
    346374                async_answer_0(iid, ENOENT);
    347375        }
     
    350378static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    351379{
    352         ipc_callid_t callid;
    353         size_t len;
    354        
    355         if (!async_data_read_receive(&callid, &len)) {
    356                 async_answer_0(callid, EREFUSED);
    357                 async_answer_0(iid, EREFUSED);
    358                 return;
    359         }
    360        
    361380        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    362        
     381
    363382        fibril_mutex_lock(&vs->mode_mtx);
    364383        vslmode_list_element_t *mode_elem = NULL;
    365        
    366         list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
     384        list_foreach(vs->modes, link) {
     385                vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
    367386                if (cur->mode.index == mode_idx) {
    368387                        mode_elem = cur;
     
    370389                }
    371390        }
    372        
     391
     392        vslmode_t mode;
    373393        if (mode_elem != NULL) {
    374                 int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
    375                 async_answer_0(iid, rc);
     394                mode = mode_elem->mode;
     395                fibril_mutex_unlock(&vs->mode_mtx);
     396
     397                ipc_callid_t callid;
     398                size_t len;
     399
     400                if (!async_data_read_receive(&callid, &len)) {
     401                        async_answer_0(iid, EINVAL);
     402                        return;
     403                }
     404                int rc = async_data_read_finalize(callid, &mode, len);
     405                if (rc != EOK) {
     406                        async_answer_0(iid, ENOMEM);
     407                        return;
     408                }
     409                async_answer_0(iid, EOK);
    376410        } else {
    377                 async_answer_0(callid, ENOENT);
     411                fibril_mutex_unlock(&vs->mode_mtx);
    378412                async_answer_0(iid, ENOENT);
    379413        }
    380        
    381         fibril_mutex_unlock(&vs->mode_mtx);
    382414}
    383415
    384416static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    385417{
     418        int rc = EOK;
     419
     420        /* Retrieve mode index and version. */
     421        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
     422        sysarg_t mode_version = IPC_GET_ARG2(*icall);
     423
     424        /* Find mode in the list. */
     425        fibril_mutex_lock(&vs->mode_mtx);
     426        vslmode_list_element_t *mode_elem = NULL;
     427        list_foreach(vs->modes, link) {
     428                vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
     429                if (cur->mode.index == mode_idx) {
     430                        mode_elem = cur;
     431                        break;
     432                }
     433        }
     434
     435        /* Extract mode description from the list node. */
     436        vslmode_t new_mode;
     437        if (mode_elem != NULL) {
     438                new_mode = mode_elem->mode;
     439                fibril_mutex_unlock(&vs->mode_mtx);
     440        } else {
     441                fibril_mutex_unlock(&vs->mode_mtx);
     442                async_answer_0(iid, ENOENT);
     443                return;
     444        }
     445
     446        /* Check whether the mode is still up-to-date. */
     447        if (new_mode.version != mode_version) {
     448                async_answer_0(iid, EINVAL);
     449                return;
     450        }
     451
    386452        ipc_callid_t callid;
    387453        size_t size;
    388454        unsigned int flags;
    389        
     455
    390456        /* Retrieve the shared cell storage for the new mode. */
    391457        if (!async_share_out_receive(&callid, &size, &flags)) {
    392                 async_answer_0(callid, EREFUSED);
    393                 async_answer_0(iid, EREFUSED);
    394                 return;
    395         }
    396        
    397         /* Retrieve mode index and version. */
    398         sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    399         sysarg_t mode_version = IPC_GET_ARG2(*icall);
    400        
    401         /* Find mode in the list. */
    402         fibril_mutex_lock(&vs->mode_mtx);
    403         vslmode_list_element_t *mode_elem = NULL;
    404        
    405         list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    406                 if (cur->mode.index == mode_idx) {
    407                         mode_elem = cur;
    408                         break;
    409                 }
    410         }
    411        
    412         if (mode_elem == NULL) {
    413                 fibril_mutex_unlock(&vs->mode_mtx);
    414                 async_answer_0(callid, ENOENT);
    415                 async_answer_0(iid, ENOENT);
    416                 return;
    417         }
    418        
    419         /* Extract mode description from the list node. */
    420         vslmode_t new_mode = mode_elem->mode;
    421         fibril_mutex_unlock(&vs->mode_mtx);
    422        
    423         /* Check whether the mode is still up-to-date. */
    424         if (new_mode.version != mode_version) {
    425                 async_answer_0(callid, EINVAL);
    426458                async_answer_0(iid, EINVAL);
    427459                return;
    428460        }
    429        
    430461        void *new_cell_storage;
    431         int rc = async_share_out_finalize(callid, &new_cell_storage);
     462        rc = async_share_out_finalize(callid, &new_cell_storage);
    432463        if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
    433464                async_answer_0(iid, ENOMEM);
    434465                return;
    435466        }
    436        
     467
    437468        /* Change device internal state. */
    438469        rc = vs->ops.change_mode(vs, new_mode);
    439        
     470
    440471        /* Device driver could not establish new mode. Rollback. */
    441472        if (rc != EOK) {
     
    444475                return;
    445476        }
    446        
    447         /*
    448          * Because resources for the new mode were successfully
    449          * claimed, it is finally possible to free resources
    450          * allocated for the old mode.
    451          */
     477
     478        /* Because resources for the new mode were successfully claimed,
     479         * it is finally possible to free resources allocated for the old mode. */
    452480        if (vs->mode_set) {
    453481                if (vs->cells.data != NULL) {
     
    456484                }
    457485        }
    458        
     486
    459487        /* Insert new mode into the visualizer. */
    460488        vs->cells.width = new_mode.screen_width;
     
    463491        vs->cur_mode = new_mode;
    464492        vs->mode_set = true;
    465        
     493
    466494        async_answer_0(iid, EOK);
    467495}
     
    476504        sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff);
    477505#endif
    478        
     506
    479507        int rc = vs->ops.handle_damage(vs,
    480508            IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
    481509            IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
    482             x_offset, y_offset);
     510                x_offset, y_offset);
    483511        async_answer_0(iid, rc);
    484512}
     
    501529        ipc_call_t call;
    502530        ipc_callid_t callid;
    503        
     531
    504532        /* Claim the visualizer. */
    505533        if (!cas(&vs->ref_cnt, 0, 1)) {
     
    507535                return;
    508536        }
    509        
     537
    510538        /* Accept the connection. */
    511539        async_answer_0(iid, EOK);
    512        
     540
    513541        /* Establish callback session. */
    514542        callid = async_get_call(&call);
    515543        vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
    516         if (vs->notif_sess != NULL)
     544        if (vs->notif_sess != NULL) {
    517545                async_answer_0(callid, EOK);
    518         else
     546        } else {
    519547                async_answer_0(callid, ELIMIT);
    520        
     548        }
     549
    521550        /* Enter command loop. */
    522551        while (true) {
    523552                callid = async_get_call(&call);
    524                
     553
    525554                if (!IPC_GET_IMETHOD(call)) {
    526555                        async_answer_0(callid, EINVAL);
    527556                        break;
    528557                }
    529                
     558
    530559                switch (IPC_GET_IMETHOD(call)) {
    531560                case VISUALIZER_CLAIM:
     
    564593                }
    565594        }
    566        
     595
    567596terminate:
    568597        async_hangup(vs->notif_sess);
     
    575604{
    576605        // TODO
    577        
     606
    578607        ipc_call_t call;
    579608        ipc_callid_t callid;
    580        
     609
    581610        /* Accept the connection. */
    582611        atomic_inc(&rnd->ref_cnt);
    583612        async_answer_0(iid, EOK);
    584        
     613
    585614        /* Enter command loop. */
    586615        while (true) {
    587616                callid = async_get_call(&call);
    588                
     617
    589618                if (!IPC_GET_IMETHOD(call)) {
    590619                        async_answer_0(callid, EINVAL);
    591620                        break;
    592621                }
    593                
     622
    594623                switch (IPC_GET_IMETHOD(call)) {
    595624                default:
     
    598627                }
    599628        }
    600        
     629
    601630terminate:
    602631        atomic_dec(&rnd->ref_cnt);
     
    606635{
    607636        /* Find the visualizer or renderer with the given service ID. */
    608         visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG2(*icall));
    609         renderer_t *rnd = graph_get_renderer(IPC_GET_ARG2(*icall));
    610        
    611         if (vs != NULL)
     637        visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG1(*icall));
     638        renderer_t *rnd = graph_get_renderer(IPC_GET_ARG1(*icall));
     639
     640        if (vs != NULL) {
    612641                graph_visualizer_connection(vs, iid, icall, arg);
    613         else if (rnd != NULL)
     642        } else if (rnd != NULL) {
    614643                graph_renderer_connection(rnd, iid, icall, arg);
    615         else
     644        } else {
    616645                async_answer_0(iid, ENOENT);
     646        }
    617647}
    618648
Note: See TracChangeset for help on using the changeset viewer.