Changeset 41811af in mainline for uspace/lib/c/generic/clipboard.c
- Timestamp:
- 2011-06-10T10:14:26Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab547063
- Parents:
- 9536e6e (diff), 390d80d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/clipboard.c
r9536e6e r41811af 39 39 40 40 #include <clipboard.h> 41 #include < ipc/ns.h>41 #include <ns.h> 42 42 #include <ipc/services.h> 43 43 #include <ipc/clipboard.h> 44 #include <fibril_synch.h> 44 45 #include <async.h> 45 46 #include <str.h> … … 47 48 #include <malloc.h> 48 49 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); 50 static FIBRIL_MUTEX_INITIALIZE(clip_mutex); 51 static async_sess_t *clip_sess = NULL; 52 53 /** Start an async exchange on the clipboard session. 54 * 55 * @return New exchange. 56 * 57 */ 58 static 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 */ 76 static void clip_exchange_end(async_exch_t *exch) 77 { 78 async_exchange_end(exch); 58 79 } 59 80 … … 73 94 74 95 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); 81 100 82 101 return (int) rc; 83 102 } 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 89 109 if (rc != EOK) { 90 110 sysarg_t rc_orig; 91 111 async_wait_for(req, &rc_orig); 92 async_serialize_end();93 112 if (rc_orig == EOK) 94 113 return (int) rc; … … 98 117 99 118 async_wait_for(req, &rc); 100 async_serialize_end();101 119 102 120 return (int) rc; … … 117 135 /* Loop until clipboard read succesful */ 118 136 while (true) { 119 async_serialize_start(); 120 clip_connect(); 137 async_exch_t *exch = clip_exchange_begin(); 121 138 122 139 sysarg_t size; 123 140 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); 127 144 128 145 if (rc != EOK) … … 145 162 return ENOMEM; 146 163 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 151 169 if ((int) rc == EOVERFLOW) { 152 170 /* … … 154 172 * the last call of CLIPBOARD_CONTENT 155 173 */ 156 async_serialize_end();157 174 break; 158 175 } … … 161 178 sysarg_t rc_orig; 162 179 async_wait_for(req, &rc_orig); 163 async_serialize_end();164 180 if (rc_orig == EOK) 165 181 return (int) rc; … … 169 185 170 186 async_wait_for(req, &rc); 171 async_serialize_end();172 187 173 188 if (rc == EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.