Changeset 9940ce0 in mainline for uspace/srv/hid/output/port/chardev.c
- Timestamp:
- 2017-11-26T01:03:40Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5f4c41b2
- Parents:
- 96258fc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/output/port/chardev.c
r96258fc r9940ce0 1 1 /* 2 2 * Copyright (c) 2016 Jakub Jermar 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 50 51 static chardev_t *chardev; 51 52 static service_id_t serial_cat_id; 53 static service_id_t console_cat_id; 52 54 53 55 static FIBRIL_MUTEX_INITIALIZE(discovery_lock); … … 68 70 chardev_write(chardev, (void *) str, str_size(str), &nwr); 69 71 /* XXX Handle error */ 72 } 73 74 static bool find_output_dev(service_id_t *svcid) 75 { 76 service_id_t *svc; 77 size_t svcs; 78 int rc; 79 80 rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs); 81 if (rc != EOK) { 82 fibril_mutex_unlock(&discovery_lock); 83 printf("%s: Failed to get services\n", NAME); 84 return false; 85 } 86 87 for (size_t i = 0; i < svcs; i++) { 88 char *name; 89 90 rc = loc_service_get_name(svc[i], &name); 91 if (rc != EOK) 92 continue; 93 94 if (!str_cmp(console, name)) { 95 /* 96 * This is the serial console service that the user 97 * wanted to use. 98 */ 99 *svcid = svc[i]; 100 free(svc); 101 return true; 102 } 103 104 free(name); 105 } 106 107 free(svc); 108 109 /* Look for any service in the 'console' category */ 110 111 rc = loc_category_get_svcs(console_cat_id, &svc, &svcs); 112 if (rc != EOK) { 113 fibril_mutex_unlock(&discovery_lock); 114 printf("%s: Failed to get services\n", NAME); 115 return false; 116 } 117 118 if (svcs > 0) { 119 *svcid = svc[0]; 120 free(svc); 121 return true; 122 } 123 124 free(svc); 125 return false; 70 126 } 71 127 … … 79 135 { 80 136 int rc; 137 bool found; 138 service_id_t sid; 81 139 82 140 fibril_mutex_lock(&discovery_lock); … … 87 145 } 88 146 89 service_id_t *svc; 90 size_t svcs; 91 rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs); 92 if (rc != EOK) { 93 fibril_mutex_unlock(&discovery_lock); 94 printf("%s: Failed to get services\n", NAME); 95 return; 96 } 97 98 service_id_t sid; 99 bool found = false; 100 101 for (size_t i = 0; i < svcs && !found; i++) { 102 char *name; 103 104 rc = loc_service_get_name(svc[i], &name); 105 if (rc != EOK) 106 continue; 107 108 if (!str_cmp(console, name)) { 109 /* 110 * This is the serial console service that the user 111 * wanted to use. 112 */ 113 found = true; 114 sid = svc[i]; 115 } 116 117 free(name); 118 } 119 120 free(svc); 121 147 found = find_output_dev(&sid); 122 148 if (!found) { 123 149 fibril_mutex_unlock(&discovery_lock); … … 148 174 int chardev_init(void) 149 175 { 150 console = config_get_value("console"); 151 if (!console) { 152 /* 153 * The system is not configured to use serial console. 154 */ 176 if (!config_key_exists("console")) { 177 console = NULL; 178 #ifndef MACHINE_ski 155 179 return EOK; 180 #endif 181 } else { 182 console = config_get_value("console"); 183 if (!console) 184 return EOK; 156 185 } 157 186 … … 162 191 } 163 192 193 rc = loc_category_get_id("console", &console_cat_id, IPC_FLAG_BLOCKING); 194 if (rc != EOK) { 195 printf("%s: Failed to get \"console\" category ID.\n", NAME); 196 return rc; 197 } 198 164 199 rc = loc_register_cat_change_cb(check_for_dev); 165 200 if (rc != EOK) { … … 168 203 return rc; 169 204 } 205 206 check_for_dev(); 170 207 171 208 fibril_mutex_lock(&discovery_lock);
Note:
See TracChangeset
for help on using the changeset viewer.