blob: 803bffb77f1757d28118ad9548d34d0c5bdb73dc [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Agopian3b4062e2009-05-31 19:13:00 -070020#include <utils/Log.h>
21#include <utils/threads.h>
22#include <utils/List.h>
23#include <utils/Errors.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <pthread.h>
25
Jeff Brown2c70d4a2011-07-20 16:38:43 -070026struct dirent;
27
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028namespace android {
29
30class MediaScannerClient;
31class StringArray;
32
Jeff Brown2c70d4a2011-07-20 16:38:43 -070033enum MediaScanResult {
34 // This file or directory was scanned successfully.
35 MEDIA_SCAN_RESULT_OK,
36 // This file or directory was skipped because it was not found, could
37 // not be opened, was of an unsupported type, or was malfored in some way.
38 MEDIA_SCAN_RESULT_SKIPPED,
39 // The scan should be aborted due to a fatal error such as out of memory
40 // or an exception.
41 MEDIA_SCAN_RESULT_ERROR,
42};
43
Andreas Huberbfb9fb12009-12-03 11:31:19 -080044struct MediaScanner {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 MediaScanner();
Andreas Huberbfb9fb12009-12-03 11:31:19 -080046 virtual ~MediaScanner();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Jeff Brown2c70d4a2011-07-20 16:38:43 -070048 virtual MediaScanResult processFile(
49 const char *path, const char *mimeType, MediaScannerClient &client) = 0;
Andreas Huberbfb9fb12009-12-03 11:31:19 -080050
Jeff Brown2c70d4a2011-07-20 16:38:43 -070051 virtual MediaScanResult processDirectory(
52 const char *path, MediaScannerClient &client);
Andreas Huberbfb9fb12009-12-03 11:31:19 -080053
54 void setLocale(const char *locale);
55
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 // extracts album art as a block of data
Andreas Huberbfb9fb12009-12-03 11:31:19 -080057 virtual char *extractAlbumArt(int fd) = 0;
58
59protected:
60 const char *locale() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
62private:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 // current locale (like "ja_JP"), created/destroyed with strdup()/free()
Andreas Huberbfb9fb12009-12-03 11:31:19 -080064 char *mLocale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
Jeff Brown2c70d4a2011-07-20 16:38:43 -070066 MediaScanResult doProcessDirectory(
67 char *path, int pathRemaining, MediaScannerClient &client, bool noMedia);
68 MediaScanResult doProcessDirectoryEntry(
69 char *path, int pathRemaining, MediaScannerClient &client, bool noMedia,
70 struct dirent* entry, char* fileSpot);
Andreas Huberbfb9fb12009-12-03 11:31:19 -080071
72 MediaScanner(const MediaScanner &);
73 MediaScanner &operator=(const MediaScanner &);
74};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
76class MediaScannerClient
77{
78public:
Marco Nelissen8b046612009-09-03 10:49:55 -070079 MediaScannerClient();
80 virtual ~MediaScannerClient();
81 void setLocale(const char* locale);
82 void beginFile();
Jeff Brown2c70d4a2011-07-20 16:38:43 -070083 status_t addStringTag(const char* name, const char* value);
Marco Nelissen8b046612009-09-03 10:49:55 -070084 void endFile();
85
Jeff Brown2c70d4a2011-07-20 16:38:43 -070086 virtual status_t scanFile(const char* path, long long lastModified,
Mike Lockwood997354e2011-04-24 11:15:09 -070087 long long fileSize, bool isDirectory, bool noMedia) = 0;
Jeff Brown2c70d4a2011-07-20 16:38:43 -070088 virtual status_t handleStringTag(const char* name, const char* value) = 0;
89 virtual status_t setMimeType(const char* mimeType) = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91protected:
92 void convertValues(uint32_t encoding);
93
94protected:
95 // cached name and value strings, for native encoding support.
96 StringArray* mNames;
97 StringArray* mValues;
Andreas Huberbfb9fb12009-12-03 11:31:19 -080098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 // default encoding based on MediaScanner::mLocale string
100 uint32_t mLocaleEncoding;
101};
102
103}; // namespace android
104
105#endif // MEDIASCANNER_H
106