launch_daemon: launching on demand now actually works.
* Was broken in two ways: if only the shortcut "on_demand" was used, the event didn't get created at all due to a bug in Events::AddOnDemand(). * Furthermore, _LaunchJob() always triggered a demand, but it should only do this when not called from a target.
This commit is contained in:
@@ -474,15 +474,15 @@ Events::FromMessage(const BMessenger& target, const BMessage& message)
|
|||||||
|
|
||||||
|
|
||||||
/*static*/ Event*
|
/*static*/ Event*
|
||||||
Events::AddOnDemand(Event* event)
|
Events::AddOnDemand(const BMessenger& target, Event* event)
|
||||||
{
|
{
|
||||||
OrEvent* orEvent = dynamic_cast<OrEvent*>(event);
|
OrEvent* orEvent = dynamic_cast<OrEvent*>(event);
|
||||||
if (orEvent == NULL) {
|
if (orEvent == NULL) {
|
||||||
EventContainer* container = dynamic_cast<EventContainer*>(event);
|
EventContainer* container = dynamic_cast<EventContainer*>(event);
|
||||||
if (container == NULL)
|
if (container != NULL)
|
||||||
return NULL;
|
orEvent = new OrEvent(container->Owner(), container->Target());
|
||||||
|
else
|
||||||
orEvent = new OrEvent(container->Owner(), container->Target());
|
orEvent = new OrEvent(NULL, target);
|
||||||
}
|
}
|
||||||
if (orEvent != event && event != NULL)
|
if (orEvent != event && event != NULL)
|
||||||
orEvent->AddEvent(event);
|
orEvent->AddEvent(event);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class Events {
|
|||||||
public:
|
public:
|
||||||
static Event* FromMessage(const BMessenger& target,
|
static Event* FromMessage(const BMessenger& target,
|
||||||
const BMessage& message);
|
const BMessage& message);
|
||||||
static Event* AddOnDemand(Event* event);
|
static Event* AddOnDemand(const BMessenger& target, Event* event);
|
||||||
static bool ResolveRegisteredEvent(Event* event,
|
static bool ResolveRegisteredEvent(Event* event,
|
||||||
const char* name);
|
const char* name);
|
||||||
static void TriggerRegisteredEvent(Event* event,
|
static void TriggerRegisteredEvent(Event* event,
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ static const char* kLaunchDirectory = "launch";
|
|||||||
static const char* kUserLaunchDirectory = "user_launch";
|
static const char* kUserLaunchDirectory = "user_launch";
|
||||||
|
|
||||||
|
|
||||||
|
enum launch_options {
|
||||||
|
FORCE_NOW = 0x01,
|
||||||
|
TRIGGER_DEMAND = 0x02
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
public:
|
public:
|
||||||
Session(uid_t user, const BMessenger& target);
|
Session(uid_t user, const BMessenger& target);
|
||||||
@@ -138,7 +144,7 @@ private:
|
|||||||
void _InitJobs(Target* target);
|
void _InitJobs(Target* target);
|
||||||
void _LaunchJobs(Target* target,
|
void _LaunchJobs(Target* target,
|
||||||
bool forceNow = false);
|
bool forceNow = false);
|
||||||
void _LaunchJob(Job* job, bool forceNow = false);
|
void _LaunchJob(Job* job, uint32 options = 0);
|
||||||
void _AddTarget(Target* target);
|
void _AddTarget(Target* target);
|
||||||
void _SetCondition(BaseJob* job,
|
void _SetCondition(BaseJob* job,
|
||||||
const BMessage& message);
|
const BMessage& message);
|
||||||
@@ -490,7 +496,7 @@ LaunchDaemon::_HandleGetLaunchData(BMessage* message)
|
|||||||
if (reply.what == B_OK) {
|
if (reply.what == B_OK) {
|
||||||
// Launch the job if it hasn't been launched already
|
// Launch the job if it hasn't been launched already
|
||||||
if (launchJob)
|
if (launchJob)
|
||||||
_LaunchJob(job);
|
_LaunchJob(job, TRIGGER_DEMAND);
|
||||||
|
|
||||||
DetachCurrentMessage();
|
DetachCurrentMessage();
|
||||||
status_t result = job->HandleGetLaunchData(message);
|
status_t result = job->HandleGetLaunchData(message);
|
||||||
@@ -1021,19 +1027,23 @@ LaunchDaemon::_LaunchJobs(Target* target, bool forceNow)
|
|||||||
Calling this method will trigger a demand event.
|
Calling this method will trigger a demand event.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
LaunchDaemon::_LaunchJob(Job* job, bool forceNow)
|
LaunchDaemon::_LaunchJob(Job* job, uint32 options)
|
||||||
{
|
{
|
||||||
if (job == NULL || job->IsLaunched() || (!forceNow
|
if (job == NULL || job->IsLaunched() || ((options & FORCE_NOW) == 0
|
||||||
&& (!job->EventHasTriggered() || !job->CheckCondition(*this)
|
&& (!job->EventHasTriggered() || !job->CheckCondition(*this)
|
||||||
|| Events::TriggerDemand(job->Event())))) {
|
|| ((options & TRIGGER_DEMAND) != 0
|
||||||
|
&& Events::TriggerDemand(job->Event()))))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 count = job->Requirements().CountStrings();
|
int32 count = job->Requirements().CountStrings();
|
||||||
for (int32 index = 0; index < count; index++) {
|
for (int32 index = 0; index < count; index++) {
|
||||||
Job* requirement = FindJob(job->Requirements().StringAt(index));
|
Job* requirement = FindJob(job->Requirements().StringAt(index));
|
||||||
if (requirement != NULL)
|
if (requirement != NULL) {
|
||||||
_LaunchJob(requirement);
|
// TODO: For jobs that have their communication channels set up,
|
||||||
|
// we would not need to trigger demand at this point
|
||||||
|
_LaunchJob(requirement, TRIGGER_DEMAND);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (job->Target() != NULL)
|
if (job->Target() != NULL)
|
||||||
@@ -1087,7 +1097,7 @@ LaunchDaemon::_SetEvent(BaseJob* job, const BMessage& message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message.GetBool("on_demand")) {
|
if (message.GetBool("on_demand")) {
|
||||||
event = Events::AddOnDemand(event);
|
event = Events::AddOnDemand(this, event);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user