root/juggler/branches/2.2/modules/gadgeteer/gadget/Reactor.cpp

Revision 20010, 2.7 kB (checked in by aronb, 1 year ago)

Change clustering to be single threaded. This uses a Reactor to do a select on
all sockets.

  • Property svn:eol-style set to native
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  * -----------------------------------------------------------------
26  * File:          $RCSfile$
27  * Date modified: $Date: 2005-01-01 14:59:16 -0600 (Sat, 01 Jan 2005) $
28  * Version:       $Revision: 16524 $
29  * -----------------------------------------------------------------
30  *
31  *************** <auto-copyright.pl END do not edit this line> ***************/
32
33 #include <gadget/gadgetConfig.h>
34
35 #include <gadget/Node.h>
36 #include <gadget/Reactor.h>
37
38
39 namespace gadget
40 {
41
42 void Reactor::addNode(gadget::Node* node)
43 {
44    vpr::IOSys::Handle handle = node->getSockStream()->getHandle();
45
46    if ( mDemuxTable.find(handle) == mDemuxTable.end() )
47    {
48       mDemuxTable[handle] = node;
49       mSelector.addHandle(handle);
50       mSelector.setIn(handle, vpr::Selector::Read);
51    }
52 }
53
54 void Reactor::removeNode(gadget::Node* node)
55 {
56    vpr::IOSys::Handle handle = node->getSockStream()->getHandle();
57
58    typedef std::map<vpr::IOSys::Handle, gadget::Node*>::iterator iter_t;
59    iter_t i = mDemuxTable.find(handle);
60
61    if ( i != mDemuxTable.end() )
62    {
63       mDemuxTable.erase(i);
64       mSelector.removeHandle(handle);
65    }
66 }
67
68 std::vector<gadget::Node*> Reactor::getReadyNodes(const vpr::Interval& timeout)
69 {
70    vpr::Uint16 num_events(0);
71    mSelector.select(num_events, timeout);
72
73    std::vector<gadget::Node*> ready_nodes;
74
75    if ( num_events > 0 )
76    {
77       ready_nodes.reserve(num_events);
78
79       for ( vpr::Uint16 i = 0; i < mSelector.getNumHandles(); ++i )
80       {
81          vpr::IOSys::Handle h         = mSelector.getHandle(i);
82          const vpr::Uint16 event_mask = mSelector.getOut(h);
83
84          if ( 0 != event_mask )
85          {
86             ready_nodes.push_back(mDemuxTable[h]);
87          }
88       }
89    }
90
91    return ready_nodes;
92 }
93
94 }
Note: See TracBrowser for help on using the browser.