Ignore:
File:
1 edited

Legend:

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

    r007e6efa 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.