• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 // -*- c++ -*-
19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
20 
21 //                     O S C L _ F I L E  _ FIND
22 
23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
24 
25 /*! \addtogroup osclio OSCL IO
26  *
27  * @{
28  */
29 
30 
31 /*! \file oscl_file_find.h
32     \brief The file oscl_file_find.h defines the  class Oscl_FileFind
33 
34 */
35 
36 #ifndef OSCL_FILE_FIND_H_INCLUDED
37 #define OSCL_FILE_FIND_H_INCLUDED
38 
39 #ifndef OSCLCONFIG_IO_H_INCLUDED
40 #include "osclconfig_io.h"
41 #endif
42 
43 #ifndef OSCL_BASE_H_INCLUDED
44 #include "oscl_base.h"
45 #endif
46 
47 #ifndef OSCL_MEM_H_INCLUDED
48 #include "oscl_mem.h"
49 #endif
50 
51 #ifndef OSCL_VECTOR_H_INCLUDED
52 #include "oscl_vector.h"
53 #endif
54 
55 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
56 #include "oscl_string_containers.h"
57 #endif
58 
59 #ifndef OSCL_FILE_TYPES_H_INCLUDED
60 #include "oscl_file_types.h"
61 #endif
62 
63 /**
64  * Oscl_FileFind class defines the generic way of finding filesystem elements that match a pattern  within a directory
65  */
66 
67 class Oscl_FileFind
68 {
69     public:
70 
71         /**
72          * Finds first element matching the pattern.
73          *
74          * @param directory directory to search (utf8).
75          * @param pattern wildcard pattern filter (utf8).  passing NULL, results in a universal match.
76          * @param buf buffer for returned pathname (utf8).
77          * @param buflen size in wide characters of buf.  If buf is not large enough to hold the returned string, NULL is returned, and GetLastError is set to E_BUFFER_TOO_SMALL.
78          *
79          * @return returns a pointer to buffer supplied, which contains the pathname of the next found element, or NULL otherwise.On a NULL return value, GetLastError() returns a more detailed error.
80          */
81         OSCL_IMPORT_REF const char *FindFirst(const char *directory, const char *pattern, char *buf, uint32 buflen);
82         /**
83          * Opens a directory for reading.
84          *
85          * @param directory directory to search (utf16).
86          * @param pattern wildcard pattern filter (utf16).  passing NULL, results in a universal match.
87          * @param buf buffer for returned pathname (utf16).
88          * @param buflen size in wide characters of buf.  If buf is not large enough to hold the returned string, NULL is returned, and GetLastError is set to E_BUFFER_TOO_SMALL.
89          *
90          * @return returns a pointer to buffer supplied, which contains the pathname of the next found element, or NULL otherwise.  On a NULL return value, GetLastError() returns a more detailed error.
91          */
92         OSCL_IMPORT_REF const oscl_wchar *FindFirst(const oscl_wchar *directory, const oscl_wchar *pattern, oscl_wchar *buf, uint32 buflen);
93         /**
94          * Reads the next element in the directory.
95          * Note: the pointer returned by this function is not persistent and
96          *   should be stored.  Its scope is limited to the lifetime of the class.
97          * @param buf buffer to hold directory name(utf8)
98          * @param buflen size in wide characters of buf.  If buf is not large enough to hold the returned string, NULL is returned, and GetLastError is set to E_BUFFER_TOO_SMALL.
99          * @return returns a pointer to buffer supplied, which contains the pathname of the next found element, or NULL otherwise.  On a NULL return value, GetLastError() returns a more detailed error.
100          */
101         OSCL_IMPORT_REF char *FindNext(char *buf, uint32 buflen);
102         /**
103          * Reads the next element in a directory.
104          * Note: the pointer returned by this function is not persistent and
105          *   should be stored.  Its scope is limited to the lifetime of the class.
106          * @param buf buffer to hold directory name(utf16)
107          * @param buflen size in wide characters of buf.  If buf is not large enough to hold the returned string, NULL is returned, and GetLastError is set to E_BUFFER_TOO_SMALL.
108          * @return returns a pointer to buffer supplied, which contains the pathname of the next found element, or NULL otherwise.  On a NULL return value, GetLastError() returns a more detailed error.
109          */
110         OSCL_IMPORT_REF oscl_wchar *FindNext(oscl_wchar *buf, uint32 buflen);
111         /**
112          * closes the handle to directory.
113          * @return none
114          */
115         OSCL_IMPORT_REF void Close();
116 
117         typedef enum
118         {
119             E_OK = 0,
120             E_INVALID_STATE,
121             E_INVALID_ARG,
122             E_PATH_TOO_LONG,
123             E_PATH_NOT_FOUND,
124             E_NO_MATCH,
125             E_BUFFER_TOO_SMALL,
126             E_NOT_IMPLEMENTED,
127             E_MEMORY_ERROR,
128             E_OTHER
129         } error_type;
130 
131         typedef enum
132         {
133             FILE_TYPE = 0, /* file */
134             DIR_TYPE,      /* directory */
135             INVALID_TYPE   /* no element available */
136         } element_type;
137 
138         /**
139          * Returns the element type for the last element returned
140          * @return see enumeration above for more info.
141          */
142         OSCL_IMPORT_REF element_type GetElementType();
143 
144 
145         /**
146          * Returns the error code for the last operation.
147          * @return see enumeration above for more info.
148          */
149         OSCL_IMPORT_REF error_type GetLastError();
150 
151         /**
152          * constructor.
153          * @return none
154          */
155         OSCL_IMPORT_REF Oscl_FileFind();
156         /**
157          * destructor.  will deallocate open handles if necessary
158          *
159          * @return none
160          */
161         OSCL_IMPORT_REF ~Oscl_FileFind();
162 
163     private:
164 
165         typedef char chartype;
166         bool setpathanddelimiter(const chartype* directory);
167 
168 #if   (OSCL_HAS_GLOB)
169         glob_t hFind;
170 #else
171         Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iDirEntVec;
172 #endif
173         uint32 count;
174         bool foundfirst;
175         error_type lastError;
176         element_type type;
177         bool appendPathDelimiter;
178         chartype* pathname;
179         const chartype* delimeter;
180         const chartype* nullchar;
181 };
182 
183 
184 #endif // OSCL_FILE_FIND_H_INCLUDED
185 
186 /*! @} */
187 
188