Source
93
93
}
94
94
#endif
95
95
96
96
#include <casa/namespace.h>
97
97
using namespace casa;
98
98
99
99
static pid_t manager_root_pid = 0;
100
100
static pid_t manager_xvfb_pid = 0;
101
101
static bool sigterm_received = false;
102
102
static void preprocess_args( int argc, const char *argv[], int &numargs, char **&args,
103
-
char *&dbus_name, bool &do_dbus, bool &inital_run,
103
+
char *&server_string, bool &do_dbus, bool &inital_run,
104
104
bool &server_startup, bool &daemon,
105
105
bool &without_gui, bool &persistent, bool &casapy_start,
106
106
char *&logfile_path );
107
107
static void start_manager_root( const char *origname, int numargs, char **args,
108
108
const char *dbusname, bool without_gui, pid_t root_pid );
109
109
static void launch_server( const char *origname, int numargs, char **args,
110
110
const char *dbusname, bool without_gui,
111
111
bool persistent, bool casapy_start );
112
112
static char *find_xvfb( const char *paths );
113
113
static pid_t launch_xvfb( const char *name, pid_t pid, char *&display, char *&authority );
243
243
#endif
244
244
#if ! defined(WITHOUT_DBUS)
245
245
casa::dbus::diagnostic.argv( argc, argv );
246
246
#endif
247
247
248
248
bool server_startup = false;
249
249
bool daemon = false;
250
250
bool without_gui = false;
251
251
bool persistent = false;
252
252
bool casapy_start = false;
253
-
char *dbus_name = 0;
253
+
char *server_string = 0;
254
254
bool with_dbus = false;
255
255
char *logfile_path = 0;
256
256
bool initial_run = false;
257
257
258
258
char **args;
259
259
int numargs;
260
260
261
261
signal( SIGTERM, exiting_server );
262
262
263
263
// On Mac OS X by default, Qt swaps the Control and Meta (Command) keys (i.e., whenever
268
268
// QKeySequence::toString(QKeySequence::PortableText) will be different).
269
269
//
270
270
// This avoids this swapping, making the behavior more consistent when running on an X11
271
271
// system displaying on OSX or just when using it with OSX.
272
272
//
273
273
// This option makes *NO*DIFFERENCE* for the context menu on the "Point Button Tool".
274
274
// Thu Aug 30 10:32:15 EDT 2012 <drs>
275
275
//
276
276
// QCoreApplication::setAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
277
277
278
-
preprocess_args( argc, argv, numargs, args, dbus_name, with_dbus,
278
+
preprocess_args( argc, argv, numargs, args, server_string, with_dbus,
279
279
initial_run, server_startup, daemon, without_gui,
280
280
persistent, casapy_start, logfile_path );
281
281
282
282
//
283
283
// configure datapath for casacore and colormaps...
284
284
//
285
285
auto ends_with = []( const std::string& str, const std::string& ending ) {
286
286
return ( str.size( ) >= ending.size( ) ) && equal( ending.rbegin( ), ending.rend( ), str.rbegin( ) );
287
287
};
288
288
//
315
315
std::string fontpath = std::string("PGPLOT_FONT=") + pgplotpath + "Resources/pgplot/grfont.dat";
316
316
putenv(strdup(rgbpath.c_str( )));
317
317
putenv(strdup(fontpath.c_str( )));
318
318
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
319
319
// set up Qt Plugin Path
320
320
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
321
321
pluginpath += "Plugins";
322
322
QCoreApplication::addLibraryPath(QString(pluginpath.c_str( )));
323
323
}
324
324
325
-
} else if ( ends_with(exepath, "/AppRun") ) {
325
+
} else if ( ends_with(exepath, "/AppRun") || ends_with(exepath, "/CASAviewer.app/usr/bin/CASAviewer") ) {
326
326
327
327
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
328
328
// linux -- path is specific to package format
329
+
//
330
+
// .../AppRun implies AppImage bash script startup, e.g. from an unpacked AppImage
331
+
// .../CASAviewer.app/usr/bin/CASAviewer implies debugging or running from the
332
+
// build tree before it has been packaged
333
+
//
329
334
// - - - - - - - - - - - - - - - - - - - - - - - - -
330
335
// initialize CASAviewer app data...
331
336
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
332
337
// generate path to data...
338
+
bool packed_app = ends_with(exepath, "/AppRun");
333
339
std::string datapath(exepath);
334
-
datapath.erase( datapath.end( ) - 6, datapath.end( ) );
340
+
// packed_app -> .../AppRun
341
+
// not packed_app -> .../CASAviewer.app/usr/bin/CASAviewer
342
+
datapath.erase( datapath.end( ) - (packed_app ? 6 : 18), datapath.end( ) );
335
343
std::string pgplotpath = datapath; // save for later...
336
344
std::string pluginpath = datapath; // save for later...
337
345
datapath += "data";
338
346
// initialize casacore...
339
347
std::list<std::string> datadirs;
340
348
datadirs.push_back(datapath);
341
349
casacore::AppStateSource::initialize(new ViewerDataState(datadirs));
342
350
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
343
351
// initialize CASAviewer app data...
344
352
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
361
369
FILE *file = fopen(logfile_path,"a");
362
370
if ( file ) {
363
371
fclose(file);
364
372
casacore::LogSinkInterface *sink = new casacore::StreamLogSink(new ofstream(logfile_path,std::ios_base::app));
365
373
casacore::LogSink::globalSink(sink);
366
374
}
367
375
}
368
376
369
377
if ( (server_startup || without_gui) && initial_run ) {
370
378
if ( daemon ) {
371
-
launch_server( argv[0], numargs, args, dbus_name, without_gui,
379
+
launch_server( argv[0], numargs, args, server_string, without_gui,
372
380
persistent, casapy_start );
373
381
} else {
374
-
start_manager_root( argv[0], numargs, args, dbus_name, without_gui, getpid( ) );
382
+
start_manager_root( argv[0], numargs, args, server_string, without_gui, getpid( ) );
375
383
}
376
384
exit(0);
377
385
}
378
386
379
387
INITIALIZE_PGPLOT
380
388
try {
381
389
382
390
ViewerApp qapp(numargs, args, true);
383
391
384
392
// if it's a server, stick around even if all windows are closed...
416
424
filename = "";
417
425
}
418
426
}
419
427
420
428
// Pass along the remaining arguments to QtViewer...
421
429
// instead of littering the ctor arguments...
422
430
std::list<std::string> stdargs;
423
431
for ( int arg_index=0; args[arg_index]; ++arg_index )
424
432
stdargs.push_back(args[arg_index]);
425
433
426
-
QtViewer* v = new QtViewer( stdargs, server_startup || with_dbus, dbus_name );
434
+
QtViewer* v = new QtViewer( stdargs, server_startup || with_dbus, server_string );
427
435
qapp.subscribe(v);
428
436
429
437
if ( ! server_startup ) {
430
438
431
439
// define the panel
432
440
QtDisplayPanelGui* dpg;
433
441
434
442
dpg = v->createDPG( );
435
443
436
444
QtDisplayData* qdd = 0;
545
553
cerr<<"**"<<err.getMesg()<<endl;
546
554
} catch (...) {
547
555
cerr<<"**non-AipsError exception**"<<endl;
548
556
}
549
557
550
558
}
551
559
552
560
// processes argv into args stripping out the the viewer setup flags... numargs has the number
553
561
// of args, and the last arg (not included in numargs count) is null (for execvp)
554
562
static void preprocess_args( int argc, const char *argv[], int &numargs, char **&args,
555
-
char *&dbus_name, bool &with_dbus, bool &initial_run,
563
+
char *&server_string, bool &with_dbus, bool &initial_run,
556
564
bool &server_startup, bool &daemon, bool &without_gui, bool &persistent,
557
565
bool &casapy_start, char *&logfile_path ) {
558
566
559
567
without_gui = false;
560
568
persistent = false;
561
569
casapy_start = false;
562
-
dbus_name = 0;
570
+
server_string = 0;
563
571
564
572
initial_run = (isdigit(argv[0][0]) ? false : true);
565
573
566
574
for ( int x = 0; x < argc; ++x ) {
567
575
if ( ! strncmp(argv[x],"--nogui",7) ) {
568
576
without_gui = true;
569
577
if ( argv[x][7] == '=' ) {
570
578
char *name = strdup( &argv[x][8] );
571
579
if ( strlen(name) <= 0 ) {
572
580
free( name );
581
+
#if defined(WITHOUT_DBUS)
582
+
qWarning("no gRPC registry provided with '--server=...'");
583
+
qFatal("exiting...");
584
+
exit(1);
585
+
#endif
573
586
} else {
574
-
dbus_name = name;
587
+
server_string = name;
575
588
}
576
589
}
577
590
} else if ( ! strncmp(argv[x],"--server",8) ) {
578
591
server_startup = true;
579
592
if ( argv[x][8] == '=' ) {
580
593
char *name = strdup( &argv[x][9] );
581
594
if ( strlen(name) <= 0 ) {
582
595
free( name );
596
+
#if defined(WITHOUT_DBUS)
597
+
qWarning("no gRPC registry provided with '--server=...'");
598
+
qFatal("exiting...");
599
+
exit(1);
600
+
#endif
583
601
} else {
584
-
dbus_name = name;
602
+
server_string = name;
585
603
}
586
604
}
587
-
} else if ( ! strncmp(argv[x],"--dbusname",10) ) {
605
+
#if ! defined(WITHOUT_DBUS)
606
+
} else if ( ! strncmp(argv[x],"--dbusname",10) ) {
588
607
if ( argv[x][10] == '=' ) {
589
608
char *name = strdup( &argv[x][11] );
590
609
if ( strlen(name) <= 0 ) {
591
610
free( name );
592
611
} else {
593
-
dbus_name = name;
612
+
server_string = name;
594
613
}
595
614
} else if ( x + 1 < argc ) {
596
-
dbus_name = strdup(argv[++x]);
615
+
server_string = strdup(argv[++x]);
597
616
}
598
617
} else if ( ! strcmp(argv[x],"--daemon") ) {
599
618
daemon = true;
600
619
} else if ( ! strcmp(argv[x],"--persist") ) {
601
620
persistent = true;
602
621
} else if ( ! strcmp(argv[x],"--casapy") ) {
603
622
casapy_start = true;
604
623
} else if ( ! strcmp(argv[x],"--dbus") ) {
605
624
with_dbus = true;
625
+
#endif
606
626
} else if ( ! strncmp(argv[x],"--rcdir",7) ) {
607
627
if ( argv[x][7] == '=' ) {
608
628
viewer::setrcDir(&argv[x][8]);
609
629
} else if ( x + 1 < argc ) {
610
630
viewer::setrcDir(argv[++x]);
611
631
}
612
632
} else if ( ! strncmp(argv[x],"--casalogfile",13) ) {
613
633
if ( argv[x][13] == '=' ) {
614
634
char *file = strdup( &argv[x][14] );
615
635
if ( strlen(file) <= 0 ) {
640
660
args[numargs++] = strdup(name);
641
661
free(orig_name);
642
662
} else {
643
663
args[numargs++] = orig_name;
644
664
}
645
665
646
666
647
667
if ( initial_run && (without_gui || server_startup) ) {
648
668
// --nogui imples --server and for consistency, --server also forks child
649
669
char *arg;
650
-
if ( dbus_name ) {
651
-
arg = (char*) malloc( sizeof(char)*(strlen(dbus_name)+15) );
652
-
sprintf( arg, "--server=%s", dbus_name );
653
-
} else
670
+
if ( server_string ) {
671
+
arg = (char*) malloc( sizeof(char)*(strlen(server_string)+15) );
672
+
sprintf( arg, "--server=%s", server_string );
673
+
} else {
674
+
#if defined(WITHOUT_DBUS)
675
+
qWarning("no gRPC registry provided with '--server=...'");
676
+
qFatal("exiting...");
677
+
exit(1);
678
+
#else
654
679
arg = strdup( "--server" );
655
-
680
+
#endif
681
+
}
656
682
args[numargs++] = arg;
657
683
}
658
684
659
685
for ( int x = 1; x < argc; ++x ) {
660
686
if ( ! strcmp(argv[x], "--dbusname") ) {
661
687
++x;
662
688
} else if ( strncmp( argv[x], "--server", 8 ) &&
663
689
strncmp( argv[x], "--nogui", 7 ) &&
664
690
strcmp( argv[x], "--persist" ) &&
665
691
strcmp( argv[x], "--casapy" ) &&