launch_daemon: Moved settings parsing into its own file.
This commit is contained in:
@@ -9,6 +9,7 @@ Server launch_daemon
|
|||||||
:
|
:
|
||||||
LaunchDaemon.cpp
|
LaunchDaemon.cpp
|
||||||
Job.cpp
|
Job.cpp
|
||||||
|
SettingsParser.cpp
|
||||||
Target.cpp
|
Target.cpp
|
||||||
Worker.cpp
|
Worker.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <Server.h>
|
#include <Server.h>
|
||||||
|
|
||||||
#include <AppMisc.h>
|
#include <AppMisc.h>
|
||||||
#include <DriverSettingsMessageAdapter.h>
|
|
||||||
#include <LaunchDaemonDefs.h>
|
#include <LaunchDaemonDefs.h>
|
||||||
#include <LaunchRosterPrivate.h>
|
#include <LaunchRosterPrivate.h>
|
||||||
#include <RosterPrivate.h>
|
#include <RosterPrivate.h>
|
||||||
@@ -35,6 +34,7 @@
|
|||||||
#include "InitSharedMemoryDirectoryJob.h"
|
#include "InitSharedMemoryDirectoryJob.h"
|
||||||
#include "InitTemporaryDirectoryJob.h"
|
#include "InitTemporaryDirectoryJob.h"
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
|
#include "SettingsParser.h"
|
||||||
#include "Target.h"
|
#include "Target.h"
|
||||||
#include "Worker.h"
|
#include "Worker.h"
|
||||||
|
|
||||||
@@ -47,38 +47,6 @@ using BSupportKit::BPrivate::JobQueue;
|
|||||||
static const char* kLaunchDirectory = "launch";
|
static const char* kLaunchDirectory = "launch";
|
||||||
|
|
||||||
|
|
||||||
const static settings_template kPortTemplate[] = {
|
|
||||||
{B_STRING_TYPE, "name", NULL, true},
|
|
||||||
{B_INT32_TYPE, "capacity", NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
const static settings_template kJobTemplate[] = {
|
|
||||||
{B_STRING_TYPE, "name", NULL, true},
|
|
||||||
{B_BOOL_TYPE, "disabled", NULL},
|
|
||||||
{B_STRING_TYPE, "launch", NULL},
|
|
||||||
{B_STRING_TYPE, "requires", NULL},
|
|
||||||
{B_BOOL_TYPE, "legacy", NULL},
|
|
||||||
{B_MESSAGE_TYPE, "port", kPortTemplate},
|
|
||||||
{B_BOOL_TYPE, "no_safemode", NULL},
|
|
||||||
{0, NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
const static settings_template kTargetTemplate[] = {
|
|
||||||
{B_STRING_TYPE, "name", NULL, true},
|
|
||||||
{B_BOOL_TYPE, "reset", NULL},
|
|
||||||
{B_MESSAGE_TYPE, "job", kJobTemplate},
|
|
||||||
{B_MESSAGE_TYPE, "service", kJobTemplate},
|
|
||||||
{0, NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
const static settings_template kSettingsTemplate[] = {
|
|
||||||
{B_MESSAGE_TYPE, "target", kTargetTemplate},
|
|
||||||
{B_MESSAGE_TYPE, "job", kJobTemplate},
|
|
||||||
{B_MESSAGE_TYPE, "service", kJobTemplate},
|
|
||||||
{0, NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
public:
|
public:
|
||||||
Session(uid_t user, const BMessenger& target);
|
Session(uid_t user, const BMessenger& target);
|
||||||
@@ -462,16 +430,14 @@ LaunchDaemon::_ReadDirectory(const char* context, BEntry& directoryEntry)
|
|||||||
status_t
|
status_t
|
||||||
LaunchDaemon::_ReadFile(const char* context, BEntry& entry)
|
LaunchDaemon::_ReadFile(const char* context, BEntry& entry)
|
||||||
{
|
{
|
||||||
DriverSettingsMessageAdapter adapter;
|
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
status_t status = path.SetTo(&entry);
|
status_t status = path.SetTo(&entry);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
SettingsParser parser;
|
||||||
BMessage message;
|
BMessage message;
|
||||||
status = adapter.ConvertFromDriverSettings(path.Path(), kSettingsTemplate,
|
status = parser.ParseFile(path.Path(), message);
|
||||||
message);
|
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
_AddJobs(NULL, message);
|
_AddJobs(NULL, message);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015, Axel Dörfler, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "SettingsParser.h"
|
||||||
|
|
||||||
|
#include <DriverSettingsMessageAdapter.h>
|
||||||
|
|
||||||
|
|
||||||
|
const static settings_template kPortTemplate[] = {
|
||||||
|
{B_STRING_TYPE, "name", NULL, true},
|
||||||
|
{B_INT32_TYPE, "capacity", NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
const static settings_template kJobTemplate[] = {
|
||||||
|
{B_STRING_TYPE, "name", NULL, true},
|
||||||
|
{B_BOOL_TYPE, "disabled", NULL},
|
||||||
|
{B_STRING_TYPE, "launch", NULL},
|
||||||
|
{B_STRING_TYPE, "requires", NULL},
|
||||||
|
{B_BOOL_TYPE, "legacy", NULL},
|
||||||
|
{B_MESSAGE_TYPE, "port", kPortTemplate},
|
||||||
|
{B_BOOL_TYPE, "no_safemode", NULL},
|
||||||
|
{0, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
const static settings_template kConditionTemplate[] = {
|
||||||
|
{B_STRING_TYPE, NULL, NULL, true},
|
||||||
|
{B_MESSAGE_TYPE, "not", kConditionTemplate},
|
||||||
|
{B_MESSAGE_TYPE, "and", kConditionTemplate},
|
||||||
|
{B_MESSAGE_TYPE, "or", kConditionTemplate},
|
||||||
|
{0, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
const static settings_template kTargetTemplate[] = {
|
||||||
|
{B_STRING_TYPE, "name", NULL, true},
|
||||||
|
{B_BOOL_TYPE, "reset", NULL},
|
||||||
|
{B_MESSAGE_TYPE, "if", kConditionTemplate},
|
||||||
|
{B_MESSAGE_TYPE, "job", kJobTemplate},
|
||||||
|
{B_MESSAGE_TYPE, "service", kJobTemplate},
|
||||||
|
{0, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
const static settings_template kSettingsTemplate[] = {
|
||||||
|
{B_MESSAGE_TYPE, "target", kTargetTemplate},
|
||||||
|
{B_MESSAGE_TYPE, "job", kJobTemplate},
|
||||||
|
{B_MESSAGE_TYPE, "service", kJobTemplate},
|
||||||
|
{0, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SettingsParser::SettingsParser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
SettingsParser::ParseFile(const char* path, BMessage& settings)
|
||||||
|
{
|
||||||
|
DriverSettingsMessageAdapter adapter;
|
||||||
|
return adapter.ConvertFromDriverSettings(path, kSettingsTemplate, settings);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015, Axel Dörfler, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef SETTINGS_PARSER_H
|
||||||
|
#define SETTINGS_PARSER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsParser {
|
||||||
|
public:
|
||||||
|
SettingsParser();
|
||||||
|
|
||||||
|
status_t ParseFile(const char* path, BMessage& settings);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SETTINGS_PARSER_H
|
||||||
Reference in New Issue
Block a user