pause is working again
[amper.git] / amperrpcsrv.d
blob1750b6ca133ab0f22d531e696e9a4ed5ca316d63
1 /* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module amperrpcsrv;
19 import core.time;
21 import std.concurrency;
23 import iv.cmdcon;
24 import iv.ncrpc;
25 import iv.vfs;
27 import amperrpcproto;
28 import amperskin;
31 // ////////////////////////////////////////////////////////////////////////// //
32 void startRPCServer () {
33 srvsk.create(AmperRPCSocket);
35 servertid = spawn(&rpcServerThread, thisTid);
39 void stopRPCServer () {
40 UDSocket sk;
41 sk.connect(AmperRPCSocket);
42 sk.writeNum!ushort(RPCommand.Err);
46 // ////////////////////////////////////////////////////////////////////////// //
47 private:
48 __gshared Tid servertid;
49 __gshared UDSocket srvsk;
52 void rpcServerThread (Tid ownerTid) {
53 rpcRegisterEndpoint!amperGetSongVisTitle(delegate () { return (ampMain !is null ? ampMain.wtitle.title : ""); });
54 rpcRegisterEndpoint!amperScanDir(delegate (string path, bool append) { concmdf!"scan_dir \"%s\" %s"(path, append ? "tan" : "ona"); });
55 rpcRegisterEndpoint!amperPlay(delegate () { concmd("song_play"); });
56 rpcRegisterEndpoint!amperStop(delegate () { concmd("song_stop"); });
57 rpcRegisterEndpoint!amperTogglePause(delegate () { concmd("song_pause_toggle"); });
58 rpcRegisterEndpoint!amperClearPlaylist(delegate () { concmd("pl_clear"); });
59 rpcRegisterEndpoint!amperConsoleCommand(delegate (string cmd) { concmd(cmd); });
61 //conwriteln(rpcEndpointNames);
63 for (;;) {
64 receiveTimeout(Duration.min,
65 (Variant v) { conwriteln("FUUUUUU"); },
68 auto cl = srvsk.accept();
69 auto cmd = cl.readNum!ushort;
70 if (cmd != RPCommand.Call) {
71 if (cmd != RPCommand.Err) conwriteln("invalid command");
72 break;
74 //conwriteln("connection comes!");
75 cl.rpcProcessCall;