Exemplo n.º 1
0
    void ConvertToBinaryAxi(std::string fullPath, std::string baseName, bool copyOutput)
    {
        FileFinder file_finder(fullPath+"/"+baseName+".axi", RelativeTo::ChasteSourceRoot);
        FibreReader<3> fibre_reader(file_finder, AXISYM);
        std::vector< c_vector<double, 3> > fibres;
        fibre_reader.GetAllAxi(fibres);

        std::string dir = "FibreConverter";
        FibreConverter axi_converter;
        axi_converter.Convert(file_finder, dir);

        //Read it back
        FileFinder file_finder_bin(dir+"/"+baseName+"_bin.axi", RelativeTo::ChasteTestOutput);
        FibreReader<3> fibre_reader_bin(file_finder_bin, AXISYM);
        std::vector< c_vector<double, 3> > fibres_bin;
        fibre_reader_bin.GetAllAxi(fibres_bin);

        TS_ASSERT_EQUALS(fibres.size(), fibres_bin.size());

        for (unsigned i = 0; i< fibres.size(); i++)
        {
            for (unsigned j = 0; j< 3u ; j++)
            {
                TS_ASSERT_DELTA(fibres[i][j], fibres_bin[i][j], 1e-16);
            }
        }
        if (copyOutput)
        {
            // This code is not called by default and only exists to copy test output into the trunk.
            FileFinder file_finder_test_folder(fullPath, RelativeTo::ChasteSourceRoot);
            file_finder_bin.CopyTo(file_finder_test_folder);
        }
    }
Exemplo n.º 2
0
EXPORT_C TInt CTestUtils::ResolveLogFile(const TDesC& aFileName, TParse& aParseOut)
	{
	TFileName* savedPath = new TFileName;
	TFileName* fileName = new TFileName;
	if ((savedPath == NULL) || (fileName == NULL))
		return KErrNoMemory;

	fileName->Append(KMsvPathSep);
	fileName->Append(KMsvTestFileOutputBase);
	fileName->Append(KMsvPathSep);
	
	// file finder will look in the session drive first, then Y->A,Z
	// so set session drive to Y (save old and restore it afterwards)
	iFs.SessionPath(*savedPath);
	_LIT(KTopDrive,"Y:\\");
	iFs.SetSessionPath(KTopDrive);
    TFindFile file_finder(iFs);
    TInt err = file_finder.FindByDir(*fileName,KNullDesC);

	if(err==KErrNone)
		{
		fileName->Copy(file_finder.File());
		AppendTestName(*fileName);
		fileName->Append(KMsvPathSep);
		fileName->Append(aFileName);
		iFs.MkDirAll(*fileName);
		aParseOut.Set(*fileName,NULL,NULL);
		}
	iFs.SetSessionPath(*savedPath);
	delete savedPath;
	delete fileName;
	return(err);
	}
Exemplo n.º 3
0
EXPORT_C TInt CTestConfig::ResolveFile(RFs& aFs, const TDesC& aComponent, const TDesC& aFileName, TParse& aParseOut)
	{
	TFileName* savedPath = new TFileName;
	TFileName* fileName = new TFileName;
	if ((savedPath == NULL) || (fileName == NULL))
		{
		delete savedPath;
		delete fileName;
		return KErrNoMemory;
		}

	fileName->Append(KScriptPathSep);
//	fileName->Append(KSmsTestFileInputBase);
//	fileName->Append(KScriptPathSep);
	fileName->Append(aComponent);
	fileName->Append(KScriptPathSep);
	fileName->Append(aFileName);
	
	// file finder will look in the session drive first, then Y->A,Z
	// so set session drive to Y (save old and restore it afterwards)
	aFs.SessionPath(*savedPath);
	_LIT(KTopDrive,"Y:\\");
	aFs.SetSessionPath(KTopDrive);
    TFindFile file_finder(aFs);
    TInt err = file_finder.FindByDir(*fileName,KNullDesC);
	if(err==KErrNone)
		aParseOut.Set(file_finder.File(),NULL,NULL);
	aFs.SetSessionPath(*savedPath);
	delete savedPath;
	delete fileName;
	return(err);
	}
