Changeset 6a44ee4 in mainline for uspace/lib/c/generic/io
- Timestamp:
- 2011-07-20T15:26:21Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- efcebe1
- Parents:
- 25bef0ff (diff), a701812 (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. - Location:
- uspace/lib/c/generic/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/console.c
r25bef0ff r6a44ee4 37 37 #include <libc.h> 38 38 #include <async.h> 39 #include <errno.h> 40 #include <stdio.h> 41 #include <malloc.h> 42 #include <vfs/vfs_sess.h> 39 43 #include <io/console.h> 40 44 #include <ipc/console.h> 41 45 42 void console_clear(int phone) 43 { 44 async_msg_0(phone, CONSOLE_CLEAR); 45 } 46 47 int console_get_size(int phone, sysarg_t *cols, sysarg_t *rows) 48 { 49 return async_req_0_2(phone, CONSOLE_GET_SIZE, cols, rows); 50 } 51 52 void console_set_style(int phone, uint8_t style) 53 { 54 async_msg_1(phone, CONSOLE_SET_STYLE, style); 55 } 56 57 void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color, 46 console_ctrl_t *console_init(FILE *ifile, FILE *ofile) 47 { 48 console_ctrl_t *ctrl = malloc(sizeof(console_ctrl_t)); 49 if (!ctrl) 50 return NULL; 51 52 ctrl->input_sess = fsession(EXCHANGE_SERIALIZE, ifile); 53 if (!ctrl->input_sess) { 54 free(ctrl); 55 return NULL; 56 } 57 58 ctrl->output_sess = fsession(EXCHANGE_SERIALIZE, ofile); 59 if (!ctrl->output_sess) { 60 free(ctrl); 61 return NULL; 62 } 63 64 ctrl->input = ifile; 65 ctrl->output = ofile; 66 ctrl->input_aid = 0; 67 68 return ctrl; 69 } 70 71 void console_done(console_ctrl_t *ctrl) 72 { 73 free(ctrl); 74 } 75 76 bool console_kcon(void) 77 { 78 return __SYSCALL0(SYS_DEBUG_ACTIVATE_CONSOLE); 79 } 80 81 void console_flush(console_ctrl_t *ctrl) 82 { 83 fflush(ctrl->output); 84 } 85 86 void console_clear(console_ctrl_t *ctrl) 87 { 88 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 89 async_msg_0(exch, CONSOLE_CLEAR); 90 async_exchange_end(exch); 91 } 92 93 int console_get_size(console_ctrl_t *ctrl, sysarg_t *cols, sysarg_t *rows) 94 { 95 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 96 int rc = async_req_0_2(exch, CONSOLE_GET_SIZE, cols, rows); 97 async_exchange_end(exch); 98 99 return rc; 100 } 101 102 void console_set_style(console_ctrl_t *ctrl, uint8_t style) 103 { 104 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 105 async_msg_1(exch, CONSOLE_SET_STYLE, style); 106 async_exchange_end(exch); 107 } 108 109 void console_set_color(console_ctrl_t *ctrl, uint8_t fg_color, uint8_t bg_color, 58 110 uint8_t flags) 59 111 { 60 async_msg_3(phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags); 61 } 62 63 void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color) 64 { 65 async_msg_2(phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color); 66 } 67 68 void console_cursor_visibility(int phone, bool show) 69 { 70 async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, (show != false)); 71 } 72 73 int console_get_color_cap(int phone, sysarg_t *ccap) 74 { 75 return async_req_0_1(phone, CONSOLE_GET_COLOR_CAP, ccap); 76 } 77 78 void console_kcon_enable(int phone) 79 { 80 async_msg_0(phone, CONSOLE_KCON_ENABLE); 81 } 82 83 int console_get_pos(int phone, sysarg_t *col, sysarg_t *row) 84 { 85 return async_req_0_2(phone, CONSOLE_GET_POS, col, row); 86 } 87 88 void console_set_pos(int phone, sysarg_t col, sysarg_t row) 89 { 90 async_msg_2(phone, CONSOLE_GOTO, col, row); 91 } 92 93 bool console_get_event(int phone, console_event_t *event) 94 { 95 sysarg_t type; 96 sysarg_t key; 97 sysarg_t mods; 98 sysarg_t c; 99 100 int rc = async_req_0_4(phone, CONSOLE_GET_EVENT, &type, &key, &mods, &c); 101 if (rc < 0) 112 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 113 async_msg_3(exch, CONSOLE_SET_COLOR, fg_color, bg_color, flags); 114 async_exchange_end(exch); 115 } 116 117 void console_set_rgb_color(console_ctrl_t *ctrl, uint32_t fg_color, 118 uint32_t bg_color) 119 { 120 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 121 async_msg_2(exch, CONSOLE_SET_RGB_COLOR, fg_color, bg_color); 122 async_exchange_end(exch); 123 } 124 125 void console_cursor_visibility(console_ctrl_t *ctrl, bool show) 126 { 127 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 128 async_msg_1(exch, CONSOLE_CURSOR_VISIBILITY, (show != false)); 129 async_exchange_end(exch); 130 } 131 132 int console_get_color_cap(console_ctrl_t *ctrl, sysarg_t *ccap) 133 { 134 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 135 int rc = async_req_0_1(exch, CONSOLE_GET_COLOR_CAP, ccap); 136 async_exchange_end(exch); 137 138 return rc; 139 } 140 141 int console_get_pos(console_ctrl_t *ctrl, sysarg_t *col, sysarg_t *row) 142 { 143 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 144 int rc = async_req_0_2(exch, CONSOLE_GET_POS, col, row); 145 async_exchange_end(exch); 146 147 return rc; 148 } 149 150 void console_set_pos(console_ctrl_t *ctrl, sysarg_t col, sysarg_t row) 151 { 152 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 153 async_msg_2(exch, CONSOLE_GOTO, col, row); 154 async_exchange_end(exch); 155 } 156 157 bool console_get_kbd_event(console_ctrl_t *ctrl, kbd_event_t *event) 158 { 159 if (ctrl->input_aid == 0) { 160 sysarg_t type; 161 sysarg_t key; 162 sysarg_t mods; 163 sysarg_t c; 164 165 async_exch_t *exch = async_exchange_begin(ctrl->input_sess); 166 int rc = async_req_0_4(exch, CONSOLE_GET_EVENT, &type, &key, &mods, &c); 167 async_exchange_end(exch); 168 169 if (rc != EOK) { 170 errno = rc; 171 return false; 172 } 173 174 event->type = type; 175 event->key = key; 176 event->mods = mods; 177 event->c = c; 178 } else { 179 sysarg_t retval; 180 async_wait_for(ctrl->input_aid, &retval); 181 182 ctrl->input_aid = 0; 183 184 if (retval != EOK) { 185 errno = (int) retval; 186 return false; 187 } 188 189 event->type = IPC_GET_ARG1(ctrl->input_call); 190 event->key = IPC_GET_ARG2(ctrl->input_call); 191 event->mods = IPC_GET_ARG3(ctrl->input_call); 192 event->c = IPC_GET_ARG4(ctrl->input_call); 193 } 194 195 return true; 196 } 197 198 bool console_get_kbd_event_timeout(console_ctrl_t *ctrl, kbd_event_t *event, 199 suseconds_t *timeout) 200 { 201 struct timeval t0; 202 gettimeofday(&t0, NULL); 203 204 if (ctrl->input_aid == 0) { 205 async_exch_t *exch = async_exchange_begin(ctrl->input_sess); 206 ctrl->input_aid = async_send_0(exch, CONSOLE_GET_EVENT, 207 &ctrl->input_call); 208 async_exchange_end(exch); 209 } 210 211 sysarg_t retval; 212 int rc = async_wait_timeout(ctrl->input_aid, &retval, *timeout); 213 if (rc != EOK) { 214 *timeout = 0; 215 errno = rc; 102 216 return false; 103 104 event->type = type; 105 event->key = key; 106 event->mods = mods; 107 event->c = c; 217 } 218 219 ctrl->input_aid = 0; 220 221 if (retval != EOK) { 222 errno = (int) retval; 223 return false; 224 } 225 226 event->type = IPC_GET_ARG1(ctrl->input_call); 227 event->key = IPC_GET_ARG2(ctrl->input_call); 228 event->mods = IPC_GET_ARG3(ctrl->input_call); 229 event->c = IPC_GET_ARG4(ctrl->input_call); 230 231 /* Update timeout */ 232 struct timeval t1; 233 gettimeofday(&t1, NULL); 234 *timeout -= tv_sub(&t1, &t0); 108 235 109 236 return true; -
uspace/lib/c/generic/io/io.c
r25bef0ff r6a44ee4 44 44 #include <io/klog.h> 45 45 #include <vfs/vfs.h> 46 #include <vfs/vfs_sess.h> 46 47 #include <ipc/devmap.h> 47 48 #include <adt/list.h> 48 49 #include "../private/io.h" 50 #include "../private/stdio.h" 49 51 50 52 static void _ffillbuf(FILE *stream); … … 56 58 .eof = true, 57 59 .klog = false, 58 . phone = -1,60 .sess = NULL, 59 61 .btype = _IONBF, 60 62 .buf = NULL, … … 70 72 .eof = false, 71 73 .klog = true, 72 . phone = -1,74 .sess = NULL, 73 75 .btype = _IOLBF, 74 76 .buf = NULL, … … 84 86 .eof = false, 85 87 .klog = true, 86 . phone = -1,88 .sess = NULL, 87 89 .btype = _IONBF, 88 90 .buf = NULL, … … 125 127 void __stdio_done(void) 126 128 { 127 link_t *link = files.next; 128 129 while (link != &files) { 130 FILE *file = list_get_instance(link, FILE, link); 129 while (!list_empty(&files)) { 130 FILE *file = list_get_instance(list_first(&files), FILE, link); 131 131 fclose(file); 132 link = files.next;133 132 } 134 133 } … … 255 254 stream->eof = false; 256 255 stream->klog = false; 257 stream-> phone = -1;256 stream->sess = NULL; 258 257 stream->need_sync = false; 259 258 _setvbuf(stream); … … 277 276 stream->eof = false; 278 277 stream->klog = false; 279 stream-> phone = -1;278 stream->sess = NULL; 280 279 stream->need_sync = false; 281 280 _setvbuf(stream); … … 309 308 stream->eof = false; 310 309 stream->klog = false; 311 stream-> phone = -1;310 stream->sess = NULL; 312 311 stream->need_sync = false; 313 312 _setvbuf(stream); … … 324 323 fflush(stream); 325 324 326 if (stream-> phone >= 0)327 async_hangup(stream-> phone);325 if (stream->sess != NULL) 326 async_hangup(stream->sess); 328 327 329 328 if (stream->fd >= 0) … … 715 714 off64_t ftell(FILE *stream) 716 715 { 716 _fflushbuf(stream); 717 717 return lseek(stream->fd, 0, SEEK_CUR); 718 718 } … … 732 732 } 733 733 734 if ( stream->fd >= 0 && stream->need_sync) {734 if ((stream->fd >= 0) && (stream->need_sync)) { 735 735 /** 736 736 * Better than syncing always, but probably still not the … … 770 770 } 771 771 772 int fphone(FILE *stream)772 async_sess_t *fsession(exch_mgmt_t mgmt, FILE *stream) 773 773 { 774 774 if (stream->fd >= 0) { 775 if (stream-> phone < 0)776 stream-> phone = fd_phone(stream->fd);777 778 return stream-> phone;779 } 780 781 return -1;775 if (stream->sess == NULL) 776 stream->sess = fd_session(mgmt, stream->fd); 777 778 return stream->sess; 779 } 780 781 return NULL; 782 782 } 783 783
Note:
See TracChangeset
for help on using the changeset viewer.
