5 import std
.concurrency
;
12 // ////////////////////////////////////////////////////////////////////////// //
13 __gshared
void delegate (string path
, bool append
=false) amperScanDir
;
14 __gshared
void delegate () amperPlay
;
15 __gshared
void delegate () amperStop
;
16 __gshared
void delegate () amperTogglePause
;
17 __gshared
void delegate () amperClearPlaylist
;
18 __gshared
void delegate (string cmd
) amperConsoleCommand
;
21 // ////////////////////////////////////////////////////////////////////////// //
22 auto amperRPCall(alias func
, A
...) (A args
) {
24 sk
.connect(AmperRPCSocket
);
25 return sk
.rpcall
!func(args
);
29 // ////////////////////////////////////////////////////////////////////////// //
30 enum AmperRPCSocket
= "/k8/amper";
33 // ////////////////////////////////////////////////////////////////////////// //
34 void startRPCServer () {
35 srvsk
.create(AmperRPCSocket
);
37 servertid
= spawn(&rpcServerThread
, thisTid
);
41 void stopRPCServer () {
43 sk
.connect(AmperRPCSocket
);
44 sk
.writeNum
!ushort(RPCommand
.Err
);
48 // ////////////////////////////////////////////////////////////////////////// //
50 __gshared Tid servertid
;
51 __gshared UDSocket srvsk
;
54 void rpcServerThread (Tid ownerTid
) {
55 rpcRegisterEndpoint
!amperScanDir(delegate (string path
, bool append
) { concmdf
!"scan_dir \"%s\" %s"(path
, append ?
"tan" : "ona"); });
56 rpcRegisterEndpoint
!amperPlay(delegate () { concmd("song_play"); });
57 rpcRegisterEndpoint
!amperStop(delegate () { concmd("song_stop"); });
58 rpcRegisterEndpoint
!amperTogglePause(delegate () { concmd("song_pause_toggle"); });
59 rpcRegisterEndpoint
!amperClearPlaylist(delegate () { concmd("pl_clear"); });
60 rpcRegisterEndpoint
!amperConsoleCommand(delegate (string cmd
) { concmd(cmd
); });
62 //conwriteln(rpcEndpointNames);
65 receiveTimeout(Duration
.min
,
66 (Variant v
) { conwriteln("FUUUUUU"); },
69 auto cl
= srvsk
.accept();
70 auto cmd
= cl
.readNum
!ushort;
71 if (cmd
!= RPCommand
.Call
) {
72 if (cmd
!= RPCommand
.Err
) conwriteln("invalid command");
75 //conwriteln("connection comes!");