Exemplo n.º 1
0
/*!	Initializes all jobs for the specified target (may be \c NULL).
	Jobs that cannot be initialized, and those that never will be due to
	conditions, will be removed from the list.
*/
void
LaunchDaemon::_InitJobs(Target* target)
{
	for (JobMap::iterator iterator = fJobs.begin(); iterator != fJobs.end();) {
		Job* job = iterator->second;
		JobMap::iterator remove = iterator++;

		if (job->Target() != target)
			continue;

		status_t status = B_NO_INIT;
		if (job->IsEnabled()) {
			// Filter out jobs that have a constant and failing condition
			if (job->Condition() == NULL || !job->Condition()->IsConstant(*this)
				|| job->Condition()->Test(*this)) {
				std::set<BString> dependencies;
				status = job->Init(*this, dependencies);
				if (status == B_OK && job->Event() != NULL)
					status = job->Event()->Register(*this);
			}
		}

		if (status != B_OK) {
			if (status != B_NO_INIT) {
				// TODO: log error
				debug_printf("Init \"%s\" failed: %s\n", job->Name(),
					strerror(status));
			}

			// Remove jobs that won't be used later on
			fJobs.erase(remove);
			delete job;
		}
	}
}
Exemplo n.º 2
0
void
LaunchDaemon::_AddTargets(BMessage& message)
{
	BMessage targetMessage;
	for (int32 index = 0; message.FindMessage("target", index,
			&targetMessage) == B_OK; index++) {
		const char* name = targetMessage.GetString("name");
		if (name == NULL) {
			// TODO: log error
			debug_printf("Target has no name, ignoring it!\n");
			continue;
		}

		Target* target = FindTarget(name);
		if (target == NULL) {
			target = new Target(name);
			_AddTarget(target);
		} else if (targetMessage.GetBool("reset")) {
			// Remove all jobs from this target
			for (JobMap::iterator iterator = fJobs.begin();
					iterator != fJobs.end();) {
				Job* job = iterator->second;
				JobMap::iterator remove = iterator++;

				if (job->Target() == target) {
					fJobs.erase(remove);
					delete job;
				}
			}
		}

		_SetCondition(target, targetMessage);
		_SetEvent(target, targetMessage);
		_SetEnvironment(target, targetMessage);
		_AddJobs(target, targetMessage);

		if (target->Event() != NULL)
			target->Event()->Register(*this);
	}
}