Commit 0fb61d47 authored by luyikei's avatar luyikei

Implement vlmc server

parent c320661e
......@@ -659,10 +659,42 @@ MainWindow::checkVideoLength()
}
return true;
}
#include <QProcess>
#include <QApplication>
#include "Servers/VLMCLocalFrontend.h"
bool
MainWindow::renderVideoSettings( bool shareOnInternet )
{
QStringList arguments;
arguments << "--server"
<< QString::number( qApp->applicationPid() );
auto myProcess = new QProcess( this );
connect( myProcess, &QProcess::started, this, [this,myProcess]()
{
auto s = new VLMCLocalFrontend( myProcess->processId() );
s->setParent( this );
s->connectTo( QString( "vlmc%1" ).arg( myProcess->processId() ) );
s->getResponse<QString>( QStringLiteral( "test" ), []( QString str ) { vlmcCritical() << str; } );
});
connect( myProcess, &QProcess::readyReadStandardError, this, [this, myProcess]()
{
myProcess->setReadChannel( QProcess::ProcessChannel::StandardError );
char buf[1024];
if ( myProcess->readLine( buf, sizeof( buf ) ) != -1 );
printf( "From %lld: %s", myProcess->processId(), buf );
fflush(stdout);
});
connect( myProcess, &QProcess::readyReadStandardOutput, this, [this, myProcess]()
{
myProcess->setReadChannel( QProcess::ProcessChannel::StandardOutput );
char buf[1024];
if ( myProcess->readLine( buf, sizeof( buf ) ) != -1 );
printf( "From %lld: %s", myProcess->processId(), buf );
fflush(stdout);
});
myProcess->start( qApp->applicationFilePath(), arguments );
RendererSettings settings( shareOnInternet );
if ( settings.exec() == QDialog::Rejected )
......
......@@ -32,6 +32,7 @@
#include "Tools/VlmcDebug.h"
#include "Workflow/Types.h"
#include "Servers/VLMCLocalBackend.h"
#include "Renderer/ConsoleRenderer.h"
#include "Project/Project.h"
#include "Backend/IBackend.h"
......@@ -237,9 +238,44 @@ VLMCCoremain( int argc, char **argv )
return res;
}
int VLMCServerMain( int argc, char **argv )
{
#ifdef HAVE_GUI
QApplication app( argc, argv );
#else
QCoreApplication app( argc, argv );
#endif
Backend::IBackend* backend;
VLMCmainCommon( app, &backend );
QStringList&& args = app.arguments();
const QString* id = nullptr;
// We don't check the first argument, possibly "./vlmc"
args.pop_front();
for ( const auto& arg : args )
{
// Make sure it's not an option
if ( id == nullptr && arg.at( 0 ) != '-' )
id = &arg;
}
if ( id == nullptr )
{
VLMCLocalBackend server( qApp->applicationPid() );
return app.exec();
}
VLMCLocalBackend server( id->toLongLong() );
return app.exec();
}
int
VLMCmain( int argc, char **argv, bool gui )
VLMCmain( int argc, char **argv, bool gui, bool server )
{
if ( server == true )
return VLMCServerMain( argc, argv );
#ifdef HAVE_GUI
if ( gui == true )
return VLMCGuimain( argc, argv );
......
......@@ -37,7 +37,7 @@
#include <unistd.h>
int VLMCmain( int , char**, bool );
int VLMCmain( int , char**, bool, bool );
#if defined(WITH_CRASHHANDLER) && defined(Q_OS_UNIX)
......@@ -105,6 +105,7 @@ main( int argc, char **argv )
#else
bool gui = false;
#endif
bool server = false;
/* Check for command arguments */
for ( int i = 1; i < argc; i++ )
......@@ -125,6 +126,8 @@ main( int argc, char **argv )
else if ( arg == "--no-gui" )
gui = false;
#endif
else if ( arg == "--server" )
server = true;
}
#ifdef WITH_CRASHHANDLER
......@@ -165,5 +168,5 @@ main( int argc, char **argv )
}
#endif
return VLMCmain( argc, argv, gui );
return VLMCmain( argc, argv, gui, server );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment