* Got rid of is_running_on_haiku(). It was used for the test environment,

but wouldn't work when running it on Haiku anyway. At any rate, it was
  relatively expensive (uname()) and used already in the libbe
  initialization.
* Got rid of the non-Haiku support of main_thread_for().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34371 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-11-30 12:14:02 +00:00
parent 879f9a0937
commit 4b9cf09f14
3 changed files with 36 additions and 71 deletions
+3 -3
View File
@@ -1,15 +1,17 @@
/* /*
* Copyright 2002-2007, Ingo Weinhold, [email protected]. * Copyright 2002-2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _APP_MISC_H #ifndef _APP_MISC_H
#define _APP_MISC_H #define _APP_MISC_H
#include <Handler.h> #include <Handler.h>
#include <Locker.h> #include <Locker.h>
#include <OS.h> #include <OS.h>
#include <SupportDefs.h> #include <SupportDefs.h>
struct entry_ref; struct entry_ref;
namespace BPrivate { namespace BPrivate {
@@ -25,8 +27,6 @@ status_t get_app_ref(entry_ref *ref, bool traverse = true);
team_id current_team(); team_id current_team();
thread_id main_thread_for(team_id team); thread_id main_thread_for(team_id team);
bool is_running_on_haiku();
bool is_app_showing_modal_window(team_id team); bool is_app_showing_modal_window(team_id team);
} // namespace BPrivate } // namespace BPrivate
+6 -38
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku. * Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -21,7 +21,6 @@ namespace BPrivate {
BLocker gInitializationLock("global init lock"); BLocker gInitializationLock("global init lock");
// get_app_path
/*! \brief Returns the path to an application's executable. /*! \brief Returns the path to an application's executable.
\param team The application's team ID. \param team The application's team ID.
\param buffer A pointer to a pre-allocated character array of at least \param buffer A pointer to a pre-allocated character array of at least
@@ -54,7 +53,7 @@ get_app_path(team_id team, char *buffer)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
// get_app_path
/*! \brief Returns the path to the application's executable. /*! \brief Returns the path to the application's executable.
\param buffer A pointer to a pre-allocated character array of at least \param buffer A pointer to a pre-allocated character array of at least
size B_PATH_NAME_LENGTH to be filled in by this function. size B_PATH_NAME_LENGTH to be filled in by this function.
@@ -69,7 +68,7 @@ get_app_path(char *buffer)
return get_app_path(B_CURRENT_TEAM, buffer); return get_app_path(B_CURRENT_TEAM, buffer);
} }
// get_app_ref
/*! \brief Returns an entry_ref referring to an application's executable. /*! \brief Returns an entry_ref referring to an application's executable.
\param team The application's team ID. \param team The application's team ID.
\param ref A pointer to a pre-allocated entry_ref to be initialized \param ref A pointer to a pre-allocated entry_ref to be initialized
@@ -97,7 +96,7 @@ get_app_ref(team_id team, entry_ref *ref, bool traverse)
return error; return error;
} }
// get_app_ref
/*! \brief Returns an entry_ref referring to the application's executable. /*! \brief Returns an entry_ref referring to the application's executable.
\param ref A pointer to a pre-allocated entry_ref to be initialized \param ref A pointer to a pre-allocated entry_ref to be initialized
to an entry_ref referring to the application's executable. to an entry_ref referring to the application's executable.
@@ -113,7 +112,7 @@ get_app_ref(entry_ref *ref, bool traverse)
return get_app_ref(B_CURRENT_TEAM, ref, traverse); return get_app_ref(B_CURRENT_TEAM, ref, traverse);
} }
// current_team
/*! \brief Returns the ID of the current team. /*! \brief Returns the ID of the current team.
\return The ID of the current team. \return The ID of the current team.
*/ */
@@ -129,7 +128,7 @@ current_team()
return team; return team;
} }
// main_thread_for
/*! Returns the ID of the supplied team's main thread. /*! Returns the ID of the supplied team's main thread.
\param team The team. \param team The team.
\return \return
@@ -140,44 +139,14 @@ current_team()
thread_id thread_id
main_thread_for(team_id team) main_thread_for(team_id team)
{ {
#ifdef __HAIKU__
// Under Haiku the team ID is equal to it's main thread ID. We just get // Under Haiku the team ID is equal to it's main thread ID. We just get
// a team info to verify the existence of the team. // a team info to verify the existence of the team.
team_info info; team_info info;
status_t error = get_team_info(team, &info); status_t error = get_team_info(team, &info);
return (error == B_OK ? team : error); return (error == B_OK ? team : error);
#else
// For I can't find any trace of how to explicitly get the main thread,
// I assume the main thread is the one with the least thread ID.
thread_id thread = B_BAD_TEAM_ID;
int32 cookie = 0;
thread_info info;
while (get_next_thread_info(team, &cookie, &info) == B_OK) {
if (thread < 0 || info.thread < thread)
thread = info.thread;
}
return thread;
#endif
} }
// is_running_on_haiku
/*! Returns whether we're running under Haiku natively.
This is a runtime check for components compiled only once for both
BeOS and Haiku and nevertheless need to behave differently on the two
systems, like the registrar, which uses another MIME database directory
under BeOS.
\return \c true, if we're running under Haiku, \c false otherwise.
*/
bool
is_running_on_haiku()
{
struct utsname info;
return (uname(&info) == 0 && strcmp(info.sysname, "Haiku") == 0);
}
// is_app_showing_modal_window
/*! \brief Returns whether the application identified by the supplied /*! \brief Returns whether the application identified by the supplied
\c team_id is currently showing a modal window. \c team_id is currently showing a modal window.
\param team the ID of the application in question. \param team the ID of the application in question.
@@ -192,4 +161,3 @@ is_app_showing_modal_window(team_id team)
} }
} // namespace BPrivate } // namespace BPrivate
+27 -30
View File
@@ -45,10 +45,7 @@ static const std::string sSettingsDir = get_user_settings_dir(sSettingsDirPath);
static const char *sHaikuDBDirName = "beos_mime"; static const char *sHaikuDBDirName = "beos_mime";
// when running natively under Haiku // when running natively under Haiku
static const char *sBeOSDBDirName = "obos_mime"; const std::string kDatabaseDir = sSettingsDir + "/" + sHaikuDBDirName;
// when running under BeOS
const std::string kDatabaseDir = sSettingsDir + "/"
+ (is_running_on_haiku() ? sHaikuDBDirName : sBeOSDBDirName);
const std::string kApplicationDatabaseDir = kDatabaseDir + "/application"; const std::string kApplicationDatabaseDir = kDatabaseDir + "/application";
#define ATTR_PREFIX "META:" #define ATTR_PREFIX "META:"
@@ -57,7 +54,7 @@ const std::string kApplicationDatabaseDir = kDatabaseDir + "/application";
const char *kMiniIconAttrPrefix = MINI_ICON_ATTR_PREFIX; const char *kMiniIconAttrPrefix = MINI_ICON_ATTR_PREFIX;
const char *kLargeIconAttrPrefix = LARGE_ICON_ATTR_PREFIX; const char *kLargeIconAttrPrefix = LARGE_ICON_ATTR_PREFIX;
const char *kIconAttrPrefix = ATTR_PREFIX; const char *kIconAttrPrefix = ATTR_PREFIX;
// attribute names // attribute names
const char *kFileTypeAttr = "BEOS:TYPE"; const char *kFileTypeAttr = "BEOS:TYPE";
@@ -143,7 +140,7 @@ open_type(const char *type, BNode *result)
return B_BAD_VALUE; return B_BAD_VALUE;
status_t status = result->SetTo(type_to_filename(type).c_str()); status_t status = result->SetTo(type_to_filename(type).c_str());
// TODO: this can be removed again later - we just didn't write this // TODO: this can be removed again later - we just didn't write this
// attribute is before at all... // attribute is before at all...
#if 1 #if 1
@@ -161,7 +158,7 @@ open_type(const char *type, BNode *result)
// open_or_create_type // open_or_create_type
/*! \brief Opens a BNode on the given type, creating a node of the /*! \brief Opens a BNode on the given type, creating a node of the
appropriate flavor if necessary. appropriate flavor if necessary.
All MIME types are converted to lowercase for use in the filesystem. All MIME types are converted to lowercase for use in the filesystem.
\param type The MIME type to open \param type The MIME type to open
\param result Pointer to a pre-allocated BNode into which \param result Pointer to a pre-allocated BNode into which
@@ -177,7 +174,7 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
status_t err = (type && result ? B_OK : B_BAD_VALUE); status_t err = (type && result ? B_OK : B_BAD_VALUE);
if (!err) { if (!err) {
filename = type_to_filename(type); filename = type_to_filename(type);
err = result->SetTo(filename.c_str()); err = result->SetTo(filename.c_str());
} }
if (err == B_ENTRY_NOT_FOUND) { if (err == B_ENTRY_NOT_FOUND) {
// Figure out what type of node we need to create // Figure out what type of node we need to create
@@ -185,7 +182,7 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
// + Non-supertype == file // + Non-supertype == file
uint32 pos = typeLower.find_first_of('/'); uint32 pos = typeLower.find_first_of('/');
if (pos == std::string::npos) { if (pos == std::string::npos) {
// Supertype == directory // Supertype == directory
BDirectory parent(kDatabaseDir.c_str()); BDirectory parent(kDatabaseDir.c_str());
err = parent.InitCheck(); err = parent.InitCheck();
if (!err) if (!err)
@@ -209,16 +206,16 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
result->WriteAttr(kTypeAttr, B_STRING_TYPE, 0, type, strlen(type) + 1); result->WriteAttr(kTypeAttr, B_STRING_TYPE, 0, type, strlen(type) + 1);
} }
} }
return err; return err;
} }
// read_mime_attr // read_mime_attr
/*! \brief Reads up to \c len bytes of the given data from the given attribute /*! \brief Reads up to \c len bytes of the given data from the given attribute
for the given MIME type. for the given MIME type.
If no entry for the given type exists in the database, the function fails, If no entry for the given type exists in the database, the function fails,
and the contents of \c data are undefined. and the contents of \c data are undefined.
\param type The MIME type \param type The MIME type
\param attr The attribute name \param attr The attribute name
\param data Pointer to a memory buffer into which the data should be copied \param data Pointer to a memory buffer into which the data should be copied
@@ -234,8 +231,8 @@ read_mime_attr(const char *type, const char *attr, void *data,
BNode node; BNode node;
ssize_t err = (type && attr && data ? B_OK : B_BAD_VALUE); ssize_t err = (type && attr && data ? B_OK : B_BAD_VALUE);
if (!err) if (!err)
err = open_type(type, &node); err = open_type(type, &node);
if (!err) if (!err)
err = node.ReadAttr(attr, datatype, 0, data, len); err = node.ReadAttr(attr, datatype, 0, data, len);
return err; return err;
} }
@@ -243,11 +240,11 @@ read_mime_attr(const char *type, const char *attr, void *data,
// read_mime_attr_message // read_mime_attr_message
/*! \brief Reads a flattened BMessage from the given attribute of the given /*! \brief Reads a flattened BMessage from the given attribute of the given
MIME type. MIME type.
If no entry for the given type exists in the database, or if the data If no entry for the given type exists in the database, or if the data
stored in the attribute is not a flattened BMessage, the function fails stored in the attribute is not a flattened BMessage, the function fails
and the contents of \c msg are undefined. and the contents of \c msg are undefined.
\param type The MIME type \param type The MIME type
\param attr The attribute name \param attr The attribute name
\param data Pointer to a pre-allocated BMessage into which the attribute \param data Pointer to a pre-allocated BMessage into which the attribute
@@ -266,12 +263,12 @@ read_mime_attr_message(const char *type, const char *attr, BMessage *msg)
err = node.GetAttrInfo(attr, &info); err = node.GetAttrInfo(attr, &info);
if (!err) if (!err)
err = info.type == B_MESSAGE_TYPE ? B_OK : B_BAD_VALUE; err = info.type == B_MESSAGE_TYPE ? B_OK : B_BAD_VALUE;
if (!err) { if (!err) {
buffer = new(std::nothrow) char[info.size]; buffer = new(std::nothrow) char[info.size];
if (!buffer) if (!buffer)
err = B_NO_MEMORY; err = B_NO_MEMORY;
} }
if (!err) if (!err)
err = node.ReadAttr(attr, B_MESSAGE_TYPE, 0, buffer, info.size); err = node.ReadAttr(attr, B_MESSAGE_TYPE, 0, buffer, info.size);
if (err >= 0) if (err >= 0)
err = err == info.size ? (status_t)B_OK : (status_t)B_FILE_ERROR; err = err == info.size ? (status_t)B_OK : (status_t)B_FILE_ERROR;
@@ -284,10 +281,10 @@ read_mime_attr_message(const char *type, const char *attr, BMessage *msg)
// read_mime_attr_string // read_mime_attr_string
/*! \brief Reads a BString from the given attribute of the given /*! \brief Reads a BString from the given attribute of the given
MIME type. MIME type.
If no entry for the given type exists in the database, the function fails If no entry for the given type exists in the database, the function fails
and the contents of \c str are undefined. and the contents of \c str are undefined.
\param type The MIME type \param type The MIME type
\param attr The attribute name \param attr The attribute name
\param str Pointer to a pre-allocated BString into which the attribute \param str Pointer to a pre-allocated BString into which the attribute
@@ -299,8 +296,8 @@ read_mime_attr_string(const char *type, const char *attr, BString *str)
BNode node; BNode node;
status_t err = (type && attr && str ? B_OK : B_BAD_VALUE); status_t err = (type && attr && str ? B_OK : B_BAD_VALUE);
if (!err) if (!err)
err = open_type(type, &node); err = open_type(type, &node);
if (!err) if (!err)
err = node.ReadAttrString(attr, str); err = node.ReadAttrString(attr, str);
return err; return err;
} }
@@ -308,15 +305,15 @@ read_mime_attr_string(const char *type, const char *attr, BString *str)
// write_mime_attr // write_mime_attr
/*! \brief Writes \c len bytes of the given data to the given attribute /*! \brief Writes \c len bytes of the given data to the given attribute
for the given MIME type. for the given MIME type.
If no entry for the given type exists in the database, it is created. If no entry for the given type exists in the database, it is created.
\param type The MIME type \param type The MIME type
\param attr The attribute name \param attr The attribute name
\param data Pointer to the data to write \param data Pointer to the data to write
\param len The number of bytes to write \param len The number of bytes to write
\param datatype The data type of the given data \param datatype The data type of the given data
*/ */
status_t status_t
write_mime_attr(const char *type, const char *attr, const void *data, write_mime_attr(const char *type, const char *attr, const void *data,
size_t len, type_code datatype, bool *didCreate) size_t len, type_code datatype, bool *didCreate)
@@ -324,7 +321,7 @@ write_mime_attr(const char *type, const char *attr, const void *data,
BNode node; BNode node;
status_t err = (type && attr && data ? B_OK : B_BAD_VALUE); status_t err = (type && attr && data ? B_OK : B_BAD_VALUE);
if (!err) if (!err)
err = open_or_create_type(type, &node, didCreate); err = open_or_create_type(type, &node, didCreate);
if (!err) { if (!err) {
ssize_t bytes = node.WriteAttr(attr, datatype, 0, data, len); ssize_t bytes = node.WriteAttr(attr, datatype, 0, data, len);
if (bytes < B_OK) if (bytes < B_OK)
@@ -338,9 +335,9 @@ write_mime_attr(const char *type, const char *attr, const void *data,
// write_mime_attr_message // write_mime_attr_message
/*! \brief Flattens the given \c BMessage and writes it to the given attribute /*! \brief Flattens the given \c BMessage and writes it to the given attribute
of the given MIME type. of the given MIME type.
If no entry for the given type exists in the database, it is created. If no entry for the given type exists in the database, it is created.
\param type The MIME type \param type The MIME type
\param attr The attribute name \param attr The attribute name
\param msg The BMessage to flatten and write \param msg The BMessage to flatten and write
@@ -359,8 +356,8 @@ write_mime_attr_message(const char *type, const char *attr, const BMessage *msg,
if (!err) if (!err)
err = bytes == msg->FlattenedSize() ? B_OK : B_ERROR; err = bytes == msg->FlattenedSize() ? B_OK : B_ERROR;
if (!err) if (!err)
err = open_or_create_type(type, &node, didCreate); err = open_or_create_type(type, &node, didCreate);
if (!err) if (!err)
err = node.WriteAttr(attr, B_MESSAGE_TYPE, 0, data.Buffer(), data.BufferLength()); err = node.WriteAttr(attr, B_MESSAGE_TYPE, 0, data.Buffer(), data.BufferLength());
if (err >= 0) if (err >= 0)
err = err == (ssize_t)data.BufferLength() ? (ssize_t)B_OK : (ssize_t)B_FILE_ERROR; err = err == (ssize_t)data.BufferLength() ? (ssize_t)B_OK : (ssize_t)B_FILE_ERROR;