コード例 #1
0
/**
 * Removes a proxy aliases in config database.
 * @pre none
 * @post (alias not in list) ==> returns = false<br>
 *       (alias is in list) ==> (alias is removed from list) returns true
 */
bool InputManager::removeProxyAlias(jccl::ConfigElementPtr element)
{
vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL,
                        std::string("gadget::InputManager::removeProxyAlias\n"),
                        std::string("...done removing alias.\n"));

   vprASSERT(element->getID() == "alias");

   std::string alias_name, proxy_name;  // The string of the alias, name of proxy to pt to

   alias_name = element->getName();

   if(mProxyAliases.end() == mProxyAliases.find(alias_name))
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << "gadget::InputManager::RemoveProxyAlias: Alias: " << alias_name
         << "  cannot find proxy: " << proxy_name.c_str() << std::endl
         << vprDEBUG_FLUSH;
      return false;
   }

   mProxyAliases.erase(alias_name);

   vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_CONFIG_LVL)
      << "   alias:" << alias_name.c_str() << "   index:"
      << mProxyAliases[proxy_name] << "  has been removed." << std::endl
      << vprDEBUG_FLUSH;

   return true;
}
コード例 #2
0
ファイル: User.cpp プロジェクト: Michael-Lfx/vrjuggler
bool User::config(jccl::ConfigElementPtr element)
{
   vprASSERT(element.get() != NULL);
   vprASSERT(element->getID() == "user");

   vprDEBUG_BEGIN(vrjDBG_KERNEL, vprDBG_STATE_LVL)
      << "vjUser::config: Creating a new user\n" << vprDEBUG_FLUSH;

   // Assign user id
   mUserId = mNextUserId++;

   // Setup user name
   mName = element->getName();

   // Initialize the head stuff
   std::string head_alias = element->getProperty<std::string>("head_position");
   mHead.init(head_alias);

   // Initialize interocular distance
   mInterocularDist = element->getProperty<float>("interocular_distance");

   if(mInterocularDist == 0.0f)
   {
      vprDEBUG(vrjDBG_KERNEL,vprDBG_CONFIG_LVL) << clrOutNORM(clrRED, "WARNING:") << "User: "******" has interocular distance is set to 0.0f.  This is probably not what you wanted.\n" << vprDEBUG_FLUSH;
   }

   vprDEBUG(vrjDBG_KERNEL,vprDBG_STATE_LVL) << "id: " << mUserId << "   Name:" << mName.c_str()
                           << "   head_positon:" << head_alias.c_str()
                           << "   interocular_distance:" << mInterocularDist
                           << std::endl << vprDEBUG_FLUSH;

   return true;
}
コード例 #3
0
void MultiObjectGrabStrategy::configure(jccl::ConfigElementPtr elt)
{
   vprASSERT(elt->getID() == getElementType());

   const unsigned int req_cfg_version(1);

   // Check for correct version of plugin configuration.
   if ( elt->getVersion() < req_cfg_version )
   {
      std::stringstream msg;
      msg << "Configuration of MultiObjectGrabStrategy failed.  Required "
          << "config element version is " << req_cfg_version
          << ", but element '" << elt->getName() << "' is version "
          << elt->getVersion();
      throw PluginException(msg.str(), VRKIT_LOCATION);
   }

   const std::string choose_btn_prop("choose_button_nums");
   const std::string grab_btn_prop("grab_button_nums");
   const std::string release_btn_prop("release_button_nums");

   mChooseBtn.configure(elt->getProperty<std::string>(choose_btn_prop),
                        mWandInterface);
   mGrabBtn.configure(elt->getProperty<std::string>(grab_btn_prop),
                      mWandInterface);
   mReleaseBtn.configure(elt->getProperty<std::string>(release_btn_prop),
                         mWandInterface);
}
コード例 #4
0
/**
 * Adds the element to the configuration.
 *
 * @pre configCanHandle(element) == true
 * @post (display of same name already loaded) ==> old display closed, new one opened<br>
 *       (display is new) ==> (new display is added)<br>
 *       Draw Manager is notified of the display change.
 */
