Changeset 5576358 in mainline
- Timestamp:
- 2012-01-09T17:52:42Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6f7cd5d
- Parents:
- 21a9869
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/remcons/remcons.c
r21a9869 r5576358 67 67 int socket; 68 68 service_id_t service_id; 69 char *service_name; 69 70 /** Producer-consumer of kbd_event_t. */ 70 71 prodcons_t in_events; … … 75 76 } client_t; 76 77 78 static FIBRIL_MUTEX_INITIALIZE(clients_guard); 77 79 static LIST_INITIALIZE(clients); 78 static int client_counter = 0; 80 81 static client_t *client_create(int socket) 82 { 83 static int client_counter = 0; 84 85 client_t *client = malloc(sizeof(client_t)); 86 if (client == NULL) { 87 return NULL; 88 } 89 90 client->id = ++client_counter; 91 92 int rc = asprintf(&client->service_name, "%s/telnet%d", NAMESPACE, client->id); 93 if (rc < 0) { 94 free(client); 95 return NULL; 96 } 97 98 client->socket = socket; 99 client->service_id = (service_id_t) -1; 100 prodcons_initialize(&client->in_events); 101 link_initialize(&client->link); 102 client->socket_buffer_len = 0; 103 client->socket_buffer_pos = 0; 104 105 106 fibril_mutex_lock(&clients_guard); 107 list_append(&client->link, &clients); 108 fibril_mutex_unlock(&clients_guard); 109 110 return client; 111 } 112 113 static void client_destroy(client_t *client) 114 { 115 assert(client); 116 117 fibril_mutex_lock(&clients_guard); 118 list_remove(&client->link); 119 fibril_mutex_unlock(&clients_guard); 120 121 free(client); 122 } 123 124 static client_t *client_find(service_id_t id) 125 { 126 client_t *client = NULL; 127 128 fibril_mutex_lock(&clients_guard); 129 list_foreach(clients, link) { 130 client_t *tmp = list_get_instance(link, client_t, link); 131 if (tmp->service_id == id) { 132 client = tmp; 133 break; 134 } 135 } 136 fibril_mutex_unlock(&clients_guard); 137 138 return client; 139 } 140 79 141 80 142 … … 94 156 static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 95 157 { 96 service_id_t id = IPC_GET_ARG1(*icall);97 98 158 /* Find the client. */ 99 client_t *client = NULL; 100 list_foreach(clients, link) { 101 client_t *tmp = list_get_instance(link, client_t, link); 102 if (tmp->service_id == IPC_GET_ARG1(*icall)) { 103 client = tmp; 104 break; 105 } 106 } 107 159 client_t *client = client_find(IPC_GET_ARG1(*icall)); 108 160 if (client == NULL) { 109 161 async_answer_0(iid, ENOENT); … … 111 163 } 112 164 113 printf("New client for service % " PRIun ".\n", id);165 printf("New client for service %s.\n", client->service_name); 114 166 115 167 /* Accept the connection */ … … 256 308 client_t *client = arg; 257 309 258 // FIXME: locking 259 list_append(&client->link, &clients); 260 261 char vc[LOC_NAME_MAXLEN + 1]; 262 snprintf(vc, LOC_NAME_MAXLEN, "%s/rem%d", NAMESPACE, client->id); 263 if (loc_service_register(vc, &client->service_id) != EOK) { 264 fprintf(stderr, "%s: Unable to register device %s\n", NAME, vc); 310 rc = loc_service_register(client->service_name, &client->service_id); 311 if (rc != EOK) { 312 fprintf(stderr, "%s: Unable to register device %s\n", NAME, 313 client->service_name); 265 314 return EOK; 266 315 } 267 printf("Service %s registered as %" PRIun "\n", vc, client->service_id); 268 269 270 prodcons_initialize(&client->in_events); 271 client->socket_buffer_len = 0; 272 client->socket_buffer_pos = 0; 316 printf("Service %s registered as %" PRIun "\n", client->service_name, 317 client->service_id); 273 318 274 319 char term[LOC_NAME_MAXLEN]; 275 snprintf(term, LOC_NAME_MAXLEN, "%s/%s", "/loc", vc);320 snprintf(term, LOC_NAME_MAXLEN, "%s/%s", "/loc", client->service_name); 276 321 277 322 task_id_t task; … … 289 334 290 335 closesocket(client->socket); 336 337 client_destroy(client); 291 338 292 339 return EOK; … … 350 397 } 351 398 352 client_t *client = malloc(sizeof(client_t));399 client_t *client = client_create(conn_sd); 353 400 assert(client); 354 client->id = ++client_counter;355 client->socket = conn_sd;356 401 357 402 fid_t fid = fibril_create(network_client_fibril, client);
Note:
See TracChangeset
for help on using the changeset viewer.