Changeset 0ca15eb7 in mainline


Ignore:
Timestamp:
2014-07-09T10:53:33Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7d276395
Parents:
005ac3c
Message:

Compositor need not jump through hoops to connect to a visualizer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/compositor/compositor.c

    r005ac3c r0ca15eb7  
    5555#include <async.h>
    5656#include <loc.h>
    57 #include <devman.h>
    5857
    5958#include <event.h>
     
    11491148}
    11501149
    1151 static async_sess_t *vsl_connect(const char *svc)
     1150static async_sess_t *vsl_connect(service_id_t sid, const char *svc)
    11521151{
    11531152        int rc;
    11541153        async_sess_t *sess;
    1155         service_id_t dsid;
    1156         devman_handle_t handle;
    1157 
    1158         rc = loc_service_get_id(svc, &dsid, 0);
     1154
     1155        sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 0);
     1156        if (sess == NULL) {
     1157                printf("%s: Unable to connect to visualizer %s\n", NAME, svc);
     1158                return NULL;
     1159        }
     1160
     1161        rc = graph_dev_connect(sess);
    11591162        if (rc != EOK) {
     1163                printf("%s: Failed initializing visualiser %s\n", NAME, svc);
    11601164                return NULL;
    11611165        }
    11621166
    1163         rc = devman_fun_sid_to_handle(dsid, &handle);
    1164         if (rc == EOK) {
    1165                 sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 0);
    1166                 if (sess == NULL) {
    1167                         printf("%s: Unable to connect to visualizer %s\n", NAME, svc);
    1168                         return NULL;
    1169                 }
    1170                 rc = graph_dev_connect(sess);
    1171                 if (rc != EOK) {
    1172                         return NULL;
    1173                 }
    1174         } else if (rc == ENOENT) {
    1175                 sess = loc_service_connect(EXCHANGE_SERIALIZE, dsid, 0);
    1176                 if (sess == NULL) {
    1177                         printf("%s: Unable to connect to visualizer %s\n", NAME, svc);
    1178                         return NULL;
    1179                 }
    1180         } else {
    1181                 return NULL;
    1182         }
    1183 
    11841167        async_exch_t *exch = async_exchange_begin(sess);
    1185         rc = async_connect_to_me(exch, dsid, 0, 0, vsl_notifications, NULL);
     1168        rc = async_connect_to_me(exch, sid, 0, 0, vsl_notifications, NULL);
    11861169        async_exchange_end(exch);
    11871170
     
    11961179}
    11971180
    1198 static viewport_t *viewport_create(const char *vsl_name)
     1181static viewport_t *viewport_create(service_id_t sid)
    11991182{
    12001183        int rc;
    1201 
    1202         viewport_t *vp = (viewport_t *) malloc(sizeof(viewport_t));
    1203         if (!vp) {
    1204                 return NULL;
    1205         }
     1184        char *vsl_name = NULL;
     1185        viewport_t *vp = NULL;
     1186        bool claimed = false;
     1187
     1188        rc = loc_service_get_name(sid, &vsl_name);
     1189        if (rc != EOK)
     1190                goto error;
     1191
     1192        vp = (viewport_t *) calloc(1, sizeof(viewport_t));
     1193        if (!vp)
     1194                goto error;
    12061195
    12071196        link_initialize(&vp->link);
     
    12101199
    12111200        /* Establish output bidirectional connection. */
    1212         vp->sess = vsl_connect(vsl_name);
    1213         rc = loc_service_get_id(vsl_name, &vp->dsid, 0);
    1214         if (vp->sess == NULL || rc != EOK) {
    1215                 free(vp);
    1216                 return NULL;
    1217         }
     1201        vp->dsid = sid;
     1202        vp->sess = vsl_connect(sid, vsl_name);
     1203        if (vp->sess == NULL)
     1204                goto error;
    12181205
    12191206        /* Claim the given visualizer. */
    12201207        rc = visualizer_claim(vp->sess, 0);
    12211208        if (rc != EOK) {
    1222                 async_hangup(vp->sess);
    1223                 free(vp);
    12241209                printf("%s: Unable to claim visualizer (%s)\n", NAME, str_error(rc));
    1225                 return NULL;
    1226         }
     1210                goto error;
     1211        }
     1212
     1213        claimed = true;
    12271214
    12281215        /* Retrieve the default mode. */
    12291216        rc = visualizer_get_default_mode(vp->sess, &vp->mode);
    12301217        if (rc != EOK) {
    1231                 visualizer_yield(vp->sess);
    1232                 async_hangup(vp->sess);
    1233                 free(vp);
    12341218                printf("%s: Unable to retrieve mode (%s)\n", NAME, str_error(rc));
    1235                 return NULL;
     1219                goto error;
    12361220        }
    12371221
     
    12401224            NULL, SURFACE_FLAG_SHARED);
    12411225        if (vp->surface == NULL) {
    1242                 visualizer_yield(vp->sess);
    1243                 async_hangup(vp->sess);
    1244                 free(vp);
    12451226                printf("%s: Unable to create surface (%s)\n", NAME, str_error(rc));
    1246                 return NULL;
     1227                goto error;
    12471228        }
    12481229
     
    12511232                vp->mode.index, vp->mode.version, surface_direct_access(vp->surface));
    12521233        if (rc != EOK) {
     1234                printf("%s: Unable to set mode (%s)\n", NAME, str_error(rc));
     1235                goto error;
     1236        }
     1237
     1238        return vp;
     1239error:
     1240        if (claimed)
    12531241                visualizer_yield(vp->sess);
    1254                 surface_destroy(vp->surface);
     1242        if (vp->sess != NULL)
    12551243                async_hangup(vp->sess);
    1256                 free(vp);
    1257                 printf("%s: Unable to set mode (%s)\n", NAME, str_error(rc));
    1258                 return NULL;
    1259         }
    1260 
    1261         return vp;
     1244        free(vp);
     1245        free(vsl_name);
     1246        return NULL;
    12621247}
    12631248
     
    21902175                        continue;
    21912176               
    2192                 char *svc_name;
    2193                 rc = loc_service_get_name(svcs[i], &svc_name);
    2194                 if (rc == EOK) {
    2195                         viewport_t *vp = viewport_create(svc_name);
    2196                         if (vp != NULL) {
    2197                                 list_append(&vp->link, &viewport_list);
    2198                         }
    2199                 }
     2177                viewport_t *vp = viewport_create(svcs[i]);
     2178                if (vp != NULL)
     2179                        list_append(&vp->link, &viewport_list);
    22002180        }
    22012181        fibril_mutex_unlock(&viewport_list_mtx);
Note: See TracChangeset for help on using the changeset viewer.