bool DisplayManager::configAddDisplay(jccl::ConfigElementPtr element)
{
   vprASSERT(configCanHandle(element)); // We must be able to handle it first of all

   vprDEBUG_BEGIN(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configAddDisplay -------\n" << vprDEBUG_FLUSH;

   // Find out if we already have a window of this name
   // If so, then close it before we open a new one of the same name
   // This basically allows re-configuration of a window
   DisplayPtr cur_disp = findDisplayNamed(element->getName());
   if (cur_disp != NULL)                         // We have an old display
   {
      vprDEBUG(vrjDBG_DISP_MGR,vprDBG_CONFIG_LVL) << "Removing old window: " << cur_disp->getName().c_str() << vprDEBUG_FLUSH;
      closeDisplay(cur_disp,true);              // Close the display and notify the draw manager to close the window
   }

   // --- Add a display (of the correct type) ---- //
   if (element->getID() == std::string("display_window"))       // Display window
   {
      DisplayPtr newDisp = Display::create();      // Create the display
      newDisp->config(element);
      addDisplay(newDisp,true);                    // Add it
      vprDEBUG(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "Adding display: " << newDisp->getName().c_str() << std::endl << vprDEBUG_FLUSH;
      vprDEBUG(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "Display: "  << newDisp << std::endl << vprDEBUG_FLUSH;
   }

   vprDEBUG_END(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configAddDisplay Done. --------\n" << vprDEBUG_FLUSH;
   return true;
}
コード例 #5
0
void SignalGrabStrategy::configure(jccl::ConfigElementPtr elt)
{
   vprASSERT(elt->getID() == getElementType());

   const unsigned int req_cfg_version(1);

   // Check for correct version of plugin configuration.
   if ( elt->getVersion() < req_cfg_version )
   {
      std::stringstream msg;
      msg << "Configuration of SignalGrabStrategy failed.  Required config "
          << "element version is " << req_cfg_version << ", but element '"
          << elt->getName() << "' is version " << elt->getVersion();
      throw PluginException(msg.str(), VRKIT_LOCATION);
   }

   const std::string choose_btn_prop("choose_button_nums");
   const std::string grab_btn_prop("grab_button_nums");
   const std::string release_btn_prop("release_button_nums");

   mChooseBtn.configure(elt->getProperty<std::string>(choose_btn_prop),
                        mWandInterface);
   mGrabBtn.configure(elt->getProperty<std::string>(grab_btn_prop),
                      mWandInterface);
   mReleaseBtn.configure(elt->getProperty<std::string>(release_btn_prop),
                         mWandInterface);

   // Determine if grab and release are activated using the same button
   // sequence. This indicates that the grab/release operation is a toggle
   // and must be handled differently than if the two operations are
   // separate.
   mGrabReleaseToggle = mGrabBtn == mReleaseBtn;
}
コード例 #6
0
ファイル: RIMPlugin.cpp プロジェクト: Michael-Lfx/vrjuggler
/** Add the pending elm to the configuration.
 *  @pre configCanHandle (elm) == true.
 *  @return true iff elm was successfully added to configuration.
 */
bool RIMPlugin::configAdd(jccl::ConfigElementPtr elm)
{
   vprASSERT(ClusterManager::instance()->recognizeRemoteDeviceConfig(elm));
   vprASSERT(ClusterManager::instance()->isClusterActive());
   std::string device_name = elm->getName();

   vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_STATUS_LVL)
      << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
      << "Adding device: " << device_name
      << std::endl << vprDEBUG_FLUSH;

   vprASSERT(cluster::ClusterManager::instance()->isClusterActive() && "RIM called in non-cluster mode.");
   bool master = cluster::ClusterManager::instance()->isMaster();
   bool result(false);

   // If we are the master, configure the device and tell all slaves to prepare
   // virtual devices.
   if (master)
   {
      vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_STATUS_LVL)
         << clrOutBOLD(clrMAGENTA, "[RemoteInputManager]")
         << "Configuring device on master node: " << device_name
         << std::endl << vprDEBUG_FLUSH;

      gadget::InputManager::instance()->configureDevice(elm);
      gadget::InputPtr input_device = gadget::InputManager::instance()->getDevice(device_name);
      if ( input_device != NULL )
      {
         result = addDeviceServer(device_name, input_device);
         DeviceServerPtr device_server = getDeviceServer(device_name);
         vprASSERT(NULL != device_server.get() && "Must have device server.");

         const vpr::Uint16 dev_type_id(input_device->getTypeId());
         const vpr::GUID& temp_guid(device_server->getId());
         DeviceAckPtr device_ack = DeviceAck::create(mHandlerGUID, temp_guid,
                                                     device_name, dev_type_id,
                                                     true);

         vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_STATUS_LVL)
            << clrOutBOLD(clrMAGENTA, "[RemoteInputManager]")
            << "Sending device ack [" << device_name << "] to all cluster nodes."
            << std::endl << vprDEBUG_FLUSH;
         cluster::ClusterManager::instance()->getNetwork()->sendToAll(device_ack);
      }
   }
   else
   {
      vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_STATUS_LVL)
         << clrOutBOLD(clrMAGENTA, "[RemoteInputManager]")
         << "Configuring device on slave node: " << device_name
         << std::endl << vprDEBUG_FLUSH;

      result = true;
   }

   return result;
}
コード例 #7
0
bool Flock::config(jccl::ConfigElementPtr e)
{
    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
            << "Flock::Flock(jccl::ConfigElementPtr)\n" << vprDEBUG_FLUSH;

    // read in Position's config stuff,
    // --> this will be the port and baud fields
    if(! (Input::config(e) && Position::config(e)))
    {
        return false;
    }

    // Keep this up to date with the version of the element definition we're
    // expecting to handle.
    const unsigned int cur_version(2);
    bool status(true);

    // If the element version is less than cur_version, we will not try to
    // proceed.  Instead, we'll print an error message and return false so
    // that the Config Manager knows this element wasn't consumed.
    if ( e->getVersion() < cur_version )
    {
        vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                << clrOutBOLD(clrRED, "ERROR") << " [Flock] Element named '"
                << e->getName() << "'" << std::endl << vprDEBUG_FLUSH;
        vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                << "is version " << e->getVersion()
                << ", but we require at least version " << cur_version << std::endl
                << vprDEBUG_FLUSH;
        vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                << "Ignoring this element and moving on." << std::endl
                << vprDEBUG_FLUSH;
        status = false;
    }
    else
    {
        // keep FlockStandalone's port and baud members in sync with Input's port
        // and baud members.
        mFlockOfBirds.setPort( e->getProperty<std::string>("port") );
        mFlockOfBirds.setBaudRate( e->getProperty<int>("baud") );

        // Set mFlockOfBirds with the config info.
        mFlockOfBirds.setHemisphere( (BIRD_HEMI) e->getProperty<int>("hemisphere") );
        mFlockOfBirds.setMasterAddress( e->getProperty<unsigned>("master_address") );
        mFlockOfBirds.setAddressingMode( (::Flock::AddressingMode) e->getProperty<int>("addressing_mode") );
        mFlockOfBirds.setFilterType( (BIRD_FILT) e->getProperty<int>("filter") ); //
        mFlockOfBirds.setOutputFormat(::Flock::Output::PositionQuaternion);          // Default to pos quaternion
    }

    return status;
}
コード例 #8
0
   /** Add the pending element to the configuration.
    *  @pre configCanHandle (element) == true.
    *  @return true iff element was successfully added to configuration.
    */
   bool RIMPlugin::configAdd(jccl::ConfigElementPtr element)
   {
      // XXX: We may still use this to handle the configuration 
      //      of clustered RIM connections.
      if ( ClusterManager::instance()->recognizeRemoteDeviceConfig(element) )
      {
         std::string device_host = element->getProperty<std::string>("device_host");
         gadget::Node* node = ClusterManager::instance()->getNetwork()->getNodeByName(device_host);
         std::string device_name = element->getName();

         vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
            << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
            << "Adding the Remote Device: " << device_name
            << " to the RIM Pending List"
            << std::endl << vprDEBUG_FLUSH;

         if ( node == NULL )
         {
            vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_STATUS_LVL)
               << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
               << clrOutBOLD(clrRED, "WARNING:") << " Cluster node: " << device_host
               << " does not exist, there must be an error in the ClusterDepChecker."
               << std::endl << vprDEBUG_FLUSH;
            return false;
         }
         else if ( !node->isConnected() )
         {
            vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL)
               << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
               << clrOutBOLD(clrRED, "WARNING:") << " Cluster node: " << device_host
               << " is not connected, there must be an error in the ClusterDepChecker."
               << std::endl << vprDEBUG_FLUSH;
            return false;
         }

         DeviceRequest* device_req = new DeviceRequest(getHandlerGUID(), device_name);
         mRIM.addPendingDeviceRequest(device_req, node);
         setActive(true);
         return(true);
      }
      else
      {
         vprDEBUG(gadgetDBG_RIM,vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrCYAN,"[RIMPlugin] ")
            << clrOutBOLD(clrRED, "ERROR: ")
            << "recognizeRemoteDeviceConfig is broken."
            << std::endl << vprDEBUG_FLUSH;
         return(false);
      }
   }
コード例 #9
0
/**
 * Configures proxy aliases in config database.
 * @pre none
 * @post (alias not already in list) ==> Alias is added to proxyAlias list<br>
 *       (alias was already is list) ==> Alias is set to point to the new proxy instead
 */
bool InputManager::configureProxyAlias(jccl::ConfigElementPtr element)
{
vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL,
                           std::string("gadget::InputManager: Configuring proxy alias\n"),
                           std::string("...done configuring alias.\n"));

   vprASSERT(element->getID() == "alias");

   std::string alias_name, proxy_name;  // The string of the alias, name of proxy to pt to

   alias_name = element->getName();
   proxy_name = element->getProperty<std::string>("proxy");

   addProxyAlias(alias_name, proxy_name);

   return true;
}
コード例 #10
0
void DisplayManager::setDisplaySystemElement(jccl::ConfigElementPtr elt)
{
   if ( elt->getVersion() < 3 )
   {
      vprDEBUG(vrjDBG_DISP_MGR, vprDBG_WARNING_LVL)
         << clrOutBOLD(clrYELLOW, "WARNING") << ": Display system element '"
         << elt->getName() << "'" << std::endl;
      vprDEBUG_NEXTnl(vrjDBG_DISP_MGR, vprDBG_WARNING_LVL)
         << "         is out of date.\n";
      vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
         << "         Expected version 3 but found version "
         << elt->getVersion() << ".  Pipe\n";
      vprDEBUG_NEXTnl(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
         << "         configurations will not work.\n" << vprDEBUG_FLUSH;
   }

   mDisplaySystemElement = elt;
}
コード例 #11
0
 bool AbstractNetworkManager::configRemove(jccl::ConfigElementPtr element)
 {
    if (recognizeClusterMachineConfig( element ))
    {
       vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL )
          << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" )
          << " Removing the Node: " << element->getName()
          << " from the Cluster Network\n" << vprDEBUG_FLUSH;
       return true;
    }
    else
    {
       vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL )
          << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" )
          << " ERROR, Something is seriously wrong, we should never get here\n"
          << vprDEBUG_FLUSH;
       return false;
    }
 }
