void launch(){
		RuntimeErrorValidator * validator = NULL;

		if(isInfoEnabled())
			info("Quedando a la espera de peticiones para realizar operaciones FSS");

		MpsMessage * request = NULL;

		while(isFssRunningStatus()){
			validator = buildErrorSuccessValidator();
			request = receiveMpsMessage(getFileSystemSocket(), validator);

			if(request == NULL || hasError(validator)){
				error("Se produjo un error en la recepcion, finalizando la aplicacion");
				close(getFileSystemSocket());
				exit(1);
			}

			if(isDebugEnabled())
				debug("Reciviendo peticion MPS");

			if(isDebugEnabled())
				debug(concatAll(3 , "Header.DescriptorId: '" , strndup(request->descriptorId , 16) , "'"));

			if(isDebugEnabled())
				debug( concatAll(3 , "Payload.Arguments: '" , formatListToPreetyString(request->commands) , "'"));

			if(isDebugEnabled())
				debug(concatAll(3 , "Payload.OperationName: '" , request->operationName , "'"));

			executeOperation(getFileSystemSocket() , request , validator);
		}

	}
	Bool removeDirectory(char * dirname){
		//return !rmdir(dirname);

		char * cmd = concatAll(2 , "rm -r " , dirname);
		if(isDebugEnabled())
			logDebug("linux-commons" , concatAll(3 , "Ejecutando comando nativo del sistema: '" , cmd , "'"));
		return !system(cmd);
	}
	int main(void) {

		configure();

		//testFormat();
		//testCreate();
		//testCreatingBitVector();
		//testUpdateSize();
		//testGettingFileInformation();
		//testAddingSectors();
		//testListingFiles();
		//testFreeingSectors();
		//testGetCurrentSize();

		//testListImplementation();
		//testListImplementation2();

		if(isInfoEnabled())
			info("Conectando con modulo KSS");

		ListenSocket s = openClientConnection(getKssHost() , getKssPort());

		if(s == INVALID_SOCKET){
			error("no se puede abrir la coneccion");
			return EXIT_FAILURE;
		}

		if(isInfoEnabled())
			info("Quedando a la espera de peticiones para realizar operaciones FSS");

		RuntimeErrorValidator * validator ;
		MpsRequest * request = NULL;

		while(isFssRunningStatus()){
			validator = buildErrorSuccessValidator();
			request = receiveMpsRequest(s , validator);
			validator = buildErrorSuccessValidator();
			info("Reciviendo peticion MPS");

			if(isInfoEnabled())
				info(concatAll(3 , "Header.DescriptorId: '" , strndup(request->descriptorId , 16) , "'"));

			if(isInfoEnabled())
				info( concatAll(3 , "Payload.Arguments: '" , formatListToPreetyString(request->arguments) , "'"));

			if(isInfoEnabled())
				info(concatAll(3 , "Payload.OperationName: '" , request->operationName , "'"));

			executeOperation(s , request , validator);
		}

		return EXIT_SUCCESS;
	}
	void testFilesTransferMps2(){


		RuntimeErrorValidator * validator = buildErrorSuccessValidator();

		MpsMessage * request = receiveMpsMessage(getFileSystemConnection() , validator);

		Iterator * ite = buildIterator(request->commands);
		char * path = hasMoreElements(ite) ? next(ite) : NULL;

		if(path == NULL){
			setError(validator , "El puto archivo vino en null");
			return ;
		}

		info(concatAll(3 , "DescriptorId = '" , strndup(request->descriptorId , 16) , "'"));
		info(concatAll(2, "Archivo solicitado: " , path));


		File * file1 = fopen(path , "r");

		char buffer1[512];
		char buffer2[512];

		while(! feof(file1) ){

			bzero(buffer1 , 512);
			bzero(buffer2 , 512);

			int readedS1 = fread(buffer1, sizeof(char) , 512 , file1);
			int readedS2 = fread(buffer2, sizeof(char) , 512 , file1);

			info(concatAll(5 , "Enviando contenido: { Sector1 = " , itoa(readedS1) , " , Sector2 = " , itoa(readedS2) , "}"));

			FileBlock * block = buildEmptyFileBlock();
			setFileBlockContents(block , buffer1 , buffer2 , readedS1 , readedS2);

			MpsMessage * response = buildMpsMessage(request->descriptorId,
					MPS_RESPONSE_STATUS_CODE_SUCCESS , request->operationName , NULL);
			response->block = block;

			sendMpsBlockMessage(getFileSystemConnection() , response , validator);

		}

		MpsMessage * response = buildMpsMessage(request->descriptorId,
			MPS_RESPONSE_STATUS_CODE_SUCCESS , request->operationName , NULL);

		sendMpsMessage(response , getFileSystemConnection() , validator);

		fclose(file1);
	}
	void setupDirectoryIndexes(){
		if(existsFile(getDataDirectory())){
			if(isInfoEnabled()) info(concatAll( 3, "Usando " , getDataDirectory() , " como directorio de indices"));
		}else{
			if(isInfoEnabled()) info(concatAll(2 , "No existe el directorio " , getDataDirectory()));

			if(createDirectory(getDataDirectory())){
				if(isInfoEnabled()) info(concatAll(2 , "Se crea " , getDataDirectory()));
			}else{
				if(isInfoEnabled()) info(concatAll(2 , "No se pudo crear el directorio " , getDataDirectory()));
				killAndWait(1);
				return;
			}
		}
	}
