root/juggler/branches/2.2/modules/gadgeteer/gadget/DeviceServer.h

Revision 20292, 4.3 kB (checked in by patrick, 1 year ago)

Reduced the potential for expensive object copying and increased const
correctness of gadget::DeviceServer?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 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  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27 #ifndef GADGET_DEVICE_SERVER_H
28 #define GADGET_DEVICE_SERVER_H
29
30 #include <gadget/gadgetConfig.h>
31 #include <cluster/Packets/DataPacket.h>
32 #include <gadget/Type/Input.h>
33 #include <vpr/Sync/Semaphore.h>
34 #include <vpr/Thread/Thread.h>
35
36 namespace gadget
37 {
38    class Node;
39    
40    /** \class DeviceServer DeviceServer.h gadget/DeviceServer.h
41     *
42     * Device server class.
43     */
44    class GADGET_CLASS_API DeviceServer
45    {
46    public:
47       /**
48        * Create a new DeviceServer.
49        *
50        * @param name      Name of the device that we are sharing.
51        * @param device    Pointer to the device that we are sharing.
52        * @param plugin_id GUID that should be placed at the beginning of
53        *                  each data packet so that the receiver knows which
54        *                  plugin the data is coming from.
55        */
56       DeviceServer(const std::string& name, gadget::Input* device,
57                    const vpr::GUID& plugin_id);
58
59       ~DeviceServer();
60
61       void send();
62       void updateLocalData();
63
64       void addClient(gadget::Node* new_client_node);
65       void removeClient(const std::string& host_name);
66
67       /**
68        * Dumps the state of the clients as debug output.
69        *
70        * @pre \c mClientsLock is locked by the calling thread.
71        *
72        * @param debugLevel The debug output level to use for the output.
73        *
74        * @see lockClients()
75        * @see unlockClients()
76        */
77       void debugDump(int debugLevel);
78
79       const std::string& getName() const
80       {
81          return mName;
82       }
83
84       /** Locks the active list.
85        *
86        *  This function blocks until it can lock the std::vector of active
87        *  Nodes.
88        *
89        *  The caller of this method must call unlockActive() when it
90        *  is finished viewing/modifying the active list.
91        */
92       void lockClients()
93       { mClientsLock.acquire(); }
94
95       /** Unlocks the active list.
96        *
97        *  The method releases the lock on the active connections std::vector.
98        *
99        *  The caller of this method must have previously locked the active
100        *  list with lockActive().
101        */
102       void unlockClients()
103       { mClientsLock.release(); }
104
105       const vpr::GUID& getId() const
106       {
107          return mId;
108       }
109
110    private:
111       std::string                         mName;   /**< DeviceServer name */
112       std::vector<gadget::Node*>  mClients;
113       vpr::Mutex                          mClientsLock;   /**< Lock on active config list.*/   
114      
115       gadget::Input*                      mDevice;
116       cluster::DataPacket*                mDataPacket;
117       vpr::BufferObjectWriter*            mBufferObjectWriter;
118       std::vector<vpr::Uint8>*            mDeviceData;
119
120       vpr::Semaphore                      deviceServerTriggerSema;/**< Semaphore for draw trigger */
121       vpr::Semaphore                      deviceServerDoneSema;   /**< Semaphore for drawing done */
122       vpr::Thread*                        mControlThread;
123       bool                                mThreadActive;
124       vpr::GUID                           mId;                    /**< GUID for shared device */
125       vpr::GUID                           mPluginGUID;
126    };
127
128 } // end namespace gadget
129
130 #endif
Note: See TracBrowser for help on using the browser.