blob: 0d397acc91d8a3f170342b1cd60425f5682e8a45 [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
Mathias Agopian273d0982009-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 Project89fa4ad2009-03-03 19:31:44 -080024#include <pthread.h>
25
26namespace android {
27
28class MediaScannerClient;
29class StringArray;
30
Andreas Huber413f5232009-12-03 11:31:19 -080031struct MediaScanner {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080032 MediaScanner();
Andreas Huber413f5232009-12-03 11:31:19 -080033 virtual ~MediaScanner();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080034
Andreas Huber413f5232009-12-03 11:31:19 -080035 virtual status_t processFile(
36 const char *path, const char *mimeType,
37 MediaScannerClient &client) = 0;
38
39 typedef bool (*ExceptionCheck)(void* env);
40 virtual status_t processDirectory(
41 const char *path, const char *extensions,
42 MediaScannerClient &client,
43 ExceptionCheck exceptionCheck, void *exceptionEnv);
44
45 void setLocale(const char *locale);
46
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080047 // extracts album art as a block of data
Andreas Huber413f5232009-12-03 11:31:19 -080048 virtual char *extractAlbumArt(int fd) = 0;
49
50protected:
51 const char *locale() const;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052
53private:
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080054 // current locale (like "ja_JP"), created/destroyed with strdup()/free()
Andreas Huber413f5232009-12-03 11:31:19 -080055 char *mLocale;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080056
Andreas Huber413f5232009-12-03 11:31:19 -080057 status_t doProcessDirectory(
58 char *path, int pathRemaining, const char *extensions,
59 MediaScannerClient &client, ExceptionCheck exceptionCheck,
60 void *exceptionEnv);
61
62 MediaScanner(const MediaScanner &);
63 MediaScanner &operator=(const MediaScanner &);
64};
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065
66class MediaScannerClient
67{
68public:
Marco Nelissenf482a412009-09-03 10:49:55 -070069 MediaScannerClient();
70 virtual ~MediaScannerClient();
71 void setLocale(const char* locale);
72 void beginFile();
73 bool addStringTag(const char* name, const char* value);
74 void endFile();
75
76 virtual bool scanFile(const char* path, long long lastModified, long long fileSize) = 0;
77 virtual bool handleStringTag(const char* name, const char* value) = 0;
78 virtual bool setMimeType(const char* mimeType) = 0;
79 virtual bool addNoMediaFolder(const char* path) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080080
81protected:
82 void convertValues(uint32_t encoding);
83
84protected:
85 // cached name and value strings, for native encoding support.
86 StringArray* mNames;
87 StringArray* mValues;
Andreas Huber413f5232009-12-03 11:31:19 -080088
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080089 // default encoding based on MediaScanner::mLocale string
90 uint32_t mLocaleEncoding;
91};
92
93}; // namespace android
94
95#endif // MEDIASCANNER_H
96