Add the skeleton of JobManagerProxy, which is used to implement the API 74/133774/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 13 Jun 2017 09:48:47 +0000 (18:48 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 13 Jun 2017 11:53:59 +0000 (20:53 +0900)
Change-Id: I6ba2218ec0259b35ebcc689de58c9f83f7a53965
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/job_scheduler_internal.h
src/client/JobManagerProxy.cpp [new file with mode: 0644]
src/client/JobManagerProxy.h [new file with mode: 0644]
src/client/job_scheduler.cpp
src/shared/JobInfo.cpp
src/shared/JobInfo.h

index 716bc9accf65c8c737fcd648c6374b7dc3b84415..30c6007bae7f256a85f5a34f85a4ebf11db57d16 100644 (file)
@@ -301,14 +301,18 @@ int ctx_sched_job_get_user_data(ctx_sched_job_h job, const char** user_data);
 
 /**
  * @brief      Checks whether the trigger context corresponding to a URI is supported.
+ * @param[in]  scheduler       TBD
  * @param[in]  uri                     URI
  * @param[out] supported       @c true, if the corresponding context is supported as a trigger
  * @return     @c 0 on success, otherwise a negative error value
  */
-int ctx_sched_job_trigger_is_supported(const char* uri, bool* supported);
+int ctx_sched_job_trigger_is_supported(ctx_sched_h scheduler, const char* uri, bool* supported);
 
 /**
  * @brief      Creates a trigger context handle.
+ * @remarks    Before creating a trigger context handle, It is strongly recommended to check
+ *                     the availability of the trigger corresponding to the given URI using
+ *                     ctx_sched_job_trigger_is_supported().
  * @param[in]  uri                     URI
  * @param[out] job_context     Trigger context handle
  * @return     @c 0 on success, otherwise a negative error value
@@ -317,14 +321,18 @@ int ctx_sched_job_trigger_create(const char* uri, ctx_sched_job_context_h* job_c
 
 /**
  * @brief      Checks whether the requirement context corresponding to a URI is supported.
+ * @param[in]  scheduler       TBD
  * @param[in]  uri                     URI
  * @param[out] supported       @c true, if the corresponding context is supported as a requirement
  * @return     @c 0 on success, otherwise a negative error value
  */
-int ctx_sched_job_requirement_is_supported(const char* uri, bool* supported);
+int ctx_sched_job_requirement_is_supported(ctx_sched_h scheduler, const char* uri, bool* supported);
 
 /**
  * @brief      Creates a requirement context handle.
+ * @remarks    Before creating a requirement context handle, It is strongly recommended to check
+ *                     the availability of the requirement corresponding to the given URI using
+ *                     ctx_sched_job_requirement_is_supported().
  * @param[in]  uri                     URI
  * @param[in]  optional        @c true, if the requirement is optional
  * @param[out] job_context     Requirement context handle
diff --git a/src/client/JobManagerProxy.cpp b/src/client/JobManagerProxy.cpp
new file mode 100644 (file)
index 0000000..27decb9
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+#include <JobSchedulerTypesPrivate.h>
+#include "JobManagerProxy.h"
+
+using namespace ctx;
+
+JobManagerProxy::JobManagerProxy() :
+       __serviceProxy(CTX_JOB_SCHEDULER)
+{
+}
+
+JobManagerProxy::~JobManagerProxy()
+{
+}
+
+int JobManagerProxy::addJob(JobInfo* jobInfo)
+{
+       //TODO: return a positive jobId or a negative error value
+       return E_SUPPORT;
+}
+
+int JobManagerProxy::startJob(int jobId)
+{
+       //TODO
+       return E_SUPPORT;
+}
+
+int JobManagerProxy::stopJob(int jobId)
+{
+       //TODO
+       return E_SUPPORT;
+}
+
+int JobManagerProxy::removeJob(int jobId)
+{
+       //TODO
+       return E_SUPPORT;
+}
+
+JobInfo* JobManagerProxy::getJob(int jobId)
+{
+       //TODO: throwable
+       return NULL;
+}
+
+std::vector<JobInfo*> JobManagerProxy::getAllJob()
+{
+       //TODO: throwable
+       std::vector<JobInfo*> jobInfos;
+       return jobInfos;
+}
+
+void JobManagerProxy::setStopJobCb(void (*stopJobCb)(JobInfo*, void*), void* userData)
+{
+       //TODO
+}
+
+bool JobManagerProxy::isAvailableTrigger(const std::string& uri)
+{
+       //TODO: throwable
+       return false;
+}
+
+bool JobManagerProxy::isAvailableRequirement(const std::string& uri)
+{
+       //TODO: throwable
+       return false;
+}
diff --git a/src/client/JobManagerProxy.h b/src/client/JobManagerProxy.h
new file mode 100644 (file)
index 0000000..69a4f8d
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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_MANAGER_PROXY_H__
+#define __CONTEXT_JOB_SCHEDULER_MANAGER_PROXY_H__
+
+#include <vector>
+#include <string>
+#include <ServiceProxy.h>
+#include <JobInfo.h>
+
+namespace ctx {
+
+       class JobManagerProxy {
+       public:
+               JobManagerProxy();
+               ~JobManagerProxy();
+
+               int addJob(JobInfo* jobInfo);
+               int removeJob(int jobId);
+
+               int startJob(int jobId);
+               int stopJob(int jobId);
+
+               JobInfo* getJob(int jobId);
+               std::vector<JobInfo*> getAllJob();
+
+               void setStopJobCb(void (*stopJobCb)(JobInfo*, void*), void* userData);
+
+               bool isAvailableTrigger(const std::string& uri);
+               bool isAvailableRequirement(const std::string& uri);
+
+       private:
+               ServiceProxy __serviceProxy;
+       };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_MANAGER_PROXY_H__ */
index bc4d2456b44c2349171d8b817aecf3b2b8fc7ef0..26c468579bff0a0f17f1a8813dd72dcdfe5826f8 100644 (file)
  * limitations under the License.
  */
 
-#include <ServiceProxy.h>
+#include <algorithm>
 #include <JobSchedulerTypesPrivate.h>
 #include <job_scheduler_internal.h>
 #include <JobInfo.h>
 #include <JobContext.h>
 #include <JobAction.h>
 #include <Attribute.h>
+#include "JobManagerProxy.h"
 
 #define ASSERT_ALLOC(PTR)      IF_FAIL_RETURN_TAG((PTR), E_NO_MEM, _E, E_STR_ALLOC)
 
 using namespace ctx;
 
+
 typedef struct _ctx_sched_s {
-       ServiceProxy proxy;     //FIXME
-       _ctx_sched_s() : proxy(CTX_JOB_SCHEDULER) {}
+       JobManagerProxy jobManager;
+       ctx_sched_stop_job_cb stopJobCb;
+       void* userData;
+
+       _ctx_sched_s() :
+               stopJobCb(NULL), userData(NULL) {}
 } ctx_sched_s;
 
+
 typedef struct _ctx_sched_job_s {
-       int jobId;
-       bool started;
        JobInfo* jobInfo;
-       _ctx_sched_job_s() : jobId(-1), started(false), jobInfo(NULL) {}
-       ~_ctx_sched_job_s() { delete jobInfo; }
+
+       _ctx_sched_job_s() :
+               jobInfo(NULL) {}
+
+       ~_ctx_sched_job_s()
+       {
+               delete jobInfo;
+       }
 } ctx_sched_job_s;
 
+
 typedef struct _ctx_sched_job_context_s {
        JobContext* jobContext;
-       _ctx_sched_job_context_s() : jobContext(NULL) {}
-       ~_ctx_sched_job_context_s() { delete jobContext; }
+
+       _ctx_sched_job_context_s() :
+               jobContext(NULL) {}
+
+       ~_ctx_sched_job_context_s()
+       {
+               delete jobContext;
+       }
 } ctx_sched_job_context_s;
 
 
@@ -52,13 +70,16 @@ EXPORT_API int ctx_sched_create(ctx_sched_h* scheduler)
        ASSERT_ALLOC(sched);
 
        *scheduler = sched;
+
        return E_NONE;
 }
 
 EXPORT_API int ctx_sched_destroy(ctx_sched_h scheduler)
 {
        IF_FAIL_RETURN(scheduler, E_PARAM);
+
        delete scheduler;
+
        return E_NONE;
 }
 
