/**                                                                    
 * Remove all extended keys for the given @a page from the            
 * extended key cache.                                                
 */                                                                    
static ham_status_t
my_fun_free_page_extkeys(ham_btree_t *be, ham_page_t *page, ham_u32_t flags)
{
    ham_db_t *db=be_get_db(be);
    
    ham_assert(page_get_owner(page) == db, (0));
    
    ham_assert(0 == (flags & ~DB_MOVE_TO_FREELIST), (0));

    /*
     * if this page has a header, and it's either a B-Tree root page or 
     * a B-Tree index page: remove all extended keys from the cache, 
     * and/or free their blobs
     */
    if (page_get_pers(page) 
            && (!(page_get_npers_flags(page)&PAGE_NPERS_NO_HEADER))
            && (page_get_type(page)==PAGE_TYPE_B_ROOT 
                || page_get_type(page)==PAGE_TYPE_B_INDEX)) 
    {
        ham_size_t i;
        ham_offset_t blobid;
        int_key_t *bte;
        btree_node_t *node=ham_page_get_btree_node(page);
        extkey_cache_t *c;

        ham_assert(db, ("Must be set as page owner when this is a Btree page"));
        ham_assert(db=page_get_owner(page), (""));
        c=db_get_extkey_cache(db);

        for (i=0; i<btree_node_get_count(node); i++) 
        {
            bte=btree_node_get_key(db, node, i);
            if (key_get_flags(bte)&KEY_IS_EXTENDED) 
            {
                blobid=key_get_extended_rid(db, bte);
                if (env_get_rt_flags(db_get_env(db))&HAM_IN_MEMORY_DB) 
                {
                    /* delete the blobid to prevent that it's freed twice */
                    *(ham_offset_t *)(key_get_key(bte)+
                        (db_get_keysize(db)-sizeof(ham_offset_t)))=0;
                }
                //(void)key_erase_record(db, bte, 0, BLOB_FREE_ALL_DUPES);
                if (c)
                    (void)extkey_cache_remove(c, blobid);
            }
        }
    }

    return (HAM_SUCCESS);
}
示例#2
0
UINT32 upg_check_exit_key(void)
{
	UINT32 hkey,vkey;
    struct pan_key key_struct;

    if(key_get_key(&key_struct, 0))
    {
		hkey = scan_code_to_msg_code(&key_struct);
        ap_hk_to_vk(0,hkey, &vkey);
        if(vkey == V_KEY_EXIT ||  vkey==V_KEY_MENU)
            return TRUE;
    }

    return FALSE;
}
示例#3
0
static ham_status_t
__insert_split(ham_page_t *page, ham_key_t *key, 
        ham_offset_t rid, insert_scratchpad_t *scratchpad, 
        insert_hints_t *hints)
{
    int cmp;
    ham_status_t st;
    ham_page_t *newpage, *oldsib;
    int_key_t *nbte, *obte;
    btree_node_t *nbtp, *obtp, *sbtp;
    ham_size_t count, keysize;
    ham_db_t *db=page_get_owner(page);
    ham_env_t *env = db_get_env(db);
    ham_key_t pivotkey, oldkey;
    ham_offset_t pivotrid;
    ham_u16_t pivot;
    ham_bool_t pivot_at_end=HAM_FALSE;

    ham_assert(page_get_owner(page), (0));
    ham_assert(device_get_env(page_get_device(page)) 
            == db_get_env(page_get_owner(page)), (0));

    ham_assert(hints->force_append == HAM_FALSE, (0));

    keysize=db_get_keysize(db);

    /*
     * allocate a new page
     */
    hints->cost++;
    st=db_alloc_page(&newpage, db, PAGE_TYPE_B_INDEX, 0); 
    ham_assert(st ? page == NULL : 1, (0));
    ham_assert(!st ? page  != NULL : 1, (0));
    if (st)
        return st; 
    ham_assert(page_get_owner(newpage), (""));
    /* clear the node header */
    memset(page_get_payload(newpage), 0, sizeof(btree_node_t));

    stats_page_is_nuked(db, page, HAM_TRUE);

    /*
     * move half of the key/rid-tuples to the new page
     *
     * !! recno: keys are sorted; we do a "lazy split"
     */
    nbtp=ham_page_get_btree_node(newpage);
    nbte=btree_node_get_key(db, nbtp, 0);
    obtp=ham_page_get_btree_node(page);
    obte=btree_node_get_key(db, obtp, 0);
    count=btree_node_get_count(obtp);

    /*
     * for databases with sequential access (this includes recno databases):
     * do not split in the middle, but at the very end of the page
     *
     * if this page is the right-most page in the index, and this key is 
     * inserted at the very end, then we select the same pivot as for
     * sequential access
     */
    if (db_get_data_access_mode(db)&HAM_DAM_SEQUENTIAL_INSERT)
        pivot_at_end=HAM_TRUE;
    else if (btree_node_get_right(obtp)==0) {
        cmp=key_compare_pub_to_int(db, page, key, btree_node_get_count(obtp)-1);
        if (cmp>0)
            pivot_at_end=HAM_TRUE;
    }

    /*
     * internal pages set the count of the new page to count-pivot-1 (because
     * the pivot element will become ptr_left of the new page).
     * by using pivot=count-2 we make sure that at least 1 element will remain
     * in the new node.
     */
    if (pivot_at_end) {
        pivot=count-2;
    }
    else {
        pivot=count/2;
    }

    /*
     * uncouple all cursors
     */
    st=bt_uncouple_all_cursors(page, pivot);
    if (st)
        return (st);

    /*
     * if we split a leaf, we'll insert the pivot element in the leaf
     * page, too. in internal nodes, we don't insert it, but propagate
     * it to the parent node only.
     */
    if (btree_node_is_leaf(obtp)) {
        hints->cost += stats_memmove_cost((db_get_int_key_header_size()+keysize)*(count-pivot));
        memcpy((char *)nbte,
               ((char *)obte)+(db_get_int_key_header_size()+keysize)*pivot, 
               (db_get_int_key_header_size()+keysize)*(count-pivot));
    }
    else {
        hints->cost += stats_memmove_cost((db_get_int_key_header_size()+keysize)*(count-pivot-1));
        memcpy((char *)nbte,
               ((char *)obte)+(db_get_int_key_header_size()+keysize)*(pivot+1), 
               (db_get_int_key_header_size()+keysize)*(count-pivot-1));
    }
    
    /* 
     * store the pivot element, we'll need it later to propagate it 
     * to the parent page
     */
    nbte=btree_node_get_key(db, obtp, pivot);

    memset(&pivotkey, 0, sizeof(pivotkey));
    memset(&oldkey, 0, sizeof(oldkey));
    oldkey.data=key_get_key(nbte);
    oldkey.size=key_get_size(nbte);
    oldkey._flags=key_get_flags(nbte);
    st = util_copy_key(db, &oldkey, &pivotkey);
    if (st) 
    {
        (void)db_free_page(newpage, DB_MOVE_TO_FREELIST);
        goto fail_dramatically;
    }
    pivotrid=page_get_self(newpage);

    /*
     * adjust the page count
     */
    if (btree_node_is_leaf(obtp)) {
        btree_node_set_count(obtp, pivot);
        btree_node_set_count(nbtp, count-pivot);
    }
    else {
        btree_node_set_count(obtp, pivot);
        btree_node_set_count(nbtp, count-pivot-1);
    }

    /*
     * if we're in an internal page: fix the ptr_left of the new page
     * (it points to the ptr of the pivot key)
     */ 
    if (!btree_node_is_leaf(obtp)) {
        /* 
         * nbte still contains the pivot key 
         */
        btree_node_set_ptr_left(nbtp, key_get_ptr(nbte));
    }

    /*
     * insert the new element
     */
    hints->cost++;
    cmp=key_compare_pub_to_int(db, page, key, pivot);
    if (cmp < -1) 
    {
        st = (ham_status_t)cmp;
        goto fail_dramatically;
    }

    if (cmp>=0)
        st=__insert_nosplit(newpage, key, rid, 
                scratchpad->record, scratchpad->cursor, hints);
    else
        st=__insert_nosplit(page, key, rid, 
                scratchpad->record, scratchpad->cursor, hints);
    if (st) 
    {
        goto fail_dramatically;
    }
    scratchpad->cursor=0; /* don't overwrite cursor if __insert_nosplit
                             is called again */

    /*
     * fix the double-linked list of pages, and mark the pages as dirty
     */
    if (btree_node_get_right(obtp)) 
    {
        st=db_fetch_page(&oldsib, db, btree_node_get_right(obtp), 0);
        if (st)
            goto fail_dramatically;
    }
    else
    {
        oldsib=0;
    }

    if (oldsib) {
        st=ham_log_add_page_before(oldsib);
        if (st)
            goto fail_dramatically;
    }

    btree_node_set_left (nbtp, page_get_self(page));
    btree_node_set_right(nbtp, btree_node_get_right(obtp));
    btree_node_set_right(obtp, page_get_self(newpage));
    if (oldsib) {
        sbtp=ham_page_get_btree_node(oldsib);
        btree_node_set_left(sbtp, page_get_self(newpage));
        page_set_dirty(oldsib, env);
    }
    page_set_dirty(newpage, env);
    page_set_dirty(page, env);

    /* 
     * propagate the pivot key to the parent page
     */
    ham_assert(!(scratchpad->key.flags & HAM_KEY_USER_ALLOC), (0));
    if (scratchpad->key.data)
        allocator_free(env_get_allocator(env), scratchpad->key.data);
    scratchpad->key=pivotkey;
    scratchpad->rid=pivotrid;
    ham_assert(!(scratchpad->key.flags & HAM_KEY_USER_ALLOC), (0));

    return (SPLIT);

fail_dramatically:
    ham_assert(!(pivotkey.flags & HAM_KEY_USER_ALLOC), (0));
    if (pivotkey.data)
        allocator_free(env_get_allocator(env), pivotkey.data);
    return st;
}
示例#4
0
void power_switch(UINT32 mode)
{
	unsigned long keycode;
	SYSTEM_DATA* sys_data;
	UINT32 vkey;
	UINT32 times = 0,display_type=0;
	date_time dt;
	UINT32 hh,mm,ss;
	char time_str[10];
	struct pan_key key_struct;
	UINT32 timer;
	struct sf_panel_attr panel_attr;
/*alfred.wu 1.0版本的MCU程序因为待机时间不能超过256小时*/
#ifdef MCUSTANDBY
	struct sf_panel_time time;
	date_time sRecentTime;	
	UINT32 nDurationTime = 0;
	UINT32 nYear = 0;
	UINT32 nMonth = 0;
	UINT32 nDay = 0;
	UINT32 nHour = 0;
	UINT32 nMin = 0;
	UINT32 nSec = 0;
	struct sf_standby_param standby_param;
	/*Note: For the limited memory size of MCU, if using led panel, the maximum IR key num is 5 and for vfd panel the size is 2. */
	struct sf_power_ir_key ir_key[] = \
		{
#ifdef RC04_A
			{0x007f, 0x1c}, /*RC04_A*/
#endif
#ifdef RC09_A
			{0x00FD, 0x1A}, /*RC09_A*/
#endif
#ifdef RC11_A
			{0x00ff, 0x54}, /*RC11_A*/	
#endif
#ifdef RC19_D
			{0x01fe, 0x00}, /*RC11_A*/	
#endif
#ifdef RC01_A_02
			{0x807f, 0x0a}, /*RC01_A_02*/	
#endif
#ifdef ORDER_GZ1010001
			{0x007f, 0x1c}, /*RC04_A*/
#else
			{0x007f, 0x0a}, /*RC01_A*/
#endif
			{0x01FE, 0x01}, /*REMOTE02420100*/
			{0x06FB, 0x0E}, /*ALI_RCU_60_KEY*/
		};
#endif
	sys_data = sys_data_get();
	sys_data->bstandmode = 1;
	sys_data_save(1);
	system_state = SYS_STATE_POWER_OFF;

/*Archer:The following process is unnessary when using mcu standby resolution.*/
#if 0
	power_off_process();
	power_off_process2();
#endif
#ifndef MCUSTANDBY
    if(mode != 1)
		key_pan_display("off ", 4);
	key_pan_display_standby(1);
	key_pan_display_lock(0);

    api_standby_led_onoff(TRUE);
#else
#if 0
    get_local_time(&dt);
    nDurationTime = api_get_recently_timer();
	POWER_PRINTF("nDurationTime = 0x%x\n",nDurationTime);
	if(0 != nDurationTime)
	{
		sRecentTime.year = YEAR(nDurationTime);
		sRecentTime.month= MONTH(nDurationTime);
		sRecentTime.day= DAY(nDurationTime);
		sRecentTime.hour= HOUR(nDurationTime);
		sRecentTime.min= MIN(nDurationTime);
		sRecentTime.sec= SEC(nDurationTime);

		POWER_PRINTF("RecentTime:%d-%d-%d %d:%d:%d\n",sRecentTime.year,sRecentTime.month,\
							sRecentTime.day, sRecentTime.hour,sRecentTime.min,sRecentTime.sec);
		
		get_time_offset(&dt,&sRecentTime,&nDay,&nHour,&nMin,&nSec);
		//standby_param.standby_time_sec = nHour*60*60+nMin*60;
		standby_param.standby_time_sec = 60;
		POWER_PRINTF("standby:hour:%d, minute:%d, total secs:%d\n",nHour,nMin, standby_param.standby_time_sec);
		//pan_set_standby_time((struct pan_device*)dev_get_by_id(HLD_DEV_TYPE_PAN,0),&sPanelTime);
	}
	else
	{
		POWER_PRINTF("no timer\n");
	}
#endif

	//pan_display(g_pan_dev, "        ", 8);//albert.li del 2011.1.25
	
	/*albert.li add 2011.1.25*/
	get_local_time(&dt);
	time.hour = dt.hour;
	time.min= dt.min;
	time.sec = dt.sec;
#ifndef FAKE_STANDBY	

	sf_panel_clear();
	reset_sf_panel_all_led();
	/*albert.li add end*/

	sf_panel_display_time(&time);

	sf_panel_term();
#else	
	pan_io_control(g_pan_dev, PAN_DRIVER_GET_ATTRIBUTE, &panel_attr);
	if (panel_attr.type == SF_PANEL_TYPE_LED)
	{
		pan_display(g_pan_dev,"OFF ", 4);
	}
	else
	{
		pan_display(g_pan_dev,"STANDBY", 7);
	}
#endif	
	power_off_process();
	//S5PanelStandby(g_pan_dev,(const)&sPanIRSpecialKey,2);//guop edit
	standby_param.ir_key_num = sizeof(ir_key)/sizeof(struct sf_power_ir_key);
	standby_param.ir_key_list = ir_key;
	standby_param.standby_time_sec = 0;
#ifndef FAKE_STANDBY
	sf_power_down(&standby_param);
#else	 //zhouxp fake standby
	{
		while (1)
		{
			ControlMsg_t msg;
			times++;
			times = times % 100; 
			osal_delay(5000);
						
			vkey = V_KEY_NULL;
			if(key_get_key(&key_struct,0))
			{
				keycode = scan_code_to_msg_code(&key_struct);
				ap_hk_to_vk(0, keycode, &vkey);
			}
			else
				keycode = PAN_KEY_INVALID;
			if(vkey == V_KEY_POWER)
			{
				power_on_process();
			}
			ap_receive_msg( &msg, 10);
			libc_printf("got msg type=%d\n",msg.msgType);
			if(msg.msgType== CTRL_MSG_SUBTYPE_CMD_TIMER_WAKEUP)
				power_on_process();
				
		}
	}
#endif		

#endif
#ifndef MCUSTANDBY
	if(1)	/* Real Standby*//*alfred.wu ali的IC真待机处理流程在MCUSTANDBY后不会执行*/
	{
		UINT32	cur_time, target_time;

		get_local_time(&dt);
		pan_close(g_pan_dev);
        timer = api_get_recently_timer();
		// disable interrupt
		osal_interrupt_disable();

		cur_time = (dt.sec & 0x3F ) | ((dt.min & 0x3F )<<6)  | ((dt.hour & 0x1F )<<12) | ((dt.day & 0x1F)<<17)
			| ((dt.month & 0xF) << 22) | (((dt.year % 100) & 0x3F)<<26);

		sys_ic_enter_standby(timer, cur_time);
		// enable interrupt
		osal_interrupt_enable();
	}	
    
     
    while (1)
    {
		times++;
		times = times % 100; 
		osal_delay(5000);
    				
		if(times==0)
		{
			//get_cur_time(&hh,&mm,&ss);
			get_local_time(&dt);
			hh = dt.hour;
			mm = dt.min;

			if(display_type==0)
			    sprintf(time_str,"%02d%02d ",hh,mm);
			else
				sprintf(time_str,"%02d.%02d",hh,mm);

			key_pan_display(time_str, 5);
			display_type++;
			display_type %= 2;
		}
		
		vkey = V_KEY_NULL;
		if(key_get_key(&key_struct,0))
		{
			keycode = scan_code_to_msg_code(&key_struct);
			ap_hk_to_vk(0, keycode, &vkey);
		}
		else
			keycode = PAN_KEY_INVALID;
		if(vkey == V_KEY_POWER)
		{
			power_on_process();
		}
	}
#endif	
}