Daiki Kato / scan_folder

Dependents:   GR-PEACH_Digital_Signage

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers scan_folder.h Source File

scan_folder.h

00001 /*******************************************************************************
00002 * DISCLAIMER
00003 * This software is supplied by Renesas Electronics Corporation and is only
00004 * intended for use with Renesas products. No other uses are authorized. This
00005 * software is owned by Renesas Electronics Corporation and is protected under
00006 * all applicable laws, including copyright laws.
00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00016 * Renesas reserves the right, without notice, to make changes to this software
00017 * and to discontinue the availability of this software. By using this software,
00018 * you agree to the additional terms and conditions found by accessing the
00019 * following link:
00020 * http://www.renesas.com/disclaimer*
00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 
00024 #ifndef SCAN_FOLDER_H
00025 #define SCAN_FOLDER_H
00026 
00027 #include "r_typedefs.h"
00028 #include "FATFileSystem.h"
00029 
00030 /*--- Macro definition of folder scan ---*/
00031 #define MAX_FOLDER_NUM      (99u)       /* Supported number of folders */
00032 #define MAX_TRACK_NUM       (999u)      /* Supported number of files  */
00033 #define MAX_FOLDER_DEPTH    (8u)        /* Supported folder levels */
00034 #define MAX_NAME_LENGTH     (NAME_MAX)  /* Maximum length of track name and folder name */
00035 #define MAX_PATH_LENGTH     (511)       /* Maximum length of the full path */
00036 
00037 class ScanFolder {
00038 public:
00039 
00040     /** Initializes the folder structure
00041      *
00042      */
00043     void init();
00044 
00045     /** Scans the folder structure
00046      *
00047      *  @param p_root_name The character string to identify root directory.
00048      *  @param p_extension_tbl extension tbl
00049      *
00050      *  @returns 
00051      *    Results of process. true is success. false is failure.
00052      */
00053     bool scan(char_t * p_root_name, const char_t ** pp_extension_tbl);
00054 
00055     /** Gets the total number of detected files
00056      *
00057      *  @returns 
00058      *    the total number of files
00059      */
00060     uint32_t getTotalFile();
00061 
00062     /** Gets the file name
00063      *
00064      *  @param track_id Track ID [0 - (total track - 1)]
00065      *
00066      *  @returns 
00067      *    Pointer to the file name.
00068      */
00069     const char_t * getFileName(const uint32_t track_id);
00070 
00071     /** Opens the file
00072      *
00073      *  @param track_id Track ID [0 - (total track - 1)]
00074      *
00075      *  @returns 
00076      *    Pointer to the track handle
00077      */
00078     FILE * open(const uint32_t track_id);
00079 
00080     /** Closes the file
00081      *
00082      *  @param fp Pointer to the track handle
00083      */
00084     void close(FILE * const fp);
00085 
00086 private:
00087     /* Information of a folder / track. */
00088     typedef struct {
00089         char_t      name[MAX_NAME_LENGTH + 1];      /* Name of a folder / track. */
00090         uint32_t    parent_number;                  /* Number of the parent folder. */
00091     } item_t;
00092 
00093     /* Information of folder scan in USB memory */
00094     typedef struct {
00095         item_t      folder_list[MAX_FOLDER_NUM];        /* Folder list */
00096         item_t      track_list[MAX_TRACK_NUM];          /* File list */
00097         uint32_t    total_folder;                       /* Total number of folders */
00098         uint32_t    total_file;                         /* Total number of files */
00099         char_t      work_buf[MAX_PATH_LENGTH + 1];      /* Work */
00100                                                         /* (Including the null terminal character.) */
00101     } fid_scan_folder_t;
00102 
00103     fid_scan_folder_t scan_data;
00104 
00105     const char_t * get_full_path(const item_t * const p_item);
00106     bool open_dir(const item_t * const p_item, FATFS_DIR * const p_fdir);
00107     bool read_dir(FATFS_DIR * const p_fdir,  const char_t ** const p_name, bool * const p_flag_dir);
00108     bool regist_item(item_t * const p_item, const char_t * const p_name, const uint32_t parent);
00109     bool check_extension(const char_t * const p_name, const char_t ** pp_extension_tbl);
00110     bool check_folder_depth(const uint32_t folder_id);
00111 };
00112 
00113 #endif /* SCAN_FOLDER_H */