コード例 #12
0
/**
 * Removes the element from the current configuration.
 *
 * @pre configCanHandle(element) == true
 * @return success
 */
bool DisplayManager::configRemoveDisplay(jccl::ConfigElementPtr element)
{
   vprASSERT(configCanHandle(element)); // We must be able to handle it first of all

   vprDEBUG_BEGIN(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configRemoveDisplay -------\n" << vprDEBUG_FLUSH;

   bool success_flag(false);

   if (element->getID() == std::string("display_window"))      // It is a display
   {
      DisplayPtr remove_disp = findDisplayNamed(element->getName());
      if (remove_disp != NULL)
      {
         closeDisplay(remove_disp, true);                            // Remove it
         success_flag = true;
      }
   }

   vprDEBUG_END(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configRemoveDisplay done. --------\n" << vprDEBUG_FLUSH;
   return success_flag;
}
コード例 #13
0
   bool CorbaPerfPlugin::configAdd(jccl::ConfigElementPtr element)
   {
      const unsigned int min_def_version(2);

      if ( element->getVersion() < min_def_version )
      {
         vprDEBUG(jcclDBG_PLUGIN, vprDBG_WARNING_LVL)
            << clrOutBOLD(clrYELLOW, "WARNING") << ": Element named '"
            << element->getName() << "'" << std::endl;
         vprDEBUG_NEXTnl(jcclDBG_PLUGIN, vprDBG_WARNING_LVL)
            << "is version " << element->getVersion()
            << ", but we expect at least version " << min_def_version
            << ".\n";
         vprDEBUG_NEXTnl(jcclDBG_PLUGIN, vprDBG_WARNING_LVL)
            << "Default values will be used for some settings.\n"
            << vprDEBUG_FLUSH;
      }

      // If the ORB is already running, we need to shut it down first.  One big
      // reason for doing this is to release the resources (memory and so on)
      // allocated previously.
      if ( mInterface != NULL || mCorbaManager != NULL )
      {
         vprDEBUG(vrjDBG_PLUGIN, vprDBG_STATE_LVL)
            << "[CorbaPerfPlugin::configAdd()] Attempting to shut down "
            << "existing CORBA instance.\n" << vprDEBUG_FLUSH;

         // stopCorba() will call disable() if we are still in the enabled state.
         stopCorba();
      }

      // We'll ignore the return value for now.  startCorba() prints out enough
      // warning information on its own if something goes wrong.
      this->startCorba(element->getProperty<std::string>("endpoint_addr"),
                       element->getProperty<vpr::Uint16>("endpoint_port"));

      return true;
   }
コード例 #14
0
bool DirectXJoystick::config(jccl::ConfigElementPtr e)
{
   if(! (Input::config(e) && Digital::config(e) && Analog::config(e)))
   {
      return false;
   }

   mJsLabel = e->getName();

   unsigned int num_axis_buttons = e->getNum("axis_buttons");
   for ( unsigned int i = 0; i < num_axis_buttons; ++i )
   {
      unsigned idx = e->getProperty<int>("axis_buttons", i);
      mAxisButtonIndices.push_back(idx);
   }

   // Override whatever the user configured with the minimum and maximum values
   // used by the standalone Direct Input device.  User configuration input is
   // useless in this case.
   setMin((float) DirectXJoystickStandalone::getAxisMin());
   setMax((float) DirectXJoystickStandalone::getAxisMax());

   return true;
}
コード例 #15
0
void WandInterface::configure(jccl::ConfigElementPtr elt)
{
   vprASSERT(elt->getID() == getElementType());

   const unsigned int req_cfg_version(1);

   if ( elt->getVersion() < req_cfg_version )
   {
      std::ostringstream msg;
      msg << "Configuration of WandInterface failed.  Required config "
          << "element version is " << req_cfg_version << ", but element '"
          << elt->getName() << "' is version " << elt->getVersion();
      throw Exception(msg.str(), VRKIT_LOCATION);
   }

   const std::string pos_name_prop("position_name");
   const std::string digital_name_prop("digital_name");
   const std::string analog_name_prop("analog_name");

   const std::string wand_name = elt->getProperty<std::string>(pos_name_prop);

   if ( wand_name.empty() )
   {
      throw Exception("Empty wand name is not allowed", VRKIT_LOCATION);
   }

   mWandInterface.init(wand_name);

   const unsigned int num_digitals(elt->getNum(digital_name_prop));

   if ( num_digitals > 0 )
   {
      mButtonInterfaces.resize(num_digitals);

      for ( unsigned int d = 0; d < num_digitals; ++d )
      {
         const std::string digital_name =
            elt->getProperty<std::string>(digital_name_prop, d);

         if ( digital_name.empty() )
         {
            mButtonInterfaces.clear();

            std::ostringstream msg_stream;
            msg_stream << "Empty digital name (index " << d
                       << ") is not allowed";
            throw Exception(msg_stream.str(), VRKIT_LOCATION);
         }

         mButtonInterfaces[d].init(digital_name);
      }
   }

   const unsigned int num_analogs(elt->getNum(analog_name_prop));

   if ( num_analogs > 0 )
   {
      mAnalogInterfaces.resize(num_analogs);

      for ( unsigned int a = 0; a < num_analogs; ++a )
      {
         const std::string analog_name =
            elt->getProperty<std::string>(analog_name_prop, a);

         if ( analog_name.empty() )
         {
            mAnalogInterfaces.clear();

            std::ostringstream msg_stream;
            msg_stream << "Empty analog name (index " << a
                       << ") is not allowed";
            throw Exception(msg_stream.str(), VRKIT_LOCATION);
         }

         mAnalogInterfaces[a].init(analog_name);
      }
   }
}
コード例 #16
0
ファイル: Grid.cpp プロジェクト: patrickhartling/vrkit
GridPtr Grid::init(jccl::ConfigElementPtr cfgElt)
{
   vprASSERT(cfgElt->getID() == std::string("grid"));

   const unsigned int req_cfg_version(1);

   // Check for correct version of plugin configuration.
   if ( cfgElt->getVersion() < req_cfg_version )
   {
      std::ostringstream msg;
      msg << "Failed to configure grid '" << cfgElt->getName()
          << "'. Required config element version is " << req_cfg_version
          << ", but this element is version " << cfgElt->getVersion();
      throw PluginException(msg.str(), VRKIT_LOCATION);
   }

   mName = cfgElt->getName();

   const std::string size_prop("size");
   const std::string granularity_prop("granularity");
   const std::string color_prop("color");
   const std::string corner_prop("corner");
   const std::string corner_pos_prop("corner_position");
   const std::string orient_prop("orientation");

   const OSG::Real32 width  = cfgElt->getProperty<OSG::Real32>(size_prop, 0);
   const OSG::Real32 height = cfgElt->getProperty<OSG::Real32>(size_prop, 1);

   if ( width <= 0.0f || height <= 0.0f )
   {
      std::ostringstream msg_stream;
      msg_stream << "Invalid grid dimensions " << width << "x" << height;
      throw PluginException(msg_stream.str(), VRKIT_LOCATION);
   }

   const float granularity = cfgElt->getProperty<float>(granularity_prop);

   if ( granularity <= 0.0f )
   {
      std::ostringstream msg_stream;
      msg_stream << "Invalid grid cell granularity " << granularity;
      throw PluginException(msg_stream.str(), VRKIT_LOCATION);
   }

   OSG::Real32 red   = cfgElt->getProperty<OSG::Real32>(color_prop, 0);
   OSG::Real32 green = cfgElt->getProperty<OSG::Real32>(color_prop, 1);
   OSG::Real32 blue  = cfgElt->getProperty<OSG::Real32>(color_prop, 2);

   if ( red < 0.0f || red > 1.0f )
   {
      std::cerr << "WARNING: Invalid red color value " << red
                << " in config element '" << cfgElt->getName() << "'"
                << std::endl;
      red = 0.0f;
   }

   if ( green < 0.0f || green > 1.0f )
   {
      std::cerr << "WARNING: Invalid green color value " << green
                << " in config element '" << cfgElt->getName() << "'"
                << std::endl;
      green = 0.0f;
   }

   if ( blue < 0.0f || blue > 1.0f )
   {
      std::cerr << "WARNING: Invalid blue color value " << blue
                << " in config element '" << cfgElt->getName() << "'"
                << std::endl;
      blue = 0.0f;
   }

   unsigned int corner_val = cfgElt->getProperty<unsigned int>(corner_prop);
   Corner corner;

   if ( 0 <= corner_val && corner_val <= 3 )
   {
      corner = static_cast<Corner>(corner_val);
   }
   else
   {
      std::ostringstream msg_stream;
      msg_stream << "Invalid corner value " << corner_val
                 << "; must be one of 0, 1, 2, or 3";
      throw PluginException(msg_stream.str(), VRKIT_LOCATION);
   }

   const OSG::Vec3f corner_pos(
      cfgElt->getProperty<float>(corner_pos_prop, 0),
      cfgElt->getProperty<float>(corner_pos_prop, 1),
      cfgElt->getProperty<float>(corner_pos_prop, 2)
   );
   OSG::Quaternion rot;
   rot.setValue(
      gmtl::Math::deg2Rad(cfgElt->getProperty<float>(orient_prop, 0)),
      gmtl::Math::deg2Rad(cfgElt->getProperty<float>(orient_prop, 1)),
      gmtl::Math::deg2Rad(cfgElt->getProperty<float>(orient_prop, 2))
   );

   initGeometry(width, height, granularity, corner, corner_pos, rot,
                OSG::Color3f(red, green, blue));

   return shared_from_this();
}
コード例 #17
0
bool InputManager::configureInputManager(jccl::ConfigElementPtr element)
{
   bool have_bad_elt = (element->getID() != std::string("input_manager"));
   vprASSERT(!have_bad_elt);
   if(have_bad_elt)
   {
      return false;
   }

   bool ret_val = false;

   vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL,
                                    std::string("Handling input_manager element:\n"),
                                    std::string("-- end state -- \n"));

   // Keep this up to date with the version of the element definition we're
   // expecting to handle.
   const unsigned int cur_version(2);

   // If the element version is less than cur_version, we will not try to
   // proceed.  Instead, we'll print an error message and return false so
   // that the Config Manager knows this element wasn't consumed.
   if ( element->getVersion() < cur_version )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": [gadget::InputManager::configureInputManager()] Element named '"
         << element->getName() << "'" << std::endl << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << "is version " << element->getVersion()
         << ", but we require at least version " << cur_version
         << std::endl << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << "Ignoring this element and moving on." << std::endl
         << vprDEBUG_FLUSH;
      ret_val = false;
   }
   // We got the right version of the config element and can proceed.
   else
   {
      const std::string driver_path_prop_name("driver_path");
      const int path_count(element->getNum(driver_path_prop_name));
      std::vector<fs::path> search_path(path_count);

      for ( unsigned int i = 0; i < search_path.size(); ++i )
      {
         std::string temp_str =
            vpr::replaceEnvVars(element->getProperty<std::string>(driver_path_prop_name, i));

         try
         {
            search_path[i] = fs::path(temp_str, fs::native);
         }
         catch(fs::filesystem_error& fsEx)
         {
            vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
               << clrOutNORM(clrRED, "ERROR")
               << ": [gadget::InputManager::configureInputManager()] File "
               << "system exception caught while converting\n"
               << vprDEBUG_FLUSH;
            vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
               << "'" << temp_str << "'\n" << vprDEBUG_FLUSH;
            vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
               << "to a Boost.Filesystem path.\n" << vprDEBUG_FLUSH;
            vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
               << fsEx.what() << std::endl << vprDEBUG_FLUSH;
         }
      }

      // Append a default driver search path to search_path.
      const fs::path default_search_dir =
         gadget::getDefaultPluginRoot() / std::string("drivers");

      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_VERB_LVL)
         << "[gadget::InputManager::configureInputManager()] Appending "
         << "default search path '"
         << default_search_dir.native_directory_string() << "'\n"
         << vprDEBUG_FLUSH;

#if defined(GADGET_DEBUG)
      // For a debug build, search in the debug subdirectory of
      // default_search_dir before looking in default_search_dir.
      search_path.push_back(default_search_dir / std::string("debug"));
#endif

      search_path.push_back(default_search_dir);

      // --- Load device driver dsos -- //
      // - Load individual drivers
      const std::string driver_prop_name("driver");
      const std::string get_version_func("getGadgeteerVersion");
      const std::string driver_init_func("initDevice");

      int driver_count = element->getNum(driver_prop_name);
      std::string driver_dso_name;

      for ( int i = 0; i < driver_count; ++i )
      {
         driver_dso_name =
            element->getProperty<std::string>(driver_prop_name, i);

         if ( ! driver_dso_name.empty() )
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
               << "[gadget::InputManager::configureInputManager()] Loading "
               << "driver DSO '" << driver_dso_name << "'\n" << vprDEBUG_FLUSH;

            vpr::LibraryPtr dso = vpr::LibraryLoader::findDSO(driver_dso_name,
                                                              search_path);

            if ( dso.get() != NULL )
            {
               try
               {
                  VersionCheckCallable version_functor;
                  vpr::LibraryLoader::callEntryPoint(dso, get_version_func,
                                                     version_functor);

                  DriverInitCallable init_functor(this);
                  vpr::LibraryLoader::callEntryPoint(dso, driver_init_func,
                                                     init_functor);

                  mLoadedDrivers.push_back(dso);
               }
               catch (gadget::PluginVersionException& ex)
               {
                  vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                     << clrOutBOLD(clrRED, "ERROR")
                     << ": Version mismatch while loading driver DSO '"
                     << driver_dso_name << "'\n" << vprDEBUG_FLUSH;
                  vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                     << "This driver will not be usable.\n"
                     << vprDEBUG_FLUSH;
                  vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                     << ex.getExtendedDescription() << std::endl
                     << vprDEBUG_FLUSH;
               }
               catch (vpr::Exception& ex)
               {
                  vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                     << clrOutBOLD(clrRED, "ERROR")
                     << ": Failed to load driver DSO '"
                     << driver_dso_name << "'\n" << vprDEBUG_FLUSH;
                  vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                     << "This driver will not be usable.\n" << vprDEBUG_FLUSH;
                  vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                     << ex.what() << std::endl << vprDEBUG_FLUSH;
               }
            }
            else
            {
               vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                  << clrOutBOLD(clrRED, "ERROR")
                  << ": Failed to find driver DSO '" << driver_dso_name
                  << "'\n" << vprDEBUG_FLUSH;
            }
         }
      }

      // - Load driver directory
      const std::string dir_prop_name("driver_scan_path");
      int dir_count = element->getNum(dir_prop_name);
      std::string driver_dir;

