2 * Copyright (c) 2011, 2012, 2013, 2014 Spectra Logic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * substantially similar to the "NO WARRANTY" disclaimer below
13 * ("Disclaimer") and any redistribution must be conditioned upon
14 * including a substantially similar Disclaimer requirement for further
15 * binary redistribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGES.
30 * Authors: Justin T. Gibbs (Spectra Logic Corporation)
36 * \file devdctl_consumer.h
38 #ifndef _DEVDCTL_CONSUMER_H_
39 #define _DEVDCTL_CONSUMER_H_
41 /*============================ Namespace Control =============================*/
45 /*=========================== Forward Declarations ===========================*/
48 /*============================ Class Declarations ============================*/
49 /*----------------------------- DevdCtl::Consumer ----------------------------*/
56 Consumer(Event::BuildMethod *defBuilder = NULL,
57 EventFactory::Record *regEntries = NULL,
58 size_t numEntries = 0);
61 bool Connected() const;
64 * Return file descriptor useful for client's wishing to poll(2)
70 * Queue an event for deferred processing or replay.
72 bool SaveEvent(const Event &event);
75 * Reprocess any events saved via the SaveEvent() facility.
77 * \param discardUnconsumed If true, events that are not consumed
78 * during replay are discarded.
80 void ReplayUnconsumedEvents(bool discardUnconsumed);
82 /** Return an event, if one is available. */
86 * Extract events and invoke each event's Process method.
90 /** Discard all data pending in m_devdSockFD. */
94 * Test for data pending in m_devdSockFD
96 * \return True if data is pending. Otherwise false.
101 * Open a connection to devd's unix domain socket.
103 * \return True if the connection attempt is successsful. Otherwise
106 bool ConnectToDevd();
109 * Close a connection (if any) to devd's unix domain socket.
111 void DisconnectFromDevd();
113 EventFactory GetFactory();
117 * \brief Reads the most recent record
119 * On error, "" is returned, and errno will be set by the OS
121 * \returns A string containing the record
123 std::string ReadEvent();
127 * The maximum event size supported by libdevdctl.
129 MAX_EVENT_SIZE = 8192,
132 static const char s_devdSockPath[];
135 * File descriptor representing the unix domain socket
136 * connection with devd.
140 EventFactory m_eventFactory;
142 /** Queued events for replay. */
143 EventList m_unconsumedEvents;
146 * Flag controlling whether events can be queued. This boolean
147 * is set during event replay to ensure that previosuly deferred
148 * events are not requeued and thus retained forever.
150 bool m_replayingEvents;
153 //- Consumer Const Public Inline Methods ---------------------------------------
155 Consumer::Connected() const
157 return (m_devdSockFD != -1);
160 //- Consumer Public Inline Methods ---------------------------------------------
162 Consumer::GetPollFd()
164 return (m_devdSockFD);
168 Consumer::GetFactory()
170 return (m_eventFactory);
173 } // namespace DevdCtl
174 #endif /* _DEVDCTL_CONSUMER_H_ */