1

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?

4

1 回答 1

1

我不能推荐一个现成的库 - 相反,我建议你看一下Music Player Daemon。它使用一个非常简单的文本协议来远程控制整个应用程序。您也可以查看几个客户端(带有代码)。

于 2010-11-03T06:42:24.197 回答