From: mike Date: Thu, 26 Jul 2001 20:34:06 +0000 (+0000) Subject: Finished monitor X-Git-Tag: old_repository~8 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=ac4dd87b06cfbbd279502578121654fc969eceb1;p=tpot%2Fpegasus%2F.git Finished monitor --- diff --git a/src/Pegasus/Common/Message.cpp b/src/Pegasus/Common/Message.cpp index 6e9a0b952..231ba26a9 100644 --- a/src/Pegasus/Common/Message.cpp +++ b/src/Pegasus/Common/Message.cpp @@ -94,7 +94,8 @@ static const char* _MESSAGE_TYPE_STRINGS[] = "CIM_SET_QUALIFIER_RESPONSE_MESSAGE", "CIM_DELETE_QUALIFIER_RESPONSE_MESSAGE", "CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE", - "CIM_INVOKE_METHOD_RESPONSE_MESSAGE" + "CIM_INVOKE_METHOD_RESPONSE_MESSAGE", + "SOCKET_MESSAGE", }; const char* MessageTypeToString(Uint32 messageType) diff --git a/src/Pegasus/Common/Message.h b/src/Pegasus/Common/Message.h index 496614918..a38e9b114 100644 --- a/src/Pegasus/Common/Message.h +++ b/src/Pegasus/Common/Message.h @@ -141,6 +141,10 @@ enum MessageType CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE, CIM_INVOKE_METHOD_RESPONSE_MESSAGE, + // Monitor-related methods: + + SOCKET_MESSAGE, + NUMBER_OF_MESSAGES }; diff --git a/src/Pegasus/Common/Monitor.cpp b/src/Pegasus/Common/Monitor.cpp index ce8be2553..593215e3d 100644 --- a/src/Pegasus/Common/Monitor.cpp +++ b/src/Pegasus/Common/Monitor.cpp @@ -36,22 +36,6 @@ PEGASUS_USING_STD; PEGASUS_NAMESPACE_BEGIN -//////////////////////////////////////////////////////////////////////////////// -// -// Local routines: -// -//////////////////////////////////////////////////////////////////////////////// - -static inline int select_wrapper( - int nfds, - fd_set* rd_fd_set, - fd_set* wr_fd_set, - fd_set* ex_fd_set, - const struct timeval* tv) -{ - return select(FD_SETSIZE, rd_fd_set, wr_fd_set, ex_fd_set, tv); -} - //////////////////////////////////////////////////////////////////////////////// // // Routines for starting and stoping socket interface. @@ -60,7 +44,7 @@ static inline int select_wrapper( extern Uint32 _socketInterfaceInitCount; -static void _SocketInterfaceInc() +static void _OpenSocketInterface() { if (_socketInterfaceInitCount == 0) { @@ -73,7 +57,7 @@ static void _SocketInterfaceInc() _socketInterfaceInitCount++; } -static void _SocketInterfaceDec() +static void _CloseSocketInterface() { _socketInterfaceInitCount--; @@ -105,7 +89,7 @@ struct MonitorRep Monitor::Monitor() { - _SocketInterfaceInc(); + _OpenSocketInterface(); _rep = new MonitorRep; FD_ZERO(&_rep->rd_fd_set); @@ -116,17 +100,12 @@ Monitor::Monitor() FD_ZERO(&_rep->active_ex_fd_set); } -MonitorHandler::~MonitorHandler() -{ - _SocketInterfaceDec(); -} - Monitor::~Monitor() { - delete _rep; + _CloseSocketInterface(); } -Boolean Monitor::select(Uint32 milliseconds) +Boolean Monitor::run(Uint32 milliseconds) { // Windows select() has a strange little bug. It returns immediately if // there are no descriptors in the set even if the timeout is non-zero. @@ -150,7 +129,7 @@ Boolean Monitor::select(Uint32 milliseconds) const Uint32 USEC = (milliseconds % 1000) * 1000; struct timeval tv = { SEC, USEC }; - count = select_wrapper( + count = select( FD_SETSIZE, &_rep->active_rd_fd_set, &_rep->active_wr_fd_set, @@ -172,13 +151,13 @@ Boolean Monitor::select(Uint32 milliseconds) Uint32 events = 0; if (FD_ISSET(socket, &_rep->active_rd_fd_set)) - events |= READ; + events |= SocketMessage::READ; if (FD_ISSET(socket, &_rep->active_wr_fd_set)) - events |= WRITE; + events |= SocketMessage::WRITE; if (FD_ISSET(socket, &_rep->active_ex_fd_set)) - events |= EXCEPTION; + events |= SocketMessage::EXCEPTION; if (events) { @@ -187,17 +166,17 @@ Boolean Monitor::select(Uint32 milliseconds) if (!queue) unsolicitSocketMessages(_entries[i].queueId); - if (events & WRITE) + if (events & SocketMessage::WRITE) { FD_CLR(socket, &_rep->active_wr_fd_set); } - if (events & EXCEPTION) + if (events & SocketMessage::EXCEPTION) { FD_CLR(socket, &_rep->active_ex_fd_set); } - if (events & READ) + if (events & SocketMessage::READ) { FD_CLR(socket, &_rep->active_rd_fd_set); } @@ -213,24 +192,24 @@ Boolean Monitor::select(Uint32 milliseconds) Boolean Monitor::solicitSocketMessages( Sint32 socket, Uint32 events, - Uint32 queueId); + Uint32 queueId) { // See whether a handler is already registered for this one: Uint32 pos = _findEntry(socket); - if (pos != PEGUSUS_NOT_FOUND) + if (pos != PEGASUS_NOT_FOUND) return false; // Set the events: - if (events & READ) + if (events & SocketMessage::READ) FD_SET(socket, &_rep->rd_fd_set); - if (events & WRITE) + if (events & SocketMessage::WRITE) FD_SET(socket, &_rep->wr_fd_set); - if (events & EXCEPTION) + if (events & SocketMessage::EXCEPTION) FD_SET(socket, &_rep->ex_fd_set); // Add the entry to the list: @@ -243,7 +222,7 @@ Boolean Monitor::solicitSocketMessages( return true; } -Boolean Monitor::unolicitSocketMessages(Sint32 socket) +Boolean Monitor::unsolicitSocketMessages(Sint32 socket) { // Look for the given entry and remove it: diff --git a/src/Pegasus/Common/Monitor.h b/src/Pegasus/Common/Monitor.h index 71569ae84..ac1b4722b 100644 --- a/src/Pegasus/Common/Monitor.h +++ b/src/Pegasus/Common/Monitor.h @@ -32,6 +32,7 @@ #include #include #include +#include PEGASUS_NAMESPACE_BEGIN @@ -44,18 +45,18 @@ struct _MonitorEntry struct MonitorRep; /** This message occurs when there is activity on a socket. */ -class SocketMessage +class SocketMessage : public Message { public: + enum Events { READ = 1, WRITE = 2, EXCEPTION = 4 }; + SocketMessage(Events events_, Uint32 socket_) : Message(SOCKET_MESSAGE), events(events_), socket(socket_) { } - enum Events { READ = 1, WRITE = 2, EXCEPTION = 4 }; - Uint32 events; Uint32 socket; @@ -126,7 +127,6 @@ public: whichever occurs first. @param timeoutMsec the number of milliseconds to wait for an event. - @return true if an event occured. */ Boolean run(Uint32 timeoutMsec); @@ -135,12 +135,9 @@ public: be one solicitor per socket. @param socket the socket to monitor for activity. - @param events socket events to monitor (see the SocketMessage::Events enumeration for details). - @param queueId of queue on which to post socket messages. - @return false if messages have already been solicited on this socket. */ Boolean solicitSocketMessages( @@ -149,21 +146,20 @@ public: Uint32 queueId); /** Unsolicit messages on the given socket. + @param socket on which to unsolicit messages. @return false if no such solicitation has been made on the given socket. */ - Boolean unolicitSocketMessages(Sint32 socket); + Boolean unsolicitSocketMessages(Sint32 socket); private: Uint32 _findEntry(Sint32 socket) const; - Array _entries; + Array<_MonitorEntry> _entries; MonitorRep* _rep; }; -PEGASUS_MEMORY_FUNCTIONS(MonitorEntry) - PEGASUS_NAMESPACE_END #endif /* Pegasus_Monitor_h */