#ifndef __CONTEXT_JOB_SCHEDULER_SERVICE_H__
#define __CONTEXT_JOB_SCHEDULER_SERVICE_H__
+#include <vector>
#include <ISystemService.h>
#include <IServiceRunner.h>
#include <IClient.h>
// Own members
JobManager* getJobManager(uid_t uid);
+ std::vector<JobManager*> getAllJobManager();
private:
IServiceRunner* __serviceRunner;
return jobInfos;
}
+void JobManager::purgeJobOf(const std::string& ownerId)
+{
+ _I("Purge all jobs of %s from %u", ownerId.c_str(), __uid);
+
+ std::vector<JobRunner*> toPurge;
+
+ for (auto& runner : __jobRunners) {
+ if (runner->getOwner() == ownerId) {
+ toPurge.push_back(runner);
+ }
+ }
+
+ for (auto& runner : toPurge) {
+ if (runner->isStarted())
+ runner->stop();
+
+ if (runner->isPersistent())
+ __jobInfoDatabase.remove(runner->getJobId());
+
+ __removeRunner(runner);
+ }
+}
+
void JobManager::addCustom(const std::string& uri, const std::string& ownerId)
{
std::string key = uri + "@" + ownerId;
JobInfo* getJobInfo(int jobId, IClient* owner);
std::vector<JobInfo*> getAllJobInfo(IClient* owner);
+ void purgeJobOf(const std::string& ownerId);
+
// For supporting Context-Trigger's custom context registration APIs
void addCustom(const std::string& uri, const std::string& ownerId);
void removeCustom(const std::string& uri, const std::string& ownerId);
#include "MethodCallHandler.h"
#include "ContextManager.h"
#include "SchedTimer.h"
+#include "OrphanedJobCleaner.h"
#define SYSTEM_UID 0
using namespace ctx;
static std::map<uid_t, JobManager*> __jobManagers;
+static OrphanedJobCleaner* __orphanedJobCleaner = NULL;
JobSchedulerService::JobSchedulerService() :
__serviceRunner(NULL)
ContextManager::init();
SchedTimer::init();
__jobManagers.emplace(SYSTEM_UID, new JobManager(SYSTEM_UID));
+ __orphanedJobCleaner = new OrphanedJobCleaner(this);
return true;
}
void JobSchedulerService::cleanup()
{
+ delete __orphanedJobCleaner;
for (auto& it : __jobManagers) {
delete it.second;
}
return it->second;
}
+
+std::vector<JobManager*> JobSchedulerService::getAllJobManager()
+{
+ std::vector<JobManager*> managers;
+
+ for (auto& it : __jobManagers) {
+ managers.push_back(it.second);
+ }
+
+ return managers;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ServerUtil.h>
+#include <SharedUtil.h>
+#include <JobSchedulerService.h>
+#include "JobManager.h"
+#include "OrphanedJobCleaner.h"
+
+#define GLOBAL_APP_UID 376
+
+using namespace ctx;
+
+OrphanedJobCleaner::OrphanedJobCleaner(JobSchedulerService* hostService) :
+ __hostService(hostService)
+{
+ __dbusMonitor.subscribe(NULL,
+ "/org/tizen/pkgmgr/signal", "org.tizen.pkgmgr.signal", "uninstall", this);
+}
+
+OrphanedJobCleaner::~OrphanedJobCleaner()
+{
+}
+
+void OrphanedJobCleaner::onSignal(const std::string& sender, const std::string& objPath,
+ const std::string& interface, const std::string& signalName, GVariant *param)
+{
+ uint32_t uid = 0;
+ const char *pkgId = NULL;
+ const char *key = NULL;
+ const char *val = NULL;
+
+ g_variant_get(param, "(u&s&s&s&s&s&s)", &uid, NULL, NULL, &pkgId, NULL, &key, &val);
+ IF_FAIL_VOID(pkgId && STR_EQ(key, "end") && STR_EQ(val, "ok"));
+
+ _I("%s has been removed from %u", pkgId, uid);
+
+ if (uid != GLOBAL_APP_UID) {
+ JobManager* manager = __hostService->getJobManager(static_cast<uid_t>(uid));
+ if (manager)
+ manager->purgeJobOf(pkgId);
+ return;
+ }
+
+ std::vector<JobManager*> managers = __hostService->getAllJobManager();
+
+ for (auto& manager : managers) {
+ manager->purgeJobOf(pkgId);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_ORPHANED_JOB_CLEANER_H__
+#define __CONTEXT_JOB_SCHEDULER_ORPHANED_JOB_CLEANER_H__
+
+#include <DBusMonitor.h>
+#include <IDBusSignalListener.h>
+
+namespace ctx {
+
+ class JobSchedulerService;
+
+ class OrphanedJobCleaner : public IDBusSignalListener {
+ public:
+ OrphanedJobCleaner(JobSchedulerService* hostService);
+ ~OrphanedJobCleaner();
+
+ void onSignal(const std::string& sender, const std::string& objPath,
+ const std::string& interface, const std::string& signalName, GVariant *param);
+
+ private:
+ JobSchedulerService* __hostService;
+ DBusMonitor __dbusMonitor;
+ };
+
+}
+
+#endif