Ejemplo n.º 1
0
/**********************************************************************
 * 函数名称: MapFile
 * 功能描述: 使用mmap函数映射一个文件到内存,以后就可以直接通过内存来访问文件
 * 输入参数: ptFileMap - 内含文件名strFileName
 * 输出参数: ptFileMap - tFp           : 所打开的文件句柄
 *                        iFileSize     : 文件大小
 *                        pucFileMapMem : 映射内存的首地址
 * 返 回 值: 0      - 成功
 *            其他值 - 失败
 * 修改日期        版本号     修改人	      修改内容
 * -----------------------------------------------
 * 2013/02/08	     V1.0	  韦东山	      创建
 ***********************************************************************/
int MapFile(PT_FileMap ptFileMap)
{
	int iFd;
    FILE *tFp;
	struct stat tStat;
	
	/* 打开文件 */
	tFp = fopen(ptFileMap->strFileName, "r+");
	if (tFp == NULL)
	{
		DBG_PRINTF("can't open %s\n", ptFileMap->strFileName);
		return -1;
	}
	ptFileMap->tFp = tFp;

	/*fileno()用来取得参数stream指定的文件流所使用的文件描述符*/
    iFd = fileno(tFp);

	fstat(iFd, &tStat);
	ptFileMap->iFileSize = tStat.st_size;
	ptFileMap->pucFileMapMem = (unsigned char *)mmap(NULL , tStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, iFd, 0);
	if (ptFileMap->pucFileMapMem == (unsigned char *)-1)
	{
		DBG_PRINTF("mmap error!\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 2
0
/*******************************************************************************
* Function Name: CscsInit()
********************************************************************************
*
* Summary:
*   Initializes the Cycling Speed and Cadence Service.
*
*******************************************************************************/
void CscsInit(void)
{
    uint8 buff[CSC_MEASUREMENT_CHAR_SIZE];

    /* Register service specific callback function */
    CyBle_CscsRegisterAttrCallback(CscsCallback);

    /* Get initial value of CSC Measurement Characteristic */
    if(CyBle_CscssGetCharacteristicValue(CYBLE_CSCS_CSC_MEASUREMENT, CSC_MEASUREMENT_CHAR_SIZE, buff) !=
            CYBLE_ERROR_OK)
    {
        DBG_PRINTF("Failed to read the CSC Measurement value.\r\n");
    }

    /* Set initial CSC Characteristic flags as per values set in the customizer */
    cscFlags = buff[0u];

    /* Get the CSC Feature */
    /* Get the characteristic into the buffer */
    if((CyBle_CscssGetCharacteristicValue(CYBLE_CSCS_CSC_FEATURE, CSC_FEATURE_SIZE, buff)) == CYBLE_ERROR_OK)
    {
        cscFeature = (uint16) ((((uint16) buff[1u]) << ONE_BYTE_SHIFT) | ((uint16) buff[0u]));
    }
    else
    {
        DBG_PRINTF("Failed to read the CSC Feature value.\r\n");
    }
}
void
db_error_dialog::handle_error()
{
  int btn_id = m_btn_group->checkedId();
  DBG_PRINTF(3, "handle_error clicked=%d", btn_id);

  if (btn_id == action_quit) {
    gl_pApplication->cleanup();
    // we want to really quit, not just leave the main event loop
    ::exit(1);
  }

  if (btn_id == action_reconnect) {
    db_cnx db;
    if (!db.ping()) {
      DBG_PRINTF(3, "No reply to database ping");
      if (!db.datab()->reconnect()) {
	DBG_PRINTF(3, "Failed to reconnect to database");
	return;
      }
      else {
	DBG_PRINTF(3, "Database reconnect successful");
      }
    }    
  }

  // when btn_id == action_continue, there is nothing to do.

  close();
}
Ejemplo n.º 4
0
static int FreeTypeFontInit(char *pcFontFile, unsigned int dwFontSize)
{
	int iError;

	/* ÏÔʾʸÁ¿×ÖÌå */
	iError = FT_Init_FreeType(&g_tLibrary );			   /* initialize library */
	/* error handling omitted */
	if (iError)
	{
		DBG_PRINTF("FT_Init_FreeType failed\n");
		return -1;
	}

	iError = FT_New_Face(g_tLibrary, pcFontFile, 0, &g_tFace); /* create face object */
	/* error handling omitted */
	if (iError)
	{
		DBG_PRINTF("FT_Init_FreeType failed\n");
		return -1;
	}

	g_tSlot = g_tFace->glyph;

	iError = FT_Set_Pixel_Sizes(g_tFace, dwFontSize, 0);
	if (iError)
	{
		DBG_PRINTF("FT_Set_Pixel_Sizes failed : %d\n", dwFontSize);
		return -1;
	}


	return 0;
}
Ejemplo n.º 5
0
Archivo: mixer.c Proyecto: GCrean/wmamp
/* Do the actual work */
void set_volume(int l, int r)
{
    int fd, v, cmd, devs;

    DBG_PRINTF("mixer: set_volume(%d, %d)\n", l, r);
    fd = open(MIXER_DEV, O_WRONLY);

    if (fd == -1) {
        DBG_PRINTF("mixer: Unable to open mixer device\n");
        return;
    }

    ioctl(fd, SOUND_MIXER_DEVMASK, &devs);
    if (devs & SOUND_MASK_PCM) {
        cmd = SOUND_MIXER_WRITE_PCM;
    }
    else if (devs & SOUND_MASK_VOLUME) {
        cmd = SOUND_MIXER_WRITE_VOLUME;
    }
    else {
        close(fd);
        return;
    }
    v = (r << 8) | l;
    ioctl(fd, cmd, &v);
    close(fd);	
}
Ejemplo n.º 6
0
/* 注意: 由于要用到LCD的分辨率, 此函数要在SelectAndInitDisplay之后调用 */
static int TouchScreenDevInit(void)
{
	char *pcTSName = NULL;

	if ((pcTSName = getenv("TSLIB_TSDEVICE")) != NULL ) 
	{
		g_tTSDev = ts_open(pcTSName, 0);  /* 以阻塞方式打开 */
	}
	else
	{
		g_tTSDev = ts_open("/dev/event0", 1);
	}

	if (!g_tTSDev) {
		DBG_PRINTF(APP_ERR"ts_open error!\n");
		return -1;
	}

	if (ts_config(g_tTSDev)) {
		DBG_PRINTF("ts_config error!\n");
		return -1;
	}

	if (GetDispResolution(&giXres, &giYres))
	{
		return -1;
	}

	return 0;
}
Ejemplo n.º 7
0
/*----------------------------------------------------------------------------*/
int
tres_mem_arch_pf_store_step(int id, const uint8_t * buf, int len)
{
  int j;
  uint16_t tmp;
  uint8_t *tmp8;

  DBG_PRINTF("tres_mem_arch_pf_store_step()\n");
  // ensure that we don't exceed the slot limit 
  DBG_PRINTF("Len: %d\n", len);
  DBG_PRINTF("Cur: %x\n", cur[id]);
  DBG_PRINTF("SLOT_END_ADDR: %x\n", SLOT_END_ADDR(id));
  if(((SLOT_END_ADDR(id)) - cur[id]) < len) {
    return -1;
  }
  flash_setup();
  // write to flash
  tmp8 = (uint8_t *) &tmp;
  for(j = 0; j < len; j += 2) {
    // we need this because buf may be misaligned
    tmp8[0] = buf[j];
    // don't worry about possible buffer overflow in read mode
    tmp8[1] = buf[j + 1];
    DBG_PRINTF("Writing @%x\n", cur[id]);
    flash_write((unsigned short *)cur[id], tmp);
    cur[id] += 2;
  }
  return 0;
}
Ejemplo n.º 8
0
/*
  Iterate through the tree items of the Current mail (=unprocessed) tags
  to find the one matching 'tag_id'.
  If found, change its counters.
*/
void
query_listview::update_tag_current_counter(uint tag_id)
{
  if (tag_id!=0) {
    if (!m_item_current_tags)
      return;
    int child_index=0;
    query_tag_lvitem* q = static_cast<query_tag_lvitem*>(m_item_current_tags->child(child_index));
    while (q) {
      if (q->m_tag_id==tag_id) {
	DBG_PRINTF(5, "update_tag_current_counter(%d)", tag_id);
	qs_tag_map::const_iterator it = m_tagged.find(tag_id);
	q->set_title(tags_repository::hierarchy(tag_id),
		     it != m_tagged.end() ? it->second : NULL);
	break;	// tag found, stop iterating
      }
      q = static_cast<query_tag_lvitem*>(m_item_current_tags->child(++child_index));
    }
  }
  else {
    if (m_item_current_untagged) {
      DBG_PRINTF(5, "update_tag_current_counter(%d)", tag_id);
      qs_tag_map::const_iterator it = m_tagged.find(0); // 0=>not tagged
      m_item_current_untagged->set_title(tr("Not tagged"),
					 it != m_tagged.end() ? it->second : NULL);
    }
  }
}
Ejemplo n.º 9
0
/*******************************************************************************
* Function Name: ScpsCallBack()
********************************************************************************
*
* Summary:
*   This is an event callback function to receive service specific events from 
*   SCPS Service.
*
* Parameters:
*  event - the event code
*  *eventParam - the event parameters
*
* Return:
*  None.
*
********************************************************************************/
void ScpsCallBack (uint32 event, void *eventParam)
{
    DBG_PRINTF("SCPS event: %lx, ", event);
    switch(event)
    {
        case CYBLE_EVT_SCPSS_NOTIFICATION_ENABLED:
            DBG_PRINTF("CYBLE_EVT_SCPSS_NOTIFICATION_ENABLED \r\n");
            requestScanRefresh = ENABLED;
            break;
        case CYBLE_EVT_SCPSS_NOTIFICATION_DISABLED:
            DBG_PRINTF("CYBLE_EVT_SCPSS_NOTIFICATION_DISABLED \r\n");
            requestScanRefresh = DISABLED;
            break;
        case CYBLE_EVT_SCPSS_SCAN_INT_WIN_CHAR_WRITE:
            scanInterval = CyBle_Get16ByPtr(((CYBLE_SCPS_CHAR_VALUE_T *)eventParam)->value->val);
            scanWindow = CyBle_Get16ByPtr(((CYBLE_SCPS_CHAR_VALUE_T *)eventParam)->value->val + sizeof(scanInterval));
            DBG_PRINTF("CYBLE_EVT_SCPSS_SCAN_INT_WIN_CHAR_WRITE scanInterval: %x, scanWindow: %x \r\n", scanInterval, scanWindow);
            break;
        case CYBLE_EVT_SCPSC_NOTIFICATION:
            break;
        case CYBLE_EVT_SCPSC_READ_DESCR_RESPONSE:
            break;
        case CYBLE_EVT_SCPSC_WRITE_DESCR_RESPONSE:
            break;
        default:
            DBG_PRINTF("Not supported event\r\n");
			break;
    }
}
Ejemplo n.º 10
0
QStandardItem*
mail_item_model::reparent_msg(mail_msg* msg, mail_id_t parent_id)
{
  DBG_PRINTF(7, "reparent_msg");
  QMap<mail_id_t, QStandardItem*>::iterator itp = items_map.find(parent_id);
  if (itp==items_map.end())
    return NULL;
  QMap<mail_id_t, QStandardItem*>::iterator itc = items_map.find(msg->get_id());
  if (itc!=items_map.end()) {
    QModelIndex index_child=this->indexFromItem(itc.value());
    QStandardItem* old_parent=itc.value()->parent();
    QStandardItem* new_parent=itp.value();
    if (old_parent==new_parent)
      return NULL;
    QList<QStandardItem*> ql;
    if (!old_parent) {
      ql=takeRow(index_child.row());
    }
    else {
      DBG_PRINTF(9,"old_parent for mail_id=%d", msg->get_id());
      ql=old_parent->takeRow(index_child.row());
    }
    new_parent->appendRow(ql);
    DBG_PRINTF(9, "reparented %d as child of %d", msg->get_id(), parent_id);
    return new_parent;
  }
  else {
    DBG_PRINTF(1, "ERR: mail_id=%d not found in items_map", msg->get_id());
  }
  return NULL;
}
Ejemplo n.º 11
0
void
msg_status_cache::db_new_mail_notif()
{
  DBG_PRINTF(5, "We have NEW MAIL!");
  db_cnx db;
  try {
    sql_stream s("SELECT ms.mail_id,ms.status,sender,sender_fullname,subject,recipients FROM mail m JOIN mail_status ms USING(mail_id) WHERE ms.mail_id>:p1", db);
    s << m_max_mail_id;
    mail_id_t mail_id;
    int status;
    int count=0;
    while (!s.eos()) {
      QString sender,sender_fullname,subject,recipients;
      s >> mail_id >> status>> sender >> sender_fullname >> subject >> recipients;
      count++;
      DBG_PRINTF(5, "Seen mail_id %d with status %d", mail_id, status);
      if (!(status & mail_msg::statusRead)) {
	gl_pApplication->desktop_notify(tr("New mail"), QString("From: %1\nSubject: %2").arg(sender_fullname.isEmpty()?sender:sender_fullname).arg(subject));
      }
      update(mail_id, status);
      message_port::instance()->broadcast_new_mail(mail_id);
    }
    if (count>0 && get_config().get_bool("fetch/auto_incorporate_new_results", false)) {
      message_port::instance()->broadcast_list_refresh_request();
    }
  }
  catch(db_excpt& p) {
    DBEXCPT(p);
  }
}
Ejemplo n.º 12
0
void
mail_item_model::remove_msg(mail_msg* msg)
{
  DBG_PRINTF(8, "remove_msg(mail_id=" MAIL_ID_FMT_STRING ")", msg->get_id());
  QMap<mail_id_t, QStandardItem*>::iterator it = items_map.find(msg->get_id());
  if (it!=items_map.end()) {
    QStandardItem* item = it.value();
    QStandardItem* parent_item = item->parent();
    while (item->child(0,0)!=NULL) {
      // reparent childs of the item to remove
      QList<QStandardItem*> ql = item->takeRow(0);
      if (parent_item) {
	DBG_PRINTF(9, "reparenting child to immediate parent row=%d", item->index().row());
	parent_item->insertRow(item->index().row(), ql);
      }
      else {
	DBG_PRINTF(9, "reparenting child to root");
	insertRow(item->index().row(), ql);
      }
    }
    // 
    DBG_PRINTF(9, "removing mail_id=" MAIL_ID_FMT_STRING
	       " from model at index.row=%d index.column=%d",
	       msg->get_id(), item->index().row(),
	       item->index().column());
    QModelIndex index = item->index();
    removeRow(index.row(), index.parent());
    items_map.erase(it);
  }
  else {
    DBG_PRINTF(1, "ERR: mail_id=" MAIL_ID_FMT_STRING " not found in items_map", msg->get_id());
  }
}
Ejemplo n.º 13
0
static void sni_mem_init(void )
{
	int i, memsize;
	struct membank {
	        u32		size;
	        u32		base;
	        u32		size2;
	        u32		pad1;
	        u32		pad2;
	} memconf[8];

	/* MemSIZE from prom in 16MByte chunks */
	memsize=*((unsigned char *) SNI_IDPROM_MEMSIZE) * 16;

	DBG_PRINTF("IDProm memsize: %lu MByte\n", memsize);

	/* get memory bank layout from prom */
	__prom_get_memconf(&memconf);

	DBG_PRINTF("prom_get_mem_conf memory configuration:\n");
	for(i=0;i<8 && memconf[i].size;i++) {
		prom_printf("Bank%d: %08x @ %08x\n", i,
			memconf[i].size, memconf[i].base);
		add_memory_region(memconf[i].base, memconf[i].size, BOOT_MEM_RAM);
	}
}
Ejemplo n.º 14
0
/**
	The actual signal handler for Windows.
	Does not respond on LOGOFF signal. 
	Exits on shutdown ..., Ctl-C,...
*/
static int dyndns_win32_signal_handler_func(OS_SIGNAL_TYPE signal, void *p_in)
{
	int ret_flag = 0;

	DYN_DNS_CLIENT *p_self = (DYN_DNS_CLIENT *) p_in;
	if (p_self == NULL)
	{
		return 0;
	}

	switch (signal.signal)
	{
		case OS_CTRL_C_SIGNAL :
		case OS_CTRL_CLOSE_SIGNAL :
		case OS_CTRL_BREAK_SIGNAL :
		case OS_CTRL_SHUTDOWN_SIGNAL :
				DBG_PRINTF((LOG_INFO,MODULE_TAG "Signal '0x%x' received. Sending 'Shutdown cmd'.\n", signal));
				ret_flag = 1;
				p_self->cmd = CMD_STOP;
			break;
			
		case OS_CTRL_LOGOFF_SIGNAL :						
		default:
				DBG_PRINTF((LOG_DEBUG,MODULE_TAG "Signal '0x%x' received. NO ACTION.\n", signal));
	}
	return ret_flag;
}
Ejemplo n.º 15
0
Archivo: tcp.c Proyecto: ebichu/dd-wrt
RC_TYPE tcp_test_connect(TCP_SOCKET *p_self,CB_EXIT_COND p_exit_func,void *p_cb_data)
{

	RC_TYPE	rc_is_online=RC_OK;


	DBG_PRINTF((LOG_INFO,"I:" MODULE_TAG "entered tcp_test_connect...\n"));

	if (get_mutex_try(&test_timer_loop_mutex)==0) {

		DBG_PRINTF((LOG_INFO,"I:" MODULE_TAG "timer loop mutex is free in tcp_test_connect...\n"));

		rc_is_online=tcp_initialize_async(p_self,p_exit_func,p_cb_data);

		release_mutex(&test_timer_loop_mutex);

		DBG_PRINTF((LOG_INFO,"I:" MODULE_TAG "tcp_initialize_async returned %d in tcp_test_connect...\n",(rc_is_online==RC_OK)));

	}
	else {

		/*init async presently in timeout loop -- wait for it*/

		DBG_PRINTF((LOG_INFO,"I:" MODULE_TAG "timer loop mutex is not free in tcp_test_connect...\n"));

		get_mutex(&test_timer_loop_mutex);
		release_mutex(&test_timer_loop_mutex);

		rc_is_online=global_is_online;

		DBG_PRINTF((LOG_INFO,"I:" MODULE_TAG "got timer loop mutex in tcp_test_connect, return to be %d...\n",(rc_is_online==RC_OK)));
	}

	return rc_is_online;
}
Ejemplo n.º 16
0
int FontsInit(void)
{
	int iError;
	
	iError = ASCIIInit();
	if (iError)
	{
		DBG_PRINTF("ASCIIInit error!\n");
		return -1;
	}

	iError = GBKInit();
	if (iError)
	{
		DBG_PRINTF("GBKInit error!\n");
		return -1;
	}
	
	iError = FreeTypeInit();
	if (iError)
	{
		DBG_PRINTF("FreeTypeInit error!\n");
		return -1;
	}

	return 0;
}
Ejemplo n.º 17
0
/**********************************************************************
 * 函数名称: ShowIntervalPage
 * 功能描述: 显示"interval页面"
 * 输入参数: ptPageLayout - 内含多个图标的文件名和显示区域
 * 输出参数: 无
 * 返 回 值: 无
 * 修改日期        版本号     修改人	      修改内容
 * -----------------------------------------------
 * 2013/02/08	     V1.0	  韦东山	      创建
 ***********************************************************************/
static void ShowIntervalPage(PT_PageLayout ptPageLayout)
{
	PT_VideoMem ptVideoMem;
	int iError;
	PT_Layout atLayout = ptPageLayout->atLayout;
		
	/* 1. 获得显存 */
	ptVideoMem = GetVideoMem(ID("interval"), 1);
	if (ptVideoMem == NULL)
	{
		DBG_PRINTF("can't get video mem for interval page!\n");
		return;
	}

	/* 2. 描画数据 */
	/* 如果还没有计算过各图标的坐标 */
	if (atLayout[0].iTopLeftX == 0)
	{
		CalcIntervalPageLayout(ptPageLayout);
	}

	iError = GeneratePage(ptPageLayout, ptVideoMem);

	iError = GenerateIntervalPageSpecialIcon(g_iIntervalSecond, ptVideoMem);
	if (iError)
	{
		DBG_PRINTF("GenerateIntervalPageSpecialIcon error!\n");
	}
	
	/* 3. 刷到设备上去 */
	FlushVideoMemToDev(ptVideoMem);

	/* 4. 解放显存 */
	PutVideoMem(ptVideoMem);
}
Ejemplo n.º 18
0
static int videoin_mmap (struct file *file, struct vm_area_struct *vma)
{	
	struct video_device *dev = video_devdata(file);
	videoin_priv_t *priv = (videoin_priv_t *)dev->priv;
	unsigned long start = vma->vm_start;
	unsigned long size  = vma->vm_end-vma->vm_start;
	unsigned long page, pos;
	DBG_PRINTF("%s\n",__FUNCTION__);	
	DBG_PRINTF("start = 0x%x\n",start);
	DBG_PRINTF("size = 0x%x\n",size);
	
	if(bDumpframeBuffer==0)	
		pos = videoIn_buf[0].u32VirtAddr;	
	else
		pos = videoIn_buf[3].u32VirtAddr;
	priv->mmap_bufsize = size;
	while (size > 0) 
	{
		page = vmalloc_to_pfn((void *)pos);
		if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
		{
			ERR_PRINTF("remap error\n");
			return -EAGAIN;
		}
		start += PAGE_SIZE;
		pos += PAGE_SIZE;
		if (size > PAGE_SIZE)
			size -= PAGE_SIZE;
		else
			size = 0;
	}
	return 0;
	
}
Ejemplo n.º 19
0
unsigned long videoin_dmamalloc_phy(unsigned int u32Buf, unsigned long size)
{
	videoin_priv_t *priv = (videoin_priv_t *)&videoin_priv;
	void *mem;
	unsigned long adr;

	DBG_PRINTF("%s\n",__FUNCTION__);	
	size = PAGE_ALIGN(size);	
	priv->vaddr = dma_alloc_writecombine(NULL/*dev*/, 
									size,&priv->paddr, 
									GFP_KERNEL);	
	printk("videoin priv->paddr=%x,priv->vaddr=%x\n", priv->paddr, priv->vaddr);
	if (!priv->vaddr)
		return NULL;

	adr = (unsigned long) priv->vaddr;
	videoIn_buf[u32Buf].u32PhysAddr = priv->paddr;
	if(u32Buf<3)
		videoIn_buf[u32Buf+5].u32PhysAddr;
	videoIn_buf[u32Buf].u32VirtAddr = adr;
	while (size > 0) {
		SetPageReserved(vmalloc_to_page((void *)adr));		
		adr += PAGE_SIZE;
		size -= PAGE_SIZE;		
	}
	DBG_PRINTF("SetPageReserved = 0x%x\n", adr);
	return priv->paddr;
}
Ejemplo n.º 20
0
/* the real action:
	- increment the forced update times counter
	- detect current IP
		- connect to an HTTP server 
		- parse the response for IP addr

	- for all the names that have to be maintained
		- get the current DYN DNS address from DYN DNS server
		- compare and update if neccessary
*/
RC_TYPE dyn_dns_update_ip(DYN_DNS_CLIENT *p_self)
{
	RC_TYPE rc;

	if (p_self == NULL)
	{
		return RC_INVALID_POINTER;
	}

	do
	{
		/*ask IP server something so he will respond and give me my IP */
		rc = do_ip_server_transaction(p_self);
		if (rc != RC_OK)
		{
			DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error '%s' (0x%x) when talking to IP server\n",
				errorcode_get_name(rc), rc));
			break;
		}
		if (p_self->dbg.level > 1)
		{
			DBG_PRINTF((LOG_DEBUG,"DYNDNS: IP server response: %s\n", p_self->p_work_buffer));		
		}

		/*extract my IP, check if different than previous one*/
		rc = do_parse_my_ip_address(p_self);
		if (rc != RC_OK)
		{	
			break;
		}
		
		if (p_self->dbg.level > 1)
		{
			DBG_PRINTF((LOG_WARNING,"W: DYNDNS: My IP address: %s\n", p_self->info.my_ip_address.name));		
		}

		/*step through aliases list, resolve them and check if they point to my IP*/
		rc = do_check_alias_update_table(p_self);
		if (rc != RC_OK)
		{	
			break;
		}

		/*update IPs marked as not identical with my IP*/
		rc = do_update_alias_table(p_self);
		if (rc != RC_OK)
		{	
			break;
		}
	}
	while(0);

	return rc;
}
Ejemplo n.º 21
0
/**********************************************************************
 * 函数名称: PicZoom
 * 功能描述: 近邻取样插值方法缩放图片
 *            注意该函数会分配内存来存放缩放后的图片,用完后要用free函数释放掉
 *            "近邻取样插值"的原理请参考网友"lantianyu520"所著的"图像缩放算法"
 * 输入参数: ptOriginPic - 内含原始图片的象素数据
 *            ptBigPic    - 内含缩放后的图片的象素数据
 * 输出参数: 无
 * 返 回 值: 0 - 成功, 其他值 - 失败
 * 修改日期        版本号     修改人	      修改内容
 * -----------------------------------------------
 * 2013/02/08	     V1.0	  韦东山	      创建
 ***********************************************************************/
int PicZoom(PT_PixelDatas ptOriginPic, PT_PixelDatas ptZoomPic)
{
    unsigned long dwDstWidth = ptZoomPic->iWidth;
    unsigned long* pdwSrcXTable;
	unsigned long x;
	unsigned long y;
	unsigned long dwSrcY;
	unsigned char *pucDest;
	unsigned char *pucSrc;
	unsigned long dwPixelBytes = ptOriginPic->iBpp/8;

    DBG_PRINTF("src:\n");
    DBG_PRINTF("%d x %d, %d bpp, data: 0x%x\n", ptOriginPic->iWidth, ptOriginPic->iHeight, ptOriginPic->iBpp, (unsigned int)ptOriginPic->aucPixelDatas);

    DBG_PRINTF("dest:\n");
    DBG_PRINTF("%d x %d, %d bpp, data: 0x%x\n", ptZoomPic->iWidth, ptZoomPic->iHeight, ptZoomPic->iBpp, (unsigned int)ptZoomPic->aucPixelDatas);

	if (ptOriginPic->iBpp != ptZoomPic->iBpp)
	{
		return -1;
	}

    pdwSrcXTable = malloc(sizeof(unsigned long) * dwDstWidth);
    if (NULL == pdwSrcXTable)
    {
        DBG_PRINTF("malloc error!\n");
        return -1;
    }

    for (x = 0; x < dwDstWidth; x++)//生成表 pdwSrcXTable
    {
        pdwSrcXTable[x]=(x*ptOriginPic->iWidth/ptZoomPic->iWidth);
    }

    for (y = 0; y < ptZoomPic->iHeight; y++)
    {			
        dwSrcY = (y * ptOriginPic->iHeight / ptZoomPic->iHeight);

		pucDest = ptZoomPic->aucPixelDatas + y*ptZoomPic->iLineBytes;
		pucSrc  = ptOriginPic->aucPixelDatas + dwSrcY*ptOriginPic->iLineBytes;
		
        for (x = 0; x <dwDstWidth; x++)
        {
            /* 原图座标: pdwSrcXTable[x],srcy
             * 缩放座标: x, y
			 */
			 memcpy(pucDest+x*dwPixelBytes, pucSrc+pdwSrcXTable[x]*dwPixelBytes, dwPixelBytes);
        }
    }

    free(pdwSrcXTable);
	return 0;
}
Ejemplo n.º 22
0
/* 
  Update the contents for the message pointed to by 'msg', if it's in the
  model, otherwise ignore the request.  Currently the contents are the
  status (icon) and the priority. Other changes such as in the subject
  or the date could be visually reflected by this function if the UI
  permitted those changes.
*/
void
mail_item_model::update_msg(const mail_msg* msg)
{
  DBG_PRINTF(4, "update_msg of " MAIL_ID_FMT_STRING, msg->get_id());
  QStandardItem* item=item_from_id(msg->get_id());
  if (!item)
    return;
  QModelIndex index=item->index();
  QStandardItem* isubject = itemFromIndex(index);
  bool bold=isubject->font().bold();
  DBG_PRINTF(5, "mail_id=" MAIL_ID_FMT_STRING ", status=%d, bold=%d",
	     msg->get_id(), msg->status(), bold);
  if ((msg->status()!=0 && bold) || (msg->status()==0 && !bold)) {
    // reverse bold attribute
    QFont f=isubject->font();
    f.setBold(!bold);
    isubject->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_sender))->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_date))->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_pri))->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_recipient))->setFont(f);
  }

  // status icon
  QIcon* icon = icon_status(msg->status());
  QStandardItem* istatus = itemFromIndex(index.sibling(index.row(), column_status));
  if (istatus) {
    if (icon)
      istatus->setIcon(*icon);
    else
      istatus->setIcon(QIcon());
  }

  // priority
  QStandardItem* ipri = itemFromIndex(index.sibling(index.row(), column_pri));
  if (ipri) {
    if (msg->priority()!=0)
      ipri->setText(QString("%1").arg(msg->priority()));
    else
      ipri->setText("");
  }

  // note
  QStandardItem* inote = itemFromIndex(index.sibling(index.row(), column_note));
  if (inote) {
    inote->setData(msg->has_note());
    if (msg->has_note())
      inote->setIcon(STATUS_ICON(FT_ICON16_EDIT_NOTE));
    else
      inote->setIcon(QIcon());
  }

}
Ejemplo n.º 23
0
void
tags_box_widget::unset_tag(int tag_id)
{
  DBG_PRINTF(5,"tags_box_widget::unset_tag(%d)", tag_id);
  tag_lvitem* item = find(tag_id);
  if (item) {
    item->set_on(false);
  }
  else {
    DBG_PRINTF(5,"Error: can't tag_lvitem button with id=%d in tagsbox", tag_id);
  }
}
Ejemplo n.º 24
0
/*******************************************************************************
* Function Name: CpsInit()
********************************************************************************
*
* Summary:
*   Initializes the SCP service.
*
*******************************************************************************/
void CpsInit(void)
{
    CYBLE_API_RESULT_T apiResult;
    uint16 cccdValue;
    CYBLE_CPS_SL_VALUE_T sensorLocation = CYBLE_CPS_SL_TOP_OF_SHOE;
    
    /* Register service specific callback function */
    CyBle_CpsRegisterAttrCallback(&CpsCallback);
    /* Read CCCD configurations from flash */
    apiResult = CyBle_CpssGetCharacteristicDescriptor(CYBLE_CPS_POWER_MEASURE, CYBLE_CPS_CCCD, 
        CYBLE_CCCD_LEN, (uint8 *)&cccdValue);
    if((apiResult == CYBLE_ERROR_OK) && (cccdValue != 0u))
    {
        powerSimulation |= CPS_NOTIFICATION_MEASURE_ENABLE;
    }
    apiResult = CyBle_CpssGetCharacteristicDescriptor(CYBLE_CPS_POWER_VECTOR, CYBLE_CPS_CCCD, 
        CYBLE_CCCD_LEN, (uint8 *)&cccdValue);
    if((apiResult == CYBLE_ERROR_OK) && (cccdValue != 0u))
    {
        powerSimulation |= CPS_NOTIFICATION_VECTOR_ENABLE;
    }
    
    /* Read flags of Power Measure characteristic default value */
    apiResult = CyBle_CpssGetCharacteristicValue(CYBLE_CPS_POWER_MEASURE, sizeof(powerMeasure.flags), (uint8 *)&powerMeasure);
    if((apiResult != CYBLE_ERROR_OK))
    {
        DBG_PRINTF("CyBle_CpssGetCharacteristicValue API Error: %x \r\n", apiResult);
    }
    
    /* Read flags of Power Vector characteristic default value */
    apiResult = CyBle_CpssGetCharacteristicValue(CYBLE_CPS_POWER_VECTOR, sizeof(powerVector.flags), (uint8 *)&powerVector);
    if((apiResult != CYBLE_ERROR_OK))
    {
        DBG_PRINTF("CyBle_CpssGetCharacteristicValue API Error: %x \r\n", apiResult);
    }

    /* Set default values which might be placed in EEPROM by application */
    cyBle_cpssAdjustment.factoryCalibrationDate.year = 2014;
    cyBle_cpssAdjustment.factoryCalibrationDate.day = 12;
    cyBle_cpssAdjustment.factoryCalibrationDate.month = 12;
    
    powerMeasure.instantaneousPower = CPS_SIM_POWER_INIT; 
    powerMeasure.accumulatedTorque = CPS_SIM_TORQUE_INIT;
    powerMeasure.cumulativeWheelRevolutions = CPS_SIM_CUMULATIVE_WHEEL_REVOLUTION_INIT;
    powerMeasure.lastWheelEventTime = CPS_SIM_WHEEL_EVENT_TIME_INIT;
    powerMeasure.accumulatedEnergy = CPS_SIM_ACCUMULATED_ENERGY_INIT;
    
    powerVector.cumulativeCrankRevolutions += CPS_SIM_CUMULATIVE_CRANK_REVOLUTION_INIT;
    powerVector.lastCrankEventTime += CPS_SIM_CRANK_EVENT_TIME_INIT;
    
    CyBle_CpssSetCharacteristicValue(CYBLE_CPS_SENSOR_LOCATION, sizeof(uint8), (uint8 *)&sensorLocation);
}
Ejemplo n.º 25
0
int
main (int argc, char **argv)
{
  UProfReport *report;
  UProfContext *context;
  int i;

  uprof_init (&argc, &argv);

  context = uprof_context_new ("Test");


  for (i = 0; i < 4; i ++)
    {
      struct timespec delay;

      if (i == 1)
        {
          DBG_PRINTF ("suspending context\n");
          uprof_context_suspend (context);
        }

      UPROF_COUNTER_INC (context, loop_counter);

      UPROF_TIMER_START (context, loop_timer);
      DBG_PRINTF ("  <delay: 1 sec>\n");
      delay.tv_sec = 1;
      delay.tv_nsec = 0;
      nanosleep (&delay, NULL);

      UPROF_TIMER_STOP (context, loop_timer);
      DBG_PRINTF ("stop simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n",
                  uprof_get_system_counter ());

      if (i == 2)
        {
          DBG_PRINTF ("resuming context\n");
          uprof_context_resume (context);
        }
    }

  DBG_PRINTF ("Expected result = 2 seconds accounted for and count == 2:\n");

  report = uprof_report_new ("Suspend report");
  uprof_report_add_context (report, context);
  uprof_report_print (report);
  uprof_report_unref (report);

  uprof_context_unref (context);

  return 0;
}
Ejemplo n.º 26
0
void
message_view::load_finished(bool ok)
{
  if (ok) {
    DBG_PRINTF(5, "load_finished");
    m_bodyv->set_loaded(true);
    if (!m_highlight_words.empty()) {
      m_bodyv->highlight_terms(m_highlight_words);
    }
  }
  else {
    DBG_PRINTF(2, "load_finished not OK");
  }
}
Ejemplo n.º 27
0
/*
  Called by an msg_list_window to update counters when a mail tag
  has changed. 'added' is true if the tag has been added, false if removed
*/
void
query_listview::mail_tag_changed(const mail_msg& msg, uint tag_id, bool added)
{
  DBG_PRINTF(8, "mail_tag_changed mail_id=%u, tag=%u %s\n", msg.get_id(),
	     tag_id, added?"added":"removed");
  qs_tag_map::iterator itt = m_tagged.find(tag_id);
  qs_tag_map::iterator it_no_tag = m_tagged.find(0);
  if (itt!=m_tagged.end()) {
    // the leaf for the tag already exists
    qs_mail_map* m = itt->second;
    if (added) {
      (*m)[msg.get_id()] = msg.status();
    }
    else {
      m->erase(msg.get_id());
      // if the message no longer has any tag, update the 'Not Tagged' branches
      if (msg.get_cached_tags().empty() && it_no_tag!=m_tagged.end()) {
	qs_mail_map* m_no_tag = it_no_tag->second;
	(*m_no_tag)[msg.get_id()] = msg.status();
	update_tag_current_counter(0);
	display_counter(query_lvitem::new_not_tagged);
      }	
    }
    update_tag_current_counter(tag_id);
    // update the 'Not Tagged' branch counter if the mail was counted in it
    if (added) {
      if (it_no_tag!=m_tagged.end()) {
	m = it_no_tag->second;
	qs_mail_map::iterator qi;
	qi = m->find(msg.get_id());
	if (qi!=m->end()) {
	  m->erase(msg.get_id());
	  update_tag_current_counter(0);
	}
      }
    }
  }
  else {
    DBG_PRINTF(8, "create a new tag branch for '%u' in query_listview\n", tag_id);
    add_current_tag(tag_id);	// adds tag_id to m_tagged
    itt = m_tagged.find(tag_id);
    if (itt!=m_tagged.end()) {
      qs_mail_map* m = itt->second;
      (*m)[msg.get_id()] = msg.status();
      update_tag_current_counter(tag_id);
    }
    else
      DBG_PRINTF(1, "ERR: couldn't find tag map for tag_id=%u just added\n", tag_id);
  }
}
Ejemplo n.º 28
0
/**
  * @brief    Repeat Control IN pipe
  *
  * @param    None
  *
  * @return   None
  *
  * @details  This function processes the remained data of Control IN transfer.
  *
  */
