Change log function according to update of libmm-common/libmm-log
[platform/core/multimedia/avsystem.git] / avsys-audio-handle.c
index 3cbe050..1232c92 100644 (file)
@@ -80,16 +80,10 @@ static int g_default_volume[AVSYS_AUDIO_VOLUME_TYPE_MAX] = {
 EXPORT_API
 int avsys_audio_handle_init(void)
 {
-       int i, err = 0;
+       int i = 0;
        avsys_audio_handle_info_t *control = NULL;
        avsys_audio_handle_info_t **temp = NULL;
 
-       /* Check root user */
-       err = avsys_check_root_privilege();
-       if (AVSYS_FAIL(err)) {
-               return err;
-       }
-
        if (AVSYS_FAIL(avsys_audio_create_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
                avsys_error(AVAUDIO, "avsys_audio_create_sync() failed in %s\n", __func__);
                return AVSYS_STATE_ERR_INTERNAL;
@@ -147,19 +141,13 @@ int avsys_audio_handle_fini(void)
 EXPORT_API
 int avsys_audio_handle_reset(int *volume_value)
 {
-       int i = 0, err = 0;
+       int i = 0;
        long long int flag = 0x01;
        avsys_audio_handle_info_t *control = NULL;
        avsys_audio_handle_info_t **temp = NULL;
        int * volumes;
        temp = &control;
 
-       /* Check root user */
-       err = avsys_check_root_privilege();
-       if (AVSYS_FAIL(err)) {
-               return err;
-       }
-
        AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
        if (control == NULL) {
                avsys_error(AVAUDIO, "control is null in %s\n", __func__);
@@ -451,6 +439,39 @@ int avsys_audio_handle_alloc(int *handle)
        }
 }
 
+int avsys_audio_handle_alloc_unlocked(int *handle)
+{
+       long long int flag = 0x01;
+       int i;
+       avsys_audio_handle_info_t *control = NULL;
+       avsys_audio_handle_info_t **temp = NULL;
+       temp = &control;
+
+       avsys_info(AVAUDIO, "%s\n", __func__);
+       AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
+
+       for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
+               if ((control->allocated & flag) == 0) { /* alloc condition */
+                       control->allocated |= flag;
+                       break;
+               } else {
+                       flag <<= 1;
+               }
+       }
+
+       if (i == AVSYS_AUDIO_HANDLE_MAX) {
+               *handle = -1;
+               return AVSYS_STATE_ERR_RANGE_OVER;
+       } else {
+               avsys_info(AVAUDIO, "handle allocated %d\n", i);
+               memset(&control->handles[i], 0, sizeof(avsys_audio_handle_t));
+               control->handles[i].pid = getpid();
+               control->handles[i].tid = avsys_gettid();
+               *handle = i;
+               return AVSYS_STATE_SUCCESS;
+       }
+}
+
 int avsys_audio_handle_free(int handle)
 {
        long long int flag = 0x01;
@@ -535,6 +556,43 @@ int avsys_audio_handle_get_ptr(int handle, avsys_audio_handle_t **ptr, const int
        return ret;
 }
 
+int avsys_audio_handle_get_ptr_unlocked(int handle, avsys_audio_handle_t **ptr, const int mode)
+{
+       long long int flag = 0x01;
+       avsys_audio_handle_info_t *control = NULL;
+       avsys_audio_handle_info_t **temp = NULL;
+       int ret = AVSYS_STATE_SUCCESS;
+
+       if (handle < 0 || handle >= AVSYS_AUDIO_HANDLE_MAX) {
+               *ptr = NULL;
+               return AVSYS_STATE_ERR_INVALID_HANDLE;
+       }
+
+       if (mode < 0 || mode >= HANDLE_PTR_MODE_NUM) {
+               *ptr = NULL;
+               return AVSYS_STATE_ERR_INVALID_PARAMETER;
+       }
+
+       temp = &control;
+       if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE, (void **)temp))) {
+               avsys_error(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
+               *ptr = NULL;
+               return AVSYS_STATE_ERR_INTERNAL;
+       }
+
+       flag <<= handle;
+
+       if (control->allocated & flag) {
+               *ptr = &(control->handles[handle]);
+               ret = AVSYS_STATE_SUCCESS;
+       } else {
+               *ptr = NULL;
+               ret = AVSYS_STATE_ERR_INVALID_VALUE;
+       }
+
+       return ret;
+}
+
 int avsys_audio_handle_release_ptr(int handle, const int mode)
 {
        long long int flag = 0x01;