Add an API function to serialize a context handle 94/142394/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 4 Aug 2017 01:05:39 +0000 (10:05 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 4 Aug 2017 01:05:39 +0000 (10:05 +0900)
Change-Id: I11f1554fe663ff96bd17756d662c69a072f83bb9
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/job_scheduler_internal.h
src/client-dummy/job_scheduler.cpp
src/client/job_scheduler.cpp

index 9a46bb49dc60e8b26cc3508e235b74d9e8fe0460..7f5f709010ba36e72817a8001d358e4030a3edea 100644 (file)
@@ -221,14 +221,6 @@ int ctx_sched_job_create_on_demand(ctx_sched_job_h* job);
  */
 int ctx_sched_job_destroy(ctx_sched_job_h job);
 
-/**
- * @brief      Serializes a job handle.
- * @remarks    This function is not thread safe.
- * @param[in]  job                     Job handle
- * @return     The Json representation of @c job
- */
-const char* ctx_sched_job_serialize(ctx_sched_job_h job);
-
 
 /**
  * @brief      Adds a trigger context to a job.
@@ -501,6 +493,25 @@ int ctx_sched_job_context_destroy(ctx_sched_job_context_h job_context);
 int ctx_sched_publish_context_json(ctx_sched_h scheduler, const char* uri, const char* json_payload);
 
 
+/**
+ * @brief      Serializes a job handle.
+ * @remarks    This function is not thread safe.
+ * @param[in]  job                     Job handle
+ * @return     The Json representation of @c job
+ */
+const char* ctx_sched_job_serialize(ctx_sched_job_h job);
+
+/**
+ * @brief      Serializes a job context handle.
+ * @remarks    This function is not thread safe.
+ * @param[in]  job_context     Job context handle
+ * @return     The Json representation of @c job_context
+ */
+const char* ctx_sched_job_context_serialize(ctx_sched_job_context_h job_context);
+
+// Job context handler duplicator
+ctx_sched_job_context_h ctx_sched_job_context_duplicate(ctx_sched_job_context_h job_context);
+
 // Logical-disjunction modifiers to support legacy Context-Trigger API.
 // NOT recommended to use.
 int ctx_sched_job_set_disjunction(ctx_sched_job_h job, bool disjunction);
@@ -511,9 +522,6 @@ int ctx_sched_custom_register(ctx_sched_h scheduler, const char* uri);
 int ctx_sched_custom_unregister(ctx_sched_h scheduler, const char* uri);
 int ctx_sched_custom_is_registered(ctx_sched_h scheduler, const char* uri, const char* pkg_id, bool* registered);
 
-// Job context handler duplicator
-ctx_sched_job_context_h ctx_sched_job_context_duplicate(ctx_sched_job_context_h job_context);
-
 /**
  * @}
  */
index f91f80133340deb588daf7eb36731a6feafee947..1fef60eab7fadba2c0311649dce775683861bdba 100644 (file)
@@ -109,11 +109,6 @@ EXPORT_API int ctx_sched_job_destroy(ctx_sched_job_h job)
        return E_SUPPORT;
 }
 