示例#6
0
std::vector<typename Partial::SolutionT> generatePar(int depth, Partial const & part, Constraint constr)
{
    using SolutionVec = std::vector<typename Partial::SolutionT>;

    if (depth == 0)
    {
        return generate(part, constr);
    }
    else if (part.isFinished(constr))
    {
        SolutionVec result{ part.getSolution() };
        return result;
    }
    else
    {
        Stream<Partial> partList = part.refine(constr);

        std::vector<std::future<SolutionVec>> futResult;
        forEach(std::move(partList), [&constr, &futResult, depth](Partial const & part)
        {
            std::future<SolutionVec> futLst =
                std::async([constr, part, depth]() {
                return generatePar(depth - 1, part, constr);
            });
            futResult.push_back(std::move(futLst));
        });
        std::vector<SolutionVec> all = when_all_vec(futResult);
        return concatAll(all);
    }
}
	void configure(RuntimeErrorValidator * v){
		setupConfiguration(v);
		closingEvents();
		if(hasError(v)){
			return;
		}

		//setLoggingLevelEnabled(LOGGING_LEVEL_INFO);
		setFssRunningStatus(TRUE);
		setupDirectoryIndexes();

		if(isInfoEnabled())
			info("Conectando con modulo KSS");

		ListenSocket s = openClientConnection(getKssHost() , getKssPort());

		if(s == INVALID_SOCKET){
			setError(v , "no se puede abrir la coneccion");
			return;
		}

		MpsHandshake * handshake = buildMpsHandhake(generateRandomKey(16) , FSS_HANDSHAKE);
		handshake = sendAndReceiveMpsHandshake(handshake , s , v);

		if(handshake != NULL && handshake->statusCode == MPS_RESPONSE_STATUS_CODE_SUCCESS ){
			info(concatAll(2 , "Handshake realizado satisfactoriamente con DescriptorId: " , handshake->descriptorId));
			setFileSystemSocket(s);
		}else{
			setError(v , "Hubo un problema y no se pudo realizar el handshake");
			return;
		}
	}
示例#8
0
	void testGetCurrentSize(){
		RuntimeErrorValidator * v = buildErrorSuccessValidator();

		long s1 = getCurrentFileSize("VDA1" , "archivo1.txt" , v);
		info(concatAll(2 , "FileSize: " , ltoa(s1)));

		long s2 = getCurrentFileSize("VDA1" , "archivo2.txt" , v);
		info(concatAll(2 , "FileSize: " , ltoa(s2)));

		long s3 = getCurrentFileSize("VDA1" , "archivo3.txt" , v);
		info(concatAll(2 , "FileSize: " , ltoa(s3)));

		long s4 = getCurrentFileSize("VDA1" , "archivo4.txt" , v);
		info(concatAll(2 , "FileSize: " , ltoa(s4)));

	}
	char * coreOperationListFiles(char * pattern , RuntimeErrorValidator * validator){
		if(isDebugEnabled())
			debug(concatAll(2 , "Listando Ruta: " , pattern));

		List elements = getPathContentElements(pattern  , validator);
		return serializeList(elements , ",");
	}
	void executeKssCommandList(char * arg , ListenSocket ls){
		RuntimeErrorValidator * validator = buildErrorSuccessValidator();
		//List params = getFirstParameter("Dispositivo o directorio a Listar");
		List params = buildStringsListWithValues(1 , arg);

		MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_LS , params);
		MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator);

		if(isDebugEnabled())
			debug(concatAll(2, "Codigo de resultado: " , resp->statusCode));

		Iterator * ite = buildIterator(resp->returnValues);

		if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){

			char * serializedFiles = next(ite);
			List files = deserializeList(serializedFiles);
			ite = buildIterator(files);

			printf("Contenido del directorio:\n");
			printf("--------------------------------------------------------------------------------------\n");

			while(hasMoreElements(ite)){
				char * elem = next(ite);
				printf("%s\n " , trim(elem));
			}
		}else{
			printf("%s" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error"));
		}
	}
