3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_SC_PROCESS_HPP_INCLUDED
22 #define SCIDE_SC_PROCESS_HPP_INCLUDED
24 #include "sc_introspection.hpp"
25 #include "settings/manager.hpp"
33 #include <QtNetwork/QLocalSocket>
34 #include <QtNetwork/QLocalServer>
39 class ScIntrospectionParser
;
47 SCProcess( Main
*, class ScResponder
* responder
, Settings::Manager
* );
49 enum SCProcessActionRole
{
51 RecompileClassLibrary
,
60 const ScLanguage::Introspection
& introspection() { return mIntrospection
; }
62 void sendRequest( const QString
&id
, const QString
&command
, const QString
&data
)
64 QString cmd
= QString("ScIDE.request(\"%1\",'%2',\"%3\")")
69 evaluateCode(cmd
, true);
72 void setActiveDocument(class Document
*);
73 void sendActiveDocument();
75 QAction
*action(SCProcessActionRole role
)
77 return mActions
[role
];
80 void emitClassLibraryRecompiled()
82 emit
classLibraryRecompiled();
86 void scPost(QString
const &);
87 void statusMessage(const QString
&);
88 void response(const QString
& id
, const QString
& data
);
89 void classLibraryRecompiled();
92 void recompileClassLibrary (void);
93 void runMain(void) { evaluateCode("thisProcess.run", false); }
94 void stopMain(void) { evaluateCode("thisProcess.stop", false); }
95 void startLanguage (void);
96 void stopLanguage (void);
97 void restartLanguage (void);
98 void onReadyRead(void);
99 void evaluateCode(QString
const & commandString
, bool silent
= false);
101 void swapIntrospection (ScLanguage::Introspection
*newIntrospection
)
103 // LATER: use c++11/std::move
104 mIntrospection
= *newIntrospection
;
105 delete newIntrospection
;
109 void onNewIpcConnection();
111 void finalizeConnection();
114 void onSclangStart();
116 void prepareActions(Settings::Manager
* settings
);
118 QAction
* mActions
[SCProcessActionCount
];
120 ScLanguage::Introspection mIntrospection
;
121 ScIntrospectionParser
*mIntrospectionParser
;
123 QLocalServer
*mIpcServer
;
124 QLocalSocket
*mIpcSocket
;
125 QString mIpcServerName
;
128 QString mCurrentDocumentPath
;
131 class ScRequest
: public QObject
135 ScRequest( SCProcess
*sc
, QObject
* parent
= 0 ):
139 connect(mSc
, SIGNAL(response(QString
,QString
)),
140 this, SLOT(onResponse(QString
,QString
)));
142 connect(mSc
, SIGNAL(classLibraryRecompiled()),
143 this, SLOT(onCancelRequest()));
146 void send( const QString
& command
, const QString
& data
)
148 mId
= QUuid::createUuid();
150 mSc
->sendRequest(mId
.toString(), command
, data
);
159 void response( const QString
& command
, const QString
& data
);
160 void requestCanceled();
163 void onCancelRequest()
166 emit
requestCanceled();
170 void onResponse( const QString
& responseId
, const QString
& responseData
)
172 if (responseId
== mId
.toString())
173 emit
response(mCommand
, responseData
);
182 class ScResponder
: public QObject
187 ScResponder( QObject
* parent
= 0):
192 void serverRunningChanged( bool serverRunning
, const QString
& hostName
, int port
);
193 void newIntrospectionData( const QString
& yaml
);
196 void onResponse( const QString
& selector
, const QString
& data
);
199 void handleOpenFile( const QString
& data
) const;
200 void handleServerRunningChanged( const QString
& data
);
203 class ScIntrospectionParserWorker
: public QObject
207 void done( ScLanguage::Introspection
* output
);
209 void process( const QString
& input
)
212 ScLanguage::Introspection
*introspection
= new ScLanguage::Introspection (input
);
213 emit
done(introspection
);
214 } catch (std::exception
& e
) {
215 // LATER: show message in status bar
216 qDebug() << e
.what();
225 class ScIntrospectionParser
: public QThread
229 ScIntrospectionParser( ScResponder
* responder
, QObject
* parent
= 0 ):
232 connect(responder
, SIGNAL(newIntrospectionData(QString
)),
233 &mWorker
, SLOT(process(QString
)), Qt::QueuedConnection
);
234 connect(&mWorker
, SIGNAL(done(ScLanguage::Introspection
*)),
235 this, SIGNAL(done(ScLanguage::Introspection
*)), Qt::QueuedConnection
);
236 mWorker
.moveToThread(this);
238 ~ScIntrospectionParser()
240 QMetaObject::invokeMethod(&mWorker
, "quit");
245 void done( ScLanguage::Introspection
* );
248 ScIntrospectionParserWorker mWorker
;