Skip to content

Commit

Permalink
C++ REAPI: implement find
Browse files Browse the repository at this point in the history
  • Loading branch information
milroy committed Feb 13, 2025
1 parent 33e8528 commit 96eff0c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
17 changes: 17 additions & 0 deletions resource/reapi/bindings/c++/reapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ class reapi_t {
{
return -1;
}

/*! Find a subgraph based on input criteria.
*
* \param h Opaque handle. How it is used is an implementation
* detail. However, when it is used within a Flux's
* service module, it is expected to be a pointer
* to a flux_t object.
* \param criteria input string of criteria to match.
* \param out return string
* \return 0 on success; -1 on error.
*/
static int info (void *h,
const std::string &criteria,
std::string &out)
{
return -1;
}
};

} // namespace resource_model
Expand Down
2 changes: 1 addition & 1 deletion resource/reapi/bindings/c++/reapi_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class reapi_cli_t : public reapi_t {
const std::string &R,
bool noent_ok,
bool &full_removal);
static int find (void *h, std::string criteria, json_t *&o);
static int find (void *h, const std::string &criteria, std::string &out);
static int info (void *h,
const uint64_t jobid,
std::string &mode,
Expand Down
22 changes: 21 additions & 1 deletion resource/reapi/bindings/c++/reapi_cli_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,14 @@ int reapi_cli_t::cancel (void *h,
return rc;
}

int reapi_cli_t::find (void *h, std::string criteria, json_t *&o)
int reapi_cli_t::find (void *h, const std::string &criteria, std::string &out)
{
int rc = -1;
resource_query_t *rq = static_cast<resource_query_t *> (h);
json_t *o = nullptr;
char *json_str = nullptr;

out = "";
if ((rc = rq->traverser_find (criteria)) < 0) {
if (rq->get_traverser_err_msg () != "") {
m_err_msg += __FUNCTION__;
Expand All @@ -251,6 +254,23 @@ int reapi_cli_t::find (void *h, std::string criteria, json_t *&o)
return rc;
}

if (o) {
if (json_is_string (o)) {
out = json_string_value (o);
} else if (!(json_str = json_dumps (o, JSON_INDENT (0)))) {
json_decref (o);
o = NULL;
errno = ENOMEM;
rc = -1;
goto done;
} else if (json_str) {
out = json_str;
free (json_str);
}
json_decref (o);
}

done:
return rc;
}

Expand Down

0 comments on commit 96eff0c

Please sign in to comment.