-EXPORT_API const char* ctx_sched_job_serialize(ctx_sched_job_h job)
-{
-       return EMPTY_STR;
-}
-
 EXPORT_API int ctx_sched_job_add_trigger(ctx_sched_job_h job, ctx_sched_job_context_h trigger)
 {
        return E_SUPPORT;
@@ -257,6 +252,21 @@ EXPORT_API int ctx_sched_publish_context_json(ctx_sched_h scheduler, const char*
        return E_SUPPORT;
 }
 
+EXPORT_API const char* ctx_sched_job_serialize(ctx_sched_job_h job)
+{
+       return EMPTY_STR;
+}
+
+EXPORT_API const char* ctx_sched_job_context_serialize(ctx_sched_job_context_h job_context)
+{
+       return EMPTY_STR;
+}
+
+EXPORT_API ctx_sched_job_context_h ctx_sched_job_context_duplicate(ctx_sched_job_context_h job_context)
+{
+       return NULL;
+}
+
 EXPORT_API int ctx_sched_job_set_disjunction(ctx_sched_job_h job, bool disjunction)
 {
        return E_SUPPORT;
@@ -281,8 +291,3 @@ EXPORT_API int ctx_sched_custom_is_registered(ctx_sched_h scheduler, const char*
 {
        return E_SUPPORT;
 }
-
-EXPORT_API ctx_sched_job_context_h ctx_sched_job_context_duplicate(ctx_sched_job_context_h job_context)
-{
-       return NULL;
-}
index a53e21088658a72433c6ac5d88a24176743d9e33..1d4af95290e5a15823310426506f3858f9f5e2bd 100644 (file)
@@ -305,19 +305,6 @@ EXPORT_API int ctx_sched_job_destroy(ctx_sched_job_h job)
        return E_NONE;
 }
 
-EXPORT_API const char* ctx_sched_job_serialize(ctx_sched_job_h job)
-{
-       static std::string serialized;
-
-       Json::Value jsonRoot;
-       Json::StyledWriter writer;
-
-       job->jobInfo->toJson(jsonRoot);
-       serialized = writer.write(jsonRoot);
-
-       return serialized.c_str();
-}
-
 EXPORT_API int ctx_sched_job_add_trigger(ctx_sched_job_h job, ctx_sched_job_context_h trigger)
 {
        IF_FAIL_RETURN(job && trigger, E_PARAM);
@@ -650,6 +637,56 @@ EXPORT_API int ctx_sched_publish_context_json(ctx_sched_h scheduler, const char*
        return scheduler->jobManager.publishContext(uri, json_payload);
 }
 
+EXPORT_API const char* ctx_sched_job_serialize(ctx_sched_job_h job)
+{
+       static std::string serialized;
+
+       Json::Value jsonRoot;
+       Json::StyledWriter writer;
+
+       job->jobInfo->toJson(jsonRoot);
+       serialized = writer.write(jsonRoot);
+
+       return serialized.c_str();
+}
+
+EXPORT_API const char* ctx_sched_job_context_serialize(ctx_sched_job_context_h job_context)
+{
+       static std::string serialized;
+
+       Json::Value jsonRoot;
+       Json::StyledWriter writer;
+
+       job_context->jobContext->toJson(jsonRoot);
+       serialized = writer.write(jsonRoot);
+
+       return serialized.c_str();
+}
+
+EXPORT_API ctx_sched_job_context_h ctx_sched_job_context_duplicate(ctx_sched_job_context_h job_context)
+{
+       IF_FAIL_RETURN(job_context, NULL);
+
+       ctx_sched_job_context_s* dup = new(std::nothrow) ctx_sched_job_context_s();
+       IF_FAIL_RETURN_TAG(dup, NULL, _E, E_STR_ALLOC);
+
+       if (!job_context->jobContext)
+               return dup;
+
+       if (job_context->jobContext->getType() == JobContext::Type::TRIGGER)
+               dup->jobContext = new(std::nothrow) JobTrigger(*static_cast<JobTrigger*>(job_context->jobContext));
+       else
+               dup->jobContext = new(std::nothrow) JobRequirement(*static_cast<JobRequirement*>(job_context->jobContext));
+
+       if (!dup->jobContext) {
+               _E_ALLOC;
+               delete dup;
+               return NULL;
+       }
+
+       return dup;
+}
+
 EXPORT_API int ctx_sched_job_set_disjunction(ctx_sched_job_h job, bool disjunction)
 {
        IF_FAIL_RETURN(job, E_PARAM);
@@ -689,27 +726,3 @@ EXPORT_API int ctx_sched_custom_is_registered(ctx_sched_h scheduler, const char*
 
        return E_NONE;
 }
-
-EXPORT_API ctx_sched_job_context_h ctx_sched_job_context_duplicate(ctx_sched_job_context_h job_context)
-{
-       IF_FAIL_RETURN(job_context, NULL);
-
-       ctx_sched_job_context_s* dup = new(std::nothrow) ctx_sched_job_context_s();
-       IF_FAIL_RETURN_TAG(dup, NULL, _E, E_STR_ALLOC);
-
-       if (!job_context->jobContext)
-               return dup;
-
-       if (job_context->jobContext->getType() == JobContext::Type::TRIGGER)
-               dup->jobContext = new(std::nothrow) JobTrigger(*static_cast<JobTrigger*>(job_context->jobContext));
-       else
-               dup->jobContext = new(std::nothrow) JobRequirement(*static_cast<JobRequirement*>(job_context->jobContext));
-
-       if (!dup->jobContext) {
-               _E_ALLOC;
-               delete dup;
-               return NULL;
-       }
-
-       return dup;
-}