summaryrefslogtreecommitdiffstats
path: root/ahl-binding
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
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')
-rw-r--r--ahl-binding/ahl-binding.cpp36
-rw-r--r--ahl-binding/interrupt.cpp8
-rw-r--r--ahl-binding/jsonc_utils.hpp8
-rw-r--r--ahl-binding/role.cpp10
4 files changed, 43 insertions, 19 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);
diff --git a/ahl-binding/interrupt.cpp b/ahl-binding/interrupt.cpp
index fc54139..9c247b3 100644
--- a/ahl-binding/interrupt.cpp
+++ b/ahl-binding/interrupt.cpp
@@ -3,13 +3,17 @@
interrupt_t::interrupt_t(json_object* o)
{
jcast(type_, o, "type");
- args_ = json_object_object_get(o, "args");
+ json_object * value = NULL;
+ json_object_object_get_ex(o, "args", &value);
+ args_ = value;
}
interrupt_t& interrupt_t::operator<<(json_object* o)
{
jcast(type_, o, "type");
- args_ = json_object_object_get(o, "args");
+ json_object * value = NULL;
+ json_object_object_get_ex(o, "args", &value);
+ args_ = value;
return *this;
}
diff --git a/ahl-binding/jsonc_utils.hpp b/ahl-binding/jsonc_utils.hpp
index 5e82fca..097eda4 100644
--- a/ahl-binding/jsonc_utils.hpp
+++ b/ahl-binding/jsonc_utils.hpp
@@ -81,11 +81,15 @@ inline std::string& jcast<std::string>(std::string& v, json_object* o)
template<class T>
inline T& jcast(T& v, json_object* o, std::string field)
{
- return jcast<T>(v, json_object_object_get(o, field.c_str()));
+ json_object * value;
+ json_object_object_get_ex(o, field.c_str(), &value);
+ return jcast<T>(v, value);
}
template<class T>
inline T& jcast_array(T& v, json_object* o, std::string field)
{
- return jcast_array<T>(v, json_object_object_get(o, field.c_str()));
+ json_object * value;
+ json_object_object_get_ex(o, field.c_str(), &value);
+ return jcast_array<T>(v, value);
}
diff --git a/ahl-binding/role.cpp b/ahl-binding/role.cpp
index 5215a60..5b2f95e 100644
--- a/ahl-binding/role.cpp
+++ b/ahl-binding/role.cpp
@@ -168,8 +168,9 @@ void role_t::invoke(afb_request* req)
return;
}
- json_object* jaction = json_object_object_get(arg, "action");
- if (jaction == nullptr)
+ json_object* jaction;
+ json_bool ret = json_object_object_get_ex(arg, "action", &jaction);
+ if (!ret)
{
afb_request_fail(req, "No valid action!", nullptr);
return;
@@ -248,8 +249,9 @@ void role_t::volume(afb_request* r, json_object* o)
AFB_DYNAPI_NOTICE(ahl_binding_t::instance().handle(), "Granted special audio-mixer permission to change volume");
}
- json_object* value = json_object_object_get(o, "value");
- if(!value)
+ json_object* value;
+ json_bool ret = json_object_object_get_ex(o, "value", &value);
+ if (!ret)
{
afb_request_fail(r, "No value given!", nullptr);
return;