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
This commit is contained in:
Joe Taylor 2013-07-19 00:23:40 +00:00
parent 0110ab88dd
commit fb7948a836
7 changed files with 48 additions and 12 deletions

View File

@ -2,6 +2,7 @@
#include <qsharedmemory.h>
#include <QSystemSemaphore>
// Multiple instances: KK1D, 17 Jul 2013
QSharedMemory mem_jt9("mem_jt9");
QSystemSemaphore sem_jt9("sem_jt9", 1, QSystemSemaphore::Open);

View File

@ -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 <key>'
print*,' Gets data from shared memory region with key==<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

View File

@ -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 <thekey>' from within WSJT-X."
go to 999
endif
p_jt9=>address_jt9()

View File

@ -7,7 +7,10 @@
#include <portaudio.h>
#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();
}

View File

@ -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 <thekey>"
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; \

View File

@ -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;

View File

@ -2214,7 +2214,7 @@ p, li { white-space: pre-wrap; }
</property>
<widget class="QMenu" name="menuAdvanced">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="title">
<string>Advanced</string>