OpenCores代码阅读-之文件识别插件注册流程

文件的种类繁多,文件的识别就会很麻烦,并且还要考虑到可扩展性,所以这个文件的识别是以插件的形式来存在的,这里我们简要的说一下,这个插件的框架。 由于文件的格式很多,而且标准也很多,很难肯定某一文件就是某种的格式,因而就引入一个确信度的概念。 typ
摘要由CSDN通过智能技术生成

文件的种类繁多,文件的识别就会很麻烦,并且还要考虑到可扩展性,所以这个文件的识别是以插件的形式来存在的,这里我们简要的说一下,这个插件的框架。

 

由于文件的格式很多,而且标准也很多,很难肯定某一文件就是某种的格式,因而就引入一个确信度的概念。

 

typedef Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> PVMFRecognizerMIMEStringList;

 

typedef enum _PVMFRecognizerConfidence

{

    PVMFRecognizerConfidenceNotCertain,             // 100% sure not the format

    PVMFRecognizerConfidenceNotPossible,    // Maybe not the format

    PVMFRecognizerConfidenceUnknown,              // Not sure one way or the other

    PVMFRecognizerConfidencePossible,          // Maybe the format

    PVMFRecognizerConfidenceCertain                   // 100% sure of the format

} PVMFRecognizerConfidence;

 

然后是文件识别的结果:

class PVMFRecognizerResult

{

    public:

        PVMFRecognizerResult()

        {

        };

 

        // Copy constructor for use in Oscl_Vector

        PVMFRecognizerResult(const PVMFRecognizerResult& aSrc)

        {

            iRecognizedFormat = aSrc.iRecognizedFormat;

            iRecognitionConfidence = aSrc.iRecognitionConfidence;

            //     iRecognizerSubFormatList=aSrc.iRecognizerSubFormatList;

        };

 

        ~PVMFRecognizerResult()

        {

        };

 

        // The format of interest as a MIME string

        OSCL_HeapString<OsclMemAllocator> iRecognizedFormat;

        // The confidence level of recognition

        PVMFRecognizerConfidence iRecognitionConfidence;

        // If the format is a container format, the format of content within

//     Oscl_Vector<PVMFRecognizerResult, OsclMemAllocator> iRecognizerSubFormatList;

};

格式和确信度。

然后就是一个事件的监控者Observer

 

 

class PVMFRecognizerCommmandHandler

{

    public:

        

        virtual void RecognizerCommandCompleted(const PVMFCmdResp& aResponse) = 0;

        virtual ~PVMFRecognizerCommmandHandler() {}

};

 

#endif // PVMF_RECOGNIZER_TYPES_H_INCLUDED

这些都只是纯虚类。

 

文件识别,一般都是读取文件中的某些特殊的字节,然后才能做判断的,由于不同的文件读取的地方不同,并且识别的规则也是不同,所以定义一个基本的接口。

class PVMFRecognizerPluginInterface

{

  public:

        

        virtual ~PVMFRecognizerPluginInterface()

        {

        };

 

        本插件支持下面的一些格式的识别,以一个列表的形式返回

                     注意我们的文件识别都是以插件的形式存在的,这样就可以保证文件识别的可扩展性,每一个插件都必须从这个接口来继承,另外还必须有一个类统一管理这些插件,如插件的查找和注册

        virtual PVMFStatus SupportedFormats(PVMFRecognizerMIMEStringList& aSupportedFormatsList) = 0;

 

        

//给定一个数据源让你去识别,有一个优先考虑的格式列表参数,返回的是一个识别结果的列表,列出可能的格式和确信度。

        virtual PVMFStatus Recognize(PVMFDataStreamFactory& aSourceDataStreamFactory,

                                     PVMFRecognizerMIMEStringList* aFormatHint,

                                     Oscl_Vector<PVMFRecognizerResult, OsclMemAllocator>& aRecognizerResult) = 0;

 

        //或者识别所需的最小字节数

 

        virtual PVMFStatus GetRequiredMinBytesForRecognition(uint32& aBytes) = 0;

};

 

每一个插件都需要占用一定内存,因而就有下面的定义:一个插件的工厂的基类,每一个插件都要有一个这样的工厂接口来创建和删除某一个插件。

 

class PVMFRecognizerPluginFactory: public HeapBase

{

    public:

        

        virtual ~PVMFRecognizerPluginFactory()

        {

        };

 

        

        virtual PVMFRecognizerPluginInterface* CreateRecognizerPlugin() = 0;

 

        

        virtual void DestroyRecognizerPlugin(PVMFRecognizerPluginInterface* aPlugIn) = 0;

};

然后就是一个模板的定义,因为插件很多,这里我们写一个简单的模板:

 

template<class T>

class PVMFRecognizerPluginFactoryBasic : public PVMFRecognizerPluginFactory

{

    public:

        virtual ~PVMFRecognizerPluginFactoryBasic()

        {

        };

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值