-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
925 lines (780 loc) · 21.3 KB
/
client.cpp
File metadata and controls
925 lines (780 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
/* This file is part of pas.
pas is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pas is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pas. If not, see <http://www.gnu.org/licenses/>.
*/
/* pas is Copyright 2017 by Perry Kivolowitz
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <map>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <memory.h>
#include <getopt.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <unordered_set>
#include <time.h>
#include <assert.h>
#include "commands.pb.h"
using namespace std;
using namespace pas;
// Template function comment
/* FUNCTIONNAME() - This function
Parameters:
Returns:
Side Effects:
Expceptions:
*/
#define LOG(s) (string(__FILE__) + string(":") + string(__FUNCTION__) + string("() line: ") + to_string(__LINE__) + string(" msg: ") + string(s))
// NOTE:
// NOTE: Assumtion about the number of DACS (for sanity checking of user input.
// NOTE:
const int MAX_DACS = 4;
bool keep_going = true;
bool network_diagnostics = false;
void SIGHandler(int signal_number)
{
keep_going = false;
cout << endl;
throw string("");
}
/* InitializeNetworkConnection() - This function provides standard network
client initialization which does include accepting an alternate port
and IP address.
The default port and IP, BTW, are: 5077 and 127.0.0.1.
TODO: Calls to perror print directly to the console. These should
be folded into the LOG().
Parameters:
int argc Taken from main - the usual meaning
char * argv[] Taken from main - the usual meaning
Returns:
int The file descriptor of the server socket
Side Effects:
Expceptions:
Error conditions are thrown as strings.
*/
int InitializeNetworkConnection(int argc, char * argv[])
{
int server_socket = -1;
int port = 5077;
char * ip = (char *) ("127.0.0.1");
int opt;
while ((opt = getopt(argc, argv, "dh:p:")) != -1)
{
switch (opt)
{
case 'd':
network_diagnostics = true;
cout << "network diagnostics turned on" << endl;
break;
case 'h':
ip = optarg;
break;
case 'p':
port = atoi(optarg);
break;
}
}
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if (server_socket < 0)
{
perror("Failed to open socket");
throw string("");
}
hostent * server_hostent = gethostbyname(ip);
if (server_hostent == nullptr)
{
close(server_socket);
throw "Failed gethostbyname()";
}
sockaddr_in server_sockaddr;
memset(&server_sockaddr, 0, sizeof(sockaddr_in));
server_sockaddr.sin_family = AF_INET;
memmove(&server_sockaddr.sin_addr.s_addr, server_hostent->h_addr, server_hostent->h_length);
server_sockaddr.sin_port = htons(port);
if (connect(server_socket, (struct sockaddr*) &server_sockaddr, sizeof(sockaddr_in)) == -1)
{
perror("Connection failed");
throw string("");
}
return server_socket;
}
// Holdover from old version of code. Useful routine to remains here for
// possible future reuse.
inline bool BeginsWith(string const & fullString, string const & prefix)
{
bool rv = false;
if (fullString.length() >= prefix.length())
{
rv = (0 == fullString.compare(0, prefix.length(), prefix));
}
return rv;
}
// Holdover from old version of code. Useful routine to remains here for
// possible future reuse.
bool HasEnding (string const & fullString, string const & ending)
{
bool rv = false;
if (fullString.length() >= ending.length())
{
rv = (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
}
return rv;
}
/* GetResponse() - This function abstracts the network code and error checking
when a response is expected from the pas server. Examples of this include
sending a SELECT_QUERY command and then GetResponse() to receive back the
rows resulting from the DB query.
An important consequence of this function is not only to provide the
Protocol Buffer string but also to taste the buffer to determine its type.
The type field is required to be the first value in all messages.
Yes, this has the side effect of having to decode the string twice.
Parameters:
int server_socket The incoming file descriptor for the server network connection
Type type The OUTGOING type sniffed from the incoming message
Returns:
string The binary (couched in a string) PB message.
Side Effects:
None
Expceptions:
Errors are thrown as strings.
*/
string GetResponse(int server_socket, Type & type)
{
// NOTE:
// NOTE: length cannot be a size_t as size_t may be 64 bits or 32 bits.
// NOTE: unsigned int is always 32 bits.
// NOTE:
unsigned int length = 0;
size_t bytes_read = recv(server_socket, (void *) &length, sizeof(length), 0);
if (bytes_read != sizeof(length))
throw LOG("bad recv getting length: " + to_string(bytes_read));
//cout << LOG("recv of length: " + to_string(length)) << endl;
length = ntohl(length);
string s;
s.resize(length);
//cout << LOG("string is now: " + to_string(s.size())) << endl;
bytes_read = recv(server_socket, (void *) &s[0], length, MSG_WAITALL);
if (bytes_read != length)
throw LOG("bad recv getting pbuffer: " + to_string(bytes_read));
GenericPB g;
// Start out as generic and return this if a) it IS generic or b) does not parse out.
type = GENERIC;
if (g.ParseFromString(s))
type = g.type();
return s;
}
/* GetDeviceNumber() - This function abstracts asking the user for a device
number. This is done so many times, it is an appropriate abstraction.
Note that the device number is tested against MAX_DACS which contains
an arbitrary value. A useful change for the future would be to somehow
determine from actual hardware how many DACs there are.
Parameters:
None
Returns:
int The user entered (and vetted) device number.
Side Effects:
None
Expceptions:
None
*/
int GetDeviceNumber()
{
string l;
cout << "Device number: ";
getline(cin, l);
int device_id = atoi(l.c_str());
if (device_id < 0 || device_id >= MAX_DACS)
device_id = -1;
return device_id;
}
void SendPB(string & s, int server_socket);
/* InnerPlayCommand() - This function abstracts the mechanics of sending
play commands. It is useful because both PLAY and PLAYLIST need
this function (so it is shared).
Parameters:
int device_id Which DACS to queue up
int track The database index of the track to queue
int server_socket How to reach the server
Returns:
None
Side Effects:
A false assertion could crash the program.
Expceptions:
SendPB can send exceptions on network issues.
This function can throw exceptions due to bad Protocol Buffer outcomes.
These exceptions are in the form of strings.
*/
/* This is broken out to make the playlist feature easier.
*/
static void InnerPlayCommand(int device_id, int track, int server_socket)
{
assert(server_socket >= 0);
string s;
PlayTrackCommand c;
c.set_type(PLAY_TRACK_DEVICE);
c.set_device_id(device_id);
c.set_track_id(track);
bool outcome = c.SerializeToString(&s);
if (!outcome)
throw string("InnerPlayCommand() bad serialize");
SendPB(s, server_socket);
}
/* FUNCTIONNAME() - This function executes as a consequence of the
user's selection of a PLAY command. It asks for a DAC number and
track number and uses InnerPlayCommand to actually queue up
the track. Note the "queue." If the play queue is empty, the
newly queued track is played immediately. Else it goes to the
back of the bus.
Parameters:
int server_socket How to reach the server.
Returns:
None
Side Effects:
A false assertion can crash the program.
Expceptions:
InnerPlayCommand can cause string-based exceptions.
*/
static void PlayCommand(int server_socket)
{
assert(server_socket >= 0);
int device_id = GetDeviceNumber();
if (device_id >= 0)
{
string s;
cout << "Track number: ";
getline(cin, s);
int track = atoi(s.c_str());
InnerPlayCommand(device_id, track, server_socket);
}
}
/* SimplePlayList() - This function asks for a file name which
contains database track numbers. This is a simple playlist
in that track numbers are transitory. If the database is
rebuilt, track numbers change. This is for debugging.
Parameters:
int server_socket How to reach the server
Returns:
None
Side Effects:
A false assertion can crash the program.
Expceptions:
Network related errors can cause string-based exception.
*/
static void SimplePlayList(int server_socket)
{
assert(server_socket >= 0);
int device_id = GetDeviceNumber();
if (device_id >= 0)
{
string l;
cout << "File: ";
getline(cin, l);
ifstream f(l);
if (f.is_open())
{
while (getline(f, l))
{
if (l.size() == 0)
continue;
int track = atoi(l.c_str());
InnerPlayCommand(device_id, track, server_socket);
usleep(900000);
}
}
f.close();
}
}
/* DacInfoCommand() - This function implements the command of the
same name. It is not abstracted because the return from the pas
server is an array of rows which must be interpreted in a unique
way.
Parameters:
int server_socket How to reach the server
Returns:
None
Side Effects:
None
Expceptions:
Both this function and the network functions it calls can
throw string-based exceptions.
*/
void DacInfoCommand(int server_socket)
{
assert(server_socket >= 0);
string s;
DacInfo a;
a.set_type(DAC_INFO_COMMAND);
bool outcome = a.SerializeToString(&s);
if (!outcome)
throw string("DacInfoCommand() bad serialize");
SendPB(s, server_socket);
Type type;
s = GetResponse(server_socket, type);
if (type == Type::SELECT_RESULT)
{
//cout << LOG("got select result back") << endl;
SelectResult sr;
if (!sr.ParseFromString(s))
{
throw string("dacinfocomment parsefromstring failed");
}
cout << setw(8) << left << "Index";
cout << setw(24) << "Name";
cout << setw(24) << "Who";
cout << setw(24) << "What";
cout << setw(10) << "When";
cout << right << endl;
for (int i = 0; i < sr.row_size(); i++)
{
Row r = sr.row(i);
google::protobuf::Map<string, string> results = r.results();
cout << setw(8) << left << results[string("index")];
cout << setw(24) << results[string("name")];
cout << setw(24) << results[string("who")];
cout << setw(24) << results[string("what")];
cout << setw(10) << results[string("when")];
cout << right << endl;
}
}
else
{
throw string("did not get select_result back");
}
}
/* TrackCountCommand() - This function SHOULD BE MERGED WITH ArtistCountCommand.
It sends a zero-arg message and receives back a one integer message.
This is exactly the same as ArtistCount.
Parameters:
int server_socket How to reach the server.
Returns:
None
Side Effects:
A false assertion can crash the program.
Something is printed.
Expceptions:
Both this function and the network functions it calls can
throw string-based exceptions.
*/
void TrackCountCommand(int server_socket)
{
assert(server_socket >= 0);
string s;
TrackCountQuery a;
a.set_type(TRACK_COUNT);
bool outcome = a.SerializeToString(&s);
if (!outcome)
throw string("TrackCountQuery() bad serialize");
SendPB(s, server_socket);
Type type;
s = GetResponse(server_socket, type);
if (type == Type::ONE_INT)
{
OneInteger o;
if (o.ParseFromString(s))
{
cout << o.value() << endl;
}
else
{
throw string("track_count parsefromstring failed");
}
}
else
{
throw string("track count did not get a ONE_INTEGER back");
}
}
/* ArtistCountCommand() - This function SHOULD BE MERGED WITH TrackCountCommand.
It sends a zero-arg message and receives back a one integer message.
This is exactly the same as ArtistCount.
Parameters:
int server_socket How to reach the server.
Returns:
None
Side Effects:
A false assertion can crash the program.
Something is printed.
Expceptions:
Both this function and the network functions it calls can
throw string-based exceptions.
*/
void ArtistCountCommand(int server_socket)
{
assert(server_socket >= 0);
string s;
ArtistCountQuery a;
a.set_type(ARTIST_COUNT);
bool outcome = a.SerializeToString(&s);
if (!outcome)
throw string("ArtistCountQuery() bad serialize");
SendPB(s, server_socket);
Type type;
s = GetResponse(server_socket, type);
if (type == Type::ONE_INT)
{
OneInteger o;
if (o.ParseFromString(s))
{
cout << o.value() << endl;
}
else
{
throw string("artist_count parsefromstring failed");
}
}
else
{
throw string("artist did not get a ONE_INTEGER back");
}
}
/* DevCmdForOneString() - This function abstracts several commands
in the same what the ArtistCount and TrackCount should be. These
commands, such as Who, What, and When send a DAC number and
receive back a string.
Parameters:
Type type The precise command to send
int server_socket How to reach the server
Returns:
None
Side Effects:
A false assertion can crash the program.
Something is printed.
Expceptions:
This and network functions can throw string-based exceptions.
*/
void DevCmdForOneString(Type type, int server_socket)
{
int device_id = GetDeviceNumber();
if (device_id >= 0)
{
string s;
// Using a WhatCommand container - doesn't matter.
WhatDeviceCommand sc;
sc.set_type(type);
sc.set_device_id(device_id);
bool outcome = sc.SerializeToString(&s);
if (!outcome)
throw string("bad serialize");
SendPB(s, server_socket);
Type type;
s = GetResponse(server_socket, type);
if (type == Type::ONE_STRING)
{
OneString o;
if (o.ParseFromString(s))
{
cout << o.value() << endl;
}
else
{
throw string("parsefromstring failed");
}
}
else
{
throw string("did not get a ONE_STRING back");
}
}
}
void BadDAC(int server_socket)
{
string s;
WhatDeviceCommand sc;
sc.set_type(WHO_DEVICE);
sc.set_device_id(99);
bool outcome = sc.SerializeToString(&s);
if (!outcome)
throw string("bad serialize");
SendPB(s, server_socket);
Type type;
s = GetResponse(server_socket, type);
if (type == Type::ONE_STRING)
{
OneString o;
if (o.ParseFromString(s))
{
cout << o.value() << endl;
}
else
{
throw string("parsefromstring failed");
}
}
else
{
cout << "Got back: " << type << endl;
if (type == ERROR_MESSAGE)
{
OneInteger o;
o.ParseFromString(s);
cout << "Specific error: " << o.value() << endl;
}
}
}
/* SelectCommand() - This function initiates a full blowed
SQL select statement inside pas. The mount of data returned
could be large (and will be deserialized twice).
This function cannot be abstracted (well, in theory it can
be combined with DacInfo) due to custom parsing of the result
data.
Parameters:
int server_socket The usual
Returns:
None
Side Effects:
A false assertion can crash the program.
A potentially large amount is printed.
Expceptions:
Lots of ways this comman can throw a atring-based exception,
*/
void SelectCommand(int server_socket)
{
assert(server_socket >= 0);
string s;
SelectQuery c;
c.set_type(SELECT_QUERY);
cout << "Column: ";
getline(cin, s);
c.set_column(s);
cout << "Pattern: ";
getline(cin , s);
c.set_pattern(s);
bool outcome = c.SerializeToString(&s);
cout << c.DebugString() << endl;
if (!outcome)
throw string("bad serialize");
cout << LOG(to_string(s.size())) << endl;
SendPB(s, server_socket);
Type type;
s = GetResponse(server_socket, type);
if (type == Type::SELECT_RESULT)
{
SelectResult sr;
if (!sr.ParseFromString(s))
{
throw string("parsefromstring failed");
}
cout << left << setw(8) << "id" << setw(24) << "artist" << setw(24) << "title" << setw(10) << "duration" << endl;
for (int i = 0; i < sr.row_size(); i++)
{
Row r = sr.row(i);
// r.results_size() tells how many are in map.
google::protobuf::Map<string, string> m = r.results();
cout << left << setw(8) << m["id"];
cout << setw(30) << m["artist"];
cout << setw(36) << m["title"];
cout << setw(10) << m["duration"];
cout << endl;
/* KEEP THIS AROUND FOR REFERENCE
google::protobuf::Map<string, string>::iterator it = m.begin();
while (it != m.end())
{
cout << it->first << " " << it->second << endl;
it++;
}
*/
}
}
else
{
throw string("did not get back a SELECT_RESULT");
}
}
/* FUNCTIONNAME() - This function
Parameters:
Returns:
Side Effects:
Expceptions:
*/
void DevCmdNoReply(Type type, int server_socket)
{
int device_id = GetDeviceNumber();
if (device_id >= 0)
{
string s;
ClearDeviceCommand c;
c.set_type(type);
c.set_device_id(device_id);
bool outcome = c.SerializeToString(&s);
if (!outcome)
throw string("bad serialize");
SendPB(s, server_socket);
}
}
/* FUNCTIONNAME() - This function
Parameters:
Returns:
Side Effects:
Expceptions:
*/
void SendPB(string & s, int server_socket)
{
assert(server_socket >= 0);
// NOTE:
// NOTE: length must be an unsigned int rather than a size_t. size_t
// NOTE: varies on different size machines. unsigned int is always
// NOTE: 32 bits.
// NOTE:
unsigned int length = (unsigned int) s.size();
unsigned int ll = length;
length = htonl(length);
if (network_diagnostics) {
cout << "Length: " << ll << " encoded as: " << hex << length << dec << endl;
if (ll < 64) {
for (size_t i = 0; i < 64 && i < ll; i++) {
cout << setfill('0') << hex << "0x" << setw(2) << hex << (int)(((int) s.at(i)) & 0xFF) << " ";
if (i % 32 == 0 && i > 0)
cout << endl;
}
if (ll % 32 != 0)
cout << endl;
}
cout << dec << setfill(' ');
}
size_t bytes_sent = send(server_socket, (const void *) &length, sizeof(length), 0);
if (bytes_sent != sizeof(length))
throw string("bad bytes_sent for length");
bytes_sent = send(server_socket, (const void *) s.data(), ll, 0);
if (bytes_sent != ll)
throw string("bad bytes_sent for message");
if (network_diagnostics)
cout << "sent " << ll << " bytes" << " " << strerror(errno) << endl;
}
void MakeHelp(vector<pair<string, string>> & help_text)
{
help_text.push_back(make_pair("", ""));
help_text.push_back(make_pair("help", ""));
help_text.push_back(make_pair("stop", ""));
help_text.push_back(make_pair("resume", ""));
help_text.push_back(make_pair("pause", ""));
help_text.push_back(make_pair("play", ""));
help_text.push_back(make_pair("playlist", ""));
help_text.push_back(make_pair("next", ""));
help_text.push_back(make_pair("clear", ""));
help_text.push_back(make_pair("select", ""));
help_text.push_back(make_pair("who", ""));
help_text.push_back(make_pair("what", ""));
help_text.push_back(make_pair("when", ""));
help_text.push_back(make_pair("tracks", ""));
help_text.push_back(make_pair("artists", ""));
help_text.push_back(make_pair("quit", ""));
help_text.push_back(make_pair("dacs", ""));
help_text.push_back(make_pair("time", ""));
help_text.push_back(make_pair("rc", ""));
help_text.push_back(make_pair("qs", ""));
}
void PrintHelp(vector<pair<string, string>> & help_text)
{
for (auto it = help_text.begin(); it < help_text.end(); it++) {
cout << setw(10) << left << it->first << setw(30) << it->second << endl;
}
}
int main(int argc, char * argv[])
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
vector<pair<string, string>> help_text;
MakeHelp(help_text);
int server_socket = -1;
bool connected = false;
string l;
try
{
if (signal(SIGINT, SIGHandler) == SIG_ERR)
throw LOG("");
server_socket = InitializeNetworkConnection(argc, argv);
connected = true;
while (keep_going)
{
cout << "Command: ";
getline(cin, l);
if (l == "baddac")
BadDAC(server_socket);
if (l == "help")
PrintHelp(help_text);
if (l == "stop")
DevCmdNoReply(STOP_DEVICE, server_socket);
else if (l == "resume")
DevCmdNoReply(RESUME_DEVICE, server_socket);
else if (l == "pause")
DevCmdNoReply(PAUSE_DEVICE, server_socket);
else if (l == "play")
PlayCommand(server_socket);
else if (l == "playlist")
SimplePlayList(server_socket);
else if (l == "next")
DevCmdNoReply(NEXT_DEVICE, server_socket);
else if (l == "clear")
DevCmdNoReply(CLEAR_DEVICE, server_socket);
else if (l == "select")
SelectCommand(server_socket);
else if (l == "what")
DevCmdForOneString(WHAT_DEVICE, server_socket);
else if (l == "who")
DevCmdForOneString(WHO_DEVICE, server_socket);
else if (l == "tracks")
TrackCountCommand(server_socket);
else if (l == "artists")
ArtistCountCommand(server_socket);
else if (l == "quit")
break;
else if (l == "dacs")
DacInfoCommand(server_socket);
else if (l == "time")
DevCmdForOneString(WHEN_DEVICE, server_socket);
else if (l == "rc")
{
if (!connected)
{
server_socket = InitializeNetworkConnection(argc, argv);
if (server_socket < 0)
break;
connected = true;
cout << "Connected" << endl;
}
continue;
}
else if (l == "qs")
{
if (!connected)
continue;
close(server_socket);
cout << "Disconnected" << endl;
connected = false;
server_socket = -1;
}
else if ("netd")
{
network_diagnostics = !network_diagnostics;
cout << "Network diagnostic mode: " << network_diagnostics << endl;
}
}
}
catch (string s)
{
if (s.size() > 0)
cerr << s << endl;
}
if (server_socket >= 0)
close(server_socket);
return 0;
}