示例#11
0
void test_concatall_first_null(void){
	char* first = NULL;
	char* second = "bar";
	char* third = "42";
	char* result = concatAll(3,first, second, third);
	CU_ASSERT_STRING_EQUAL(result, "bar42");
	free(result);
}
示例#12
0
void test_concatall_three_values(void){
	char* first = "foo";
	char* second = "bar";
	char* third = "42";
	char* result = concatAll(3,first, second, third);
	CU_ASSERT_STRING_EQUAL(result, "foobar42");
	free(result);
}
示例#13
0
void testAssignAndGetSectors() {
    RuntimeErrorValidator * v = buildErrorSuccessValidator();
    List freeSectors = callFssOperationAssignAndGetSectors("VDA1" , "archivo1 con espacios.txt", v);

    if(!hasError(v)) {
        info(concatAll(3,"Se han traido los sectores correctamente: (" , serializeList(freeSectors , " , ") , ")"));
    } else {
        error(v->errorDescription);
    }
}
	/*
	 * Devuelve una lista de nombres de archivos con sus tamaños
	 * Ambos datos estan separados por una coma y en formato de un
	 * string.
	 */
	List getVdaFiles(char * vda , RuntimeErrorValidator * validator){
		List fileNames = buildSringsList();
		List fileInformations = callFssOperationGetDirectoryInformation(vda , validator);
		Iterator * fileInfosIterator = buildIterator(fileInformations);

		while(hasMoreElements(fileInfosIterator)){
			FileInformation * infor = next(fileInfosIterator);
			char * element =  concatAll(3, ltoa(infor->size) ,",", infor->name);
			addNode(fileNames , element );
		}
		return (fileNames->size > 0) ? fileNames : NULL;
	}
示例#15
0
	void testListImplementation(){


		Bool equling(char * f1 , char * f2){
			return !strcmp(f1 , f2);
		}

		Bool sorting(char * f1 , char * f2){
			return ( strcmp(f1 , f2) < 0 );
		}

		void listing(char * e){
			if(e != NULL) logInfo( "linux-commons" , e);
		}

		List list = createList(listing , equling , sorting);

		addNode(list , "hola1");
		addNode(list , "hola2");
		addNode(list , "hola3");
		addNode(list , "hola4");
		addNode(list , "hola5");
		addNode(list , "hola6");

		logInfo("linux-commons" , concatAll(2 , "list size: " , itoa(list->size)));

		//una forma chota de listar los elementos de la lista
		listNodes(list);

		//otra forma de listar elementos mas prolija y con mas
		//control sobre el proceso de listado

		Iterator * iterator = buildIterator(list);

		while(hasMoreElements(iterator)){
			char * element = next(iterator);
			logInfo("linux-commons" , concatAll(2 , "element: " , element));
		}
	}
	char * serializeList(List list , char * separator){
		Iterator * ite = buildIterator(list);
		char * serialization = NULL;
		while(hasMoreElements(ite)){
			char * element = next(ite);
			if(serialization == NULL){
				serialization = strdup(element);
			}else{
				serialization = concatAll(3 , serialization , separator , strdup(element));
			}
		}
		return serialization;
	}
示例#17
0
Stream<int> testCat()
{
    List<int> lst1 = { 1, 3, 5, 7 };
    Stream<int> s1 = mkStream<int>(lst1);
    List<int> lst2 = {10, 20, 30 };
    Stream<int> s2 = mkStream<int>(lst2);
    List<int> lst3 = { 100, 200, 300 };
    Stream<int> s3 = mkStream<int>(lst3);
    List<Stream<int>> lss;
    lss = lss.push_front(s3);
    lss = lss.push_front(s2);
    lss = lss.push_front(s1);
    return concatAll(lss);
}
示例#18
0
	void testListImplementation2(){


		Bool equling(int * f1 , int * f2){
			return *f1 == *f2;
		}

		Bool sorting(int * f1 , int * f2){
			return *f1<*f2;
		}

		void listing(int * e){
			if(e != NULL) logInfo( "linux-commons" , itoa(*e));
		}

		List list = createList(listing , equling , sorting);

		addNode(list , newInteger(1));
		addNode(list , newInteger(2));
		addNode(list , newInteger(3));
		addNode(list , newInteger(4));
		addNode(list , newInteger(5));
		addNode(list , newInteger(6));

		logInfo("linux-commons" , concatAll(2 , "list size: " , itoa(list->size)));

		listNodes(list);

		//otra forma de listar elementos

		Iterator * iterator = buildIterator(list);

		while(hasMoreElements(iterator)){
			int * element = next(iterator);
			logInfo("linux-commons" , concatAll(2 , "element: " , itoa(*element)));
		}
	}
