Changeset 178d6a3 in mainline for uspace/srv/hid/remcons/user.c
- Timestamp:
- 2012-01-12T11:03:17Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 03e0a244
- Parents:
- c17c4e28
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/remcons/user.c
rc17c4e28 r178d6a3 100 100 fibril_mutex_unlock(&users_guard); 101 101 102 user->cursor_x = 0; 103 102 104 return user; 103 105 } … … 245 247 } 246 248 249 /** Process telnet command (currently only print to screen). 250 * 251 * @param user Telnet user structure. 252 * @param option_code Command option code. 253 * @param cmd Telnet command. 254 */ 247 255 static void process_telnet_command(telnet_user_t *user, 248 256 telnet_cmd_t option_code, telnet_cmd_t cmd) … … 257 265 } 258 266 267 /** Get next keyboard event. 268 * 269 * @param user Telnet user. 270 * @param event Where to store the keyboard event. 271 * @return Error code. 272 */ 259 273 int telnet_user_get_next_keyboard_event(telnet_user_t *user, kbd_event_t *event) 260 274 { … … 318 332 } 319 333 334 /** Send data (convert them first) to the socket, no locking. 335 * 336 * @param user Telnet user. 337 * @param data Data buffer (not zero terminated). 338 * @param size Size of @p data buffer in bytes. 339 */ 340 static int telnet_user_send_data_no_lock(telnet_user_t *user, uint8_t *data, size_t size) 341 { 342 uint8_t *converted = malloc(3 * size + 1); 343 assert(converted); 344 int converted_size = 0; 345 346 /* Convert new-lines. */ 347 for (size_t i = 0; i < size; i++) { 348 if (data[i] == 10) { 349 converted[converted_size++] = 13; 350 converted[converted_size++] = 10; 351 user->cursor_x = 0; 352 } else { 353 converted[converted_size++] = data[i]; 354 if (data[i] == '\b') { 355 user->cursor_x--; 356 } else { 357 user->cursor_x++; 358 } 359 } 360 } 361 362 363 int rc = send(user->socket, converted, converted_size, 0); 364 free(converted); 365 366 return rc; 367 } 368 369 /** Send data (convert them first) to the socket. 370 * 371 * @param user Telnet user. 372 * @param data Data buffer (not zero terminated). 373 * @param size Size of @p data buffer in bytes. 374 */ 375 int telnet_user_send_data(telnet_user_t *user, uint8_t *data, size_t size) 376 { 377 fibril_mutex_lock(&user->guard); 378 379 int rc = telnet_user_send_data_no_lock(user, data, size); 380 381 fibril_mutex_unlock(&user->guard); 382 383 return rc; 384 } 385 386 /** Update cursor X position. 387 * 388 * This call may result in sending control commands over socket. 389 * 390 * @param user Telnet user. 391 * @param new_x New cursor location. 392 */ 393 void telnet_user_update_cursor_x(telnet_user_t *user, int new_x) 394 { 395 fibril_mutex_lock(&user->guard); 396 if (user->cursor_x - 1 == new_x) { 397 uint8_t data = '\b'; 398 /* Ignore errors. */ 399 telnet_user_send_data_no_lock(user, &data, 1); 400 } 401 user->cursor_x = new_x; 402 fibril_mutex_unlock(&user->guard); 403 404 } 405 320 406 /** 321 407 * @}
Note:
See TracChangeset
for help on using the changeset viewer.