-
Notifications
You must be signed in to change notification settings - Fork 222
/
main.cpp
1212 lines (1096 loc) · 48.5 KB
/
main.cpp
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
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************\
* Copyright (c) 2004-2024
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program 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 2 of the License, or (at your option) any later
* version.
*
* This program 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
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
\******************************************************************************/
#include <QCoreApplication>
#include <QDir>
#include <iostream>
#include "global.h"
#ifndef HEADLESS
# include <QApplication>
# include <QMessageBox>
# include "serverdlg.h"
# ifndef SERVER_ONLY
# include "clientdlg.h"
# endif
#endif
#include "settings.h"
#ifndef SERVER_ONLY
# include "testbench.h"
#endif
#include "util.h"
#ifdef ANDROID
# include <QtAndroidExtras/QtAndroid>
#endif
#if defined( Q_OS_MACOS )
# include "mac/activity.h"
extern void qt_set_sequence_auto_mnemonic ( bool bEnable );
#endif
#include <memory>
#ifndef NO_JSON_RPC
# include "rpcserver.h"
# include "serverrpc.h"
# ifndef SERVER_ONLY
# include "clientrpc.h"
# endif
#endif
// Implementation **************************************************************
int main ( int argc, char** argv )
{
#if defined( Q_OS_MACOS )
// Mnemonic keys are default disabled in Qt for MacOS. The following function enables them.
// Qt will not show these with underline characters in the GUI on MacOS. (#1873)
qt_set_sequence_auto_mnemonic ( true );
#endif
QString strArgument;
double rDbleArgument;
QList<QString> CommandLineOptions;
QList<QString> ServerOnlyOptions;
QList<QString> ClientOnlyOptions;
// initialize all flags and string which might be changed by command line
// arguments
#if ( defined( SERVER_BUNDLE ) && defined( Q_OS_MACOS ) ) || defined( SERVER_ONLY )
// if we are on MacOS and we are building a server bundle or requested build with serveronly, start Jamulus in server mode
bool bIsClient = false;
qInfo() << "- Starting in server mode by default (due to compile time option)";
#else
bool bIsClient = true;
#endif
bool bUseGUI = true;
bool bStartMinimized = false;
bool bShowComplRegConnList = false;
bool bDisconnectAllClientsOnQuit = false;
bool bUseDoubleSystemFrameSize = true; // default is 128 samples frame size
bool bUseMultithreading = false;
bool bShowAnalyzerConsole = false;
bool bMuteStream = false;
bool bMuteMeInPersonalMix = false;
bool bDisableRecording = false;
bool bDelayPan = false;
bool bNoAutoJackConnect = false;
bool bUseTranslation = true;
bool bCustomPortNumberGiven = false;
bool bEnableIPv6 = false;
int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS;
quint16 iPortNumber = DEFAULT_PORT_NUMBER;
int iJsonRpcPortNumber = INVALID_PORT;
QString strJsonRpcBindIP = DEFAULT_JSON_RPC_LISTEN_ADDRESS;
quint16 iQosNumber = DEFAULT_QOS_NUMBER;
ELicenceType eLicenceType = LT_NO_LICENCE;
QString strMIDISetup = "";
QString strConnOnStartupAddress = "";
QString strIniFileName = "";
QString strHTMLStatusFileName = "";
QString strLoggingFileName = "";
QString strRecordingDirName = "";
QString strDirectoryAddress = "";
QString strServerListFileName = "";
QString strServerInfo = "";
QString strServerPublicIP = "";
QString strServerBindIP = "";
QString strServerListFilter = "";
QString strWelcomeMessage = "";
QString strClientName = "";
QString strJsonRpcSecretFileName = "";
#if defined( HEADLESS ) || defined( SERVER_ONLY )
Q_UNUSED ( bStartMinimized )
Q_UNUSED ( bUseTranslation )
Q_UNUSED ( bShowComplRegConnList )
Q_UNUSED ( bShowAnalyzerConsole )
Q_UNUSED ( bMuteStream )
#endif
#if defined( SERVER_ONLY )
Q_UNUSED ( bMuteMeInPersonalMix )
Q_UNUSED ( bNoAutoJackConnect )
Q_UNUSED ( bCustomPortNumberGiven )
#endif
#if !defined( HEADLESS ) && defined( _WIN32 )
if ( AttachConsole ( ATTACH_PARENT_PROCESS ) )
{
freopen ( "CONOUT$", "w", stdout );
freopen ( "CONOUT$", "w", stderr );
}
#endif
// When adding new options, follow the same order as --help output
// QT docu: argv()[0] is the program name, argv()[1] is the first
// argument and argv()[argc()-1] is the last argument.
// Start with first argument, therefore "i = 1"
for ( int i = 1; i < argc; i++ )
{
// Help (usage) flag ---------------------------------------------------
if ( ( !strcmp ( argv[i], "--help" ) ) || ( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) )
{
const QString strHelp = UsageArguments ( argv );
std::cout << qUtf8Printable ( strHelp );
exit ( 0 );
}
// Version number ------------------------------------------------------
if ( ( !strcmp ( argv[i], "--version" ) ) || ( !strcmp ( argv[i], "-v" ) ) )
{
std::cout << qUtf8Printable ( GetVersionAndNameStr ( false ) );
exit ( 0 );
}
// Common options:
// Initialization file -------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) )
{
strIniFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- initialization file name: %1" ).arg ( strIniFileName ) );
CommandLineOptions << "--inifile";
continue;
}
// Disable GUI flag ----------------------------------------------------
if ( GetFlagArgument ( argv, i, "-n", "--nogui" ) )
{
bUseGUI = false;
qInfo() << "- no GUI mode chosen";
CommandLineOptions << "--nogui";
continue;
}
// Port number ---------------------------------------------------------
if ( GetNumericArgument ( argc, argv, i, "-p", "--port", 0, 65535, rDbleArgument ) )
{
iPortNumber = static_cast<quint16> ( rDbleArgument );
bCustomPortNumberGiven = true;
qInfo() << qUtf8Printable ( QString ( "- selected port number: %1" ).arg ( iPortNumber ) );
CommandLineOptions << "--port";
continue;
}
// JSON-RPC port number ------------------------------------------------
if ( GetNumericArgument ( argc, argv, i, "--jsonrpcport", "--jsonrpcport", 0, 65535, rDbleArgument ) )
{
iJsonRpcPortNumber = static_cast<quint16> ( rDbleArgument );
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC port number: %1" ).arg ( iJsonRpcPortNumber ) );
CommandLineOptions << "--jsonrpcport";
continue;
}
// JSON-RPC secret file name -------------------------------------------
if ( GetStringArgument ( argc, argv, i, "--jsonrpcsecretfile", "--jsonrpcsecretfile", strArgument ) )
{
strJsonRpcSecretFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC secret file: %1" ).arg ( strJsonRpcSecretFileName ) );
CommandLineOptions << "--jsonrpcsecretfile";
continue;
}
// JSON-RPC bind address ------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "--jsonrpcbindip", "--jsonrpcbindip", strArgument ) )
{
strJsonRpcBindIP = QString ( strArgument );
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC will bind to: %1 if enabled" ).arg ( strJsonRpcBindIP ) );
CommandLineOptions << "--jsonrpcbindip";
continue;
}
// Quality of Service --------------------------------------------------
if ( GetNumericArgument ( argc, argv, i, "-Q", "--qos", 0, 255, rDbleArgument ) )
{
iQosNumber = static_cast<quint16> ( rDbleArgument );
qInfo() << qUtf8Printable ( QString ( "- selected QoS value: %1" ).arg ( iQosNumber ) );
CommandLineOptions << "--qos";
continue;
}
// Disable translations ------------------------------------------------
if ( GetFlagArgument ( argv, i, "-t", "--notranslation" ) )
{
bUseTranslation = false;
qInfo() << "- translations disabled";
CommandLineOptions << "--notranslation";
continue;
}
// Enable IPv6 ---------------------------------------------------------
if ( GetFlagArgument ( argv, i, "-6", "--enableipv6" ) )
{
bEnableIPv6 = true;
qInfo() << "- IPv6 enabled";
CommandLineOptions << "--enableipv6";
continue;
}
// Server only:
// Disconnect all clients on quit --------------------------------------
if ( GetFlagArgument ( argv, i, "-d", "--discononquit" ) )
{
bDisconnectAllClientsOnQuit = true;
qInfo() << "- disconnect all clients on quit";
CommandLineOptions << "--discononquit";
ServerOnlyOptions << "--discononquit";
continue;
}
// Directory to register with ------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-e", "--directoryaddress", strArgument ) )
{
strDirectoryAddress = strArgument;
qInfo() << qUtf8Printable ( QString ( "- register with directory at address: %1" ).arg ( strDirectoryAddress ) );
CommandLineOptions << "--directoryaddress";
ServerOnlyOptions << "--directoryaddress";
continue;
}
// Central server ** D E P R E C A T E D ** ----------------------------
if ( GetStringArgument ( argc,
argv,
i,
"--centralserver", // for backwards compatibility
"--directoryserver", // also for backwards compatibility
strArgument ) )
{
strDirectoryAddress = strArgument;
qInfo() << qUtf8Printable ( QString ( "- register with directory at address: %1" ).arg ( strDirectoryAddress ) );
CommandLineOptions << "--directoryaddress";
ServerOnlyOptions << "--directoryaddress";
continue;
}
// Directory file ------------------------------------------------------
if ( GetStringArgument ( argc,
argv,
i,
"--directoryfile", // no short form
"--directoryfile",
strArgument ) )
{
strServerListFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server list persistence file: %1" ).arg ( strServerListFileName ) );
CommandLineOptions << "--directoryfile";
ServerOnlyOptions << "--directoryfile";
continue;
}
// Server list filter --------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-f", "--listfilter", strArgument ) )
{
strServerListFilter = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server list filter: %1" ).arg ( strServerListFilter ) );
CommandLineOptions << "--listfilter";
ServerOnlyOptions << "--listfilter";
continue;
}
// Use 64 samples frame size mode --------------------------------------
if ( GetFlagArgument ( argv, i, "-F", "--fastupdate" ) )
{
bUseDoubleSystemFrameSize = false; // 64 samples frame size
qInfo() << qUtf8Printable ( QString ( "- using %1 samples frame size mode" ).arg ( SYSTEM_FRAME_SIZE_SAMPLES ) );
CommandLineOptions << "--fastupdate";
ServerOnlyOptions << "--fastupdate";
continue;
}
// Use logging ---------------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-l", "--log", strArgument ) )
{
strLoggingFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- logging file name: %1" ).arg ( strLoggingFileName ) );
CommandLineOptions << "--log";
ServerOnlyOptions << "--log";
continue;
}
// Use licence flag ----------------------------------------------------
if ( GetFlagArgument ( argv, i, "-L", "--licence" ) )
{
// LT_CREATIVECOMMONS is now used just to enable the pop up
eLicenceType = LT_CREATIVECOMMONS;
qInfo() << "- licence required";
CommandLineOptions << "--licence";
ServerOnlyOptions << "--licence";
continue;
}
// HTML status file ----------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) )
{
strHTMLStatusFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- HTML status file name: %1" ).arg ( strHTMLStatusFileName ) );
CommandLineOptions << "--htmlstatus";
ServerOnlyOptions << "--htmlstatus";
continue;
}
// Server info ---------------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-o", "--serverinfo", strArgument ) )
{
strServerInfo = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server info: %1" ).arg ( strServerInfo ) );
CommandLineOptions << "--serverinfo";
ServerOnlyOptions << "--serverinfo";
continue;
}
// Server Public IP ----------------------------------------------------
if ( GetStringArgument ( argc,
argv,
i,
"--serverpublicip", // no short form
"--serverpublicip",
strArgument ) )
{
strServerPublicIP = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server public IP: %1" ).arg ( strServerPublicIP ) );
CommandLineOptions << "--serverpublicip";
ServerOnlyOptions << "--serverpublicip";
continue;
}
// Enable delay panning on startup -------------------------------------
if ( GetFlagArgument ( argv, i, "-P", "--delaypan" ) )
{
bDelayPan = true;
qInfo() << "- starting with delay panning";
CommandLineOptions << "--delaypan";
ServerOnlyOptions << "--delaypan";
continue;
}
// Recording directory -------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-R", "--recording", strArgument ) )
{
strRecordingDirName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- recording directory name: %1" ).arg ( strRecordingDirName ) );
CommandLineOptions << "--recording";
ServerOnlyOptions << "--recording";
continue;
}
// Disable recording on startup ----------------------------------------
if ( GetFlagArgument ( argv,
i,
"--norecord", // no short form
"--norecord" ) )
{
bDisableRecording = true;
qInfo() << "- recording will not take place until enabled";
CommandLineOptions << "--norecord";
ServerOnlyOptions << "--norecord";
continue;
}
// Server mode flag ----------------------------------------------------
if ( GetFlagArgument ( argv, i, "-s", "--server" ) )
{
bIsClient = false;
qInfo() << "- server mode chosen";
CommandLineOptions << "--server";
ServerOnlyOptions << "--server";
continue;
}
// Server Bind IP --------------------------------------------------
if ( GetStringArgument ( argc,
argv,
i,
"--serverbindip", // no short form
"--serverbindip",
strArgument ) )
{
strServerBindIP = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server bind IP: %1" ).arg ( strServerBindIP ) );
CommandLineOptions << "--serverbindip";
ServerOnlyOptions << "--serverbindip";
continue;
}
// Use multithreading --------------------------------------------------
if ( GetFlagArgument ( argv, i, "-T", "--multithreading" ) )
{
bUseMultithreading = true;
qInfo() << "- using multithreading";
CommandLineOptions << "--multithreading";
ServerOnlyOptions << "--multithreading";
continue;
}
// Maximum number of channels ------------------------------------------
if ( GetNumericArgument ( argc, argv, i, "-u", "--numchannels", 1, MAX_NUM_CHANNELS, rDbleArgument ) )
{
iNumServerChannels = static_cast<int> ( rDbleArgument );
qInfo() << qUtf8Printable ( QString ( "- maximum number of channels: %1" ).arg ( iNumServerChannels ) );
CommandLineOptions << "--numchannels";
ServerOnlyOptions << "--numchannels";
continue;
}
// Server welcome message ----------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-w", "--welcomemessage", strArgument ) )
{
strWelcomeMessage = strArgument;
qInfo() << qUtf8Printable ( QString ( "- welcome message: %1" ).arg ( strWelcomeMessage ) );
CommandLineOptions << "--welcomemessage";
ServerOnlyOptions << "--welcomemessage";
continue;
}
// Start minimized -----------------------------------------------------
if ( GetFlagArgument ( argv, i, "-z", "--startminimized" ) )
{
bStartMinimized = true;
qInfo() << "- start minimized enabled";
CommandLineOptions << "--startminimized";
ServerOnlyOptions << "--startminimized";
continue;
}
// Client only:
// Connect on startup --------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-c", "--connect", strArgument ) )
{
strConnOnStartupAddress = NetworkUtil::FixAddress ( strArgument );
qInfo() << qUtf8Printable ( QString ( "- connect on startup to address: %1" ).arg ( strConnOnStartupAddress ) );
CommandLineOptions << "--connect";
ClientOnlyOptions << "--connect";
continue;
}
// Disabling auto Jack connections -------------------------------------
if ( GetFlagArgument ( argv, i, "-j", "--nojackconnect" ) )
{
bNoAutoJackConnect = true;
qInfo() << "- disable auto Jack connections";
CommandLineOptions << "--nojackconnect";
ClientOnlyOptions << "--nojackconnect";
continue;
}
// Mute stream on startup ----------------------------------------------
if ( GetFlagArgument ( argv, i, "-M", "--mutestream" ) )
{
bMuteStream = true;
qInfo() << "- others on a server will not hear you (mutestream active)";
CommandLineOptions << "--mutestream";
ClientOnlyOptions << "--mutestream";
continue;
}
// For headless client mute my own signal in personal mix --------------
if ( GetFlagArgument ( argv,
i,
"--mutemyown", // no short form
"--mutemyown" ) )
{
bMuteMeInPersonalMix = true;
qInfo() << "- you will not hear yourself in the server mix (mutemyown active)";
CommandLineOptions << "--mutemyown";
ClientOnlyOptions << "--mutemyown";
continue;
}
// Client Name ---------------------------------------------------------
if ( GetStringArgument ( argc,
argv,
i,
"--clientname", // no short form
"--clientname",
strArgument ) )
{
strClientName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- client name: %1" ).arg ( strClientName ) );
CommandLineOptions << "--clientname";
ClientOnlyOptions << "--clientname";
continue;
}
// Controller MIDI channel ---------------------------------------------
if ( GetStringArgument ( argc,
argv,
i,
"--ctrlmidich", // no short form
"--ctrlmidich",
strArgument ) )
{
strMIDISetup = strArgument;
qInfo() << qUtf8Printable ( QString ( "- MIDI controller settings: %1" ).arg ( strMIDISetup ) );
CommandLineOptions << "--ctrlmidich";
ClientOnlyOptions << "--ctrlmidich";
continue;
}
// Undocumented:
// Show all registered servers in the server list ----------------------
// Undocumented debugging command line argument: Show all registered
// servers in the server list regardless if a ping to the server is
// possible or not.
if ( GetFlagArgument ( argv,
i,
"--showallservers", // no short form
"--showallservers" ) )
{
bShowComplRegConnList = true;
qInfo() << "- show all registered servers in server list";
CommandLineOptions << "--showallservers";
ClientOnlyOptions << "--showallservers";
continue;
}
// Show analyzer console -----------------------------------------------
// Undocumented debugging command line argument: Show the analyzer
// console to debug network buffer properties.
if ( GetFlagArgument ( argv,
i,
"--showanalyzerconsole", // no short form
"--showanalyzerconsole" ) )
{
bShowAnalyzerConsole = true;
qInfo() << "- show analyzer console";
CommandLineOptions << "--showanalyzerconsole";
ClientOnlyOptions << "--showanalyzerconsole";
continue;
}
// Unknown option ------------------------------------------------------
qCritical() << qUtf8Printable ( QString ( "%1: Unknown option '%2' -- use '--help' for help" ).arg ( argv[0] ).arg ( argv[i] ) );
// clicking on the Mac application bundle, the actual application
// is called with weird command line args -> do not exit on these
#if !( defined( Q_OS_MACOS ) )
exit ( 1 );
#endif
}
// Dependencies ------------------------------------------------------------
#ifdef HEADLESS
if ( bUseGUI )
{
bUseGUI = false;
qWarning() << "No GUI support compiled. Running in headless mode.";
}
#endif
#ifdef SERVER_ONLY
if ( bIsClient )
{
qCritical() << "Only --server mode is supported in this build.";
exit ( 1 );
}
#else
if ( bIsClient )
{
if ( ServerOnlyOptions.size() != 0 )
{
qCritical() << qUtf8Printable ( QString ( "%1: Server only option(s) '%2' used. Did you omit '--server'?" )
.arg ( argv[0] )
.arg ( ServerOnlyOptions.join ( ", " ) ) );
exit ( 1 );
}
// mute my own signal in personal mix is only supported for headless mode
if ( bUseGUI && bMuteMeInPersonalMix )
{
bMuteMeInPersonalMix = false;
qWarning() << "Mute my own signal in my personal mix is only supported in headless mode.";
}
// adjust default port number for client: use different default port than the server since
// if the client is started before the server, the server would get a socket bind error
if ( !bCustomPortNumberGiven )
{
iPortNumber += 10; // increment by 10
qInfo() << qUtf8Printable ( QString ( "- allocated port number: %1" ).arg ( iPortNumber ) );
}
}
else
#endif
{
if ( ClientOnlyOptions.size() != 0 )
{
qCritical() << qUtf8Printable (
QString ( "%1: Client only option(s) '%2' used. See '--help' for help" ).arg ( argv[0] ).arg ( ClientOnlyOptions.join ( ", " ) ) );
exit ( 1 );
}
if ( ServerOnlyOptions.contains ( "--serverinfo" ) && strServerInfo.split ( ";" ).count() < 3 )
{
qWarning() << qUtf8Printable (
QString ( "\"--serverinfo '%1'\": must contain [name];[city];[country] - value will be ignored" ).arg ( strServerInfo ) );
strServerInfo = "";
}
#ifndef HEADLESS
if ( bUseGUI )
{
// by definition, when running with the GUI we always default to registering somewhere but
// until the settings are loaded we do not know where, so we cannot be prescriptive here
if ( !strServerListFileName.isEmpty() )
{
qInfo() << "Note:"
<< "Server list persistence file will only take effect when running as a directory.";
}
if ( !strServerListFilter.isEmpty() )
{
qInfo() << "Note:"
<< "Server list filter will only take effect when running as a directory.";
}
}
else
#endif
{
// the inifile is not supported for the headless server mode
if ( !strIniFileName.isEmpty() )
{
qWarning() << "No initialization file support in headless server mode.";
strIniFileName = "";
}
// therefore we know everything based on command line options
if ( strDirectoryAddress.compare ( "localhost", Qt::CaseInsensitive ) == 0 || strDirectoryAddress.compare ( "127.0.0.1" ) == 0 )
{
if ( !strServerListFileName.isEmpty() )
{
QFileInfo serverListFileInfo ( strServerListFileName );
if ( !serverListFileInfo.exists() )
{
QFile strServerListFile ( strServerListFileName );
if ( !strServerListFile.open ( QFile::OpenModeFlag::ReadWrite ) )
{
qWarning() << qUtf8Printable (
QString ( "Cannot create %1 for reading and writing. Please check permissions." ).arg ( strServerListFileName ) );
strServerListFileName = "";
}
}
else if ( !serverListFileInfo.isFile() )
{
qWarning() << qUtf8Printable (
QString ( "Server list file %1 must be a plain file. Please check the name." ).arg ( strServerListFileName ) );
strServerListFileName = "";
}
else if ( !serverListFileInfo.isReadable() || !serverListFileInfo.isWritable() )
{
qWarning() << qUtf8Printable (
QString ( "Server list file %1 must be readable and writeable. Please check the permissions." )
.arg ( strServerListFileName ) );
strServerListFileName = "";
}
}
if ( !strServerListFilter.isEmpty() )
{
QStringList slWhitelistAddresses = strServerListFilter.split ( ";" );
for ( int iIdx = 0; iIdx < slWhitelistAddresses.size(); iIdx++ )
{
// check for special case: [version]
if ( ( slWhitelistAddresses.at ( iIdx ).length() > 2 ) && ( slWhitelistAddresses.at ( iIdx ).left ( 1 ) == "[" ) &&
( slWhitelistAddresses.at ( iIdx ).right ( 1 ) == "]" ) )
{
// Good case - it seems QVersionNumber isn't fussy
}
else if ( slWhitelistAddresses.at ( iIdx ).isEmpty() )
{
qWarning() << "There is empty entry in the server list filter that will be ignored";
}
else
{
QHostAddress InetAddr;
if ( !InetAddr.setAddress ( slWhitelistAddresses.at ( iIdx ) ) )
{
qWarning() << qUtf8Printable (
QString ( "%1 is not a valid server list filter entry. Only plain IP addresses are supported" )
.arg ( slWhitelistAddresses.at ( iIdx ) ) );
}
}
}
}
}
else
{
if ( !strServerListFileName.isEmpty() )
{
qWarning() << "Server list persistence file will only take effect when running as a directory.";
strServerListFileName = "";
}
if ( !strServerListFilter.isEmpty() )
{
qWarning() << "Server list filter will only take effect when running as a directory.";
strServerListFileName = "";
}
}
if ( strDirectoryAddress.isEmpty() )
{
if ( !strServerPublicIP.isEmpty() )
{
qWarning() << "Server Public IP will only take effect when registering a server with a directory.";
strServerPublicIP = "";
}
}
else
{
if ( !strServerPublicIP.isEmpty() )
{
QHostAddress InetAddr;
if ( !InetAddr.setAddress ( strServerPublicIP ) )
{
qWarning() << "Server Public IP is invalid. Only plain IP addresses are supported.";
strServerPublicIP = "";
}
}
}
}
if ( !strServerBindIP.isEmpty() )
{
QHostAddress InetAddr;
if ( !InetAddr.setAddress ( strServerBindIP ) )
{
qWarning() << "Server Bind IP is invalid. Only plain IP addresses are supported.";
strServerBindIP = "";
}
}
#ifndef NO_JSON_RPC
// strJsonRpcBind address defaults to loopback and should not be empty, but
// in the odd chance that an empty IP is passed, we'll check for it here.
if ( strJsonRpcBindIP.trimmed().isEmpty() )
{
qCritical() << qUtf8Printable ( QString ( "JSON-RPC is enabled but the bind address provided is empty, exiting." ) );
exit ( 1 );
}
// This means of testing the validity of IP addresses is far from perfect but
// we do it here as an upfront check. The downstream network calls will error
// out on malformed addresses not caught here.
{
QHostAddress InetAddr;
if ( !InetAddr.setAddress ( strJsonRpcBindIP ) )
{
qCritical() << qUtf8Printable ( QString ( "The JSON-RPC address specified is not valid, exiting. " ) );
exit ( 1 );
}
}
#endif
}
// Application/GUI setup ---------------------------------------------------
// Application object
#ifdef HEADLESS
QCoreApplication* pApp = new QCoreApplication ( argc, argv );
#else
# if defined( Q_OS_IOS )
bUseGUI = true;
bIsClient = true; // Client only - TODO: maybe a switch in interface to change to server?
// bUseMultithreading = true;
QApplication* pApp = new QApplication ( argc, argv );
# else
QCoreApplication* pApp = bUseGUI ? new QApplication ( argc, argv ) : new QCoreApplication ( argc, argv );
# endif
#endif
#ifdef ANDROID
// special Android coded needed for record audio permission handling
auto result = QtAndroid::checkPermission ( QString ( "android.permission.RECORD_AUDIO" ) );
if ( result == QtAndroid::PermissionResult::Denied )
{
QtAndroid::PermissionResultMap resultHash = QtAndroid::requestPermissionsSync ( QStringList ( { "android.permission.RECORD_AUDIO" } ) );
if ( resultHash["android.permission.RECORD_AUDIO"] == QtAndroid::PermissionResult::Denied )
{
return 0;
}
}
#endif
#ifdef _WIN32
// set application priority class -> high priority
SetPriorityClass ( GetCurrentProcess(), HIGH_PRIORITY_CLASS );
// For accessible support we need to add a plugin to qt. The plugin has to
// be located in the install directory of the software by the installer.
// Here, we set the path to our application path.
QDir ApplDir ( QApplication::applicationDirPath() );
pApp->addLibraryPath ( QString ( ApplDir.absolutePath() ) );
#endif
#if defined( Q_OS_MACOS )
// On OSX we need to declare an activity to ensure the process doesn't get
// throttled by OS level Nap, Sleep, and Thread Priority systems.
CActivity activity;
activity.BeginActivity();
#endif
// init resources
Q_INIT_RESOURCE ( resources );
#ifndef SERVER_ONLY
//### TEST: BEGIN ###//
// activate the following line to activate the test bench,
// CTestbench Testbench ( "127.0.0.1", DEFAULT_PORT_NUMBER );
//### TEST: END ###//
#endif
#ifdef NO_JSON_RPC
if ( iJsonRpcPortNumber != INVALID_PORT || !strJsonRpcSecretFileName.isEmpty() )
{
qWarning() << "No JSON-RPC support in this build.";
}
#else
CRpcServer* pRpcServer = nullptr;
if ( iJsonRpcPortNumber != INVALID_PORT )
{
if ( strJsonRpcSecretFileName.isEmpty() )
{
qCritical() << qUtf8Printable ( QString ( "- JSON-RPC: --jsonrpcsecretfile is required. Exiting." ) );
exit ( 1 );
}
QFile qfJsonRpcSecretFile ( strJsonRpcSecretFileName );
if ( !qfJsonRpcSecretFile.open ( QFile::OpenModeFlag::ReadOnly ) )
{
qCritical() << qUtf8Printable ( QString ( "- JSON-RPC: Unable to open secret file %1. Exiting." ).arg ( strJsonRpcSecretFileName ) );
exit ( 1 );
}
QTextStream qtsJsonRpcSecretStream ( &qfJsonRpcSecretFile );
QString strJsonRpcSecret = qtsJsonRpcSecretStream.readLine();
if ( strJsonRpcSecret.length() < JSON_RPC_MINIMUM_SECRET_LENGTH )
{
qCritical() << qUtf8Printable ( QString ( "JSON-RPC: Refusing to run with secret of length %1 (required: %2). Exiting." )
.arg ( strJsonRpcSecret.length() )
.arg ( JSON_RPC_MINIMUM_SECRET_LENGTH ) );
exit ( 1 );
}
qWarning() << "- JSON-RPC: This interface is experimental and is subject to breaking changes even on patch versions "
"(not subject to semantic versioning) during the initial phase.";
pRpcServer = new CRpcServer ( pApp, strJsonRpcBindIP, iJsonRpcPortNumber, strJsonRpcSecret );
if ( !pRpcServer->Start() )
{
qCritical() << qUtf8Printable ( QString ( "- JSON-RPC: Server failed to start. Exiting." ) );
exit ( 1 );
}
}
#endif
try
{
#ifndef SERVER_ONLY
if ( bIsClient )
{
// Client:
// actual client object
CClient Client ( iPortNumber,
iQosNumber,
strConnOnStartupAddress,
strMIDISetup,
bNoAutoJackConnect,
strClientName,
bEnableIPv6,
bMuteMeInPersonalMix );
// load settings from init-file (command line options override)
CClientSettings Settings ( &Client, strIniFileName );
Settings.Load ( CommandLineOptions );
# ifndef NO_JSON_RPC
if ( pRpcServer )
{
new CClientRpc ( &Client, pRpcServer, pRpcServer );
}
# endif
# ifndef HEADLESS
if ( bUseGUI )
{
// load translation
if ( bUseTranslation )
{
CLocale::LoadTranslation ( Settings.strLanguage, pApp );
CInstPictures::UpdateTableOnLanguageChange();
}
// GUI object
CClientDlg ClientDlg ( &Client,
&Settings,
strConnOnStartupAddress,
strMIDISetup,
bShowComplRegConnList,
bShowAnalyzerConsole,
bMuteStream,
bEnableIPv6,
nullptr );
// show dialog
ClientDlg.show();
pApp->exec();
}
else
# endif
{
// only start application without using the GUI
qInfo() << qUtf8Printable ( GetVersionAndNameStr ( false ) );
pApp->exec();
}
}
else
#endif
{
// Server:
// actual server object
CServer Server ( iNumServerChannels,
strLoggingFileName,
strServerBindIP,
iPortNumber,
iQosNumber,
strHTMLStatusFileName,
strDirectoryAddress,
strServerListFileName,
strServerInfo,
strServerPublicIP,
strServerListFilter,
strWelcomeMessage,
strRecordingDirName,
bDisconnectAllClientsOnQuit,
bUseDoubleSystemFrameSize,
bUseMultithreading,
bDisableRecording,
bDelayPan,
bEnableIPv6,