Exemplo n.º 4
0
    // Copies a file (relative to Chaste home to CHASTE_TEST_OUTPUT/dir
    void CopyToTestOutputDirectory(std::string file, std::string dir)
    {
        OutputFileHandler handler(dir);
        FileFinder file_finder(file, RelativeTo::ChasteSourceRoot);

        FileFinder copied_file = handler.CopyFileTo(file_finder);
        TS_ASSERT(copied_file.IsFile());
    }
DynamicCellModelLoaderPtr HeartConfigRelatedCellFactory<SPACE_DIM>::LoadDynamicModel(
        const cp::ionic_model_selection_type& rModel,
        bool isCollective)
{
    assert(rModel.Dynamic().present());
    HeartFileFinder file_finder(rModel.Dynamic()->Path());
    CellMLToSharedLibraryConverter converter;
    return converter.Convert(file_finder, isCollective);
}
Exemplo n.º 6
0
int file_finder( char *searching, char *result, char *directory_to_search ) // returns 101 if file is found and the full file path is in "result"
{
	DIR *d;
	struct dirent *dir;
	char buff[MAXPATHLEN];	// MAXPATHLEN is typically 4096
	//printf("directory_to_search is : %s\n",directory_to_search);
	d = opendir( directory_to_search );
	if( d == NULL ) 
	{
		printf("Opening invalid directory\n");
		return 1;
	}
	while( ( dir = readdir( d ) ) ) 
	{
		if( strcmp( dir->d_name, "." ) == 0 || strcmp( dir->d_name, ".." ) == 0 ) 
		{
			continue;
		}
		if( dir->d_name[0] == '.' )	// no need to search directories which begin with "."
		{
			continue;
		}
		//printf("At %s\n",dir->d_name);
		if( dir->d_type == DT_DIR ) 
		{
			strcpy( buff, directory_to_search );	// directory_to_search acts as the current directory here
			strcat( buff, "/" );
			strcat( buff, dir->d_name );
			//printf("planning to go to %s\n",buff);
			if ( file_finder( searching, result, buff ) == 101 )
				return 101;
		} 
		else 
		{
			if( strcmp( dir->d_name, searching ) == 0 ) 
			{
				int  len;
				getcwd( result, MAXPATHLEN );
				len = strlen( result );
				strcpy( buff, directory_to_search );	// directory_to_search acts as the current directory here
				strcat( buff, "/" );
				strcat( buff, dir->d_name );
				strcpy( result, buff );
				// printf("Found: %s\n", buff );
				return 101;
			}
		}
	}
	closedir( d );
	return *result == 0;
}
Exemplo n.º 7
0
    void TestAxiWriterAscii()
    {
        FileFinder file_finder("heart/test/data/fibre_tests/SimpleAxisymmetric2.axi", RelativeTo::ChasteSourceRoot);
        FibreReader<3> fibre_reader(file_finder, AXISYM);
        std::vector< c_vector<double, 3> > fibre_vector;
        fibre_reader.GetAllAxi(fibre_vector);

        // Write ascii file
        FibreWriter<3> fibre_writer("TestFibreWriter", "SimpleAxisymmetric2", true);
        fibre_writer.WriteAllAxi(fibre_vector);

        std::string results_dir = OutputFileHandler::GetChasteTestOutputDirectory() + "TestFibreWriter/";
        FileComparison comparer(results_dir + "/SimpleAxisymmetric2.axi","heart/test/data/fibre_tests/SimpleAxisymmetric2.axi");
        TS_ASSERT(comparer.CompareFiles());
    }
Exemplo n.º 8
0
    void TestOrthoWriterAscii()
    {
        FileFinder file_finder("heart/test/data/fibre_tests/Orthotropic3D.ortho", RelativeTo::ChasteSourceRoot);
        FibreReader<3> fibre_reader(file_finder, ORTHO);
        std::vector< c_vector<double, 3> > fibres;
        std::vector< c_vector<double, 3> > second;
        std::vector< c_vector<double, 3> > third;
        fibre_reader.GetAllOrtho(fibres, second, third);

        //Write ascii file
        FibreWriter<3> fibre_writer("TestFibreWriter", "Orthotropic3D", false);
        fibre_writer.WriteAllOrtho(fibres, second, third);

        std::string results_dir = OutputFileHandler::GetChasteTestOutputDirectory() + "TestFibreWriter/";

        FileComparison comparer(results_dir + "/Orthotropic3D.ortho","heart/test/data/fibre_tests/Orthotropic3D.ortho");
        TS_ASSERT(comparer.CompareFiles());
    }
