mediascanner.h revision 3e9f9f1596d4225ddd9288b4f7b24a15221374dc
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 20#include <utils/Log.h> 21#include <utils/threads.h> 22#include <utils/List.h> 23#include <utils/Errors.h> 24#include <pthread.h> 25 26namespace android { 27 28class MediaScannerClient; 29class StringArray; 30 31struct MediaScanner { 32 MediaScanner(); 33 virtual ~MediaScanner(); 34 35 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, MediaScannerClient &client, 42 ExceptionCheck exceptionCheck, void *exceptionEnv); 43 44 void setLocale(const char *locale); 45 46 // extracts album art as a block of data 47 virtual char *extractAlbumArt(int fd) = 0; 48 49protected: 50 const char *locale() const; 51 52private: 53 // current locale (like "ja_JP"), created/destroyed with strdup()/free() 54 char *mLocale; 55 56 status_t doProcessDirectory( 57 char *path, int pathRemaining, MediaScannerClient &client, 58 ExceptionCheck exceptionCheck, void *exceptionEnv); 59 60 MediaScanner(const MediaScanner &); 61 MediaScanner &operator=(const MediaScanner &); 62}; 63 64class MediaScannerClient 65{ 66public: 67 MediaScannerClient(); 68 virtual ~MediaScannerClient(); 69 void setLocale(const char* locale); 70 void beginFile(); 71 bool addStringTag(const char* name, const char* value); 72 void endFile(); 73 74 virtual bool scanFile(const char* path, long long lastModified, 75 long long fileSize, bool isDirectory) = 0; 76 virtual bool handleStringTag(const char* name, const char* value) = 0; 77 virtual bool setMimeType(const char* mimeType) = 0; 78 virtual bool addNoMediaFolder(const char* path) = 0; 79 80protected: 81 void convertValues(uint32_t encoding); 82 83protected: 84 // cached name and value strings, for native encoding support. 85 StringArray* mNames; 86 StringArray* mValues; 87 88 // default encoding based on MediaScanner::mLocale string 89 uint32_t mLocaleEncoding; 90}; 91 92}; // namespace android 93 94#endif // MEDIASCANNER_H 95 96