I have a daemon (which must be written in C) which should have a remote like common media players do:
mediaplayer-rc --enqueue /path/to/song.mp3
If mediaplayer-daemon
isn't running, it is started by the remote controller. The remote will pass the message.
I took the approach that seemed the most intuitive to me:
- The client application tries to connect() and starts the daemon if it can't
- The client uses
argp
to parse the params into a struct - The client sends the struct through a socket
- The server receives the struct and interprets this
I've got a simple demo implementation using libev and unix sockets on github.
My reasoning is that it seemed easier to write a client in C that I can call from other languages with their version of system()
than to try to get another language to pack
the struct correctly or to get the C library to parse some other format.
But I don't think that this is a particularly elegant solution.
Another possibility, would be to use JSON. The downshot being that using a JSON parser in vanilla C would probably be more complex by far than the args parser. The upshot being that JSON (or YAML) is in the standard libraries of just about every other language.
Any suggestions? Anybody know how songbird, gimp, itunes, and other apps with remotes handle this issue?