The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 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 express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef MEDIASCANNER_H |
| 18 | #define MEDIASCANNER_H |
| 19 | |
Mathias Agopian | 273d098 | 2009-05-31 19:13:00 -0700 | [diff] [blame] | 20 | #include <utils/Log.h> |
| 21 | #include <utils/threads.h> |
| 22 | #include <utils/List.h> |
| 23 | #include <utils/Errors.h> |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame] | 24 | #include <utils/String8.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <pthread.h> |
| 26 | |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 27 | struct dirent; |
| 28 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | |
| 31 | class MediaScannerClient; |
| 32 | class StringArray; |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame] | 33 | class CharacterEncodingDetector; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 35 | enum MediaScanResult { |
| 36 | // This file or directory was scanned successfully. |
| 37 | MEDIA_SCAN_RESULT_OK, |
| 38 | // This file or directory was skipped because it was not found, could |
| 39 | // not be opened, was of an unsupported type, or was malfored in some way. |
| 40 | MEDIA_SCAN_RESULT_SKIPPED, |
| 41 | // The scan should be aborted due to a fatal error such as out of memory |
| 42 | // or an exception. |
| 43 | MEDIA_SCAN_RESULT_ERROR, |
| 44 | }; |
| 45 | |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 46 | struct MediaScanner { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | MediaScanner(); |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 48 | virtual ~MediaScanner(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 50 | virtual MediaScanResult processFile( |
| 51 | const char *path, const char *mimeType, MediaScannerClient &client) = 0; |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 52 | |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 53 | virtual MediaScanResult processDirectory( |
| 54 | const char *path, MediaScannerClient &client); |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 55 | |
| 56 | void setLocale(const char *locale); |
| 57 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | // extracts album art as a block of data |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 59 | virtual char *extractAlbumArt(int fd) = 0; |
| 60 | |
| 61 | protected: |
| 62 | const char *locale() const; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | |
| 64 | private: |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | // current locale (like "ja_JP"), created/destroyed with strdup()/free() |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 66 | char *mLocale; |
Guang Zhu | fb6f034 | 2011-09-07 23:55:27 -0700 | [diff] [blame] | 67 | char *mSkipList; |
| 68 | int *mSkipIndex; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 70 | MediaScanResult doProcessDirectory( |
| 71 | char *path, int pathRemaining, MediaScannerClient &client, bool noMedia); |
| 72 | MediaScanResult doProcessDirectoryEntry( |
| 73 | char *path, int pathRemaining, MediaScannerClient &client, bool noMedia, |
| 74 | struct dirent* entry, char* fileSpot); |
Guang Zhu | fb6f034 | 2011-09-07 23:55:27 -0700 | [diff] [blame] | 75 | void loadSkipList(); |
| 76 | bool shouldSkipDirectory(char *path); |
| 77 | |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 78 | |
| 79 | MediaScanner(const MediaScanner &); |
| 80 | MediaScanner &operator=(const MediaScanner &); |
| 81 | }; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
| 83 | class MediaScannerClient |
| 84 | { |
| 85 | public: |
Marco Nelissen | f482a41 | 2009-09-03 10:49:55 -0700 | [diff] [blame] | 86 | MediaScannerClient(); |
| 87 | virtual ~MediaScannerClient(); |
| 88 | void setLocale(const char* locale); |
| 89 | void beginFile(); |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 90 | status_t addStringTag(const char* name, const char* value); |
Marco Nelissen | f482a41 | 2009-09-03 10:49:55 -0700 | [diff] [blame] | 91 | void endFile(); |
| 92 | |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 93 | virtual status_t scanFile(const char* path, long long lastModified, |
Mike Lockwood | c5182e3 | 2011-04-24 11:15:09 -0700 | [diff] [blame] | 94 | long long fileSize, bool isDirectory, bool noMedia) = 0; |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 95 | virtual status_t handleStringTag(const char* name, const char* value) = 0; |
| 96 | virtual status_t setMimeType(const char* mimeType) = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | |
| 98 | protected: |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame] | 99 | // default encoding from MediaScanner::mLocale |
| 100 | String8 mLocale; |
| 101 | CharacterEncodingDetector *mEncodingDetector; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | }; // namespace android |
| 105 | |
| 106 | #endif // MEDIASCANNER_H |