RIMPlugin.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile$
00027  * Date modified: $Date: 2005-01-01 14:59:16 -0600 (Sat, 01 Jan 2005) $
00028  * Version:       $Revision: 16524 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <cluster/PluginConfig.h>
00034 #include <gadget/Util/Debug.h>
00035 #include <gadget/gadgetParam.h>
00036 
00037 #include <plugins/RIMPlugin/RIMPlugin.h>
00038 
00039 // Accept Thread
00040 #include <vpr/Thread/Thread.h>
00041 #include <vpr/Thread/ThreadFunctor.h>
00042 
00043 // Sharing Devices
00044 #include <gadget/Type/BaseTypeFactory.h>
00045 #include <gadget/Type/DeviceFactory.h>
00046 #include <gadget/InputManager.h>
00047 #include <gadget/RemoteInputManager.h>
00048 
00049 // ClusterNetwork
00050 #include <cluster/ClusterNetwork.h>
00051 #include <gadget/Node.h>
00052 #include <cluster/ClusterManager.h>
00053 
00054 // IO Packets
00055 #include <cluster/Packets/PacketFactory.h>
00056 #include <cluster/Packets/ConnectionRequest.h>
00057 #include <cluster/Packets/DeviceRequest.h>
00058 #include <cluster/Packets/DeviceAck.h>
00059 #include <cluster/Packets/ApplicationDataRequest.h>
00060 #include <cluster/Packets/EndBlock.h>
00061 #include <cluster/Packets/DataPacket.h>
00062 
00063 // Configuration
00064 #include <jccl/RTRC/ConfigManager.h>
00065 #include <jccl/Config/ConfigElement.h>
00066 
00067 #include <map>
00068 
00069 extern "C"
00070 {
00071    GADGET_CLUSTER_PLUGIN_EXPORT(vpr::Uint32) getGadgeteerVersion()
00072    {
00073       return __GADGET_version;
00074    }
00075 
00076    GADGET_CLUSTER_PLUGIN_EXPORT(void) initPlugin(cluster::ClusterManager* mgr)
00077    {
00078       mgr->addPlugin(new cluster::RIMPlugin());
00079    }
00080 }
00081 
00082 namespace cluster
00083 {
00084    RIMPlugin::RIMPlugin()
00085       : mHandlerGUID("9c3fb301-b142-4c6f-8ca3-1570898974d0")
00086       , mRIM(mHandlerGUID)
00087    {;}
00088 
00089    RIMPlugin::~RIMPlugin()
00090    {;}
00091 
00092    void RIMPlugin::recoverFromLostNode(gadget::Node* lost_node)
00093    {
00094       boost::ignore_unused_variable_warning(lost_node);
00095       // Since we have lost a connection we need to set a flag so
00096       // that when we gain a new connection we will reconfigure.
00097       //setReconfigurationNeededOnConnection(true);
00098    }
00099    
00103    void RIMPlugin::handlePacket(Packet* packet, gadget::Node* node)
00104    {
00105       mRIM.handlePacket(packet, node);
00106       // We do not handle packets, we are here only to sync.
00107    }
00108 
00109    void RIMPlugin::preDraw()
00110    {
00111       // Do nothing we are only here to sync.
00112    }
00113 
00114    void RIMPlugin::postPostFrame()
00115    {
00116       mRIM.sendDataAndSync();
00117    }
00118 
00119    void RIMPlugin::sendRequests()
00120    {
00121       mRIM.sendDeviceRequests();
00122    }
00123 
00125    //    CONFIG METHODS    //
00127 
00132    bool RIMPlugin::configAdd(jccl::ConfigElementPtr element)
00133    {
00134       // XXX: We may still use this to handle the configuration 
00135       //      of clustered RIM connections.
00136       if ( ClusterManager::instance()->recognizeRemoteDeviceConfig(element) )
00137       {
00138          std::string device_host = element->getProperty<std::string>("device_host");
00139          gadget::Node* node = ClusterManager::instance()->getNetwork()->getNodeByName(device_host);
00140          std::string device_name = element->getName();
00141 
00142          vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
00143             << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
00144             << "Adding the Remote Device: " << device_name
00145             << " to the RIM Pending List"
00146             << std::endl << vprDEBUG_FLUSH;
00147 
00148          if ( node == NULL )
00149          {
00150             vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_STATUS_LVL)
00151                << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
00152                << clrOutBOLD(clrRED, "WARNING:") << " Cluster node: " << device_host
00153                << " does not exist, there must be an error in the ClusterDepChecker."
00154                << std::endl << vprDEBUG_FLUSH;
00155             return false;
00156          }
00157          else if ( !node->isConnected() )
00158          {
00159             vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
00160                << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
00161                << clrOutBOLD(clrRED, "WARNING:") << " Cluster node: " << device_host
00162                << " is not connected, there must be an error in the ClusterDepChecker."
00163                << std::endl << vprDEBUG_FLUSH;
00164             return false;
00165          }
00166 
00167          DeviceRequest* device_req = new DeviceRequest(getHandlerGUID(), device_name);
00168          mRIM.addPendingDeviceRequest(device_req, node);
00169          setActive(true);
00170          return(true);
00171       }
00172       else
00173       {
00174          vprDEBUG(gadgetDBG_RIM,vprDBG_CRITICAL_LVL)
00175             << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
00176             << clrOutBOLD(clrRED, "ERROR: ")
00177             << "recognizeRemoteDeviceConfig is broken."
00178             << std::endl << vprDEBUG_FLUSH;
00179          return(false);
00180       }
00181    }
00182 
00183 
00189    bool RIMPlugin::configRemove(jccl::ConfigElementPtr element)
00190    {
00191       boost::ignore_unused_variable_warning(element);
00192       return false;
00193 
00194       // XXX: We may still use this to handle the configuration 
00195       //      of clustered RIM connections.
00196       /*
00197       if ( ClusterManager::instance()->recognizeRemoteDeviceConfig(element) )
00198       {
00199          vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
00200          << "Removing the Remote Device: " << element->getName()
00201          << " from the active configuration \n" << vprDEBUG_FLUSH;
00202 
00203          removeVirtualDevice(element->getName());
00204          if ( this->mVirtualDevices.size()== 0 && mDeviceServers.size() == 0 )
00205          {
00206             setActive(false);
00207          }
00208          return(true);
00209       }
00210       else
00211       {
00212          vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
00213             << "[RIMPlugin::configRemove] ERROR, Something is seriously wrong, we should never get here\n"
00214             << vprDEBUG_FLUSH;
00215          return(false);
00216       }
00217       */
00218    }
00219 
00220 
00227    bool RIMPlugin::configCanHandle(jccl::ConfigElementPtr element)
00228    {
00229       // XXX: We may still use this to handle the configuration 
00230       //      of clustered RIM connections.
00231       return ClusterManager::instance()->recognizeRemoteDeviceConfig(element);
00232    }
00233 
00234    bool RIMPlugin::isPluginReady()
00235    {
00236       //XXX: Fix this to check for any pending devices. We might want to keep a local
00237       //     copy of this also so that we don't stall when we are waiting for pending
00238       //     RIM requests that are not in the cluster configuration.
00239 
00240       //vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock);
00241       //return(0 == mPendingDeviceRequests.size());
00242       return true;
00243    }
00244 }  // end namespace cluster

Generated on Thu Jan 4 10:41:56 2007 for Gadgeteer by  doxygen 1.5.1