Пример #1
0
void NodeInstanceManager::Save(QSettings& settings)
{
	int regIdx = 0;
	for (int i = 0; i < mInstances.count(); ++i)
	{
		NodeInstance* nodeInstance = mInstances[i];

		// Check that the instance is valid
		if ( !nodeInstance->IsValid() )
			continue;

		NodeInstanceSettings instanceSettings;
		instanceSettings.scriptPath = nodeInstance->GetScriptPath();
		instanceSettings.port = nodeInstance->GetPort();
		instanceSettings.vars = nodeInstance->GetVars();
		instanceSettings.debug = nodeInstance->IsDebugEnabled();

		QString instanceKey = QString("instance%1").arg(regIdx);
		QVariant varInstanceSettings = QVariant::fromValue(instanceSettings);
		settings.setValue( instanceKey, varInstanceSettings );

		regIdx++;
	}

	// Clear the next instance registry setting to make sure not to load invalid data.
	QString instanceKeyToRemove = QString("instance%1").arg(regIdx);
	settings.remove( instanceKeyToRemove );

}
Пример #2
0
void NodeInstanceManager::HostAlreadyRunningNodes()
{
	QList<ProcessInfo> nodeProcesses = GetProcessInfoList("SELECT * FROM Win32_Process WHERE Name = 'node.exe'");
	
	ProcessInfo pi;
	foreach( pi, nodeProcesses )
	{
		// Get script name
		// We suppose the script is the last argument
		QString scriptName = pi.args.last();

		// Check if we have everything needed
		if ( scriptName.isEmpty() || pi.workingDir.isEmpty() )
			continue;

		QFileInfo scriptPath( QDir(pi.workingDir), scriptName );

		if ( !scriptPath.exists() )
			continue;
		
		// Check if the process matches any available slots
		bool hasSlot = false;
		for (int i = 0; i < mInstances.count(); ++i)
		{
			NodeInstance* nodeInstance = mInstances[i];
			if ( QFileInfo(nodeInstance->GetScriptPath()).canonicalFilePath() == scriptPath.canonicalFilePath() )
			{
				// TODO: Reuse slot
				hasSlot = true;
				nodeInstance->EnableExternalProcess( pi.pid );
				break;
			}
		}

		if ( !hasSlot )
		{
			// Create new slot
			NodeInstance* newInstance = CreateInstance();
			newInstance->SetScriptPath( scriptPath.absoluteFilePath() );
			newInstance->EnableExternalProcess( pi.pid );

			// get port
			newInstance->SetPort( pi.env["PORT"].toInt() );
		}
	}