Changeset eda925a in mainline


Ignore:
Timestamp:
2010-02-04T15:46:51Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d32358f
Parents:
b4cbef1
Message:

improve naming conventions:
merge async_data_receive() and async_string_receive() into async_data_write_accept()
rename async_data_void() to async_data_write_void()
rename async_data_forward_fast() to async_data_write_forward_fast()
rename async_data_forward_n_m to async_data_write_forward_n_m

Location:
uspace
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/async.c

    rb4cbef1 reda925a  
    13831383}
    13841384
    1385 /** Wrapper for receiving binary data
     1385/** Wrapper for receiving binary data or strings
    13861386 *
    13871387 * This wrapper only makes it more comfortable to use async_data_write_*
    1388  * functions to receive binary data.
     1388 * functions to receive binary data or strings.
    13891389 *
    13901390 * @param data       Pointer to data pointer (which should be later disposed
    13911391 *                   by free()). If the operation fails, the pointer is not
    13921392 *                   touched.
     1393 * @param nullterm   If true then the received data is always zero terminated.
     1394 *                   This also causes to allocate one extra byte beyond the
     1395 *                   raw transmitted data.
    13931396 * @param min_size   Minimum size (in bytes) of the data to receive.
    13941397 * @param max_size   Maximum size (in bytes) of the data to receive. 0 means
    13951398 *                   no limit.
    1396  * @param granulariy If non-zero, then the size of the received data has to
     1399 * @param granulariy If non-zero then the size of the received data has to
    13971400 *                   be divisible by this value.
    13981401 * @param received   If not NULL, the size of the received data is stored here.
     
    14011404 *
    14021405 */
    1403 int async_data_receive(void **data, const size_t min_size,
    1404     const size_t max_size, const size_t granularity, size_t *received)
     1406int async_data_write_accept(void **data, const bool nullterm,
     1407    const size_t min_size, const size_t max_size, const size_t granularity,
     1408    size_t *received)
    14051409{
    14061410        ipc_callid_t callid;
     
    14261430        }
    14271431       
    1428         void *_data = malloc(size);
     1432        void *_data;
     1433       
     1434        if (nullterm)
     1435                _data = malloc(size + 1);
     1436        else
     1437                _data = malloc(size);
     1438       
    14291439        if (_data == NULL) {
    14301440                ipc_answer_0(callid, ENOMEM);
     
    14381448        }
    14391449       
     1450        if (nullterm)
     1451                ((char *) _data)[size] = 0;
     1452       
    14401453        *data = _data;
    14411454        if (received != NULL)
     
    14451458}
    14461459
    1447 /** Wrapper for receiving strings
    1448  *
    1449  * This wrapper only makes it more comfortable to use async_data_write_*
    1450  * functions to receive strings.
    1451  *
    1452  * @param str      Pointer to string pointer (which should be later disposed
    1453  *                 by free()). If the operation fails, the pointer is not
    1454  *                 touched.
    1455  * @param max_size Maximum size (in bytes) of the string to receive. 0 means
    1456  *                 no limit.
    1457  * @param received If not NULL, the size of the received data is stored here.
    1458  *
    1459  * @return Zero on success or a value from @ref errno.h on failure.
    1460  *
    1461  */
    1462 int async_string_receive(char **str, const size_t max_size, size_t *received)
    1463 {
    1464         ipc_callid_t callid;
    1465         size_t size;
    1466         if (!async_data_write_receive(&callid, &size)) {
    1467                 ipc_answer_0(callid, EINVAL);
    1468                 return EINVAL;
    1469         }
    1470        
    1471         if ((max_size > 0) && (size > max_size)) {
    1472                 ipc_answer_0(callid, EINVAL);
    1473                 return EINVAL;
    1474         }
    1475        
    1476         char *data = (char *) malloc(size + 1);
    1477         if (data == NULL) {
    1478                 ipc_answer_0(callid, ENOMEM);
    1479                 return ENOMEM;
    1480         }
    1481        
    1482         int rc = async_data_write_finalize(callid, data, size);
    1483         if (rc != EOK) {
    1484                 free(data);
    1485                 return rc;
    1486         }
    1487        
    1488         data[size] = 0;
    1489         *str = data;
    1490         if (received != NULL)
    1491                 *received = size;
    1492        
    1493         return EOK;
    1494 }
    1495 
    14961460/** Wrapper for voiding any data that is about to be received
    14971461 *
     
    15011465 *
    15021466 */
    1503 void async_data_void(const int retval)
     1467void async_data_write_void(const int retval)
    15041468{
    15051469        ipc_callid_t callid;
     
    15121476 *
    15131477 */
    1514 int async_data_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
     1478int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
    15151479    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
    15161480{
  • uspace/lib/libc/include/async.h

    rb4cbef1 reda925a  
    310310extern int async_data_read_receive(ipc_callid_t *, size_t *);
    311311extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
     312
    312313extern int async_data_read_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t,
    313314    ipcarg_t, ipcarg_t, ipc_call_t *);
    314315
    315316/*
    316  * User-friendly wrappers for async_data_forward_fast().
    317  */
    318 #define async_data_forward_0_0(phoneid, method, answer) \
    319         async_data_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL)
    320 #define async_data_forward_0_1(phoneid, method, answer) \
    321         async_data_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer))
    322 #define async_data_forward_1_0(phoneid, method, arg1, answer) \
    323         async_data_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL)
    324 #define async_data_forward_1_1(phoneid, method, arg1, answer) \
    325         async_data_forward_fast((phoneid), (method), (arg1), 0, 0, 0, (answer))
    326 #define async_data_forward_2_0(phoneid, method, arg1, arg2, answer) \
    327         async_data_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, NULL)
    328 #define async_data_forward_2_1(phoneid, method, arg1, arg2, answer) \
    329         async_data_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
     317 * User-friendly wrappers for async_data_write_forward_fast().
     318 */
     319#define async_data_write_forward_0_0(phoneid, method, answer) \
     320        async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL)
     321#define async_data_write_forward_0_1(phoneid, method, answer) \
     322        async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer))
     323#define async_data_write_forward_1_0(phoneid, method, arg1, answer) \
     324        async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL)
     325#define async_data_write_forward_1_1(phoneid, method, arg1, answer) \
     326        async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, \
    330327            (answer))
    331 #define async_data_forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \
    332         async_data_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
    333             NULL)
    334 #define async_data_forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \
    335         async_data_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
     328#define async_data_write_forward_2_0(phoneid, method, arg1, arg2, answer) \
     329        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
     330            NULL)
     331#define async_data_write_forward_2_1(phoneid, method, arg1, arg2, answer) \
     332        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
    336333            (answer))
    337 #define async_data_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \
    338         async_data_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     334#define async_data_write_forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \
     335        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     336            0, NULL)
     337#define async_data_write_forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \
     338        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     339            0, (answer))
     340#define async_data_write_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \
     341        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
    339342            (arg4), NULL)
    340 #define async_data_forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \
    341         async_data_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     343#define async_data_write_forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \
     344        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
    342345            (arg4), (answer))
    343346
     
    345348extern int async_data_write_receive(ipc_callid_t *, size_t *);
    346349extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
    347 extern int async_data_receive(void **, const size_t, const size_t,
    348     const size_t, size_t *);
    349 extern int async_string_receive(char **, const size_t, size_t *);
    350 extern void async_data_void(const int);
    351 extern int async_data_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
    352     ipcarg_t, ipc_call_t *);
     350
     351extern int async_data_write_accept(void **, const bool, const size_t,
     352    const size_t, const size_t, size_t *);
     353extern void async_data_write_void(const int);
     354
     355extern int async_data_write_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t,
     356    ipcarg_t, ipcarg_t, ipc_call_t *);
    353357
    354358#endif
  • uspace/lib/libfs/libfs.c

    rb4cbef1 reda925a  
    176176        if ((res != EOK) || (!fn)) {
    177177                ipc_hangup(mountee_phone);
    178                 async_data_void(combine_rc(res, ENOENT));
     178                async_data_write_void(combine_rc(res, ENOENT));
    179179                ipc_answer_0(rid, combine_rc(res, ENOENT));
    180180                return;
     
    184184                ipc_hangup(mountee_phone);
    185185                (void) ops->node_put(fn);
    186                 async_data_void(EBUSY);
     186                async_data_write_void(EBUSY);
    187187                ipc_answer_0(rid, EBUSY);
    188188                return;
     
    193193                ipc_hangup(mountee_phone);
    194194                (void) ops->node_put(fn);
    195                 async_data_void(rc);
     195                async_data_write_void(rc);
    196196                ipc_answer_0(rid, rc);
    197197                return;
     
    199199       
    200200        ipc_call_t answer;
    201         rc = async_data_forward_1_1(mountee_phone, VFS_OUT_MOUNTED, mr_dev_handle,
    202             &answer);
     201        rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED,
     202            mr_dev_handle, &answer);
    203203       
    204204        if (rc == EOK) {
  • uspace/srv/clip/clip.c

    rb4cbef1 reda925a  
    6565                break;
    6666        case CLIPBOARD_TAG_DATA:
    67                 rc = async_data_receive(&data, 0, 0, 0, &size);
     67                rc = async_data_write_accept((char **) &data, false, 0, 0, 0, &size);
    6868                if (rc != EOK) {
    6969                        ipc_answer_0(rid, rc);
  • uspace/srv/devmap/devmap.c

    rb4cbef1 reda925a  
    396396         * Get driver name
    397397         */
    398         int rc = async_string_receive(&driver->name, DEVMAP_NAME_MAXLEN, NULL);
     398        int rc = async_data_write_accept((char **) &driver->name, true, 0,
     399            DEVMAP_NAME_MAXLEN, 0, NULL);
    399400        if (rc != EOK) {
    400401                free(driver);
     
    510511        /* Get fqdn */
    511512        char *fqdn;
    512         int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL);
     513        int rc = async_data_write_accept((char **) &fqdn, true, 0,
     514            DEVMAP_NAME_MAXLEN, 0, NULL);
    513515        if (rc != EOK) {
    514516                free(device);
     
    622624       
    623625        /* Get fqdn */
    624         int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL);
     626        int rc = async_data_write_accept((char **) &fqdn, true, 0,
     627            DEVMAP_NAME_MAXLEN, 0, NULL);
    625628        if (rc != EOK) {
    626629                ipc_answer_0(iid, rc);
     
    683686       
    684687        /* Get device name */
    685         int rc = async_string_receive(&name, DEVMAP_NAME_MAXLEN, NULL);
     688        int rc = async_data_write_accept((char **) &name, true, 0,
     689            DEVMAP_NAME_MAXLEN, 0, NULL);
    686690        if (rc != EOK) {
    687691                ipc_answer_0(iid, rc);
  • uspace/srv/fs/devfs/devfs_ops.c

    rb4cbef1 reda925a  
    419419       
    420420        /* Accept the mount options */
    421         ipcarg_t retval = async_string_receive(&opts, 0, NULL);
     421        ipcarg_t retval = async_data_write_accept((char **) &opts, true, 0, 0,
     422            0, NULL);
    422423        if (retval != EOK) {
    423424                ipc_answer_0(rid, retval);
  • uspace/srv/fs/fat/fat_ops.c

    rb4cbef1 reda925a  
    977977        /* Accept the mount options */
    978978        char *opts;
    979         int rc = async_string_receive(&opts, 0, NULL);
     979        int rc = async_data_write_accept((char **) &opts, true, 0, 0, 0, NULL);
    980980       
    981981        if (rc != EOK) {
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    rb4cbef1 reda925a  
    442442        /* Accept the mount options */
    443443        char *opts;
    444         int rc = async_string_receive(&opts, 0, NULL);
     444        int rc = async_data_write_accept((char **) &opts, true, 0, 0, 0, NULL);
    445445       
    446446        if (rc != EOK) {
  • uspace/srv/hid/console/console.c

    rb4cbef1 reda925a  
    477477        void *buf;
    478478        size_t size;
    479         int rc = async_data_receive(&buf, 0, 0, 0, &size);
     479        int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size);
    480480       
    481481        if (rc != EOK) {
  • uspace/srv/loader/main.c

    rb4cbef1 reda925a  
    126126{
    127127        char *buf;
    128         int rc = async_string_receive(&buf, 0, NULL);
     128        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
    129129       
    130130        if (rc == EOK) {
     
    146146{
    147147        char *buf;
    148         int rc = async_string_receive(&buf, 0, NULL);
     148        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
    149149       
    150150        if (rc == EOK) {
     
    167167        char *buf;
    168168        size_t buf_size;
    169         int rc = async_string_receive(&buf, 0, &buf_size);
     169        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, &buf_size);
    170170       
    171171        if (rc == EOK) {
     
    232232        fdi_node_t *buf;
    233233        size_t buf_size;
    234         int rc = async_data_receive(&buf, 0, 0, sizeof(fdi_node_t), &buf_size);
     234        int rc = async_data_write_accept((void **) &buf, false, 0, 0,
     235            sizeof(fdi_node_t), &buf_size);
    235236       
    236237        if (rc == EOK) {
  • uspace/srv/vfs/vfs_ops.c

    rb4cbef1 reda925a  
    267267        /* We want the client to send us the mount point. */
    268268        char *mp;
    269         int rc = async_string_receive(&mp, MAX_PATH_LEN, NULL);
     269        int rc = async_data_write_accept((char **) &mp, true, 0, MAX_PATH_LEN,
     270            0, NULL);
    270271        if (rc != EOK) {
    271272                ipc_answer_0(rid, rc);
     
    275276        /* Now we expect to receive the mount options. */
    276277        char *opts;
    277         rc = async_string_receive(&opts, MAX_MNTOPTS_LEN, NULL);
     278        rc = async_data_write_accept((char **) &opts, true, 0, MAX_MNTOPTS_LEN,
     279            0, NULL);
    278280        if (rc != EOK) {
    279281                free(mp);
     
    287289         */
    288290        char *fs_name;
    289         rc = async_string_receive(&fs_name, FS_NAME_MAXLEN, NULL);
     291        rc = async_data_write_accept((char **) &fs_name, true, 0, FS_NAME_MAXLEN,
     292            0, NULL);
    290293        if (rc != EOK) {
    291294                free(mp);
     
    357360         * Receive the mount point path.
    358361         */
    359         rc = async_string_receive(&mp, MAX_PATH_LEN, NULL);
     362        rc = async_data_write_accept((char **) &mp, true, 0, MAX_PATH_LEN,
     363            0, NULL);
    360364        if (rc != EOK)
    361365                ipc_answer_0(rid, rc);
     
    522526       
    523527        char *path;
    524         int rc = async_string_receive(&path, 0, NULL);
     528        int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL);
    525529        if (rc != EOK) {
    526530                ipc_answer_0(rid, rc);
     
    836840                    &answer);
    837841        } else {
    838                 rc = async_data_forward_3_1(fs_phone, VFS_OUT_WRITE,
     842                rc = async_data_write_forward_3_1(fs_phone, VFS_OUT_WRITE,
    839843                    file->node->dev_handle, file->node->index, file->pos,
    840844                    &answer);
     
    10071011{
    10081012        char *path;
    1009         int rc = async_string_receive(&path, 0, NULL);
     1013        int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL);
    10101014        if (rc != EOK) {
    10111015                ipc_answer_0(rid, rc);
     
    10611065       
    10621066        char *path;
    1063         int rc = async_string_receive(&path, 0, NULL);
     1067        int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL);
    10641068        if (rc != EOK) {
    10651069                ipc_answer_0(rid, rc);
     
    10831087       
    10841088        char *path;
    1085         int rc = async_string_receive(&path, 0, NULL);
     1089        int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL);
    10861090        if (rc != EOK) {
    10871091                ipc_answer_0(rid, rc);
     
    11181122        /* Retrieve the old path. */
    11191123        char *old;
    1120         int rc = async_string_receive(&old, 0, NULL);
     1124        int rc = async_data_write_accept((char **) &old, true, 0, 0, 0, NULL);
    11211125        if (rc != EOK) {
    11221126                ipc_answer_0(rid, rc);
     
    11261130        /* Retrieve the new path. */
    11271131        char *new;
    1128         rc = async_string_receive(&new, 0, NULL);
     1132        rc = async_data_write_accept((char **) &new, true, 0, 0, 0, NULL);
    11291133        if (rc != EOK) {
    11301134                free(old);
  • uspace/srv/vfs/vfs_register.c

    rb4cbef1 reda925a  
    114114       
    115115        vfs_info_t *vfs_info;
    116         int rc = async_data_receive(&vfs_info, sizeof(vfs_info_t),
    117             sizeof(vfs_info_t), 0, NULL);
     116        int rc = async_data_write_accept((void **) &vfs_info, false,
     117            sizeof(vfs_info_t), sizeof(vfs_info_t), 0, NULL);
    118118       
    119119        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.