Updated on 2022-03-13 GMT+08:00

AINNNodeFactory

Macro that supports service engine self-registration, provides the API for creating an NN node, and supports the query of registered NN node description information (by name or all). The AINNNodeFactory class is defined in ai_nn_node.h.

    class AINNNodeFactory
    {
    public:
        static AINNNodeFactory* GetInstance();

        /*
        * @brief   Create an NN node based on the NN node name.
        * @param [in] name   NN node name
        * @return std::shared_ptr<IAINNNode>   Pointer to the NN node object corresponding to the name. If nullptr is returned, the corresponding NN node cannot be found.
        */
        std::shared_ptr<IAINNNode> CreateNNNode(const std::string &name);

        /*
        * @brief   Obtain the descriptions of all registered NN nodes.
        * @param [out] nnnode_desc   Descriptions of all registered NN nodes
        * @return SUCCESS   Success
        * @return   Other: failure
        */
        void GetAllNNNodeDescription(AINNNodeDescriptionList &nnnode_desc);

        /*
        * @brief   Obtain the description of the NN node based on the NN node name.
        * @param [in] name   NN node name
        * @param [out] engin_desc    NN node description
        * @return SUCCESS   Success
        * @return   Other: failure
        */
        AIStatus GetNNNodeDescription(const std::string &name, AINNNodeDescription &engin_desc);

        /*
        * @brief   Register the NN node creation function.
        * @param [in] nnnode_desc   NN node description
        * @param [in] create_func   Function for creating an NN node
        * @return SUCCESS   Success
        * @return   Other: failure
        */
        AIStatus RegisterNNNodeCreator(const AINNNodeDescription &nnnode_desc, 
            AINNNODE_CREATE_FUN create_func);
        AIStatus RegisterNNNodeCreator(const string nnnode_str, 
            AINNNODE_CREATE_FUN create_func);

        /*
        * @brief   Deregister the NN node.
        * @param [in] name   NN node name
        * @return SUCCESS   Success
        */
        AIStatus UnRegisterNNNode(const AINNNodeDescription &nnnode_desc);
        AIStatus UnRegisterNNNode(const string nnnode_str);

    private:
        std::map<std::string, AINNNODE_CREATE_FUN> create_func_map_;
        std::map<std::string, AINNNodeDescription> nnnode_desc_map_;
        std::mutex  map_lock_;
    };