示例#19
0
Stream<T> concatAll(List<Stream<T>> const & in)
{
    if (in.isEmpty())
        return Stream<T>();
    Stream<T> strm = in.front();
    List<Stream<T>> tailStrm = in.pop_front();
    if (strm.isEmpty())
        return concatAll(tailStrm);
    return Stream<T>([=]()
    {
        T val = strm.get();
        auto tail = strm.pop_front();
        return Cell<T>(val, concatAll<T>(tailStrm.push_front(tail)));
    });
}
示例#20
0
	void testListingFiles(){
		RuntimeErrorValidator * validator = buildErrorSuccessValidator();
		List l = getAllFiles("VDA1", validator);
		if(hasError(validator)){
			error(validator->errorDescription);
			return ;
		}

		Iterator * ite = buildIterator(l);

		char * element = NULL;
		while( hasMoreElements(ite)){
			element = next(ite);
			info( concatAll(4, "Archivo: " , element , " con tamaño: " , ltoa(getCurrentFileSize("VDA1" , element , validator))));
		}

	}
	void executeKssCommandTddDump(ListenSocket ls){
		RuntimeErrorValidator * validator = buildErrorSuccessValidator();

		MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_TDD_DUMP , NULL);
		MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator);

		Iterator * ite = buildIterator(resp->returnValues);

		if(isDebugEnabled())
			debug(concatAll(2, "Codigo de resultado: " , resp->statusCode));

		if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){
			info("Resultado satisfactorio ");
		}else{
			printf("%s\n" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error"));
		}
	}
	void executeKssCommandFormat(char * arg , ListenSocket ls){

		RuntimeErrorValidator * validator = buildErrorSuccessValidator();
		//List params = getFirstParameter("Dispositivo a Formatear");
		List params = buildStringsListWithValues(1 , arg);

		MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_FORMAT , params);
		MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator);

		if(isDebugEnabled())
			debug(concatAll(2, "Codigo de resultado: " , resp->statusCode));

		Iterator * ite = buildIterator(resp->returnValues);

		if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){
			printf("Dispositivo formateado\n");
		}else{
			printf("%s" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error"));
		}
	}
示例#23
0
void testListInexistingDirectory() {

    RuntimeErrorValidator * v = buildErrorSuccessValidator();
    List files = callFssOperationGetDirectoryInformation("VDA2", v);

    if(!hasError(v)) {

        Iterator * ite = buildIterator(files);

        info("Se han recuperado con exito los archivos del directorio");
        while(hasMoreElements(ite)) {
            FileInformation * infof = next(ite);
            info(concatAll(2, "FileName: " , infof->name , " , FileSize: " , ltoa(infof->size)));
        }

    } else {
        error(v->errorDescription);
    }


}
	void flush(TddRecord * record , RuntimeErrorValidator * validator){


		if(!hasTwoSectors(record->fileBlock)){
			error(concatAll(4, "Ojo! Se estan asignando dos sectores para un bloque que solo necesita uno: /"
					, record->vdaName , "/" , record->fileName));
		}

		if(record->openingMode != OPENING_MODE_WRITE){
			setError(validator , "El archivo no fue abierto para escritura");
			return;
		}

		List sectors = callFssOperationAssignAndGetSectors(record->vdaName , record->fileName , validator);

		if(hasError(validator)){
			return;
		}

		Iterator * ite = buildIterator(sectors);

		int sector1 = atoi( hasMoreElements(ite) ? next(ite) : "-1" );
		int sector2 = atoi( hasMoreElements(ite) ? next(ite) : "-1" );

		if(sector1 < 0 || sector2 < 0 || sector1 == sector2 ){
			setError(validator , "Los numeros de sectores deben ser mayores o iguales a cero y deben ser distintos");
			return;
		}

		setFileBlockSectors( record->fileBlock , sector1 , sector2);

		VdaComponent * comp = getMountedVda(record->vdaName);

		if(comp == NULL){
			setError(validator , "El vda necesario para realizar el flush no se encuentra montado");
			return;
		}

		callVdaOperationPutSectores(comp , record->fileBlock , validator);
	}
	void insertEntry(char * key , char * value , File * file){
		const char * content = concatAll(3 , key , "=" , value);
		insertLine(content, file);
	}
	void insertLine(const char * line , File * file){
		int inserted = fwrite(line , sizeof(char) , strlen(line) , file);
		if(isDebugEnabled()) logDebug("linux-commons" , concatAll(3 , "Se han insertado " , itoa(inserted) , " bytes en el archivo"));
		fputc('\n' , file);
	}