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

Revision 20291, 24.2 kB (checked in by patrick, 1 year ago)

Fixed a potential mutex deadlock. To do this, I changed the pre-condition of
gadget::DeviceServer::debugDump() so that mClientsLock must be held prior to
calling this method. This is not exactly ideal, but the alternative is to
reduce the exception safety guarantee of gadget::DeviceServer::send(), and
that seems like a much worse scenario.

  • 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 <gadget/gadgetConfig.h>
28 #include <gadget/Util/Debug.h>
29
30 #include <gadget/RemoteInputManager.h>
31
32 // Sharing Devices
33 #include <gadget/Type/BaseTypeFactory.h>
34 #include <gadget/VirtualDevice.h>
35 #include <gadget/DeviceServer.h>
36 #include <gadget/Type/DeviceFactory.h>
37 #include <gadget/InputManager.h>
38
39 #include <gadget/Node.h>
40 #include <cluster/ClusterManager.h>
41
42 // IO Packets
43 #include <cluster/Packets/PacketFactory.h>
44 #include <cluster/Packets/ConnectionRequest.h>
45 #include <cluster/Packets/DeviceRequest.h>
46 #include <cluster/Packets/DeviceAck.h>
47 #include <cluster/Packets/ApplicationDataRequest.h>
48 #include <cluster/Packets/EndBlock.h>
49 #include <cluster/Packets/DataPacket.h>
50
51 // Configuration
52 #include <jccl/RTRC/ConfigManager.h>
53 #include <jccl/Config/ConfigElement.h>
54
55 #include <map>
56
57 /*
58 extern "C"
59 {
60    GADGET_CLUSTER_PLUGIN_EXPORT(void) initPlugin(cluster::ClusterManager* mgr)
61    {
62       mgr->addPlugin(new cluster::RemoteInputManager());
63    }
64 }
65 */
66
67 namespace gadget
68 {
69    RemoteInputManager::RemoteInputManager(const vpr::GUID& guid) : mHandlerGUID(guid)
70    {
71       //mReconfigurationNeededOnConnection = false;
72    }
73
74    RemoteInputManager::~RemoteInputManager()
75    {
76       for ( std::map<vpr::GUID, VirtualDevice*>::iterator j = mVirtualDevices.begin(); j != mVirtualDevices.end(); j++ )
77       {
78          if ( (*j).second != NULL )
79          {
80             delete (*j).second;
81          }
82       }
83       for ( std::vector<DeviceServer*>::iterator j = mDeviceServers.begin(); j != mDeviceServers.end(); j++ )
84       {
85          if ( (*j) != NULL )
86          {
87             delete (*j);
88          }
89       }
90    }
91
92    void RemoteInputManager::recoverFromLostNode(Node* lost_node)
93    {
94       removeVirtualDevicesOnHost(lost_node->getHostname());
95       removeDeviceClientsForHost(lost_node->getHostname());
96
97       // Since we have lost a connection we need to set a flag so
98       // that when we gain a new connection we will reconfigure.
99       //mReconfigurationNeededOnConnection = true;
100    }
101
102    /**
103     * Handle a incoming packet.
104     */
105    void RemoteInputManager::handlePacket(cluster::Packet* packet, Node* node)
106    {
107       //We are only handling data packets right now.
108       if ( NULL != packet && NULL != node )
109       {
110          switch ( packet->getPacketType() )
111          {
112          case cluster::Header::RIM_DEVICE_REQ:
113             {
114                cluster::DeviceRequest* temp_device_request = dynamic_cast<cluster::DeviceRequest*>(packet);
115                vprASSERT(NULL != temp_device_request && "Dynamic cast failed!");
116                std::string device_name = temp_device_request->getDeviceName();
117
118                if ( jccl::ConfigManager::instance()->isPendingStale() )
119                {
120                   gadget::Input* temp_input_device = gadget::InputManager::instance()->getDevice(device_name);
121                   if ( temp_input_device != NULL )
122                   {
123                      DeviceServer* temp_device_server = getDeviceServer(device_name);
124                      if ( NULL == temp_device_server )
125                      {
126                         addDeviceServer(device_name, temp_input_device);
127                         temp_device_server = getDeviceServer(device_name);
128                      }
129
130                      temp_device_server->addClient(node);
131
132                      // Create a responce ACK
133                      std::string temp_string = temp_input_device->getInputTypeName();
134                      vpr::GUID   temp_guid   = temp_device_server->getId();
135                      cluster::DeviceAck* temp_ack =
136                         new cluster::DeviceAck(mHandlerGUID, temp_guid,
137                                                device_name, temp_string, true);
138                      node->send(temp_ack);
139                      delete temp_ack;
140                   }
141                   else
142                   {
143                      std::string temp_string = "";
144                      vpr::GUID empty_id;
145                      cluster::DeviceAck* temp_ack =
146                         new cluster::DeviceAck(mHandlerGUID, empty_id, device_name,
147                                                temp_string/*BaseType*/, false);
148                      node->send(temp_ack);
149                      delete temp_ack;
150                   }
151                }
152                else
153                {
154                   vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
155                   << clrOutBOLD(clrRED,"Pending List is not stale(Config Manager is still configuring the local system) ")
156                   << clrOutBOLD(clrRED,"So we can not process this device request right now.") << std::endl << vprDEBUG_FLUSH;
157
158                   std::string temp_string = "";
159                   vpr::GUID empty_id;
160                   cluster::DeviceAck* temp_ack =
161                      new cluster::DeviceAck(mHandlerGUID, empty_id, device_name,
162                                             temp_string/*BaseType*/, false);
163                   node->send(temp_ack);
164                   delete temp_ack;
165                }
166                break;
167             }
168          case cluster::Header::RIM_DEVICE_ACK:
169             {
170                // -If ACK
171                //   -Create VirtualDevice
172                // -If Nack
173                //   -Do nothing(let the config manager worry about re-trying)
174
175                cluster::DeviceAck* temp_device_ack = dynamic_cast<cluster::DeviceAck*>(packet);
176                vprASSERT(NULL != temp_device_ack && "Dynamic cast failed!");
177                std::string device_name = temp_device_ack->getDeviceName();
178
179                if ( temp_device_ack->getAck() )
180                {
181                   removePendingDeviceRequest(device_name);
182
183                   if ( getVirtualDevice(device_name) != NULL )
184                   {
185                      vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << clrOutBOLD(clrRED, "ERROR:")
186                      << "Somehow we already have a virtual device named: " << device_name << std::endl << vprDEBUG_FLUSH;
187                   }
188                   else
189                   {
190                      addVirtualDevice(temp_device_ack->getId(), device_name,
191                                       temp_device_ack->getDeviceBaseType(),
192                                       temp_device_ack->getHostname());
193
194                      // Add this virtual device to the InputManager's list of devices.
195                      gadget::InputManager::instance()->addRemoteDevice(getVirtualDevice(device_name), device_name);
196                   }
197                }
198                else
199                {  //XXX: FIX
200                   // Do Nothing Since we will just re-try later
201                   //createPendingConfigRemoveAndAdd(mDeviceName);
202                   //jccl::ConfigManager::instance()->delayStalePendingList();
203                }
204                break;
205             }
206          case cluster::Header::RIM_DATA_PACKET:
207             {
208                cluster::DataPacket* temp_data_packet = dynamic_cast<cluster::DataPacket*>(packet);
209                vprASSERT(NULL != temp_data_packet && "Dynamic cast failed!");
210
211                //vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << "RIM::handlePacket()..." << std::endl <<  vprDEBUG_FLUSH;
212                //temp_data_packet->printData(1);
213
214                gadget::Input* virtual_device = getVirtualDevice(temp_data_packet->getObjectId());
215                if ( virtual_device != NULL )
216                {
217                   vpr::BufferObjectReader* temp_reader = new vpr::BufferObjectReader(temp_data_packet->getDeviceData());
218
219                   temp_reader->setAttrib("rim.timestamp.delta", node->getDelta());
220                   virtual_device->readObject(temp_reader);
221                   delete temp_reader;
222                }
223                break;
224             }
225          default:
226             {
227                std::cout << "RIM DOES NOT HANDLE THIS PACKET TYPE" << packet->getPacketType() << std::endl;
228                break;
229             }
230          } // End switch
231       } // End if
232    }
233
234
235    bool RemoteInputManager::addVirtualDevice(const vpr::GUID& device_id,
236                                              const std::string& name,
237                                              const std::string& device_base_type,
238                                              const std::string& hostname)
239    {
240       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
241
242       vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
243       << clrOutBOLD(clrMAGENTA, "[RemoteInputManager]")
244       << "Creating Virtual Device: " << name << std::endl << vprDEBUG_FLUSH;
245
246       gadget::Input* temp_input_device = gadget::BaseTypeFactory::instance()->loadNetDevice(device_base_type);
247       VirtualDevice* temp_virtual_device = new VirtualDevice(name, device_id, device_base_type, hostname, temp_input_device);
248
249       mVirtualDevices[device_id] = temp_virtual_device;
250
251       return true;
252    }
253
254    void RemoteInputManager::addVirtualDevice(VirtualDevice* device)
255    {
256       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
257
258       mVirtualDevices[device->getId()] = device;
259    }
260
261    gadget::Input* RemoteInputManager::getVirtualDevice(const vpr::GUID& device_id)
262    {
263       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
264
265       for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin();
266           i != mVirtualDevices.end() ; i++ )
267       {
268          if ( (*i).first == device_id )
269          {
270             return((*i).second->getDevice());
271          }
272       }
273       return NULL;
274    }
275
276    gadget::Input* RemoteInputManager::getVirtualDevice(const std::string& device_name)
277    {
278       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
279
280       for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin();
281           i != mVirtualDevices.end() ; i++ )
282       {
283          if ( (*i).second->getName() == device_name )
284          {
285             return((*i).second->getDevice());
286          }
287       }
288       return NULL;
289    }
290
291    bool RemoteInputManager::
292    removeVirtualDevicesOnHost(const std::string& host_name)
293    {
294       // - Get a list of all remote devices on the given host
295       // - Remove them from the current configuration
296       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
297
298       std::vector<std::string> devices_to_remove;
299       for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin();
300           i != mVirtualDevices.end() ; i++ )
301       {
302          if ( (*i).second->getRemoteHostname() == host_name )
303          {
304             devices_to_remove.push_back((*i).second->getName());
305          }
306       }
307
308       for ( std::vector<std::string>::iterator i = devices_to_remove.begin();
309           i != devices_to_remove.end();i++ )
310       {
311          // We could just remove it here, but for the sake of testing RTRC
312          // we will create a pending remove
313          // removeVirtualDevice(*i);
314          createPendingConfigRemoveAndAdd(*i);
315       }
316       return true;
317    }
318
319    bool RemoteInputManager::
320    removeDeviceClientsForHost(const std::string& host_name)
321    {
322       // Loop through all Device Servers and remove any device clients that
323       // may exist for the given host
324       vpr::Guard<vpr::Mutex> guard(mDeviceServersLock);
325
326       vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
327          << clrOutBOLD(clrMAGENTA,"[RemoteInputManager]")
328          << " Removing client, " << host_name << " from all Device Servers.\n"
329          << vprDEBUG_FLUSH;
330
331       for ( std::vector<DeviceServer*>::iterator i = mDeviceServers.begin();
332           i != mDeviceServers.end() ; i++ )
333       {
334          (*i)->removeClient(host_name);
335       }
336       return true;
337    }
338
339    void RemoteInputManager::removeVirtualDevice(const vpr::GUID& device_id)
340    {
341       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
342
343       for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin();
344           i != mVirtualDevices.end() ; i++ )
345       {
346          if ( (*i).first == device_id )
347          {
348             // Remove remote device from the InputManager
349             gadget::InputManager::instance()->removeDevice((*i).second->getName());
350             delete (*i).second;
351             mVirtualDevices.erase(i);
352             return;
353          }
354       }
355    }
356
357    void RemoteInputManager::removeVirtualDevice(const std::string& device_name)
358    {
359       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
360
361       // Remove remote device from the InputManager
362       gadget::InputManager::instance()->removeDevice(device_name);
363
364       for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin();
365           i != mVirtualDevices.end() ; i++ )
366       {
367          if ( (*i).second->getName() == device_name )
368          {
369             (*i).second->debugDump(vprDBG_CONFIG_LVL);
370             delete (*i).second;
371             mVirtualDevices.erase(i);
372             return;
373          }
374       }
375    }
376
377    void RemoteInputManager::debugDumpVirtualDevices(int debug_level)
378    {
379       vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock);
380
381       vpr::DebugOutputGuard dbg_output(gadgetDBG_RIM,debug_level,
382                                        std::string("-------------- Virtual Devices --------------\n"),
383                                        std::string("---------------------------------------------\n"));
384       for ( std::map<vpr::GUID, VirtualDevice*>::iterator j = mVirtualDevices.begin(); j != mVirtualDevices.end(); j++ )
385       {
386          (*j).second->debugDump(debug_level);
387       }
388    }
389
390
391    // ===================== DEVICE SERVERS =============================
392
393    bool RemoteInputManager::addDeviceServer(const std::string& name,
394                                             gadget::Input* device)
395    {
396       vpr::Guard<vpr::Mutex> guard(mDeviceServersLock);
397
398       DeviceServer* temp_device_server =
399          new DeviceServer(name, device, mHandlerGUID);
400       mDeviceServers.push_back(temp_device_server);
401
402       return true;
403    }
404
405    void RemoteInputManager::addDeviceServer(DeviceServer* device)
406    {
407       vpr::Guard<vpr::Mutex> guard(mDeviceServersLock);
408       mDeviceServers.push_back(device);
409    }
410
411    DeviceServer* RemoteInputManager::getDeviceServer(const std::string& device_name)
412    {
413       vpr::Guard<vpr::Mutex> guard(mDeviceServersLock);
414
415       for ( std::vector<DeviceServer*>::iterator i = mDeviceServers.begin();
416           i != mDeviceServers.end() ; i++ )
417       {
418          if ( (*i)->getName() == device_name )
419          {
420             return(*i);
421          }
422       }
423       return NULL;
424    }
425
426    void RemoteInputManager::removeDeviceServer(const std::string& device_name)
427    {
428       vpr::Guard<vpr::Mutex> guard(mDeviceServersLock);
429
430       for ( std::vector<DeviceServer*>::iterator i = mDeviceServers.begin();
431           i != mDeviceServers.end() ; i++ )
432       {
433          if ( (*i)->getName() == device_name )
434          {
435             delete (*i);
436             mDeviceServers.erase(i);
437             return;
438          }
439       }
440    }
441
442    void RemoteInputManager::debugDumpDeviceServers(int debug_level)
443    {
444       vpr::Guard<vpr::Mutex> guard(mDeviceServersLock);
445
446       vpr::DebugOutputGuard dbg_output(gadgetDBG_RIM,debug_level,
447                                        std::string("-------------- Device Servers --------------\n"),
448                                        std::string("---------------------------------------------\n"));
449       for ( std::vector<DeviceServer*>::iterator j = mDeviceServers.begin(); j != mDeviceServers.end(); j++ )
450       {
451          (*j)->lockClients();
452          (*j)->debugDump(debug_level);
453          (*j)->unlockClients();
454       }
455    }
456
457    void RemoteInputManager::sendDataAndSync()
458    {
459       //      vpr::Interval first;
460       //      vpr::Interval second;
461
462       //      std::cout << "Number Device Servers: " << mDeviceServers.size() << " Number Virtual Devices" << mVirtualDevices.size() << std::endl;
463
464       vpr::Guard<vpr::Mutex> guard(mDeviceServersLock);
465
466       // Update all local device servers and send their data.
467       for ( unsigned int i=0; i<mDeviceServers.size(); i++ )
468       {
469          mDeviceServers[i]->updateLocalData();
470          mDeviceServers[i]->send();
471       }
472
473       //      second.setNow();
474       //      vpr::Interval diff_time4(second-first);
475       //      std::cout << "Recv DeviceData Time: " << diff_time4.getBaseVal() << std::endl;
476
477    }
478
479    //////////////////////////
480    //    CONFIG METHODS    //
481    //////////////////////////
482
483    /** Add the pending element to the configuration.
484     *  @pre configCanHandle (element) == true.
485     *  @return true iff element was successfully added to configuration.
486     */
487    /*
488    bool RemoteInputManager::configAdd(jccl::ConfigElementPtr element)
489    {
490       if ( ClusterManager::instance()->recognizeRemoteDeviceConfig(element) )
491       {
492          std::string device_host = element->getProperty<std::string>("device_host");
493          Node* node = cluseter::ClusterManager::instance()->getNetwork()->getNodeByName(device_host);
494          std::string device_name = element->getName();
495
496          vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << clrOutBOLD(clrCYAN,"[RemoteInputManager] ")
497          << "Adding the Remote Device: " << device_name
498          << " to the RIM Pending List\n" << vprDEBUG_FLUSH;
499
500          if ( node == NULL )
501          {
502             vprDEBUG(gadgetDBG_RIM,vprDBG_CRITICAL_LVL)
503             << clrOutBOLD(clrCYAN,"[RemoteInputManager] ")
504             << clrOutBOLD(clrRED," ERROR: ")
505             << "Cluster node: " << device_host
506             << " does not exist! This is not possible since having a connection"
507             << " is a dependancy of this config element." << std::endl << vprDEBUG_FLUSH;
508             return false;
509          }
510          else if ( !node->isConnected() )
511          {
512             vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << clrOutBOLD(clrCYAN,"[RemoteInputManager] ")
513             << "Cluster node: " << device_host
514             << " is not connected! WE SHOULD NEVER REACH THIS HERE!!!!\n" << vprDEBUG_FLUSH;
515             return false;
516          }
517
518          cluster::DeviceRequest* device_req = new DeviceRequest(mHandlerGUID, device_name);
519          //device_req->send(node->getSockStream());
520          //delete device_req;
521          //node->addDeviceRequest(device_req);
522          addPendingDeviceRequest(device_req, node);
523          return(true);
524       }
525       else
526       {
527          vprDEBUG(gadgetDBG_RIM,vprDBG_CRITICAL_LVL)
528          << clrOutBOLD(clrRED,"[RemoteInputManager::ConfigAdd] ERROR, Something is seriously wrong, we should never get here\n")
529          << vprDEBUG_FLUSH;
530          return(false);
531       }
532    }
533    */
534
535
536    /** Remove the pending element from the current configuration.
537     *  @pre configCanHandle (element) == true.
538     *  @return true iff the element (and any objects it represented)
539     *          were successfully removed.
540     */
541    /*
542    bool RemoteInputManager::configRemove(jccl::ConfigElementPtr element)
543    {
544       if ( ClusterManager::instance()->recognizeRemoteDeviceConfig(element) )
545       {
546          vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << clrOutBOLD(clrCYAN,"[RemoteInputManager] ")
547          << "Removing the Remote Device: " << element->getName()
548          << " from the active configuration \n" << vprDEBUG_FLUSH;
549
550          removeVirtualDevice(element->getName());
551          if ( this->mVirtualDevices.size()== 0 && mDeviceServers.size() == 0 )
552          {
553          }
554          return(true);
555       }
556       else
557       {
558          vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << "[RemoteInputManager::configRemove] ERROR, Something is seriously wrong, we should never get here\n"
559          << vprDEBUG_FLUSH;
560          return(false);
561       }
562    }
563    */
564
565
566    /** Checks if this handler can process element.
567     *  Typically, an implementation of handler will check the element's
568     *  description name/token to decide if it knows how to deal with
569     *  it.
570     *  @return true iff this handler can process element.
571     */
572    /*
573    bool RemoteInputManager::configCanHandle(jccl::ConfigElementPtr element)
574    {
575       return ClusterManager::instance()->recognizeRemoteDeviceConfig(element);
576    }
577    */
578
579    vpr::Uint16 RemoteInputManager::getNumberPendingDeviceRequests()
580    {
581       vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock);
582       return(mPendingDeviceRequests.size());
583    }
584
585    bool RemoteInputManager::createPendingConfigRemove(std::string device_name)
586    {
587       jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance();
588
589       cfg_mgr->lockActive();
590       std::vector<jccl::ConfigElementPtr>::iterator active_begin = cfg_mgr->getActiveBegin();
591       std::vector<jccl::ConfigElementPtr>::iterator active_end   = cfg_mgr->getActiveEnd();
592       std::vector<jccl::ConfigElementPtr>::iterator i;
593
594       // Find the active device that we want to remove
595       for ( i = active_begin ; i != active_end ; i++ )
596       {
597          if ( /*recognizeRemoteDeviceConfig(*i) && */(*i)->getName() == device_name )
598          {
599             cfg_mgr->addConfigElement(*i, jccl::ConfigManager::PendingElement::REMOVE);
600
601             cfg_mgr->unlockActive();
602             cfg_mgr->removeActive(device_name);
603             cfg_mgr->lockActive();
604          }
605       }
606       cfg_mgr->unlockActive();
607       return true;
608    }
609
610    bool RemoteInputManager::
611    createPendingConfigRemoveAndAdd(std::string device_name)
612    {
613       jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance();
614
615       cfg_mgr->lockActive();
616       std::vector<jccl::ConfigElementPtr>::iterator active_begin = cfg_mgr->getActiveBegin();
617       std::vector<jccl::ConfigElementPtr>::iterator active_end   = cfg_mgr->getActiveEnd();
618       std::vector<jccl::ConfigElementPtr>::iterator i;
619       for ( i = active_begin ; i != active_end ; i++ )
620       {
621          if ( /*recognizeRemoteDeviceConfig(*i) && */(*i)->getName() == device_name )
622          {
623             cfg_mgr->addConfigElement(*i, jccl::ConfigManager::PendingElement::REMOVE);
624             cfg_mgr->addConfigElement(*i, jccl::ConfigManager::PendingElement::ADD);
625
626             cfg_mgr->unlockActive();
627             cfg_mgr->removeActive(device_name);
628             cfg_mgr->lockActive();
629          }
630       }
631       cfg_mgr->unlockActive();
632       return true;
633    }
634
635    void RemoteInputManager::addPendingDeviceRequest(cluster::DeviceRequest* new_device_req, Node* node)
636    {
637       vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock);
638       mPendingDeviceRequests[new_device_req] = node;
639    }
640
641    void RemoteInputManager::removePendingDeviceRequest(std::string device_name)
642    {
643       vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock);
644
645       std::map<cluster::DeviceRequest*, Node*>::iterator begin = mPendingDeviceRequests.begin();
646       std::map<cluster::DeviceRequest*, Node*>::iterator end = mPendingDeviceRequests.end();
647       std::map<cluster::DeviceRequest*, Node*>::iterator i;
648
649       for ( i = begin ; i != end ; i++ )
650       {
651          if ( (*i).first->getDeviceName() == device_name )
652          {
653             mPendingDeviceRequests.erase(i);
654             return;
655          }
656       }
657    }
658
659    void RemoteInputManager::sendDeviceRequests()
660    {
661       vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock);
662
663       std::map<cluster::DeviceRequest*, Node*>::iterator begin = mPendingDeviceRequests.begin();
664       std::map<cluster::DeviceRequest*, Node*>::iterator end   = mPendingDeviceRequests.end();
665       std::map<cluster::DeviceRequest*, Node*>::iterator i;
666
667       for ( i = begin ; i != end ; i++ )
668       {
669          if ( (*i).second->isConnected() )
670          {
671             vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
672                << clrOutBOLD(clrMAGENTA, "[RemoteInputManager]")
673                << " Sending device request for: " << (*i).first->getDeviceName()
674                << std::endl << vprDEBUG_FLUSH;
675
676             (*i).second->send((*i).first);
677          }
678       }
679    }
680 // end namespace gadget
681
Note: See TracBrowser for help on using the browser.