Midi Devices Changed Callback?

I was wondering if there is, or could be, a way to receive some sort of callback when a midi-device has been connected / disconnected ?
I could build the functionality myself, but It’s nice to have a nudge in the right direction.

I inquired about this recently and Jules said that he may need it for a project soon so he might get to it, but hes a busy guy, and I’m sure he would appreciate it if you took a stab at it. I have a project which will also require this in the future, but unfortunately have some more immediate things on my plate so I haven’t had a go yet myself…