Lines Matching +full:entry +full:- +full:name

1  /*-
2 * Copyright (c) 2005-2006 The FreeBSD Project
5 * Author: Victor Cruceru <soc-victor@freebsd.org>
51 free(entry_p->name); \
52 free(entry_p->location); \
53 free(entry_p->descr); \
86 static int devd_sock = -1;
96 * Create a new entry out of thin air.
99 device_entry_create(const char *name, const char *location, const char *descr) in device_entry_create() argument
101 struct device_entry *entry = NULL; in device_entry_create() local
106 assert((name[0] != 0) || (location[0] != 0)); in device_entry_create()
108 if (name[0] == 0 && location[0] == 0) in device_entry_create()
112 assert(map->name_key != NULL); in device_entry_create()
113 assert(map->location_key != NULL); in device_entry_create()
115 if (strcmp(map->name_key, name) == 0 && in device_entry_create()
116 strcmp(map->location_key, location) == 0) { in device_entry_create()
122 /* new object - get a new index */ in device_entry_create()
129 * So it is better to exit - if the table is sparsed in device_entry_create()
141 map->entry_p = NULL; in device_entry_create()
143 name_len = strlen(name) + 1; in device_entry_create()
147 if ((map->name_key = malloc(name_len)) == NULL) { in device_entry_create()
157 if ((map->location_key = malloc(location_len )) == NULL) { in device_entry_create()
159 free(map->name_key); in device_entry_create()
164 map->hrIndex = next_device_index++; in device_entry_create()
166 strlcpy(map->name_key, name, name_len); in device_entry_create()
167 strlcpy(map->location_key, location, location_len); in device_entry_create()
171 name, location, map->hrIndex); in device_entry_create()
174 name, location, map->hrIndex); in device_entry_create()
177 if ((entry = malloc(sizeof(*entry))) == NULL) { in device_entry_create()
181 memset(entry, 0, sizeof(*entry)); in device_entry_create()
183 entry->index = map->hrIndex; in device_entry_create()
184 map->entry_p = entry; in device_entry_create()
186 if ((entry->name = strdup(map->name_key)) == NULL) { in device_entry_create()
188 free(entry); in device_entry_create()
192 if ((entry->location = strdup(map->location_key)) == NULL) { in device_entry_create()
194 free(entry->name); in device_entry_create()
195 free(entry); in device_entry_create()
201 * for a different purpose - for device_entry::descr in device_entry_create()
203 if (name[0] != '\0') in device_entry_create()
204 name_len = strlen(name) + strlen(descr) + in device_entry_create()
213 if ((entry->descr = malloc(name_len )) == NULL) { in device_entry_create()
215 free(entry->name); in device_entry_create()
216 free(entry->location); in device_entry_create()
217 free(entry); in device_entry_create()
221 memset(&entry->descr[0], '\0', name_len); in device_entry_create()
223 if (name[0] != '\0') in device_entry_create()
224 snprintf(entry->descr, name_len, in device_entry_create()
225 "%s: %s", name, descr); in device_entry_create()
227 snprintf(entry->descr, name_len, in device_entry_create()
230 entry->id = &oid_zeroDotZero; /* unknown id - FIXME */ in device_entry_create()
231 entry->status = (u_int)DS_UNKNOWN; in device_entry_create()
232 entry->errors = 0; in device_entry_create()
233 entry->type = &OIDX_hrDeviceOther_c; in device_entry_create()
235 INSERT_OBJECT_INT(entry, &device_tbl); in device_entry_create()
237 return (entry); in device_entry_create()
241 * Create a new entry into the device table.
247 assert(dev_p->dd_name != NULL); in device_entry_create_devinfo()
248 assert(dev_p->dd_location != NULL); in device_entry_create_devinfo()
250 return (device_entry_create(dev_p->dd_name, dev_p->dd_location, in device_entry_create_devinfo()
251 dev_p->dd_desc)); in device_entry_create_devinfo()
255 * Delete an entry from the device table.
258 device_entry_delete(struct device_entry *entry) in device_entry_delete() argument
262 assert(entry != NULL); in device_entry_delete()
264 TAILQ_REMOVE(&device_tbl, entry, link); in device_entry_delete()
267 if (map->entry_p == entry) { in device_entry_delete()
268 map->entry_p = NULL; in device_entry_delete()
272 FREE_DEV_STRUCT(entry); in device_entry_delete()
276 * Find an entry given its name and location
286 if (strcmp(map->name_key, dev_p->dd_name) == 0 && in device_find_by_dev()
287 strcmp(map->location_key, dev_p->dd_location) == 0) in device_find_by_dev()
288 return (map->entry_p); in device_find_by_dev()
293 * Find an entry given its index.
298 struct device_entry *entry; in device_find_by_index() local
300 TAILQ_FOREACH(entry, &device_tbl, link) in device_find_by_index()
301 if (entry->index == idx) in device_find_by_index()
302 return (entry); in device_find_by_index()
307 * Find an device entry given its name.
317 if (strcmp(map->name_key, dev_name) == 0) in device_find_by_name()
318 return (map->entry_p); in device_find_by_name()
336 if (strncmp(dev_p->dd_name, "cpu", strlen("cpu")) == 0 && in device_get_type()
337 strstr(dev_p->dd_location, ".CPU") != NULL) { in device_get_type()
352 switch (dev->dd_state) { in device_get_status()
370 struct device_entry *entry; in device_collector() local
372 HRDBG("%llu/%llu name='%s' desc='%s' drivername='%s' location='%s'", in device_collector()
373 (unsigned long long)dev->dd_handle, in device_collector()
374 (unsigned long long)dev->dd_parent, dev->dd_name, dev->dd_desc, in device_collector()
375 dev->dd_drivername, dev->dd_location); in device_collector()
377 if (dev->dd_name[0] != '\0' || dev->dd_location[0] != '\0') { in device_collector()
379 dev->dd_name, dev->dd_location); in device_collector()
381 if ((entry = device_find_by_dev(dev)) != NULL) { in device_collector()
382 entry->flags |= HR_DEVICE_FOUND; in device_collector()
383 entry->status = (u_int)device_get_status(dev); in device_collector()
384 } else if ((entry = device_entry_create_devinfo(dev)) != NULL) { in device_collector()
385 device_get_type(dev, &entry->type); in device_collector()
387 entry->flags |= HR_DEVICE_FOUND; in device_collector()
388 entry->status = (u_int)device_get_status(dev); in device_collector()
392 dev->dd_location ); in device_collector()
412 return (-1); in create_devd_socket()
418 sizeof(devd_addr.sun_path) - 1); in create_devd_socket()
421 sizeof(devd_addr)) == -1) { in create_devd_socket()
427 return (-1); in create_devd_socket()
443 int read_len = -1; in devd_socket_callback()
453 devd_sock = -1; in devd_socket_callback()
469 devd_sock = -1; in devd_socket_callback()
480 if (buf[0] == '+' || buf[0] == '-') in devd_socket_callback()
495 /* no problem if that fails - just use polling mode */ in init_device_tbl()
525 if (devd_sock != -1) in fini_device_tbl()
532 if (n1->entry_p != NULL) { in fini_device_tbl()
533 TAILQ_REMOVE(&device_tbl, n1->entry_p, link); in fini_device_tbl()
534 FREE_DEV_STRUCT(n1->entry_p); in fini_device_tbl()
536 free(n1->name_key); in fini_device_tbl()
537 free(n1->location_key); in fini_device_tbl()
547 * socket). In either case a refresh can be forced by passing a non-zero value.
552 struct device_entry *entry, *entry_tmp; in refresh_device_tbl() local
557 (device_tick != 0 && this_tick - device_tick < device_tbl_refresh))){ in refresh_device_tbl()
578 /* mark each entry as missing */ in refresh_device_tbl()
579 TAILQ_FOREACH(entry, &device_tbl, link) in refresh_device_tbl()
580 entry->flags &= ~HR_DEVICE_FOUND; in refresh_device_tbl()
589 TAILQ_FOREACH_SAFE(entry, &device_tbl, link, entry_tmp) { in refresh_device_tbl()
592 * this entry was not detected by the above in refresh_device_tbl()
596 if (!(entry->flags & HR_DEVICE_FOUND) && in refresh_device_tbl()
597 !(entry->flags & HR_DEVICE_IMMUTABLE)) in refresh_device_tbl()
598 device_entry_delete(entry); in refresh_device_tbl()
623 struct device_entry *entry; in op_hrDeviceTable() local
630 if ((entry = NEXT_OBJECT_INT(&device_tbl, in op_hrDeviceTable()
631 &value->var, sub)) == NULL) in op_hrDeviceTable()
633 value->var.len = sub + 1; in op_hrDeviceTable()
634 value->var.subs[sub] = entry->index; in op_hrDeviceTable()
638 if ((entry = FIND_OBJECT_INT(&device_tbl, in op_hrDeviceTable()
639 &value->var, sub)) == NULL) in op_hrDeviceTable()
644 if ((entry = FIND_OBJECT_INT(&device_tbl, in op_hrDeviceTable()
645 &value->var, sub)) == NULL) in op_hrDeviceTable()
656 switch (value->var.subs[sub - 1]) { in op_hrDeviceTable()
659 value->v.integer = entry->index; in op_hrDeviceTable()
663 assert(entry->type != NULL); in op_hrDeviceTable()
664 value->v.oid = *(entry->type); in op_hrDeviceTable()
668 return (string_get(value, entry->descr, -1)); in op_hrDeviceTable()
671 value->v.oid = *(entry->id); in op_hrDeviceTable()
675 value->v.integer = entry->status; in op_hrDeviceTable()
679 value->v.uint32 = entry->errors; in op_hrDeviceTable()