Exemplo n.º 9
0
void CResourceManager::CleanCachedPage(nid aPageId)
{
    int len = GetCachePath().Length();
    HBufC* cache = HBufC::New(len + 64);
    TPtr p = cache->Des();
    TPtr path = GetCachePath();
    p.Format(KCachePathFormat, &path, aPageId);
    
    _LIT(KWildName, "*.*");
    RFs& fs = CCoeEnv::Static()->FsSession();
    TFindFile file_finder(fs);
    CDir* file_list;
    TInt err = file_finder.FindWildByDir(KWildName, p, file_list);
    while (err == KErrNone) {
        for (TInt i = 0; i < file_list->Count(); i++) {
            if ((*file_list)[i].IsDir())
                continue;

            TParse fullentry;
            fullentry.Set((*file_list)[i].iName, &file_finder.File(), NULL);
            if (fullentry.ExtPresent()) {
                err = fs.Delete(fullentry.FullName());
            }
            else {
                TFileName filename;
                filename.Append(fullentry.DriveAndPath());
                filename.Append(fullentry.Name());
                err = fs.Delete(filename);
            }
        }
        delete file_list;
        err = file_finder.FindWild(file_list);
    }

    err = fs.RmDir(p);
    delete cache;
}
Exemplo n.º 10
0
    void TestWritingToFile() throw(Exception)
    {
        EXIT_IF_PARALLEL;

        std::string output_directory = "TestCellBasedPdeHandlerWritingToFile";

        // Create a cell population
        HoneycombMeshGenerator generator(4, 4, 0);
        MutableMesh<2,2>* p_generating_mesh = generator.GetMesh();
        NodesOnlyMesh<2> mesh;
        mesh.ConstructNodesWithoutMesh(*p_generating_mesh, 1.5);

        std::vector<CellPtr> cells;
        CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator;
        cells_generator.GenerateBasic(cells, mesh.GetNumNodes());
        TS_ASSERT_EQUALS(cells.size(), mesh.GetNumNodes());
        NodeBasedCellPopulation<2> cell_population(mesh, cells);

        cell_population.SetDataOnAllCells("variable", 1.0);

        // Create a PDE handler object using this cell population
        CellBasedPdeHandler<2> pde_handler(&cell_population);

        TS_ASSERT_THROWS_THIS(pde_handler.OpenResultsFiles(output_directory),
                "Trying to solve a PDE on a cell population that doesn't have a mesh. Try calling UseCoarsePdeMesh().");

        // Use a coarse PDE mesh since we are using a node-based cell population
        AveragedSourcePde<2> pde(cell_population, -0.1);
        ConstBoundaryCondition<2> bc(1.0);
        PdeAndBoundaryConditions<2> pde_and_bc(&pde, &bc, false);
        pde_and_bc.SetDependentVariableName("variable");
        pde_handler.AddPdeAndBc(&pde_and_bc);

        ChastePoint<2> lower(0.0, 0.0);
        ChastePoint<2> upper(9.0, 9.0);
        ChasteCuboid<2> cuboid(lower, upper);

        pde_handler.UseCoarsePdeMesh(3.0, cuboid, true);

        // For coverage, call SetWriteAverageRadialPdeSolution() prior to output
        pde_handler.SetWriteAverageRadialPdeSolution("variable", 5, true);

        // Test that output files are opened correctly
        pde_handler.OpenResultsFiles(output_directory);

        FileFinder file_finder(output_directory + "/results.vizcoarsepdesolution", RelativeTo::ChasteTestOutput);
        TS_ASSERT(file_finder.Exists());
        TS_ASSERT(file_finder.IsFile());

        FileFinder file_finder2(output_directory + "/radial_dist.dat", RelativeTo::ChasteTestOutput);
        TS_ASSERT(file_finder2.Exists());
        TS_ASSERT(file_finder2.IsFile());

        TS_ASSERT_THROWS_NOTHING(pde_handler.CloseResultsFiles());

        // For coverage, also test that output files are opened correctly when not using a coarse PDE mesh
        HoneycombMeshGenerator generator2(5, 5, 0);
        MutableMesh<2,2>* p_mesh2 = generator2.GetMesh();

        std::vector<CellPtr> cells2;
        CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator2;
        cells_generator2.GenerateBasic(cells2, p_mesh2->GetNumNodes());

        MeshBasedCellPopulation<2> cell_population2(*p_mesh2, cells2);

        cell_population2.SetDataOnAllCells("another variable", 1.0);

        CellBasedPdeHandler<2> pde_handler2(&cell_population2);
        pde_handler2.OpenResultsFiles(output_directory);

        FileFinder file_finder3(output_directory + "/results.vizpdesolution", RelativeTo::ChasteTestOutput);
        TS_ASSERT(file_finder3.Exists());
        TS_ASSERT(file_finder3.IsFile());

        pde_handler2.CloseResultsFiles();
    }
