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:
@@ -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.
|
||||
*/
|
||||
#ifndef _ADD_ON_MONITOR_HANDLER_H
|
||||
@@ -45,6 +45,8 @@ public:
|
||||
virtual status_t AddDirectory(const node_ref* nref,
|
||||
bool sync = false);
|
||||
|
||||
status_t AddAddOnDirectories(const char* leafPath = "");
|
||||
|
||||
protected:
|
||||
// hooks for sub-class
|
||||
virtual void AddOnCreated(
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus, [email protected]
|
||||
* Andrew Bachmann
|
||||
* Stephan Aßmus <[email protected]>
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
@@ -14,6 +15,12 @@
|
||||
|
||||
#include <Autolock.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
|
||||
@@ -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,
|
||||
¶meterLength) == 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,
|
||||
¶meterLength) == 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
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku.
|
||||
* Copyright 2010-2013 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Clemens Zeidler <[email protected]>
|
||||
* John Scipione, [email protected]
|
||||
* Clemens Zeidler, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "IndexServer.h"
|
||||
|
||||
#include <Directory.h>
|
||||
#include <driver_settings.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <syscalls.h>
|
||||
|
||||
|
||||
VolumeObserverHandler::VolumeObserverHandler(IndexServer* indexServer)
|
||||
:
|
||||
@@ -315,41 +312,12 @@ void
|
||||
IndexServer::_StartWatchingAddOns()
|
||||
{
|
||||
AddHandler(&fAddOnMonitorHandler);
|
||||
|
||||
BMessage pulse(B_PULSE);
|
||||
fPulseRunner = new BMessageRunner(&fAddOnMonitorHandler, &pulse, 1000000LL);
|
||||
// the monitor handler needs a pulse to check if add-ons are ready
|
||||
|
||||
char parameter[32];
|
||||
size_t parameterLength = sizeof(parameter);
|
||||
bool safeMode = false;
|
||||
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
|
||||
¶meterLength) == 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);
|
||||
}
|
||||
&fAddOnMonitorHandler->AddAddOnDirectories("index_server");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* Authors:
|
||||
* Marcus Overhagen
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
* Jérôme Duval
|
||||
* Marcus Overhagen
|
||||
* John Scipione, jscipione@gmail.com
|
||||
*/
|
||||
|
||||
|
||||
@@ -21,7 +22,6 @@
|
||||
#include <Deskbar.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <image.h>
|
||||
#include <Path.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(),
|
||||
fHandler(new(std::nothrow) MonitorHandler(this)),
|
||||
fSafeMode(safeMode)
|
||||
fHandler(new(std::nothrow) MonitorHandler(this))
|
||||
{
|
||||
SetHandler(fHandler);
|
||||
}
|
||||
@@ -259,34 +258,9 @@ AddOnManager::_RegisterAddOns()
|
||||
CALLED();
|
||||
BAutolock locker(this);
|
||||
|
||||
const directory_which directories[] = {
|
||||
B_USER_NONPACKAGED_ADDONS_DIRECTORY,
|
||||
B_USER_ADDONS_DIRECTORY,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
fHandler->AddAddOnDirectories("input_server/devices");
|
||||
fHandler->AddAddOnDirectories("input_server/filters");
|
||||
fHandler->AddAddOnDirectories("input_server/methods");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* Authors:
|
||||
* Marcus Overhagen
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
* Jérôme Duval
|
||||
* Marcus Overhagen
|
||||
* John Scipione, jscipione@gmail.com
|
||||
*/
|
||||
#ifndef ADD_ON_MANAGER_H
|
||||
#define ADD_ON_MANAGER_H
|
||||
@@ -27,7 +28,7 @@ using namespace BPrivate;
|
||||
|
||||
class AddOnManager : public AddOnMonitor {
|
||||
public:
|
||||
AddOnManager(bool safeMode);
|
||||
AddOnManager();
|
||||
~AddOnManager();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "BottomlineWindow.h"
|
||||
#include "MethodReplicant.h"
|
||||
|
||||
#include <driver_settings.h>
|
||||
#include <safemode_defs.h>
|
||||
#include <syscalls.h>
|
||||
|
||||
@@ -20,7 +21,6 @@
|
||||
#include <Autolock.h>
|
||||
#include <Deskbar.h>
|
||||
#include <Directory.h>
|
||||
#include <driver_settings.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
@@ -138,8 +138,8 @@ InputDeviceListItem::Matches(const char* name, input_device_type type) const
|
||||
|
||||
|
||||
InputServer::InputServer()
|
||||
: BApplication(INPUTSERVER_SIGNATURE),
|
||||
fSafeMode(false),
|
||||
:
|
||||
BApplication(INPUTSERVER_SIGNATURE),
|
||||
fKeyboardID(0),
|
||||
fInputDeviceListLocker("input server device list"),
|
||||
fKeyboardSettings(),
|
||||
@@ -162,28 +162,9 @@ InputServer::InputServer()
|
||||
|
||||
_StartEventLoop();
|
||||
|
||||
char parameter[32];
|
||||
size_t parameterLength = sizeof(parameter);
|
||||
|
||||
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
|
||||
¶meterLength) == 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,
|
||||
¶meterLength) == B_OK) {
|
||||
if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on")
|
||||
|| !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes")
|
||||
|| !strcasecmp(parameter, "enable") || !strcmp(parameter, "1"))
|
||||
fSafeMode = true;
|
||||
}
|
||||
|
||||
_InitKeyboardMouseStates();
|
||||
|
||||
fAddOnManager = new(std::nothrow) ::AddOnManager(SafeMode());
|
||||
fAddOnManager = new(std::nothrow) ::AddOnManager();
|
||||
if (fAddOnManager != NULL) {
|
||||
// We need to Run() the AddOnManager looper after having loaded
|
||||
// the initial add-ons, otherwise we may deadlock when the looper
|
||||
@@ -1363,7 +1344,28 @@ InputServer::SetMousePos(long *, long *, float, float)
|
||||
bool
|
||||
InputServer::SafeMode()
|
||||
{
|
||||
return fSafeMode;
|
||||
char parameter[32];
|
||||
size_t parameterLength = sizeof(parameter);
|
||||
|
||||
if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter,
|
||||
¶meterLength) == 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,
|
||||
¶meterLength) == 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,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.
|
||||
*/
|
||||
#ifndef INPUT_SERVER_APP_H
|
||||
@@ -211,7 +211,6 @@ class InputServer : public BApplication {
|
||||
void _ReleaseInput(BMessage* message);
|
||||
|
||||
private:
|
||||
bool fSafeMode;
|
||||
uint16 fKeyboardID;
|
||||
|
||||
BList fInputDeviceList;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Copyright 2013 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -37,9 +38,7 @@
|
||||
#include <Application.h>
|
||||
#include <Beep.h>
|
||||
#include <Directory.h>
|
||||
#include <driver_settings.h>
|
||||
#include <Entry.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <MediaAddOn.h>
|
||||
#include <MediaRoster.h>
|
||||
#include <MessageRunner.h>
|
||||
@@ -47,9 +46,6 @@
|
||||
#include <Roster.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <safemode_defs.h>
|
||||
#include <syscalls.h>
|
||||
|
||||
#include <AddOnMonitorHandler.h>
|
||||
#include <debug.h>
|
||||
#include <DataExchange.h>
|
||||
@@ -274,17 +270,6 @@ MediaAddonServer::ReadyToRun()
|
||||
// will be autostarted. Finally, add-ons that don't have
|
||||
// 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,
|
||||
¶meterLength) == 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);
|
||||
AddHandler(fMonitorHandler);
|
||||
|
||||
@@ -292,32 +277,14 @@ MediaAddonServer::ReadyToRun()
|
||||
fPulseRunner = new BMessageRunner(fMonitorHandler, &pulse, 1000000LL);
|
||||
// the monitor handler needs a pulse to check if add-ons are ready
|
||||
|
||||
// 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("media") == B_OK
|
||||
&& directory.SetTo(path.Path()) == B_OK
|
||||
&& directory.GetNodeRef(&nodeRef) == B_OK)
|
||||
fMonitorHandler->AddDirectory(&nodeRef);
|
||||
}
|
||||
fMonitorHandler->AddAddOnDirectories("media");
|
||||
|
||||
#ifdef USER_ADDON_PATH
|
||||
node_ref nodeRef;
|
||||
if (entry.SetTo(USER_ADDON_PATH) == B_OK
|
||||
&& entry.GetNodeRef(&nodeRef) == B_OK)
|
||||
&& entry.GetNodeRef(&nodeRef) == B_OK) {
|
||||
fMonitorHandler->AddDirectory(&nodeRef);
|
||||
}
|
||||
#endif
|
||||
|
||||
fStartup = false;
|
||||
|
||||
Reference in New Issue
Block a user