@@ -75,6 +96,7 @@ EXPORT_API int ctx_sched_schedule(ctx_sched_h scheduler, ctx_sched_job_h job, in
        }
 
        *job_id = jid;
+
        return E_NONE;
 }
 
@@ -87,9 +109,11 @@ EXPORT_API int ctx_sched_cancel(ctx_sched_h scheduler, int job_id)
 static bool __cancelJob(ctx_sched_h scheduler, ctx_sched_job_h job, void* user_data)
 {
        int jid = -1;
+
        ctx_sched_job_get_id(job, &jid);
        ctx_sched_cancel(scheduler, jid);
        ctx_sched_job_destroy(job);
+
        return true;
 }
 
@@ -102,56 +126,104 @@ EXPORT_API int ctx_sched_add_job(ctx_sched_h scheduler, ctx_sched_job_h job, int
 {
        IF_FAIL_RETURN(scheduler && job && job_id, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       int jid = scheduler->jobManager.addJob(job->jobInfo);
+       IF_FAIL_RETURN(jid > 0, jid);
+
+       *job_id = jid;
+       job->jobInfo->setId(jid);
+
+       return E_NONE;
 }
 
 EXPORT_API int ctx_sched_start_job(ctx_sched_h scheduler, int job_id)
 {
        IF_FAIL_RETURN(scheduler && job_id > 0, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       return scheduler->jobManager.startJob(job_id);
 }
 
 EXPORT_API int ctx_sched_stop_job(ctx_sched_h scheduler, int job_id)
 {
        IF_FAIL_RETURN(scheduler && job_id > 0, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       return scheduler->jobManager.stopJob(job_id);
 }
 
 EXPORT_API int ctx_sched_remove_job(ctx_sched_h scheduler, int job_id)
 {
        IF_FAIL_RETURN(scheduler && job_id > 0, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       return scheduler->jobManager.removeJob(job_id);
 }
 
 EXPORT_API int ctx_sched_get_job(ctx_sched_h scheduler, int job_id, ctx_sched_job_h* job)
 {
        IF_FAIL_RETURN(scheduler && job_id > 0 && job, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       ctx_sched_job_s* jobHandle = new(std::nothrow) ctx_sched_job_s();
+       ASSERT_ALLOC(jobHandle);
+
+       try {
+               jobHandle->jobInfo = scheduler->jobManager.getJob(job_id);
+       } catch (const int err) {
+               delete jobHandle;
+               return err;
+       }
+
+       return E_NONE;
 }
 
 EXPORT_API int ctx_sched_foreach_job(ctx_sched_h scheduler, ctx_sched_foreach_job_cb callback, void* user_data)
 {
        IF_FAIL_RETURN(scheduler && callback, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       std::vector<JobInfo*> jobInfos;
+
+       try {
+               jobInfos = scheduler->jobManager.getAllJob();
+       } catch (const int err) {
+               return err;
+       }
+
+       for (auto& jobInfo : jobInfos) {
+               ctx_sched_job_s* jobHandle = new(std::nothrow) ctx_sched_job_s();
+               if (jobHandle == NULL) {
+                       _E_ALLOC;
+                       std::for_each(jobInfos.begin(), jobInfos.end(), [](JobInfo*& j){ delete j; });
+                       return E_NO_MEM;
+               }
+
+               jobHandle->jobInfo = jobInfo;
+               jobInfo = NULL;
+
+               if (!callback(scheduler, jobHandle, user_data)) {
+                       std::for_each(jobInfos.begin(), jobInfos.end(), [](JobInfo*& j){ delete j; });
+                       break;
+               }
+       }
+
+       return E_NONE;
+}
+
+static void __stopJob(JobInfo* jobInfo, void* userData)
+{
+       ctx_sched_s* scheduler = static_cast<ctx_sched_s*>(userData);
+       ctx_sched_job_s* job = new(std::nothrow) ctx_sched_job_s();
+       IF_FAIL_VOID_TAG(job, _E, E_STR_ALLOC);
+
+       job->jobInfo = jobInfo;
+       scheduler->stopJobCb(scheduler, job, scheduler->userData);
 }
 
 EXPORT_API int ctx_sched_set_stop_job_cb(ctx_sched_h scheduler, ctx_sched_stop_job_cb callback, void* user_data)
 {
        IF_FAIL_RETURN(scheduler && callback, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       scheduler->stopJobCb = callback;
+       scheduler->userData = user_data;
+       scheduler->jobManager.setStopJobCb(__stopJob, scheduler);
+
+       return E_NONE;
 }
 
 EXPORT_API int ctx_sched_job_create_periodic(unsigned int interval, time_t anchor, ctx_sched_job_h* job)
@@ -169,6 +241,7 @@ EXPORT_API int ctx_sched_job_create_periodic(unsigned int interval, time_t ancho
        }
 
        *job = _job;
+
        return E_NONE;
 }
 
@@ -187,6 +260,7 @@ EXPORT_API int ctx_sched_job_create_on_demand(ctx_sched_job_h* job)
        }
 
        *job = _job;
+
        return E_NONE;
 }
 
@@ -195,6 +269,7 @@ EXPORT_API int ctx_sched_job_destroy(ctx_sched_job_h job)
        IF_FAIL_RETURN(job, E_PARAM);
 
        delete job;
+
        return E_NONE;
 }
 
@@ -205,6 +280,7 @@ EXPORT_API int ctx_sched_job_add_trigger(ctx_sched_job_h job, ctx_sched_job_cont
        IF_FAIL_RETURN(trigger->jobContext->getType() == JobContext::Type::TRIGGER, E_PARAM);
 
        static_cast<OnDemandJobInfo*>(job->jobInfo)->addTrigger(static_cast<JobTrigger*>(trigger->jobContext));
+
        return E_NONE;
 }
 
@@ -214,6 +290,7 @@ EXPORT_API int ctx_sched_job_add_requirement(ctx_sched_job_h job, ctx_sched_job_
        IF_FAIL_RETURN(requirement->jobContext->getType() == JobContext::Type::REQUIREMENT, E_PARAM);
 
        job->jobInfo->addRequirement(static_cast<JobRequirement*>(requirement->jobContext));
+
        return E_NONE;
 }
 
@@ -222,6 +299,7 @@ EXPORT_API int ctx_sched_job_set_requirement_timeout(ctx_sched_job_h job, unsign
        IF_FAIL_RETURN(job, E_PARAM);
 
        job->jobInfo->setRequirementTimeout(timeout);
+
        return E_NONE;
 }
 
@@ -230,6 +308,7 @@ EXPORT_API int ctx_sched_job_set_persistent(ctx_sched_job_h job, bool persistent
        IF_FAIL_RETURN(job, E_PARAM);
 
        job->jobInfo->setPersistent(persistent);
+
        return E_NONE;
 }
 
@@ -238,6 +317,7 @@ EXPORT_API int ctx_sched_job_set_one_time(ctx_sched_job_h job, bool one_time)
        IF_FAIL_RETURN(job, E_PARAM);
 
        job->jobInfo->setOneTime(one_time);
+
        return E_NONE;
 }
 
@@ -249,6 +329,7 @@ EXPORT_API int ctx_sched_job_set_app_control(ctx_sched_job_h job, bundle* app_co
        ASSERT_ALLOC(action);
 
        job->jobInfo->setAction(action);
+
        return E_NONE;
 }
 
@@ -262,6 +343,7 @@ EXPORT_API int ctx_sched_job_set_dbus(ctx_sched_job_h job,
        ASSERT_ALLOC(action);
 
        job->jobInfo->setAction(action);
+
        return E_NONE;
 }
 
@@ -270,6 +352,7 @@ EXPORT_API int ctx_sched_job_set_user_data(ctx_sched_job_h job, const char* user
        IF_FAIL_RETURN(job && user_data, E_PARAM);
 
        job->jobInfo->setUserData(user_data);
+
        return E_NONE;
 }
 
@@ -277,7 +360,8 @@ EXPORT_API int ctx_sched_job_is_started(ctx_sched_job_h job, bool* started)
 {
        IF_FAIL_RETURN(job && started, E_PARAM);
 
-       *started = job->started;
+       *started = job->jobInfo->isStarted();
+
        return E_NONE;
 }
 
@@ -285,7 +369,8 @@ EXPORT_API int ctx_sched_job_get_id(ctx_sched_job_h job, int* job_id)
 {
        IF_FAIL_RETURN(job && job_id, E_PARAM);
 
-       *job_id = job->jobId;
+       *job_id = job->jobInfo->getId();
+
        return E_NONE;
 }
 
@@ -294,14 +379,20 @@ EXPORT_API int ctx_sched_job_get_user_data(ctx_sched_job_h job, const char** use
        IF_FAIL_RETURN(job && user_data, E_PARAM);
 
        *user_data = job->jobInfo->getUserData().c_str();
+
        return E_NONE;
 }
 
-EXPORT_API int ctx_sched_job_trigger_is_supported(const char* uri, bool* supported)
+EXPORT_API int ctx_sched_job_trigger_is_supported(ctx_sched_h scheduler, const char* uri, bool* supported)
 {
-       IF_FAIL_RETURN(uri && supported, E_PARAM);
+       IF_FAIL_RETURN(scheduler && uri && supported, E_PARAM);
+
+       try {
+               *supported = scheduler->jobManager.isAvailableTrigger(uri);
+       } catch (const int& err) {
+               return err;
+       }
 
-       //TODO
        return E_NONE;
 }
 
@@ -309,10 +400,6 @@ EXPORT_API int ctx_sched_job_trigger_create(const char* uri, ctx_sched_job_conte
 {
        IF_FAIL_RETURN(uri && job_context, E_PARAM);
 
-       bool supported = false;
-       ctx_sched_job_trigger_is_supported(uri, &supported);
-       IF_FAIL_RETURN(supported, E_SUPPORT);
-
        ctx_sched_job_context_s* jobCtxHandle = new(std::nothrow) ctx_sched_job_context_s();
        ASSERT_ALLOC(jobCtxHandle);
 
@@ -324,25 +411,27 @@ EXPORT_API int ctx_sched_job_trigger_create(const char* uri, ctx_sched_job_conte
        }
 
        *job_context = jobCtxHandle;
+
        return E_NONE;
 }
 
-EXPORT_API int ctx_sched_job_requirement_is_supported(const char* uri, bool* supported)
+EXPORT_API int ctx_sched_job_requirement_is_supported(ctx_sched_h scheduler, const char* uri, bool* supported)
 {
-       IF_FAIL_RETURN(uri && supported, E_PARAM);
+       IF_FAIL_RETURN(scheduler && uri && supported, E_PARAM);
 
-       //TODO
-       return E_SUPPORT;
+       try {
+               *supported = scheduler->jobManager.isAvailableRequirement(uri);
+       } catch (const int& err) {
+               return err;
+       }
+
+       return E_NONE;
 }
 
 EXPORT_API int ctx_sched_job_requirement_create(const char* uri, bool optional, ctx_sched_job_context_h* job_context)
 {
        IF_FAIL_RETURN(uri && job_context, E_PARAM);
 
-       bool supported = false;
-       ctx_sched_job_requirement_is_supported(uri, &supported);
-       IF_FAIL_RETURN(supported, E_SUPPORT);
-
        ctx_sched_job_context_s* jobCtxHandle = new(std::nothrow) ctx_sched_job_context_s();
        ASSERT_ALLOC(jobCtxHandle);
 
@@ -354,6 +443,7 @@ EXPORT_API int ctx_sched_job_requirement_create(const char* uri, bool optional,
        }
 
        *job_context = jobCtxHandle;
+
        return E_NONE;
 }
 
@@ -362,6 +452,7 @@ EXPORT_API int ctx_sched_job_context_prepare_name_int(ctx_sched_job_context_h jo
        IF_FAIL_RETURN(job_context && name, E_PARAM);
 
        bool ret = job_context->jobContext->prepareAttributeInt(name);
+
        return ret ? E_NONE : E_PARAM;
 }
 
@@ -370,6 +461,7 @@ EXPORT_API int ctx_sched_job_context_prepare_name_str(ctx_sched_job_context_h jo
        IF_FAIL_RETURN(job_context && name, E_PARAM);
 
        bool ret = job_context->jobContext->prepareAttributeStr(name);
+
        return ret ? E_NONE : E_PARAM;
 }
 
@@ -382,6 +474,7 @@ EXPORT_API int ctx_sched_job_context_name_add_eq_int(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
        static_cast<IntegerAttribute*>(attr)->addTarget(value);
+
        return E_NONE;
 }
 
@@ -394,6 +487,7 @@ EXPORT_API int ctx_sched_job_context_name_add_eq_str(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::STRING, E_PARAM);
 
        static_cast<StringAttribute*>(attr)->addTarget(value);
+
        return E_NONE;
 }
 
@@ -406,6 +500,7 @@ EXPORT_API int ctx_sched_job_context_name_add_ne_int(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
        static_cast<IntegerAttribute*>(attr)->addNonTarget(value);
+
        return E_NONE;
 }
 
@@ -418,6 +513,7 @@ EXPORT_API int ctx_sched_job_context_name_add_ne_str(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::STRING, E_PARAM);
 
        static_cast<StringAttribute*>(attr)->addNonTarget(value);
+
        return E_NONE;
 }
 
@@ -430,6 +526,7 @@ EXPORT_API int ctx_sched_job_context_name_set_gt_int(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
        static_cast<IntegerAttribute*>(attr)->setOpenLowerBound(value);
+
        return E_NONE;
 }
 
@@ -442,6 +539,7 @@ EXPORT_API int ctx_sched_job_context_name_set_ge_int(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
        static_cast<IntegerAttribute*>(attr)->setClosedLowerBound(value);
+
        return E_NONE;
 }
 
@@ -454,6 +552,7 @@ EXPORT_API int ctx_sched_job_context_name_set_lt_int(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
        static_cast<IntegerAttribute*>(attr)->setOpenUpperBound(value);
+
        return E_NONE;
 }
 
@@ -466,6 +565,7 @@ EXPORT_API int ctx_sched_job_context_name_set_le_int(ctx_sched_job_context_h job
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
        static_cast<IntegerAttribute*>(attr)->setClosedUpperBound(value);
+
        return E_NONE;
 }
 
@@ -474,6 +574,7 @@ EXPORT_API int ctx_sched_job_context_destroy(ctx_sched_job_context_h job_context
        IF_FAIL_RETURN(job_context, E_PARAM);
 
        delete job_context;
+
        return E_NONE;
 }
 
@@ -511,5 +612,6 @@ EXPORT_API int ctx_sched_job_context_set_disjunction(ctx_sched_job_context_h job
        IF_FAIL_RETURN(job_context, E_PARAM);
 
        job_context->jobContext->setDisjunction(disjunction);
+
        return E_NONE;
 }
index 7e7badd15bfddd5350cdb6c33edc6d84d6d68dd4..8e752617de189b60ef786294f750d9a3cacf822d 100644 (file)
 #define KEY_USER_DATA  "UserData"
 #define KEY_INTERVAL   "Interval"
 #define KEY_ANCHOR             "Anchor"
+
 #define KEY_TRIGGER            "Trigger"
 #define KEY_REQUIREMENT        "Requirement"
 #define KEY_ACTION             "Action"
+
+#define KEY_JOB_ID             "JobId"
+#define KEY_STARTED            "Started"
+
 #define KEY_DISJUNCTION        "Disjunction"
 
 using namespace ctx;
@@ -40,6 +45,8 @@ JobInfo::JobInfo() :
        __persistent(false),
        __requirementTimeout(0),
        __action(NULL),
+       __jobId(-1),
+       __started(false),
        __disjunction(false)
 {
 }
@@ -61,6 +68,12 @@ JobInfo::JobInfo(Json::Value& jsonRoot, const std::string& serializedStr) :
                __requirements.push_back(new JobRequirement(name, reqNode[name]));
        }
 
+       if (jsonRoot.isMember(KEY_JOB_ID))
+               __jobId = jsonRoot[KEY_JOB_ID].asInt();
+
+       if (jsonRoot.isMember(KEY_STARTED))
+               __started = jsonRoot[KEY_STARTED].asBool();
+
        __disjunction = jsonRoot[KEY_DISJUNCTION].asBool();
 }
 
