diff options
author | Farshid Monhaseri <monhaseri.f@gmail.com> | 2020-11-10 14:20:08 +0330 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2020-11-10 15:04:30 +0000 |
commit | 980b0dbc25e1b423562b87bc402c09329c039212 (patch) | |
tree | bf579d7e5125e9926b1da9f3afdd58c861af3ea8 /src/platform-info-binding.c | |
parent | 172db50c33beeb53f8e75c115699179be880b960 (diff) |
Add 'scan' verb for runtime device scan
Changes:
- Add 'scan' verb so client can pass 'filter'(udev rules in JSON
format) and 'mask' (desired data fields mask) arguments.
'filter' & 'mask' can include 'properties' and 'attributes' sub-
fields so their key & values act as parameters for device scanning
and mask the scanned devices properties & attributes when service
report back. The 'filter' argument can contain an additional field
with 'tags' key and JSON array value hence the tags will match for
device scanning too.
Bug-AGL: SPEC-3512
Signed-off-by: Farshid Monhaseri <monhaseri.f@gmail.com>
Change-Id: I83e91ec4405a8144e1ee813633c4895214b5b9df
Diffstat (limited to 'src/platform-info-binding.c')
-rw-r--r-- | src/platform-info-binding.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/platform-info-binding.c b/src/platform-info-binding.c index 4ae3c70..8aecdfe 100644 --- a/src/platform-info-binding.c +++ b/src/platform-info-binding.c @@ -172,17 +172,35 @@ afv_static_info(const char* dir) { return static_info; } +void afv_scan(afb_req_t req) { + json_object* jres = NULL; + json_object* jfilter = NULL; + json_object* jmask = NULL; + json_object* jargs = afb_req_json(req); + + if(json_object_is_type(jargs,json_type_object)) { + json_object_object_get_ex(jargs,"filter",&jfilter); + json_object_object_get_ex(jargs,"mask",&jmask); + } + + jres = pinfo_device_scan(jfilter,jmask); + + if(jres) { + afb_req_success(req,jres,"Scan success"); + } else { + afb_req_fail(req,"failed","Scan failed"); + } +} + int init(afb_api_t api) { // Initializing the platform_info binding object and associated it to // the api - AFB_DEBUG("init() ..."); pinfo_api_ctx_t *api_ctx = NULL; int ret = PINFO_OK; api_ctx = malloc(sizeof(*api_ctx)); if(api_ctx) { - AFB_DEBUG("init() ... OK"); api_ctx->info = afv_static_info(PLATFORM_INFO_DIR); AFB_API_DEBUG(api,"The API static data: %s", json_object_to_json_string_ext(api_ctx->info, JSON_C_TO_STRING_PRETTY)); |