void USBD_CtrlIn(void)
{
    static uint8_t u8ZeroFlag = 0;
    
    DBG_PRINTF("Ctrl In Ack. residue %d\n", g_usbd_CtrlInSize);
    if(g_usbd_CtrlInSize)
    {
        // Process remained data
        if(g_usbd_CtrlInSize > g_usbd_CtrlMaxPktSize)
        {
            // Data size > MXPLD
            USBD_MemCopy((uint8_t *)USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP0), (uint8_t *)g_usbd_CtrlInPointer, g_usbd_CtrlMaxPktSize);
            USBD_SET_PAYLOAD_LEN(EP0, g_usbd_CtrlMaxPktSize);
            g_usbd_CtrlInPointer += g_usbd_CtrlMaxPktSize;
            g_usbd_CtrlInSize -= g_usbd_CtrlMaxPktSize;
        }
        else
        {
            // Data size <= MXPLD
            USBD_MemCopy((uint8_t *)USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP0), (uint8_t *)g_usbd_CtrlInPointer, g_usbd_CtrlInSize);
            USBD_SET_PAYLOAD_LEN(EP0, g_usbd_CtrlInSize);
            if(g_usbd_CtrlInSize == g_usbd_CtrlMaxPktSize)
                u8ZeroFlag = 1;
            g_usbd_CtrlInPointer = 0;
            g_usbd_CtrlInSize = 0;
        }
    }
    else // No more data for IN token
    {
        // In ACK for Set address
        if((g_usbd_SetupPacket[0] == REQ_STANDARD) && (g_usbd_SetupPacket[1] == USBD_SET_ADDRESS))
        {
            if((USBD_GET_ADDR() != g_usbd_UsbAddr) && (USBD_GET_ADDR() == 0))
            {
                USBD_SET_ADDR(g_usbd_UsbAddr);
            }
        }

        /* For the case of data size is integral times maximum packet size */
        if(u8ZeroFlag)
        {
            USBD_SET_PAYLOAD_LEN(EP0, 0);
            u8ZeroFlag = 0;
        }
        
        DBG_PRINTF("Ctrl In done.\n");

    }
}
Ejemplo n.º 29
0
/*----------------------------------------------------------------------------*/
static inline int
find_free_slot(void)
{
  int i;

  DBG_PRINTF("find_free_slot()\n");
  for(i = 0; i < NUM_SLOT; i++) {
    if(!used[i]) {
      DBG_PRINTF("Slot ID: %d\n", i);
      return i;
    }
  }
  printf("T-Res: Mem: Error: no free slot available\n");
  return -1;
}
Ejemplo n.º 30
0
int
pgConnection::logon(const char* conninfo)
{
  m_pgConn = PQconnectdb(conninfo);
  if (!m_pgConn) {
    throw db_excpt("connect", "not enough memory");
  }
  DBG_PRINTF(5,"logon m_pgConn=0x%p", m_pgConn);
  if (PQstatus(m_pgConn) == CONNECTION_BAD) {
    throw db_excpt("connect", PQerrorMessage(m_pgConn));
  }

  /* If the user has set PGCLIENTENCODING in its environment, then we decide
     to do no translation behind the postgresql client layer, since we
     assume that the user knows what he's doing. In the future, we may
     decide for a fixed encoding (that would be unicode/utf8, most
     probably) and override PGCLIENTENCODING. */
  if (!getenv("PGCLIENTENCODING")) {
    PGresult* res=PQexec(m_pgConn, "SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname=current_database()");
    if (res && PQresultStatus(res)==PGRES_TUPLES_OK) {
      const char* enc=(const char*)PQgetvalue(res,0,0);
      // pgsql versions under 8.1 return 'UNICODE', >=8.1 return 'UTF8'
      // we keep UTF8
      if (!strcmp(enc,"UNICODE"))
        enc="UTF8";
      set_encoding(enc);
    }
    if (res)
      PQclear(res);
  }
  PQclear(PQexec(m_pgConn, "SET standard_conforming_strings=on"));
  return 1;
}