@@ -149,10 +162,33 @@ void JobInfo::toJson(Json::Value& jsonRoot)
 
        __toJson(jsonRoot);
 
+       jsonRoot[KEY_JOB_ID] = __jobId;
+       jsonRoot[KEY_STARTED] = __started;
+
        /* For legacy support */
        jsonRoot[KEY_DISJUNCTION] = __disjunction;
 }
 
+void JobInfo::setId(int jobId)
+{
+       __jobId = jobId;
+}
+
+int JobInfo::getId()
+{
+       return __jobId;
+}
+
+void JobInfo::setStarted(bool started)
+{
+       __started = started;
+}
+
+bool JobInfo::isStarted()
+{
+       return __started;
+}
+
 JobInfo& JobInfo::setDisjunction(bool disjunction)
 {
        __disjunction = disjunction;
index 4e5670653d80fae32d0a164bb51f5410942ef734..c55d304b82d0e63f925580cbb249d142dd7b63a3 100644 (file)
@@ -58,6 +58,12 @@ namespace ctx {
                const std::string& serialize();
                void toJson(Json::Value& jsonRoot);
 
+               void setId(int jobId);
+               int getId();
+
+               void setStarted(bool started);
+               bool isStarted();
+
                /* Legacy support */
                JobInfo& setDisjunction(bool disjunction);
 
@@ -76,6 +82,9 @@ namespace ctx {
                JobAction* __action;
                std::string __serializedStr;
 
+               int __jobId;
+               bool __started;
+
                /* Legacy support */
                bool __disjunction;
        };