Finished monitor
authormike <mike>
Thu, 26 Jul 2001 20:34:06 +0000 (20:34 +0000)
committermike <mike>
Thu, 26 Jul 2001 20:34:06 +0000 (20:34 +0000)
src/Pegasus/Common/Message.cpp
src/Pegasus/Common/Message.h
src/Pegasus/Common/Monitor.cpp
src/Pegasus/Common/Monitor.h

index 6e9a0b952ea443c8c15ef96692a0cdacfd2bf264..231ba26a98bd41cf91555857439f880b10416c96 100644 (file)
@@ -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)
index 4966149186abd4e6463d291d141b8be90df8c1f5..a38e9b114b1490e1cb2c42a98e520980ef4bf526 100644 (file)
@@ -141,6 +141,10 @@ enum MessageType
     CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE,
     CIM_INVOKE_METHOD_RESPONSE_MESSAGE,
 
+    // Monitor-related methods:
+
+    SOCKET_MESSAGE,
+
     NUMBER_OF_MESSAGES
 };
 
index ce8be2553ae6f851bb32db3a5c8d1ada48ea3992..593215e3d1bce2777a395b5661e94af3fab5bdc1 100644 (file)
@@ -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:
 
index 71569ae8471b509545455a671405137c16c9da08..ac1b4722b325aaf9e14c4074332d5c32e2f9ef36 100644 (file)
@@ -32,6 +32,7 @@
 #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Array.h>
 #include <Pegasus/Common/String.h>
+#include <Pegasus/Common/Message.h>
 
 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<MonitorEntry> _entries;
+    Array<_MonitorEntry> _entries;
     MonitorRep* _rep;
 };
 
-PEGASUS_MEMORY_FUNCTIONS(MonitorEntry)
-
 PEGASUS_NAMESPACE_END
 
 #endif /* Pegasus_Monitor_h */