2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <stdlib.h>
2N/A#include <stdio.h>
2N/A#include <string.h>
2N/A#include <assert.h>
2N/A#include <stdarg.h>
2N/A#include <stddef.h>
2N/A#include <inttypes.h>
2N/A#include <pthread.h>
2N/A
2N/A#include "adr.h"
2N/A#include "adr_object.h"
2N/A
2N/Avoid
2N/Aadr_free(adr_object_t *o)
2N/A{
2N/A free((char *)o->ao_aname);
2N/A free((char *)o->ao_ifname);
2N/A
2N/A for (int i = 0; i < o->ao_nparents; i++) {
2N/A adr_object_t *p = o->ao_parents[i];
2N/A if (p != NULL)
2N/A adr_free(p);
2N/A }
2N/A free(o->ao_parents);
2N/A
2N/A for (int i = 0; i < o->ao_nattributes; i++) {
2N/A adr_attribute_t *a = o->ao_attributes[i];
2N/A if (a != NULL) {
2N/A free((char *)a->aa_name);
2N/A adr_type_free(a->aa_type);
2N/A adr_type_free(a->aa_read_error);
2N/A adr_type_free(a->aa_write_error);
2N/A free(a);
2N/A }
2N/A }
2N/A free(o->ao_attributes);
2N/A
2N/A for (int i = 0; i < o->ao_nmethods; i++) {
2N/A adr_method_t *m = o->ao_methods[i];
2N/A if (m != NULL) {
2N/A free((char *)m->am_name);
2N/A adr_type_free(m->am_result);
2N/A adr_type_free(m->am_error);
2N/A for (int j = 0; j < m->am_nargs; j++) {
2N/A adr_parameter_t *p = &m->am_args[j];
2N/A free((char *)p->ap_name);
2N/A adr_type_free(p->ap_type);
2N/A }
2N/A free(m);
2N/A }
2N/A }
2N/A free(o->ao_methods);
2N/A
2N/A for (int i = 0; i < o->ao_nevents; i++) {
2N/A adr_event_t *e = &o->ao_events[i];
2N/A free((char *)e->ae_name);
2N/A adr_type_free(e->ae_type);
2N/A }
2N/A free(o->ao_events);
2N/A
2N/A free(o);
2N/A}
2N/A
2N/Aint
2N/Aadr_lookup_attr_index(adr_object_t *o, const char *name)
2N/A{
2N/A adr_attribute_t **attrs = o->ao_attributes;
2N/A for (int i = 0; i < o->ao_nattributes; i++)
2N/A if (strcmp(attrs[i]->aa_name, name) == 0)
2N/A return (i);
2N/A return (-1);
2N/A}
2N/A
2N/Aadr_attribute_t *
2N/Aadr_lookup_attr(adr_object_t *o, const char *name)
2N/A{
2N/A int index = adr_lookup_attr_index(o, name);
2N/A return (index == -1 ? NULL : o->ao_attributes[index]);
2N/A}
2N/A
2N/Aadr_attribute_t *
2N/Aadr_get_attr(adr_object_t *o, int index)
2N/A{
2N/A return (index >= 0 && index < o->ao_nattributes ?
2N/A o->ao_attributes[index] : NULL);
2N/A}
2N/A
2N/A
2N/Aint
2N/Aadr_lookup_method_index(adr_object_t *o, const char *name)
2N/A{
2N/A adr_method_t **methods = o->ao_methods;
2N/A for (int i = 0; i < o->ao_nmethods; i++)
2N/A if (strcmp(methods[i]->am_name, name) == 0)
2N/A return (i);
2N/A return (-1);
2N/A}
2N/A
2N/Aadr_method_t *
2N/Aadr_lookup_method(adr_object_t *o, const char *name)
2N/A{
2N/A int index = adr_lookup_method_index(o, name);
2N/A return (index == -1 ? NULL : o->ao_methods[index]);
2N/A}
2N/A
2N/Aadr_method_t *
2N/Aadr_get_method(adr_object_t *o, int index)
2N/A{
2N/A return (index >= 0 && index < o->ao_nmethods ?
2N/A o->ao_methods[index] : NULL);
2N/A}
2N/A
2N/A
2N/Aint
2N/Aadr_lookup_event_index(adr_object_t *o, const char *name)
2N/A{
2N/A adr_event_t *events = o->ao_events;
2N/A for (int i = 0; i < o->ao_nevents; i++)
2N/A if (strcmp(events[i].ae_name, name) == 0)
2N/A return (i);
2N/A return (-1);
2N/A}
2N/A
2N/Aadr_event_t *
2N/Aadr_lookup_event(adr_object_t *o, const char *name)
2N/A{
2N/A int index = adr_lookup_event_index(o, name);
2N/A return (index == -1 ? NULL : &o->ao_events[index]);
2N/A}
2N/A
2N/Aadr_event_t *
2N/Aadr_get_event(adr_object_t *o, int index)
2N/A{
2N/A return (index >= 0 && index < o->ao_nmethods ?
2N/A &o->ao_events[index] : NULL);
2N/A}