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 #ifndef	_FCSYSEVENTBRIDGE_H
27 #define	_FCSYSEVENTBRIDGE_H
28 
29 
30 
31 #include "AdapterAddEventBridge.h"
32 #include "AdapterEventBridge.h"
33 #include "AdapterPortEventBridge.h"
34 #include "AdapterDeviceEventBridge.h"
35 #include "TargetEventBridge.h"
36 #include "Lockable.h"
37 #include <vector>
38 #include <libsysevent.h>
39 
40 /**
41  * Note: Even though we take various arguments in within the API,
42  * we don't actually filter anything, since sys-even is either on
43  * or off.  The idea is that the actual Listener themselves will perform
44  * a final filter pass, so why do the work twice.  If we were going to
45  * use proprietary IOCTLs or some other event plumbing that allowed filtering,
46  * we could use the passed in arguments to do useful work.  In short,
47  * once turned on, we send events of a given type and rely on
48  * someone downstream to filter.
49  */
50 class FCSyseventBridge :
51 	public AdapterAddEventBridge,
52 	public AdapterEventBridge,
53 	public AdapterPortEventBridge,
54 	public AdapterDeviceEventBridge,
55 	public TargetEventBridge,
56 	public Lockable {
57 public:
58     static FCSyseventBridge* getInstance();
59     virtual int32_t getMaxListener();
60     virtual void addListener(AdapterAddEventListener *listener);
61     virtual void addListener(AdapterEventListener *listener, HBA *hba);
62     virtual void addListener(AdapterPortEventListener *listener, HBAPort *port);
63     virtual void addListener(AdapterDeviceEventListener *listener,
64 	     HBAPort *port);
65     virtual void addListener(TargetEventListener *listener,
66 	    HBAPort *port, uint64_t targetWWN, bool filter);
67     virtual void removeListener(AdapterAddEventListener *listener);
68     virtual void removeListener(AdapterEventListener *listener);
69     virtual void removeListener(AdapterPortEventListener *listener);
70     virtual void removeListener(AdapterDeviceEventListener *listener);
71     virtual void removeListener(TargetEventListener *listener);
72 
73     /* Private function, called by handler.  Friend maybe? */
74     void dispatch(sysevent_t *ev);
75 
76 private:
FCSyseventBridge()77     FCSyseventBridge() :handle(NULL) { }
78     /**
79      * Subscribe if we need to, or unsubscribe if nobody is left
80      * Instance lock must already be held!
81      */
82     void validateRegistration();
83     sysevent_handle_t *handle;
84     static FCSyseventBridge*	_instance;
85 
86 
87     std::vector<AdapterAddEventListener*>	adapterAddEventListeners;
88     std::vector<AdapterEventListener*>		adapterEventListeners;
89     std::vector<AdapterPortEventListener*>	adapterPortEventListeners;
90     std::vector<AdapterDeviceEventListener*>	adapterDeviceEventListeners;
91     std::vector<TargetEventListener*>		targetEventListeners;
92 };
93 
94 #endif /* _FCSYSEVENTBRIDGE_H */
95