Plugin architecture for file type recognition

I am working on an application that needs to handle "file paths" to import different types of resources. The problem is that in different situations (for example, OS) some file types are not applicable. What I want to do is define a very simple set of types that everyone supports and then have a built-in architecture that supports adding new types with minimal code modification, ideally (for now) adding one line in main () for each type and binding in the required files. Later, I would like to be able to do this loading at runtime via DLL / SO loading.

Now the file types I need to support include

  • binaries
  • text files
  • catalogs
  • zip files
  • any of the above in zip files

in the future I would like to support things like:

  • HTML / XML files
  • Docx files
  • image files
  • MP3 files
  • SQL queries SQL
  • HTTP URL
  • email via POP / IMAP
  • and etc.

A solution to this problem would be to support (at least) two levels of processing.

  • identity-based "path" to determine where to look (local files versus MySQL and HTTP va. MSSQL ...)
  • determining the content type of a resource to determine the exact type of resource once it is found. (this is a file, what type of file?)

Another part of the same application solves a similar problem for output by creating a hash table of output types and output handlers where plugins are registered with the main application.

Ultimately the big question is: does anyone have any advice on how to proceed? Does anyone create a similar system and have any advice based on this experience?

+1


source to share


1 answer


This reminds me of the XMMS2 plugin chain. XMMS2 is a music player capable of playing different formats from different sources (files, http, shoutcast, daap, ...).

The main idea behind the XMMS2 plugin is that each plugin records what input it can handle and what its output will be (from unknown / encoded binary to 44kHz 16-bit integer audio).

Transport plugins such as files or descriptor files with a specific prefix (file: // daap: //). They then output the binary, which is then linked to the next suitable plugin. Thus, the mp3 plugin uses this "magic" test to see if it is an mp3 stream. If it isn't, then the next plugin (like ogg vorbis or modplug) will try to execute.



You can do the same, for example to magically recognize ZIP files (they have a standard prefix), so you have a plugin that unpacks them in your chain. Then several ressource extensions like PNG, JPG could additionally recognize the output.

An interesting feature of this design is the lack of architecture differences between the plugin talking to the web server, unpacking the plugins zip files, or reading the plugin in a piece of music / image. You can, for example, even read from a zip file into a zip file. Plugins do not need to know each other or talk to each other, they only pass data down the chain.

If you are interested in implementing there, which is obviously best for working with audio - you can find the project here: http://wiki.xmms2.xmms.se/ I mentioned that the code is x-platform and the plugins are loadable libraries?

+1


source







All Articles