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