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, version 3 of the License ONLY.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 import std
.concurrency
;
30 // ////////////////////////////////////////////////////////////////////////// //
31 void startRPCServer () {
32 srvsk
.create(AmperRPCSocket
);
34 servertid
= spawn(&rpcServerThread
, thisTid
);
38 void stopRPCServer () {
40 sk
.connect(AmperRPCSocket
);
41 sk
.writeNum
!ushort(RPCommand
.Err
);
45 // ////////////////////////////////////////////////////////////////////////// //
47 __gshared Tid servertid
;
48 __gshared UDSocket srvsk
;
51 void rpcServerThread (Tid ownerTid
) {
52 rpcRegisterEndpoint
!amperGetSongVisTitle(delegate () { return (ampMain
!is null ? ampMain
.wtitle
.title
: ""); });
53 rpcRegisterEndpoint
!amperScanDir(delegate (string path
, bool append
) { concmdf
!"scan_dir \"%s\" %s"(path
, append ?
"tan" : "ona"); });
54 rpcRegisterEndpoint
!amperPlay(delegate () { concmd("song_play"); });
55 rpcRegisterEndpoint
!amperStop(delegate () { concmd("song_stop"); });
56 rpcRegisterEndpoint
!amperTogglePause(delegate () { concmd("song_pause_toggle"); });
57 rpcRegisterEndpoint
!amperClearPlaylist(delegate () { concmd("pl_clear"); });
58 rpcRegisterEndpoint
!amperConsoleCommand(delegate (string cmd
) { concmd(cmd
); });
60 //conwriteln(rpcEndpointNames);
63 receiveTimeout(Duration
.min
,
64 (Variant v
) { conwriteln("FUUUUUU"); },
67 auto cl
= srvsk
.accept();
68 auto cmd
= cl
.readNum
!ushort;
69 if (cmd
!= RPCommand
.Call
) {
70 if (cmd
!= RPCommand
.Err
) conwriteln("invalid command");
73 //conwriteln("connection comes!");