Removed mime update code

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1271 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2002-09-29 07:12:42 +00:00
parent a122f181c1
commit b690150ecf
4 changed files with 11 additions and 267 deletions

View File

@ -34,6 +34,12 @@ namespace BPrivate {
namespace Storage {
namespace Mime {
// types of mime update functions that may be run asynchronously
typedef enum {
B_REG_UPDATE_MIME_INFO,
B_REG_CREATE_APP_META_MIME,
} mime_update_function;
class Database {
public:
Database();
@ -87,10 +93,6 @@ public:
status_t DeleteSnifferRule(const char *type);
status_t DeleteSupportedTypes(const char *type, bool fullSync);
// Asynchronous C function calls
status_t UpdateMimeInfoAsync(const entry_ref *ref, bool recursive, bool force);
status_t CleanupAfterAsyncThread(thread_id id);
private:
// Functions to send monitor notifications
status_t SendInstallNotification(const char *type);
@ -105,16 +107,12 @@ private:
int32 action);
status_t SendMonitorUpdate(BMessage &msg);
// Entry point functions for asynchronous update threads
static int32 UpdateMimeInfoAsyncEntry(void *data);
status_t fCStatus;
status_t fStatus;
std::set<BMessenger> fMonitorMessengers;
AssociatedTypes fAssociatedTypes;
InstalledTypes fInstalledTypes;
SnifferRules fSnifferRules;
SupportingApps fSupportingApps;
std::list<async_thread_data*> fAsyncThreads;
};
} // namespace Mime

View File

@ -39,22 +39,6 @@ bool is_installed(const char *type);
// to be shipped off to SetIcon*() and written to the database
status_t get_icon_data(const BBitmap *icon, icon_size size, void **data, int32 *dataSize);
// Common struct used to manage ansynchronous update threads
struct async_thread_data {
public:
async_thread_data(thread_id id = -1);
bool should_exit() const;
void post_exit_notification();
thread_id id;
private:
bool _should_exit;
};
// Called by directly (synchronous calls) and indirectly (asynchronous calls)
// by update_mime_info()
int update_mime_info(entry_ref *ref, bool recursive, bool force, async_thread_data *data = NULL);
} // namespace Mime
} // namespace Storage
} // namespace BPrivate

View File

@ -45,28 +45,6 @@ namespace BPrivate {
namespace Storage {
namespace Mime {
// update_mime_info_async_params
/*! \brief All the neccessary data for managing an asynchronous update_mime_info()
call bundled into a single struct.
*/
struct update_mime_info_async_data : public async_thread_data {
public:
entry_ref ref;
bool recursive;
bool force;
update_mime_info_async_data(const entry_ref *ref, bool recursive, bool force)
: async_thread_data()
, ref(ref ? *ref : entry_ref())
, recursive(recursive)
, force(force)
{
}
private:
update_mime_info_async_data();
};
/*!
\class Database
\brief Mime::Database is the master of the MIME data base.
@ -82,37 +60,18 @@ private:
/*! \brief Creates and initializes a Mime::Database object.
*/
Database::Database()
: fCStatus(B_NO_INIT)
: fStatus(B_NO_INIT)
{
// Do some really minor error checking
BEntry entry(kDatabaseDir.c_str());
fCStatus = entry.Exists() ? B_OK : B_BAD_VALUE;
fStatus = entry.Exists() ? B_OK : B_BAD_VALUE;
}
// destructor
/*! \brief Frees all resources associated with this object.
Any currently running asynchronous update threads are instructed
to politely exit and then waited on.
*/
Database::~Database()
{
std::list<async_thread_data*>::iterator i;
DBG(OUT("Asking async threads to quit...\n"));
for (i = fAsyncThreads.begin();
i != fAsyncThreads.end();
i++)
{
DBG(OUT(" id == %ld\n", (*i)->id));
(*i)->post_exit_notification();
}
for (i = fAsyncThreads.begin();
i != fAsyncThreads.end();
i++)
{
status_t exitValue;
wait_for_thread((*i)->id, &exitValue);
}
}
// InitCheck
@ -124,7 +83,7 @@ Database::~Database()
status_t
Database::InitCheck() const
{
return fCStatus;
return fStatus;
}
// Install
@ -1005,62 +964,6 @@ Database::DeleteSupportedTypes(const char *type, bool fullSync)
return err;
}
// UpdateMimeInfoAsync
/*! \brief Performs the corresponding update_mime_info() call asynchronously (i.e
in a new thread).
*/
status_t
Database::UpdateMimeInfoAsync(const entry_ref *ref, bool recursive, bool force)
{
thread_id id = -1;
status_t err;
update_mime_info_async_data *data;
data = new(nothrow) update_mime_info_async_data(ref, recursive, force);
err = data ? B_OK : B_NO_MEMORY;
// Spawn the thread
if (!err) {
id = spawn_thread(&Database::UpdateMimeInfoAsyncEntry, "mime updater (umi)",
B_NORMAL_PRIORITY, (void*)data);
err = id >= 0 ? B_OK : id;
}
// Update the thread_id, store the thread info, and get it running
if (!err) {
data->id = id;
fAsyncThreads.push_back(data);
err = resume_thread(id);
}
if (!err)
DBG(OUT("spawned new update_mime_info() thread, id == %ld\n", id));
return err;
}
// CleanupAfterAsyncThread
/*! \brief Removes the given thread from the list of currently running asynchronous
threads and frees its associated shared \c async_thread_data object.
*/
status_t
Database::CleanupAfterAsyncThread(thread_id id)
{
status_t err = B_ENTRY_NOT_FOUND;
std::list<async_thread_data*>::iterator i;
for (i = fAsyncThreads.begin(); i != fAsyncThreads.end(); i++) {
if (*i) {
if ((*i)->id == id) {
delete *i;
fAsyncThreads.erase(i);
err = B_OK;
break;
}
} else {
OUT("WARNING: NULL async_thread_data pointer found in Mime::Database::fAsyncThreads list\n");
fAsyncThreads.erase(i);
}
}
return err;
}
// SendInstallNotification
//! \brief Sends a \c B_MIME_TYPE_CREATED notification to the mime monitor service
status_t
@ -1201,16 +1104,6 @@ Database::SendMonitorUpdate(BMessage &msg) {
return err;
}
// UpdateMimeInfoAsyncEntry(void *data)
/*! \brief Entry point for asynchronous update_mime_info() threads
*/
int32
Database::UpdateMimeInfoAsyncEntry(void *data)
{
update_mime_info_async_data *info = (update_mime_info_async_data*)data;
return update_mime_info(&(info->ref), info->recursive, info->force, info);
}
} // namespace Mime
} // namespace Storage
} // namespace BPrivate

