Example #1
0
TEST_F(Initialization, Component)
{
	Session_Container_i a_container(orb, root_poa.in());

	Components::CCMObject_var component = create_sender(a_container, home);
	component->configuration_complete();
	a_container.activate_component(component);
	//component->_request("hertz");

	ASSERT_FALSE( CORBA::is_nil(component));
}
Example #2
0
typename COMP_SVNT::_stub_ptr_type
Home_Servant_Impl<BASE_SKEL,
                  EXEC,
                  COMP_SVNT,
                  CONTAINER>::_ciao_activate_component (
                      typename COMP_SVNT::_exec_type::_ptr_type exe)
{
    CIAO_TRACE ("Home_Servant_Impl<>::_ciao_activate_component");

    typename CONTAINER::_var_type cnt_safe =
        CONTAINER::_duplicate (this->container_.in());

    CORBA::Object_var hobj = cnt_safe->get_objref (this);

    Components::CCMHome_var home =
        Components::CCMHome::_narrow (hobj.in ());

    char buffer[256];
    unsigned long const serial = this->serial_number_++;
    if (ACE_OS::sprintf (buffer, "%ld", serial) < 0)
    {
        throw CORBA::INTERNAL ();
    }

    typedef typename COMP_SVNT::_stub_type stub_type;
    COMP_SVNT *svt = 0;
    ACE_NEW_THROW_EX (svt,
                      COMP_SVNT (exe,
                                 home.in (),
                                 (this->ins_name_ + buffer).c_str (),
                                 this,
                                 cnt_safe),
                      CORBA::NO_MEMORY ());

    PortableServer::ServantBase_var safe (svt);
    PortableServer::ObjectId_var oid;

    CORBA::Object_var objref =
        cnt_safe->install_servant (svt,
                                   Container_Types::COMPONENT_t,
                                   oid.out ());
    typedef typename COMP_SVNT::_stub_type stub_type;
    typename COMP_SVNT::_stub_var_type ho = stub_type::_narrow (objref.in ());

    Components::CCMObject_var ccmobjref =
        Components::CCMObject::_narrow (objref.in ());

    this->objref_map_.bind (
        oid.in (),
        Components::CCMObject::_duplicate (ccmobjref.in ()));
    return ho._retn ();
}
Example #3
0
Components::CCMObject_ptr
AssemblyImpl::getInstance (std::string name)
throw( Components::CreateFailure )
{
    Components::CCMObject_var obj;
	std::map < std::string, Components::CCMObject_var > ::iterator it;
    it = instanceMap_.find(name);
    if (it != instanceMap_.end())
    {
        obj = (*it).second;
        return obj._retn();
    }

    DEBUG_OUT2(".......... no component reference for ", name);
    throw Components::CreateFailure();
}
Example #4
0
  Components::CCMObject_ptr
  Session_Container_i::install_component (const char *primary_artifact,
                                          const char *entry_point,
                                          const char *servant_artifact,
                                          const char *servant_entrypoint,
                                          const char *name,
                                          CORBA::Long open_mode)
  {
    CIAO_TRACE ("Session_Container_i::install_component");

    ACE_DLL executor_dll;
    ACE_DLL servant_dll;

    Container_i < ::CIAO::Session_Container>::prepare_installation ("Session Component",
                                                                    primary_artifact,
                                                                    entry_point,
                                                                    servant_artifact,
                                                                    servant_entrypoint,
                                                                    name,
                                                                    open_mode,
                                                                    executor_dll,
                                                                    servant_dll);

    void *void_ptr_executor = executor_dll.symbol (ACE_TEXT_CHAR_TO_TCHAR (entry_point));
    void *void_ptr_servant = servant_dll.symbol (ACE_TEXT_CHAR_TO_TCHAR (servant_entrypoint));

    ptrdiff_t tmp_ptr = reinterpret_cast<ptrdiff_t> (void_ptr_executor);
    ComponentFactory ccreator = reinterpret_cast<ComponentFactory> (tmp_ptr);

    tmp_ptr = reinterpret_cast<ptrdiff_t> (void_ptr_servant);
    ComponentServantFactory screator = reinterpret_cast<ComponentServantFactory> (tmp_ptr);

    if (ccreator == 0)
      {
        std::ostringstream err;
        err << "Entry point [" << entry_point << "] invalid in DLL ["
            << primary_artifact;

        CIAO_ERROR (1,
                    (LM_ERROR,
                     CLINFO
                     "Session_Container_i::install_component "
                     "- Error: %C\n",
                     err.str ().c_str ()));

        throw CIAO::Installation_Failure (name,
                                          err.str ().c_str ());
      }

    if (screator == 0)
      {
        std::ostringstream err;
        err << "Entry point [" << servant_entrypoint << "] invalid in DLL ["
            << servant_artifact;

        CIAO_ERROR (1,
                    (LM_ERROR,
                     CLINFO
                     "Session_Container_i::install_component "
                     "- Error: %C\n",
                     err.str ().c_str ()));

        throw CIAO::Installation_Failure (name,
                                          err.str ().c_str ());
      }

    CIAO_DEBUG (9,
                (LM_TRACE,
                 CLINFO
                 "Session_Container_i::install_component - "
                 "Loading component executor\n"));

    Components::EnterpriseComponent_var component_executor;
    try
      {
        component_executor = ccreator ();
      }
    catch (...)
      {
        CIAO_ERROR (1,
                    (LM_ERROR, CLINFO
                    "Session_Container_i::install_component - "
                     "Caught unexpected exception from component factory."));
        throw CIAO::Installation_Failure (name,
                                          "Component executor factory threw exception");
      }

    if (CORBA::is_nil (component_executor.in ()))
      {
        CIAO_ERROR (1,
                    (LM_ERROR,
                     CLINFO
                     "Session_Container_i::install_component - "
                     "Component executor factory failed.\n"));

        throw CIAO::Installation_Failure (name,
                                          "Component executor factory failed");
      }

    CIAO_DEBUG (9,
                (LM_TRACE,
                 CLINFO
                 "Session_Container_i::install_component - "
                 "Loading component servant\n"));

    PortableServer::Servant component_servant;

    try
      {
        component_servant = screator (component_executor.in (),
                                      this,
                                      name);
      }
    catch (...)
      {
        CIAO_ERROR (1,
                    (LM_ERROR, CLINFO
                    "Session_Container_i::install_component - "
                     "Caught unexpected exception from component servant factory."));
        throw CIAO::Installation_Failure (name,
                                          "Component servant factory threw exception");
      }


    if (component_servant == 0)
      {
        CIAO_ERROR (1,
                    (LM_ERROR,
                     CLINFO
                     "Session_Container_i::install_component - "
                     "Component servant factory failed.\n"));

        throw CIAO::Installation_Failure (name,
                                          "Component servant factory failed");
      }

    PortableServer::ServantBase_var safe (component_servant);

    CIAO_DEBUG (9,
                (LM_TRACE,
                 CLINFO
                 "Session_Container_i::install_component - "
                 "Installing component servant\n"));

    PortableServer::ObjectId_var oid;

    CORBA::Object_var objref =
      this->install_servant (component_servant,
                             Container_Types::COMPONENT_t,
                             oid.out ());

    Components::CCMObject_var componentref =
      Components::CCMObject::_narrow (objref.in ());

    CIAO_DEBUG (9, (LM_TRACE, CLINFO
                    "Session_Container_i::install_component - "
                    "Component successfully created\n"));

    return componentref._retn ();
  }