#if defined(VPR_OS_Windows)
      const std::string driver_ext("dll");
#elif defined(VPR_OS_Darwin)
      const std::string driver_ext("dylib");
#else
      const std::string driver_ext("so");
#endif

      for ( int i = 0; i < dir_count; ++i )
      {
         driver_dir = vpr::replaceEnvVars(element->getProperty<std::string>(dir_prop_name, i));

         // The vpr::LibraryFinder will throw an exception if driver_dir is
         // (somehow) an invalid path.
         try
         {
            fs::path drv_path(driver_dir, fs::native);

            if ( fs::exists(drv_path) )
            {
               vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                  << "[gadget::InputManager::configureInputManager()] "
                  << "Searching for driver DSOs in '" << driver_dir << "'\n"
                  << vprDEBUG_FLUSH;

               vpr::LibraryFinder finder(driver_dir, driver_ext);
               vpr::LibraryFinder::LibraryList libs = finder.getLibraries();
               VersionCheckCallable version_functor;
               DriverInitCallable init_functor(this);

               for ( vpr::LibraryFinder::LibraryList::iterator lib = libs.begin();
                     lib != libs.end();
                     ++lib )
               {
                  try
                  {
                     vpr::LibraryLoader::callEntryPoint(*lib, get_version_func,
                                                        version_functor);
                     vpr::LibraryLoader::callEntryPoint(*lib, driver_init_func,
                                                        init_functor);
                     mLoadedDrivers.push_back(*lib);
                  }
                  catch (vpr::Exception& ex)
                  {
                     vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                        << clrOutBOLD(clrRED, "ERROR")
                        << ": Failed to load driver DSO '"
                        << (*lib)->getName() << "'\n" << vprDEBUG_FLUSH;
                     vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                        << "This driver will not be usable.\n"
                        << vprDEBUG_FLUSH;
                     vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                        << ex.what() << std::endl << vprDEBUG_FLUSH;
                  }
               }
            }
            else
            {
               vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                  << clrOutBOLD(clrYELLOW, "WARNING")
                  << ": [gadget::InputManager::configureInputManager()] "
                  << "Invalid directory for driver DSOs: " << driver_dir
                  << std::endl << vprDEBUG_FLUSH;
            }
         }
         catch(fs::filesystem_error& fsEx)
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << clrOutNORM(clrRED, "ERROR")
               << ": [gadget::InputManager::configureInputManager()] File "
               << "system exception caught!\n" << vprDEBUG_FLUSH;
            vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << fsEx.what() << std::endl << vprDEBUG_FLUSH;
         }
      }

      ret_val = true;
   }

   return ret_val;
}
コード例 #18
0
bool SurfaceViewport::config(jccl::ConfigElementPtr element)
{
   vprASSERT(element.get() != NULL);
   vprASSERT(element->getID() == "surface_viewport");

   // Call base class config
   if ( ! Viewport::config(element) )
   {
      return false;
   }

   bool result(true);

   mType = SURFACE;

   // Read in the corners
   mLLCorner.set(element->getProperty<float>("lower_left_corner", 0),
                 element->getProperty<float>("lower_left_corner", 1),
                 element->getProperty<float>("lower_left_corner", 2));
   mLRCorner.set(element->getProperty<float>("lower_right_corner", 0),
                 element->getProperty<float>("lower_right_corner", 1),
                 element->getProperty<float>("lower_right_corner", 2));
   mURCorner.set(element->getProperty<float>("upper_right_corner", 0),
                 element->getProperty<float>("upper_right_corner", 1),
                 element->getProperty<float>("upper_right_corner", 2));
   mULCorner.set(element->getProperty<float>("upper_left_corner", 0),
                 element->getProperty<float>("upper_left_corner", 1),
                 element->getProperty<float>("upper_left_corner", 2));
   
   mCornerUpdateMode = static_cast<CornerUpdateMode>(element->getProperty<int>("auto_corner_update", 0));

   // Calculate the rotation and the pts
//   calculateSurfaceRotation();
//   calculateCornersInBaseFrame();

   // Get info about being tracked
   mTracked = element->getProperty<bool>("tracked");
   if(mTracked)
   {
      mTrackerProxyName = element->getProperty<std::string>("tracker_proxy");
   }

   // Create Projection objects
   // NOTE: The -'s are because we are measuring distance to
   //  the left(bottom) which is opposite the normal axis direction
   //vjMatrix rot_inv;
   //rot_inv.invert(mSurfaceRotation);
   SurfaceProjectionPtr left_proj;
   SurfaceProjectionPtr right_proj;

   if(!mTracked)
   {
      left_proj = SurfaceProjection::create(mLLCorner, mLRCorner, mURCorner,
                                            mULCorner);
      right_proj = SurfaceProjection::create(mLLCorner, mLRCorner, mURCorner,
                                             mULCorner);
   }
   else
   {
      left_proj = TrackedSurfaceProjection::create(mLLCorner, mLRCorner,
                                                   mURCorner, mULCorner,
                                                   mTrackerProxyName);
      right_proj = TrackedSurfaceProjection::create(mLLCorner, mLRCorner,
                                                    mURCorner, mULCorner,
                                                    mTrackerProxyName);
   }

   try
   {
      left_proj->validateCorners();
      right_proj->validateCorners();

      // NOTE: Even if the corner validation above failed, we still proceed with
      // setting up mLeftProj and mRightProj. This is because other code is not
      // written to handle the case of a viewport having no projections. This
      // could definitely be improved.
      mLeftProj  = left_proj;
      mRightProj = right_proj;

      // Configure the projections
      mLeftProj->config(element);
      mLeftProj->setEye(Projection::LEFT);
      mLeftProj->setViewport(shared_from_this());

      mRightProj->config(element);
      mRightProj->setEye(Projection::RIGHT);
      mRightProj->setViewport(shared_from_this());
   }
   catch (InvalidSurfaceException& ex)
   {
      vprDEBUG(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": The surface defined by the viewport named\n" << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
         << "       '" << element->getName() << "' is invalid!\n"
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;

      result = false;
   }

   return result;
}
コード例 #19
0
   /**
    * Adds the element to the configuration.
    * @pre configCanHandle(element) == true
    */
   bool SoundManagerSonix::configAdd(jccl::ConfigElementPtr element)
   {
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
         << "======================================\n" << vprDEBUG_FLUSH;
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
         << "SoundManagerSonix is being configured...\n" << vprDEBUG_FLUSH;

      if (!configCanHandle( element ))
      {
         std::cerr << "ERROR: Wrong element type in SoundManagerSonix\n"
                   << std::flush;
         return false;
      }

      std::string manager_name = element->getName();
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "My Name: " << manager_name
                                              << "\n" << vprDEBUG_FLUSH;
      std::string api_to_use = element->getProperty<std::string>( "api" );
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Use API: " << api_to_use
                                              << "\n" << vprDEBUG_FLUSH;

      float listener_position[3];
      listener_position[0] = element->getProperty<float>("listener_position", 0);
      listener_position[1] = element->getProperty<float>("listener_position", 1);
      listener_position[2] = element->getProperty<float>("listener_position", 2);
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
         << "Listener Position: " << listener_position[0] << ","
         << listener_position[1] << "," << listener_position[2] << std::endl
         << vprDEBUG_FLUSH;

      std::vector<std::string> file_search_path(element->getNum("file_search_path"));

      for ( unsigned int i = 0; i < file_search_path.size(); ++i )
      {
         file_search_path[i] =
            vpr::replaceEnvVars(element->getProperty<std::string>("file_search_path", i));
      }

//      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
//         << "Search path: " << file_search_path << "\n" << vprDEBUG_FLUSH;

      // configure sonix
      snx::sonix::instance()->changeAPI(api_to_use);
      gmtl::Matrix44f mat;
      gmtl::setTrans( mat, gmtl::Vec3f( listener_position[0], listener_position[1], listener_position[2] ) );
      snx::sonix::instance()->setListenerPosition(mat);

      // read the list of sounds
      int size = element->getNum( "sound" );
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Configuring " << size
                                              << " sounds.\n" << vprDEBUG_FLUSH;
      for (int x = 0; x < size; ++x)
      {
         jccl::ConfigElementPtr sound_element =
            element->getProperty<jccl::ConfigElementPtr>("sound", x);
         std::string alias = sound_element->getName();
         std::string filename = sound_element->getProperty<std::string>("filename");
         filename = vpr::replaceEnvVars( filename );
         bool ambient = sound_element->getProperty<bool>("ambient");
         bool retriggerable = sound_element->getProperty<bool>("retriggerable");
         bool streaming = sound_element->getProperty<bool>("streaming");
         int loop = sound_element->getProperty<int>("loop");
         float cutoff = sound_element->getProperty<float>("cutoff");
         float volume = sound_element->getProperty<float>("volume");
         float pitchbend = sound_element->getProperty<float>("pitch_bend");
         float position[3];
         position[0] = sound_element->getProperty<float>("position", 0);
         position[1] = sound_element->getProperty<float>("position", 1);
         position[2] = sound_element->getProperty<float>("position", 2);

         // configure the sound...
         snx::SoundInfo si;
         si.datasource = snx::SoundInfo::FILESYSTEM;
         si.filename = filename;
         si.cutoff = cutoff;
         si.volume = volume;
         si.pitchbend = pitchbend;
         si.repeat = loop;
         si.ambient = ambient;
         si.retriggerable = retriggerable;
         si.streaming = streaming;
         si.position[0] = position[0];
         si.position[1] = position[1];
         si.position[2] = position[2];
         vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
            << "- Configuring " << alias << " (" << filename << ")\n"
            << vprDEBUG_FLUSH;
         vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
            << "  + pos(" << position[0] << "," << position[1] << ","
            << position[2] << ")," << "loop(" << loop << "),\n"
            << vprDEBUG_FLUSH;
         vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
            << "  + amb(" << ambient << ")," << "ct(" << cutoff << "),"
            << "vl(" << volume << "),\n" << vprDEBUG_FLUSH;
         vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
            << "  + freq(" << pitchbend << ")," << "retrig(" << retriggerable
            << ")\n" << vprDEBUG_FLUSH;

         snx::sonix::instance()->configure(alias, si);
      }
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
         << "======================================\n" << vprDEBUG_FLUSH;

      return true;
   }
コード例 #20
0
   bool AbstractNetworkManager::configAdd(jccl::ConfigElementPtr element)
   {
      if (recognizeClusterMachineConfig(element))
      {
         // -If local machine element
         //   -Add machine specific ConfigElements to the pending list.
         //   -Start Listening thread
         // -Else
         //   -Add Node to AbstractNetworkManager

         if (isLocalHost( element->getProperty<std::string>( "host_name" ) ))
         {
            // XXX: Hack to ensure that we don't start listening for connections until
            //      we have fully configured all other nodes.
            ElementPred pred(getClusterNodeElementType());

            jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance();
            unsigned int num_pending_nodes =
               std::count_if(cfg_mgr->getPendingBegin(), cfg_mgr->getPendingEnd(), pred);

            if (num_pending_nodes > 1)
            {
               vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) << clrSetBOLD(clrRED)
                  << clrOutBOLD( clrMAGENTA,"[AbstractNetworkManager]" )
                  << " Some nodes not configured yet: " << num_pending_nodes
                  << clrRESET << std::endl << vprDEBUG_FLUSH;
               return false;
            }

            // NOTE: Add all machine dependent ConfigElementPtr's here
            vprASSERT( element->getNum("display_system") == 1 
               && "A Cluster System element must have exactly 1 display_system element" );

            std::vector<jccl::ConfigElementPtr> cluster_node_elements =
               element->getChildElements();

            for (std::vector<jccl::ConfigElementPtr>::iterator i = cluster_node_elements.begin();
                 i != cluster_node_elements.end();
                 ++i)
            {
               jccl::ConfigManager::instance()->addConfigElement(*i, jccl::ConfigManager::PendingElement::ADD);

               vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) << clrSetBOLD(clrCYAN)
                  << clrOutBOLD( clrMAGENTA,"[AbstractNetworkManager]" )
                  << " Adding Machine specific ConfigElement: "
                  << (*i)->getName() << clrRESET << std::endl << vprDEBUG_FLUSH;
            }

            const int listen_port = element->getProperty<int>( "listen_port" );
            startListening( listen_port, false );
         }
         else
         {
            vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL )
               << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" )
               << " Adding Node: " << element->getName()
               << " to the Cluster Network\n" << vprDEBUG_FLUSH;

            std::string    name        = element->getName();
            std::string    host_name   = element->getProperty<std::string>( "host_name" );
            vpr::Uint16    listen_port = element->getProperty<int>( "listen_port" );

            addNode(name, host_name, listen_port);
         }
         return true;
      }
      return false;
   }
