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);
/**
* @}
{
return E_SUPPORT;
}
+
+EXPORT_API ctx_sched_job_context_h ctx_sched_job_context_duplicate(ctx_sched_job_context_h job_context)
+{
+ return NULL;
+}
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;
+}
return NULL;
}
+Attribute* Attribute::build(const Attribute& other)
+{
+ Attribute::Type type = other.getType();
+
+ if (type == Attribute::Type::INTEGER) {
+ Attribute* dup = new IntegerAttribute(other.getName());
+ *dup = other;
+ return dup;
+
+ } else if (type == Attribute::Type::STRING) {
+ Attribute* dup = new StringAttribute(other.getName());
+ *dup = other;
+ return dup;
+ }
+
+ return NULL;
+}
IntegerAttribute::IntegerAttribute(const std::string& name) :
Attribute(name),
virtual bool operator<=(const std::string& antecedent) = 0;
static Attribute* build(const std::string& name, Json::Value& jsonNode);
+ static Attribute* build(const Attribute& other);
protected:
Attribute(const std::string& name);
using namespace ctx;
+static void __dup_attributes(std::list<Attribute*>& dest, std::list<Attribute*>& source)
+{
+ for (auto& attr : dest) {
+ delete attr;
+ }
+
+ dest.clear();
+
+ for (auto& attr : source) {
+ Attribute* dup = Attribute::build(*attr);
+ if (dup)
+ dest.push_back(dup);
+ }
+}
+
JobContext::JobContext(const std::string& uri) :
__uri(uri),
__disjunction(false)
Json::Value::Members members = attrNode.getMemberNames();
for (auto& name : members) {
- __attributes.push_back(Attribute::build(name, attrNode[name]));
+ Attribute* attr = Attribute::build(name, attrNode[name]);
+ if (attr)
+ __attributes.push_back(attr);
}
__disjunction = jsonNode[KEY_DISJUNCTION].asBool();
}
+JobContext::JobContext(JobContext& other) :
+ __uri(other.__uri),
+ __disjunction(other.__disjunction)
+{
+}
+
JobContext::~JobContext()
{
for (auto& attr : __attributes) {
{
}
+JobTrigger::JobTrigger(JobTrigger& other) :
+ JobContext(static_cast<JobContext&>(other))
+{
+ __dup_attributes(__attributes, other.__attributes);
+}
+
JobTrigger::~JobTrigger()
{
}
__optional = jsonNode[KEY_OPTIONAL].asBool();
}
+JobRequirement::JobRequirement(JobRequirement& other) :
+ JobContext(static_cast<JobContext&>(other)),
+ __optional(other.__optional)
+{
+ __dup_attributes(__attributes, other.__attributes);
+}
+
JobRequirement::~JobRequirement()
{
}
protected:
JobContext(const std::string& uri);
JobContext(const std::string& uri, Json::Value& jsonNode);
-
- private:
- virtual void __toJson(Json::Value& jsonNode) const = 0;
+ JobContext(JobContext& other);
std::string __uri;
std::list<Attribute*> __attributes;
bool __disjunction;
+
+ private:
+ virtual void __toJson(Json::Value& jsonNode) const = 0;
};
public:
JobTrigger(const std::string& uri);
JobTrigger(const std::string& uri, Json::Value& jsonNode);
+ JobTrigger(JobTrigger& other);
~JobTrigger();
JobContext::Type getType() const;
public:
JobRequirement(const std::string& uri, bool optional);
JobRequirement(const std::string& uri, Json::Value& jsonNode);
+ JobRequirement(JobRequirement& other);
~JobRequirement();
JobContext::Type getType() const;