summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sm-helper.c19
-rw-r--r--src/sm-helper.h7
-rw-r--r--src/soundmanager.c82
3 files changed, 41 insertions, 67 deletions
diff --git a/src/sm-helper.c b/src/sm-helper.c
index 3794c30..f9e7ec3 100644
--- a/src/sm-helper.c
+++ b/src/sm-helper.c
@@ -229,3 +229,22 @@ GVariant* create_domain_data(struct domain_data* data)
AFB_DEBUG("created domainData %d", __LINE__);
return g_variant_builder_end (&builder);
}
+
+bool send_result(const GError* result_of_send, struct afb_req req, const char* function){
+ /* GError = NULL means success in case of gdbus request */
+ if(result_of_send != NULL)
+ {
+ AFB_ERROR("Unable to call %s", function);
+ afb_req_fail_f(req, "failed", "Unable to call %s", function);
+ return false;
+ }
+ return true;
+}
+
+bool send_result_no_resp(const GError* result_of_send, const char* function){
+ if(result_of_send != NULL){
+ AFB_ERROR("Unable to call %s", function);
+ return false;
+ }
+ return true;
+} \ No newline at end of file
diff --git a/src/sm-helper.h b/src/sm-helper.h
index 1737f48..8c26049 100644
--- a/src/sm-helper.h
+++ b/src/sm-helper.h
@@ -20,8 +20,10 @@
#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include <stdint.h>
+#include <stdbool.h>
#include <glib.h>
-//#include <errno.h>
+#define SEND_RESULT(...) send_result(__VA_ARGS__, __FUNCTION__)
+#define SEND_RESULT_NO_RESP(...) send_result_no_resp(__VA_ARGS__, __FUNCTION__)
typedef enum REQ_ERROR
{
@@ -89,6 +91,7 @@ GVariant* create_source_data(guint16 sourceID, guint16 domainID, const char* app
struct main_sound_property_s mainPropertyList, struct notification_config_s NConfRouting,
struct notification_config_s NConfCommand);
GVariant* create_domain_data(struct domain_data*);
-
+bool send_result_no_resp(const GError* result_of_send, const char* function);
+bool send_result(const GError* result_of_send, struct afb_req req, const char* function);
#endif /*AM_HELPER_H*/ \ No newline at end of file
diff --git a/src/soundmanager.c b/src/soundmanager.c
index 2c67f83..d8df22e 100644
--- a/src/soundmanager.c
+++ b/src/soundmanager.c
@@ -101,11 +101,7 @@ void connect (struct afb_req request)
&main_connectionID,
NULL, &err);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
/* ToDo Remember appname(key) and tie to sourceID(value) */
@@ -142,11 +138,7 @@ void disconnect (struct afb_req request)
NULL, &err);
AFB_DEBUG( "ret = %d", ret);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
struct json_object* res_obj = json_object_new_object();
sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2,
@@ -182,11 +174,7 @@ void setVolume (struct afb_req request)
NULL, &err);
AFB_DEBUG( "ret = %d", ret);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
struct json_object* res_obj = json_object_new_object();
sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2,
@@ -222,11 +210,7 @@ void volumeStep (struct afb_req request)
NULL, &err);
AFB_DEBUG( "ret = %d", ret);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
struct json_object* res_obj = json_object_new_object();
sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2,
@@ -263,11 +247,7 @@ void setSinkMuteState(struct afb_req request)
NULL, &err);
AFB_DEBUG( "ret = %d", ret);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
struct json_object* res_obj = json_object_new_object();
sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2,
@@ -292,11 +272,7 @@ void getListMainConnections(struct afb_req request)
&err
);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
/* create response */
struct json_object *array_res = json_object_new_array();
@@ -349,11 +325,7 @@ void getListMainSources(struct afb_req request)
&err
);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
/* create response */
struct json_object *response = json_object_new_object();
@@ -411,11 +383,7 @@ void getListMainSinks(struct afb_req request)
&err
);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
/* create response */
struct json_object *response = json_object_new_object();
@@ -498,11 +466,8 @@ void ackConnect(struct afb_req request)
error,
NULL, &err);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
+
/*create response json object*/
struct json_object *res = json_object_new_object();
sm_add_object_to_json_object_func(res, __FUNCTION__, 2,
@@ -541,11 +506,8 @@ void ackDisconnect(struct afb_req request)
error,
NULL, &err);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
+
/*create response json object*/
struct json_object *res = json_object_new_object();
sm_add_object_to_json_object_func(res, __FUNCTION__, 2,
@@ -578,11 +540,8 @@ void ackSetSourceState(struct afb_req request)
error,
NULL, &err);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
+
/*create response json object*/
struct json_object *res = json_object_new_object();
sm_add_object_to_json_object_func(res, __FUNCTION__, 2,
@@ -684,11 +643,7 @@ void registerSource(struct afb_req request)
NULL, &err);
g_variant_unref(input);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
/*create response json object*/
struct json_object *res = json_object_new_object();
@@ -715,11 +670,8 @@ void deregisterSource(struct afb_req request)
&ret,
NULL, &err
);
- if(err != NULL)
- {
- afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
- return;
- }
+ if(!SEND_RESULT(err, request)) return;
+
/*create response json object*/
struct json_object *res = json_object_new_object();
sm_add_object_to_json_object_func(res, __FUNCTION__, 2,