Example #5
0
void 
AssemblyImpl::tear_down ()
throw( Components::RemoveFailure )
{
	DEBUG_OUT2( "AssemblyImpl: tear down the application for ", package_ );

	//
	// use reverse start order to remove components
	//
	std::vector < std::string > ::reverse_iterator iter;
	std::map < std::string, Components::CCMObject_var > ::iterator instanceIter;
	Components::CCMObject_var comp;
	for(iter = data_.start_order_.rbegin();
		iter != data_.start_order_.rend();
		iter++ )
	{
		instanceIter = instanceMap_.find( *iter );
		if( instanceIter != instanceMap_.end() )
		{
			try
			{
				DEBUG_OUT2("..... remove ", instanceIter->first );
				comp = Components::CCMObject::_duplicate( instanceIter->second );
				comp->remove();
			}
			catch (CORBA::Exception&)
			{
				NORMAL_ERR2( "AssemblyImpl: EXCEPTION during removal of ", instanceIter->first );
			}

			instanceMap_.erase( instanceIter );
		}
	}

	//
	// call remove for all remaining components
	//
	for( instanceIter = instanceMap_.begin();
		 instanceIter != instanceMap_.end();
		 instanceIter++ )
	{
		try
		{
			DEBUG_OUT2( "..... remove ", instanceIter->first );
			instanceIter->second->remove();
		}
		catch (CORBA::Exception&)
		{
			NORMAL_ERR2( "AssemblyImpl: EXCEPTION during removal of ", instanceIter->first );
		}
	}

	instanceMap_.clear();

	//
	// remove homes/containers/servers
	//
	std::vector < HostData > ::iterator host_iter;
	std::vector < ProcessData > ::iterator process_iter;
	std::vector < HomeInstanceData > ::iterator home_iter;

	// for each host
	for(host_iter = data_.hosts_.begin();
		host_iter != data_.hosts_.end();
		host_iter++)
	{
		// for each processcollocation
		for(process_iter = (*host_iter).processes.begin(); 
			process_iter != (*host_iter).processes.end();
			process_iter++)
		{
			// for each homeplacement
			for(home_iter = (*process_iter).homes.begin();
				home_iter != (*process_iter).homes.end();
				home_iter++)
			{
				// remove home
				try
				{
					DEBUG_OUT2( "..... remove home ", (*home_iter).id );
					(*home_iter).container->remove_home(getHomeInstance((*home_iter).id));
				}
				catch (Components::RemoveFailure)
				{
					NORMAL_ERR2( "AssemblyImpl: remove home failure for ", (*home_iter).id );
				}
				catch (CORBA::Exception& e)
				{
					NORMAL_ERR2( "AssemblyImpl: EXCEPTION during removal of home ", (*home_iter).id );
#ifdef MICO_ORB
					e._print (std::cerr);
					std::cerr << std::endl;
#endif
				}

				// remove container
				try
				{
					DEBUG_OUT( "..... remove container" );
					(*home_iter).container->remove();
				}
				catch (Components::RemoveFailure)
				{
					NORMAL_ERR( "AssemblyImpl: remove container failure" );
				}
				catch (CORBA::Exception& e)
				{
					NORMAL_ERR( "AssemblyImpl: EXCEPTION during removal of container" );
#ifdef MICO_ORB
					e._print (std::cerr);
					std::cerr << std::endl;
#endif
				}
			}

			// remove component server
			try
			{
				DEBUG_OUT( "..... remove component server" );
				(*process_iter).server->remove();
			}
			catch (Components::RemoveFailure)
			{
				NORMAL_ERR( "AssemblyImpl: remove component server failure");
			}
			catch (CORBA::Exception& e)
			{
				NORMAL_ERR( "AssemblyImpl: EXCEPTION during removal of container" );
#ifdef MICO_ORB
				e._print (std::cerr);
				std::cerr << std::endl;
#endif
			}
		}
	}

	homeMap_.clear();

	//
	// uninstall
	//
	uninstall();

	DEBUG_OUT3( "application for ", package_, " is teared down and uninstalled" );
}
Example #6
0
void
AssemblyImpl::configurationComplete()
throw(Components::CreateFailure)
{
	DEBUG_OUT2( "AssemblyImpl: start the application for ", package_ );

	//
    // call configuration complete according to startorder
    //
	std::vector < std::string > ::iterator iter;
	for(iter = data_.start_order_.begin();
		iter != data_.start_order_.end();
		iter++)
	{
		std::string id = (*iter);
		Components::CCMObject_var comp = instanceMap_[id];
		if( comp )
		{
			try
			{
				DEBUG_OUT2( "..... configuration_complete for ", id );
				comp->configuration_complete();
			}
			catch (CORBA::Exception& ex)
			{
				NORMAL_ERR2( "AssemblyImpl: EXCEPTION during configuration_complete: ", ex );
                throw Components::CreateFailure();
			}
			catch ( ... )
			{
				NORMAL_ERR( "AssemblyImpl: UNKNOWN EXCEPTION during configuration_complete" );
                throw Components::CreateFailure();
			}
		}
	}

	//
	// call configuration complete for all remaining components
	//
   	Components::CCMObject_var comp;
	std::map < std::string, Components::CCMObject_var > ::iterator instanceIter;
	bool found = false;
	for(instanceIter = instanceMap_.begin();
		instanceIter != instanceMap_.end();
		instanceIter++ )
	{
		//
		// if not yet started, start it
		//
		for(iter = data_.start_order_.begin();
			iter != data_.start_order_.end();
			iter++ )
		{
			if( instanceIter->first == *iter )
			{
				found = true;
				break;
			}
		}

		if( !found )
		{
			try
			{
				DEBUG_OUT2( "..... configuration_complete for ", instanceIter->first );
				instanceIter->second->configuration_complete();
			}
			catch ( CORBA::Exception& ex )
			{
				NORMAL_ERR2( "AssemblyImpl EXCEPTION during configuration_complete : ", ex );
                throw Components::CreateFailure();
			}
			catch ( ... )
			{
				NORMAL_ERR( "AssemblyImpl: UNKNOWN EXCEPTION during configuration_complete" );
                throw Components::CreateFailure();
			}
		}
	}

	// set assembly state to active
	state_ = Components::Deployment::INSERVICE;
}
Example #7
0
void
AssemblyImpl::connectevent()
throw(Components::CreateFailure)
{
	std::string consume;
	std::string emit;
	Components::CCMObject_var consumer;
	Components::EventConsumerBase_var consumer_port;
	Components::CCMObject_var source;
	std::vector < EventConnectionData > ::const_iterator iter;
	for(iter = data_.event_connections_.begin();
		iter != data_.event_connections_.end();
		iter++)
	{
		DEBUG_OUT( "AssemblyImpl: make event connection" );
		
		//
		// consumer
		//
		consume = (*iter).consumer.name;
		DEBUG_OUT2( "..... consumer is ", (*iter).consumer.ref.name );
		DEBUG_OUT2( "..... port is ", consume );
		consumer = Components::CCMObject::_narrow(getRef((*iter).consumer.ref));
        
		try
	    {
		    consumer_port = consumer->get_consumer(consume.c_str());
	    }
		catch(Components::InvalidName&)
	    {
			NORMAL_ERR2( "AssemblyImpl: invalid sink name ", consume );
		    throw Components::CreateFailure();
		}

		if((*iter).kind == EMITTER)
		{
			//
			// emitter
			//
            source = Components::CCMObject::_narrow( getRef((*iter).emitter.ref) );
            emit = (*iter).emitter.name;
            DEBUG_OUT2( "..... emitter is ", (*iter).emitter.ref.name );
			DEBUG_OUT2( "..... port is ", emit );
                    
            //
            // connect
            //
      		try
      		{
       			source->connect_consumer( emit.c_str(), consumer_port );
       		}
       		catch(Components::InvalidName&)
       		{
				NORMAL_ERR2( "AssemblyImpl: invalid emits name ", emit );
       			throw Components::CreateFailure();
       		}
       		catch(Components::AlreadyConnected&)
            {
				NORMAL_ERR2( "AssemblyImpl: already connected with ", emit );
       			throw Components::CreateFailure();
       		}
        }
		else
		{
			//
			// publishesport
			//
			source = Components::CCMObject::_narrow( getRef((*iter).emitter.ref) );
            emit = (*iter).emitter.name;
            DEBUG_OUT2( "..... publisher is ", (*iter).emitter.ref.name );
			DEBUG_OUT2( "..... port is ", emit );

            //
            // connect
            //
            try
       		{
                // returns Cookie TODO
	   			source->subscribe( emit.c_str(), consumer_port );
	   		}
	   		catch( Components::InvalidName& )
	   		{
				NORMAL_ERR2( "AssemblyImpl: invalid publishes name ", emit );
	   			throw Components::CreateFailure();
	   		}
        }
    }
}
Example #8
0
void
AssemblyImpl::connectinterface ()
throw(Components::CreateFailure)
{
	std::string receptacle;
	Components::CCMObject_var user;
	std::string facet;
	CORBA::Object_var provider;
	std::vector < InterfaceConnectionData > ::const_iterator iter;
	for(iter = data_.interface_connections_.begin();
		iter != data_.interface_connections_.end();
		iter++)
	{
		DEBUG_OUT( "AssemblyImpl: make interface connection" );

		//
		// receptacle
		//
		receptacle = (*iter).use.name;
		DEBUG_OUT2( "..... user is ", (*iter).use.ref.name );
		DEBUG_OUT2( "..... receptacle is ", receptacle );
		user = Components::CCMObject::_narrow(getRef((*iter).use.ref));
		
		//
		// facet
		//
		facet = (*iter).provide.name;
		DEBUG_OUT2( "..... provider is ", (*iter).provide.ref.name );
		provider = getRef((*iter).provide.ref);
		if(facet.length())
		{
			// get facet
			DEBUG_OUT2( "..... facet is ", facet );
			try
			{
				provider = Components::CCMObject::_narrow(provider)->provide_facet(facet.c_str());
			}
			catch( Components::InvalidName& )
			{
				NORMAL_ERR2( "AssemblyImpl: invalid facet name ", facet );
				throw Components::CreateFailure();
			}
		}

		//
		// connect
		//
		Components::Cookie_var cookie;
		try
		{
			cookie = user->connect(receptacle.c_str(), provider);
		}
		catch(Components::InvalidName&)
		{
			NORMAL_ERR2( "AssemblyImpl: invalid receptacle name ", receptacle );
			throw Components::CreateFailure();
		}
		catch( Components::InvalidConnection& )
		{
			NORMAL_ERR2( "AssemblyImpl: invalid connection for ", receptacle );
			throw Components::CreateFailure();
		}
		catch( Components::AlreadyConnected& )
		{
			NORMAL_ERR2( "AssemblyImpl: already connected for ", receptacle );
			throw Components::CreateFailure();
		}
		catch( Components::ExceededConnectionLimit& )
		{
			NORMAL_ERR2( "AssemblyImpl: exceeded connection limit for ", receptacle );
			throw Components::CreateFailure();
		}
	}
}