* More or less rewrote BTranslatorRoster - it now has a private implementation

class, and only wraps around that one.
* Translating is no longer serialized, you can translate more than one object
  at a time now.
* A BTranslator that is released (ie. deleted) will no longer let its BTranslatorRoster
  crash.
* Removed BTranslatorRoster::Version() - this kind of call definitely makes no
  sense at all. It's still exported from the sources, though, for backwards
  compatibility.
* Simplified and improved code.
* Images are now unloaded only once.
* Added new method IsTranslator() that will be used by the DataTranslations preferences
  application.
* Began implementing new methods StartWatching()/StopWatching() that will notify
  you if new translators are installed or old ones removed (this will also be used
  by DataTranslations once it's ready).
* The private BTranslatorRoster class will now add itself to the existing BApplication,
  in order to provide automatic updating of the translators if needed (not yet implemented
  though).
* Not heavily tested yet, there might be some regressions.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17247 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-04-27 18:40:28 +00:00
parent 11add5a5d7
commit f90e454336
9 changed files with 1559 additions and 2768 deletions
+49 -111
View File
@@ -1,127 +1,67 @@
/*****************************************************************************/ /*
// File: Translator.h * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// Class: BTranslator * Distributed under the terms of the MIT License.
// Reimplemented by: Michael Wilber, Translation Kit Team */
// Reimplementation: 2002-06-15
//
// Description: This file contains the BTranslator class, the base class for
// all translators that don't use the BeOS R4/R4.5 add-on method.
//
//
// Copyright (c) 2002 OpenBeOS Project
//
// Original Version: Copyright 1998, Be Incorporated, All Rights Reserved.
// Copyright 1995-1997, Jon Watte
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#ifndef _TRANSLATOR_H #ifndef _TRANSLATOR_H
#define _TRANSLATOR_H #define _TRANSLATOR_H
#include <TranslationDefs.h>
#include <Archivable.h> #include <Archivable.h>
#include <TranslationDefs.h>
#include <TranslatorRoster.h>
class BTranslator : public BArchivable { class BTranslator : public BArchivable {
public: public:
BTranslator(); BTranslator();
// Sets refcount to 1 (the object is initially Acquired()'d once)
BTranslator *Acquire(); BTranslator* Acquire();
// return actual object and increment the refcount BTranslator* Release();
BTranslator *Release();
// Decrements the refcount and returns pointer to the object.
// When the refcount is zero, NULL is returned and the object is
// deleted
int32 ReferenceCount();
// returns the refcount, THIS IS NOT THREAD SAFE, ITS ONLY FOR "FUN"
virtual const char *TranslatorName() const = 0; int32 ReferenceCount();
// returns the short name of the translator // returns the refcount, THIS IS NOT THREAD SAFE, ITS ONLY FOR "FUN"
virtual const char *TranslatorInfo() const = 0;
// returns a verbose name/description for the translator
virtual int32 TranslatorVersion() const = 0;
// returns the version of the translator
virtual const translation_format *InputFormats(int32 *out_count) virtual const char *TranslatorName() const = 0;
const = 0; virtual const char *TranslatorInfo() const = 0;
// returns the input formats and the count of input formats virtual int32 TranslatorVersion() const = 0;
// that this translator supports
virtual const translation_format *OutputFormats(int32 *out_count)
const = 0;
// returns the output formats and the count of output formats
// that this translator supports
virtual status_t Identify(BPositionIO *inSource, virtual const translation_format *InputFormats(int32 *out_count)
const translation_format *inFormat, BMessage *ioExtension, const = 0;
translator_info *outInfo, uint32 outType) = 0; virtual const translation_format *OutputFormats(int32 *out_count)
// determines whether or not this translator can convert the const = 0;
// data in inSource to the type outType virtual status_t Identify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType) = 0;
virtual status_t Translate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension,
uint32 outType, BPositionIO *outDestination) = 0;
virtual status_t MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent);
virtual status_t GetConfigurationMessage(BMessage *ioExtension);
virtual status_t Translate(BPositionIO *inSource, protected:
const translator_info *inInfo, BMessage *ioExtension, virtual ~BTranslator();
uint32 outType, BPositionIO *outDestination) = 0; // this is protected because the object is deleted by the
// this function is the whole point of the Translation Kit, // Release() function instead of being deleted directly by
// it translates the data in inSource to outDestination // the user
// using the format outType
virtual status_t MakeConfigurationView(BMessage *ioExtension, private:
BView **outView, BRect *outExtent); friend class BTranslatorRoster::Private;
// this function creates a view that allows the user to
// configure the translator, this function is not
// required for all translators
virtual status_t GetConfigurationMessage(BMessage *ioExtension); virtual status_t _Reserved_Translator_0(int32, void *);
// puts information about the current configuration of the virtual status_t _Reserved_Translator_1(int32, void *);
// translator into ioExtension so that it can be used with virtual status_t _Reserved_Translator_2(int32, void *);
// Identify or Translate or whatever, this function is virtual status_t _Reserved_Translator_3(int32, void *);
// not required for all translators virtual status_t _Reserved_Translator_4(int32, void *);
virtual status_t _Reserved_Translator_5(int32, void *);
virtual status_t _Reserved_Translator_6(int32, void *);
virtual status_t _Reserved_Translator_7(int32, void *);
protected: BTranslatorRoster::Private* fOwningRoster;
virtual ~BTranslator(); translator_id fID;
// this is protected because the object is deleted by the int32 fRefCount;
// Release() function instead of being deleted directly by
// the user
private: uint32 _reserved[7];
int32 fRefCount;
// number of times this object has been referenced
// by the Acquire() function
sem_id fSem;
// used to lock object for Acquire() and Release()
// For binary compatibility with past and future
// version of this class
uint32 fUnused[8];
virtual status_t _Reserved_Translator_0(int32, void *);
virtual status_t _Reserved_Translator_1(int32, void *);
virtual status_t _Reserved_Translator_2(int32, void *);
virtual status_t _Reserved_Translator_3(int32, void *);
virtual status_t _Reserved_Translator_4(int32, void *);
virtual status_t _Reserved_Translator_5(int32, void *);
virtual status_t _Reserved_Translator_6(int32, void *);
virtual status_t _Reserved_Translator_7(int32, void *);
}; };
// The post-4.5 API suggests implementing this function in your translator // The post-4.5 API suggests implementing this function in your translator
@@ -132,6 +72,4 @@ private:
extern "C" _EXPORT BTranslator *make_nth_translator(int32 n, image_id you, extern "C" _EXPORT BTranslator *make_nth_translator(int32 n, image_id you,
uint32 flags, ...); uint32 flags, ...);
#endif /* _TRANSLATOR_H */ #endif /* _TRANSLATOR_H */
+60 -200
View File
@@ -1,63 +1,13 @@
/*****************************************************************************/ /*
// File: TranslatorRoster.h * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// Class: BTranslatorRoster * Distributed under the terms of the MIT License.
// Reimplemented by: Michael Wilber, Translation Kit Team */
// Reimplementation: 2002-06-11
//
// Description: This class is the guts of the translation kit, it makes the
// whole thing happen. It bridges the applications using this
// object with the translators that the apps need to access.
//
//
// Copyright (c) 2002 OpenBeOS Project
//
// Original Version: Copyright 1998, Be Incorporated, All Rights Reserved.
// Copyright 1995-1997, Jon Watte
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#ifndef _TRANSLATOR_ROSTER_H #ifndef _TRANSLATOR_ROSTER_H
#define _TRANSLATOR_ROSTER_H #define _TRANSLATOR_ROSTER_H
#include <TranslationDefs.h>
#include <OS.h>
#include <StorageDefs.h>
#include <InterfaceDefs.h>
#include <Archivable.h> #include <Archivable.h>
#include <TranslatorFormats.h>
#include <TranslationDefs.h> #include <TranslationDefs.h>
#include <TranslationErrors.h>
#include <Translator.h>
#include <String.h>
#include <image.h>
#include <File.h>
#include <Directory.h>
#include <Volume.h>
#include <string.h>
#include <OS.h>
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <alloca.h>
struct translation_format; struct translation_format;
@@ -67,174 +17,84 @@ class BPositionIO;
class BQuery; class BQuery;
class BMessage; class BMessage;
const char kgDefaultTranslatorPath[] = "/boot/home/config/add-ons/Translators:/boot/home/config/add-ons/Datatypes:/system/add-ons/Translators";
// used by BTranslatorRoster to store the list of translators
struct translator_node {
BTranslator *translator;
char *path;
image_id image;
translator_id id;
translator_node *next;
};
class BTranslatorRoster : public BArchivable { class BTranslatorRoster : public BArchivable {
// private, unimplemented functions public:
// (I'm not sure if there is a need for them anyway) BTranslatorRoster();
BTranslatorRoster(const BTranslatorRoster &); BTranslatorRoster(BMessage* model);
BTranslatorRoster & operator=(const BTranslatorRoster &); virtual ~BTranslatorRoster();
public: static BTranslatorRoster *Default();
BTranslatorRoster();
// initializes the object with no translators
BTranslatorRoster(BMessage *model);
// initializes the object and loads all translators from the
// "be:translator_path" string array in model
~BTranslatorRoster();
// frees memory used by this object
virtual status_t Archive(BMessage *into, bool deep = true) const; virtual status_t Archive(BMessage* into, bool deep = true) const;
// store the BTranslatorRoster in into so it can later be static BArchivable* Instantiate(BMessage* from);
// used with Instantiate or the BMessage constructor
static BArchivable *Instantiate(BMessage *from);
// creates a BTranslatorRoster object from the from archive
static const char *Version(int32 *outCurVersion, int32 *outMinVersion, status_t AddTranslators(const char* loadPath = NULL);
int32 inAppVersion = B_TRANSLATION_CURRENT_VERSION); status_t AddTranslator(BTranslator* translator);
// returns the version of BTranslator roster as a string
// and through the int32 pointers; inAppVersion appears
// to be ignored
static BTranslatorRoster *Default(); virtual status_t Identify(BPositionIO* source, BMessage* ioExtension,
// returns the "default" set of translators, they are translators translator_info* _info, uint32 hintType = 0,
// that are loaded from the default paths const char* hintMIME = NULL, uint32 wantType = 0);
// /boot/home/config/add-ons/Translators,
// /boot/home/config/add-ons/Datatypes,
// /system/add-ons/Translators or the paths in the
// TRANSLATORS environment variable, if it exists
status_t AddTranslators(const char *load_path = NULL); virtual status_t GetTranslators(BPositionIO* source,
// this adds a translator, all of the translators in a folder or BMessage* ioExtension, translator_info** _info, int32* _numInfo,
// the default translators if the path is NULL uint32 hintType = 0, const char* hintMIME = NULL,
uint32 wantType = 0);
status_t AddTranslator(BTranslator * translator); virtual status_t GetAllTranslators(translator_id** _list,
// adds a translator that you've created yourself to the int32* _count);
// BTranslatorRoster; this is useful if you have translators
// that you don't want to make public or don't want loaded as
// an add-on
virtual status_t Identify(BPositionIO *inSource, BMessage *ioExtension, virtual status_t GetTranslatorInfo(translator_id translatorID,
translator_info *outInfo, uint32 inHintType = 0, const char** _name, const char** _info, int32* _version);
const char *inHintMIME = NULL, uint32 inWantType = 0);
// identifies the translator that can handle the data in inSource
virtual status_t GetTranslators(BPositionIO *inSource, virtual status_t GetInputFormats(translator_id translatorID,
BMessage *ioExtension, translator_info **outInfo, int32 *outNumInfo, const translation_format** _formats, int32* _numFormats);
uint32 inHintType = 0, const char *inHintMIME = NULL,
uint32 inWantType = 0);
// finds all translators for the given type
virtual status_t GetAllTranslators(translator_id **outList, virtual status_t GetOutputFormats(translator_id translatorID,
int32 *outCount); const translation_format** _formats, int32* _numFormats);
// returns all translators that this object contains
virtual status_t GetTranslatorInfo(translator_id forTranslator, virtual status_t Translate(BPositionIO* source,
const char **outName, const char **outInfo, int32 *outVersion); const translator_info* info, BMessage* ioExtension,
// gets user visible info about a specific translator BPositionIO* destination, uint32 wantOutType,
uint32 hintType = 0, const char* hintMIME = NULL);
virtual status_t GetInputFormats(translator_id forTranslator, virtual status_t Translate(translator_id translatorID,
const translation_format **outFormats, int32 *outNumFormats); BPositionIO* source, BMessage* ioExtension,
// finds all input formats for a translator; BPositionIO* destination, uint32 wantOutType);
// note that translators don't always publish the formats
// that they support
virtual status_t GetOutputFormats(translator_id forTranslator, virtual status_t MakeConfigurationView(translator_id translatorID,
const translation_format **outFormats, int32 *outNumFormats); BMessage* ioExtension, BView** _view, BRect* _extent);
// finds all output formats for a translator;
// note that translators don't always publish the formats
// that they support
virtual status_t Translate(BPositionIO *inSource, virtual status_t GetConfigurationMessage(translator_id translatorID,
const translator_info *inInfo, BMessage *ioExtension, BMessage* ioExtension);
BPositionIO *outDestination, uint32 inWantOutType,
uint32 inHintType = 0, const char *inHintMIME = NULL);
// the whole point of this entire kit boils down to this function;
// this translates the data in inSource into outDestination
// using the format inWantOutType
virtual status_t Translate(translator_id inTranslator, status_t GetRefFor(translator_id translatorID, entry_ref* ref);
BPositionIO *inSource, BMessage *ioExtension, bool IsTranslator(entry_ref* ref);
BPositionIO *outDestination, uint32 inWantOutType);
// the whole point of this entire kit boils down to this function;
// this translates the data in inSource into outDestination
// using the format inWantOutType and the translator inTranslator
virtual status_t MakeConfigurationView(translator_id forTranslator, status_t StartWatching(BMessenger target);
BMessage *ioExtension, BView **outView, BRect *outExtent); status_t StopWatching(BMessenger target);
// create the view for forTranslator that allows the user
// to configure it;
// NOTE: translators are not required to support this function
virtual status_t GetConfigurationMessage(translator_id forTranslator, private:
BMessage *ioExtension); // unimplemented
// this is used to save the settings for a translator so that BTranslatorRoster(const BTranslatorRoster& other);
// they can be written to disk or used in an Indentify or BTranslatorRoster& operator=(const BTranslatorRoster& other);
// Translate call
status_t GetRefFor(translator_id translator, entry_ref *out_ref); virtual void ReservedTranslatorRoster1();
// I'm guessing that this returns the entry_ref for the virtual void ReservedTranslatorRoster2();
// translator add-on file for the translator_id translator virtual void ReservedTranslatorRoster3();
virtual void ReservedTranslatorRoster4();
virtual void ReservedTranslatorRoster5();
virtual void ReservedTranslatorRoster6();
private: void _Initialize();
void Initialize();
// class initialization code used by all constructors
translator_node *FindTranslatorNode(translator_id id);
// used to find the translator_node for the translator_id id
// returns NULL if the id is not valid
status_t LoadTranslator(const char *path); private:
// loads the translator add-on specified by path class Private;
void LoadDir(const char *path, int32 &loadErr, int32 &nLoaded);
// loads all of the translator add-ons from path and
// returns error status in loadErr and the number of
// translators loaded in nLoaded
bool CheckFormats(const translation_format *inputFormats,
int32 inputFormatsCount, uint32 hintType, const char *hintMIME,
const translation_format **outFormat);
// determines how the Identify function is called
// adds the translator to the list of translators Private* fPrivate;
// that this object maintains int32 fUnused[6];
status_t AddTranslatorToList(BTranslator *translator);
status_t AddTranslatorToList(BTranslator *translator,
const char *path, image_id image, bool acquire);
static BTranslatorRoster *fspDefaultTranslators; static BTranslatorRoster* sDefaultRoster;
// object that contains the default translators
// list of translators maintained by this object
translator_node *fpTranslators;
translator_node *fpLastTranslator;
sem_id fSem;
// semaphore used to lock this object
// used to maintain binary combatibility with
// past and future versions of this object
int32 fUnused[4];
virtual void ReservedTranslatorRoster1();
virtual void ReservedTranslatorRoster2();
virtual void ReservedTranslatorRoster3();
virtual void ReservedTranslatorRoster4();
virtual void ReservedTranslatorRoster5();
virtual void ReservedTranslatorRoster6();
}; };
#endif /* _TRANSLATOR_ROSTER_H */ #endif /* _TRANSLATOR_ROSTER_H */
@@ -1,130 +0,0 @@
/*****************************************************************************/
// File: FuncTranslator.h
// Class: BFuncTranslator
// Author: Michael Wilber, Translation Kit Team
// Originally Created: 2002-06-11
//
// Description:
// This header file contains the BTranslator based object for
// function based translators, i.e. the translators which export
// each translator function individually, instead of exporting
// the make_nth_translator() function, which returns the
// translator as a class derived from BTranslator.
//
// All of the BeOS R5 translators are function based translators.
// All of the Gobe Productive translators are function based
// translators. Nearly all of the translators I've found, with
// the exception of the Haiku translators, are function based.
//
// This class is used by the OpenBeOS BTranslatorRoster
// so that function based translators, make_nth_translator()
// translators and private BTranslator objects could be
// accessed in the same way.
//
//
// Copyright (c) 2002 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#ifndef _FUNC_TRANSLATOR_H
#define _FUNC_TRANSLATOR_H
#include <Translator.h>
#include <image.h>
#include <TranslationDefs.h>
// Structure used to hold the collection of function pointers and
// public variables exported by function based translator add-ons.
struct translator_data {
const char *translatorName;
const char *translatorInfo;
int32 translatorVersion;
const translation_format *inputFormats;
const translation_format *outputFormats;
status_t (*Identify)(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType);
status_t (*Translate)(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension,
uint32 outType, BPositionIO *outDestination);
status_t (*MakeConfig)(BMessage *ioExtension,
BView **outView, BRect *outExtent);
status_t (*GetConfigMessage)(BMessage *ioExtension);
};
class BFuncTranslator : public BTranslator {
public:
BFuncTranslator(const translator_data *kpData);
// assigns the translator to the object
virtual const char *TranslatorName() const;
// returns the short translator name
virtual const char *TranslatorInfo() const;
// returns the verbose translator name/description
virtual int32 TranslatorVersion() const;
// returns the translator's version
virtual const translation_format *InputFormats(int32 *out_count) const;
// returns the list of supported input formats
virtual const translation_format *OutputFormats(int32 *out_count) const;
// returns the list of supported output formats
virtual status_t Identify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType);
// identifies wether or not the translator can handle
// translating the data in inSource
virtual status_t Translate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
BPositionIO * outDestination);
// translates the data from inSource to outDestination
// in the format outType
virtual status_t MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent);
// creates a view object that allows the user to change
// the translator's options
// (not required to be in all translators)
virtual status_t GetConfigurationMessage(BMessage *ioExtension);
// returns the current settings of the translator
// (not required to be in all translators)
protected:
virtual ~BFuncTranslator();
// This object is deleted by calling Release(),
// it can not be deleted directly. See BTranslator in the Be Book
private:
translator_data *fpData;
// This contains all of the member variables used by this class.
// It also contains pointers to functions that the member functions
// use to do all of the actual work for this class.
};
#endif // _FUNC_TRANSLATOR_H
+90 -322
View File
@@ -1,365 +1,133 @@
/*****************************************************************************/ /*
// File: FuncTranslator.cpp * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// Class: BFuncTranslator * Distributed under the terms of the MIT License.
// Author: Michael Wilber, Translation Kit Team *
// Originally Created: 2002-06-11 * Authors:
// * Michael Wilber
// Description: This file contains the BTranslator based object for * Axel Dörfler, [email protected]
// function based translators, aka, the translators */
// that don't use the make_nth_translator() mechanism.
//
// This class is used by the OpenBeOS BTranslatorRoster
// so that function based translators, make_nth_translator()
// translators and private BTranslator objects could be
// accessed in the same way.
//
//
// Copyright (c) 2002 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#include <FuncTranslator.h> /*!
This file contains the BTranslator based object for
function based translators, aka, the translators
that don't use the make_nth_translator() mechanism.
// --------------------------------------------------------------- This class is used by the BTranslatorRoster class
// Constructor so that function based translators, make_nth_translator()
// translators and private BTranslator objects could be
// Initializes class data. accessed in the same way.
// */
// Preconditions:
//
// Parameters: kpData, data and function pointers that do all of #include "FuncTranslator.h"
// the useful work for this class
//
// Postconditions: If kpData is freed before the BFuncTranslator, namespace BPrivate {
// the BFuncTranslator will fail to work and
// could the computer to crash. kpData may point BFuncTranslator::BFuncTranslator(const translator_data& data)
// to a translator add-on image, this image
// should not be unloaded before the
// BFuncTranslator is freed.
//
//
// Returns:
// ---------------------------------------------------------------
BFuncTranslator::BFuncTranslator(const translator_data *kpData) : BTranslator()
{ {
fpData = new translator_data; memcpy(&fData, &data, sizeof(translator_data));
if (fpData) {
fpData->translatorName = kpData->translatorName;
fpData->translatorInfo = kpData->translatorInfo;
fpData->translatorVersion = kpData->translatorVersion;
fpData->inputFormats = kpData->inputFormats;
fpData->outputFormats = kpData->outputFormats;
fpData->Identify = kpData->Identify;
fpData->Translate = kpData->Translate;
fpData->MakeConfig = kpData->MakeConfig;
fpData->GetConfigMessage = kpData->GetConfigMessage;
}
} }
// ---------------------------------------------------------------
// Destructor
//
// Frees memory used by this object. Note that none of the members
// of the struct have delete used on them, this is because most
// are const pointers and the one that isn't is a regular int32.
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
BFuncTranslator::~BFuncTranslator() BFuncTranslator::~BFuncTranslator()
{ {
delete fpData;
fpData = NULL;
} }
// ---------------------------------------------------------------
// TranslatorName const char *
// BFuncTranslator::TranslatorName() const
// Returns a short name for the translator that this object stores
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns: NULL if fpData was not allocated successfully,
// or the short name of the translator otherwise
// ---------------------------------------------------------------
const char *BFuncTranslator::TranslatorName() const
{ {
if (fpData) return fData.name;
return fpData->translatorName;
else
return NULL;
} }
// ---------------------------------------------------------------
// TranslatorInfo const char *
// BFuncTranslator::TranslatorInfo() const
// Returns a verbose name/description for the translator that this
// object stores
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns: NULL if fpData was not allocated successfully,
// or the verbose name of the translator otherwise
// ---------------------------------------------------------------
const char *BFuncTranslator::TranslatorInfo() const
{ {
if (fpData) return fData.info;
return fpData->translatorInfo;
else
return NULL;
} }
// ---------------------------------------------------------------
// TranslatorVersion int32
// BFuncTranslator::TranslatorVersion() const
// Returns the version number for this translator
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns: B_ERROR if fpData was not allocated successfully,
// or the integer representation of the translator
// version otherwise
// ---------------------------------------------------------------
int32 BFuncTranslator::TranslatorVersion() const
{ {
if (fpData) return fData.version;
return fpData->translatorVersion;
else
return B_ERROR;
} }
// ---------------------------------------------------------------
// InputFormats const translation_format *
// BFuncTranslator::InputFormats(int32* _count) const
// Returns the list of supported input formats and the count
// of supported input formats
//
// Preconditions:
//
// Parameters: out_count, the number of input formats is stored
// here after the function completes
//
// Postconditions:
//
// Returns: NULL if out_count is NULL,
// NULL if fpData is not allocated,
// or the list of supported input formats if all is well
// ---------------------------------------------------------------
const translation_format *BFuncTranslator::InputFormats(int32 *out_count) const
{ {
if (!out_count) if (_count == NULL || fData.input_formats == NULL)
return NULL;
if (fpData && fpData->inputFormats != NULL) {
int32 i;
for (i = 0; fpData->inputFormats[i].type; i++);
*out_count = i;
return fpData->inputFormats;
} else {
*out_count = 0;
return NULL; return NULL;
int32 count = 0;
while (fData.input_formats[count].type) {
count++;
} }
*_count = count;
return fData.input_formats;
} }
// ---------------------------------------------------------------
// OutputFormats const translation_format *
// BFuncTranslator::OutputFormats(int32* _count) const
// Returns the list of supported output formats
//
// Preconditions:
//
// Parameters: out_count, the number of output formats is stored
// here after the function completes
//
// Postconditions:
//
// Returns: NULL if out_count is NULL,
// NULL if fpData is not allocated,
// or the list of supported output formats if all is well
// ---------------------------------------------------------------
const translation_format *BFuncTranslator::OutputFormats(int32 *out_count) const
{ {
if (!out_count) if (_count == NULL || fData.output_formats == NULL)
return NULL;
if (fpData && fpData->outputFormats != NULL) {
int32 i;
for (i = 0; fpData->outputFormats[i].type; i++);
*out_count = i;
return fpData->outputFormats;
} else {
*out_count = 0;
return NULL; return NULL;
int32 count = 0;
while (fData.output_formats[count].type) {
count++;
} }
*_count = count;
return fData.output_formats;
} }
// ---------------------------------------------------------------
// Identify status_t
// BFuncTranslator::Identify(BPositionIO* source, const translation_format* format,
// If the translator understands how to convert the data contained BMessage* ioExtension, translator_info* info, uint32 type)
// in inSource to media type outType, it fills outInfo with
// details about the input format and return B_OK. If it doesn't
// know how to translate the data, it returns B_NO_TRANSLATOR.
//
// The actual work for this function is done by the translator
// add-on at the other end of the Identify function pointer.
// So, there's no telling the actual behavior of this function
// it depends on the translator add-on.
//
// Preconditions:
//
// Parameters: inSource, the data that wants to be converted
// inFormat, (can be null) hint about the data in
// inSource
// ioExtension, (can be null) contains additional
// information for the translator
// add-on
// outInfo, information about the capabilities
// of this translator
// outType, the output type
//
//
// Postconditions:
//
// Returns: B_OK if this translator can handle the data,
// B_ERROR, if fpData is unallocated or something else
// went wrong
// B_NO_TRANSLATOR if it can't
// ---------------------------------------------------------------
status_t BFuncTranslator::Identify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType)
{ {
if (fpData && fpData->Identify) if (fData.identify_hook == NULL)
return fpData->Identify(inSource, inFormat, ioExtension, outInfo,
outType);
else
return B_ERROR; return B_ERROR;
return fData.identify_hook(source, format, ioExtension, info, type);
} }
// ---------------------------------------------------------------
// Translate status_t
// BFuncTranslator::Translate(BPositionIO* source, const translator_info *info,
// The translator translates data from inSource to format outType, BMessage* ioExtension, uint32 type, BPositionIO* destination)
// writing the output to outDestination.
//
// The actual work for this function is done by the translator
// add-on at the other end of the Translate function pointer.
// So, there's no telling the actual behavior of this function
// it depends on the translator add-on.
//
// Preconditions:
//
// Parameters: inSource, data to be translated
// inInfo, hint about the data in inSource
// ioExtension, contains configuration information
// outType, the format to translate the data to
// outDestination, where the source is translated to
//
// Postconditions:
//
// Returns: B_OK, if it converted the data
// B_NO_TRANSLATOR, if it couldn't
// B_ERROR, if fpData is unallocated or something else
// went wrong
// some other value, if it feels like it
// ---------------------------------------------------------------
status_t BFuncTranslator::Translate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
BPositionIO *outDestination)
{ {
if (fpData && fpData->Translate) if (fData.translate_hook == NULL)
return fpData->Translate(inSource, inInfo, ioExtension, outType,
outDestination);
else
return B_ERROR; return B_ERROR;
return fData.translate_hook(source, info, ioExtension, type, destination);
} }
// ---------------------------------------------------------------
// MakeConfigurationView status_t
// BFuncTranslator::MakeConfigurationView(BMessage* ioExtension,
// This creates a BView object that allows the user to configure BView** _view, BRect* _extent)
// the options for the translator. Not all translators support
// this feature, and for those that don't, this function
// returns B_NO_TRANSLATOR.
//
// Preconditions:
//
// Parameters: ioExtension, the settings for the translator
// outView, the view created by the translator
// outExtent, the bounds of the view
//
// Postconditions:
//
// Returns: B_ERROR, if this function is not supported
// anything else, whatever the translator feels like
// returning
// ---------------------------------------------------------------
status_t BFuncTranslator::MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent)
{ {
if (fpData && fpData->MakeConfig) if (fData.make_config_hook == NULL)
return fpData->MakeConfig(ioExtension, outView, outExtent);
else
return B_ERROR; return B_ERROR;
return fData.make_config_hook(ioExtension, _view, _extent);
} }
// ---------------------------------------------------------------
// GetConfigurationMessage status_t
// BFuncTranslator::GetConfigurationMessage(BMessage* ioExtension)
// This function stores the current configuration for the
// translator into ioExtension. Not all translators
// support this function.
//
// Preconditions:
//
// Parameters: ioExtension, where the configuration is stored
//
// Postconditions:
//
// Returns: B_ERROR, if function is not supported
// something else, if it is
// ---------------------------------------------------------------
status_t BFuncTranslator::GetConfigurationMessage(BMessage *ioExtension)
{ {
if (fpData && fpData->GetConfigMessage) if (fData.get_config_message_hook == NULL)
return fpData->GetConfigMessage(ioExtension); return B_ERROR;
else
return B_ERROR; return fData.get_config_message_hook(ioExtension);
} }
} // namespace BPrivate
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Wilber
* Axel Dörfler, [email protected]
*/
#ifndef _FUNC_TRANSLATOR_H
#define _FUNC_TRANSLATOR_H
#include <Translator.h>
// Structure used to hold the collection of function pointers and
// public variables exported by function based translator add-ons.
struct translator_data {
const char* name;
const char* info;
int32 version;
const translation_format* input_formats;
const translation_format* output_formats;
status_t (*identify_hook)(BPositionIO* source, const translation_format* format,
BMessage* ioExtension, translator_info* outInfo, uint32 outType);
status_t (*translate_hook)(BPositionIO* source, const translator_info* info,
BMessage* ioExtension, uint32 outType, BPositionIO* destination);
status_t (*make_config_hook)(BMessage* ioExtension, BView** _view, BRect* _extent);
status_t (*get_config_message_hook)(BMessage* ioExtension);
};
namespace BPrivate {
class BFuncTranslator : public BTranslator {
public:
BFuncTranslator(const translator_data& data);
virtual const char *TranslatorName() const;
virtual const char *TranslatorInfo() const;
virtual int32 TranslatorVersion() const;
virtual const translation_format *InputFormats(int32 *out_count) const;
virtual const translation_format *OutputFormats(int32 *out_count) const;
virtual status_t Identify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType);
virtual status_t Translate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
BPositionIO * outDestination);
virtual status_t MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent);
virtual status_t GetConfigurationMessage(BMessage *ioExtension);
protected:
virtual ~BFuncTranslator();
// This object is deleted by calling Release(),
// it can not be deleted directly. See BTranslator in the Be Book
private:
translator_data fData;
};
} // namespace BPrivate
#endif // _FUNC_TRANSLATOR_H
+2 -2
View File
@@ -15,8 +15,8 @@ SharedLibrary libtranslation.so :
TranslationUtils.cpp TranslationUtils.cpp
Translator.cpp Translator.cpp
TranslatorRoster.cpp TranslatorRoster.cpp
:
be : be
; ;
Package haiku-translationkit-cvs : Package haiku-translationkit-cvs :
+68 -323
View File
@@ -1,356 +1,101 @@
/*****************************************************************************/ /*
// File: Translator.cpp * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// Class: BTranslator * Distributed under the terms of the MIT License.
// Reimplemented by: Michael Wilber, Translation Kit Team *
// Reimplementation: 2002-06-15 * Authors:
// * Michael Wilber
// Description: This file contains the BTranslator class, the base class for * Axel Dörfler, [email protected]
// all translators that don't use the BeOS R4/R4.5 add-on method. */
//
//
// Copyright (c) 2002 OpenBeOS Project #include "TranslatorRosterPrivate.h"
//
// Original Version: Copyright 1998, Be Incorporated, All Rights Reserved.
// Copyright 1995-1997, Jon Watte
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#include <Translator.h> #include <Translator.h>
// Set refcount to 1
// ---------------------------------------------------------------
// Constructor
//
// Sets refcount to 1 and creates a semaphore for locking the
// object.
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
BTranslator::BTranslator() BTranslator::BTranslator()
:
fOwningRoster(NULL),
fID(0),
fRefCount(1)
{ {
fRefCount = 1;
fSem = create_sem(1, "BTranslator Lock");
} }
// ---------------------------------------------------------------
// Destructor
//
// Deletes the semaphore and resets it.
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
BTranslator::~BTranslator() BTranslator::~BTranslator()
{ {
delete_sem(fSem); if (fOwningRoster != NULL)
fSem = 0; fOwningRoster->TranslatorDeleted(fID);
} }
// ---------------------------------------------------------------
// Acquire /*!
// Increments the refcount and returns a pointer to this object.
// Increments the refcount and returns a pointer to this object. */
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns: NULL, if failed to acquire the sempaphore
// pointer to this object if successful
// ---------------------------------------------------------------
BTranslator *BTranslator::Acquire() BTranslator *BTranslator::Acquire()
{ {
if (fSem > 0 && acquire_sem(fSem) == B_OK) { if (atomic_add(&fRefCount, 1) > 0)
fRefCount++;
release_sem(fSem);
return this; return this;
} else
return NULL; return NULL;
} }
// ---------------------------------------------------------------
// Release /*!
// Decrements the refcount and returns a pointer to this object.
// Decrements the refcount and returns a pointer to this object. When the refcount hits zero, the object is destroyed. This is
// When the refcount hits zero, the object is destroyed. This is so multiple objects can own the BTranslator and it won't get
// so multiple objects can own the BTranslator and it won't get deleted until all of them are done with it.
// deleted until all of them are done with it.
// \return NULL, if the object was just deleted
// Preconditions: */
//
// Parameters:
//
// Postconditions:
//
// Returns: NULL, if failed to acquire the sempaphore or the
// object was just deleted
// pointer to this object if successful
// ---------------------------------------------------------------
BTranslator *BTranslator::Release() BTranslator *BTranslator::Release()
{ {
if (fSem > 0 && acquire_sem(fSem) == B_OK) { int32 oldValue = atomic_add(&fRefCount, -1);
fRefCount--; if (oldValue > 0)
if (fRefCount > 0) { return this;
release_sem(fSem);
return this; delete this;
} else { return NULL;
delete this;
return NULL;
}
} else
return NULL;
} }
// ---------------------------------------------------------------
// ReferenceCount int32
// BTranslator::ReferenceCount()
// This function returns the current
// refcount. Notice that it is not thread safe.
// This function is only meant for fun/debugging.
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns: the current refcount
// ---------------------------------------------------------------
int32 BTranslator::ReferenceCount()
{ {
return fRefCount; return fRefCount;
} }
// ---------------------------------------------------------------
// MakeConfigurationView /*!
// This virtual function is for creating a configuration view
// This virtual function is for creating a configuration view for the translator so the user can change its settings.
// for the translator so the user can change its settings. This This method is optional.
// base class version does nothing. Not all BTranslator derived */
// object are required to support this function. status_t
// BTranslator::MakeConfigurationView(BMessage* ioExtension,
// Preconditions: BView** outView, BRect* outExtent)
//
// Parameters: ioExtension, configuration data for the translator
// outView, where the created view is stored
// outText, the bounds of the view are stored here
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent)
{ {
return B_ERROR; return B_ERROR;
} }
// ---------------------------------------------------------------
// GetConfigurationMessage /*!
// Puts the current configuration for the translator into
// Puts the current configuration for the translator into ioExtension. This method is optional.
// ioExtension. Not all translators are required to support */
// this function status_t
// BTranslator::GetConfigurationMessage(BMessage* ioExtension)
// Preconditions:
//
// Parameters: ioExtension, where the configuration data is stored
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::GetConfigurationMessage(BMessage *ioExtension)
{ {
return B_ERROR; return B_ERROR;
} }
// ---------------------------------------------------------------
// _Reserved_Translator_0
//
// It does nothing! :) Its only here for past/future binary
// compatiblity.
//
// Preconditions:
//
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_0(int32 n, void *p)
{
return B_ERROR;
}
// --------------------------------------------------------------- status_t BTranslator::_Reserved_Translator_0(int32 n, void *p) { return B_ERROR; }
// _Reserved_Translator_1 status_t BTranslator::_Reserved_Translator_1(int32 n, void *p) { return B_ERROR; }
// status_t BTranslator::_Reserved_Translator_2(int32 n, void *p) { return B_ERROR; }
// It does nothing! :) Its only here for past/future binary status_t BTranslator::_Reserved_Translator_3(int32 n, void *p) { return B_ERROR; }
// compatiblity. status_t BTranslator::_Reserved_Translator_4(int32 n, void *p) { return B_ERROR; }
// status_t BTranslator::_Reserved_Translator_5(int32 n, void *p) { return B_ERROR; }
// Preconditions: status_t BTranslator::_Reserved_Translator_6(int32 n, void *p) { return B_ERROR; }
// status_t BTranslator::_Reserved_Translator_7(int32 n, void *p) { return B_ERROR; }
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_1(int32 n, void *p)
{
return B_ERROR;
}
// ---------------------------------------------------------------
// _Reserved_Translator_2
//
// It does nothing! :) Its only here for past/future binary
// compatiblity.
//
// Preconditions:
//
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_2(int32 n, void *p)
{
return B_ERROR;
}
// ---------------------------------------------------------------
// _Reserved_Translator_3
//
// It does nothing! :) Its only here for past/future binary
// compatiblity.
//
// Preconditions:
//
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_3(int32 n, void *p)
{
return B_ERROR;
}
// ---------------------------------------------------------------
// _Reserved_Translator_4
//
// It does nothing! :) Its only here for past/future binary
// compatiblity.
//
// Preconditions:
//
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_4(int32 n, void *p)
{
return B_ERROR;
}
// ---------------------------------------------------------------
// _Reserved_Translator_5
//
// It does nothing! :) Its only here for past/future binary
// compatiblity.
//
// Preconditions:
//
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_5(int32 n, void *p)
{
return B_ERROR;
}
// ---------------------------------------------------------------
// _Reserved_Translator_6
//
// It does nothing! :) Its only here for past/future binary
// compatiblity.
//
// Preconditions:
//
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_6(int32 n, void *p)
{
return B_ERROR;
}
// ---------------------------------------------------------------
// _Reserved_Translator_7
//
// It does nothing! :) Its only here for past/future binary
// compatiblity.
//
// Preconditions:
//
// Parameters: n, not used
// p, not used
//
// Postconditions:
//
// Returns: B_ERROR
// ---------------------------------------------------------------
status_t BTranslator::_Reserved_Translator_7(int32 n, void *p)
{
return B_ERROR;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,82 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Axel Dörfler, [email protected]
*/
#ifndef TRANSLATOR_ROSTER_PRIVATE_H
#define TRANSLATOR_ROSTER_PRIVATE_H
#include <Entry.h>
#include <Handler.h>
#include <Locker.h>
#include <Messenger.h>
#include <TranslatorRoster.h>
#include <map>
#include <vector>
struct translator_data;
struct translator_item {
BTranslator* translator;
entry_ref ref;
image_id image;
};
typedef std::map<translator_id, translator_item> TranslatorMap;
typedef std::vector<BMessenger> MessengerList;
class BTranslatorRoster::Private : public BHandler, public BLocker {
public:
Private();
virtual ~Private();
virtual void MessageReceived(BMessage* message);
void AddDefaultPaths();
status_t AddPaths(const char* paths);
status_t AddPath(const char* path, int32* _added = NULL);
status_t AddTranslator(BTranslator* translator, image_id image = -1,
const entry_ref* ref = NULL);
BTranslator* FindTranslator(translator_id id);
status_t StoreTranslators(BMessage& archive);
status_t Identify(BPositionIO* source, BMessage* ioExtension,
uint32 hintType, const char* hintMIME, uint32 wantType,
translator_info* _info);
status_t GetTranslators(BPositionIO* source, BMessage* ioExtension,
uint32 hintType, const char* hintMIME, uint32 wantType,
translator_info** _info, int32* _numInfo);
status_t GetAllTranslators(translator_id** _ids, int32* _count);
status_t GetRefFor(translator_id id, entry_ref& ref);
bool IsActive() const { return Looper(); }
status_t CreateTranslators(const entry_ref& ref, int32& count);
status_t GetTranslatorData(image_id image, translator_data& data);
status_t StartWatching(BMessenger target);
status_t StopWatching(BMessenger target);
void TranslatorDeleted(translator_id id);
private:
static int _CompareSupport(const void* _a, const void* _b);
const translation_format* _CheckHints(const translation_format* formats,
int32 formatsCount, uint32 hintType, const char* hintMIME);
const translator_item* _FindTranslator(translator_id id) const;
const translator_item* _FindTranslator(const char* name) const;
TranslatorMap fTranslators;
MessengerList fMessengers;
int32 fNextID;
};
#endif // TRANSLATOR_ROSTER_PRIVATE_H