From fb7948a836b5f01534f657d2e8a0311f9e4cea64 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Fri, 19 Jul 2013 00:23:40 +0000 Subject: [PATCH] Full activation of "Multiple Instances", thanks to some code by Josh Rovero, KK1D. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3495 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- lib/ipcomm.cpp | 1 + lib/jt9.f90 | 9 ++++++--- lib/jt9a.f90 | 18 +++++++++++++++--- main.cpp | 13 +++++++++++-- mainwindow.cpp | 12 ++++++++++-- mainwindow.h | 5 ++++- mainwindow.ui | 2 +- 7 files changed, 48 insertions(+), 12 deletions(-) diff --git a/lib/ipcomm.cpp b/lib/ipcomm.cpp index 306e4a328..a6b05c3f9 100644 --- a/lib/ipcomm.cpp +++ b/lib/ipcomm.cpp @@ -2,6 +2,7 @@ #include #include +// Multiple instances: KK1D, 17 Jul 2013 QSharedMemory mem_jt9("mem_jt9"); QSystemSemaphore sem_jt9("sem_jt9", 1, QSystemSemaphore::Open); diff --git a/lib/jt9.f90 b/lib/jt9.f90 index a08645f56..1f0a619d6 100644 --- a/lib/jt9.f90 +++ b/lib/jt9.f90 @@ -17,13 +17,16 @@ program jt9 print*,'Usage: jt9 TRperiod ndepth rxfreq file1 [file2 ...]' print*,' Reads data from *.wav files.' print*,'' - print*,' jt9 -s' - print*,' Gets data from shared memory region.' + print*,' jt9 -s ' + print*,' Gets data from shared memory region with key==' go to 999 endif call getarg(1,arg) if(arg(1:2).eq.'-s') then - call jt9a +! Multiple instances: + call getarg(2,arg) + i0=len(trim(arg)) + call jt9a(trim(arg)) go to 999 endif read(arg,*) ntrperiod diff --git a/lib/jt9a.f90 b/lib/jt9a.f90 index 052073208..113533c7e 100644 --- a/lib/jt9a.f90 +++ b/lib/jt9a.f90 @@ -1,7 +1,8 @@ -subroutine jt9a +subroutine jt9a(thekey) + + character(len=*), intent(in):: thekey ! These routines connect the shared memory region to the decoder. - interface function address_jt9() integer*1, pointer :: address_jt9 @@ -13,15 +14,26 @@ subroutine jt9a integer size_jt9 integer*1, pointer :: p_jt9 character*80 cwd +! Multiple instances: + character*80 mykey logical fileExists common/tracer/limtrace,lu +! Multiple instances: + i0 = len(trim(thekey)) + call getcwd(cwd) open(12,file='timer.out',status='unknown') limtrace=0 ! limtrace=-1 !Disable all calls to timer() lu=12 + +! Multiple instances: set the shared memory key before attaching + mykey=trim(repeat(thekey,1)) + i0 = len(mykey) + i0=setkey_jt9(trim(mykey)) + i1=attach_jt9() 10 inquire(file=trim(cwd)//'/.lock',exist=fileExists) @@ -41,7 +53,7 @@ subroutine jt9a nbytes=size_jt9() if(nbytes.le.0) then print*,'jt9a: Shared memory mem_jt9 does not exist.' - print*,"Must start 'jt9 -s' from within WSJT-X." + print*,"Must start 'jt9 -s ' from within WSJT-X." go to 999 endif p_jt9=>address_jt9() diff --git a/main.cpp b/main.cpp index 08bf7eb8c..add1ab16c 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,10 @@ #include #include "mainwindow.h" -QSharedMemory mem_jt9("mem_jt9"); +// Multiple instances: +QSharedMemory mem_jt9; +QUuid my_uuid; +QString my_key; int main(int argc, char *argv[]) { @@ -26,6 +29,11 @@ int main(int argc, char *argv[]) } // Create and initialize shared memory segment + // Multiple instances: generate shared memory keys with UUID + my_uuid = QUuid::createUuid(); + my_key = my_uuid.toString(); + mem_jt9.setKey(my_key); + if(!mem_jt9.attach()) { if (!mem_jt9.create(sizeof(jt9com_))) { QMessageBox::critical( 0, "Error", "Unable to create shared memory segment."); @@ -45,7 +53,8 @@ int main(int argc, char *argv[]) exit(1); } - MainWindow w(&mem_jt9); +// Multiple instances: Call MainWindow() with the UUID key + MainWindow w(&mem_jt9, &my_key); w.show(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index cc3d44c8c..068b5bfc2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -40,7 +40,8 @@ QString Program_Title_Version=" WSJT-X v1.1, r" + rev.mid(6,4) + " by K1JT"; //-------------------------------------------------- MainWindow constructor -MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : +// Multiple instances: new arg *thekey +MainWindow::MainWindow(QSharedMemory *shdmem, QString *thekey, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -200,6 +201,8 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : ui->labDist->setStyleSheet("border: 0px;"); mem_jt9 = shdmem; +// Multiple instances: + mykey_jt9 = thekey; readSettings(); //Restore user's setup params if(m_dFreq.length()<=1) { //Use the startup default frequencies m_dFreq.clear(); @@ -225,7 +228,12 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : lockFile.open(QIODevice::ReadWrite); //QFile quitFile(m_appDir + "/.lock"); //quitFile.remove(); - proc_jt9.start(QDir::toNativeSeparators('"' + m_appDir + '"' + "/jt9 -s")); + +// Multiple instances: make the Qstring key into command line arg +// Multiple instances: start "jt9 -s " + QByteArray ba = mykey_jt9->toLocal8Bit(); + const char *bc = ba.data(); + proc_jt9.start(QDir::toNativeSeparators('"' + m_appDir + '"' + "/jt9 -s " + bc)); m_pbdecoding_style1="QPushButton{background-color: cyan; \ border-style: outset; border-width: 1px; border-radius: 5px; \ diff --git a/mainwindow.h b/mainwindow.h index 04ddcaf0d..51e0b41af 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,8 +27,9 @@ class MainWindow : public QMainWindow { Q_OBJECT +// Multiple instances: call MainWindow() with *thekey public: - explicit MainWindow(QSharedMemory *shdmem, QWidget *parent = 0); + explicit MainWindow(QSharedMemory *shdmem, QString *thekey, QWidget *parent = 0); ~MainWindow(); public slots: @@ -332,6 +333,8 @@ private: SoundInThread soundInThread; //Instantiate the audio threads SoundOutThread soundOutThread; QSharedMemory *mem_jt9; + // Multiple instances: + QString *mykey_jt9; PSK_Reporter *psk_Reporter; SignalMeter *signalMeter; diff --git a/mainwindow.ui b/mainwindow.ui index 8b6395af3..5c58f212c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -2214,7 +2214,7 @@ p, li { white-space: pre-wrap; } - false + true Advanced