Ignore:
File:
1 edited

Legend:

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

    r6d5e378 rdf2e621c  
    5858visualizer_t *graph_alloc_visualizer(void)
    5959{
    60         visualizer_t *vs = (visualizer_t *) malloc(sizeof(visualizer_t));
    61         if (vs == NULL) {
    62                 return NULL;
    63         }
    64        
    65         return vs;
     60        return ((visualizer_t *) malloc(sizeof(visualizer_t)));
    6661}
    6762
     
    6964{
    7065        // TODO
    71         renderer_t *rnd = (renderer_t *) malloc(sizeof(renderer_t));
    72         if (rnd == NULL) {
    73                 return NULL;
    74         }
    75 
    76         return rnd;
     66        return ((renderer_t *) malloc(sizeof(renderer_t)));
    7767}
    7868
     
    9888int graph_register_visualizer(visualizer_t *vs)
    9989{
    100         int rc = EOK;
    101        
    10290        char node[LOC_NAME_MAXLEN + 1];
    10391        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    10492            namespace_idx, VISUALIZER_NAME, visualizer_idx++);
    105 
     93       
    10694        category_id_t cat;
    107         rc = loc_category_get_id("visualizer", &cat, 0);
    108         if (rc != EOK) {
     95        int rc = loc_category_get_id("visualizer", &cat, 0);
     96        if (rc != EOK)
    10997                return rc;
    110         }
    111 
     98       
    11299        rc = loc_service_register(node, &vs->reg_svc_handle);
    113         if (rc != EOK) {
     100        if (rc != EOK)
    114101                return rc;
    115         }
    116 
     102       
    117103        rc = loc_service_add_to_cat(vs->reg_svc_handle, cat);
    118104        if (rc != EOK) {
     
    120106                return rc;
    121107        }
    122 
     108       
    123109        fibril_mutex_lock(&visualizer_list_mtx);
    124110        list_append(&vs->link, &visualizer_list);
    125111        fibril_mutex_unlock(&visualizer_list_mtx);
    126 
     112       
    127113        return rc;
    128114}
     
    130116int graph_register_renderer(renderer_t *rnd)
    131117{
    132         int rc = EOK;
    133 
    134118        char node[LOC_NAME_MAXLEN + 1];
    135119        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    136120            namespace_idx, RENDERER_NAME, renderer_idx++);
    137 
     121       
    138122        category_id_t cat;
    139         rc = loc_category_get_id("renderer", &cat, 0);
    140         if (rc != EOK) {
     123        int rc = loc_category_get_id("renderer", &cat, 0);
     124        if (rc != EOK)
    141125                return rc;
    142         }
    143 
     126       
    144127        rc = loc_service_register(node, &rnd->reg_svc_handle);
    145         if (rc != EOK) {
     128        if (rc != EOK)
    146129                return rc;
    147         }
    148 
     130       
    149131        rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat);
    150132        if (rc != EOK) {
     
    152134                return rc;
    153135        }
    154 
     136       
    155137        fibril_mutex_lock(&renderer_list_mtx);
    156138        list_append(&rnd->link, &renderer_list);
    157139        fibril_mutex_unlock(&renderer_list_mtx);
    158 
     140       
    159141        return rc;
    160142}
     
    163145{
    164146        visualizer_t *vs = NULL;
    165 
     147       
    166148        fibril_mutex_lock(&visualizer_list_mtx);
    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         }
     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       
    174157        fibril_mutex_unlock(&visualizer_list_mtx);
    175 
     158       
    176159        return vs;
    177160}
     
    180163{
    181164        renderer_t *rnd = NULL;
    182 
     165       
    183166        fibril_mutex_lock(&renderer_list_mtx);
    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         }
     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       
    191175        fibril_mutex_unlock(&renderer_list_mtx);
    192 
     176       
    193177        return rnd;
    194178}
     
    196180int graph_unregister_visualizer(visualizer_t *vs)
    197181{
    198         int rc = EOK;
    199 
    200182        fibril_mutex_lock(&visualizer_list_mtx);
    201         rc = loc_service_unregister(vs->reg_svc_handle);
     183        int rc = loc_service_unregister(vs->reg_svc_handle);
    202184        list_remove(&vs->link);
    203185        fibril_mutex_unlock(&visualizer_list_mtx);
    204 
     186       
    205187        return rc;
    206188}
     
    208190int graph_unregister_renderer(renderer_t *rnd)
    209191{
    210         int rc = EOK;
    211 
    212192        fibril_mutex_lock(&renderer_list_mtx);
    213         rc = loc_service_unregister(rnd->reg_svc_handle);
     193        int rc = loc_service_unregister(rnd->reg_svc_handle);
    214194        list_remove(&rnd->link);
    215195        fibril_mutex_unlock(&renderer_list_mtx);
    216 
     196       
    217197        return rc;
    218198}
     
    227207        assert(vs->cells.data == NULL);
    228208        assert(vs->dev_ctx == NULL);
    229 
     209       
    230210        free(vs);
    231211}
     
    235215        // TODO
    236216        assert(atomic_get(&rnd->ref_cnt) == 0);
    237 
     217       
    238218        free(rnd);
    239219}
     
    244224        int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
    245225        async_exchange_end(exch);
    246 
     226       
    247227        return ret;
    248228}
     
    253233        int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
    254234        async_exchange_end(exch);
    255 
     235       
    256236        async_hangup(sess);
    257 
     237       
    258238        return ret;
    259239}
     
    275255                }
    276256        }
    277 
     257       
    278258        /* Driver might also deallocate resources for the current mode. */
    279259        int rc = vs->ops.yield(vs);
    280 
     260       
    281261        /* Now that the driver was given a chance to deallocate resources,
    282262         * current mode can be unset. */
    283         if (vs->mode_set) {
     263        if (vs->mode_set)
    284264                vs->mode_set = false;
    285         }
    286 
     265       
    287266        async_answer_0(iid, rc);
    288267}
     
    290269static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    291270{
     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       
    292280        fibril_mutex_lock(&vs->mode_mtx);
    293281        link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
    294 
     282       
    295283        if (link != NULL) {
    296284                vslmode_list_element_t *mode_elem =
    297285                    list_get_instance(link, vslmode_list_element_t, link);
    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);
     286               
     287                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     288                async_answer_0(iid, rc);
    315289        } else {
     290                async_answer_0(callid, ENOENT);
    316291                async_answer_0(iid, ENOENT);
    317292        }
     293       
     294        fibril_mutex_unlock(&vs->mode_mtx);
    318295}
    319296
    320297static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    321298{
     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       
    322308        fibril_mutex_lock(&vs->mode_mtx);
    323309        vslmode_list_element_t *mode_elem = NULL;
    324         list_foreach(vs->modes, link) {
    325                 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
     310       
     311        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    326312                if (cur->mode.index == vs->def_mode_idx) {
    327313                        mode_elem = cur;
     
    329315                }
    330316        }
    331 
    332         vslmode_t mode;
     317       
    333318        if (mode_elem != NULL) {
    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);
     319                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     320                async_answer_0(iid, rc);
    350321        } else {
    351322                fibril_mutex_unlock(&vs->mode_mtx);
     323                async_answer_0(callid, ENOENT);
    352324                async_answer_0(iid, ENOENT);
    353325        }
     326       
     327        fibril_mutex_unlock(&vs->mode_mtx);
    354328}
    355329
    356330static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    357331{
     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       
    358341        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                 }
    366342                int rc = async_data_read_finalize(callid, &vs->cur_mode, len);
    367                 if (rc != EOK) {
    368                         async_answer_0(iid, ENOMEM);
    369                         return;
    370                 }
    371 
    372                 async_answer_0(iid, EOK);
     343                async_answer_0(iid, rc);
    373344        } else {
     345                async_answer_0(callid, ENOENT);
    374346                async_answer_0(iid, ENOENT);
    375347        }
     
    378350static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    379351{
     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       
    380361        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    381 
     362       
    382363        fibril_mutex_lock(&vs->mode_mtx);
    383364        vslmode_list_element_t *mode_elem = NULL;
    384         list_foreach(vs->modes, link) {
    385                 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
     365       
     366        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    386367                if (cur->mode.index == mode_idx) {
    387368                        mode_elem = cur;
     
    389370                }
    390371        }
    391 
    392         vslmode_t mode;
     372       
    393373        if (mode_elem != NULL) {
    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);
     374                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     375                async_answer_0(iid, rc);
    410376        } else {
    411                 fibril_mutex_unlock(&vs->mode_mtx);
     377                async_answer_0(callid, ENOENT);
    412378                async_answer_0(iid, ENOENT);
    413379        }
     380       
     381        fibril_mutex_unlock(&vs->mode_mtx);
    414382}
    415383
    416384static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    417385{
    418         int rc = EOK;
    419 
     386        ipc_callid_t callid;
     387        size_t size;
     388        unsigned int flags;
     389       
     390        /* Retrieve the shared cell storage for the new mode. */
     391        if (!async_share_out_receive(&callid, &size, &flags)) {
     392                async_answer_0(callid, EREFUSED);
     393                async_answer_0(iid, EREFUSED);
     394                return;
     395        }
     396       
    420397        /* Retrieve mode index and version. */
    421398        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    422399        sysarg_t mode_version = IPC_GET_ARG2(*icall);
    423 
     400       
    424401        /* Find mode in the list. */
    425402        fibril_mutex_lock(&vs->mode_mtx);
    426403        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);
     404       
     405        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    429406                if (cur->mode.index == mode_idx) {
    430407                        mode_elem = cur;
     
    432409                }
    433410        }
    434 
     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       
    435419        /* 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 
     420        vslmode_t new_mode = mode_elem->mode;
     421        fibril_mutex_unlock(&vs->mode_mtx);
     422       
    446423        /* Check whether the mode is still up-to-date. */
    447424        if (new_mode.version != mode_version) {
     425                async_answer_0(callid, EINVAL);
    448426                async_answer_0(iid, EINVAL);
    449427                return;
    450428        }
    451 
    452         ipc_callid_t callid;
    453         size_t size;
    454         unsigned int flags;
    455 
    456         /* Retrieve the shared cell storage for the new mode. */
    457         if (!async_share_out_receive(&callid, &size, &flags)) {
    458                 async_answer_0(iid, EINVAL);
    459                 return;
    460         }
     429       
    461430        void *new_cell_storage;
    462         rc = async_share_out_finalize(callid, &new_cell_storage);
     431        int rc = async_share_out_finalize(callid, &new_cell_storage);
    463432        if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
    464433                async_answer_0(iid, ENOMEM);
    465434                return;
    466435        }
    467 
     436       
    468437        /* Change device internal state. */
    469438        rc = vs->ops.change_mode(vs, new_mode);
    470 
     439       
    471440        /* Device driver could not establish new mode. Rollback. */
    472441        if (rc != EOK) {
     
    475444                return;
    476445        }
    477 
    478         /* Because resources for the new mode were successfully claimed,
    479          * it is finally possible to free resources allocated for the old mode. */
     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         */
    480452        if (vs->mode_set) {
    481453                if (vs->cells.data != NULL) {
     
    484456                }
    485457        }
    486 
     458       
    487459        /* Insert new mode into the visualizer. */
    488460        vs->cells.width = new_mode.screen_width;
     
    491463        vs->cur_mode = new_mode;
    492464        vs->mode_set = true;
    493 
     465       
    494466        async_answer_0(iid, EOK);
    495467}
     
    504476        sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff);
    505477#endif
    506 
     478       
    507479        int rc = vs->ops.handle_damage(vs,
    508480            IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
    509481            IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
    510                 x_offset, y_offset);
     482            x_offset, y_offset);
    511483        async_answer_0(iid, rc);
    512484}
     
    529501        ipc_call_t call;
    530502        ipc_callid_t callid;
    531 
     503       
    532504        /* Claim the visualizer. */
    533505        if (!cas(&vs->ref_cnt, 0, 1)) {
     
    535507                return;
    536508        }
    537 
     509       
    538510        /* Accept the connection. */
    539511        async_answer_0(iid, EOK);
    540 
     512       
    541513        /* Establish callback session. */
    542514        callid = async_get_call(&call);
    543515        vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
    544         if (vs->notif_sess != NULL) {
     516        if (vs->notif_sess != NULL)
    545517                async_answer_0(callid, EOK);
    546         } else {
     518        else
    547519                async_answer_0(callid, ELIMIT);
    548         }
    549 
     520       
    550521        /* Enter command loop. */
    551522        while (true) {
    552523                callid = async_get_call(&call);
    553 
     524               
    554525                if (!IPC_GET_IMETHOD(call)) {
    555526                        async_answer_0(callid, EINVAL);
    556527                        break;
    557528                }
    558 
     529               
    559530                switch (IPC_GET_IMETHOD(call)) {
    560531                case VISUALIZER_CLAIM:
     
    593564                }
    594565        }
    595 
     566       
    596567terminate:
    597568        async_hangup(vs->notif_sess);
     
    604575{
    605576        // TODO
    606 
     577       
    607578        ipc_call_t call;
    608579        ipc_callid_t callid;
    609 
     580       
    610581        /* Accept the connection. */
    611582        atomic_inc(&rnd->ref_cnt);
    612583        async_answer_0(iid, EOK);
    613 
     584       
    614585        /* Enter command loop. */
    615586        while (true) {
    616587                callid = async_get_call(&call);
    617 
     588               
    618589                if (!IPC_GET_IMETHOD(call)) {
    619590                        async_answer_0(callid, EINVAL);
    620591                        break;
    621592                }
    622 
     593               
    623594                switch (IPC_GET_IMETHOD(call)) {
    624595                default:
     
    627598                }
    628599        }
    629 
     600       
    630601terminate:
    631602        atomic_dec(&rnd->ref_cnt);
     
    637608        visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG1(*icall));
    638609        renderer_t *rnd = graph_get_renderer(IPC_GET_ARG1(*icall));
    639 
    640         if (vs != NULL) {
     610       
     611        if (vs != NULL)
    641612                graph_visualizer_connection(vs, iid, icall, arg);
    642         } else if (rnd != NULL) {
     613        else if (rnd != NULL)
    643614                graph_renderer_connection(rnd, iid, icall, arg);
    644         } else {
     615        else
    645616                async_answer_0(iid, ENOENT);
    646         }
    647617}
    648618
Note: See TracChangeset for help on using the changeset viewer.