Consolidate adding add-on directories

This builds off of hrev46243 adding add-on directories all in one place
in AddOnMonitorHandler instead of repeating the code 3 times in
IndexServer, AddOnManager, and MediaAddOnServer.

The safe mode checking in InputServer is now redundant since it all
gets funneled into AddOnMonitorHandler::AddAddOnDirectories()
and the safe mode flags are checked there.

We should probably remove the InputServer::SafeMode() method, but,
I didn't want to break anything that depended on it so I left it.
This commit is contained in:
John Scipione
2013-10-17 01:28:31 -04:00
parent 96cb5c35a3
commit 916be2df3c
8 changed files with 116 additions and 143 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2010, Haiku, Inc. All rights reserved. * Copyright 2004-2013, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _ADD_ON_MONITOR_HANDLER_H #ifndef _ADD_ON_MONITOR_HANDLER_H
@@ -45,6 +45,8 @@ public:
virtual status_t AddDirectory(const node_ref* nref, virtual status_t AddDirectory(const node_ref* nref,
bool sync = false); bool sync = false);
status_t AddAddOnDirectories(const char* leafPath = "");
protected: protected:
// hooks for sub-class // hooks for sub-class
virtual void AddOnCreated( virtual void AddOnCreated(
+62 -2
View File
@@ -1,10 +1,11 @@
/* /*
* Copyright 2004-2010, Haiku, Inc. All rights reserved. * Copyright 2004-2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus, [email protected]
* Andrew Bachmann * Andrew Bachmann
* Stephan Aßmus <[email protected]> * John Scipione, [email protected]
*/ */
@@ -14,6 +15,12 @@
#include <Autolock.h> #include <Autolock.h>
#include <Directory.h> #include <Directory.h>
#include <FindDirectory.h>
#include <Path.h>
#include <driver_settings.h>
#include <safemode_defs.h>
#include <syscalls.h>
#ifndef ADD_ON_STABLE_SECONDS #ifndef ADD_ON_STABLE_SECONDS
@@ -105,6 +112,59 @@ AddOnMonitorHandler::AddDirectory(const node_ref* nref, bool sync)
} }
status_t
AddOnMonitorHandler::AddAddOnDirectories(const char* leafPath)
{
char parameter[32];
size_t parameterLength = sizeof(parameter);
uint32 start = 0;
const directory_which addOnDirectories[] = {
B_USER_NONPACKAGED_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY,
B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY
};
if (_kern_get_safemode_option(B_SAFEMODE_DISABLE_USER_ADD_ONS, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1")) {
// skip user add on directories
start = 2;
}
}
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1")) {
// safe mode, only B_SYSTEM_ADDONS_DIRECTORY is used
start = 3;
}
}
for (uint32 i = start;
i < sizeof(addOnDirectories) / sizeof(directory_which); i++) {
BDirectory directory;
node_ref nodeRef;
BPath path;
if (find_directory(addOnDirectories[i], &path) == B_OK
&& path.Append(leafPath) == B_OK
&& directory.SetTo(path.Path()) == B_OK
&& directory.GetNodeRef(&nodeRef) == B_OK) {
status_t result = this->AddDirectory(&nodeRef);
if (result != B_OK)
return result;
}
}
return B_OK;
}
// #pragma mark - AddOnMonitorHandler hooks // #pragma mark - AddOnMonitorHandler hooks
+6 -38
View File
@@ -1,21 +1,18 @@
/* /*
* Copyright 2010, Haiku. * Copyright 2010-2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Clemens Zeidler <[email protected]> * John Scipione, [email protected]
* Clemens Zeidler, [email protected]
*/ */
#include "IndexServer.h" #include "IndexServer.h"
#include <Directory.h>
#include <driver_settings.h>
#include <FindDirectory.h>
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
#include <syscalls.h>
VolumeObserverHandler::VolumeObserverHandler(IndexServer* indexServer) VolumeObserverHandler::VolumeObserverHandler(IndexServer* indexServer)
: :
@@ -315,41 +312,12 @@ void
IndexServer::_StartWatchingAddOns() IndexServer::_StartWatchingAddOns()
{ {
AddHandler(&fAddOnMonitorHandler); AddHandler(&fAddOnMonitorHandler);
BMessage pulse(B_PULSE); BMessage pulse(B_PULSE);
fPulseRunner = new BMessageRunner(&fAddOnMonitorHandler, &pulse, 1000000LL); fPulseRunner = new BMessageRunner(&fAddOnMonitorHandler, &pulse, 1000000LL);
// the monitor handler needs a pulse to check if add-ons are ready // the monitor handler needs a pulse to check if add-ons are ready
char parameter[32]; &fAddOnMonitorHandler->AddAddOnDirectories("index_server");
size_t parameterLength = sizeof(parameter);
bool safeMode = false;
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1"))
safeMode = true;
}
// load dormant media nodes
const directory_which directories[] = {
B_USER_NONPACKAGED_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY,
B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY
};
// when safemode, only B_SYSTEM_ADDONS_DIRECTORY is used
for (uint32 i = safeMode ? 3 : 0;
i < sizeof(directories) / sizeof(directory_which); i++) {
BDirectory directory;
node_ref nodeRef;
BPath path;
if (find_directory(directories[i], &path) == B_OK
&& path.Append("index_server") == B_OK
&& directory.SetTo(path.Path()) == B_OK
&& directory.GetNodeRef(&nodeRef) == B_OK)
fAddOnMonitorHandler.AddDirectory(&nodeRef, true);
}
} }
+9 -35
View File
@@ -1,11 +1,12 @@
/* /*
* Copyright 2004-2010, Haiku, Inc. All rights reserved. * Copyright 2004-2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Marcus Overhagen
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
* Jérôme Duval * Jérôme Duval
* Marcus Overhagen
* John Scipione, [email protected]
*/ */
@@ -21,7 +22,6 @@
#include <Deskbar.h> #include <Deskbar.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <FindDirectory.h>
#include <image.h> #include <image.h>
#include <Path.h> #include <Path.h>
#include <Roster.h> #include <Roster.h>
@@ -118,14 +118,13 @@ instantiate_add_on(image_id image, const char* path, const char* type)
} }
// #pragma mark - // #pragma mark - AddOnManager
AddOnManager::AddOnManager(bool safeMode) AddOnManager::AddOnManager()
: :
AddOnMonitor(), AddOnMonitor(),
fHandler(new(std::nothrow) MonitorHandler(this)), fHandler(new(std::nothrow) MonitorHandler(this))
fSafeMode(safeMode)
{ {
SetHandler(fHandler); SetHandler(fHandler);
} }
@@ -259,34 +258,9 @@ AddOnManager::_RegisterAddOns()
CALLED(); CALLED();
BAutolock locker(this); BAutolock locker(this);
const directory_which directories[] = { fHandler->AddAddOnDirectories("input_server/devices");
B_USER_NONPACKAGED_ADDONS_DIRECTORY, fHandler->AddAddOnDirectories("input_server/filters");
B_USER_ADDONS_DIRECTORY, fHandler->AddAddOnDirectories("input_server/methods");
B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY
};
const char* subDirectories[] = {
"input_server/devices",
"input_server/filters",
"input_server/methods"
};
int32 subDirectoryCount = sizeof(subDirectories) / sizeof(const char*);
node_ref nref;
BDirectory directory;
BPath path;
// when safemode, only B_SYSTEM_ADDONS_DIRECTORY is used
for (uint32 i = fSafeMode ? 2 : 0;
i < sizeof(directories) / sizeof(directory_which); i++) {
for (int32 j = 0; j < subDirectoryCount; 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);
}
}
}
} }
+4 -3
View File
@@ -1,11 +1,12 @@
/* /*
* Copyright 2004-2010, Haiku, Inc. All rights reserved. * Copyright 2004-2013, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Marcus Overhagen
* Axel Dörfler, axeld@pinc-software.de * Axel Dörfler, axeld@pinc-software.de
* Jérôme Duval * Jérôme Duval
* Marcus Overhagen
* John Scipione, jscipione@gmail.com
*/ */
#ifndef ADD_ON_MANAGER_H #ifndef ADD_ON_MANAGER_H
#define ADD_ON_MANAGER_H #define ADD_ON_MANAGER_H
@@ -27,7 +28,7 @@ using namespace BPrivate;
class AddOnManager : public AddOnMonitor { class AddOnManager : public AddOnMonitor {
public: public:
AddOnManager(bool safeMode); AddOnManager();
~AddOnManager(); ~AddOnManager();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
+27 -25
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2011, Haiku, Inc. All Rights Reserved. * Copyright 2002-2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -9,6 +9,7 @@
#include "BottomlineWindow.h" #include "BottomlineWindow.h"
#include "MethodReplicant.h" #include "MethodReplicant.h"
#include <driver_settings.h>
#include <safemode_defs.h> #include <safemode_defs.h>
#include <syscalls.h> #include <syscalls.h>
@@ -20,7 +21,6 @@
#include <Autolock.h> #include <Autolock.h>
#include <Deskbar.h> #include <Deskbar.h>
#include <Directory.h> #include <Directory.h>
#include <driver_settings.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
@@ -138,8 +138,8 @@ InputDeviceListItem::Matches(const char* name, input_device_type type) const
InputServer::InputServer() InputServer::InputServer()
: BApplication(INPUTSERVER_SIGNATURE), :
fSafeMode(false), BApplication(INPUTSERVER_SIGNATURE),
fKeyboardID(0), fKeyboardID(0),
fInputDeviceListLocker("input server device list"), fInputDeviceListLocker("input server device list"),
fKeyboardSettings(), fKeyboardSettings(),
@@ -162,28 +162,9 @@ InputServer::InputServer()
_StartEventLoop(); _StartEventLoop();
char parameter[32];
size_t parameterLength = sizeof(parameter);
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1"))
fSafeMode = true;
}
if (_kern_get_safemode_option(B_SAFEMODE_DISABLE_USER_ADD_ONS, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1"))
fSafeMode = true;
}
_InitKeyboardMouseStates(); _InitKeyboardMouseStates();
fAddOnManager = new(std::nothrow) ::AddOnManager(SafeMode()); fAddOnManager = new(std::nothrow) ::AddOnManager();
if (fAddOnManager != NULL) { if (fAddOnManager != NULL) {
// We need to Run() the AddOnManager looper after having loaded // We need to Run() the AddOnManager looper after having loaded
// the initial add-ons, otherwise we may deadlock when the looper // the initial add-ons, otherwise we may deadlock when the looper
@@ -1363,7 +1344,28 @@ InputServer::SetMousePos(long *, long *, float, float)
bool bool
InputServer::SafeMode() InputServer::SafeMode()
{ {
return fSafeMode; char parameter[32];
size_t parameterLength = sizeof(parameter);
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1")) {
return true;
}
}
if (_kern_get_safemode_option(B_SAFEMODE_DISABLE_USER_ADD_ONS, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1")) {
return true;
}
}
return false;
} }
+1 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku, Inc. All Rights Reserved. * Copyright 2001-2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef INPUT_SERVER_APP_H #ifndef INPUT_SERVER_APP_H
@@ -211,7 +211,6 @@ class InputServer : public BApplication {
void _ReleaseInput(BMessage* message); void _ReleaseInput(BMessage* message);
private: private:
bool fSafeMode;
uint16 fKeyboardID; uint16 fKeyboardID;
BList fInputDeviceList; BList fInputDeviceList;
+4 -37
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -37,9 +38,7 @@
#include <Application.h> #include <Application.h>
#include <Beep.h> #include <Beep.h>
#include <Directory.h> #include <Directory.h>
#include <driver_settings.h>
#include <Entry.h> #include <Entry.h>
#include <FindDirectory.h>
#include <MediaAddOn.h> #include <MediaAddOn.h>
#include <MediaRoster.h> #include <MediaRoster.h>
#include <MessageRunner.h> #include <MessageRunner.h>
@@ -47,9 +46,6 @@
#include <Roster.h> #include <Roster.h>
#include <String.h> #include <String.h>
#include <safemode_defs.h>
#include <syscalls.h>
#include <AddOnMonitorHandler.h> #include <AddOnMonitorHandler.h>
#include <debug.h> #include <debug.h>
#include <DataExchange.h> #include <DataExchange.h>
@@ -274,17 +270,6 @@ MediaAddonServer::ReadyToRun()
// will be autostarted. Finally, add-ons that don't have // will be autostarted. Finally, add-ons that don't have
// any active nodes (flavors) will be unloaded. // any active nodes (flavors) will be unloaded.
char parameter[32];
size_t parameterLength = sizeof(parameter);
bool safeMode = false;
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
&parameterLength) == B_OK) {
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1"))
safeMode = true;
}
fMonitorHandler = new MonitorHandler(this); fMonitorHandler = new MonitorHandler(this);
AddHandler(fMonitorHandler); AddHandler(fMonitorHandler);
@@ -292,32 +277,14 @@ MediaAddonServer::ReadyToRun()
fPulseRunner = new BMessageRunner(fMonitorHandler, &pulse, 1000000LL); fPulseRunner = new BMessageRunner(fMonitorHandler, &pulse, 1000000LL);
// the monitor handler needs a pulse to check if add-ons are ready // the monitor handler needs a pulse to check if add-ons are ready
// load dormant media nodes fMonitorHandler->AddAddOnDirectories("media");
const directory_which directories[] = {
B_USER_NONPACKAGED_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY,
B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY
};
// when safemode, only B_SYSTEM_ADDONS_DIRECTORY is used
for (uint32 i = safeMode ? 3 : 0;
i < sizeof(directories) / sizeof(directory_which); i++) {
BDirectory directory;
node_ref nodeRef;
BPath path;
if (find_directory(directories[i], &path) == B_OK
&& path.Append("media") == B_OK
&& directory.SetTo(path.Path()) == B_OK
&& directory.GetNodeRef(&nodeRef) == B_OK)
fMonitorHandler->AddDirectory(&nodeRef);
}
#ifdef USER_ADDON_PATH #ifdef USER_ADDON_PATH
node_ref nodeRef; node_ref nodeRef;
if (entry.SetTo(USER_ADDON_PATH) == B_OK if (entry.SetTo(USER_ADDON_PATH) == B_OK
&& entry.GetNodeRef(&nodeRef) == B_OK) && entry.GetNodeRef(&nodeRef) == B_OK) {
fMonitorHandler->AddDirectory(&nodeRef); fMonitorHandler->AddDirectory(&nodeRef);
}
#endif #endif
fStartup = false; fStartup = false;