1*f90e4543SAxel Dörfler /* 2*f90e4543SAxel Dörfler * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. 3*f90e4543SAxel Dörfler * Distributed under the terms of the MIT License. 4*f90e4543SAxel Dörfler * 5*f90e4543SAxel Dörfler * Authors: 6*f90e4543SAxel Dörfler * Michael Wilber 7*f90e4543SAxel Dörfler * Axel Dörfler, axeld@pinc-software.de 8*f90e4543SAxel Dörfler */ 927aa9660SMatthew Wilber 10*f90e4543SAxel Dörfler /*! 11*f90e4543SAxel Dörfler This file contains the BTranslator based object for 12*f90e4543SAxel Dörfler function based translators, aka, the translators 13*f90e4543SAxel Dörfler that don't use the make_nth_translator() mechanism. 1427aa9660SMatthew Wilber 15*f90e4543SAxel Dörfler This class is used by the BTranslatorRoster class 16*f90e4543SAxel Dörfler so that function based translators, make_nth_translator() 17*f90e4543SAxel Dörfler translators and private BTranslator objects could be 18*f90e4543SAxel Dörfler accessed in the same way. 19*f90e4543SAxel Dörfler */ 20*f90e4543SAxel Dörfler 21*f90e4543SAxel Dörfler 22*f90e4543SAxel Dörfler #include "FuncTranslator.h" 23*f90e4543SAxel Dörfler 24*f90e4543SAxel Dörfler 25*f90e4543SAxel Dörfler namespace BPrivate { 26*f90e4543SAxel Dörfler 27*f90e4543SAxel Dörfler BFuncTranslator::BFuncTranslator(const translator_data& data) 2827aa9660SMatthew Wilber { 29*f90e4543SAxel Dörfler memcpy(&fData, &data, sizeof(translator_data)); 3027aa9660SMatthew Wilber } 3127aa9660SMatthew Wilber 32*f90e4543SAxel Dörfler 3327aa9660SMatthew Wilber BFuncTranslator::~BFuncTranslator() 3427aa9660SMatthew Wilber { 3527aa9660SMatthew Wilber } 3627aa9660SMatthew Wilber 37*f90e4543SAxel Dörfler 38*f90e4543SAxel Dörfler const char * 39*f90e4543SAxel Dörfler BFuncTranslator::TranslatorName() const 4027aa9660SMatthew Wilber { 41*f90e4543SAxel Dörfler return fData.name; 42*f90e4543SAxel Dörfler } 43*f90e4543SAxel Dörfler 44*f90e4543SAxel Dörfler 45*f90e4543SAxel Dörfler const char * 46*f90e4543SAxel Dörfler BFuncTranslator::TranslatorInfo() const 47*f90e4543SAxel Dörfler { 48*f90e4543SAxel Dörfler return fData.info; 49*f90e4543SAxel Dörfler } 50*f90e4543SAxel Dörfler 51*f90e4543SAxel Dörfler 52*f90e4543SAxel Dörfler int32 53*f90e4543SAxel Dörfler BFuncTranslator::TranslatorVersion() const 54*f90e4543SAxel Dörfler { 55*f90e4543SAxel Dörfler return fData.version; 56*f90e4543SAxel Dörfler } 57*f90e4543SAxel Dörfler 58*f90e4543SAxel Dörfler 59*f90e4543SAxel Dörfler const translation_format * 60*f90e4543SAxel Dörfler BFuncTranslator::InputFormats(int32* _count) const 61*f90e4543SAxel Dörfler { 62*f90e4543SAxel Dörfler if (_count == NULL || fData.input_formats == NULL) 6327aa9660SMatthew Wilber return NULL; 64*f90e4543SAxel Dörfler 65*f90e4543SAxel Dörfler int32 count = 0; 66*f90e4543SAxel Dörfler while (fData.input_formats[count].type) { 67*f90e4543SAxel Dörfler count++; 6827aa9660SMatthew Wilber } 6927aa9660SMatthew Wilber 70*f90e4543SAxel Dörfler *_count = count; 71*f90e4543SAxel Dörfler return fData.input_formats; 72*f90e4543SAxel Dörfler } 73*f90e4543SAxel Dörfler 74*f90e4543SAxel Dörfler 75*f90e4543SAxel Dörfler const translation_format * 76*f90e4543SAxel Dörfler BFuncTranslator::OutputFormats(int32* _count) const 7727aa9660SMatthew Wilber { 78*f90e4543SAxel Dörfler if (_count == NULL || fData.output_formats == NULL) 7927aa9660SMatthew Wilber return NULL; 80*f90e4543SAxel Dörfler 81*f90e4543SAxel Dörfler int32 count = 0; 82*f90e4543SAxel Dörfler while (fData.output_formats[count].type) { 83*f90e4543SAxel Dörfler count++; 8427aa9660SMatthew Wilber } 8527aa9660SMatthew Wilber 86*f90e4543SAxel Dörfler *_count = count; 87*f90e4543SAxel Dörfler return fData.output_formats; 88*f90e4543SAxel Dörfler } 89*f90e4543SAxel Dörfler 90*f90e4543SAxel Dörfler 91*f90e4543SAxel Dörfler status_t 92*f90e4543SAxel Dörfler BFuncTranslator::Identify(BPositionIO* source, const translation_format* format, 93*f90e4543SAxel Dörfler BMessage* ioExtension, translator_info* info, uint32 type) 9427aa9660SMatthew Wilber { 95*f90e4543SAxel Dörfler if (fData.identify_hook == NULL) 9627aa9660SMatthew Wilber return B_ERROR; 97*f90e4543SAxel Dörfler 98*f90e4543SAxel Dörfler return fData.identify_hook(source, format, ioExtension, info, type); 9927aa9660SMatthew Wilber } 10027aa9660SMatthew Wilber 101*f90e4543SAxel Dörfler 102*f90e4543SAxel Dörfler status_t 103*f90e4543SAxel Dörfler BFuncTranslator::Translate(BPositionIO* source, const translator_info *info, 104*f90e4543SAxel Dörfler BMessage* ioExtension, uint32 type, BPositionIO* destination) 10527aa9660SMatthew Wilber { 106*f90e4543SAxel Dörfler if (fData.translate_hook == NULL) 10727aa9660SMatthew Wilber return B_ERROR; 108*f90e4543SAxel Dörfler 109*f90e4543SAxel Dörfler return fData.translate_hook(source, info, ioExtension, type, destination); 11027aa9660SMatthew Wilber } 11127aa9660SMatthew Wilber 112*f90e4543SAxel Dörfler 113*f90e4543SAxel Dörfler status_t 114*f90e4543SAxel Dörfler BFuncTranslator::MakeConfigurationView(BMessage* ioExtension, 115*f90e4543SAxel Dörfler BView** _view, BRect* _extent) 11627aa9660SMatthew Wilber { 117*f90e4543SAxel Dörfler if (fData.make_config_hook == NULL) 11827aa9660SMatthew Wilber return B_ERROR; 119*f90e4543SAxel Dörfler 120*f90e4543SAxel Dörfler return fData.make_config_hook(ioExtension, _view, _extent); 12127aa9660SMatthew Wilber } 12227aa9660SMatthew Wilber 123*f90e4543SAxel Dörfler 124*f90e4543SAxel Dörfler status_t 125*f90e4543SAxel Dörfler BFuncTranslator::GetConfigurationMessage(BMessage* ioExtension) 12627aa9660SMatthew Wilber { 127*f90e4543SAxel Dörfler if (fData.get_config_message_hook == NULL) 12827aa9660SMatthew Wilber return B_ERROR; 129*f90e4543SAxel Dörfler 130*f90e4543SAxel Dörfler return fData.get_config_message_hook(ioExtension); 13127aa9660SMatthew Wilber } 13227aa9660SMatthew Wilber 133*f90e4543SAxel Dörfler } // namespace BPrivate 134