00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00040 #include <vpr/Thread/Thread.h>
00041 #include <vpr/Thread/ThreadFunctor.h>
00042
00043
00044 #include <gadget/Type/BaseTypeFactory.h>
00045 #include <gadget/Type/DeviceFactory.h>
00046 #include <gadget/InputManager.h>
00047 #include <gadget/RemoteInputManager.h>
00048
00049
00050 #include <cluster/ClusterNetwork.h>
00051 #include <gadget/Node.h>
00052 #include <cluster/ClusterManager.h>
00053
00054
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
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
00096
00097
00098 }
00099
00103 void RIMPlugin::handlePacket(Packet* packet, gadget::Node* node)
00104 {
00105 mRIM.handlePacket(packet, node);
00106
00107 }
00108
00109 void RIMPlugin::preDraw()
00110 {
00111
00112 }
00113
00114 void RIMPlugin::postPostFrame()
00115 {
00116 mRIM.sendDataAndSync();
00117 }
00118
00119 void RIMPlugin::sendRequests()
00120 {
00121 mRIM.sendDeviceRequests();
00122 }
00123
00125
00127
00132 bool RIMPlugin::configAdd(jccl::ConfigElementPtr element)
00133 {
00134
00135
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
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 }
00219
00220
00227 bool RIMPlugin::configCanHandle(jccl::ConfigElementPtr element)
00228 {
00229
00230
00231 return ClusterManager::instance()->recognizeRemoteDeviceConfig(element);
00232 }
00233
00234 bool RIMPlugin::isPluginReady()
00235 {
00236
00237
00238
00239
00240
00241
00242 return true;
00243 }
00244 }