int ProgramManager::StopProgram( int programId )
{
	Process* process = this->runningPrograms[programId];
	if ( process == NULL )
	{
		EventLogger::Instance()->WriteVerbose( "Program with id %d is not started!", programId );
		return ERROR_PRNOTSTARTED_ID;
	}

	Program* program = process->GetProgram();
	if ( program == NULL )
	{
		EventLogger::Instance()->WriteVerbose( "Program with id %d is not started!", programId );
		return ERROR_PRNOTSTARTED_ID;
	}

	process->Stop();

	// to do !!!
	MappingManager::Instance()->FinalizeProgram( program );

	// delete process & program;
	// delete this->runningPrograms[program->Id()];
	this->runningPrograms[program->Id()] = NULL;
	this->runningPrograms.erase( program->Id() );

	return 0;
}
Пример #2
0
bool Programs::Remove(const Program& program)
{
	Programs::iterator it = std::find(m_programs.begin(), m_programs.end(), program.Id());
	if (it != m_programs.end())
	{
		m_programs.erase(it);
		return true;
	}
	return false;
}
void ProgramManager::LoadProgram( string programName, string mappingName )
{
	string storageFolderPath = Configuration::Instance()->GetStringParam(
			PROGRAMS_STORAGE_DIR );
	string programSavePath = storageFolderPath + "/" + programName;
	string mappingSavePath = storageFolderPath + "/" + mappingName;

	string programDefinition = DataSerializationManager::Load( programSavePath.c_str() );
	string mappingDefinition = DataSerializationManager::Load( mappingSavePath.c_str() );

	Program* program = UpcbJsonParser::Instance()->ParseProgram( programDefinition );
	if( program == NULL )
		return;

	this->availablePrograms[program->Id()] = programDefinition;
	this->programMappings[program->Id()] = mappingDefinition;

	//delete program;
}
void ProgramManager::HandleError( void* sender, ErrorItem* error)
{
	Process* process = ( Process* )sender;
	if( process == NULL )
		return;

	Program* program = process->GetProgram();
	if ( program == NULL )
	{
		EventLogger::Instance()->WriteVerbose( "Program with id %d is still not started but an Error in the process with the same id is found!", program->Id() );
		return;
	}

	process->Stop();

	// to do !!!
	MappingManager::Instance()->FinalizeProgram( program );
	// delete process & program;
	// delete this->runningPrograms[program->Id()];
	this->runningPrograms[program->Id()] = NULL;
	this->runningPrograms.erase( program->Id() );
}
void ProgramManager::AddProgram( string json )
{
	Program* program = UpcbJsonParser::Instance()->ParseProgram( json );

	if( program == NULL )
		return;

	this->availablePrograms[program->Id()] = json;

	//delete program;

	//Save Program & Mapping:
	string storageFolderPath = Configuration::Instance()->GetStringParam( PROGRAMS_STORAGE_DIR );

	struct stat st;
	if ( stat( storageFolderPath.c_str(), &st ) != 0 )
		mkdir( storageFolderPath.c_str(), 0777 );

	string programSavePath = storageFolderPath + "/" + program->Name() + ".xml";
	DataSerializationManager::Save( json, programSavePath.c_str() );
}