Changeset 79ae36dd in mainline for uspace/lib/c/generic/clipboard.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/clipboard.c

    r764d71e r79ae36dd  
    3939
    4040#include <clipboard.h>
    41 #include <ipc/ns.h>
     41#include <ns.h>
    4242#include <ipc/services.h>
    4343#include <ipc/clipboard.h>
     44#include <fibril_synch.h>
    4445#include <async.h>
    4546#include <str.h>
     
    4748#include <malloc.h>
    4849
    49 static int clip_phone = -1;
    50 
    51 /** Connect to clipboard server
    52  *
    53  */
    54 static void clip_connect(void)
    55 {
    56         while (clip_phone < 0)
    57                 clip_phone = service_connect_blocking(SERVICE_CLIPBOARD, 0, 0);
     50static FIBRIL_MUTEX_INITIALIZE(clip_mutex);
     51static async_sess_t *clip_sess = NULL;
     52
     53/** Start an async exchange on the clipboard session.
     54 *
     55 * @return New exchange.
     56 *
     57 */
     58static async_exch_t *clip_exchange_begin(void)
     59{
     60        fibril_mutex_lock(&clip_mutex);
     61       
     62        while (clip_sess == NULL)
     63                clip_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
     64                    SERVICE_CLIPBOARD, 0, 0);
     65       
     66        fibril_mutex_unlock(&clip_mutex);
     67       
     68        return async_exchange_begin(clip_sess);
     69}
     70
     71/** Finish an async exchange on the clipboard session.
     72 *
     73 * @param exch Exchange to be finished.
     74 *
     75 */
     76static void clip_exchange_end(async_exch_t *exch)
     77{
     78        async_exchange_end(exch);
    5879}
    5980
     
    7394       
    7495        if (size == 0) {
    75                 async_serialize_start();
    76                 clip_connect();
    77                
    78                 sysarg_t rc = async_req_1_0(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_NONE);
    79                
    80                 async_serialize_end();
     96                async_exch_t *exch = clip_exchange_begin();
     97                sysarg_t rc = async_req_1_0(exch, CLIPBOARD_PUT_DATA,
     98                    CLIPBOARD_TAG_NONE);
     99                clip_exchange_end(exch);
    81100               
    82101                return (int) rc;
    83102        } else {
    84                 async_serialize_start();
    85                 clip_connect();
    86                
    87                 aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_DATA, NULL);
    88                 sysarg_t rc = async_data_write_start(clip_phone, (void *) str, size);
     103                async_exch_t *exch = clip_exchange_begin();
     104                aid_t req = async_send_1(exch, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_DATA,
     105                    NULL);
     106                sysarg_t rc = async_data_write_start(exch, (void *) str, size);
     107                clip_exchange_end(exch);
     108               
    89109                if (rc != EOK) {
    90110                        sysarg_t rc_orig;
    91111                        async_wait_for(req, &rc_orig);
    92                         async_serialize_end();
    93112                        if (rc_orig == EOK)
    94113                                return (int) rc;
     
    98117               
    99118                async_wait_for(req, &rc);
    100                 async_serialize_end();
    101119               
    102120                return (int) rc;
     
    117135        /* Loop until clipboard read succesful */
    118136        while (true) {
    119                 async_serialize_start();
    120                 clip_connect();
     137                async_exch_t *exch = clip_exchange_begin();
    121138               
    122139                sysarg_t size;
    123140                sysarg_t tag;
    124                 sysarg_t rc = async_req_0_2(clip_phone, CLIPBOARD_CONTENT, &size, &tag);
    125                
    126                 async_serialize_end();
     141                sysarg_t rc = async_req_0_2(exch, CLIPBOARD_CONTENT, &size, &tag);
     142               
     143                clip_exchange_end(exch);
    127144               
    128145                if (rc != EOK)
     
    145162                                return ENOMEM;
    146163                       
    147                         async_serialize_start();
    148                        
    149                         aid_t req = async_send_1(clip_phone, CLIPBOARD_GET_DATA, tag, NULL);
    150                         rc = async_data_read_start(clip_phone, (void *) sbuf, size);
     164                        exch = clip_exchange_begin();
     165                        aid_t req = async_send_1(exch, CLIPBOARD_GET_DATA, tag, NULL);
     166                        rc = async_data_read_start(exch, (void *) sbuf, size);
     167                        clip_exchange_end(exch);
     168                       
    151169                        if ((int) rc == EOVERFLOW) {
    152170                                /*
     
    154172                                 * the last call of CLIPBOARD_CONTENT
    155173                                 */
    156                                 async_serialize_end();
    157174                                break;
    158175                        }
     
    161178                                sysarg_t rc_orig;
    162179                                async_wait_for(req, &rc_orig);
    163                                 async_serialize_end();
    164180                                if (rc_orig == EOK)
    165181                                        return (int) rc;
     
    169185                       
    170186                        async_wait_for(req, &rc);
    171                         async_serialize_end();
    172187                       
    173188                        if (rc == EOK) {
Note: See TracChangeset for help on using the changeset viewer.