root/juggler/branches/2.2/modules/gadgeteer/gadget/Type/DeviceInterface.cpp

Revision 19729, 5.0 kB (checked in by patrick, 2 years ago)

Copyright update.

  • 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 #include <iomanip>
28
29 #include <gadget/gadgetConfig.h>
30 #include <gadget/Type/DeviceInterface.h>
31 #include <gadget/InputManager.h>
32 #include <gadget/Type/Proxy.h>
33
34 namespace gadget
35 {
36
37 BaseDeviceInterface::BaseDeviceInterface()
38    : mProxyPtr(NULL)
39    , mProxyName("UnInitialized")
40    , mNameSet(false)
41 {
42    // Keep reference to the interface.
43    BaseDeviceInterface::addDevInterface(this);
44 }
45
46 BaseDeviceInterface::~BaseDeviceInterface()
47 {
48    // Remove it from the list of active interfaces.
49    BaseDeviceInterface::removeDevInterface(this);
50 }
51
52
53 BaseDeviceInterface::BaseDeviceInterface(const BaseDeviceInterface& other)
54    : mProxyPtr(other.mProxyPtr)
55    , mProxyName(other.mProxyName)
56    , mNameSet(other.mNameSet)
57 {
58    // Keep reference to the interface.
59    BaseDeviceInterface::addDevInterface(this);
60 }
61
62 void BaseDeviceInterface::init(const std::string& proxyName)
63 {
64    mProxyName = proxyName;    // Set the name
65    mNameSet = true;
66    refresh();                 // Refresh the name
67 }
68
69 // NOTE: If the interface does not have an initialized mProxyName, then
70 // don't try to refresh it.
71 void BaseDeviceInterface::refresh()
72 {
73    Proxy* prev_proxy_ptr = mProxyPtr;    // Keep track of previous value
74
75    // If it is not initialized, then don't try
76    if ( ! mNameSet )
77    {
78       return;
79    }
80
81    mProxyPtr = InputManager::instance()->getProxy(mProxyName);
82
83    if (NULL == mProxyPtr)
84    {
85       vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
86          << "WARNING: DeviceInterface::refresh: could not find proxy: "
87          << mProxyName.c_str() << std::endl << vprDEBUG_FLUSH;
88       vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
89          << "         Make sure the proxy exists in the current configuration."
90          << std::endl << vprDEBUG_FLUSH;
91       vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
92          << "   referencing device interface will be stupefied to point at dummy device."
93          << std::endl << vprDEBUG_FLUSH;
94    }
95    // ASSERT: We have just gotten a valid proxy to point to
96    else if((NULL != mProxyPtr) && (NULL == prev_proxy_ptr))
97    {
98       const int item_width(25+12);
99       //const int type_width(20);
100
101       //vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL)
102       //   << "DeviceInterface now able to find proxy: "
103       //   << mProxyName.c_str() << "               [ "
104       //   << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]"
105       //   << std::endl << vprDEBUG_FLUSH;
106
107       //std::string device_name("");
108       //Input* deviceptr = mProxyPtr->getProxiedInputDevice();
109       //if (NULL != deviceptr)
110       //{
111       //   device_name = deviceptr->getInstanceName();
112       //}
113
114       vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL)
115          << "DeviceInterface found proxy: "
116          << std::setiosflags(std::ios::right)
117          << std::setfill(' ') << std::setw(item_width) << mProxyName
118          << std::resetiosflags(std::ios::right) << "  ";
119       vprDEBUG_CONTnl(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL)
120          << "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]";
121       vprDEBUG_CONTnl(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL)
122          << std::endl << vprDEBUG_FLUSH;
123    }
124 }
125
126 void BaseDeviceInterface::addDevInterface(BaseDeviceInterface* dev)
127 {
128    mAllocatedDevices.push_back(dev);
129 }
130
131 void BaseDeviceInterface::removeDevInterface(BaseDeviceInterface* dev)
132 {
133    // Attempt to find the device, if found, erase it, if not, then assert
134    std::vector<BaseDeviceInterface*>::iterator found_dev =
135       std::find(mAllocatedDevices.begin(), mAllocatedDevices.end(), dev);
136    vprASSERT(found_dev != mAllocatedDevices.end() &&
137              "Tried to remove non-registered interface");
138
139    if ( mAllocatedDevices.end() != found_dev )
140    {
141       mAllocatedDevices.erase(found_dev);
142    }
143 }
144
145 void BaseDeviceInterface::refreshAllInterfaces()
146 {
147    for ( unsigned int i = 0; i < mAllocatedDevices.size(); ++i )
148    {
149       BaseDeviceInterface* dev = mAllocatedDevices[i];
150       dev->refresh();
151    }
152 }
153
154 std::vector<BaseDeviceInterface*> BaseDeviceInterface::mAllocatedDevices;
155
156 } // End of gadget namespace
157
Note: See TracBrowser for help on using the browser.