Exemplo n.º 1
0
std::vector< std::string > CorbaNameService::getRegisteredTasks()
{
    if(CORBA::is_nil(orb))
    {
        throw std::runtime_error("CorbaNameService::Error, called getRegisteredTasks() without connection " );
    }
    CosNaming::Name server_name;
    server_name.length(1);
    server_name[0].id = CORBA::string_dup("TaskContexts");
    std::vector<std::string> task_names;
    CosNaming::BindingList_var binding_list;
    CosNaming::BindingIterator_var binding_it;

    // get all available task names from the name server
    CORBA::Object_var control_tasks_var = rootContext->resolve(server_name);
    CosNaming::NamingContext_var control_tasks = CosNaming::NamingContext::_narrow (control_tasks_var);
    if (CORBA::is_nil(control_tasks))
        return task_names;

    control_tasks->list(0, binding_list, binding_it);
    if (CORBA::is_nil(binding_it))
        return task_names;

    // iterate over all task names
    while(binding_it->next_n(10, binding_list))
    {
        CosNaming::BindingList list = binding_list.in();
        for (unsigned int i = 0; i < list.length(); ++i)
        {
            std::string name = list[i].binding_name[0].id.in();
            CosNaming::Name serverName;
            serverName.length(2);
            serverName[0].id = CORBA::string_dup("TaskContexts");
            serverName[1].id = CORBA::string_dup( name.c_str() );

            try {
                //verify that the object really exists, and is not just some leftover from a crash
                
                // Get object reference
                CORBA::Object_var task_object = rootContext->resolve(serverName);
                RTT::corba::CTaskContext_var mtask = RTT::corba::CTaskContext::_narrow (task_object.in ());
                
                std::cout << "Connection test to " << name << std::endl;
                
                // force connect to object.
                CORBA::String_var nm = mtask->getName(); 
                task_names.push_back(name);
                }
            catch (...)
            {
            }
        }
    }
    return task_names;
}
Exemplo n.º 2
0
void
Connection_Manager::add_to_receivers (CosNaming::BindingList &binding_list)
{
  for (CORBA::ULong i = 0;
       i < binding_list.length ();
       i++)
    {
      // Get the receiver name from the binding list.
      ACE_CString receiver_name =
        binding_list [i].binding_name [0].id.in ();

      CosNaming::Name name (1);
      name.length (1);
      name [0].id =
        CORBA::string_dup (receiver_name.c_str ());

      // Resolve the reference of the receiver from the receiver
      // context.
      CORBA::Object_var obj =
        this->receiver_context_->resolve (name);

      AVStreams::MMDevice_var receiver_device =
        AVStreams::MMDevice::_narrow (obj.in ());

      // Add this receiver to the receiver map.
      ACE_CString flowname =
        this->sender_name_ +
        "_" +
        receiver_name;
      this->receivers_.bind (flowname,
                             receiver_device);
    }
}
Exemplo n.º 3
0
void CorbaService::addSubjectManagers(const CosNaming::BindingList& bindingList,
                                      std::list<tweek::SubjectManager_var>& mgrList)
{
   CosNaming::Binding binding;

   for ( CORBA::ULong i = 0; i < bindingList.length(); ++i )
   {
      binding = bindingList[i];

      // We do not care about anything that is a naming context.
      if ( CosNaming::ncontext != binding.binding_type )
      {
         const std::string subj_mgr_name("SubjectManager");
         bool substr_match(false);

#if defined(__GNUC__) && __GNUC__ == 2
         // XXX: This is a hack to deal with GCC 2.96 (and earlier?) having
         // a std::string::compare() method that does not match the actual
         // STL prototype.
         substr_match = (subj_mgr_name.compare(binding.binding_name[0].id, 0,
                                               subj_mgr_name.size()) == 0);
#else
         substr_match = (subj_mgr_name.compare(0, subj_mgr_name.size(),
                                               binding.binding_name[0].id));
#endif

         // Furthermore, we only care about SubjectManager* instances.
         if ( substr_match )
         {
            CosNaming::Name name_comp = binding.binding_name;

            try
            {
               CORBA::Object_var ref = mLocalContext->resolve(name_comp);
               tweek::SubjectManager_var mgr = tweek::SubjectManager::_narrow(ref);

               try
               {
                  // Filter out any references that we know are not usable.
                  if ( ! mgr->_non_existent() )
                  {
                     mgrList.push_back(mgr);
                  }
               }
               // In the Java equivalent of this method, CORBA::TRANSIENT
               // exceptions are sometimes thrown by the call to
               // tweek::SubjectManager::_non_existent() above.  I don't know
               // if they are also thrown here, but we might as well be safe.
               catch (CORBA::TRANSIENT ex)
               {
                  boost::ignore_unused_variable_warning(ex);
                  vprDEBUG(tweekDBG_CORBA, vprDBG_WARNING_LVL)
                     << "addSubjectManagers(): Caught CORBA::TRANSIENT "
                     << "exception thrown by _non_existent\n"
                     << vprDEBUG_FLUSH;
               }
               // XXX: Figure out what exception(s) can be thrown by
               // CORBA::Object::_non_existent()!
               catch (...)
               {
                  vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
                     << "addSubjectManagers(): Caught unknown exception "
                     << "thrown by _non_existent\n"
                     << vprDEBUG_FLUSH;
               }
            }
            catch (CosNaming::NamingContext::InvalidName& nameEx)
            {
               boost::ignore_unused_variable_warning(nameEx);
               vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
                  << "addSubjectManagers(): Tried to resolve invalid name\n"
                  << vprDEBUG_FLUSH;
            }
            catch (CosNaming::NamingContext::CannotProceed& proceedEx)
            {
               vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
                  << "addSubjectManagers(): Cannot proceed with resolution of '"
                  << proceedEx.rest_of_name[0].id << "'\n" << vprDEBUG_FLUSH;
            }
            catch (CosNaming::NamingContext::NotFound& notFoundEx)
            {
               vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
                  << "addSubjectManagers(): No binding for name '"
                  << notFoundEx.rest_of_name[0].id << "' " << vprDEBUG_FLUSH;

               switch ( notFoundEx.why )
               {
                  case CosNaming::NamingContext::missing_node:
                     vprDEBUG_CONT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
                        << "(missing node)" << std::endl << vprDEBUG_FLUSH;
                     break;
                  case CosNaming::NamingContext::not_context:
                     vprDEBUG_CONT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
                        << "(not a context)" << std::endl << vprDEBUG_FLUSH;
                     break;
                  case CosNaming::NamingContext::not_object:
                     vprDEBUG_CONT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
                        << "(not an object)" << std::endl << vprDEBUG_FLUSH;
                     break;
               }
            }
         }
         else
         {
            vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
               << "addSubjectManagers(): Skipping binding with name '"
               << binding.binding_name[0].id << "'\n" << vprDEBUG_FLUSH;
         }
      }
   }
}