示例#1
0
bool SimAnalog::config(jccl::ConfigElementPtr element)
{
   //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimAnalog::config()\n"<< vprDEBUG_FLUSH;
   if (! (Input::config(element) && Analog::config(element) &&
          SimInput::config(element)) )
   {
      return false;
   }

   std::vector<jccl::ConfigElementPtr> key_inc_list, key_dec_list;

   int key_count = element->getNum("increment_keypress");

   for ( int i = 0; i < key_count; ++i )
   {
      key_inc_list.push_back(element->getProperty<jccl::ConfigElementPtr>("increment_keypress", i));
   }

   key_count = element->getNum("decrement_keypress");

   for ( int i = 0; i < key_count; ++i )
   {
      key_dec_list.push_back(element->getProperty<jccl::ConfigElementPtr>("decrement_keypress", i));
   }

   mSimKeysUp = readKeyList(key_inc_list);
   mSimKeysDown = readKeyList(key_dec_list);

   mAnaStep = element->getProperty<float>("delta");
   mInitialValue = element->getProperty<float>("initial_value");

   // Initialize all the data to the inital_value
   size_t num_pairs = mSimKeysUp.size();
   mAnaData = std::vector<AnalogData>(num_pairs);
   for (size_t i=0; i<num_pairs; ++i)
   {
      mAnaData[i].setValue(mInitialValue);
   }

   mAutoReturn = element->getProperty<bool>("auto_return");

   return true;
}
   /**
    * Removes the element from the current configuration.
    * @pre configCanHandle(element) == true
    */
   bool SoundManagerSonix::configRemove(jccl::ConfigElementPtr element)
   {
      // remove any specified sounds...
      int size = element->getNum("sound");
      for (int x = 0; x < size; ++x)
      {
         jccl::ConfigElementPtr sound_element =
            element->getProperty<jccl::ConfigElementPtr>("sound", x);
         std::string alias(sound_element->getName());
         snx::sonix::instance()->remove(alias);
      }

      return true;
   }
示例#3
0
bool SimDigital::config(jccl::ConfigElementPtr element)
{
    //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimDigital::config()\n"<< vprDEBUG_FLUSH;
    if (! (Input::config(element) && Digital::config(element) &&
            SimInput::config(element)) )
    {
        return false;
    }

    std::vector<jccl::ConfigElementPtr> key_list;
    int key_count = element->getNum("key_pair");
    for ( int i = 0; i < key_count; ++i )
    {
        key_list.push_back(element->getProperty<jccl::ConfigElementPtr>("key_pair", i));
    }
    mSimKeys = readKeyList(key_list);

    return true;
}
示例#4
0
bool IntersenseAPI::config(jccl::ConfigElementPtr e)
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
      << "*** IntersenseAPI::config() ***" << std::endl << vprDEBUG_FLUSH;

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

   // Set various attributes of the Intersense driver
   mTracker.setPort( e->getProperty<std::string>("port") );
   mTracker.setVerbose(e->getProperty<bool>("verbose"));

   // Get the location of the Intersense DSO
   mISenseDriverLocation = e->getProperty<std::string>("driver");

   // Create a new array of StationConfigs
   mStations.resize(e->getNum("stations"));

   // Configure each station
   for( unsigned int i = 0; i < mStations.size(); ++i )
   {
      jccl::ConfigElementPtr station_config =
         e->getProperty<jccl::ConfigElementPtr>("stations", i);

      mStations[i].enabled = station_config->getProperty<bool>("enabled");
      mStations[i].stationIndex =
         station_config->getProperty<int>("station_index");
      mStations[i].useDigital =
         station_config->getProperty<bool>("use_digital");
      mStations[i].useAnalog = station_config->getProperty<bool>("use_analog");

      mStations[i].dig_num = station_config->getProperty<int>("digital_count");
      mStations[i].ana_num = station_config->getProperty<int>("analog_count");
   }

   return true;
}
示例#5
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;
}
   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;
   }
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));
}
示例#8
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;
}
   /**
    * 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;
   }
示例#10
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;
}
示例#11
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);
      }
   }
}