Exemplo n.º 11
0
int main ( ) 
{ 
	int s , cd, pid, port_no; 
	printf("Enter port number for the server\n");
	scanf("%d", &port_no);
	if ( port_no < 0 )
	{
		error("negative port numbers ");
	}

	char start_directory_to_find_file[MAXPATHLEN];	// this can be hardcoded to "/home" for example if there are no permission problems to search files in that directory. The safest option would be to search in the current directory where server is running

    getcwd( start_directory_to_find_file, MAXPATHLEN );
	printf("current working directory is %s\n", start_directory_to_find_file);
	
	struct sockaddr_in ser; 
	/*
		struct sockaddr_in 
		{
			short sin_family;	// AF_INET 
			u short sin_port;	// 16-bit port number 
			struct in_addr sin_addr;	// 32-bit netid/hostid 
			char sin_zero[8];	// unused 	
		};
	*/
	s = socket( AF_INET,SOCK_STREAM, 0 ); 	
	/* 
		socket(domain, type, protocol); 
		Protocol ’0’ means use of default protocol. 
		Socket domains
			AF_UNIX 				Unix Domain
			AF_INET 				Internet Domain
			AF_NS 					Xerox Protocols Domain
		Socket types
			SOCK_STREAM				reliable, no record boundaries
			SOCK_DGRAM				Datagram unreliable, record boundaries
			SOCK_RAW				Raw Access underlying protocol directly
			SOCK_SEQPACKET 			Sequenced reliable, record boundaries
		Return value: Upon successful completion, socket() shall return a non-negative integer, the socket file descriptor. Otherwise, a 			value of -1 shall be returned and errno set to indicate the error.
	*/

	if( s < 0 ) 
	{
		error("Socket not created "); 
	}	
	bzero( &ser, sizeof(struct sockaddr_in) ); // bzero (dest, nbytes); bzero writes null bytes to the string

	ser.sin_family = AF_INET; 

	ser.sin_port = htons( port_no ); 	// htons convert host byte order to network byte order, it is used to make sure that endianess of bytes is correct as desired by network bytes

	inet_aton("localhost", &ser.sin_addr); 	// The inet_aton() function converts the specified string, in the Internet standard dot notation, to a network address, and stores the address in the structure provided in the second parameter

	if ( bind( s, (struct sockaddr *)&ser, sizeof(ser)) < 0 ) // The bind() function shall assign a local socket address ("ser" here) to a socket identified by descriptor "s" that has no local socket address assigned. Returns 0 if no error occurs
	{
		error("Bind Error ");
	} 

	listen( s, 5 ); // int listen (int usocket, int n): The listen function enables the socket "usocket" to accept connections, thus making it a server socket. The argument "n" specifies the length of the queue for pending connections. When the queue fills, new clients attempting to connect fail with ECONNREFUSED until the server calls accept to accept a connection from the queue. 
	
	//cd=accept( s, NULL, NULL );

	while ( 1 ) 
	{  
		printf("Ready to accept requests\n");
		cd=accept( s, NULL, NULL );
		if ( cd == -1 )
			error("connection refused ");
		/*
			int accept (int usocket, struct sockaddr *addr, socklen_t *length_ptr);
			This function is used to accept a connection request on the server socket "usocket". 
			The "addr" and "length-ptr" arguments are used to return information about the name of the client socket that initiated the 			connection. 
			Accepting a connection does not make "usocket" part of the connection. Instead, it creates a new socket which becomes connected. 				The normal RETURN value of accept is the file descriptor for the new socket.

			After accept, the original socket socket remains open and unconnected, and continues listening until you close it. You can 				accept further connections with socket by calling accept again.

			If an error occurs, accept returns -1.
		*/

		char buf[BUF_SIZE] = ""; 
		char result[1000];
		pid = fork( ); 
		if( pid == 0 ) 
		{  
			printf("accept value %d\n",cd); 

			read( cd, buf, BUF_SIZE ); 	// read(int fildes, void *buf, size_t nbyte); The read() function shall attempt to read nbyte bytes from the file associated with the open file descriptor, fildes, into the buffer pointed to by buf.
			printf("Message from client: %s\n", buf); 

			if( file_finder( buf, result, start_directory_to_find_file ) == 101 ) 
			{
				printf( "File Found: %s\nSending to client\n", result );
				get_file_contents (cd, result );	// getting the file's content and sending it to client in chunks of SEND_SIZE bytes
			} 
			else 
			{
				printf("File requested by client not found\n");
				strcpy(result, "-1");	// file not found is indicated by -1 
				write( cd, result, strlen(result) ); 
			}
			
			//write( cd, result, strlen(result) ); 

			close( cd ); 
			//printf("closed cd\n");
			//exit(0);
		}
		//printf("after pid condition\n");
	} 
	close( s ); 
	return 0;
} 
Exemplo n.º 12
0
int file_finder(api_config *config, char *path, char *parent_dir)
{
	BYTE *bytes;
	DWORD size;
	photo_linked_list *temp, *head, *killme, *last;
	char *album_id;
	DIR *dp;
	struct stat st;
	struct dirent *dptr;
	char filename[DIRPATHSIZE];
	char **dirs_array;
	char **files_array;
	int dirs_array_size, files_array_size, dirs_index, files_index, i, upload_tries;

	dptr = NULL;
	upload_tries = 0;
	head = (photo_linked_list*) malloc(sizeof(photo_linked_list));
	memset(head->photo_path, 0, DIRPATHSIZE);
	head->next = NULL;
	dp = NULL;
	last = head;
	dirs_array_size = files_array_size = dirs_index = files_index = 0;

	throw_error(NULL == (dp = opendir(path)), CANT_OPEN_DIR, "Could not open %s", path);
	log_info("Entering %s", path);
	while(NULL != (dptr = readdir(dp))) {
		if(0 == strcmp(".", dptr->d_name))
			continue;
		if(0 == strcmp("..", dptr->d_name))
			continue;
		strncpy(filename, path, DIRPATHSIZE);
		strncat(filename, PATH_SEPARATOR, DIRPATHSIZE);
		strncat(filename, dptr->d_name, DIRPATHSIZE);

		stat(filename, &st);
		if(S_ISDIR(st.st_mode)) {
			strcpy(last->photo_path, filename);
			last->type = 0x01;
			dirs_array_size++;
			last->next = (photo_linked_list*) malloc(sizeof(photo_linked_list));
			last->next->next = NULL;
			last = last->next;
		} else {
			strcpy(last->photo_path, filename);
			last->type = 0x02;
			files_array_size++;
			last->next = (photo_linked_list*) malloc(sizeof(photo_linked_list));
			last->next->next = NULL;
			last = last->next;
		}
	}
	closedir(dp);
	temp = head;
	dirs_array = malloc(sizeof(char*) * dirs_array_size);
	files_array = malloc(sizeof(char*) * files_array_size);

	while(NULL != temp->next) {
		if(0x01 == temp->type) {
			dirs_array[dirs_index] = malloc(sizeof(char) * strlen(temp->photo_path) + 1);
			strcpy(dirs_array[dirs_index], temp->photo_path);
			dirs_index++;
		}
		if(0x02 == temp->type) {
			files_array[files_index] = malloc(sizeof(char) * strlen(temp->photo_path) + 1);
			strcpy(files_array[files_index], temp->photo_path);
			files_index++;
		}

		killme = temp;
		temp = temp->next;
		free(killme);
	}
	free(temp);

	qsort(dirs_array, dirs_array_size, sizeof(char*), compare_strings);
	qsort(files_array, files_array_size, sizeof(char*), compare_strings);

	for(i=0; i<dirs_array_size; i++) {
		throw_error(!file_finder(config, dirs_array[i], &dirs_array[i][strlen(path) + sizeof(char)]), last_error, "problem calling file_finder");
		free(dirs_array[i]);
	}

	for(i=0; i<files_array_size; i++) {
		log_info("running (%s): %s", parent_dir, files_array[i]);
		if(NULL == parent_dir) {
			log_info("=> No album. File %s should be uploaded without a album", files_array[i]);
			album_id = NULL;
		} else {
			throw_error(!get_album_by_name(config, parent_dir, &album_id),
					APP_ERROR,
					"problem calling get_album_by_name for %s",
					parent_dir);

			if(NULL == album_id) {
				log_info("=> Album %s doesn't exist. We must create it", parent_dir);
				throw_error(!create_new_album(config,
						parent_dir),
						APP_ERROR,
						"could not create new album %s", parent_dir);

				throw_error(!get_album_by_name(config,
							parent_dir,
							&album_id), APP_ERROR, "problem calling get_album_by_name for %s", parent_dir);

				throw_error(NULL == album_id, APP_ERROR, "Album was not created or could not be found. Must exit");
			} else {
				log_info("=> Album %s found. It's id is %s. Let's upload photo %s to album id %s", parent_dir, album_id, files_array[i], album_id);
			}
		}

		throw_error(!resize_jpeg(files_array[i], &bytes, &size), APP_ERROR, "Problem calling resize_jpeg on %s", files_array[i]);

		log_info("Begin upload %s", files_array[i]);
		while(!upload_photo_stream_to_album(config, bytes, size, album_id)) {
			throw_error(upload_tries++ > 2, APP_ERROR, "too many tries to upload image");
			if(OUTDATE_ACCESS_TOKEN == last_error) {
				log_warn("access_token esta desatualizado");
				throw_error(!get_access_token(config), APP_ERROR, "error calling get_access_token");
			}
		}
		log_info("Ended upload %s", files_array[i]);
		free(bytes);

		throw_error(unlink(files_array[i]) < 0,
				APP_ERROR,
				"could not delete file %s", files_array[i]);
		free(files_array[i]);
	}

	if(NULL != parent_dir)
		rmdir(path);

	free(dirs_array);
	free(files_array);

	return 1;
error:
	return 0;
}
Exemplo n.º 13
0
int main()
{
	DIR *dirtry = NULL;
	api_config config_data;
	curl_version_info_data *curl_info_data;

	curl_global_init(CURL_GLOBAL_ALL);
	init_idname_mylist();
	FreeImage_Initialise(TRUE);
	FreeImage_SetOutputMessage(FreeImageErrorHandler);

	curl_info_data = curl_version_info(CURLVERSION_NOW);
	log_info("Imgur Folder2Album Uploader " VERSION_NUMBER);
	log_info("Using Curl %s", curl_info_data->version);
	log_info("Using FreeImage %s", FreeImage_GetVersion());

	memset(&config_data, 0, sizeof(api_config));

	if(!get_config_from_file(&config_data)) {
		if(CONFIG_FILE_DOESNOT_EXIST == last_error) {
			if(!get_imgur_pin(&config_data)) {
				return 1;
			}
			if(!get_access_token(&config_data)) {
				return 1;
			}
			if(!save_config_data(&config_data)) {
				return 1;
			}
		}
	}
	log_info("Welcome %s", config_data.account_username);
	if(!load_idname() && CANT_OPEN_FILE == last_error) {
		log_info("File " ALBUM_DATA_FILE " does not exist.");
	}

	while(NULL == (dirtry = opendir(config_data.images_directory))) {
		log_err("Could not open dir %s\n", config_data.images_directory);
		get_imgur_dir(&config_data);
	}
	closedir(dirtry);

	if(!save_config_data(&config_data)) {
		return 1;
	}

	file_finder(&config_data, config_data.images_directory, NULL);

	curl_global_cleanup();
	FreeImage_DeInitialise();
	if(!save_config_data(&config_data)) {
		return 1;
	}
	if(!save_idname()) {
		return 1;
	}
// 	print_albuns();
	kill_idname_mylist();
	log_info("Bye");
	return 0;
}