Wrong error handling when fire diagnostic request.
[apps/agl-service-can-low-level.git] / src / low-can-binding.cpp
index 0b7cd8f..2b04fa8 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "low-can-binding.hpp"
 
+#include <map>
 #include <queue>
 #include <mutex>
 #include <vector>
@@ -55,7 +56,7 @@ static int make_subscription_unsubscription(struct afb_req request, const std::s
        /* Make the subscription or unsubscription to the event */
        if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s[sig_name])) < 0)
        {
-               ERROR(binder_interface, "Operation goes wrong for signal: %s", sig_name.c_str());
+               ERROR(binder_interface, "make_subscription_unsubscription: Operation goes wrong for signal: %s", sig_name.c_str());
                return 0;
        }
        return 1;
@@ -67,7 +68,7 @@ static int create_event_handle(const std::string& sig_name, std::map<std::string
        s[sig_name] = afb_daemon_make_event(binder_interface->daemon, sig_name.c_str());
        if (!afb_event_is_valid(s[sig_name]))
        {
-               ERROR(binder_interface, "Can't create an event for %s, something goes wrong.", sig_name.c_str());
+               ERROR(binder_interface, "create_event_handle: Can't create an event for %s, something goes wrong.", sig_name.c_str());
                return 0;
        }
        return 1;
@@ -88,7 +89,7 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
                }
                /*else
                {
-                       // Event it isn't valid annymore, recreate it 
+                       // Event it isn't valid annymore, recreate it
                        ret = create_event_handle(sig, s);
                }*/
        }
@@ -134,6 +135,11 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe,
                        configuration_t::instance().find_diagnostic_messages(build_DynamicField(sig), found);
                        DiagnosticRequest* diag_req = new DiagnosticRequest(found.front()->build_diagnostic_request());
 
+                       // If the requested diagnostic message isn't supported by the car then unssubcribe.
+                       // no matter what we want, worse case will be a fail unsubscription but at least we don't
+                       // poll a PID for nothing.
+                       if(found.front()->get_supported())
+                               subscribe = false;
                        if(subscribe)
                        {
                                float frequency = found.front()->get_frequency();