Changeset af2a76c in mainline for uspace/lib/graph/graph.c


Ignore:
Timestamp:
2014-07-13T17:25:15Z (10 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7493e7b
Parents:
b8e75319 (diff), 78192cc7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    rb8e75319 raf2a76c  
    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);
     149       
    167150        list_foreach(visualizer_list, link, visualizer_t, vcur) {
    168151                if (vcur->reg_svc_handle == handle) {
     
    171154                }
    172155        }
     156       
    173157        fibril_mutex_unlock(&visualizer_list_mtx);
    174 
     158       
    175159        return vs;
    176160}
     
    179163{
    180164        renderer_t *rnd = NULL;
    181 
     165       
    182166        fibril_mutex_lock(&renderer_list_mtx);
     167       
    183168        list_foreach(renderer_list, link, renderer_t, rcur) {
    184169                if (rcur->reg_svc_handle == handle) {
     
    187172                }
    188173        }
     174       
    189175        fibril_mutex_unlock(&renderer_list_mtx);
    190 
     176       
    191177        return rnd;
    192178}
     
    194180int graph_unregister_visualizer(visualizer_t *vs)
    195181{
    196         int rc = EOK;
    197 
    198182        fibril_mutex_lock(&visualizer_list_mtx);
    199         rc = loc_service_unregister(vs->reg_svc_handle);
     183        int rc = loc_service_unregister(vs->reg_svc_handle);
    200184        list_remove(&vs->link);
    201185        fibril_mutex_unlock(&visualizer_list_mtx);
    202 
     186       
    203187        return rc;
    204188}
     
    206190int graph_unregister_renderer(renderer_t *rnd)
    207191{
    208         int rc = EOK;
    209 
    210192        fibril_mutex_lock(&renderer_list_mtx);
    211         rc = loc_service_unregister(rnd->reg_svc_handle);
     193        int rc = loc_service_unregister(rnd->reg_svc_handle);
    212194        list_remove(&rnd->link);
    213195        fibril_mutex_unlock(&renderer_list_mtx);
    214 
     196       
    215197        return rc;
    216198}
     
    225207        assert(vs->cells.data == NULL);
    226208        assert(vs->dev_ctx == NULL);
    227 
     209       
    228210        free(vs);
    229211}
     
    233215        // TODO
    234216        assert(atomic_get(&rnd->ref_cnt) == 0);
    235 
     217       
    236218        free(rnd);
    237219}
     
    242224        int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
    243225        async_exchange_end(exch);
    244 
     226       
    245227        return ret;
    246228}
     
    251233        int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
    252234        async_exchange_end(exch);
    253 
     235       
    254236        async_hangup(sess);
    255 
     237       
    256238        return ret;
    257239}
     
    273255                }
    274256        }
    275 
     257       
    276258        /* Driver might also deallocate resources for the current mode. */
    277259        int rc = vs->ops.yield(vs);
    278 
     260       
    279261        /* Now that the driver was given a chance to deallocate resources,
    280262         * current mode can be unset. */
    281         if (vs->mode_set) {
     263        if (vs->mode_set)
    282264                vs->mode_set = false;
    283         }
    284 
     265       
    285266        async_answer_0(iid, rc);
    286267}
     
    288269static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    289270{
     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       
    290280        fibril_mutex_lock(&vs->mode_mtx);
    291281        link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
    292 
     282       
    293283        if (link != NULL) {
    294284                vslmode_list_element_t *mode_elem =
    295285                    list_get_instance(link, vslmode_list_element_t, link);
    296                 vslmode_t mode = mode_elem->mode;
    297                 fibril_mutex_unlock(&vs->mode_mtx);
    298 
    299                 ipc_callid_t callid;
    300                 size_t len;
    301 
    302         if (!async_data_read_receive(&callid, &len)) {
    303                         async_answer_0(iid, EINVAL);
    304                         return;
    305         }
    306         int rc = async_data_read_finalize(callid, &mode, len);
    307                 if (rc != EOK) {
    308                         async_answer_0(iid, ENOMEM);
    309                         return;
    310                 }
    311 
    312                 async_answer_0(iid, EOK);
     286               
     287                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     288                async_answer_0(iid, rc);
    313289        } else {
     290                async_answer_0(callid, ENOENT);
    314291                async_answer_0(iid, ENOENT);
    315292        }
     293       
     294        fibril_mutex_unlock(&vs->mode_mtx);
    316295}
    317296
    318297static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    319298{
     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       
    320308        fibril_mutex_lock(&vs->mode_mtx);
    321309        vslmode_list_element_t *mode_elem = NULL;
     310       
    322311        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    323312                if (cur->mode.index == vs->def_mode_idx) {
     
    326315                }
    327316        }
    328 
    329         vslmode_t mode;
     317       
    330318        if (mode_elem != NULL) {
    331                 mode = mode_elem->mode;
    332                 fibril_mutex_unlock(&vs->mode_mtx);
    333 
    334                 ipc_callid_t callid;
    335                 size_t len;
    336 
    337                 if (!async_data_read_receive(&callid, &len)) {
    338                         async_answer_0(iid, EINVAL);
    339                         return;
    340                 }
    341                 int rc = async_data_read_finalize(callid, &mode, len);
    342                 if (rc != EOK) {
    343                         async_answer_0(iid, ENOMEM);
    344                         return;
    345                 }
    346                 async_answer_0(iid, EOK);
     319                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     320                async_answer_0(iid, rc);
    347321        } else {
    348322                fibril_mutex_unlock(&vs->mode_mtx);
     323                async_answer_0(callid, ENOENT);
    349324                async_answer_0(iid, ENOENT);
    350325        }
     326       
     327        fibril_mutex_unlock(&vs->mode_mtx);
    351328}
    352329
    353330static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    354331{
     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       
    355341        if (vs->mode_set) {
    356                 ipc_callid_t callid;
    357                 size_t len;
    358 
    359                 if (!async_data_read_receive(&callid, &len)) {
    360                         async_answer_0(iid, EINVAL);
    361                         return;
    362                 }
    363342                int rc = async_data_read_finalize(callid, &vs->cur_mode, len);
    364                 if (rc != EOK) {
    365                         async_answer_0(iid, ENOMEM);
    366                         return;
    367                 }
    368 
    369                 async_answer_0(iid, EOK);
     343                async_answer_0(iid, rc);
    370344        } else {
     345                async_answer_0(callid, ENOENT);
    371346                async_answer_0(iid, ENOENT);
    372347        }
     
    375350static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    376351{
     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       
    377361        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    378 
     362       
    379363        fibril_mutex_lock(&vs->mode_mtx);
    380364        vslmode_list_element_t *mode_elem = NULL;
     365       
    381366        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    382367                if (cur->mode.index == mode_idx) {
     
    385370                }
    386371        }
    387 
    388         vslmode_t mode;
     372       
    389373        if (mode_elem != NULL) {
    390                 mode = mode_elem->mode;
    391                 fibril_mutex_unlock(&vs->mode_mtx);
    392 
    393                 ipc_callid_t callid;
    394                 size_t len;
    395 
    396                 if (!async_data_read_receive(&callid, &len)) {
    397                         async_answer_0(iid, EINVAL);
    398                         return;
    399                 }
    400                 int rc = async_data_read_finalize(callid, &mode, len);
    401                 if (rc != EOK) {
    402                         async_answer_0(iid, ENOMEM);
    403                         return;
    404                 }
    405                 async_answer_0(iid, EOK);
     374                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     375                async_answer_0(iid, rc);
    406376        } else {
    407                 fibril_mutex_unlock(&vs->mode_mtx);
     377                async_answer_0(callid, ENOENT);
    408378                async_answer_0(iid, ENOENT);
    409379        }
     380       
     381        fibril_mutex_unlock(&vs->mode_mtx);
    410382}
    411383
    412384static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    413385{
    414         int rc = EOK;
    415 
     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       
    416397        /* Retrieve mode index and version. */
    417398        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    418399        sysarg_t mode_version = IPC_GET_ARG2(*icall);
    419 
     400       
    420401        /* Find mode in the list. */
    421402        fibril_mutex_lock(&vs->mode_mtx);
    422403        vslmode_list_element_t *mode_elem = NULL;
     404       
    423405        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    424406                if (cur->mode.index == mode_idx) {
     
    427409                }
    428410        }
    429 
     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       
    430419        /* Extract mode description from the list node. */
    431         vslmode_t new_mode;
    432         if (mode_elem != NULL) {
    433                 new_mode = mode_elem->mode;
    434                 fibril_mutex_unlock(&vs->mode_mtx);
    435         } else {
    436                 fibril_mutex_unlock(&vs->mode_mtx);
    437                 async_answer_0(iid, ENOENT);
    438                 return;
    439         }
    440 
     420        vslmode_t new_mode = mode_elem->mode;
     421        fibril_mutex_unlock(&vs->mode_mtx);
     422       
    441423        /* Check whether the mode is still up-to-date. */
    442424        if (new_mode.version != mode_version) {
     425                async_answer_0(callid, EINVAL);
    443426                async_answer_0(iid, EINVAL);
    444427                return;
    445428        }
    446 
    447         ipc_callid_t callid;
    448         size_t size;
    449         unsigned int flags;
    450 
    451         /* Retrieve the shared cell storage for the new mode. */
    452         if (!async_share_out_receive(&callid, &size, &flags)) {
    453                 async_answer_0(iid, EINVAL);
    454                 return;
    455         }
     429       
    456430        void *new_cell_storage;
    457         rc = async_share_out_finalize(callid, &new_cell_storage);
     431        int rc = async_share_out_finalize(callid, &new_cell_storage);
    458432        if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
    459433                async_answer_0(iid, ENOMEM);
    460434                return;
    461435        }
    462 
     436       
    463437        /* Change device internal state. */
    464438        rc = vs->ops.change_mode(vs, new_mode);
    465 
     439       
    466440        /* Device driver could not establish new mode. Rollback. */
    467441        if (rc != EOK) {
     
    470444                return;
    471445        }
    472 
    473         /* Because resources for the new mode were successfully claimed,
    474          * 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         */
    475452        if (vs->mode_set) {
    476453                if (vs->cells.data != NULL) {
     
    479456                }
    480457        }
    481 
     458       
    482459        /* Insert new mode into the visualizer. */
    483460        vs->cells.width = new_mode.screen_width;
     
    486463        vs->cur_mode = new_mode;
    487464        vs->mode_set = true;
    488 
     465       
    489466        async_answer_0(iid, EOK);
    490467}
     
    499476        sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff);
    500477#endif
    501 
     478       
    502479        int rc = vs->ops.handle_damage(vs,
    503480            IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
    504481            IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
    505                 x_offset, y_offset);
     482            x_offset, y_offset);
    506483        async_answer_0(iid, rc);
    507484}
     
    524501        ipc_call_t call;
    525502        ipc_callid_t callid;
    526 
     503       
    527504        /* Claim the visualizer. */
    528505        if (!cas(&vs->ref_cnt, 0, 1)) {
     
    530507                return;
    531508        }
    532 
     509       
    533510        /* Accept the connection. */
    534511        async_answer_0(iid, EOK);
    535 
     512       
    536513        /* Establish callback session. */
    537514        callid = async_get_call(&call);
    538515        vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
    539         if (vs->notif_sess != NULL) {
     516        if (vs->notif_sess != NULL)
    540517                async_answer_0(callid, EOK);
    541         } else {
     518        else
    542519                async_answer_0(callid, ELIMIT);
    543         }
    544 
     520       
    545521        /* Enter command loop. */
    546522        while (true) {
    547523                callid = async_get_call(&call);
    548 
     524               
    549525                if (!IPC_GET_IMETHOD(call)) {
    550526                        async_answer_0(callid, EINVAL);
    551527                        break;
    552528                }
    553 
     529               
    554530                switch (IPC_GET_IMETHOD(call)) {
    555531                case VISUALIZER_CLAIM:
     
    588564                }
    589565        }
    590 
     566       
    591567terminate:
    592568        async_hangup(vs->notif_sess);
     
    599575{
    600576        // TODO
    601 
     577       
    602578        ipc_call_t call;
    603579        ipc_callid_t callid;
    604 
     580       
    605581        /* Accept the connection. */
    606582        atomic_inc(&rnd->ref_cnt);
    607583        async_answer_0(iid, EOK);
    608 
     584       
    609585        /* Enter command loop. */
    610586        while (true) {
    611587                callid = async_get_call(&call);
    612 
     588               
    613589                if (!IPC_GET_IMETHOD(call)) {
    614590                        async_answer_0(callid, EINVAL);
    615591                        break;
    616592                }
    617 
     593               
    618594                switch (IPC_GET_IMETHOD(call)) {
    619595                default:
     
    622598                }
    623599        }
    624 
     600       
    625601terminate:
    626602        atomic_dec(&rnd->ref_cnt);
     
    632608        visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG1(*icall));
    633609        renderer_t *rnd = graph_get_renderer(IPC_GET_ARG1(*icall));
    634 
    635         if (vs != NULL) {
     610       
     611        if (vs != NULL)
    636612                graph_visualizer_connection(vs, iid, icall, arg);
    637         } else if (rnd != NULL) {
     613        else if (rnd != NULL)
    638614                graph_renderer_connection(rnd, iid, icall, arg);
    639         } else {
     615        else
    640616                async_answer_0(iid, ENOENT);
    641         }
    642617}
    643618
Note: See TracChangeset for help on using the changeset viewer.