コード例 #21
0
ファイル: Vrpn.cpp プロジェクト: Michael-Lfx/vrjuggler
bool Vrpn::config(jccl::ConfigElementPtr e)
{
   const unsigned int min_def_version(2);

   if ( e->getVersion() < min_def_version )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
         << clrOutBOLD(clrYELLOW, "WARNING:") << " Element named '"
         << e->getName() << "'" << std::endl;
      vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
         << "is version " << e->getVersion()
         << ", but we expect at least version " << min_def_version
         << ".\n";
      vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
         << "Default values will be used for some settings.\n"
         << vprDEBUG_FLUSH;
   }

   if ( ! (Input::config(e) && Position::config(e) && Digital::config(e) &&
           Analog::config(e)) )
   {
      return false;
   }

   // Get the name of the VRPN tracker server.
   mTrackerServer = e->getProperty<std::string>("tracker_server");
   // Get the number of tracked objects.
   mTrackerNumber = e->getProperty<int>("tracker_count");

   if ( mTrackerNumber > 0 )
   {
      if ( mTrackerServer.empty() )
      {
         vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
            << "[Vrpn::config()] VRPN tracker server name not set!\n"
            << vprDEBUG_FLUSH;
         mTrackerNumber = 0;
      }
      else
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "VRPN driver set to read " << mTrackerNumber
            << " tracker values from '" << mTrackerServer << "'\n"
            << vprDEBUG_FLUSH;
      }

      mPositions.resize(mTrackerNumber);
      mQuats.resize(mTrackerNumber);
   }

   // Get the name of the VRPN button server.
   mButtonServer = e->getProperty<std::string>("button_server");
   // Get the number of buttons.
   mButtonNumber = e->getProperty<int>("button_count");

   if ( mButtonNumber > 0 )
   {
      if ( mButtonServer.empty() )
      {
         vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
            << "[Vrpn::config()] VRPN button server name not set!\n"
            << vprDEBUG_FLUSH;
         mButtonNumber = 0;
      }
      else
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "VRPN driver set to read " << mButtonNumber
            << " button values from '" << mButtonServer << "'\n"
            << vprDEBUG_FLUSH;
      }

      mButtons.resize(mButtonNumber);
   }

   // Get the name of the VRPN analog server.
   mAnalogServer = e->getProperty<std::string>("analog_server");
   // Get the number of analogs.
   mAnalogNumber = e->getProperty<int>("analog_count");

   if ( mAnalogNumber > 0 )
   {
      if ( mAnalogServer.empty() )
      {
         vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
            << "[Vrpn::config()] VRPN analog server name not set!\n"
            << vprDEBUG_FLUSH;
         mAnalogNumber = 0;
      }
      else
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "VRPN driver set to read " << mAnalogNumber
            << " analog values from '" << mAnalogServer << "'\n"
            << vprDEBUG_FLUSH;
      }

      mAnalogs.resize(mAnalogNumber);
   }

   return true;
}
コード例 #22
0
bool InputWindowXWin::config(jccl::ConfigElementPtr e)
{
   unsigned required_definition_ver(1);

   if (e->getVersion() < required_definition_ver)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": [gadget::InputWindowXWin::config()] Element named '"
         << e->getName() << "'" << std::endl << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << "is version " << e->getVersion()
         << ", but we require at least version " << required_definition_ver
         << ". Ignoring.\n" << vprDEBUG_FLUSH;
      return false;
   }

   if ( ! ( InputArea::config(e) && Input::config(e) ) )
   {
      return false;
   }

   const char neg_one_STRING[] = "-1";

   // Get size and position
   mWidth  = e->getProperty<int>("size", 0);
   mHeight = e->getProperty<int>("size", 1);

   // Sanity checks.
   if (mWidth == 0)
   {
      mWidth = 400;
   }
   if (mHeight == 0)
   {
      mHeight = 400;
   }

   mX = e->getProperty<int>("origin", 0);
   mY = e->getProperty<int>("origin", 1);

   // Get the X display string
   int x_disp_num = e->getProperty<int>("display_number");
   jccl::ConfigElementPtr disp_sys_elt =
      gadget::InputManager::instance()->getDisplaySystemElement();

   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
      << "gadget::InputWindowXWin: display_number: " << x_disp_num
      << std::endl << vprDEBUG_FLUSH;

   if (NULL == disp_sys_elt.get())
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CONFIG_LVL)
         << clrOutNORM(clrRED, "ERROR")
         << ": [gadget::InputWindowXWin::config()] display_system element "
         << "is NULL.\n" << vprDEBUG_FLUSH;
      return false;
   }

   if ( x_disp_num >= 0 && disp_sys_elt.get() != NULL )
   {
      if ( disp_sys_elt->getVersion() < 3 )
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << clrOutBOLD(clrYELLOW, "WARNING") << ": Display system element '"
            << disp_sys_elt->getName() << "'" << std::endl;
         vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << "         is out of date.\n";
         vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << "         Expected version 3 but found version "
            << disp_sys_elt->getVersion() << ".  Pipe\n";
         vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << "         configurations will not work.\n" << vprDEBUG_FLUSH;
      }

      mXDisplayString = disp_sys_elt->getProperty<std::string>("pipes",
                                                               x_disp_num);
      
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "[gadget::InputWindowXWin::config()] Display: " << mXDisplayString
         << std::endl << vprDEBUG_FLUSH;
   }
   else
   {
      mXDisplayString = std::string("-1");
   }

   if ((mXDisplayString.empty()) || (strcmp(mXDisplayString.c_str(), neg_one_STRING) == 0))    // Use display env
   {
      const std::string DISPLAY_str("DISPLAY");
      vpr::System::getenv(DISPLAY_str, mXDisplayString);
   }
   return true;
}
コード例 #23
0
void ModeHarnessPlugin::configure(jccl::ConfigElementPtr elt)
{
   vprASSERT(elt->getID() == getElementType());

   const unsigned int req_cfg_version(2);

   // Check for correct version of plugin configuration.
   if ( elt->getVersion() < req_cfg_version )
   {
      std::stringstream msg;
      msg << "Configuration of ModeHarnessPlugin failed.  Required config "
          << "element version is " << req_cfg_version << ", but element '"
          << elt->getName() << "' is version " << elt->getVersion();
      throw PluginException(msg.str(), VRKIT_LOCATION);
   }

   const std::string component_path_prop("component_path");
   const std::string default_component_prop("default_component");
   const std::string component_prop("component");
   const std::string plugin_prop("plugin");
   const std::string signal_prop("signal");
   const std::string active_component_prop("active_component");

   // Set up two default search paths:
   //    1. Relative path to './plugins/mode'
   //    2. VRKIT_BASE_DIR/lib/vrkit/plugins/mode
   //
   // In all of the above cases, the 'debug' subdirectory is searched first if
   // this is a debug build (i.e., when VRKIT_DEBUG is defined and _DEBUG is
   // not).
   std::vector<std::string> component_path =
      plugin::getDefaultSearchPath("mode");

   const unsigned int num_plugin_paths(elt->getNum(component_path_prop));
   for ( unsigned int i = 0; i < num_plugin_paths; ++i )
   {
      std::string dir = elt->getProperty<std::string>(component_path_prop, i);
      component_path.push_back(vpr::replaceEnvVars(dir));
   }

   mDefaultComponentName =
      elt->getProperty<std::string>(default_component_prop);

   const unsigned int num_comps(elt->getNum(component_prop));
   for ( unsigned int i = 0; i < num_comps; ++i )
   {
      jccl::ConfigElementPtr comp_elt =
         elt->getProperty<jccl::ConfigElementPtr>(component_prop, i);
      mComponentInfo.push_back(
         ComponentInfo(comp_elt->getName(),
                       comp_elt->getProperty<std::string>(plugin_prop))
      );
   }

   const unsigned int num_signals(elt->getNum(signal_prop));
   for ( unsigned int i = 0; i < num_signals; ++i )
   {
      jccl::ConfigElementPtr signal_elt =
         elt->getProperty<jccl::ConfigElementPtr>(signal_prop, i);
      mSignalDefs.push_back(
         SignalDef(signal_elt->getName(),
                   signal_elt->getProperty<std::string>(active_component_prop))
      );
   }

   std::vector<vpr::LibraryPtr> modules = plugin::findModules(component_path);
   std::for_each(modules.begin(), modules.end(),
                 boost::bind(&ModeHarnessPlugin::registerModule, this, _1));
}
コード例 #24
0
void ClusterDepChecker::debugOutDependencies(jccl::ConfigElementPtr element,
                                             const int dbg_lvl)
{
   vprDEBUG_NEXT_BEGIN( vprDBG_ALL, dbg_lvl )
      << "---- Dependencies for " << element->getName()
      << " (type: " << element->getID() << ") ----\n" << vprDEBUG_FLUSH;

   if (element->getID() == ClusterNetwork::getClusterNodeElementType())
   {
      // Machine Specific element should have no dependencies since we are
      // simply inserting the child elements into the pending list.
      vprDEBUG_NEXT( vprDBG_ALL, dbg_lvl ) << "0: "
          << "Host node's ConfigElement"
          << " ==> " << vprDEBUG_FLUSH;
      
      vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "none.\n"
         << vprDEBUG_FLUSH;
   }
   /*
   else if (cluster::ClusterManager::instance()->recognizeRemoteDeviceConfig( element ))
   {
      std::string device_host = element->getProperty<std::string>( "device_host");
      gadget::NodePtr node = cluster::ClusterManager::instance()->getNetwork()->getNodeByName( device_host );

      vprDEBUG_NEXT( vprDBG_ALL, dbg_lvl ) << "1: "
          << "Device node's ConfigElement"
          << " ==> " << vprDEBUG_FLUSH;

      jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance();

      if (!cfg_mgr->isElementInActiveList( device_host ) || NULL == node)
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "not in active list.\n"
            << vprDEBUG_FLUSH;
      }
      else
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "in active list.\n"
            << vprDEBUG_FLUSH;
      }

      vprDEBUG_NEXT( vprDBG_ALL, dbg_lvl ) << "2: "
          << "Device host connection status"
          << " ==> " << vprDEBUG_FLUSH;
      
      if (gadget::Node::DISCONNECTED == node->getStatus())
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "disconnected.\n"
            << vprDEBUG_FLUSH;
      }
      else if (gadget::Node::PENDING == node->getStatus())
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "pending.\n"
            << vprDEBUG_FLUSH;
      }
      else if (gadget::Node::NEWCONNECTION == node->getStatus())
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "new connection.\n"
            << vprDEBUG_FLUSH;
      }
   }
   */
   vprDEBUG_CONT_END( vprDBG_ALL, dbg_lvl ) << std::endl << vprDEBUG_FLUSH;
}
コード例 #25
0
// Configure the MotionStar with the given config element.
bool MotionStar::config(jccl::ConfigElementPtr e)
{
   bool retval(false);

   if ( Input::config(e) &&  Position::config(e) )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "MotionStar::config(jccl::ConfigElementPtr)\n"
         << vprDEBUG_FLUSH;

      const unsigned int cur_version(2);

      if ( e->getVersion() < cur_version )
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << " [gadget::MotionStar::config()] Element named '"
            << e->getName() << "'" << std::endl << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << "is version " << e->getVersion()
            << ", but we require at least version " << cur_version
            << std::endl << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << "Ignoring this element and moving on." << std::endl
            << vprDEBUG_FLUSH;
         retval = false;
      }
      else
      {
         // Configure mMotionStar with the config info.
         const unsigned num_filters = e->getNum("position_filters");

         // Sanity check.  There has to be at least one position filter
         // configured.
         if ( num_filters == 0 )
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << clrOutBOLD(clrRED, "ERROR")
               << ": [MotionStar::config(jccl::ConfigElementPtr)] No position "
               << "filters configured in " << e->getName() << std::endl
               << vprDEBUG_FLUSH;
            retval = false;
         }
         else
         {
            BIRDNET::units expected_units;

            // Find the first position_transform_filter instance and get its
            // device_units property value.  This will tell us what units we're
            // expecting from the hardware.
            const std::string filter_type("position_transform_filter");
            for ( unsigned i = 0; i < num_filters; ++i )
            {
               jccl::ConfigElementPtr pos_elt =
                  e->getProperty<jccl::ConfigElementPtr>("position_filters", i);

               if ( pos_elt->getID() == filter_type )
               {
                  const float unit_conv =
                     pos_elt->getProperty<float>("device_units");

                  vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_VERB_LVL)
                     << "[gadget::MotionStar::config()] Read " << unit_conv
                     << " as the conversion from device units to meters.\n"
                     << vprDEBUG_FLUSH;

                  // Inches.  This is the most likely configuration as of this
                  // writing.
                  if ( unit_conv == 0.0254f )
                  {
                     expected_units = BIRDNET::INCHES;
                  }
                  // Feet.
                  else if ( unit_conv == 0.3048f )
                  {
                     expected_units = BIRDNET::FEET;
                  }
                  // Meters.
                  else if ( unit_conv == 1.0f )
                  {
                     expected_units = BIRDNET::METERS;
                  }
                  // Unexpected value.
                  else
                  {
                     vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                        << "[MotionStar::config(jccl::ConfigElementPtr)] "
                        << clrOutBOLD(clrRED, "ERROR")
                        << ": Unsupported device unit value " << unit_conv
                        << " in " << pos_elt->getFullName() << std::endl
                        << vprDEBUG_FLUSH;
                     vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                        << "Check your configuration for errors.\n"
                        << vprDEBUG_FLUSH;

                     // Break out of this method early because the
                     // configuration element we were given is bad.
                     return false;
                  }

                  // We're done checking for unit conversion values.
                  break;
               }
            }

            mMotionStar.setExpectedUnits(expected_units);

            setAddressName(e->getProperty<std::string>("address").c_str());
            setServerPort((unsigned short) e->getProperty<int>("server_port"));
            setMasterStatus(e->getProperty<bool>("is_master"));
            setHemisphere((unsigned char) e->getProperty<int>("hemisphere"));
            setBirdFormat((unsigned int) e->getProperty<int>("data_format"));
            setRunMode((unsigned int) e->getProperty<int>("mode"));
            setReportRate((unsigned char) e->getProperty<int>("report_rate"));
            setMeasurementRate(e->getProperty<float>("measurement_rate"));
            retval = true;
         }
      }
   }

   return retval;
}
コード例 #26
0
void SlideMoveStrategy::configure(jccl::ConfigElementPtr cfgElt)
{
   vprASSERT(cfgElt->getID() == getElementType());

   const unsigned int req_cfg_version(2);

   if ( cfgElt->getVersion() < req_cfg_version )
   {
      std::stringstream msg;
      msg << "Configuration of SlideMoveStrategy failed.  Required config "
          << "element version is " << req_cfg_version << ", but element '"
          << cfgElt->getName() << "' is version " << cfgElt->getVersion();
      throw PluginException(msg.str(), VRKIT_LOCATION);
   }

   const std::string slide_target_prop("slide_target");
   const std::string analog_input_prop("analog_input");
   const std::string forward_value_prop("forward_slide_value");
   const std::string slide_epsilon_prop("slide_epsilon");

   const unsigned int slide_target =
      cfgElt->getProperty<unsigned int>(slide_target_prop);

   if ( slide_target == 0 || slide_target == 1 )
   {
      mSlideTarget = static_cast<SlideTarget>(slide_target);
   }
   else
   {
      VRKIT_STATUS << "ERROR: Invalid slide target identifier "
                   << slide_target << std::endl;
   }

   const int analog_num = cfgElt->getProperty<int>(analog_input_prop);

   // -1 disables sliding. Otherwise, the analog number must be in the range
   // 0 <= analog_num < 4.
   if ( analog_num == -1 || 0 <= analog_num && analog_num < 4 )
   {
      mAnalogNum = analog_num;
   }
   else
   {
      VRKIT_STATUS << "ERROR: Analog input index (" << analog_num
                   << ") given!\n"
                   << "This must be -1 (to disable) or in the range [0, 4)."
                   << std::endl;
   }

   const float fwd_val = cfgElt->getProperty<float>(forward_value_prop);

   if ( fwd_val == 0.0f || fwd_val == 1.0f )
   {
      mForwardValue = fwd_val;
   }
   else
   {
      VRKIT_STATUS << "ERROR: Invalid forward sliding value (" << fwd_val
                   << ") given!\n"
                   << "This must be either 0.0 or 1.0" << std::endl;
   }

   const float eps = cfgElt->getProperty<float>(slide_epsilon_prop);

   if ( eps >= 0.0f )
   {
      mSlideEpsilon = eps;
   }
   else
   {
      VRKIT_STATUS << "ERROR: Slide epsilon must be non-negative!"
                   << std::endl;
   }
}