Modular device

Per discussion, this is a preliminary refactoring of device.c to be more modular and support custom device types.

* make check is clean on my system
* I've refactored one of my internal devices (not included in this PR) to use the new API, and that device passes its own regression tests

There's probably more that can be done here, but this is sufficient for my present purpose.