00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #if (defined(__sgi) || defined(linux) || defined(sun))
00018 #ifndef _CAVERNMISC_FILELIST_C
00019 #define _CAVERNMISC_FILELIST_C
00020
00021 #ifdef linux
00022 #ifndef _GNU_SOURCE
00023 #define _GNU_SOURCE
00024 #endif
00025 #endif
00026
00027
00028 #include <stdio.h>
00029 #include <ftw.h>
00030 #include <sys/stat.h>
00031 #include <sys/types.h>
00032 #include <string.h>
00033 #include <time.h>
00034 #include "CAVERNnet_datapack_c.hxx"
00035
00038 class CAVERNmisc_fileInfo_c
00039 {
00040
00041 protected:
00042 char* fileName;
00043 long fileSize;
00044 long timeStamp;
00045 int objectType;
00046 char* leafName;
00047 void setLeafName(char* path);
00048 public:
00049
00051
00052 static const int OK;
00054 static const int FAILED;
00056 static const int FILE_TYPE;
00058 static const int DIRECTORY_TYPE;
00060 static const int DIRECTORY_TYPE_CANNOT_BE_READ;
00062
00063 CAVERNmisc_fileInfo_c();
00064 ~CAVERNmisc_fileInfo_c();
00065
00074 void setFileInfo(char* path, char* fName, long fSize, long tStamp, int type);
00075
00081 void getFileName(char*& fName);
00082
00088 void getLeafName(char*& lName);
00089
00090
00096 long getFileSize();
00097
00103 long getTimeStamp();
00104
00109 int getObjectType();
00110
00116 int getPackingSize();
00117
00123 int packFileInfo(CAVERNnet_datapack_c* packer);
00124
00131 int unpackFileInfo(CAVERNnet_datapack_c* packer, char* path);
00132
00136 void displayFileInfo();
00137 };
00138
00143 class CAVERNmisc_fileList_c
00144 {
00145 private:
00146 int depth;
00147 int I_ALLOCATED_MEMORY;
00148 static int ftwCallBack(const char* fname, const struct stat* statBuf, int objectType, struct FTW* ftwstruct);
00149 static int ftwDummyCallBack(const char* fname, const struct stat* statBuf, int objectType, struct FTW* ftwstruct);
00150 static CAVERNmisc_fileList_c* thisInstance ;
00151 public:
00153
00154 static const int OK;
00156 static const int FAILED;
00158 static const int LIST_RECURSIVELY;
00160 static const int SKIP_RECURSION;
00162 static const int TRAVERSE_LINKS;
00164 static const int DO_NOT_TRAVERSE_LINKS;
00166
00167 char* path;
00168 int noFiles;
00169 int fileCount;
00170 int doRecursion;
00171 CAVERNmisc_fileInfo_c* fileList;
00172
00173 CAVERNmisc_fileList_c();
00174 ~CAVERNmisc_fileList_c();
00175
00180 void setDepth(int newDepth);
00181
00193 int buildFileList(char* dirName, int recursion = SKIP_RECURSION, int linkTraversal = DO_NOT_TRAVERSE_LINKS);
00194
00200 int getNoFiles();
00201
00207 int packFileList(CAVERNnet_datapack_c* packer);
00208
00214 int getDataPackingSize();
00215
00224 int unpackfileList(CAVERNnet_datapack_c* packer, char* path, CAVERNmisc_fileInfo_c* list, int fileCount);
00225
00229 void displayFileList();
00230 };
00231
00232 #endif
00233 #endif