* Cleanup, no functional change.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28229 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-10-18 13:53:03 +00:00
parent 0f32f7ddeb
commit 8f2be9ef82
6 changed files with 384 additions and 371 deletions
+194 -192
View File
@@ -1,16 +1,23 @@
#include "AddOnMonitorHandler.h"
#include <Directory.h>
#ifndef ADD_ON_STABLE_SECONDS
#define ADD_ON_STABLE_SECONDS 15
#endif
/* /*
* public functions * Copyright 2004-2008, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Andrew Bachmann
*/ */
AddOnMonitorHandler::AddOnMonitorHandler(const char * name) #include "AddOnMonitorHandler.h"
: NodeMonitorHandler(name)
#include <Directory.h>
#ifndef ADD_ON_STABLE_SECONDS
# define ADD_ON_STABLE_SECONDS 5
#endif
AddOnMonitorHandler::AddOnMonitorHandler(const char* name)
: NodeMonitorHandler(name != NULL ? name : "AddOnMonitorHandler")
{ {
} }
@@ -20,139 +27,131 @@ AddOnMonitorHandler::~AddOnMonitorHandler()
} }
/* virtual */ void void
AddOnMonitorHandler::MessageReceived(BMessage * msg) AddOnMonitorHandler::MessageReceived(BMessage* msg)
{ {
if (msg->what == B_PULSE) { if (msg->what == B_PULSE)
HandlePulse(); _HandlePulse();
}
inherited::MessageReceived(msg); inherited::MessageReceived(msg);
} }
/* virtual */ status_t status_t
AddOnMonitorHandler::AddDirectory(const node_ref * nref) AddOnMonitorHandler::AddDirectory(const node_ref* nref)
{ {
// ignore directories added twice // ignore directories added twice
std::list<add_on_directory_info>::iterator diter = directories.begin(); std::list<add_on_directory_info>::iterator iterator = fDirectories.begin();
for (; diter != directories.end() ; diter++) { for (; iterator != fDirectories.end() ; iterator++) {
if (diter->nref == *nref) { if (iterator->nref == *nref)
return B_OK; return B_OK;
}
} }
BDirectory directory(nref); BDirectory directory(nref);
status_t status = directory.InitCheck(); status_t status = directory.InitCheck();
if (status != B_OK) { if (status != B_OK)
return status; return status;
}
add_on_directory_info dir_info; add_on_directory_info dirInfo;
dir_info.nref = *nref; dirInfo.nref = *nref;
directories.push_back(dir_info); fDirectories.push_back(dirInfo);
status = watch_node(nref, B_WATCH_DIRECTORY, this); status = watch_node(nref, B_WATCH_DIRECTORY, this);
if (status != B_OK) { if (status != B_OK) {
directories.pop_back(); fDirectories.pop_back();
return status; return status;
} }
BEntry entry; BEntry entry;
while (directory.GetNextEntry(&entry, true) == B_OK) { while (directory.GetNextEntry(&entry, true) == B_OK) {
add_on_entry_info entry_info; add_on_entry_info entryInfo;
if (entry.GetName(entry_info.name) != B_OK) { if (entry.GetName(entryInfo.name) != B_OK
continue; // discard and proceed || entry.GetNodeRef(&entryInfo.nref) != B_OK) {
continue;
} }
if (entry.GetNodeRef(&entry_info.nref) != B_OK) {
continue; // discard and proceed entryInfo.dir_nref = *nref;
} fPendingEntries.push_back(entryInfo);
entry_info.dir_nref = *nref;
pending_entries.push_back(entry_info);
} }
return B_OK; return B_OK;
} }
/* // #pragma mark - AddOnMonitorHandler hooks
* AddOnMonitorHandler hooks
*/
/* virtual */ void
AddOnMonitorHandler::AddOnCreated(const add_on_entry_info * entry_info) void
AddOnMonitorHandler::AddOnCreated(const add_on_entry_info* entryInfo)
{ {
} }
/* virtual */ void void
AddOnMonitorHandler::AddOnEnabled(const add_on_entry_info * entry_info) AddOnMonitorHandler::AddOnEnabled(const add_on_entry_info* entryInfo)
{ {
} }
/* virtual */ void void
AddOnMonitorHandler::AddOnDisabled(const add_on_entry_info * entry_info) AddOnMonitorHandler::AddOnDisabled(const add_on_entry_info* entryInfo)
{ {
} }
/* virtual */ void void
AddOnMonitorHandler::AddOnRemoved(const add_on_entry_info * entry_info) AddOnMonitorHandler::AddOnRemoved(const add_on_entry_info* entryInfo)
{ {
} }
/* // #pragma mark - NodeMonitorHandler hooks
* NodeMonitorHandler hooks
*/
/* virtual */ void void
AddOnMonitorHandler::EntryCreated(const char *name, ino_t directory, AddOnMonitorHandler::EntryCreated(const char* name, ino_t directory,
dev_t device, ino_t node) dev_t device, ino_t node)
{ {
add_on_entry_info entry_info; add_on_entry_info entryInfo;
strncpy(entry_info.name, name, sizeof(entry_info.name)); strncpy(entryInfo.name, name, sizeof(entryInfo.name));
make_node_ref(device, node, &entry_info.nref); make_node_ref(device, node, &entryInfo.nref);
make_node_ref(device, directory, &entry_info.dir_nref); make_node_ref(device, directory, &entryInfo.dir_nref);
pending_entries.push_back(entry_info); fPendingEntries.push_back(entryInfo);
} }
/* virtual */ void void
AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node) AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node)
{ {
node_ref entry_nref; node_ref entryNodeRef;
make_node_ref(device, node, &entry_nref); make_node_ref(device, node, &entryNodeRef);
// Search pending entries first, which can simply be discarded // Search pending entries first, which can simply be discarded
// We might have this entry in the pending list multiple times, // We might have this entry in the pending list multiple times,
// so we search entire list through, even after finding one. // so we search entire list through, even after finding one.
std::list<add_on_entry_info>::iterator eiter = pending_entries.begin(); std::list<add_on_entry_info>::iterator eiter = fPendingEntries.begin();
while (eiter != pending_entries.end()) { while (eiter != fPendingEntries.end()) {
if (eiter->nref == entry_nref) { if (eiter->nref == entryNodeRef) {
eiter = pending_entries.erase(eiter); eiter = fPendingEntries.erase(eiter);
} else { } else {
eiter++; eiter++;
} }
} }
add_on_entry_info info; add_on_entry_info info;
node_ref dir_nref; node_ref dirNodeRef;
make_node_ref(device, directory, &dir_nref); make_node_ref(device, directory, &dirNodeRef);
// find the entry's info, and the entry's directory info // find the entry's info, and the entry's directory info
std::list<add_on_directory_info>::iterator diter = directories.begin(); std::list<add_on_directory_info>::iterator diter = fDirectories.begin();
for (; diter != directories.end() ; diter++) { for (; diter != fDirectories.end() ; diter++) {
if (diter->nref == dir_nref) { if (diter->nref == dirNodeRef) {
std::list<add_on_entry_info>::iterator eiter = diter->entries.begin(); std::list<add_on_entry_info>::iterator eiter
= diter->entries.begin();
for (; eiter != diter->entries.end() ; eiter++) { for (; eiter != diter->entries.end() ; eiter++) {
info = *eiter; info = *eiter;
if (eiter->nref == entry_nref) { if (eiter->nref == entryNodeRef) {
info = *eiter; info = *eiter;
diter->entries.erase(eiter); diter->entries.erase(eiter);
break; break;
@@ -163,15 +162,15 @@ AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node)
} }
// if it was not found, we're done // if it was not found, we're done
if (diter == directories.end()) { if (diter == fDirectories.end()) {
return; return;
} }
// Start at the top again, and search until the directory we found // Start at the top again, and search until the directory we found
// the old add_on in. If we find a add_on with the same name then // the old add-on in. If we find a add-on with the same name then
// the old add_on was not enabled. So we deallocate the old // the old add-on was not enabled. So we deallocate the old
// add_on and return. // add-on and return.
std::list<add_on_directory_info>::iterator diter2 = directories.begin(); std::list<add_on_directory_info>::iterator diter2 = fDirectories.begin();
for (; diter2 != diter ; diter2++) { for (; diter2 != diter ; diter2++) {
std::list<add_on_entry_info>::iterator eiter = diter2->entries.begin(); std::list<add_on_entry_info>::iterator eiter = diter2->entries.begin();
for (; eiter != diter2->entries.end() ; eiter++) { for (; eiter != diter2->entries.end() ; eiter++) {
@@ -182,14 +181,14 @@ AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node)
} }
} }
// The active plugin was removed. We need to disable and // The active add-on was removed. We need to disable and
// then subsequently deallocate it. // then subsequently deallocate it.
AddOnDisabled(&info); AddOnDisabled(&info);
AddOnRemoved(&info); AddOnRemoved(&info);
// Continue searching for a add_on below us. If we find a add_on // Continue searching for a add-on below us. If we find a add-on
// with the same name, we must enable it. // with the same name, we must enable it.
for (diter++ ; diter != directories.end() ; diter++) { for (diter++ ; diter != fDirectories.end() ; diter++) {
std::list<add_on_entry_info>::iterator eiter = diter->entries.begin(); std::list<add_on_entry_info>::iterator eiter = diter->entries.begin();
for (; eiter != diter->entries.end() ; eiter++) { for (; eiter != diter->entries.end() ; eiter++) {
if (strcmp(eiter->name, info.name) == 0) { if (strcmp(eiter->name, info.name) == 0) {
@@ -201,42 +200,44 @@ AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node)
} }
/* virtual */ void void
AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory, AddOnMonitorHandler::EntryMoved(const char* name, ino_t fromDirectory,
ino_t to_directory, dev_t device, ino_t node) ino_t toDirectory, dev_t device, ino_t node)
{ {
node_ref from_nref; // Search the "from" directory in the known entries
make_node_ref(device, from_directory, &from_nref); node_ref fromNodeRef;
std::list<add_on_directory_info>::iterator from_iter = directories.begin(); make_node_ref(device, fromDirectory, &fromNodeRef);
for ( ; from_iter != directories.end() ; from_iter++) { std::list<add_on_directory_info>::iterator from_iter = fDirectories.begin();
if (from_iter->nref == from_nref) { for (; from_iter != fDirectories.end(); from_iter++) {
if (from_iter->nref == fromNodeRef)
break;
}
// Search the "to" directory in the known entries
node_ref toNodeRef;
make_node_ref(device, toDirectory, &toNodeRef);
std::list<add_on_directory_info>::iterator to_iter = fDirectories.begin();
for ( ; to_iter != fDirectories.end() ; to_iter++) {
if (to_iter->nref == toNodeRef) {
break; break;
} }
} }
node_ref to_nref; if (from_iter == fDirectories.end() && to_iter == fDirectories.end()) {
make_node_ref(device, to_directory, &to_nref);
std::list<add_on_directory_info>::iterator to_iter = directories.begin();
for ( ; to_iter != directories.end() ; to_iter++) {
if (to_iter->nref == to_nref) {
break;
}
}
if ((from_iter == directories.end()) && (to_iter == directories.end())) {
// huh? whatever... // huh? whatever...
return; return;
} }
add_on_entry_info info; add_on_entry_info info;
node_ref entry_nref; node_ref entryNodeRef;
make_node_ref(device, node, &entry_nref); make_node_ref(device, node, &entryNodeRef);
if (to_iter == directories.end()) { if (to_iter == fDirectories.end()) {
// moved out of our view // moved out of our view
std::list<add_on_entry_info>::iterator eiter = from_iter->entries.begin(); std::list<add_on_entry_info>::iterator eiter
= from_iter->entries.begin();
for (; eiter != from_iter->entries.end() ; eiter++) { for (; eiter != from_iter->entries.end() ; eiter++) {
if (entry_nref == eiter->nref) { if (entryNodeRef == eiter->nref) {
// save the info and remove the entry // save the info and remove the entry
info = *eiter; info = *eiter;
from_iter->entries.erase(eiter); from_iter->entries.erase(eiter);
@@ -250,17 +251,17 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
} }
// if the name is the same, save the information about this // if the name is the same, save the information about this
// add_on into former_entries for later use // add-on into fFormerEntries for later use
if (strcmp(info.name, name) == 0) { if (strcmp(info.name, name) == 0)
former_entries.push_back(info); fFormerEntries.push_back(info);
}
// Start at the top again, and search until the from directory. // Start at the top again, and search until the from directory.
// If we find a add_on with the same name then the moved add_on // If we find a add-on with the same name then the moved add-on
// was not enabled. So we are done. // was not enabled. So we are done.
std::list<add_on_directory_info>::iterator diter = directories.begin(); std::list<add_on_directory_info>::iterator diter = fDirectories.begin();
for (; diter != from_iter ; diter++) { for (; diter != from_iter ; diter++) {
std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2
= diter->entries.begin();
for (; eiter2 != diter->entries.end() ; eiter2++) { for (; eiter2 != diter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0) {
return; return;
@@ -268,13 +269,14 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
} }
} }
// finally disable the add_on // finally disable the add-on
AddOnDisabled(&info); AddOnDisabled(&info);
// Continue searching for a add_on below us. If we find a add_on // Continue searching for a add-on below us. If we find a add-on
// with the same name, we must enable it. // with the same name, we must enable it.
for (from_iter++ ; from_iter != directories.end() ; from_iter++) { for (from_iter++ ; from_iter != fDirectories.end() ; from_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = from_iter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2
= from_iter->entries.begin();
for (; eiter2 != from_iter->entries.end() ; eiter2++) { for (; eiter2 != from_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0) {
AddOnEnabled(&*eiter2); AddOnEnabled(&*eiter2);
@@ -292,19 +294,19 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
return; return;
} }
if (from_iter == directories.end()) { if (from_iter == fDirectories.end()) {
// moved into our view // moved into our view
std::list<add_on_entry_info>::iterator eiter = former_entries.begin(); std::list<add_on_entry_info>::iterator eiter = fFormerEntries.begin();
for (; eiter != former_entries.end() ; eiter++) { for (; eiter != fFormerEntries.end() ; eiter++) {
if (entry_nref == eiter->nref) { if (entryNodeRef == eiter->nref) {
// save the info and remove the entry // save the info and remove the entry
info = *eiter; info = *eiter;
former_entries.erase(eiter); fFormerEntries.erase(eiter);
break; break;
} }
} }
if (eiter != former_entries.end()) { if (eiter != fFormerEntries.end()) {
if (strcmp(info.name, name) != 0) { if (strcmp(info.name, name) != 0) {
// name changed on the way in, remove the old one // name changed on the way in, remove the old one
AddOnRemoved(&info); AddOnRemoved(&info);
@@ -313,31 +315,30 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// update the info // update the info
strncpy(info.name, name, sizeof(info.name)); strncpy(info.name, name, sizeof(info.name));
info.nref = entry_nref; info.nref = entryNodeRef;
info.dir_nref = to_nref; info.dir_nref = toNodeRef;
if (eiter == former_entries.end()) { if (eiter == fFormerEntries.end()) {
// this add_on was not seen before // this add-on was not seen before
AddOnCreated(&info); AddOnCreated(&info);
} }
// Start at the top again, and search until the to directory. // Start at the top again, and search until the to directory.
// If we find a add_on with the same name then the moved add_on // If we find an add-on with the same name then the moved add-on
// is not to be enabled. So we are done. // is not to be enabled. So we are done.
std::list<add_on_directory_info>::iterator diter = directories.begin(); std::list<add_on_directory_info>::iterator diter = fDirectories.begin();
for (; diter != to_iter ; diter++) { for (; diter != to_iter ; diter++) {
std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin();
for (; eiter2 != diter->entries.end() ; eiter2++) { for (; eiter2 != diter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0)
return; return;
}
} }
} }
// The new add_on should be enabled, but first we check to see // The new add-on should be enabled, but first we check to see
// if there is an add_on below us. If we find one, we disable it. // if there is an add-on below us. If we find one, we disable it.
bool shadowing = false; bool shadowing = false;
for (diter++ ; diter != directories.end() ; diter++) { for (diter++ ; diter != fDirectories.end() ; diter++) {
std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin();
for (; eiter2 != diter->entries.end() ; eiter2++) { for (; eiter2 != diter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0) {
@@ -346,14 +347,13 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
break; break;
} }
} }
if (shadowing) { if (shadowing)
break; break;
}
} }
// enable the new add_on // enable the new add-on
AddOnEnabled(&info); AddOnEnabled(&info);
// put the new entry into the target directory // put the new entry into the target directory
to_iter->entries.push_back(info); to_iter->entries.push_back(info);
@@ -363,7 +363,7 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
std::list<add_on_entry_info>::iterator eiter = from_iter->entries.begin(); std::list<add_on_entry_info>::iterator eiter = from_iter->entries.begin();
for (; eiter != from_iter->entries.end() ; eiter++) { for (; eiter != from_iter->entries.end() ; eiter++) {
if (entry_nref == eiter->nref) { if (entryNodeRef == eiter->nref) {
// save the old info and remove the entry // save the old info and remove the entry
info = *eiter; info = *eiter;
from_iter->entries.erase(eiter); from_iter->entries.erase(eiter);
@@ -373,13 +373,15 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
if (strcmp(info.name, name) == 0) { if (strcmp(info.name, name) == 0) {
// same name moved in heirarchy // same name moved in heirarchy
debugger("add_on moved inside the heirarchy"); debugger("add-on moved inside the heirarchy");
} else { } else {
// check to see if it was formerly enabled // check to see if it was formerly enabled
bool was_enabled = true; bool was_enabled = true;
std::list<add_on_directory_info>::iterator old_iter = directories.begin(); std::list<add_on_directory_info>::iterator old_iter
= fDirectories.begin();
for (; old_iter != from_iter ; old_iter++) { for (; old_iter != from_iter ; old_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = old_iter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2
= old_iter->entries.begin();
for (; eiter2 != old_iter->entries.end() ; eiter2++) { for (; eiter2 != old_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0) {
was_enabled = false; was_enabled = false;
@@ -390,13 +392,15 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
break; break;
} }
} }
// if it was enabled, disable it and enable the one under us, if it exists // if it was enabled, disable it and enable the one under us, if it
// exists
if (was_enabled) { if (was_enabled) {
AddOnDisabled(&info); AddOnDisabled(&info);
bool done = false; bool done = false;
for (; old_iter != directories.end() ; old_iter++) { for (; old_iter != fDirectories.end() ; old_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = old_iter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2
= old_iter->entries.begin();
for (; eiter2 != old_iter->entries.end() ; eiter2++) { for (; eiter2 != old_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0) {
AddOnEnabled(&*eiter2); AddOnEnabled(&*eiter2);
@@ -404,9 +408,8 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
break; break;
} }
} }
if (done) { if (done)
break; break;
}
} }
} }
@@ -415,32 +418,35 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// set up new addon info // set up new addon info
strncpy(info.name, name, sizeof(info.name)); strncpy(info.name, name, sizeof(info.name));
info.dir_nref = to_nref; info.dir_nref = toNodeRef;
// presto! // presto!
AddOnCreated(&info); AddOnCreated(&info);
// check to see if we are newly enabled // check to see if we are newly enabled
bool is_enabled = true; bool isEnabled = true;
std::list<add_on_directory_info>::iterator new_iter = directories.begin(); std::list<add_on_directory_info>::iterator new_iter
= fDirectories.begin();
for (; new_iter != to_iter ; new_iter++) { for (; new_iter != to_iter ; new_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = new_iter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2
= new_iter->entries.begin();
for (; eiter2 != new_iter->entries.end() ; eiter2++) { for (; eiter2 != new_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0) {
is_enabled = false; isEnabled = false;
break; break;
} }
} }
if (!is_enabled) { if (!isEnabled)
break; break;
}
} }
// if it is newly enabled, check under us for an enabled one, and disable that first // if it is newly enabled, check under us for an enabled one, and
if (is_enabled) { // disable that first
if (isEnabled) {
bool done = false; bool done = false;
for (; new_iter != directories.end() ; new_iter++) { for (; new_iter != fDirectories.end() ; new_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = new_iter->entries.begin(); std::list<add_on_entry_info>::iterator eiter2
= new_iter->entries.begin();
for (; eiter2 != new_iter->entries.end() ; eiter2++) { for (; eiter2 != new_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) { if (strcmp(eiter2->name, info.name) == 0) {
AddOnDisabled(&*eiter2); AddOnDisabled(&*eiter2);
@@ -448,9 +454,8 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
break; break;
} }
} }
if (done) { if (done)
break; break;
}
} }
AddOnEnabled(&info); AddOnEnabled(&info);
} }
@@ -461,33 +466,30 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
} }
/* //! Process pending entries.
* process pending entries
*/
void void
AddOnMonitorHandler::HandlePulse() AddOnMonitorHandler::_HandlePulse()
{ {
BDirectory directory; BDirectory directory;
std::list<add_on_entry_info>::iterator iter = pending_entries.begin(); std::list<add_on_entry_info>::iterator iter = fPendingEntries.begin();
while (iter != pending_entries.end()) { while (iter != fPendingEntries.end()) {
add_on_entry_info info = *iter; add_on_entry_info info = *iter;
node_ref dir_nref; node_ref dirNodeRef;
if ((directory.GetNodeRef(&dir_nref) != B_OK) || if ((directory.GetNodeRef(&dirNodeRef) != B_OK) ||
(dir_nref != info.dir_nref)) { (dirNodeRef != info.dir_nref)) {
if (directory.SetTo(&info.dir_nref) != B_OK) { if (directory.SetTo(&info.dir_nref) != B_OK) {
// invalid directory, discard this pending entry // invalid directory, discard this pending entry
iter = pending_entries.erase(iter); iter = fPendingEntries.erase(iter);
continue; continue;
} }
dir_nref = info.dir_nref; dirNodeRef = info.dir_nref;
} }
struct stat st; struct stat st;
if (directory.GetStatFor(info.name, &st) != B_OK) { if (directory.GetStatFor(info.name, &st) != B_OK) {
// invalid file name, discard this pending entry // invalid file name, discard this pending entry
iter = pending_entries.erase(iter); iter = fPendingEntries.erase(iter);
continue; continue;
} }
@@ -499,12 +501,12 @@ AddOnMonitorHandler::HandlePulse()
} }
// we are going to deal with the stable entry, so remove it // we are going to deal with the stable entry, so remove it
iter = pending_entries.erase(iter); iter = fPendingEntries.erase(iter);
// put the new entry into the directory info // put the new entry into the directory info
std::list<add_on_directory_info>::iterator diter = directories.begin(); std::list<add_on_directory_info>::iterator diter = fDirectories.begin();
for (; diter != directories.end() ; diter++) { for (; diter != fDirectories.end() ; diter++) {
if (diter->nref == dir_nref) { if (diter->nref == dirNodeRef) {
diter->entries.push_back(info); diter->entries.push_back(info);
break; break;
} }
@@ -514,31 +516,32 @@ AddOnMonitorHandler::HandlePulse()
AddOnCreated(&info); AddOnCreated(&info);
// Start at the top again, and search until the directory we put // Start at the top again, and search until the directory we put
// the new add_on in. If we find a add_on with the same name then // the new add-on in. If we find a add-on with the same name then
// the new add_on should not be enabled. // the new add-on should not be enabled.
bool enabled = true; bool enabled = true;
std::list<add_on_directory_info>::iterator diter2 = directories.begin(); std::list<add_on_directory_info>::iterator diter2
= fDirectories.begin();
for (; diter2 != diter ; diter2++) { for (; diter2 != diter ; diter2++) {
std::list<add_on_entry_info>::iterator eiter = diter2->entries.begin(); std::list<add_on_entry_info>::iterator eiter
= diter2->entries.begin();
for (; eiter != diter2->entries.end() ; eiter++) { for (; eiter != diter2->entries.end() ; eiter++) {
if (strcmp(eiter->name, info.name) == 0) { if (strcmp(eiter->name, info.name) == 0) {
enabled = false; enabled = false;
break; break;
} }
} }
if (!enabled) { if (!enabled)
break; break;
}
} }
if (!enabled) { if (!enabled) {
// if we are not enabled, go on to the next pending entry // if we are not enabled, go on to the next pending entry
continue; continue;
} }
// The new add_on should be enabled, but first we check to see // The new add-on should be enabled, but first we check to see
// if there is an add_on below us. If we find one, we disable it. // if there is an add-on below us. If we find one, we disable it.
bool shadowing = false; bool shadowing = false;
for (diter++ ; diter != directories.end() ; diter++) { for (diter++ ; diter != fDirectories.end() ; diter++) {
std::list<add_on_entry_info>::iterator eiter = diter->entries.begin(); std::list<add_on_entry_info>::iterator eiter = diter->entries.begin();
for (; eiter != diter->entries.end() ; eiter++) { for (; eiter != diter->entries.end() ; eiter++) {
if (strcmp(eiter->name, info.name) == 0) { if (strcmp(eiter->name, info.name) == 0) {
@@ -547,9 +550,8 @@ AddOnMonitorHandler::HandlePulse()
break; break;
} }
} }
if (shadowing) { if (shadowing)
break; break;
}
} }
// finally, enable the new entry // finally, enable the new entry
+44 -42
View File
@@ -35,7 +35,7 @@ class AddOnManager::InputServerMonitorHandler : public AddOnMonitorHandler {
} }
virtual void virtual void
AddOnCreated(const add_on_entry_info * entry_info) AddOnCreated(const add_on_entry_info* entryInfo)
{ {
} }
@@ -116,7 +116,7 @@ AddOnManager::RegisterAddOn(BEntry& entry)
PRINT(("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path())); PRINT(("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path()));
image_id addonImage = load_add_on(path.Path()); image_id addonImage = load_add_on(path.Path());
if (addonImage < B_OK) { if (addonImage < B_OK) {
PRINT(("load addon %s failed\n", path.Path())); PRINT(("load addon %s failed\n", path.Path()));
return addonImage; return addonImage;
@@ -125,16 +125,16 @@ AddOnManager::RegisterAddOn(BEntry& entry)
BString pathString = path.Path(); BString pathString = path.Path();
if (pathString.FindFirst("input_server/devices") > 0) { if (pathString.FindFirst("input_server/devices") > 0) {
BInputServerDevice *(*instantiate_func)(); BInputServerDevice* (*instantiateFunc)();
if (get_image_symbol(addonImage, "instantiate_input_device", if (get_image_symbol(addonImage, "instantiate_input_device",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void**)&instantiateFunc) < B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n", PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerDevice *device = (*instantiate_func)(); BInputServerDevice* device = (*instantiateFunc)();
if (device == NULL) { if (device == NULL) {
PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n", PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n",
path.Path())); path.Path()));
@@ -151,16 +151,16 @@ AddOnManager::RegisterAddOn(BEntry& entry)
RegisterDevice(device, ref, addonImage); RegisterDevice(device, ref, addonImage);
} else if (pathString.FindFirst("input_server/filters") > 0) { } else if (pathString.FindFirst("input_server/filters") > 0) {
BInputServerFilter *(*instantiate_func)(); BInputServerFilter* (*instantiateFunc)();
if (get_image_symbol(addonImage, "instantiate_input_filter", if (get_image_symbol(addonImage, "instantiate_input_filter",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void**)&instantiateFunc) < B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n", PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerFilter *filter = (*instantiate_func)(); BInputServerFilter* filter = (*instantiateFunc)();
if (filter == NULL) { if (filter == NULL) {
PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n", PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n",
path.Path())); path.Path()));
@@ -176,16 +176,16 @@ AddOnManager::RegisterAddOn(BEntry& entry)
RegisterFilter(filter, ref, addonImage); RegisterFilter(filter, ref, addonImage);
} else if (pathString.FindFirst("input_server/methods") > 0) { } else if (pathString.FindFirst("input_server/methods") > 0) {
BInputServerMethod *(*instantiate_func)(); BInputServerMethod* (*instantiateFunc)();
if (get_image_symbol(addonImage, "instantiate_input_method", if (get_image_symbol(addonImage, "instantiate_input_method",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void**)&instantiateFunc) < B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n", PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerMethod *method = (*instantiate_func)(); BInputServerMethod* method = (*instantiateFunc)();
if (method == NULL) { if (method == NULL) {
PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n", PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n",
path.Path())); path.Path()));
@@ -281,7 +281,7 @@ AddOnManager::UnregisterAddOn(BEntry& entry)
if (gInputServer->MethodReplicant()) if (gInputServer->MethodReplicant())
gInputServer->MethodReplicant()->SendMessage(&msg); gInputServer->MethodReplicant()->SendMessage(&msg);
} }
} }
return B_OK; return B_OK;
} }
@@ -319,16 +319,18 @@ AddOnManager::RegisterAddOns()
BDirectory directory; BDirectory directory;
BPath path; BPath path;
// when safemode, only B_BEOS_ADDONS_DIRECTORY is used // when safemode, only B_BEOS_ADDONS_DIRECTORY is used
for (uint32 i = fSafeMode ? 2 : 0 ; i < sizeof(directories) / sizeof(directory_which) ; i++) for (uint32 i = fSafeMode ? 2 : 0;
for (uint32 j = 0 ; j < sizeof(subDirectories) / sizeof(char[24]) ; j++) { i < sizeof(directories) / sizeof(directory_which); i++) {
if ((find_directory(directories[i], &path) == B_OK) for (uint32 j = 0; j < sizeof(subDirectories) / sizeof(char[24]); j++) {
&& (path.Append(subDirectories[j]) == B_OK) if (find_directory(directories[i], &path) == B_OK
&& (directory.SetTo(path.Path()) == B_OK) && path.Append(subDirectories[j]) == B_OK
&& (directory.GetNodeRef(&nref) == B_OK)) { && directory.SetTo(path.Path()) == B_OK
&& directory.GetNodeRef(&nref) == B_OK) {
fHandler->AddDirectory(&nref); fHandler->AddDirectory(&nref);
} }
} }
#else }
#else // APPSERVER_TEST_MODE
BEntry entry("/boot/home/svnhaiku/trunk/tests/servers/input/view_input_device/input_server/devices/ViewInputDevice"); BEntry entry("/boot/home/svnhaiku/trunk/tests/servers/input/view_input_device/input_server/devices/ViewInputDevice");
RegisterAddOn(entry); RegisterAddOn(entry);
#endif #endif
@@ -349,7 +351,7 @@ AddOnManager::UnregisterAddOns()
// we have to stop manually the addons because the monitor doesn't disable them on exit // we have to stop manually the addons because the monitor doesn't disable them on exit
{ {
device_info *info; device_info* info;
for (fDeviceList.Rewind(); fDeviceList.GetNext(&info);) { for (fDeviceList.Rewind(); fDeviceList.GetNext(&info);) {
gInputServer->StartStopDevices(*info->device, false); gInputServer->StartStopDevices(*info->device, false);
delete info->device; delete info->device;
@@ -360,7 +362,7 @@ AddOnManager::UnregisterAddOns()
} }
{ {
filter_info *info; filter_info* info;
for (fFilterList.Rewind(); fFilterList.GetNext(&info);) { for (fFilterList.Rewind(); fFilterList.GetNext(&info);) {
delete info->filter; delete info->filter;
if (info->addon_image >= B_OK) if (info->addon_image >= B_OK)
@@ -370,7 +372,7 @@ AddOnManager::UnregisterAddOns()
} }
{ {
method_info *info; method_info* info;
for (fMethodList.Rewind(); fMethodList.GetNext(&info);) { for (fMethodList.Rewind(); fMethodList.GetNext(&info);) {
delete info->method; delete info->method;
if (info->addon_image >= B_OK) if (info->addon_image >= B_OK)
@@ -387,9 +389,9 @@ AddOnManager::RegisterDevice(BInputServerDevice* device, const entry_ref& ref,
{ {
BAutolock locker(fLock); BAutolock locker(fLock);
device_info *pinfo; device_info* info;
for (fDeviceList.Rewind(); fDeviceList.GetNext(&pinfo);) { for (fDeviceList.Rewind(); fDeviceList.GetNext(&info);) {
if (!strcmp(pinfo->ref.name, ref.name)) { if (!strcmp(info->ref.name, ref.name)) {
// we already know this device // we already know this device
return; return;
} }
@@ -397,12 +399,12 @@ AddOnManager::RegisterDevice(BInputServerDevice* device, const entry_ref& ref,
PRINT(("AddOnManager::RegisterDevice, name %s\n", ref.name)); PRINT(("AddOnManager::RegisterDevice, name %s\n", ref.name));
device_info info; device_info newInfo;
info.ref = ref; newInfo.ref = ref;
info.addon_image = addonImage; newInfo.addon_image = addonImage;
info.device = device; newInfo.device = device;
fDeviceList.Insert(info); fDeviceList.Insert(newInfo);
} }
@@ -508,7 +510,7 @@ AddOnManager::LoadReplicant()
BMessage reply; BMessage reply;
if ((to.SendMessage(&request, &reply) == B_OK) if ((to.SendMessage(&request, &reply) == B_OK)
&& (reply.FindMessenger("result", &status) == B_OK)) { && (reply.FindMessenger("result", &status) == B_OK)) {
// enum replicant in Status view // enum replicant in Status view
int32 index = 0; int32 index = 0;
@@ -555,17 +557,17 @@ AddOnManager::GetReplicantAt(BMessenger target, int32 index) const
return err; return err;
int32 uid; int32 uid;
if ((err = reply.FindInt32("result", &uid)) != B_OK) if ((err = reply.FindInt32("result", &uid)) != B_OK)
return err; return err;
return uid; return uid;
} }
status_t status_t
AddOnManager::GetReplicantName(BMessenger target, int32 uid, BMessage *reply) const AddOnManager::GetReplicantName(BMessenger target, int32 uid, BMessage *reply) const
{ {
// We send a message to the target shelf, asking it for the Name of the // We send a message to the target shelf, asking it for the Name of the
// replicant with the given unique id. // replicant with the given unique id.
BMessage request(B_GET_PROPERTY); BMessage request(B_GET_PROPERTY);
@@ -594,7 +596,7 @@ status_t
AddOnManager::GetReplicantView(BMessenger target, int32 uid, AddOnManager::GetReplicantView(BMessenger target, int32 uid,
BMessage* reply) const BMessage* reply) const
{ {
// We send a message to the target shelf, asking it for the Name of the // We send a message to the target shelf, asking it for the Name of the
// replicant with the given unique id. // replicant with the given unique id.
BMessage request(B_GET_PROPERTY); BMessage request(B_GET_PROPERTY);
@@ -763,27 +765,27 @@ status_t
AddOnManager::HandleMethodReplicant(BMessage* message, BMessage* reply) AddOnManager::HandleMethodReplicant(BMessage* message, BMessage* reply)
{ {
CALLED(); CALLED();
if (InputServer::gInputMethodList.CountItems() == 0) { if (InputServer::gInputMethodList.CountItems() == 0) {
UnloadReplicant(); UnloadReplicant();
return B_OK; return B_OK;
} }
LoadReplicant(); LoadReplicant();
BAutolock lock(InputServer::gInputMethodListLocker); BAutolock lock(InputServer::gInputMethodListLocker);
if (gInputServer->MethodReplicant()) { if (gInputServer->MethodReplicant()) {
_BMethodAddOn_ *addon = InputServer::gKeymapMethod.fOwner; _BMethodAddOn_ *addon = InputServer::gKeymapMethod.fOwner;
addon->AddMethod(); addon->AddMethod();
for (int32 i=0; i<InputServer::gInputMethodList.CountItems(); i++) { for (int32 i=0; i<InputServer::gInputMethodList.CountItems(); i++) {
BInputServerMethod *method = BInputServerMethod *method =
(BInputServerMethod *)InputServer::gInputMethodList.ItemAt(i); (BInputServerMethod *)InputServer::gInputMethodList.ItemAt(i);
_BMethodAddOn_ *addon = method->fOwner; _BMethodAddOn_ *addon = method->fOwner;
addon->AddMethod(); addon->AddMethod();
} }
} }
return B_OK; return B_OK;
} }
+6 -5
View File
@@ -12,11 +12,12 @@
// Manager for input_server add-ons (devices, filters, methods) // Manager for input_server add-ons (devices, filters, methods)
#include <Locker.h>
#include <Looper.h>
#include <InputServerDevice.h> #include <InputServerDevice.h>
#include <InputServerFilter.h> #include <InputServerFilter.h>
#include <InputServerMethod.h> #include <InputServerMethod.h>
#include <Locker.h>
#include <Looper.h>
#include "AddOnMonitor.h" #include "AddOnMonitor.h"
#include "AddOnMonitorHandler.h" #include "AddOnMonitorHandler.h"
#include "TList.h" #include "TList.h"
@@ -40,7 +41,7 @@ class AddOnManager : public BLooper {
void RegisterDevice(BInputServerDevice *isd, const entry_ref &ref, image_id addon_image); void RegisterDevice(BInputServerDevice *isd, const entry_ref &ref, image_id addon_image);
void RegisterFilter(BInputServerFilter *isf, const entry_ref &ref, image_id addon_image); void RegisterFilter(BInputServerFilter *isf, const entry_ref &ref, image_id addon_image);
void RegisterMethod(BInputServerMethod *ism, const entry_ref &ref, image_id addon_image); void RegisterMethod(BInputServerMethod *ism, const entry_ref &ref, image_id addon_image);
status_t HandleFindDevices(BMessage*, BMessage*); status_t HandleFindDevices(BMessage*, BMessage*);
status_t HandleWatchDevices(BMessage*, BMessage*); status_t HandleWatchDevices(BMessage*, BMessage*);
status_t HandleIsDeviceRunning(BMessage*, BMessage*); status_t HandleIsDeviceRunning(BMessage*, BMessage*);
@@ -49,13 +50,13 @@ class AddOnManager : public BLooper {
status_t HandleSystemShuttingDown(BMessage*, BMessage*); status_t HandleSystemShuttingDown(BMessage*, BMessage*);
status_t HandleMethodReplicant(BMessage*, BMessage*); status_t HandleMethodReplicant(BMessage*, BMessage*);
status_t HandleNodeMonitor(BMessage*); status_t HandleNodeMonitor(BMessage*);
void LoadReplicant(); void LoadReplicant();
void UnloadReplicant(); void UnloadReplicant();
int32 GetReplicantAt(BMessenger target, int32 index) const; int32 GetReplicantAt(BMessenger target, int32 index) const;
status_t GetReplicantName(BMessenger target, int32 uid, BMessage *reply) const; status_t GetReplicantName(BMessenger target, int32 uid, BMessage *reply) const;
status_t GetReplicantView(BMessenger target, int32 uid, BMessage *reply) const; status_t GetReplicantView(BMessenger target, int32 uid, BMessage *reply) const;
private: private:
class InputServerMonitorHandler; class InputServerMonitorHandler;
friend class InputServerMonitorHandler; friend class InputServerMonitorHandler;
+70 -70
View File
@@ -1,63 +1,67 @@
/* /*
** Copyright 2004, the Haiku project. All rights reserved. * Copyright 2004-2008, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License. * Distributed under the terms of the Haiku License.
** *
** Author : Jérôme Duval * Authors:
** Original authors: Marcus Overhagen, Axel Dörfler * Marcus Overhagen, Axel Dörfler
*/ * Jérôme Duval
*/
#include "InputServer.h"
#include "DeviceManager.h" #include "DeviceManager.h"
#include <stdio.h>
#include <string.h>
#include <Autolock.h> #include <Autolock.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <image.h>
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
#include <image.h> #include "InputServer.h"
#include <stdio.h>
#include <string.h>
void void
DeviceManager::MessageReceived(BMessage * msg) DeviceManager::MessageReceived(BMessage *msg)
{ {
CALLED(); CALLED();
if (msg->what == B_NODE_MONITOR) { if (msg->what == B_NODE_MONITOR) {
int32 opcode; int32 opcode;
if (msg->FindInt32("opcode", &opcode) == B_OK) { if (msg->FindInt32("opcode", &opcode) == B_OK) {
switch (opcode) { switch (opcode) {
case B_ENTRY_CREATED: case B_ENTRY_CREATED:
case B_ENTRY_REMOVED: case B_ENTRY_REMOVED:
case B_ENTRY_MOVED: case B_ENTRY_MOVED:
{ {
node_ref dir_nref; node_ref dir_nref;
if ((msg->FindInt32("device", &dir_nref.device)!=B_OK) if (msg->FindInt32("device", &dir_nref.device) != B_OK
|| (msg->FindInt64("directory", &dir_nref.node)!=B_OK)) || msg->FindInt64("directory", &dir_nref.node) != B_OK)
return; return;
_BDeviceAddOn_ *addon = NULL; _BDeviceAddOn_ *addon = NULL;
int32 i = 0; int32 i = 0;
while ((addon = GetAddOn(i++)) !=NULL) { while ((addon = GetAddOn(i++)) !=NULL) {
int32 j=0; int32 j=0;
node_ref *dnref = NULL; node_ref *dnref = NULL;
while ((dnref = (node_ref *)addon->fMonitoredRefs.ItemAt(j++)) != NULL) { while ((dnref = (node_ref *)addon->fMonitoredRefs.ItemAt(j++)) != NULL) {
if (*dnref == dir_nref) { if (*dnref == dir_nref) {
addon->fDevice->Control(NULL, NULL, msg->what, msg); addon->fDevice->Control(NULL, NULL, msg->what,
msg);
}
} }
} }
break;
} }
}
break; case B_STAT_CHANGED:
case B_STAT_CHANGED: case B_ATTR_CHANGED:
case B_ATTR_CHANGED: case B_DEVICE_MOUNTED:
case B_DEVICE_MOUNTED: case B_DEVICE_UNMOUNTED:
case B_DEVICE_UNMOUNTED: default:
default: BLooper::MessageReceived(msg);
BLooper::MessageReceived(msg); break;
break;
} }
} }
} }
@@ -94,7 +98,7 @@ DeviceManager::AddDirectory(const node_ref *nref, _BDeviceAddOn_ *addon)
status_t status_t
DeviceManager::RemoveDirectory(const node_ref * nref, _BDeviceAddOn_ *addon) DeviceManager::RemoveDirectory(const node_ref *nref, _BDeviceAddOn_ *addon)
{ {
CALLED(); CALLED();
BDirectory directory(nref); BDirectory directory(nref);
@@ -132,7 +136,7 @@ DeviceManager::DeviceManager()
DeviceManager::~DeviceManager() DeviceManager::~DeviceManager()
{ {
_BDeviceAddOn_ *addon = NULL; _BDeviceAddOn_ *addon = NULL;
while ((addon = (_BDeviceAddOn_ *)fDeviceAddons.RemoveItem((int32)0)) !=NULL) while ((addon = (_BDeviceAddOn_ *)fDeviceAddons.RemoveItem((int32)0)) != NULL)
delete addon; delete addon;
} }
@@ -154,9 +158,8 @@ DeviceManager::SaveState()
} }
status_t status_t
DeviceManager::StartMonitoringDevice(_BDeviceAddOn_ *addon, DeviceManager::StartMonitoringDevice(_BDeviceAddOn_ *addon, const char *device)
const char *device)
{ {
CALLED(); CALLED();
status_t err; status_t err;
@@ -173,7 +176,7 @@ DeviceManager::StartMonitoringDevice(_BDeviceAddOn_ *addon,
PRINTERR(("DeviceManager::StartMonitoringDevice SetTo error %s: %s\n", path.Path(), strerror(err))); PRINTERR(("DeviceManager::StartMonitoringDevice SetTo error %s: %s\n", path.Path(), strerror(err)));
return err; return err;
} }
if ((err = create_directory(path.Path(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != B_OK if ((err = create_directory(path.Path(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != B_OK
|| (err = directory.SetTo(path.Path())) != B_OK) { || (err = directory.SetTo(path.Path())) != B_OK) {
PRINTERR(("DeviceManager::StartMonitoringDevice CreateDirectory error %s: %s\n", path.Path(), strerror(err))); PRINTERR(("DeviceManager::StartMonitoringDevice CreateDirectory error %s: %s\n", path.Path(), strerror(err)));
return err; return err;
@@ -184,7 +187,7 @@ DeviceManager::StartMonitoringDevice(_BDeviceAddOn_ *addon,
PRINTERR(("DeviceManager::StartMonitoringDevice GetNodeRef error %s: %s\n", path.Path(), strerror(err))); PRINTERR(("DeviceManager::StartMonitoringDevice GetNodeRef error %s: %s\n", path.Path(), strerror(err)));
return err; return err;
} }
// test if already monitored // test if already monitored
bool alreadyMonitored = false; bool alreadyMonitored = false;
_BDeviceAddOn_ *tmpaddon = NULL; _BDeviceAddOn_ *tmpaddon = NULL;
@@ -200,19 +203,19 @@ DeviceManager::StartMonitoringDevice(_BDeviceAddOn_ *addon,
} }
} }
if (alreadyMonitored) if (alreadyMonitored)
break; break;
} }
// monitor if needed // monitor if needed
if (!alreadyMonitored) { if (!alreadyMonitored) {
if ((err = AddDirectory(&nref, addon)) != B_OK) if ((err = AddDirectory(&nref, addon)) != B_OK)
return err; return err;
} }
// add addon in list // add addon in list
if (!fDeviceAddons.HasItem(addon)) if (!fDeviceAddons.HasItem(addon))
fDeviceAddons.AddItem(addon); fDeviceAddons.AddItem(addon);
// add dir ref in list // add dir ref in list
int32 j=0; int32 j=0;
node_ref *dnref = NULL; node_ref *dnref = NULL;
@@ -223,37 +226,35 @@ DeviceManager::StartMonitoringDevice(_BDeviceAddOn_ *addon,
break; break;
} }
} }
if (!alreadyMonitored) { if (!alreadyMonitored)
addon->fMonitoredRefs.AddItem(new node_ref(nref)); addon->fMonitoredRefs.AddItem(new node_ref(nref));
}
return B_OK; return B_OK;
} }
status_t status_t
DeviceManager::StopMonitoringDevice(_BDeviceAddOn_ *addon, DeviceManager::StopMonitoringDevice(_BDeviceAddOn_ *addon, const char *device)
const char *device)
{ {
CALLED(); CALLED();
status_t err; status_t err;
node_ref nref; node_ref nref;
BDirectory directory; BDirectory directory;
BPath path("/dev"); BPath path("/dev");
if (((err = path.Append(device)) != B_OK) if ((err = path.Append(device)) != B_OK
|| ((err = directory.SetTo(path.Path())) != B_OK) || (err = directory.SetTo(path.Path())) != B_OK
|| ((err = directory.GetNodeRef(&nref)) != B_OK)) || (err = directory.GetNodeRef(&nref)) != B_OK)
return err; return err;
// test if still monitored // test if still monitored
bool stillMonitored = false; bool stillMonitored = false;
_BDeviceAddOn_ *tmpaddon = NULL; _BDeviceAddOn_ *tmpaddon = NULL;
int32 i = 0; int32 i = 0;
while ((tmpaddon = (_BDeviceAddOn_ *)fDeviceAddons.ItemAt(i++)) !=NULL) { while ((tmpaddon = (_BDeviceAddOn_ *)fDeviceAddons.ItemAt(i++)) != NULL) {
if (addon == tmpaddon) if (addon == tmpaddon)
continue; continue;
int32 j=0; int32 j=0;
node_ref *dnref = NULL; node_ref *dnref = NULL;
while ((dnref = (node_ref *)tmpaddon->fMonitoredRefs.ItemAt(j++)) != NULL) { while ((dnref = (node_ref *)tmpaddon->fMonitoredRefs.ItemAt(j++)) != NULL) {
@@ -265,10 +266,10 @@ DeviceManager::StopMonitoringDevice(_BDeviceAddOn_ *addon,
if (stillMonitored) if (stillMonitored)
break; break;
} }
// remove from list // remove from list
node_ref *dnref = NULL; node_ref *dnref = NULL;
int32 j=0; int32 j = 0;
while ((dnref = (node_ref *)addon->fMonitoredRefs.ItemAt(j)) != NULL) { while ((dnref = (node_ref *)addon->fMonitoredRefs.ItemAt(j)) != NULL) {
if (*dnref == nref) { if (*dnref == nref) {
addon->fMonitoredRefs.RemoveItem(j); addon->fMonitoredRefs.RemoveItem(j);
@@ -278,15 +279,14 @@ DeviceManager::StopMonitoringDevice(_BDeviceAddOn_ *addon,
j++; j++;
} }
if (addon->fMonitoredRefs.IsEmpty()) { if (addon->fMonitoredRefs.IsEmpty())
fDeviceAddons.RemoveItem(addon); fDeviceAddons.RemoveItem(addon);
}
// stop monitoring if needed // stop monitoring if needed
if (!stillMonitored) { if (!stillMonitored) {
if ((err = RemoveDirectory(&nref, addon)) != B_OK) if ((err = RemoveDirectory(&nref, addon)) != B_OK)
return err; return err;
} }
return B_OK; return B_OK;
} }
+36 -29
View File
@@ -1,47 +1,54 @@
/* /*
** Copyright 2004, the Haiku project. All rights reserved. * Copyright 2004-2008, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License. * Distributed under the terms of the Haiku License.
** *
** Author : Jérôme Duval * Authors:
** Original authors: Marcus Overhagen, Axel Dörfler * Marcus Overhagen, Axel Dörfler
*/ * Jérôme Duval
*/
#ifndef _DEVICE_MANAGER_H #ifndef _DEVICE_MANAGER_H
#define _DEVICE_MANAGER_H #define _DEVICE_MANAGER_H
// Manager for devices monitoring //! Manager for devices monitoring
#include <Handler.h> #include <Handler.h>
#include <Looper.h> #include <Looper.h>
#include <Locker.h> #include <Locker.h>
#include <Node.h>
#include <InputServerDevice.h> #include <InputServerDevice.h>
#include <InputServerFilter.h> #include <InputServerFilter.h>
#include <InputServerMethod.h> #include <InputServerMethod.h>
#include "TList.h" #include "TList.h"
class DeviceManager : public BLooper { class DeviceManager : public BLooper {
public: public:
DeviceManager(); DeviceManager();
~DeviceManager(); virtual ~DeviceManager();
void LoadState(); void LoadState();
void SaveState(); void SaveState();
status_t StartMonitoringDevice(_BDeviceAddOn_ *addon,
const char *device);
status_t StopMonitoringDevice(_BDeviceAddOn_ *addon,
const char *device);
_BDeviceAddOn_ *GetAddOn(int32 index) {
return (_BDeviceAddOn_*)fDeviceAddons.ItemAt(index);
}
void MessageReceived(BMessage *msg); status_t StartMonitoringDevice(_BDeviceAddOn_ *addon,
const char *device);
private: status_t StopMonitoringDevice(_BDeviceAddOn_ *addon,
status_t AddDirectory(const node_ref *nref, _BDeviceAddOn_ *addon); const char *device);
status_t RemoveDirectory(const node_ref *nref, _BDeviceAddOn_ *addon); _BDeviceAddOn_ *GetAddOn(int32 index)
{ return (_BDeviceAddOn_*)
BList fDeviceAddons; fDeviceAddons.ItemAt(index); }
BLocker fLock;
virtual void MessageReceived(BMessage *msg);
private:
status_t AddDirectory(const node_ref *nref,
_BDeviceAddOn_ *addon);
status_t RemoveDirectory(const node_ref *nref,
_BDeviceAddOn_ *addon);
BList fDeviceAddons;
BLocker fLock;
}; };
#endif // _DEVICE_MANAGER_H #endif // _DEVICE_MANAGER_H
+34 -33
View File
@@ -180,12 +180,11 @@ InputServer::InputServer()
fSafeMode = true; fSafeMode = true;
} }
gDeviceManager.LoadState(); gDeviceManager.LoadState();
#ifndef HAIKU_TARGET_PLATFORM_HAIKU #ifndef HAIKU_TARGET_PLATFORM_HAIKU
if (has_data(find_thread(NULL))) { if (has_data(find_thread(NULL))) {
PRINT(("HasData == YES\n")); PRINT(("HasData == YES\n"));
int32 buffer[2]; int32 buffer[2];
thread_id appThreadId; thread_id appThreadId;
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
@@ -282,7 +281,7 @@ InputServer::_LoadKeymap()
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return B_BAD_VALUE; return B_BAD_VALUE;
path.Append("Key_map"); path.Append("Key_map");
status_t err; status_t err;
@@ -290,7 +289,7 @@ InputServer::_LoadKeymap()
BFile file(path.Path(), B_READ_ONLY); BFile file(path.Path(), B_READ_ONLY);
if ((err = file.InitCheck()) != B_OK) if ((err = file.InitCheck()) != B_OK)
return err; return err;
if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys)) if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys))
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -311,7 +310,7 @@ InputServer::_LoadKeymap()
if (file.Read(fChars, fCharsSize) != (signed)fCharsSize) if (file.Read(fChars, fCharsSize) != (signed)fCharsSize)
return B_BAD_VALUE; return B_BAD_VALUE;
return B_OK; return B_OK;
} }
@@ -369,7 +368,7 @@ InputServer::_SaveKeymap(bool isDefault)
if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize) if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize)
return err; return err;
// don't bother reporting an error if this fails, since this isn't fatal // don't bother reporting an error if this fails, since this isn't fatal
// the keymap will still be functional, and will just be identified as (Current) in prefs instead of its // the keymap will still be functional, and will just be identified as (Current) in prefs instead of its
// actual name // actual name
if (isDefault) if (isDefault)
@@ -385,8 +384,8 @@ InputServer::QuitRequested()
CALLED(); CALLED();
if (!BApplication::QuitRequested()) if (!BApplication::QuitRequested())
return false; return false;
PostMessage(SYSTEM_SHUTTING_DOWN); PostMessage(SYSTEM_SHUTTING_DOWN);
bool shutdown = false; bool shutdown = false;
CurrentMessage()->FindBool("_shutdown_", &shutdown); CurrentMessage()->FindBool("_shutdown_", &shutdown);
@@ -487,9 +486,9 @@ InputServer::MessageReceived(BMessage* message)
case IS_SET_METHOD: case IS_SET_METHOD:
HandleSetMethod(message); HandleSetMethod(message);
break; break;
case IS_GET_MOUSE_TYPE: case IS_GET_MOUSE_TYPE:
status = HandleGetSetMouseType(message, &reply); status = HandleGetSetMouseType(message, &reply);
break; break;
case IS_SET_MOUSE_TYPE: case IS_SET_MOUSE_TYPE:
status = HandleGetSetMouseType(message, &reply); status = HandleGetSetMouseType(message, &reply);
break; break;
@@ -623,7 +622,7 @@ InputServer::MessageReceived(BMessage* message)
} }
default: default:
return; return;
} }
reply.AddInt32("status", status); reply.AddInt32("status", status);
@@ -655,7 +654,7 @@ InputServer::HandleGetSetMouseType(BMessage* message, BMessage* reply)
BMessage msg(IS_CONTROL_DEVICES); BMessage msg(IS_CONTROL_DEVICES);
msg.AddInt32("type", B_POINTING_DEVICE); msg.AddInt32("type", B_POINTING_DEVICE);
msg.AddInt32("code", B_MOUSE_TYPE_CHANGED); msg.AddInt32("code", B_MOUSE_TYPE_CHANGED);
return fAddOnManager->PostMessage(&msg); return fAddOnManager->PostMessage(&msg);
} }
return reply->AddInt32("mouse_type", fMouseSettings.MouseType()); return reply->AddInt32("mouse_type", fMouseSettings.MouseType());
@@ -674,7 +673,7 @@ InputServer::HandleGetSetMouseAcceleration(BMessage* message,
BMessage msg(IS_CONTROL_DEVICES); BMessage msg(IS_CONTROL_DEVICES);
msg.AddInt32("type", B_POINTING_DEVICE); msg.AddInt32("type", B_POINTING_DEVICE);
msg.AddInt32("code", B_MOUSE_ACCELERATION_CHANGED); msg.AddInt32("code", B_MOUSE_ACCELERATION_CHANGED);
return fAddOnManager->PostMessage(&msg); return fAddOnManager->PostMessage(&msg);
} }
return reply->AddInt32("speed", fMouseSettings.AccelerationFactor()); return reply->AddInt32("speed", fMouseSettings.AccelerationFactor());
@@ -779,7 +778,7 @@ InputServer::HandleSetKeyboardLocks(BMessage* message, BMessage* reply)
{ {
if (message->FindInt32("locks", (int32*)&fKeys.lock_settings) == B_OK) { if (message->FindInt32("locks", (int32*)&fKeys.lock_settings) == B_OK) {
be_app_messenger.SendMessage(IS_SAVE_KEYMAP); be_app_messenger.SendMessage(IS_SAVE_KEYMAP);
BMessage msg(IS_CONTROL_DEVICES); BMessage msg(IS_CONTROL_DEVICES);
msg.AddInt32("type", B_KEYBOARD_DEVICE); msg.AddInt32("type", B_KEYBOARD_DEVICE);
msg.AddInt32("code", B_KEY_LOCKS_CHANGED); msg.AddInt32("code", B_KEY_LOCKS_CHANGED);
@@ -1035,7 +1034,7 @@ InputServer::SetActiveMethod(BInputServerMethod* method)
} }
const BMessenger* const BMessenger*
InputServer::MethodReplicant() InputServer::MethodReplicant()
{ {
return fReplicantMessenger; return fReplicantMessenger;
@@ -1049,7 +1048,7 @@ InputServer::SetMethodReplicant(const BMessenger* messenger)
} }
bool bool
InputServer::EventLoopRunning() InputServer::EventLoopRunning()
{ {
return fEventLooperPort >= B_OK; return fEventLooperPort >= B_OK;
@@ -1122,7 +1121,7 @@ InputServer::UnregisterDevices(BInputServerDevice& serverDevice,
for (int32 i = 0; (device = devices[i]) != NULL; i++) { for (int32 i = 0; (device = devices[i]) != NULL; i++) {
for (int32 j = fInputDeviceList.CountItems() - 1; j >= 0; j--) { for (int32 j = fInputDeviceList.CountItems() - 1; j >= 0; j--) {
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(j); InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(j);
if (item->ServerDevice() == &serverDevice && item->HasName(device->name)) { if (item->ServerDevice() == &serverDevice && item->HasName(device->name)) {
item->Stop(); item->Stop();
fInputDeviceList.RemoveItem(j); fInputDeviceList.RemoveItem(j);
@@ -1159,8 +1158,8 @@ InputServer::RegisterDevices(BInputServerDevice& serverDevice,
input_device_ref *device = NULL; input_device_ref *device = NULL;
for (int32 i = 0; (device = devices[i]) != NULL; i++) { for (int32 i = 0; (device = devices[i]) != NULL; i++) {
if (device->type != B_POINTING_DEVICE if (device->type != B_POINTING_DEVICE
&& device->type != B_KEYBOARD_DEVICE && device->type != B_KEYBOARD_DEVICE
&& device->type != B_UNDEFINED_DEVICE) && device->type != B_UNDEFINED_DEVICE)
continue; continue;
@@ -1195,25 +1194,27 @@ InputServer::RegisterDevices(BInputServerDevice& serverDevice,
status_t status_t
InputServer::StartStopDevices(const char* name, input_device_type type, bool doStart) InputServer::StartStopDevices(const char* name, input_device_type type,
bool doStart)
{ {
CALLED(); CALLED();
BAutolock lock(fInputDeviceListLocker); BAutolock lock(fInputDeviceListLocker);
for (int32 i = fInputDeviceList.CountItems() - 1; i >= 0; i--) { for (int32 i = fInputDeviceList.CountItems() - 1; i >= 0; i--) {
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i); InputDeviceListItem* item
= (InputDeviceListItem*)fInputDeviceList.ItemAt(i);
if (!item) if (!item)
continue; continue;
if (item->Matches(name, type)) { if (item->Matches(name, type)) {
if (!doStart ^ item->Running()) if (!doStart ^ item->Running())
return B_ERROR; return B_ERROR;
if (doStart) if (doStart)
item->Start(); item->Start();
else else
item->Stop(); item->Stop();
if (name) if (name)
return B_OK; return B_OK;
} }
@@ -1227,7 +1228,7 @@ InputServer::StartStopDevices(const char* name, input_device_type type, bool doS
status_t status_t
InputServer::StartStopDevices(BInputServerDevice& serverDevice, bool doStart) InputServer::StartStopDevices(BInputServerDevice& serverDevice, bool doStart)
{ {
CALLED(); CALLED();
@@ -1237,7 +1238,7 @@ InputServer::StartStopDevices(BInputServerDevice& serverDevice, bool doStart)
if (item != NULL) { if (item != NULL) {
if (!doStart ^ item->Running()) if (!doStart ^ item->Running())
return B_ERROR; return B_ERROR;
if (doStart) if (doStart)
item->Start(); item->Start();
else else
@@ -1249,13 +1250,13 @@ InputServer::StartStopDevices(BInputServerDevice& serverDevice, bool doStart)
} }
status_t status_t
InputServer::ControlDevices(const char* name, input_device_type type, InputServer::ControlDevices(const char* name, input_device_type type,
uint32 code, BMessage* message) uint32 code, BMessage* message)
{ {
CALLED(); CALLED();
BAutolock lock(fInputDeviceListLocker); BAutolock lock(fInputDeviceListLocker);
for (int32 i = fInputDeviceList.CountItems() - 1; i >= 0; i--) { for (int32 i = fInputDeviceList.CountItems() - 1; i >= 0; i--) {
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i); InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i);
if (!item) if (!item)
@@ -1400,7 +1401,7 @@ InputServer::_EventLoop()
events.AddItem(event); events.AddItem(event);
} }
// This is where the message should be processed. // This is where the message should be processed.
if (_SanitizeEvents(events) if (_SanitizeEvents(events)
&& _MethodizeEvents(events) && _MethodizeEvents(events)
@@ -1466,7 +1467,7 @@ InputServer::_SanitizeEvents(EventList& events)
fMousePos.y -= y; fMousePos.y -= y;
fMousePos.ConstrainTo(fFrame); fMousePos.ConstrainTo(fFrame);
event->RemoveName("x"); event->RemoveName("x");
event->RemoveName("y"); event->RemoveName("y");
event->AddPoint("where", fMousePos); event->AddPoint("where", fMousePos);
event->AddInt32("be:delta_x", x); event->AddInt32("be:delta_x", x);
@@ -1485,7 +1486,7 @@ InputServer::_SanitizeEvents(EventList& events)
fMousePos.y = absY * fFrame.Height(); fMousePos.y = absY * fFrame.Height();
fMousePos.ConstrainTo(fFrame); fMousePos.ConstrainTo(fFrame);
event->RemoveName("x"); event->RemoveName("x");
event->RemoveName("y"); event->RemoveName("y");
event->AddPoint("where", fMousePos); event->AddPoint("where", fMousePos);
PRINT(("new position : %f, %f\n", fMousePos.x, fMousePos.y)); PRINT(("new position : %f, %f\n", fMousePos.x, fMousePos.y));
@@ -1511,7 +1512,7 @@ InputServer::_SanitizeEvents(EventList& events)
fKeyInfo.modifiers = modifiers; fKeyInfo.modifiers = modifiers;
else else
event->AddInt32("modifiers", fKeyInfo.modifiers); event->AddInt32("modifiers", fKeyInfo.modifiers);
// update or add key states // update or add key states
const uint8 *data; const uint8 *data;
ssize_t size; ssize_t size;
@@ -1537,7 +1538,7 @@ InputServer::_SanitizeEvents(EventList& events)
uint8 byte; uint8 byte;
if (event->FindInt8("byte", (int8*)&byte) < B_OK) if (event->FindInt8("byte", (int8*)&byte) < B_OK)
byte = 0; byte = 0;
if (((fKeyInfo.modifiers & B_COMMAND_KEY) != 0 && byte == ' ') if (((fKeyInfo.modifiers & B_COMMAND_KEY) != 0 && byte == ' ')
|| byte == B_ZENKAKU_HANKAKU) { || byte == B_ZENKAKU_HANKAKU) {
SetNextMethod(!(fKeyInfo.modifiers & B_SHIFT_KEY)); SetNextMethod(!(fKeyInfo.modifiers & B_SHIFT_KEY));
@@ -1551,7 +1552,7 @@ InputServer::_SanitizeEvents(EventList& events)
} }
index++; index++;
} }
return true; return true;
} }