1 /*****************************************************************************/ 2 // File: Translator.h 3 // Class: BTranslator 4 // Reimplemented by: Michael Wilber, Translation Kit Team 5 // Reimplementation: 2002-06-15 6 // 7 // Description: This file contains the BTranslator class, the base class for 8 // all translators that don't use the BeOS R4/R4.5 add-on method. 9 // 10 // 11 // Copyright (c) 2002 OpenBeOS Project 12 // 13 // Original Version: Copyright 1998, Be Incorporated, All Rights Reserved. 14 // Copyright 1995-1997, Jon Watte 15 // 16 // Permission is hereby granted, free of charge, to any person obtaining a 17 // copy of this software and associated documentation files (the "Software"), 18 // to deal in the Software without restriction, including without limitation 19 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 // and/or sell copies of the Software, and to permit persons to whom the 21 // Software is furnished to do so, subject to the following conditions: 22 // 23 // The above copyright notice and this permission notice shall be included 24 // in all copies or substantial portions of the Software. 25 // 26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 27 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 31 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 32 // DEALINGS IN THE SOFTWARE. 33 /*****************************************************************************/ 34 #ifndef _TRANSLATOR_H 35 #define _TRANSLATOR_H 36 37 #include <TranslationDefs.h> 38 #include <Archivable.h> 39 40 class BTranslator : public BArchivable { 41 public: 42 BTranslator(); 43 // Sets refcount to 1 (the object is initially Acquired()'d once) 44 45 BTranslator *Acquire(); 46 // return actual object and increment the refcount 47 48 BTranslator *Release(); 49 // Decrements the refcount and returns pointer to the object. 50 // When the refcount is zero, NULL is returned and the object is 51 // deleted 52 53 int32 ReferenceCount(); 54 // returns the refcount, THIS IS NOT THREAD SAFE, ITS ONLY FOR "FUN" 55 56 virtual const char *TranslatorName() const = 0; 57 // returns the short name of the translator 58 59 virtual const char *TranslatorInfo() const = 0; 60 // returns a verbose name/description for the translator 61 62 virtual int32 TranslatorVersion() const = 0; 63 // returns the version of the translator 64 65 virtual const translation_format *InputFormats(int32 *out_count) 66 const = 0; 67 // returns the input formats and the count of input formats 68 // that this translator supports 69 70 virtual const translation_format *OutputFormats(int32 *out_count) 71 const = 0; 72 // returns the output formats and the count of output formats 73 // that this translator supports 74 75 virtual status_t Identify(BPositionIO *inSource, 76 const translation_format *inFormat, BMessage *ioExtension, 77 translator_info *outInfo, uint32 outType) = 0; 78 // determines whether or not this translator can convert the 79 // data in inSource to the type outType 80 81 virtual status_t Translate(BPositionIO *inSource, 82 const translator_info *inInfo, BMessage *ioExtension, 83 uint32 outType, BPositionIO *outDestination) = 0; 84 // this function is the whole point of the Translation Kit, 85 // it translates the data in inSource to outDestination 86 // using the format outType 87 88 virtual status_t MakeConfigurationView(BMessage *ioExtension, 89 BView **outView, BRect *outExtent); 90 // this function creates a view that allows the user to 91 // configure the translator, this function is not 92 // required for all translators 93 94 virtual status_t GetConfigurationMessage(BMessage *ioExtension); 95 // puts information about the current configuration of the 96 // translator into ioExtension so that it can be used with 97 // Identify or Translate or whatever, this function is 98 // not required for all translators 99 100 protected: 101 virtual ~BTranslator(); 102 // this is protected because the object is deleted by the 103 // Release() function instead of being deleted directly by 104 // the user 105 106 private: 107 int32 fRefCount; 108 // number of times this object has been referenced 109 // by the Acquire() function 110 111 sem_id fSem; 112 // used to lock object for Acquire() and Release() 113 114 // For binary compatibility with past and future 115 // version of this class 116 uint32 fUnused[8]; 117 virtual status_t _Reserved_Translator_0(int32, void *); 118 virtual status_t _Reserved_Translator_1(int32, void *); 119 virtual status_t _Reserved_Translator_2(int32, void *); 120 virtual status_t _Reserved_Translator_3(int32, void *); 121 virtual status_t _Reserved_Translator_4(int32, void *); 122 virtual status_t _Reserved_Translator_5(int32, void *); 123 virtual status_t _Reserved_Translator_6(int32, void *); 124 virtual status_t _Reserved_Translator_7(int32, void *); 125 }; 126 127 // The post-4.5 API suggests implementing this function in your translator 128 // add-on rather than the separate functions and variables of the previous 129 // API. You will be called for values of n starting at 0 and increasing; 130 // return 0 when you can't make another kind of translator (i.e. for n=1 131 // if you only implement one subclass of BTranslator). Ignore flags for now. 132 extern "C" _EXPORT BTranslator *make_nth_translator(int32 n, image_id you, 133 uint32 flags, ...); 134 135 136 137 #endif /* _TRANSLATOR_H */ 138