/// \brief Return the unique identifier of the component type this
    ///        factory is responsible for
    ///
    /// \param locality     [in] The id of the locality this factory
    ///                     is responsible for.
    /// \param agas_client  [in] The AGAS client to use for component id
    ///                     registration (if needed).
    ///
    /// \return Returns the unique identifier of the component type this
    ///         factory instance is responsible for. This function throws
    ///         on any error.
    component_type get_component_type(naming::gid_type const& locality,
                                      naming::resolver_client& agas_client)
    {
        typedef typename Component::type_holder type_holder;
        if (component_invalid == components::get_component_type<type_holder>())
        {
            // First call to get_component_type, ask AGAS for a unique id.
            if (isenabled_) {
                component_type const ctype =
                    agas_client.register_factory(locality, get_component_name());

                if (component_invalid == ctype) {
                    HPX_THROW_EXCEPTION(duplicate_component_id,
                                        "component_factory::get_component_type",
                                        "the component name " + get_component_name() +
                                        " is already in use");
                }

                components::set_component_type<type_holder>(ctype);
            }
            else {
                component_type const ctype =
                    agas_client.get_component_id(get_component_name());

                components::set_component_type<type_holder>(ctype);
            }
        }
        return components::get_component_type<type_holder>();
    }
예제 #2
0
        /// \brief Return the unique identifier of the component type this
        ///        factory is responsible for
        ///
        /// \param locality     [in] The id of the locality this factory
        ///                     is responsible for.
        /// \param agas_client  [in] The AGAS client to use for component id
        ///                     registration (if needed).
        ///
        /// \return Returns the unique identifier of the component type this
        ///         factory instance is responsible for. This function throws
        ///         on any error.
        component_type get_component_type(naming::gid_type const& locality,
            naming::resolver_client& agas_client)
        {
            typedef typename Component::type_holder type_holder;
            if (component_invalid == components::get_component_type<type_holder>())
            {
                typedef typename Component::base_type_holder base_type_holder;
                component_type base_type =
                    components::get_component_type<base_type_holder>();
                if (component_invalid == base_type)
                {
                    // First call to get_component_type, ask AGAS for a unique id.
                    // NOTE: This assumes that the derived component is loaded.
                    base_type = agas_client.get_component_id(
                        unique_component_name<derived_component_factory,
                        base_name>::call());
                }

                component_type this_type;
                if (isenabled_) {
                    this_type = agas_client.register_factory(
                        locality, unique_component_name<derived_component_factory>
                        ::call());

                    if (component_invalid == this_type) {
                        HPX_THROW_EXCEPTION(duplicate_component_id,
                            "component_factory::get_component_type",
                            "the component name " + get_component_name() +
                            " is already in use");
                    }
                }
                else {
                    this_type = agas_client.get_component_id(
                        unique_component_name<derived_component_factory>::call());
                }

                components::set_component_type<type_holder>(
                    derived_component_type(this_type, base_type));
            }
            return components::get_component_type<type_holder>();
        }