Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 30d4706 in mainline


Ignore:
Timestamp:
2012-01-12T08:10:14Z (8 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
master
Children:
8562724
Parents:
787b65b
Message:

remcons: split source into more files

Location:
uspace/srv/hid/remcons
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/remcons/Makefile

    r787b65b r30d4706  
    3131
    3232SOURCES = \
    33         remcons.c
     33        remcons.c \
     34        user.c
    3435
    3536include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/hid/remcons/remcons.c

    r787b65b r30d4706  
    5555#include <inttypes.h>
    5656#include "telnet.h"
    57 
     57#include "user.h"
    5858
    5959#define APP_GETTERM  "/app/getterm"
    60 #define NAME       "remterm"
    61 #define NAMESPACE  "term"
    62 #define BACKLOG_SIZE  5
    63 
    64 #define BUFFER_SIZE 1024
    65 
    66 typedef struct {
    67         int id;
    68         int socket;
    69         service_id_t service_id;
    70         char *service_name;
    71         /** Producer-consumer of kbd_event_t. */
    72         prodcons_t in_events;
    73         link_t link;
    74         char socket_buffer[BUFFER_SIZE];
    75         size_t socket_buffer_len;
    76         size_t socket_buffer_pos;
    77 
    78         task_id_t task_id;
    79 
    80         /* Reference counting. */
    81         fibril_condvar_t refcount_cv;
    82         fibril_mutex_t refcount_mutex;
    83         bool task_finished;
    84         int locsrv_connection_count;
    85         bool socket_closed;
    86 } telnet_user_t;
    87 
    88 static FIBRIL_MUTEX_INITIALIZE(users_guard);
    89 static LIST_INITIALIZE(users);
     60
    9061
    9162/** Telnet commands to force character mode
     
    10273static const size_t telnet_force_character_mode_command_count =
    10374    sizeof(telnet_force_character_mode_command) / sizeof(telnet_cmd_t);
    104 
    105 static telnet_user_t *telnet_user_create(int socket)
    106 {
    107         static int telnet_user_id_counter = 0;
    108 
    109         telnet_user_t *user = malloc(sizeof(telnet_user_t));
    110         if (user == NULL) {
    111                 return NULL;
    112         }
    113 
    114         user->id = ++telnet_user_id_counter;
    115 
    116         int rc = asprintf(&user->service_name, "%s/telnet%d", NAMESPACE, user->id);
    117         if (rc < 0) {
    118                 free(user);
    119                 return NULL;
    120         }
    121 
    122         user->socket = socket;
    123         user->service_id = (service_id_t) -1;
    124         prodcons_initialize(&user->in_events);
    125         link_initialize(&user->link);
    126         user->socket_buffer_len = 0;
    127         user->socket_buffer_pos = 0;
    128 
    129         fibril_condvar_initialize(&user->refcount_cv);
    130         fibril_mutex_initialize(&user->refcount_mutex);
    131         user->task_finished = false;
    132         user->socket_closed = false;
    133         user->locsrv_connection_count = 0;
    134 
    135 
    136         fibril_mutex_lock(&users_guard);
    137         list_append(&user->link, &users);
    138         fibril_mutex_unlock(&users_guard);
    139 
    140         return user;
    141 }
    142 
    143 static void telnet_user_destroy(telnet_user_t *user)
    144 {
    145         assert(user);
    146 
    147         fibril_mutex_lock(&users_guard);
    148         list_remove(&user->link);
    149         fibril_mutex_unlock(&users_guard);
    150 
    151         free(user);
    152 }
    153 
    154 static telnet_user_t *telnet_user_get_for_client_connection(service_id_t id)
    155 {
    156         telnet_user_t *user = NULL;
    157 
    158         fibril_mutex_lock(&users_guard);
    159         list_foreach(users, link) {
    160                 telnet_user_t *tmp = list_get_instance(link, telnet_user_t, link);
    161                 if (tmp->service_id == id) {
    162                         user = tmp;
    163                         break;
    164                 }
    165         }
    166         if (user == NULL) {
    167                 fibril_mutex_unlock(&users_guard);
    168                 return NULL;
    169         }
    170 
    171         telnet_user_t *tmp = user;
    172         fibril_mutex_lock(&tmp->refcount_mutex);
    173         user->locsrv_connection_count++;
    174 
    175         /*
    176          * Refuse to return user whose task already finished or when
    177          * the socket is already closed().
    178          */
    179         if (user->task_finished || user->socket_closed) {
    180                 user = NULL;
    181                 user->locsrv_connection_count--;
    182         }
    183 
    184         fibril_mutex_unlock(&tmp->refcount_mutex);
    185 
    186 
    187         fibril_mutex_unlock(&users_guard);
    188 
    189         return user;
    190 }
    191 
    19275
    19376
Note: See TracChangeset for help on using the changeset viewer.