Skip to content

Commit e7872f4

Browse files
committed
Added evaluation_order json serialization
Signed-off-by: Victor Moene <[email protected]>
1 parent 0ab8db5 commit e7872f4

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

libpromises/eval_context.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4074,6 +4074,32 @@ void EvalContextSetAgentEvalOrder(EvalContext *ctx, EvalOrder eval_order)
40744074
ctx->agent_eval_order = eval_order;
40754075
}
40764076

4077+
const char *EvalContextEvaluationOrderToString(EvalOrder evaluation_order)
4078+
{
4079+
if (evaluation_order == EVAL_ORDER_CLASSIC)
4080+
{
4081+
return "classic";
4082+
}
4083+
if (evaluation_order == EVAL_ORDER_TOP_DOWN)
4084+
{
4085+
return "top_down";
4086+
}
4087+
return "undefined";
4088+
}
4089+
4090+
EvalOrder EvalContextEvaluationOrderFromString(const char *evaluation_order_string)
4091+
{
4092+
if (StringEqual(evaluation_order_string, "classic"))
4093+
{
4094+
return EVAL_ORDER_CLASSIC;
4095+
}
4096+
if (StringEqual(evaluation_order_string, "top_down"))
4097+
{
4098+
return EVAL_ORDER_TOP_DOWN;
4099+
}
4100+
return EVAL_ORDER_UNDEFINED;
4101+
}
4102+
40774103
bool EvalContextIsClassicOrder(EvalContext *ctx, const Bundle *bp)
40784104
{
40794105
assert(ctx != NULL);

libpromises/eval_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ void EvalContextProfilingEnd(EvalContext *ctx, const Policy *policy);
454454

455455
void EvalContextSetCommonEvalOrder(EvalContext *ctx, EvalOrder eval_order);
456456
void EvalContextSetAgentEvalOrder(EvalContext *ctx, EvalOrder eval_order);
457+
const char *EvalContextEvaluationOrderToString(EvalOrder evaluation_order);
458+
EvalOrder EvalContextEvaluationOrderFromString(const char *evaluation_order_string);
457459
bool EvalContextIsClassicOrder(EvalContext *ctx, const Bundle *bp);
458460

459461
#endif

libpromises/policy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,7 @@ JsonElement *BundleToJson(const Bundle *bundle)
19191919
JsonObjectAppendString(json_bundle, "namespace", bundle->ns);
19201920
JsonObjectAppendString(json_bundle, "name", bundle->name);
19211921
JsonObjectAppendString(json_bundle, "bundleType", bundle->type);
1922+
JsonObjectAppendString(json_bundle, "evaluation_order", EvalContextEvaluationOrderToString(bundle->evaluation_order));
19221923

19231924
{
19241925
JsonElement *json_args = JsonArrayCreate(10);
@@ -2303,6 +2304,7 @@ static Bundle *PolicyAppendBundleJson(Policy *policy, JsonElement *json_bundle)
23032304
const char *name = JsonObjectGetAsString(json_bundle, "name");
23042305
const char *type = JsonObjectGetAsString(json_bundle, "bundleType");
23052306
const char *source_path = JsonObjectGetAsString(json_bundle, "sourcePath");
2307+
const char *evaluation_order_string = JsonObjectGetAsString(json_bundle, "evaluation_order");
23062308

23072309
Rlist *args = NULL;
23082310
{
@@ -2314,7 +2316,7 @@ static Bundle *PolicyAppendBundleJson(Policy *policy, JsonElement *json_bundle)
23142316
}
23152317

23162318
// TODO: add eval order in json
2317-
Bundle *bundle = PolicyAppendBundle(policy, ns, name, type, args, source_path, EVAL_ORDER_UNDEFINED);
2319+
Bundle *bundle = PolicyAppendBundle(policy, ns, name, type, args, source_path, EvalContextEvaluationOrderFromString(evaluation_order_string));
23182320

23192321
{
23202322
JsonElement *json_promise_types = JsonObjectGetAsArray(json_bundle, "promiseTypes");

0 commit comments

Comments
 (0)