fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "AdapterDeviceEventListener.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "AdapterDeviceEvent.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Exceptions.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Trace.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sun_fc.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Create a new AdapterPortEvent listener
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition Listener ready to receive callbacks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception BadArgumentException
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param myCallback The listeners callback routine
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param data Opaque data that will be passed to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callback routine when and event comes in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteAdapterDeviceEventListener::AdapterDeviceEventListener(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBAPort *myPort, AdapterDeviceCallback myCallback, void *data) :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port(myPort), Listener(data), callback(myCallback) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("AdapterDeviceEventListener::AdapterDeviceEventListener");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (callback == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Send the event to this listener
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param event The event to send to the listener
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc The callback registered in the constructor will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be called.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid AdapterDeviceEventListener::dispatch(Event &event) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("AdapterDeviceEventListener::dispatch");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AdapterDeviceEvent *e = static_cast<AdapterDeviceEvent*> (&event);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t lwwn = htonll(e->getPortWWN());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Filter out unwanted events
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port->getPortWWN() == lwwn) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&wwn, &lwwn, sizeof (wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte callback(getData(), wwn, e->getType(), e->getAffectedPortID());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } // Else ignore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.internalError("Unexpected event type.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte