BOOL tg_shared_preferences_lock(const CHAR* path,BOOL lock)
{

    INT32 i = 0;
    INT32 len = 0;
    struct array_list* list = NULL;
    INT32 idx = -1;
    //sem_wait (&s_shared_preferences_sem);
    tg_os_WaitSemaphore(s_shared_preferences_sem);
    if (s_shared_preferences_lock_list.lock_list == NULL)
    {
        s_shared_preferences_lock_list.lock_list = array_list_new(tg_shared_preferences_lock_free);
    }
    //sem_post (&s_shared_preferences_sem);
    tg_os_SignalSemaphore(s_shared_preferences_sem);
    list = s_shared_preferences_lock_list.lock_list;
    return_val_if_fail(path,FALSE);
    return_val_if_fail(list,FALSE);
    idx = tg_shared_preferences_find_lock_path(path);
    if (idx>=0)
    {
        if (!lock)
        {
            //sem_wait (&s_shared_preferences_sem);
            tg_os_WaitSemaphore(s_shared_preferences_sem);
            array_list_put_idx(list, idx, NULL);
            //sem_post (&s_shared_preferences_sem);
            tg_os_SignalSemaphore(s_shared_preferences_sem);
        }
        return TRUE;
    }

    else
    {

        if (lock)
        {
            CHAR* lock_path = TG_CALLOC((strlen(path)+1),1);
            strcpy(lock_path,path);
            //sem_wait (&s_shared_preferences_sem);
            tg_os_WaitSemaphore(s_shared_preferences_sem);
            array_list_put_idx(list, tg_shared_preferences_get_first_free_slot(s_shared_preferences_lock_list.lock_list), (void*)lock_path);
            //sem_post (&s_shared_preferences_sem);
            tg_os_SignalSemaphore(s_shared_preferences_sem);
        }

        return TRUE;
    }
}
static BOOL tg_shared_preferences_add_new_register_item(const CHAR* path,const CHAR* keys,SharedPreferences_Notification_Callback cb,SharedPreferences_WRITE_TYPE type)
{
    struct array_list* list = s_shared_preferences_register_list.list;
    INT32 idx = 0;
    Shared_Preferences_Register_Item* item=NULL;
    BOOL ret = FALSE;
    return_val_if_fail(path,FALSE);
    return_val_if_fail(keys,FALSE);
    //sem_wait (&s_shared_preferences_sem);
    tg_os_WaitSemaphore(s_shared_preferences_sem);
    idx =  tg_shared_preferences_get_first_free_slot(list);
    if (idx >= 0)
    {
        item = TG_CALLOC_V2(sizeof(Shared_Preferences_Register_Item));
        item->cb = cb;
        item->type=type;
        item->path = TG_CALLOC_V2(strlen(path)+1);
        strcpy(item->path,path);
        item->keys= TG_CALLOC_V2(strlen(keys)+1);
        strcpy(item->keys,keys);
        array_list_put_idx(list, idx, item);
        ret = TRUE;
    }
    //sem_post (&s_shared_preferences_sem);
    tg_os_SignalSemaphore(s_shared_preferences_sem);
    return ret;
}
Ejemplo n.º 3
0
static int ac_update_configuration_datachannelinterfaces(void* data, void* param) {
	int i;
	int mtu;
	int length;
	const char* bridge;
	struct ac_if_datachannel* iface = (struct ac_if_datachannel*)data;
	struct array_list* interfaces = (struct array_list*)param;

	/* Search interface */
	length = array_list_length(interfaces);
	for (i = 0; i < length; i++) {
		struct json_object* jsonvalue = array_list_get_idx(interfaces, i);
		if (jsonvalue && (json_object_get_type(jsonvalue) == json_type_object)) {
			struct json_object* jsonindex = compat_json_object_object_get(jsonvalue, "Index");
			if (jsonindex && (json_object_get_type(jsonindex) == json_type_int)) {
				if (iface->index == (unsigned long)json_object_get_int(jsonindex)) {
					if (!ac_update_configuration_getdatachannel_params(jsonvalue, &mtu, &bridge)) {
						/* TODO update interface */
					}

					/* Interface found */
					array_list_put_idx(interfaces, i, NULL);
					break;
				}
			}
		}
	}

	return ((i == length) ? HASH_DELETE_AND_CONTINUE : HASH_CONTINUE);
}
static BOOL tg_shared_preferences_delete_register_item(INT32 idx)
{
    struct array_list* list = s_shared_preferences_register_list.list;
    return_val_if_fail((idx>=0),FALSE);

    //sem_wait (&s_shared_preferences_sem);
    tg_os_WaitSemaphore(s_shared_preferences_sem);
    array_list_put_idx(list, idx, NULL);
    //sem_post (&s_shared_preferences_sem);
    tg_os_SignalSemaphore(s_shared_preferences_sem);

    return TRUE;
}
INT32 tg_shared_preferences_unregister_all()
{
    INT32 i = 0;
    INT32 len = 0;
    struct array_list* list = s_shared_preferences_register_list.list;
    //sem_wait (&s_shared_preferences_sem);
    tg_os_WaitSemaphore(s_shared_preferences_sem);
    len = array_list_length(list);
    for(;i<len;i++)
    {
    	array_list_put_idx(list, i, NULL);
    }
    //sem_post (&s_shared_preferences_sem);
    tg_os_SignalSemaphore(s_shared_preferences_sem);

    return SharedPreferences_SUCC;
}
static BOOL tg_shared_preferences_update_register_item(INT32 idx,const CHAR* path,const CHAR* keys,SharedPreferences_Notification_Callback cb,SharedPreferences_WRITE_TYPE type)
{
    struct array_list* list = s_shared_preferences_register_list.list;

    Shared_Preferences_Register_Item* item = TG_CALLOC_V2(sizeof(Shared_Preferences_Register_Item));
    return_val_if_fail(path,FALSE);
    return_val_if_fail(keys,FALSE);
    item->cb = cb;
    item->type=type;
    item->path = TG_CALLOC_V2(strlen(path)+1);
    strcpy(item->path,path);
    item->keys= TG_CALLOC_V2(strlen(keys)+1);
    strcpy(item->keys,keys);
    sem_wait (&s_shared_preferences_sem);
    array_list_put_idx(list, idx, item);
    sem_post (&s_shared_preferences_sem);


    return TRUE;
}
Ejemplo n.º 7
0
int
array_list_add(struct array_list *arr, void *data)
{
  return array_list_put_idx(arr, arr->length, data);
}
Ejemplo n.º 8
0
int
array_list_add(struct array_list *self, void *data)
{
  return array_list_put_idx(self, self->length, data);
}