aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-03-30 16:38:40 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-03-30 16:38:40 +0900
commit19751bed26db1b959584b7eeef21cc2527ac48ee (patch)
tree912c885643126d9d6db6fb1d2f873018d2fa4cfb /src
parent784e69dc7f8928f22ea1603aad8c81e4d76a24fe (diff)
Test
Change-Id: If61c650f25ca241105106bb4323e403446364d71 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/audiomanager_proxy.c70
-rw-r--r--src/sm-pending.c76
-rw-r--r--src/sm-pending.h39
-rw-r--r--src/soundmanager.c61
5 files changed, 160 insertions, 87 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f157b7d..66e640f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -26,6 +26,7 @@ set(binding_sm_sources
soundmanager.c
sm-helper.c
sm-error.c
+ sm-pending.c
audiomanager_proxy.c
dbus/audio_manager_interface.c)
diff --git a/src/audiomanager_proxy.c b/src/audiomanager_proxy.c
index b62ee8b..d4cb7bc 100644
--- a/src/audiomanager_proxy.c
+++ b/src/audiomanager_proxy.c
@@ -215,16 +215,16 @@ ErrorCode am_proxy_connect(int source, int sink, int *main_connection_id){
if(is_range_over_guint16(source) == OUT_RANGE || is_range_over_guint16(sink) == OUT_RANGE){
return OUT_RANGE;
}
- guint16 connection_id = -1, ret = UNABLE_SEND;
+ guint16 connection_id = 0, ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_connect_sync(
am_cmd_bus,
(guint16)source, (guint16)sink,
- &ret, connection_id,
+ &ret, &connection_id,
NULL, &err);
*main_connection_id = (int)connection_id;
ec = check_send_error(err, ret);
@@ -235,11 +235,11 @@ ErrorCode am_proxy_disconnect(int main_connection_id){
if(is_range_over_guint16(main_connection_id) == OUT_RANGE){
return OUT_RANGE;
}
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_disconnect_sync(
am_cmd_bus,
(guint16)main_connection_id,
@@ -253,11 +253,11 @@ ErrorCode am_proxy_set_volume(int sink, int volume){
if(is_range_over_guint16(sink) == OUT_RANGE && is_range_over_gint16(volume) == OUT_RANGE){
return OUT_RANGE;
}
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_set_volume_sync(
am_cmd_bus,
(guint16)sink,
@@ -271,11 +271,11 @@ ErrorCode am_proxy_volume_step(int sink, int volume){
if(is_range_over_guint16(sink) == OUT_RANGE && is_range_over_gint16(volume) == OUT_RANGE){
return OUT_RANGE;
}
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_volume_step_sync(
am_cmd_bus,
(guint16)sink,
@@ -289,25 +289,25 @@ ErrorCode am_proxy_set_sink_mute_state(int sink, int mute_state){
if(is_range_over_guint16(sink) == OUT_RANGE || is_range_over_gint16(mute_state) == OUT_RANGE){
return OUT_RANGE;
}
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_set_sink_mute_state_sync(
am_cmd_bus,
(guint16)sink, (gint16)mute_state,
- ret, NULL, &err);
+ &ret, NULL, &err);
ec = check_send_error(err, ret);
return ec;
}
ErrorCode am_proxy_get_list_main_connections(GVariant* connection_list){
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_get_list_main_connections_sync(
am_cmd_bus,
&ret,
@@ -320,11 +320,11 @@ ErrorCode am_proxy_get_list_main_connections(GVariant* connection_list){
}
ErrorCode am_proxy_get_list_main_sources(GVariant* source_list){
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_get_list_main_sources_sync(
am_cmd_bus,
&ret,
@@ -337,11 +337,11 @@ ErrorCode am_proxy_get_list_main_sources(GVariant* source_list){
}
ErrorCode am_proxy_get_list_main_sinks(GVariant* sink_list){
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_cmd_bus);
+ assert(am_cmd_bus != NULL);
audiomanager_commandinterface_call_get_list_main_sources_sync(
am_cmd_bus,
&ret,
@@ -360,7 +360,7 @@ ErrorCode am_proxy_ack_connect(int handle, int connection_id, int usr_err){
return OUT_RANGE;
}
- assert(!am_route_bus);
+ assert(am_route_bus != NULL);
GError *err = NULL;
audiomanager_routinginterface_call_ack_connect_sync(
@@ -377,7 +377,7 @@ ErrorCode am_proxy_ack_disconnect(int handle, int connection_id, int usr_err){
is_range_over_guint16(usr_err) == OUT_RANGE){
return OUT_RANGE;
}
- assert(!am_route_bus);
+ assert(am_route_bus != NULL);
GError *err = NULL;
audiomanager_routinginterface_call_ack_disconnect_sync(
am_route_bus,
@@ -393,7 +393,7 @@ ErrorCode am_proxy_ack_set_source_state(int handle, int usr_err){
return OUT_RANGE;
}
- assert(!am_route_bus);
+ assert(am_route_bus != NULL);
GError *err = NULL;
audiomanager_routinginterface_call_ack_set_source_state_sync(
am_route_bus,
@@ -404,18 +404,19 @@ ErrorCode am_proxy_ack_set_source_state(int handle, int usr_err){
}
ErrorCode am_proxy_register_source(GVariant *source_data, int *source){
- assert(!am_route_bus);
- guint16 ret = UNABLE_SEND;
+ assert(am_route_bus != NULL);
+ guint16 ret = 0, g_source = 0;
ErrorCode ec;
GError *err = NULL;
audiomanager_routinginterface_call_register_source_sync(
am_route_bus,
source_data,
- source,
+ &g_source,
&ret,
NULL, &err);
g_variant_unref(source_data);
+ *source = (int)g_source;
ec = check_send_error(err, ret);
return ec;
}
@@ -424,11 +425,11 @@ ErrorCode am_proxy_deregister_source(int source){
if(is_range_over_guint16(source) == OUT_RANGE){
return OUT_RANGE;
}
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_route_bus);
+ assert(am_route_bus != NULL);
audiomanager_routinginterface_call_deregister_source_sync(
am_route_bus,
(guint16)source,
@@ -440,21 +441,22 @@ ErrorCode am_proxy_deregister_source(int source){
}
ErrorCode am_proxy_register_domain(GVariant* domain_data, int *domain){
- guint16 ret = UNABLE_SEND;
+ guint16 ret = 0, g_domain = 0;
ErrorCode ec;
GError *err = NULL;
- assert(!am_route_bus);
+ assert(am_route_bus != NULL);
audiomanager_routinginterface_call_register_domain_sync(
am_route_bus,
domain_data,
SOUND_MANAGER_BUS_NAME,
SOUND_MANAGER_PATH,
SOUND_MANAGER_RETURN_INTERFACE,
- domain, &ret,
+ &g_domain, &ret,
NULL, &err);
g_variant_unref(domain_data);
+ *domain = (int)g_domain;
ec = check_send_error(err, ret);
return ec;
}
@@ -564,7 +566,7 @@ ErrorCode initialize_proxy(){
NULL,
NULL
);
- return (am_cmd_bus && am_route_bus) ? OK : UNABLE_SEND;
+ return (!am_cmd_bus || !am_route_bus) ? OK : UNABLE_SEND;
}
void close_proxy(){
@@ -573,13 +575,13 @@ void close_proxy(){
}
void set_event_callback(const am_event* callback){
- assert(!am_cmd_bus);
- assert(!am_route_bus);
+ assert(am_cmd_bus != NULL);
+ assert(am_route_bus != NULL);
/* initialize signal from audio manager command interface */
_am_event.on_main_connection_state_changed = callback->on_main_connection_state_changed;
_am_event.on_new_main_connection = callback->on_new_main_connection;
_am_event.on_removed_main_connection = callback->on_removed_main_connection;
- _am_event.on_set_routing_ready = callback->on_removed_main_connection;
+ _am_event.on_set_routing_ready = callback->on_set_routing_ready;
_am_event.on_set_routing_rundown = callback->on_set_routing_rundown;
_am_event.on_sink_mute_state_changed = callback->on_sink_mute_state_changed;
_am_event.on_volume_changed = callback->on_volume_changed;
@@ -646,5 +648,5 @@ ErrorCode open_soundmanager_interface(const am_instruction *callback){
}
void close_soundmanager_inerface(){
- g_dbus_interface_skeleton_unexport(sm_adapter);
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(sm_adapter));
}
diff --git a/src/sm-pending.c b/src/sm-pending.c
new file mode 100644
index 0000000..43b18cf
--- /dev/null
+++ b/src/sm-pending.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+#include "sm-pending.h"
+
+struct pending* add_pending(struct pending *list, int source_id, struct afb_req request)
+{
+ struct pending* pd;
+
+ if(list == NULL){
+ pd = malloc(sizeof(struct pending));
+ if(NULL == pd){
+ return NULL;
+ }
+ pd->source.sourceID = source_id;
+ pd->source.request = request;
+ pd->next = NULL;
+ return pd;
+ }
+ else{
+ list->next = add_pending(list->next, source_id, request);
+ return list;
+ }
+}
+
+struct pending* get_pending(struct pending *list, int source_id){
+ if(list == NULL){
+ return NULL;
+ }
+ if(list->source.sourceID == source_id){
+ return list;
+ }
+ else{
+ struct pending* pd = get_pending(list->next, source_id);
+ return pd;
+ }
+}
+
+struct pending* del_pending(struct pending* list, int source_id){
+ struct pending* tmp;
+ if(list == NULL){
+ return NULL;
+ }
+
+ if(list->source.sourceID == source_id){
+ tmp = list->next;
+ free(list);
+ return tmp;
+ }
+ else{
+ list->next = del_pending(list->next, source_id);
+ return list;
+ }
+}
+
+void del_all_pendings(struct pending *list){
+ struct pending* tmp;
+ if(list != NULL){
+ tmp = list->next;
+ free(list);
+ del_all_pendings(tmp);
+ }
+} \ No newline at end of file
diff --git a/src/sm-pending.h b/src/sm-pending.h
new file mode 100644
index 0000000..f7de157
--- /dev/null
+++ b/src/sm-pending.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SOUNDMANAGER_PENDING_H
+#define SOUNDMANAGER_PENDING_H
+
+#define _GNU_SOURCE
+#define AFB_BINDING_VERSION 2
+#include <afb/afb-binding.h>
+
+struct pending_source{
+ int sourceID;
+ struct afb_req request;
+};
+struct pending{
+ struct pending_source source;
+ struct pending* next;
+};
+
+
+struct pending* add_pending(struct pending *list, int source_id, struct afb_req request);
+struct pending* get_pending(struct pending *list, int source_id);
+struct pending* del_pending(struct pending* list, int source_id);
+void del_all_pendings(struct pending *list);
+
+#endif //SOUNDMANAGER_PENDING_H \ No newline at end of file
diff --git a/src/soundmanager.c b/src/soundmanager.c
index 96d95d1..28ed7ba 100644
--- a/src/soundmanager.c
+++ b/src/soundmanager.c
@@ -26,60 +26,15 @@
#include "sm-def.h"
#include "sm-error.h"
#include "sm-helper.h"
+#include "sm-pending.h"
struct event{
char* name;
struct afb_event* event;
};
-struct pending{
- int sourceID;
- struct afb_req request;
- bool use_ahl;
- struct pending* next;
-};
-
static struct pending* pending_list = NULL;
-static bool add_pending(int source_id, bool use_ahl, struct afb_req request){
- struct pending* pd = malloc(sizeof(struct pending));
- if(NULL == pd){
- AFB_WARNING("memory allocation error");
- return false;
- }
- pd->sourceID = source_id;
- pd->request = request;
- pd->use_ahl = use_ahl;
- pd->next = NULL;
- if(pending_list == NULL){
- pending_list = pd;
- }
- struct pending* list = pending_list;
- while(list->next != NULL){
- list = list->next;
- }
- list->next = pd;
- return true;
-}
-
-
-static struct pending* get_pending(int source_id){
- struct pending* pd = pending_list;
- while(pd && (pd->sourceID == source_id)){
- pd = pd->next;
- }
- return pd;
-}
-
-static bool del_peding(int source_id){
- struct pending* pd = get_pending(source_id);
- if(pd != NULL){
-
- return true;
- }
- return false;
-}
-
static int SOUNDMANAGER_DOMAIN_ID;
static struct event command_event_list[COMMAND_EVENT_NUM];
static struct event routing_event_list[ROUTING_EVENT_NUM];
@@ -875,7 +830,7 @@ void setStreamState(struct afb_req request){
ctxt->source.mainConnectionID = main_connection_id;
afb_req_addref(request);
- add_peding(source_id, request);
+ pending_list = add_pending(pending_list, source_id, request);
}
#endif
@@ -1005,12 +960,12 @@ static void on_async_set_sink_volume(void *closure, int handle, int sinkID,
static void on_async_set_source_state(void *closure, int handle, int sourceID, int sourceState)
{
AFB_DEBUG( "%s called", __FUNCTION__);
- struct pending* pd = get_pending(sourceID);
- if((pd != NULL) && (pd->use_ahl)){
+ struct pending* pd = get_pending(pending_list, sourceID);
+ if(pd != NULL){
AFB_DEBUG("Call ackSetSourceState in for the application");
am_proxy_ack_set_source_state(handle, 0);
- del_peding(sourceID);
- return;
+ afb_req_success(pd->source.request, NULL, NULL);
+ pending_list = del_pending(pending_list, sourceID);
}
struct json_object* ev_obj = json_object_new_object();
const char* ss_key = get_source_state_key(sourceState);
@@ -1073,8 +1028,8 @@ int preinit()
AFB_INFO("Initialize Dbus object");
/* Initialize Dbus interface */
- ErrorCode err = initialize_proxy();
- if(err != OK){
+ ErrorCode ec = initialize_proxy();
+ if(ec != OK){
AFB_ERROR("Failed to initialize");
return -1;
}