View File

@ -15,6 +15,7 @@
#include <Node.h>
#include <Path.h>
#include <RegistrarDefs.h>
#include <String.h>
#include <storage_support.h>
#include <fs_attr.h> // For struct attr_info
@ -417,138 +418,6 @@ get_icon_data(const BBitmap *icon, icon_size which, void **data, int32 *dataSize
return err;
}
/*! \struct async_thread_data
\brief A thread id and functions to allow threads to be safely told
when they need to politely quit what they're doing and exit.
As only the \c Mime::Database class will be posting exit notifications,
and as interested threads will only be calling \c should_exit() on their
respective \c async_thread_data objects, there currently is no synchronization
implemented with respect to accessing the \c thead_data::thread_should_exit
member. If this is a problem, a \c BLocker may be added and locking calls
placed in \c should_exit() and \c post_exit_notification().
*/
//! Creates a new \c async_thread_data object
async_thread_data::async_thread_data(thread_id id)
: id(id)
, _should_exit(false)
{
}
/*! \brief Returns \c true if the thread should politely exit as soon as
possible, or \c false if it may continue running normally.
*/
bool
async_thread_data::should_exit() const {
return _should_exit;
}
/*! \brief All subsequent calls to should_exit() will return \c true.
*/
void
async_thread_data::post_exit_notification() {
_should_exit = true;
}
// update_mime_info
/*! \brief Updates the MIME information (i.e MIME type) for one or more files.
If \a path points to a file, the MIME information for this file are
updated only. If it points to a directory and \a recursive is non-null,
the information for all the files in the given directory tree are updated.
\param ref An entry_ref to a file or directory. May not be NULL.
\param recursive \c true to trigger recursive behavior.
\param force If \c true, file information is updated even if said
information already exists.
\return
- \c B_OK: success
- error code: failure
*/
int
update_mime_info(entry_ref *ref, bool recursive, bool force, async_thread_data *data)
{
// using BPrivate::Storage::Mime::kFileTypeAttr;
status_t err = ref ? B_OK : B_BAD_VALUE;
BNode node;
bool doUpdate = false;
// Figure out if we need to update or not
if (!err)
err = node.SetTo(ref);
if (!err) {
if (force)
doUpdate = true;
else {
attr_info info;
if (!err)
doUpdate = node.GetAttrInfo(kFileTypeAttr, &info) == B_ENTRY_NOT_FOUND;
}
}
// Update *this* node if necessary
if (!err && doUpdate) {
BMimeType type;
err = BMimeType::GuessMimeType(ref, &type);
if (!err && type.InitCheck() == B_OK) {
const char *typeStr = type.Type();
ssize_t len = strlen(typeStr)+1;
ssize_t bytes = node.WriteAttr(kFileTypeAttr, kFileTypeType, 0, typeStr, len);
if (bytes < B_OK)
err = bytes;
else
err = (bytes != len ? B_FILE_ERROR : B_OK);
}
}
// If we're recursing and this is a directory, update each of the directory's
// children as well
if (!err && recursive && node.IsDirectory()) {
node.Unset(); // Unset() to free a file descriptor, as we no longer need our BNode
BDirectory dir;
err = dir.SetTo(ref);
if (!err) {
entry_ref childRef;
while (!err) {
err = dir.GetNextRef(&childRef);
if (err) {
// If we've come to the end of the directory listing,
// it's not an error.
if (err == B_ENTRY_NOT_FOUND)
err = B_OK;
break;
} else {
err = update_mime_info(&childRef, true, force);
}
}
}
}
// If we're running asynchronously, notify the database manager that
// our thread is finished with its task so the manager call free our
// associated data and remove us from the list of running threads.
if (data) {
BMessage msg(B_REG_MIME_ASYNC_THREAD_FINISHED);
status_t result;
status_t error = msg.AddInt32("thread id", data->id);
if (!error)
error = _send_to_roster_(&msg, &msg, true);
if (!error)
error = msg.what = B_REG_RESULT ? B_OK : B_BAD_VALUE;
if (!error)
error = msg.FindInt32("result", &result);
if (!error)
error = result;
if (error)
OUT("WARNING: async update_mime_info() thread failed termination notification with error 0x%lx\n", error);
DBG(OUT("(id: %ld) exiting async update_mime_info() thread with result 0x%lx\n", find_thread(NULL), err));
}
if (data)
snooze(9000000);
return err;
}
} // namespace Mime
} // namespace Storage
} // namespace BPrivate