diff options
author | Tai Vuong <tvuong@audiokinetic.com> | 2017-11-07 23:55:32 -0500 |
---|---|---|
committer | Tai Vuong <tvuong@audiokinetic.com> | 2017-11-07 23:55:32 -0500 |
commit | b4049e48c1b1ff7ce1e412b7b86a1172de03951b (patch) | |
tree | bb6b2392e0eb05aac247510c542837ad4d4ebf1d /ahl-binding | |
parent | 62d1562669676641613f31f9949008b73d56b458 (diff) |
API change, set mute is now an integer instead of string, fix memory leak, remove property value not implemented
Diffstat (limited to 'ahl-binding')
-rw-r--r-- | ahl-binding/ahl-binding.c | 77 | ||||
-rw-r--r-- | ahl-binding/ahl-config.c | 46 | ||||
-rw-r--r-- | ahl-binding/ahl-deviceenum.c | 1 |
3 files changed, 69 insertions, 55 deletions
diff --git a/ahl-binding/ahl-binding.c b/ahl-binding/ahl-binding.c index 83b4dc7..446d6e3 100644 --- a/ahl-binding/ahl-binding.c +++ b/ahl-binding/ahl-binding.c @@ -59,21 +59,6 @@ static StreamStateT StreamStateToEnum(char * in_pStreamStateStr) return STREAM_STATE_MAXVALUE; } -static StreamMuteT StreamMuteToEnum(char * in_pStreamMuteStr) -{ - if (in_pStreamMuteStr == NULL) { - return STREAM_MUTE_MAXVALUE; - } - else if (strcasecmp(in_pStreamMuteStr,AHL_STREAM_UNMUTED)==0) { - return STREAM_UNMUTED; - } - else if (strcasecmp(in_pStreamMuteStr,AHL_STREAM_MUTED)==0) { - return STREAM_MUTED; - } - else - return STREAM_MUTE_MAXVALUE; -} - static streamID_t CreateNewStreamID() { streamID_t newID = g_AHLCtx.nextStreamID; @@ -678,7 +663,7 @@ PUBLIC void audiohlapi_stream_close(struct afb_req req) afb_req_success(req, NULL, "Stream close completed"); } -static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, streamID_t streamID, char * pStreamStateStr, char * pMuteStr) { +static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, streamID_t streamID, char * pStreamStateStr, int iMuteValue) { StreamInfoT * pStreamInfo = GetStream(streamID); if (pStreamInfo == NULL) { @@ -720,31 +705,28 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s #endif } - if (pMuteStr != NULL) { - StreamMuteT muteState = StreamMuteToEnum(pMuteStr); #ifndef AHL_DISCONNECT_POLICY - json_object *pPolicyStreamJ = NULL; - int err = StreamInfoToJSON(pStreamInfo, &pPolicyStreamJ); - if (err == AHL_POLICY_UTIL_FAIL) - { - afb_req_fail((*pReq), "Audio policy violation", "Unable to get JSON object for Policy_SetStreamMute"); - return AHL_FAIL; - } + json_object *pPolicyStreamJ = NULL; + int err = StreamInfoToJSON(pStreamInfo, &pPolicyStreamJ); + if (err == AHL_POLICY_UTIL_FAIL) + { + afb_req_fail((*pReq), "Audio policy violation", "Unable to get JSON object for Policy_SetStreamMute"); + return AHL_FAIL; + } - json_object *paramJ= json_object_new_int(muteState); - json_object_object_add(pPolicyStreamJ, "mute_state", paramJ); + json_object *paramJ= json_object_new_int(iMuteValue); + json_object_object_add(pPolicyStreamJ, "mute_state", paramJ); - int policyAllowed = Policy_SetStreamMute(pPolicyStreamJ); - if (policyAllowed == AHL_POLICY_REJECT) - { - afb_req_fail(*pReq, "Audio policy violation", "Mute stream not allowed in current context"); - return AHL_FAIL; - } + int policyAllowed = Policy_SetStreamMute(pPolicyStreamJ); + if (policyAllowed == AHL_POLICY_REJECT) + { + afb_req_fail(*pReq, "Audio policy violation", "Mute stream not allowed in current context"); + return AHL_FAIL; + } #else - // Simulate that policy returns target state (accepted) - pStreamInfo->streamMute = muteState; + // Simulate that policy returns target state (accepted) + pStreamInfo->streamMute = (StreamMuteT)(*piMuteValue); #endif - } return AHL_SUCCESS; } @@ -754,10 +736,10 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s json_object *queryJ = NULL; streamID_t streamID = AHL_UNDEFINED; char * streamStateStr = NULL; - char * pMuteStr = NULL; + int iMuteValue = 0; queryJ = afb_req_json(req); - int err = wrap_json_unpack(queryJ, "{s?i,s?s,s?s}", "stream_id", &streamID,"state",&streamStateStr,"mute",&pMuteStr); + int err = wrap_json_unpack(queryJ, "{s?i,s?s,s?i}", "stream_id", &streamID,"state",&streamStateStr,"mute",&iMuteValue); if (err) { afb_req_fail_f(req, "Invalid arguments", "Args not a valid json object query=%s", json_object_get_string(queryJ)); return; @@ -777,7 +759,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s for (int i = 0; i < pClientCtx->pStreamAccessList->len; i++) { streamID_t curStreamID = g_array_index(pClientCtx->pStreamAccessList,streamID_t,i); - err = SetStreamState(pClientCtx,&req,curStreamID,streamStateStr,pMuteStr); + err = SetStreamState(pClientCtx,&req,curStreamID,streamStateStr,iMuteValue); if (err) { return; } @@ -785,7 +767,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s } } else { - err = SetStreamState(pClientCtx,&req,streamID,streamStateStr,pMuteStr); + err = SetStreamState(pClientCtx,&req,streamID,streamStateStr,iMuteValue); if (err) { return; } @@ -936,7 +918,7 @@ PUBLIC void audiohlapi_property(struct afb_req req) err = EndpointInfoToJSON(pEndpointInfo, &pPolicyEndpointJ); if (err == AHL_POLICY_UTIL_FAIL) { - afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_SetVolume"); + afb_req_fail(req, "property fail", "Unable to get JSON object for Policy_SetProperty"); return; } @@ -949,14 +931,14 @@ PUBLIC void audiohlapi_property(struct afb_req req) int policyAllowed = Policy_SetProperty(pPolicyEndpointJ,&pPropertyReply); if (!policyAllowed) { - afb_req_fail(req, "Audio policy violation", "Set endpoint property not allowed in current context"); + afb_req_fail(req, "Policy Reject Set Property Control", "Policy Reject Set Property Control"); return; } json_object * pPropReplyValue = NULL; err = wrap_json_unpack(pPropertyReply,"{s:o}","value",&pPropReplyValue); if (err) { - afb_req_fail_f(req, "Invalid policy reply", "Policy property change reply not a valid json object=%s", json_object_get_string(pPropertyReply)); + afb_req_fail_f(req, "property fail", "Policy Property value not a valid json object=%s", json_object_get_string(pPropertyReply)); return; } if (pEndpointInfo->pPropTable && pPropReplyValue) { @@ -974,7 +956,7 @@ PUBLIC void audiohlapi_property(struct afb_req req) // Retrieve cached property value json_object * propertyValJ = (json_object *)g_hash_table_lookup(pEndpointInfo->pPropTable,propertyName); if (propertyValJ == NULL) { - afb_req_fail_f(req, "Property not found", "Property information not found: %s",propertyName); + afb_req_fail_f(req, "audiohlapi_property", "Property information not found: %s",propertyName); return; } @@ -1094,7 +1076,12 @@ PUBLIC void audiohlapi_event_subscription(struct afb_req req) return; } - int iNumEvents = json_object_array_length(eventArrayJ); + json_type jType = json_object_get_type(eventArrayJ); + int iNumEvents = 0; + if(jType == json_type_array) + { + iNumEvents = json_object_array_length(eventArrayJ); + } for (int i = 0; i < iNumEvents; i++) { char * pEventName = NULL; diff --git a/ahl-binding/ahl-config.c b/ahl-binding/ahl-config.c index 61b6edd..3c92733 100644 --- a/ahl-binding/ahl-config.c +++ b/ahl-binding/ahl-config.c @@ -115,10 +115,28 @@ int ParseHLBConfig() { AFB_INFO("High-level audio API version: %s", "1.0.0"); AFB_INFO("Config version: %s", versionStr); AFB_INFO("Policy module: %s", policyModule); + + int iHALListLength = 0; + int iNumberOfRoles = 0; + + if(jHALList) + { + json_type jTypeHalList = json_object_get_type(jHALList); + if(jTypeHalList ==json_type_array) + { + iHALListLength = json_object_array_length(jHALList); + } + } - int iHALListLength = json_object_array_length(jHALList); - g_AHLCtx.policyCtx.pHALList = g_ptr_array_new_with_free_func(g_free); - int iNumberOfRoles = json_object_array_length(jAudioRoles); + if(jAudioRoles) + { + json_type jTypeAudioRole = json_object_get_type(jAudioRoles); + if(jTypeAudioRole ==json_type_array) + { + iNumberOfRoles = json_object_array_length(jAudioRoles); + } + } + g_AHLCtx.policyCtx.pHALList = g_ptr_array_new_with_free_func(g_free); g_AHLCtx.policyCtx.pRoleInfo = g_hash_table_new(g_str_hash, g_str_equal); for (int i = 0; i < iHALListLength; i++) @@ -165,15 +183,25 @@ int ParseHLBConfig() { if (err) { AFB_ERROR("Invalid audio role configuration : %s", json_object_to_json_string(jAudioRole)); return AHL_FAIL; - } - + } if (jOutputDevices) - iNumOutDevices = json_object_array_length(jOutputDevices); + { + json_type jTypeOutputDevices = json_object_get_type(jOutputDevices); + if(jTypeOutputDevices == json_type_array) + iNumOutDevices = json_object_array_length(jOutputDevices); + } if (jInputDevices) - iNumInDevices = json_object_array_length(jInputDevices); + { + json_type jTypeInputDevices = json_object_get_type(jInputDevices); + if(jTypeInputDevices == json_type_array) + iNumInDevices = json_object_array_length(jInputDevices); + } if (jActions) - iNumActions = json_object_array_length(jActions); - + { + json_type jTypeActions = json_object_get_type(jActions); + if(jTypeActions == json_type_array) + iNumActions = json_object_array_length(jActions); + } RoleInfoT * pRoleInfo = (RoleInfoT*) malloc(sizeof(RoleInfoT)); memset(pRoleInfo,0,sizeof(RoleInfoT)); pRoleInfo->pRoleName = g_strdup( pRoleName ); diff --git a/ahl-binding/ahl-deviceenum.c b/ahl-binding/ahl-deviceenum.c index b5b2a46..43e5af5 100644 --- a/ahl-binding/ahl-deviceenum.c +++ b/ahl-binding/ahl-deviceenum.c @@ -230,7 +230,6 @@ void TermEndpointInfo( gpointer data ) g_hash_table_destroy(out_pEndpointInfo->pPropTable); out_pEndpointInfo->pPropTable = NULL; } - g_slice_free (EndpointInfoT, out_pEndpointInfo); } } |