1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 27 28 29 #include "TargetEventListener.h" 30 #include "TargetEvent.h" 31 #include "Exceptions.h" 32 #include "Trace.h" 33 #include "sun_fc.h" 34 35 /** 36 * @memo Create a new TargetEvent listener 37 * @postcondition Listener ready to receive callbacks 38 * @exception BadArgumentException 39 * @param myCallback The listeners callback routine 40 * @param data Opaque data that will be passed to the 41 * callback routine when and event comes in. 42 */ 43 TargetEventListener::TargetEventListener(HBAPort *myPort, 44 TargetCallback myCallback, void *data, uint64_t wwn, bool myFilter) : 45 port(myPort), Listener(data), callback(myCallback), targetPortWWN(wwn), 46 filter(myFilter) { 47 48 Trace log("TargetEventListener::TargetEventListener"); 49 if (callback == NULL) { 50 throw BadArgumentException(); 51 } 52 } 53 54 /** 55 * @memo Send the event to this listener 56 * @param event The event to send to the listener 57 * 58 * @doc The callback registered in the constructor will 59 * be called. 60 */ 61 void TargetEventListener::dispatch(Event &event) { 62 Trace log("TargetEventListener::dispatch"); 63 TargetEvent *e = static_cast<TargetEvent*> (&event); 64 if (e != NULL) { 65 HBA_WWN hbawwn; 66 uint64_t hbalwwn = e->getHBAPortWWN(); 67 // Filter out unwanted events 68 if (port->getPortWWN() != hbalwwn) { 69 return; 70 } 71 if (filter) { 72 if (targetPortWWN != e->getTargetPortWWN()) { 73 return; 74 } 75 } 76 hbalwwn = htonll(hbalwwn); 77 memcpy(&hbawwn, &hbalwwn, sizeof (hbawwn)); 78 HBA_WWN tgtwwn; 79 uint64_t tgtlwwn = htonll(e->getTargetPortWWN()); 80 memcpy(&tgtwwn, &tgtlwwn, sizeof (tgtwwn)); 81 callback(getData(), hbawwn, tgtwwn, e->getType()); 82 } else { 83 log.internalError("Unexpected event type."); 84 } 85 } 86