summaryrefslogtreecommitdiffstats
path: root/ahl-binding/ahl-binding.cpp
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-07-04 12:38:27 +0200
committerLoïc Collignon <loic.collignon@iot.bzh>2018-07-10 18:15:01 +0200
commite2e78437b472dc40e605cdcd895804105a680a1f (patch)
tree83d2554d82e64d59c8c5e4a848c47507f80000d1 /ahl-binding/ahl-binding.cpp
parent7275efd56abe3bc02b6f630dc18b415916e7f030 (diff)
Fixed compilation warnings with latest jsonc
Change-Id: I87a8c0ba3fdccf6bddd6f4fb7982225c1399f130 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'ahl-binding/ahl-binding.cpp')
-rw-r--r--ahl-binding/ahl-binding.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/ahl-binding/ahl-binding.cpp b/ahl-binding/ahl-binding.cpp
index 6247371..8ac5b22 100644
--- a/ahl-binding/ahl-binding.cpp
+++ b/ahl-binding/ahl-binding.cpp
@@ -187,7 +187,6 @@ int ahl_binding_t::update_streams()
{
json_object* loaded = nullptr;
json_object* response = nullptr;
- size_t i = 0, j = 0;
size_t hals_count = 0, streams_count = 0;
if (afb_dynapi_call_sync(handle_, "4a-hal-manager", "loaded", json_object_new_object(), &loaded))
@@ -196,13 +195,18 @@ int ahl_binding_t::update_streams()
if (loaded) AFB_DYNAPI_NOTICE(handle_, "%s", json_object_to_json_string(loaded));
return -1;
}
- response = json_object_object_get(loaded, "response");
+ json_bool ret = json_object_object_get_ex(loaded, "response", &response);
+ if (!ret)
+ {
+ AFB_DYNAPI_ERROR(handle_, "Maformed response; missing 'response' field");
+ return -1;
+ }
hals_count = json_object_array_length(response);
- for(i = 0; i < hals_count; ++i)
+ for(int i = 0; i < hals_count; ++i)
{
json_object* info = nullptr;
- json_object* streams = nullptr;
+
const char* halname = json_object_get_string(json_object_array_get_idx(response, i));
AFB_DYNAPI_DEBUG(handle_, "Found an active HAL: %s", halname);
@@ -213,14 +217,24 @@ int ahl_binding_t::update_streams()
return -1;
}
- streams = json_object_object_get(json_object_object_get(info, "response"), "streams");
- streams_count = json_object_array_length(streams);
- for(j = 0; j < streams_count; ++j)
+ json_object * responseJ = nullptr;
+ json_object_object_get_ex(info, "response", &responseJ);
+
+ json_object* streamsJ = nullptr;
+ json_object_object_get_ex(responseJ, "streams", &streamsJ);
+ streams_count = json_object_array_length(streamsJ);
+ for(int j = 0; j < streams_count; ++j)
{
+ json_object * nameJ = nullptr, * cardIdJ = nullptr;
+ json_object * streamJ = json_object_array_get_idx(streamsJ, j);
+
+ json_object_object_get_ex(streamJ, "name", &nameJ);
+ json_object_object_get_ex(streamJ, "cardId", &cardIdJ);
+
update_stream(
halname,
- json_object_get_string(json_object_object_get(json_object_array_get_idx(streams, j), "name")),
- json_object_get_string(json_object_object_get(json_object_array_get_idx(streams, j), "cardId"))
+ json_object_get_string(nameJ),
+ json_object_get_string(cardIdJ)
);
}
@@ -283,7 +297,7 @@ void ahl_binding_t::load_controller_configs()
// Only one file should be found this way, but read all just in case
size_t config_files_count = json_object_array_length(config_files);
- for(size_t i = 0; i < config_files_count; ++i)
+ for(int i = 0; i < config_files_count; ++i)
{
config_entry_t file {json_object_array_get_idx(config_files, i)};
@@ -335,7 +349,7 @@ int ahl_binding_t::parse_roles_config(json_object* o)
size_t count = json_object_array_length(o);
roles_.reserve(count);
- for(size_t i = 0; i < count; ++i)
+ for(int i = 0; i < count; ++i)
{
json_object* jr = json_object_array_get_idx(o, i);
assert(jr != nullptr);