* InstalledTypes did not preserve the case of the MIME types, and thus, Tracker queries

for some types (like "application/x-vnd.Be-elfexecutable") would fail. This fixes
  bug #666 (no, I'm not the exorcist :-)).
* Renamed private methods to have the '_' prefix.
* Cleanup, added license.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17832 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-06-14 09:30:55 +00:00
parent 7675c75fa1
commit 1b0c0ad7e9
2 changed files with 256 additions and 232 deletions

View File

@ -1,15 +1,16 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
/*! * Authors:
\file InstalledTypes.h * Tyler Dauwalder
InstalledTypes class declarations * Ingo Weinhold, bonefish@users.sf.net
*/ * Axel Dörfler, axeld@pinc-software.de
*/
#ifndef _MIME_INSTALLED_TYPES_H #ifndef _MIME_INSTALLED_TYPES_H
#define _MIME_INSTALLED_TYPES_H #define _MIME_INSTALLED_TYPES_H
#include <mime/Supertype.h> #include <mime/Supertype.h>
#include <SupportDefs.h> #include <SupportDefs.h>
@ -23,37 +24,39 @@ namespace Storage {
namespace Mime { namespace Mime {
class InstalledTypes { class InstalledTypes {
public: public:
InstalledTypes(); InstalledTypes();
~InstalledTypes(); ~InstalledTypes();
status_t GetInstalledTypes(BMessage *types);
status_t GetInstalledTypes(const char *supertype, BMessage *types);
status_t GetInstalledSupertypes(BMessage *types);
status_t AddType(const char *type); status_t GetInstalledTypes(BMessage *types);
status_t RemoveType(const char *type); status_t GetInstalledTypes(const char *supertype, BMessage *types);
private: status_t GetInstalledSupertypes(BMessage *types);
status_t AddSupertype(const char *super, std::map<std::string, Supertype>::iterator &i);
status_t AddSubtype(const char *super, const char *sub);
status_t AddSubtype(Supertype &super, const char *sub);
status_t RemoveSupertype(const char *super);
status_t RemoveSubtype(const char *super, const char *sub);
void Unset(); status_t AddType(const char *type);
void ClearCachedMessages(); status_t RemoveType(const char *type);
status_t CreateMessageWithTypes(BMessage **result) const; private:
status_t CreateMessageWithSupertypes(BMessage **result) const; status_t _AddSupertype(const char *super,
void FillMessageWithSupertypes(BMessage *msg); std::map<std::string, Supertype>::iterator &i);
status_t _AddSubtype(const char *super, const char *sub);
status_t BuildInstalledTypesList(); status_t _AddSubtype(Supertype &super, const char *sub);
std::map<std::string, Supertype> fSupertypes; status_t _RemoveSupertype(const char *super);
BMessage *fCachedMessage; status_t _RemoveSubtype(const char *super, const char *sub);
BMessage *fCachedSupertypesMessage;
bool fHaveDoneFullBuild; void _Unset();
void _ClearCachedMessages();
status_t _CreateMessageWithTypes(BMessage **result) const;
status_t _CreateMessageWithSupertypes(BMessage **result) const;
void _FillMessageWithSupertypes(BMessage *msg);
status_t _BuildInstalledTypesList();
std::map<std::string, Supertype> fSupertypes;
BMessage *fCachedMessage;
BMessage *fCachedSupertypesMessage;
bool fHaveDoneFullBuild;
}; };
} // namespace Mime } // namespace Mime

View File

@ -1,20 +1,23 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
/*! * Authors:
\file InstalledTypes.cpp * Tyler Dauwalder
InstalledTypes class implementation * Ingo Weinhold, bonefish@users.sf.net
*/ * Axel Dörfler, axeld@pinc-software.de
*/
#include "mime/InstalledTypes.h" #include "mime/InstalledTypes.h"
#include <mime/database_support.h>
#include <storage_support.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <Message.h> #include <Message.h>
#include <MimeType.h> #include <MimeType.h>
#include <mime/database_support.h> #include <String.h>
#include <storage_support.h>
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
@ -32,16 +35,16 @@ namespace Mime {
\brief Installed types information for the entire database \brief Installed types information for the entire database
*/ */
// Constructor
//! Constructs a new InstalledTypes object //! Constructs a new InstalledTypes object
InstalledTypes::InstalledTypes() InstalledTypes::InstalledTypes()
: fCachedMessage(NULL) :
, fCachedSupertypesMessage(NULL) fCachedMessage(NULL),
, fHaveDoneFullBuild(false) fCachedSupertypesMessage(NULL),
fHaveDoneFullBuild(false)
{ {
} }
// Destructor
//! Destroys the InstalledTypes object //! Destroys the InstalledTypes object
InstalledTypes::~InstalledTypes() InstalledTypes::~InstalledTypes()
{ {
@ -49,7 +52,7 @@ InstalledTypes::~InstalledTypes()
delete fCachedMessage; delete fCachedMessage;
} }
// GetInstalledTypes
/*! \brief Returns a list of all currently installed types in the /*! \brief Returns a list of all currently installed types in the
pre-allocated \c BMessage pointed to by \c types. pre-allocated \c BMessage pointed to by \c types.
@ -60,21 +63,21 @@ InstalledTypes::GetInstalledTypes(BMessage *types)
{ {
status_t err = types ? B_OK : B_BAD_VALUE; status_t err = types ? B_OK : B_BAD_VALUE;
// See if we need to do our initial build still // See if we need to do our initial build still
if (!err && !fHaveDoneFullBuild) { if (!err && !fHaveDoneFullBuild)
err = BuildInstalledTypesList(); err = _BuildInstalledTypesList();
}
// See if we need to fill up a new message // See if we need to fill up a new message
if (!err && !fCachedMessage) { if (!err && !fCachedMessage)
err = CreateMessageWithTypes(&fCachedMessage); err = _CreateMessageWithTypes(&fCachedMessage);
}
// If we get this far, there a cached message waiting // If we get this far, there a cached message waiting
if (!err) { if (!err)
*types = *fCachedMessage; *types = *fCachedMessage;
}
return err; return err;
} }
// GetInstalledTypes
/*! \brief Returns a list of all currently installed types of the given /*! \brief Returns a list of all currently installed types of the given
supertype in the pre-allocated \c BMessage pointed to by \c types. supertype in the pre-allocated \c BMessage pointed to by \c types.
@ -84,20 +87,22 @@ InstalledTypes::GetInstalledTypes(BMessage *types)
status_t status_t
InstalledTypes::GetInstalledTypes(const char *supertype, BMessage *types) InstalledTypes::GetInstalledTypes(const char *supertype, BMessage *types)
{ {
status_t err = supertype && types ? B_OK : B_BAD_VALUE; if (supertype == NULL || types == NULL)
return B_BAD_VALUE;
// Verify the supertype is valid *and* is a supertype // Verify the supertype is valid *and* is a supertype
BMimeType mime; BMimeType mime;
BMimeType super; BMimeType super;
// Make sure the supertype is valid // Make sure the supertype is valid
if (!err) status_t err = mime.SetTo(supertype);
err = mime.SetTo(supertype);
// Make sure it's really a supertype // Make sure it's really a supertype
if (!err && !mime.IsSupertypeOnly()) if (!err && !mime.IsSupertypeOnly())
err = B_BAD_VALUE; err = B_BAD_VALUE;
// See if we need to do our initial build still // See if we need to do our initial build still
if (!err && !fHaveDoneFullBuild) { if (!err && !fHaveDoneFullBuild)
err = BuildInstalledTypesList(); err = _BuildInstalledTypesList();
}
// Ask the appropriate supertype for its list // Ask the appropriate supertype for its list
if (!err) { if (!err) {
std::map<std::string, Supertype>::iterator i = fSupertypes.find(supertype); std::map<std::string, Supertype>::iterator i = fSupertypes.find(supertype);
@ -109,7 +114,7 @@ InstalledTypes::GetInstalledTypes(const char *supertype, BMessage *types)
return err; return err;
} }
// GetInstalledSupertypes
/*! \brief Returns a list of all currently installed supertypes in the /*! \brief Returns a list of all currently installed supertypes in the
pre-allocated \c BMessage pointed to by \c types. pre-allocated \c BMessage pointed to by \c types.
@ -118,23 +123,27 @@ InstalledTypes::GetInstalledTypes(const char *supertype, BMessage *types)
status_t status_t
InstalledTypes::GetInstalledSupertypes(BMessage *types) InstalledTypes::GetInstalledSupertypes(BMessage *types)
{ {
status_t err = types ? B_OK : B_BAD_VALUE; if (types == NULL)
return B_BAD_VALUE;
status_t err = B_OK;
// See if we need to do our initial build still // See if we need to do our initial build still
if (!err && !fHaveDoneFullBuild) { if (!fHaveDoneFullBuild)
err = BuildInstalledTypesList(); err = _BuildInstalledTypesList();
}
// See if we need to fill up a new message // See if we need to fill up a new message
if (!err && !fCachedSupertypesMessage) { if (!err && !fCachedSupertypesMessage)
err = CreateMessageWithSupertypes(&fCachedSupertypesMessage); err = _CreateMessageWithSupertypes(&fCachedSupertypesMessage);
}
// If we get this far, there's a cached message waiting // If we get this far, there's a cached message waiting
if (!err) { if (!err)
*types = *fCachedSupertypesMessage; *types = *fCachedSupertypesMessage;
}
return err; return err;
} }
// AddType
/*! \brief Adds the given type to the appropriate lists of installed types. /*! \brief Adds the given type to the appropriate lists of installed types.
If cached messages exist, the type is simply appended to the end of If cached messages exist, the type is simply appended to the end of
@ -143,43 +152,39 @@ InstalledTypes::GetInstalledSupertypes(BMessage *types)
status_t status_t
InstalledTypes::AddType(const char *type) InstalledTypes::AddType(const char *type)
{ {
status_t err; if (!fHaveDoneFullBuild)
if (fHaveDoneFullBuild) { return B_OK;
BMimeType mime(type);
BMimeType super; BMimeType mime(type);
err = type ? mime.InitCheck() : B_BAD_VALUE; if (type == NULL || mime.InitCheck() != B_OK)
if (!err) { return B_BAD_VALUE;
// Find the / in the string, if one exists
uint i; // Find the / in the string, if one exists
size_t len = strlen(type); uint i;
for (i = 0; i < len; i++) { size_t len = strlen(type);
if (type[i] == '/') for (i = 0; i < len; i++) {
break; if (type[i] == '/')
} break;
if (i == len) {
// Supertype only
std::map<std::string, Supertype>::iterator i;
err = AddSupertype(type, i);
} else {
// Copy the supertype
char super[B_PATH_NAME_LENGTH];
strncpy(super, type, i);
super[i] = 0;
// Get a pointer to the subtype
const char *sub = &(type[i+1]);
// Add the subtype (which will add the supertype if necessary)
err = AddSubtype(super, sub);
}
}
} else {
err = B_OK;
} }
return err; if (i == len) {
// Supertype only
std::map<std::string, Supertype>::iterator i;
return _AddSupertype(type, i);
}
// Copy the supertype
char super[B_PATH_NAME_LENGTH];
strncpy(super, type, i);
super[i] = 0;
// Get a pointer to the subtype
const char *sub = &(type[i+1]);
// Add the subtype (which will add the supertype if necessary)
return _AddSubtype(super, sub);
} }
// RemoveType
/*! \brief Removes the given type from the appropriate installed types lists. /*! \brief Removes the given type from the appropriate installed types lists.
Any corresponding cached messages are invalidated. Any corresponding cached messages are invalidated.
@ -187,65 +192,66 @@ InstalledTypes::AddType(const char *type)
status_t status_t
InstalledTypes::RemoveType(const char *type) InstalledTypes::RemoveType(const char *type)
{ {
status_t err; if (!fHaveDoneFullBuild)
if (fHaveDoneFullBuild) { return B_OK;
BMimeType mime(type);
BMimeType super; BMimeType mime(type);
err = type ? mime.InitCheck() : B_BAD_VALUE; if (type == NULL || mime.InitCheck() != B_OK)
if (!err) { return B_BAD_VALUE;
// Find the / in the string, if one exists
uint i; // Find the / in the string, if one exists
size_t len = strlen(type); uint i;
for (i = 0; i < len; i++) { size_t len = strlen(type);
if (type[i] == '/') for (i = 0; i < len; i++) {
break; if (type[i] == '/')
} break;
if (i == len) { }
// Supertype only if (i == len) {
err = RemoveSupertype(type); // Supertype only
} else { return _RemoveSupertype(type);
// Copy the supertype }
char super[B_PATH_NAME_LENGTH];
strncpy(super, type, i); // Copy the supertype
super[i] = 0; char super[B_PATH_NAME_LENGTH];
strncpy(super, type, i);
// Get a pointer to the subtype super[i] = 0;
const char *sub = &(type[i+1]);
// Get a pointer to the subtype
// Remove the subtype const char *sub = &(type[i+1]);
err = RemoveSubtype(super, sub);
} // Remove the subtype
} return _RemoveSubtype(super, sub);
} else
err = B_OK;
return err;
} }
// AddSupertype
/*! \brief Adds the given supertype to the supertype map. /*! \brief Adds the given supertype to the supertype map.
\return \return
- B_OK: success, even if the supertype already existed in the map - B_OK: success, even if the supertype already existed in the map
- "error code": failure - "error code": failure
*/ */
status_t status_t
InstalledTypes::AddSupertype(const char *super, std::map<std::string, Supertype>::iterator &i) InstalledTypes::_AddSupertype(const char *super,
std::map<std::string, Supertype>::iterator &i)
{ {
status_t err = super ? B_OK : B_BAD_VALUE; if (super == NULL)
if (!err) { return B_BAD_VALUE;
i = fSupertypes.find(super);
if (i == fSupertypes.end()) { status_t err = B_OK;
Supertype &supertype = fSupertypes[super];
supertype.SetName(super); i = fSupertypes.find(super);
if (fCachedMessage) if (i == fSupertypes.end()) {
err = fCachedMessage->AddString(kTypesField, super); Supertype &supertype = fSupertypes[super];
if (!err && fCachedSupertypesMessage) supertype.SetName(super);
err = fCachedSupertypesMessage->AddString(kSupertypesField, super); if (fCachedMessage)
} err = fCachedMessage->AddString(kTypesField, super);
if (!err && fCachedSupertypesMessage)
err = fCachedSupertypesMessage->AddString(kSupertypesField, super);
} }
return err; return err;
} }
// AddSubtype
/*! \brief Adds the given subtype to the given supertype's lists of installed types. /*! \brief Adds the given subtype to the given supertype's lists of installed types.
If the supertype does not yet exist, it is created. If the supertype does not yet exist, it is created.
@ -258,19 +264,20 @@ InstalledTypes::AddSupertype(const char *super, std::map<std::string, Supertype>
- "error code": failure - "error code": failure
*/ */
status_t status_t
InstalledTypes::AddSubtype(const char *super, const char *sub) InstalledTypes::_AddSubtype(const char *super, const char *sub)
{ {
status_t err = super && sub ? B_OK : B_BAD_VALUE; if (super == NULL || sub == NULL)
if (!err) { return B_BAD_VALUE;
std::map<std::string, Supertype>::iterator i;
err = AddSupertype(super, i); std::map<std::string, Supertype>::iterator i;
if (!err) status_t err = _AddSupertype(super, i);
err = AddSubtype(i->second, sub); if (!err)
} err = _AddSubtype(i->second, sub);
return err; return err;
} }
// AddSubtype
/*! \brief Adds the given subtype to the given supertype's lists of installed types. /*! \brief Adds the given subtype to the given supertype's lists of installed types.
\param super The supertype object \param super The supertype object
@ -281,11 +288,12 @@ InstalledTypes::AddSubtype(const char *super, const char *sub)
- "error code": failure - "error code": failure
*/ */
status_t status_t
InstalledTypes::AddSubtype(Supertype &super, const char *sub) InstalledTypes::_AddSubtype(Supertype &super, const char *sub)
{ {
status_t err = sub ? B_OK : B_BAD_VALUE; if (sub == NULL)
if (!err) return B_BAD_VALUE;
err = super.AddSubtype(sub);
status_t err = super.AddSubtype(sub);
if (!err && fCachedMessage) { if (!err && fCachedMessage) {
char type[B_PATH_NAME_LENGTH]; char type[B_PATH_NAME_LENGTH];
sprintf(type, "%s/%s", super.GetName(), sub); sprintf(type, "%s/%s", super.GetName(), sub);
@ -294,53 +302,56 @@ InstalledTypes::AddSubtype(Supertype &super, const char *sub)
return err; return err;
} }
// RemoveSupertype
/*! \brief Removes the given supertype and any corresponding subtypes. /*! \brief Removes the given supertype and any corresponding subtypes.
*/ */
status_t status_t
InstalledTypes::RemoveSupertype(const char *super) InstalledTypes::_RemoveSupertype(const char *super)
{ {
status_t err = super ? B_OK : B_BAD_VALUE; if (super == NULL)
return B_BAD_VALUE;
status_t err = fSupertypes.erase(super) == 1 ? B_OK : B_NAME_NOT_FOUND;
if (!err) if (!err)
err = fSupertypes.erase(super) == 1 ? B_OK : B_NAME_NOT_FOUND; _ClearCachedMessages();
if (!err)
ClearCachedMessages();
return err; return err;
} }
// RemoveSubtype
/*! \brief Removes the given subtype from the given supertype. /*! \brief Removes the given subtype from the given supertype.
*/ */
status_t status_t
InstalledTypes::RemoveSubtype(const char *super, const char *sub) InstalledTypes::_RemoveSubtype(const char *super, const char *sub)
{ {
status_t err = super && sub ? B_OK : B_BAD_VALUE; if (super == NULL || sub == NULL)
if (!err) { return B_BAD_VALUE;
std::map<std::string, Supertype>::iterator i = fSupertypes.find(super);
if (i != fSupertypes.end()) { status_t err = B_NAME_NOT_FOUND;
err = i->second.RemoveSubtype(sub);
if (!err) std::map<std::string, Supertype>::iterator i = fSupertypes.find(super);
ClearCachedMessages(); if (i != fSupertypes.end()) {
} else err = i->second.RemoveSubtype(sub);
err = B_NAME_NOT_FOUND; if (!err)
_ClearCachedMessages();
} }
return err; return err;
} }
// Unset
// Clears any cached messages and empties the supertype map //! Clears any cached messages and empties the supertype map
void void
InstalledTypes::Unset() InstalledTypes::_Unset()
{ {
ClearCachedMessages(); _ClearCachedMessages();
fSupertypes.clear(); fSupertypes.clear();
} }
// ClearCachedMessages
//! Frees any cached messages and sets their pointers to NULL //! Frees any cached messages and sets their pointers to NULL
void void
InstalledTypes::ClearCachedMessages() InstalledTypes::_ClearCachedMessages()
{ {
delete fCachedSupertypesMessage; delete fCachedSupertypesMessage;
delete fCachedMessage; delete fCachedMessage;
@ -348,16 +359,16 @@ InstalledTypes::ClearCachedMessages()
fCachedMessage = NULL; fCachedMessage = NULL;
} }
// BuildInstalledTypesList
/*! \brief Reads through the database and builds a complete set of installed types lists. /*! \brief Reads through the database and builds a complete set of installed types lists.
An initial set of cached messages are also created. An initial set of cached messages are also created.
*/ */
status_t status_t
InstalledTypes::BuildInstalledTypesList() InstalledTypes::_BuildInstalledTypesList()
{ {
status_t err = B_OK; status_t err = B_OK;
Unset(); _Unset();
// Create empty "cached messages" so proper messages // Create empty "cached messages" so proper messages
// will be built up as we add new types // will be built up as we add new types
@ -393,7 +404,7 @@ InstalledTypes::BuildInstalledTypesList()
// Add this supertype // Add this supertype
std::map<std::string, Supertype>::iterator i; std::map<std::string, Supertype>::iterator i;
if (AddSupertype(supertype, i) != B_OK) if (_AddSupertype(supertype, i) != B_OK)
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList() -- Error adding supertype '%s': 0x%lx\n", DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList() -- Error adding supertype '%s': 0x%lx\n",
supertype, err)); supertype, err));
Supertype &supertypeRef = fSupertypes[supertype]; Supertype &supertypeRef = fSupertypes[supertype];
@ -411,28 +422,32 @@ InstalledTypes::BuildInstalledTypesList()
if (err == B_ENTRY_NOT_FOUND) if (err == B_ENTRY_NOT_FOUND)
err = B_OK; err = B_OK;
break; break;
} else { } else {
// Get the subtype's name // We need to preserve the case of the type name for
char subtype[B_PATH_NAME_LENGTH]; // queries, so we can't use the file name directly
if (subEntry.GetName(subtype) == B_OK) { BString type;
BPrivate::Storage::to_lower(subtype); int32 subStart;
BNode node(&subEntry);
if (node.InitCheck() == B_OK
&& node.ReadAttrString(kTypeAttr, &type) >= B_OK
&& (subStart = type.FindFirst('/')) > 0) {
// Add the subtype // Add the subtype
if (AddSubtype(supertypeRef, subtype) != B_OK) { if (_AddSubtype(supertypeRef, type.String()
+ subStart + 1) != B_OK) {
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList() -- Error adding subtype '%s/%s': 0x%lx\n", DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList() -- Error adding subtype '%s/%s': 0x%lx\n",
supertype, subtype, err)); supertype, type.String() + subStart + 1, err));
} }
} }
} }
} }
} else { } else {
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): " DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): "
"Failed opening supertype directory '%s'\n", "Failed opening supertype directory '%s'\n",
supertype)); supertype));
} }
} }
} }
} }
} else { } else {
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): " DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): "
"Failed opening mime database directory '%s'\n", "Failed opening mime database directory '%s'\n",
@ -443,25 +458,28 @@ InstalledTypes::BuildInstalledTypesList()
} }
// CreateMessageWithTypes
/*! \brief Allocates a new BMessage into the BMessage pointer pointed to by \c result /*! \brief Allocates a new BMessage into the BMessage pointer pointed to by \c result
and fills it with a complete list of installed types. and fills it with a complete list of installed types.
*/ */
status_t status_t
InstalledTypes::CreateMessageWithTypes(BMessage **result) const InstalledTypes::_CreateMessageWithTypes(BMessage **_result) const
{ {
status_t err = result ? B_OK : B_BAD_VALUE; if (_result == NULL)
return B_BAD_VALUE;
status_t err = B_OK;
// Alloc the message // Alloc the message
if (!err) { try {
try { *_result = new BMessage();
*result = new BMessage(); } catch (std::bad_alloc) {
} catch (std::bad_alloc) { err = B_NO_MEMORY;
err = B_NO_MEMORY;
}
} }
// Fill with types // Fill with types
if (!err) { if (!err) {
BMessage &msg = **result; BMessage &msg = **_result;
std::map<std::string, Supertype>::const_iterator i; std::map<std::string, Supertype>::const_iterator i;
for (i = fSupertypes.begin(); i != fSupertypes.end() && !err; i++) { for (i = fSupertypes.begin(); i != fSupertypes.end() && !err; i++) {
err = msg.AddString(kTypesField, i->first.c_str()); err = msg.AddString(kTypesField, i->first.c_str());
@ -472,25 +490,28 @@ InstalledTypes::CreateMessageWithTypes(BMessage **result) const
return err; return err;
} }
// CreateMessageWithSupertypes
/*! \brief Allocates a new BMessage into the BMessage pointer pointed to by \c result /*! \brief Allocates a new BMessage into the BMessage pointer pointed to by \c result
and fills it with a complete list of installed supertypes. and fills it with a complete list of installed supertypes.
*/ */
status_t status_t
InstalledTypes::CreateMessageWithSupertypes(BMessage **result) const InstalledTypes::_CreateMessageWithSupertypes(BMessage **_result) const
{ {
status_t err = result ? B_OK : B_BAD_VALUE; if (_result == NULL)
return B_BAD_VALUE;
status_t err = B_OK;
// Alloc the message // Alloc the message
if (!err) { try {
try { *_result = new BMessage();
*result = new BMessage(); } catch (std::bad_alloc) {
} catch (std::bad_alloc) { err = B_NO_MEMORY;
err = B_NO_MEMORY;
}
} }
// Fill with types // Fill with types
if (!err) { if (!err) {
BMessage &msg = **result; BMessage &msg = **_result;
std::map<std::string, Supertype>::const_iterator i; std::map<std::string, Supertype>::const_iterator i;
for (i = fSupertypes.begin(); i != fSupertypes.end() && !err; i++) { for (i = fSupertypes.begin(); i != fSupertypes.end() && !err; i++) {
err = msg.AddString(kSupertypesField, i->first.c_str()); err = msg.AddString(kSupertypesField, i->first.c_str());