blob: fbef1dbde6c20d171ca80cf321c2b6a04aef87bf [file] [log] [blame]
The Android Open Source Project89fa4ad2009-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
20#include <utils.h>
21#include <pthread.h>
22
23namespace android {
24
25class MediaScannerClient;
26class StringArray;
27
28class MediaScanner
29{
30public:
31 MediaScanner();
32 ~MediaScanner();
33
34 typedef bool (*ExceptionCheck)(void* env);
35
36 status_t processFile(const char *path, const char *mimeType, MediaScannerClient& client);
37 status_t processDirectory(const char *path, const char* extensions,
38 MediaScannerClient& client, ExceptionCheck exceptionCheck, void* exceptionEnv);
39 void setLocale(const char* locale);
40
41 // extracts album art as a block of data
42 char* extractAlbumArt(int fd);
43
44 static void uninitializeForThread();
45
46private:
47 status_t doProcessDirectory(char *path, int pathRemaining, const char* extensions,
48 MediaScannerClient& client, ExceptionCheck exceptionCheck, void* exceptionEnv);
49 void initializeForThread();
50
51 // current locale (like "ja_JP"), created/destroyed with strdup()/free()
52 char* mLocale;
53};
54
55
56class MediaScannerClient
57{
58public:
59 MediaScannerClient();
60 virtual ~MediaScannerClient();
61 void setLocale(const char* locale);
62 void beginFile();
63 bool addStringTag(const char* name, const char* value);
64 void endFile();
65
66 virtual bool scanFile(const char* path, long long lastModified, long long fileSize) = 0;
67 virtual bool handleStringTag(const char* name, const char* value) = 0;
68 virtual bool setMimeType(const char* mimeType) = 0;
69
70protected:
71 void convertValues(uint32_t encoding);
72
73protected:
74 // cached name and value strings, for native encoding support.
75 StringArray* mNames;
76 StringArray* mValues;
77
78 // default encoding based on MediaScanner::mLocale string
79 uint32_t mLocaleEncoding;
80};
81
82}; // namespace android
83
84#endif // MEDIASCANNER_H
85