1 /*****************************************************************************/ 2 // File: TranslatorRoster.h 3 // Class: BTranslatorRoster 4 // Reimplemented by: Michael Wilber, Translation Kit Team 5 // Reimplementation: 2002-06-11 6 // 7 // Description: This class is the guts of the translation kit, it makes the 8 // whole thing happen. It bridges the applications using this 9 // object with the translators that the apps need to access. 10 // 11 // 12 // Copyright (c) 2002 OpenBeOS Project 13 // 14 // Original Version: Copyright 1998, Be Incorporated, All Rights Reserved. 15 // Copyright 1995-1997, Jon Watte 16 // 17 // Permission is hereby granted, free of charge, to any person obtaining a 18 // copy of this software and associated documentation files (the "Software"), 19 // to deal in the Software without restriction, including without limitation 20 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 // and/or sell copies of the Software, and to permit persons to whom the 22 // Software is furnished to do so, subject to the following conditions: 23 // 24 // The above copyright notice and this permission notice shall be included 25 // in all copies or substantial portions of the Software. 26 // 27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 28 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33 // DEALINGS IN THE SOFTWARE. 34 /*****************************************************************************/ 35 36 #ifndef _TRANSLATOR_ROSTER_H 37 #define _TRANSLATOR_ROSTER_H 38 39 #include <TranslationDefs.h> 40 #include <OS.h> 41 #include <StorageDefs.h> 42 #include <InterfaceDefs.h> 43 #include <Archivable.h> 44 #include <TranslatorFormats.h> 45 #include <TranslationDefs.h> 46 #include <TranslationErrors.h> 47 #include <Translator.h> 48 #include <String.h> 49 #include <image.h> 50 #include <File.h> 51 #include <Directory.h> 52 #include <Volume.h> 53 #include <string.h> 54 #include <OS.h> 55 #include <stdlib.h> 56 #include <stdio.h> 57 #include <dirent.h> 58 #include <unistd.h> 59 #include <sys/stat.h> 60 #include <alloca.h> 61 #include <FuncTranslator.h> 62 63 struct translation_format; 64 65 class BBitmap; 66 class BView; 67 class BPositionIO; 68 class BQuery; 69 class BMessage; 70 71 const char kgDefaultTranslatorPath[] = "/boot/home/config/add-ons/Translators:/boot/home/config/add-ons/Datatypes:/system/add-ons/Translators"; 72 73 // used by BTranslatorRoster to store the list of translators 74 struct translator_node { 75 BTranslator *translator; 76 char *path; 77 image_id image; 78 translator_id id; 79 translator_node *next; 80 }; 81 82 class BTranslatorRoster : public BArchivable { 83 // private, unimplemented functions 84 // (I'm not sure if there is a need for them anyway) 85 BTranslatorRoster(const BTranslatorRoster &); 86 BTranslatorRoster & operator=(const BTranslatorRoster &); 87 88 public: 89 BTranslatorRoster(); 90 // initializes the object with no translators 91 92 BTranslatorRoster(BMessage *model); 93 // initializes the object and loads all translators from the 94 // "be:translator_path" string array in model 95 96 ~BTranslatorRoster(); 97 // frees memory used by this object 98 99 virtual status_t Archive(BMessage *into, bool deep = true) const; 100 // store the BTranslatorRoster in into so it can later be 101 // used with Instantiate or the BMessage constructor 102 103 static BArchivable *Instantiate(BMessage *from); 104 // creates a BTranslatorRoster object from the from archive 105 106 static const char *Version(int32 *outCurVersion, int32 *outMinVersion, 107 int32 inAppVersion = B_TRANSLATION_CURRENT_VERSION); 108 // returns the version of BTranslator roster as a string 109 // and through the int32 pointers; inAppVersion appears 110 // to be ignored 111 112 static BTranslatorRoster *Default(); 113 // returns the "default" set of translators, they are translators 114 // that are loaded from the default paths 115 // /boot/home/config/add-ons/Translators, 116 // /boot/home/config/add-ons/Datatypes, 117 // /system/add-ons/Translators or the paths in the 118 // TRANSLATORS environment variable, if it exists 119 120 status_t AddTranslators(const char *load_path = NULL); 121 // this adds a translator, all of the translators in a folder or 122 // the default translators if the path is NULL 123 124 status_t AddTranslator(BTranslator * translator); 125 // adds a translator that you've created yourself to the 126 // BTranslatorRoster; this is useful if you have translators 127 // that you don't want to make public or don't want loaded as 128 // an add-on 129 130 virtual status_t Identify(BPositionIO *inSource, BMessage *ioExtension, 131 translator_info *outInfo, uint32 inHintType = 0, 132 const char *inHintMIME = NULL, uint32 inWantType = 0); 133 // identifies the translator that can handle the data in inSource 134 135 virtual status_t GetTranslators(BPositionIO *inSource, 136 BMessage *ioExtension, translator_info **outInfo, int32 *outNumInfo, 137 uint32 inHintType = 0, const char *inHintMIME = NULL, 138 uint32 inWantType = 0); 139 // finds all translators for the given type 140 141 virtual status_t GetAllTranslators(translator_id **outList, 142 int32 *outCount); 143 // returns all translators that this object contains 144 145 virtual status_t GetTranslatorInfo(translator_id forTranslator, 146 const char **outName, const char **outInfo, int32 *outVersion); 147 // gets user visible info about a specific translator 148 149 virtual status_t GetInputFormats(translator_id forTranslator, 150 const translation_format **outFormats, int32 *outNumFormats); 151 // finds all input formats for a translator; 152 // note that translators don't always publish the formats 153 // that they support 154 155 virtual status_t GetOutputFormats(translator_id forTranslator, 156 const translation_format **outFormats, int32 *outNumFormats); 157 // finds all output formats for a translator; 158 // note that translators don't always publish the formats 159 // that they support 160 161 virtual status_t Translate(BPositionIO *inSource, 162 const translator_info *inInfo, BMessage *ioExtension, 163 BPositionIO *outDestination, uint32 inWantOutType, 164 uint32 inHintType = 0, const char *inHintMIME = NULL); 165 // the whole point of this entire kit boils down to this function; 166 // this translates the data in inSource into outDestination 167 // using the format inWantOutType 168 169 virtual status_t Translate(translator_id inTranslator, 170 BPositionIO *inSource, BMessage *ioExtension, 171 BPositionIO *outDestination, uint32 inWantOutType); 172 // the whole point of this entire kit boils down to this function; 173 // this translates the data in inSource into outDestination 174 // using the format inWantOutType and the translator inTranslator 175 176 virtual status_t MakeConfigurationView(translator_id forTranslator, 177 BMessage *ioExtension, BView **outView, BRect *outExtent); 178 // create the view for forTranslator that allows the user 179 // to configure it; 180 // NOTE: translators are not required to support this function 181 182 virtual status_t GetConfigurationMessage(translator_id forTranslator, 183 BMessage *ioExtension); 184 // this is used to save the settings for a translator so that 185 // they can be written to disk or used in an Indentify or 186 // Translate call 187 188 status_t GetRefFor(translator_id translator, entry_ref *out_ref); 189 // I'm guessing that this returns the entry_ref for the 190 // translator add-on file for the translator_id translator 191 192 private: 193 void Initialize(); 194 // class initialization code used by all constructors 195 196 translator_node *FindTranslatorNode(translator_id id); 197 // used to find the translator_node for the translator_id id 198 // returns NULL if the id is not valid 199 200 status_t LoadTranslator(const char *path); 201 // loads the translator add-on specified by path 202 203 void LoadDir(const char *path, int32 &loadErr, int32 &nLoaded); 204 // loads all of the translator add-ons from path and 205 // returns error status in loadErr and the number of 206 // translators loaded in nLoaded 207 208 bool CheckFormats(const translation_format *inputFormats, 209 int32 inputFormatsCount, uint32 hintType, const char *hintMIME, 210 const translation_format **outFormat); 211 // determines how the Identify function is called 212 213 // adds the translator to the list of translators 214 // that this object maintains 215 status_t AddTranslatorToList(BTranslator *translator); 216 status_t AddTranslatorToList(BTranslator *translator, 217 const char *path, image_id image, bool acquire); 218 219 static BTranslatorRoster *fspDefaultTranslators; 220 // object that contains the default translators 221 translator_node *fpTranslators; 222 // list of translators maintained by this object 223 sem_id fSem; 224 // semaphore used to lock this object 225 226 // used to maintain binary combatibility with 227 // past and future versions of this object 228 int32 fUnused[5]; 229 virtual void ReservedTranslatorRoster1(); 230 virtual void ReservedTranslatorRoster2(); 231 virtual void ReservedTranslatorRoster3(); 232 virtual void ReservedTranslatorRoster4(); 233 virtual void ReservedTranslatorRoster5(); 234 virtual void ReservedTranslatorRoster6(); 235 }; 236 237 #endif /* _TRANSLATOR_ROSTER_H */ 238 239