Esempio n. 1
0
void
mt_kbd_init(void){
    keymap = keymaps[0];
    kbd_name = names[0];
    scan_mq = CreateMsgQueue("Scan code", KBDBUFSIZE, 1, false, false);
    key_mq = CreateMsgQueue("Input key", KBDBUFSIZE, 1, true, false);
    Ready(CreateTask(input_task, 0, NULL, "Input task", INPUTPRIO));
    mt_set_int_handler(KBDINT, kbdint);
    mt_enable_irq(KBDINT);
}
Esempio n. 2
0
PipeImpl::PipeImpl()
: _out(PipeIODevice::Read)
, _in(PipeIODevice::Write)
{
    MSGQUEUEOPTIONS writeOpts, readOpts;

    memset(&writeOpts, 0, sizeof(writeOpts));
    memset(&readOpts,  0, sizeof(readOpts));

    writeOpts.dwSize          = sizeof(MSGQUEUEOPTIONS);
    writeOpts.dwFlags         = MSGQUEUE_ALLOW_BROKEN;
    writeOpts.dwMaxMessages   = 100;
    writeOpts.cbMaxMessage    = 1024;
    writeOpts.bReadAccess     = FALSE;

    readOpts = writeOpts;
    readOpts.bReadAccess     = TRUE;

    HANDLE outputHandle = CreateMsgQueue(NULL, &writeOpts);
    if (outputHandle == INVALID_HANDLE_VALUE)
        throw IOError( PT_ERROR_MSG("Could not create message queue handle") );

    HANDLE inputHandle  = OpenMsgQueue(::GetCurrentProcess(), outputHandle, &readOpts);
    if (inputHandle == INVALID_HANDLE_VALUE)
        throw IOError( PT_ERROR_MSG("Could not open message queue handle") );

    _out.open(inputHandle);
    _in.open(outputHandle);
}
Esempio n. 3
0
BOOL CreateAPnpMsgQueue(PHANDLE phQueue, PHANDLE phNoti, GUID inGUID )
{
    if(phQueue == NULL || phNoti == NULL){
        return FALSE;
    }

    MSGQUEUEOPTIONS msgqopts = {0};    
    msgqopts.dwSize = sizeof(MSGQUEUEOPTIONS);
    msgqopts.dwFlags = 0;
    msgqopts.cbMaxMessage = QUEUE_ITEM_SIZE;
    msgqopts.bReadAccess = TRUE;
    
    *phQueue = NULL;
    *phQueue = CreateMsgQueue(NULL, &msgqopts);

    if(*phQueue == NULL){
        return FALSE;
    }

    *phNoti = RequestDeviceNotifications(&inGUID, *phQueue, FALSE);
    if(*phNoti == NULL){
        CloseMsgQueue(hPnpQueue);
        return FALSE;
    }

    return TRUE;
}
static void createDeviceNotificationQueue(HANDLE& queue, HANDLE& notif)
{
    MSGQUEUEOPTIONS msgopts;
    msgopts.dwSize = sizeof(msgopts);
    msgopts.dwFlags = 0;
    msgopts.dwMaxMessages = 0;
    msgopts.cbMaxMessage = sizeof(DEVDETAIL) + MAX_DEVCLASS_NAMELEN;
    msgopts.bReadAccess = TRUE;
    queue = CreateMsgQueue(NULL, &msgopts);
    notif = RequestDeviceNotifications(UkwDriverGUID(), queue, TRUE);
}
Esempio n. 5
0
void startMsgQueue(HWND hWnd){
	DEBUGMSG(1, (L"Entering msgQueue with hwnd=%i\n", hWnd));

	MSGQUEUEOPTIONS mqOptions;
	memset (&mqOptions, 0, sizeof(mqOptions));

	mqOptions.dwFlags = 0;
	mqOptions.dwSize = sizeof(mqOptions);
	mqOptions.dwMaxMessages = 10;
	mqOptions.cbMaxMessage = sizeof(BTEVENT);
	mqOptions.bReadAccess = TRUE;

	hMsgQ = CreateMsgQueue(NULL, &mqOptions);
	if (! hMsgQ) {
		nclog(L"Error creating message queue.\n");
		goto exit;
	}
	hBTNotif = RequestBluetoothNotifications(
		BTE_CLASS_CONNECTIONS	|
			BTE_CONNECTION			|
			BTE_DISCONNECTION		|
			BTE_ROLE_SWITCH			|
			BTE_MODE_CHANGE			|
			BTE_PAGE_TIMEOUT		|
			BTE_CONNECTION_AUTH_FAILURE	|
		BTE_CLASS_PAIRING	|
			BTE_KEY_NOTIFY	|
			BTE_KEY_REVOKED	|
		BTE_CLASS_DEVICE	|
			BTE_LOCAL_NAME	|
			BTE_COD			|
		BTE_CLASS_STACK		|
			BTE_STACK_UP	|
			BTE_STACK_DOWN	
		, hMsgQ);

	bStop=FALSE;
	CreateThread(NULL, 0, msgThread, hWnd, 0, &threadID);

exit:
	;
}
Esempio n. 6
0
void DispDrvrInitialize(void)
{
	PHYSICAL_ADDRESS ioPhysicalBase = {0,0};

	ioPhysicalBase.LowPart = S3C6410_BASE_REG_PA_SROMCON;
	g_pSROMReg = (volatile S3C6410_SROMCON_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(S3C6410_SROMCON_REG), FALSE);
	if (NULL == g_pSROMReg)
	{
		MYERR((_T("[S1D13521_ERR] pSROMregs = MmMapIoSpace()\r\n")));
		return;
	}
	g_pSROMReg->SROM_BW = (g_pSROMReg->SROM_BW & ~(0xF<<16)) |
							(0<<19) |		// nWBE/nBE(for UB/LB) control for Memory Bank1(0=Not using UB/LB, 1=Using UB/LB)
							(0<<18) |		// Wait enable control for Memory Bank1 (0=WAIT disable, 1=WAIT enable)
							(1<<16);		// Data bus width control for Memory Bank1 (0=8-bit, 1=16-bit)
	g_pSROMReg->SROM_BC4 = (0x7<<28) |	// Tacs
							(0x7<<24) | 	// Tcos
							(0xF<<16) | 	// Tacc
							(0x7<<12) | 	// Tcoh
							(0x7<< 8) | 	// Tah
							(0x7<< 4) | 	// Tacp
							(0x0<< 0);		// PMC

	ioPhysicalBase.LowPart = S3C6410_BASE_REG_PA_GPIO;
	g_pGPIOPReg = (volatile S3C6410_GPIO_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(S3C6410_GPIO_REG), FALSE);
	if (NULL == g_pGPIOPReg)
	{
		MYERR((_T("[S1D13521_ERR] g_pGPIOPReg = MmMapIoSpace()\r\n")));
		return;
	}
	// GPN[8] : EPD_HRDY(8)
	g_pGPIOPReg->GPNCON = (g_pGPIOPReg->GPNCON & ~(0x3<<16)) | (0x0<<16);	// input mode
	g_pGPIOPReg->GPNPUD = (g_pGPIOPReg->GPNPUD & ~(0x3<<16)) | (0x0<<16);	// pull-up/down disable

	ioPhysicalBase.LowPart = S1D13521_BASE_PA;
	g_pS1D13521Reg = (volatile S1D13521_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(S1D13521_REG), FALSE);
	if (NULL == g_pS1D13521Reg)
	{
		MYERR((_T("[S1D13521_ERR] g_pS1D13521Reg != MmMapIoSpace()\r\n")));
		return;
	}

	for (int i=0, j=0, v=0; i<DispDrvr_palSize; i++)
	{
#if	(LCD_BPP == 4)
		v = i * 0x11;
#elif	(LCD_BPP == 8)
		v = i;
#endif
		DispDrvr_palette[i].rgbRed = DispDrvr_palette[i].rgbGreen = DispDrvr_palette[i].rgbBlue = v;
		DispDrvr_palette[i].rgbReserved = 0;
	}

	InitializeCriticalSection(&g_CS);
	g_hDirtyRect = DirtyRect_Init(workDirtyRect);
	S1d13521Initialize((void *)g_pS1D13521Reg, (void *)g_pGPIOPReg);

	MSGQUEUEOPTIONS msgopts;
	memset(&msgopts, 0, sizeof(msgopts));
	msgopts.dwSize = sizeof(msgopts);
	msgopts.dwFlags = 0;	//MSGQUEUE_ALLOW_BROKEN;
	msgopts.dwMaxMessages = 0;	// no max number of messages
	msgopts.cbMaxMessage = sizeof(DIRTYRECTINFO);	// max size of each msg
	msgopts.bReadAccess = FALSE;
	g_hMQ = CreateMsgQueue(MSGQUEUE_NAME, &msgopts);
	MYMSG((_T("[S1D13521_MSG] CreateMsgQueue(Write) == 0x%X\r\n"), g_hMQ));
}
Esempio n. 7
0
void ResetOtherThread(void)
{
	UsedBuf *CameraBuf=NULL;
	if((g_mailinfo = (Mail_Info*)malloc(sizeof(Mail_Info))) ==NULL)
		PRINT_MEM_OUT;
	else
		MailInfoInit(g_mailinfo);
	/*init mail  buffer*/
	{ 
		int mailsize;
		char *mailbuf;
		mailsize  = get_mailmem_size(1);
		mailbuf = (char*)malloc(mailsize);
		if(mailbuf == NULL)
			printf("not enough memory for mail\n");
		else		
			memset(mailbuf, 0, mailsize);	
		mail_mem_init(mailbuf, mailsize);		
		
	}			
	cyg_thread_create(PTD_PRIORITY, &MailStart, (cyg_addrword_t)g_mailinfo, "mail_start", mail_stack,
                        STACK, &mail_handle, &mail_thread);
	if ( mail_handle == NULL)
	{
		printf("Thread for mail creation failed!\n");
		exit(-1);
	}
    
    cyg_thread_resume(mail_handle);
#ifdef RECORDER
	Mail_Info *mailinfo;
	Ftp_Info *ftpinfo;
	if((mailinfo = (Mail_Info*)malloc(sizeof(Mail_Info))) ==NULL)
		PRINT_MEM_OUT;
	else
		MailInfoInit(mailinfo);		
	if((ftpinfo = (Ftp_Info*)malloc(sizeof(Ftp_Info))) == NULL)
	 	PRINT_MEM_OUT;
	else
		FtpInfoInit(ftpinfo);		
	recorder_releative_thread_create(ftpinfo,mailinfo);
	/*init mail and ftp buffer*/
	{ 
		int mailsize,ftpsize;
		char *mailbuf,*ftpbuf;
		mailsize  = get_mailmem_size(0);
		mailbuf = (char*)malloc(mailsize);
		if(mailbuf == NULL)
			printf("not enough memory for mail\n");
		else		
			memset(mailbuf, 0, mailsize);	
		mail_mem_init(mailbuf, mailsize);
		
		ftpsize = get_ftpmem_size(0);
    	ftpbuf = (char*)malloc(ftpsize);
    	if(ftpbuf == NULL)
    		printf("not enough memory for ftp\n");
    	else 
    		memset(ftpbuf, 0, ftpsize);    	
    	ftp_mem_init(ftpbuf, ftpsize);
	}
	{
	   struct mallinfo info;
  	   info = mallinfo();
 	   diag_printf("******max %x, totalfree %x, total allocated %x\n",info.maxfree,info.fordblks, info.uordblks);
	}	
#endif
#ifdef USE_DDNS
	/* set message and thread for ntp */
	if ((g_pMsgSelect = CreateMsgQueue(0, TRUE)) == NULL)
	{
		fprintf(stderr, "Can not create message queue for SelectThread!\n");
		return;
	}
	
	cyg_thread_create(PTD_PRIORITY, &SelectThread, NULL, "ptdSelect", ptdSelect_stack, STACKSIZE, &ptdSelect_handle, &g_ptdSelect);
	if ( ptdSelect_handle == NULL)
	{
		fprintf(stderr, "Thread for \"Select\" creation failed!\n");
		return;
	}
	cyg_thread_resume(ptdSelect_handle);
#endif
#ifdef USE_FLASH
	/* set message and thread for flash */
	if ((g_pMsgFlash = CreateMsgQueue(0, FALSE)) == NULL)
	{
		fprintf(stderr, "Can not create message queue for FtpThread!\n");
		return;
	}
	
	
	cyg_thread_create(PTD_PRIORITY, &FlashThread, NULL, "ptdFlash", ptdFlash_stack, STACKSIZE, &ptdFlash_handle, &g_ptdFlash);
	if ( ptdFlash_handle == NULL)
	{
		fprintf(stderr, "Thread for ftp creation failed!\n");
		return;
	}
	cyg_thread_resume(ptdFlash_handle);	
#endif
	/* set message and thread for camera*/	 
	CameraBuf = (UsedBuf*)malloc(sizeof(UsedBuf));
	if (CameraBuf == NULL)
		return;
	//CameraBuf->AssignLen = MAX_CAMERA_IMG_LENGTH*2+MAX_CAMERA_MP4_LENGTH;
	CameraBuf->AssignLen = MAX_CAMERA_IMG_LENGTH * 2;
	CameraBuf->AssignBuffer  =  (char*)malloc(CameraBuf->AssignLen );
	if(CameraBuf->AssignBuffer  == NULL)
	{
		diag_printf("Malloc Camera Buffer False!!!!!!!\n");
	}
	memset(CameraBuf->AssignBuffer,0,CameraBuf->AssignLen);
	
	/**/
	if ((g_pMsgCamera = CreateMsgQueue(0, FALSE)) == NULL)
	{
		fprintf(stderr, "Can not create message queue for CameraThread!\n");
		return;
	}
	
	cyg_thread_create(PTD_PRIORITY, &CameraThread,(cyg_addrword_t) CameraBuf, "ptdCamera", ptdCamera_stack, STACKSIZE, &ptdCamera_handle, &g_ptdCamera);
	if ( ptdCamera_handle == NULL)
	{
		fprintf(stderr, "Thread for camera creation failed!\n");
		return;
	}
	cyg_thread_resume(ptdCamera_handle);
	
	// change it to sample;
	 VirtualComInit();
	 diag_printf("VcomByUSBInit successfully\n");

}
Esempio n. 8
0
HI_VOID *sw_HIFB_REFRESH(void *pData)
{
    HI_S32 s32Ret = HI_SUCCESS;
    HIFB_LAYER_INFO_S stLayerInfo = {0};
    HIFB_BUFFER_S stCanvasBuf;
    HI_U16 *pBuf;
    HI_U32 x, y;
    HI_BOOL Show;
    HI_BOOL bCompress = HI_TRUE;
    HIFB_POINT_S stPoint = {0};
    struct fb_var_screeninfo stVarInfo;
    char file[12] = "/dev/fb0";
    HI_U32 maxW,maxH;
    PTHREAD_HIFB_sw_INFO *pstInfo;
    pstInfo = (PTHREAD_HIFB_sw_INFO *)pData;
    HIFB_COLORKEY_S stColorKey;
    switch (pstInfo->layer)
    {
    case 0 :
        strcpy(file, "/dev/fb0");
        break;
    case 1 :
        strcpy(file, "/dev/fb1");
        break;
    case 2 :
        strcpy(file, "/dev/fb2");
        break;
    case 3 :
        strcpy(file, "/dev/fb3");
        break;
    case 4 :
        strcpy(file, "/dev/fb4");
        break;

    default:
        strcpy(file, "/dev/fb0");
        break;
    }
    pstInfo->fd = open(file, O_RDWR, 0);
    if (pstInfo->fd < 0)
    {
        printf("open %s failed!\n",file);
        return HI_NULL;
    }

    if (pstInfo->layer == HIFB_LAYER_0 )
    {
        if (ioctl(pstInfo->fd, FBIOPUT_COMPRESSION_HIFB, &bCompress) < 0)
        {
            printf("FBIOPUT_COMPRESSION_HIFB failed!\n");
            close(pstInfo->fd);
            return HI_NULL;
        }
    }
    stColorKey.bKeyEnable = HI_TRUE;
    stColorKey.u32Key = 0x0;
    if (ioctl(pstInfo->fd, FBIOPUT_COLORKEY_HIFB, &stColorKey) < 0)
    {
        printf("FBIOPUT_COLORKEY_HIFB!\n");
        close(pstInfo->fd);
        return HI_NULL;
    }

    s32Ret = ioctl(pstInfo->fd, FBIOGET_VSCREENINFO, &stVarInfo);
    if (s32Ret < 0)
    {
        printf("GET_VSCREENINFO failed!\n");
        return HI_NULL;
    }

    if (ioctl(pstInfo->fd, FBIOPUT_SCREEN_ORIGIN_HIFB, &stPoint) < 0)
    {
        printf("set screen original show position failed!\n");
        return HI_NULL;
    }
    
    maxW = 1280;
    maxH = 720;
    stVarInfo.xres = stVarInfo.xres_virtual = maxW;
    stVarInfo.yres = stVarInfo.yres_virtual = maxH;
    setRelolution(maxW,maxH);
    s32Ret = ioctl(pstInfo->fd, FBIOPUT_VSCREENINFO, &stVarInfo);
    if (s32Ret < 0)
    {
        printf("PUT_VSCREENINFO failed!\n");
        return HI_NULL;
    }

    switch (pstInfo->ctrlkey)
    {
        case 0 :
        {
            stLayerInfo.BufMode = HIFB_LAYER_BUF_ONE;
            stLayerInfo.u32Mask = HIFB_LAYERMASK_BUFMODE;
            break;
        }

        case 1 :
        {
            stLayerInfo.BufMode = HIFB_LAYER_BUF_DOUBLE;
            stLayerInfo.u32Mask = HIFB_LAYERMASK_BUFMODE;
            break;
        }

        default:
        {
            stLayerInfo.BufMode = HIFB_LAYER_BUF_NONE;
            stLayerInfo.u32Mask = HIFB_LAYERMASK_BUFMODE;
        }
    }

    s32Ret = ioctl(pstInfo->fd, FBIOPUT_LAYER_INFO, &stLayerInfo);
    if (s32Ret < 0)
    {
        printf("PUT_LAYER_INFO failed!\n");
        return HI_NULL;
    }
    Show = HI_TRUE;
    if (ioctl(pstInfo->fd, FBIOPUT_SHOW_HIFB, &Show) < 0)
    {
        printf("FBIOPUT_SHOW_HIFB failed!\n");
        return HI_NULL;
    }
    if (HI_FAILURE == HI_MPI_SYS_MmzAlloc(&(stCanvasBuf.stCanvas.u32PhyAddr), ((void**)&pBuf),
                                          NULL, NULL, maxW*maxH*2))
    {
        printf("allocate memory (maxW*maxH*2 bytes) failed\n");
        return HI_NULL;
    }
    
    stCanvasBuf.stCanvas.u32Height = maxH;
    stCanvasBuf.stCanvas.u32Width = maxW;
    stCanvasBuf.stCanvas.u32Pitch = maxW*2;
    stCanvasBuf.stCanvas.enFmt = HIFB_FMT_ARGB1555;
    memset(pBuf, 0x00, stCanvasBuf.stCanvas.u32Pitch*stCanvasBuf.stCanvas.u32Height);
    gdc.tcClear=0x00;
    gdc.pWinFb->hFB=pstInfo->fd;
    gdc.pWinFb->pMappedAddr=pBuf;
    gdc.pWinFb->pPhyAddr=stCanvasBuf.stCanvas.u32PhyAddr;
    gdc.pSzWin.nW=maxW;
    gdc.pSzWin.nH=maxH;
    windowInit();
    
    CreateMsgQueue(&gdc.nMsgid,20);
    while(1)
    {
        pWINDOW_S pOsd=getOSDWnd();
        MSG msg={WIN_FLASH_ALL,0};
        SendMsg(gdc.nMsgid,msg);
        while(1)
        {
            RecvMsg(gdc.nMsgid,&msg,TRUE);
            switch(msg.message)
            {
                case WIN_FLASH_ALL:
                    windowFlush();
                    stCanvasBuf.UpdateRect.x = 0;
                    stCanvasBuf.UpdateRect.y = 0;
                    stCanvasBuf.UpdateRect.w = maxW;
                    stCanvasBuf.UpdateRect.h = maxH;
                    s32Ret = ioctl(pstInfo->fd, FBIO_REFRESH, &stCanvasBuf);
                    if (s32Ret < 0)
                    {
                        printf("REFRESH failed!\n");
                    }
                    break;
                case WIN_WIN_FLASH:
                case WIN_FLASH_AREA:
                case WIN_CTRL_FLASH:
                    break;
            }
        }
    }
    return HI_NULL;
}
Esempio n. 9
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, int nCmShow)
{
    HANDLE hNotifications = NULL;
    HANDLE hDeviceNotifications[64];
    HANDLE ht;
    int i;
    LPTSTR pszFname = _T("PMMON:WinMain");

    MSGQUEUEOPTIONS msgOptions = {0};

    UNREFERENCED_PARAMETER(hInst);
    UNREFERENCED_PARAMETER(hPrevInst);
    UNREFERENCED_PARAMETER(lpCmdLine);
    UNREFERENCED_PARAMETER(nCmShow);

    // clear globals
    memset(hDeviceNotifications, 0, sizeof(hDeviceNotifications));

    // create a termination event
    ghevTerminate = CreateEvent(NULL, FALSE, FALSE, _T("SOFTWARE/PMTestPrograms/PMMON/Terminate"));
    if(ghevTerminate == NULL) {
        RetailPrint  (_T("%s: CreateEvent() failed %d for termination event\r\n"),
                      pszFname, GetLastError());
        goto _Exit;
    }

    // did the event already exist?
    if(GetLastError() == ERROR_ALREADY_EXISTS) {
        // yes, kill the existing process
        RetailPrint  (_T("%s: Signaling termination event\r\n"), pszFname);
        SetEvent(ghevTerminate);
        goto _Exit;
    }

    // create a message queue for Power Manager notifications
    msgOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
    msgOptions.dwFlags = 0;
    msgOptions.dwMaxMessages = QUEUE_ENTRIES;
    msgOptions.cbMaxMessage = sizeof(POWER_BROADCAST) + MAX_NAMELEN;
    msgOptions.bReadAccess = TRUE;

    ghPowerNotifications= CreateMsgQueue(NULL, &msgOptions);
    if (!ghPowerNotifications) {
        DWORD dwErr = GetLastError();
        RetailPrint  (TEXT("%s:CreateMessageQueue ERROR:%d\n"), pszFname, dwErr);
        goto _Exit;
    }

    // request Power notifications
    hNotifications = RequestPowerNotifications(ghPowerNotifications, POWER_NOTIFY_ALL); // Flags
    if (!hNotifications) {
        DWORD dwErr = GetLastError();
        RetailPrint  (TEXT("%s:RequestPowerNotifications ERROR:%d\n"), pszFname, dwErr);
        goto _Exit;
    }

    // create message queues
    memset(&msgOptions, 0, sizeof(msgOptions));
    msgOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
    msgOptions.dwFlags = 0;
    msgOptions.cbMaxMessage = PNP_QUEUE_SIZE;
    msgOptions.bReadAccess = TRUE;
    ghDeviceNotifications = CreateMsgQueue(NULL, &msgOptions);
    if(ghDeviceNotifications == NULL) {
        DWORD dwStatus = GetLastError();
        RetailPrint  (_T("%s:CreateMsgQueue() failed %d\r\n"), pszFname, dwStatus);
        goto _Exit;
    }

    // create the monitoring thread
    ht = CreateThread(NULL, 0, MonThreadProc, NULL, 0, NULL);
    if(ht) {
        // request device notifications (do this after the thread is
        // created so we don't drop any notifications)
        RequestPMDeviceNotifications(64, hDeviceNotifications);

        // wait for the thread to exit
        WaitForSingleObject(ht, INFINITE);
        CloseHandle(ht);
    }

_Exit:
    if(hNotifications) StopPowerNotifications(hNotifications);
    if(ghPowerNotifications) CloseMsgQueue(ghPowerNotifications);
    for(i = 0; i < 64 && hDeviceNotifications[i] != NULL; i++) {
        StopDeviceNotifications(hDeviceNotifications[i]);
    }
    if(ghDeviceNotifications) CloseMsgQueue(ghDeviceNotifications);
    if(ghevTerminate) CloseHandle(ghevTerminate);
    RetailPrint  (_T("%s: exiting\r\n"), pszFname);

    return 0;
}
Esempio n. 10
0
////////////////////////////////////////////////////////////////////////
// Function:	CImager
// Description:	CImager constructor - Variable initialization done Here, 
//              Loads Image capture Library, Initializes Image Captue API function pointers.
// Author:	    Ramanagouda S Patil(RSP)
// Date:	    JULY 2009
////////////////////////////////////////////////////////////////////////
CImager::CImager(HINSTANCE hInstance,HWND hParent,int iInstanceID, PBModule* pModule)
	:m_iInstanceID(iInstanceID)
{
#ifdef LOG_TO_FILE
	LogFile = 	fopen("CameraLog2.txt","w");
#endif
	DEBUGIT(LogFile,"Imager constructor entered \n");
	m_pModule = pModule;
	m_PreviewOn = FALSE;
	m_bImagerLoadFailed = true;
	m_bDisableDuringNavigate = true;  //  Default behaviour is to disable during navigate
	hModule = LoadLibraryEx(_T("ImgAPI32.dll"), NULL, 0);
	if (hModule != NULL) {
		m_bImagerLoadFailed = false;
		if (NULL == (Image_FindFirst = (IMAGE_FINDFIRSTPROC) GetProcAddress(hModule, _T("IMAGE_FindFirst")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_FindNext = (IMAGE_FINDNEXTPROC) GetProcAddress(hModule, _T("IMAGE_FindNext")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_FindClose = (IMAGE_FINDCLOSEPROC) GetProcAddress(hModule, _T("IMAGE_FindClose")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_Open = (IMAGE_OPENPROC) GetProcAddress(hModule, _T("IMAGE_Open")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_Close = (IMAGE_CLOSEPROC) GetProcAddress(hModule, _T("IMAGE_Close")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_StartAcquisition = (IMAGE_STARTACQUISITIONPROC) GetProcAddress(hModule, _T("IMAGE_StartAcquisition")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_StopAcquisition = (IMAGE_STOPACQUISITIONPROC) GetProcAddress(hModule, _T("IMAGE_StopAcquisition")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_StartViewfinder = (IMAGE_STARTVIEWFINDERPROC) GetProcAddress(hModule, _T("IMAGE_StartViewfinder")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_StopViewfinder = (IMAGE_STOPVIEWFINDERPROC) GetProcAddress(hModule, _T("IMAGE_StopViewfinder")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_GetImage = (IMAGE_GETIMAGEPROC) GetProcAddress(hModule, _T("IMAGE_GetImage")))) m_bImagerLoadFailed = true; 		
		if (NULL == (Image_SetCapCurrValue = (IMAGE_SETCAPCURRVALUEPROC) GetProcAddress(hModule, _T("IMAGE_SetCapCurrValue")))) m_bImagerLoadFailed = true;
		if (NULL == (Image_UnLockImager = (IMAGE_UNLOCKIMAGERPROC) GetProcAddress(hModule, _T("IMAGE_UnLockImager")))) m_bImagerLoadFailed = true;
	}
	m_bTransfer = FALSE;
	m_lpSzFilename = NULL;
	m_hImager = INVALID_HANDLE_VALUE;
	m_rcWinPos.left = GetSystemMetrics(SM_CXSCREEN)/2-50;
	m_rcWinPos.right = GetSystemMetrics(SM_CXSCREEN)/2+50;
	m_rcWinPos.top = GetSystemMetrics(SM_CYSCREEN)/2-50;
	m_rcWinPos.bottom = GetSystemMetrics(SM_CYSCREEN)/2+50;

	m_ImgNo = 1;
	//m_bHttpTransfer = TRUE;
	//memset(m_tcImagerPassword, 0, sizeof(TCHAR) * MAX_PATH); 
	//memset(m_tcImagerUsername, 0, sizeof(TCHAR) * MAX_PATH); 
	m_hInst=hInstance;
	m_hParentWnd=hParent;

	m_bImgLight = FALSE;//default state
	m_bImgAim = FALSE; //default state

	//Initialize Msg Queues
	m_MetamsgqOpt.dwSize		= sizeof(m_MetamsgqOpt);
	m_MetamsgqOpt.dwFlags		= MSGQUEUE_ALLOW_BROKEN;
	m_MetamsgqOpt.dwMaxMessages = 0;
	m_MetamsgqOpt.cbMaxMessage	= sizeof(MetaTagQEntry);
	m_MetamsgqOpt.bReadAccess	= TRUE;
	m_hMetaMsgQRead				= NULL;
	m_hMetaMsgQRead				= CreateMsgQueue(L"ImagerMetaMsgQ", &m_MetamsgqOpt);
	m_MetamsgqOpt.bReadAccess	= FALSE;
	m_hMetaMsgQWrite			= NULL;
	m_hMetaMsgQWrite			= CreateMsgQueue(L"ImagerMetaMsgQ", &m_MetamsgqOpt);
	m_iDesiredWidth				= -1;
	m_iDesiredHeight			= -1;
	
	//Initialize dev name to default dev
	wcscpy(m_szDevName,L"IMG1:");

	//Initialize it to ZERO to indicate no navigate string
	memset(m_EnumIMGNav,0,sizeof(m_EnumIMGNav));

	//Create DirectShow camera object
#ifdef STATIC_DSCAM
	m_pDSCam = &g_DSCam;
#else
	m_pDSCam = new CDShowCam(m_pModule);
#endif
	
	//Create list of available imager devices on terminal
	CreateListOfAvailableDevices();

#ifndef STATIC_DSCAM
		DEBUGIT(LogFile,"CImager::CImager deleting m_pDSCam \n");
		

	if (m_pDSCam) delete m_pDSCam;
	m_pDSCam = NULL;
	

#endif
	

	//Check that default dev exists otherwise select the first exisiting device
	ListDevName *pDevName = g_ListDevName;
	while (pDevName)
	{
		if (wcscmp(pDevName->DeviceName, m_szDevName) == 0)
			break;
		pDevName = pDevName->pNext;
	}
	if ((!pDevName) && (g_ListDevName))
	{
		wcsncpy(m_szDevName,g_ListDevName->DeviceName, 50);
	}
	m_szImagerCaptureURI = NULL;

	LPCTSTR pSettingValue = m_pModule->GetAppSettingPtr(m_iInstanceID, L"Imager\\DisableImagerDuringNavigation", L"Value");
	if (pSettingValue && pSettingValue[0] == L'0')
		m_bDisableDuringNavigate = false;
	else
		m_bDisableDuringNavigate = true;

	DEBUGIT(LogFile,"Imager created \n");
	
}
Esempio n. 11
0
MsgQueue_t*
mt_new_kbd_queue(void){
    return CreateMsgQueue("Input", KBDBUFSIZE, 1, true, false);
}
Esempio n. 12
0
void PowerMonitorThread()
{

	MSGQUEUEOPTIONS PowerMsgQOptions = {0,};
	HANDLE hPowerMsgQ = NULL;
	HANDLE hPowerNotifications = NULL;
	HANDLE rgHandles[2] = {0};

	PowerMsgQOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
	PowerMsgQOptions.dwFlags = MSGQUEUE_NOPRECOMMIT ;
	PowerMsgQOptions.dwMaxMessages = 0;
	PowerMsgQOptions.cbMaxMessage = sizeof(POWER_BROADCAST) + sizeof(POWER_BROADCAST_POWER_INFO);
	PowerMsgQOptions.bReadAccess = TRUE;
	
	hPowerMsgQ = CreateMsgQueue(NULL, &PowerMsgQOptions);
	
	if( hPowerMsgQ == NULL )
	{
		RETAILMSG(1,(L"[WSM] CreateMsgQueue Failed(%d) \r\n", GetLastError() ));
		goto Exit;
	}

	// Request power notifications 
	hPowerNotifications = RequestPowerNotifications(hPowerMsgQ, PBT_TRANSITION | PBT_RESUME | PBT_POWERINFOCHANGE);

	if( hPowerNotifications == NULL )
	{
		RETAILMSG(1,(L"[WSM] RequestPowerNotifications Failed(%d) \r\n", GetLastError() ));
		goto Exit;
	}


	rgHandles[0] = hPowerMsgQ;
	rgHandles[1] = g_hEventClosePwrMonThread;

	// 1번째 핸들이 아닌경우에는 이 스레드는 Close 된다. (g_hEventClosePwrMonThread 이벤트 인경우 Close)
	while( WaitForMultipleObjects(2, rgHandles, FALSE, INFINITE) == WAIT_OBJECT_0 )
	{
		DWORD cbRead;
		DWORD dwFlags;
		POWER_BROADCAST *ppb = (POWER_BROADCAST*) new BYTE[sizeof(POWER_BROADCAST) + sizeof(POWER_BROADCAST_POWER_INFO)];


		// loop through in case there is more than 1 msg.
		while(ReadMsgQueue(hPowerMsgQ, ppb, sizeof(POWER_BROADCAST) + sizeof(POWER_BROADCAST_POWER_INFO), &cbRead, 0, &dwFlags))
		{

			if( ppb->Message == PBT_TRANSITION )
			{
				if( ppb->Length && wcscmp(ppb->SystemPowerState, L"unattended") == 0 )
				{
					if ( g_bCheckedUnattendedMode == TRUE )
					{
						// Create RepeatSysIdleTimerResetThread
						g_bRunningRepeatSysIdleTimerResetThread = TRUE;
						g_hRepeatSysIdleTimerResetThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RepeatSysIdleTimerResetThread, NULL, 0, NULL);

						if( g_hRepeatSysIdleTimerResetThread == INVALID_HANDLE_VALUE )
						{
							RETAILMSG(1, (TEXT("[ERR] Can't create g_hRepeatSysIdleTimerResetThread \r\n") ));
							g_hRepeatSysIdleTimerResetThread = NULL;
						}

					}
				}
				else
				{
					// Close RepeatSysIdleTimerResetThread

					g_bRunningRepeatSysIdleTimerResetThread = FALSE;

					if( g_hRepeatSysIdleTimerResetThread )
					{
						if( WaitForSingleObject(g_hRepeatSysIdleTimerResetThread, 1000) == WAIT_TIMEOUT )
						{
							DWORD dwCode = 0;

							GetExitCodeThread(g_hRepeatSysIdleTimerResetThread, &dwCode);

							if( dwCode == STILL_ACTIVE )
							{
								RETAILMSG(1, (TEXT("[WSM] g_hRepeatSysIdleTimerResetThread Terminate \r\n") ));
								TerminateThread(g_hRepeatSysIdleTimerResetThread, 0);
							}
						}
						CloseHandle(g_hRepeatSysIdleTimerResetThread);
						g_hRepeatSysIdleTimerResetThread = NULL;
					}

				}
			}

		}
		delete[] ppb;
	}


	RETAILMSG(1,(L"[WSM] PowerMonitorThread End \r\n"));

Exit:
    if (hPowerNotifications)
	{
        StopPowerNotifications(hPowerNotifications);
		hPowerNotifications = NULL;
	}

    if (hPowerMsgQ)
	{
        CloseMsgQueue(hPowerMsgQ);
		hPowerMsgQ = NULL;
	}

    return;

}
Esempio n. 13
0
//***************************************************************************
// Function Name: PowerNotificationThread
//
// Purpose: listens for power change notifications
//
DWORD PowerNotificationThread(LPVOID pVoid)
{
    // size of a POWER_BROADCAST message
    DWORD cbPowerMsgSize = sizeof POWER_BROADCAST + (MAX_PATH * sizeof TCHAR);

    // Initialize our MSGQUEUEOPTIONS structure
    MSGQUEUEOPTIONS mqo;
    mqo.dwSize = sizeof(MSGQUEUEOPTIONS); 
    mqo.dwFlags = MSGQUEUE_NOPRECOMMIT;
    mqo.dwMaxMessages = 4;
    mqo.cbMaxMessage = cbPowerMsgSize;
    mqo.bReadAccess = TRUE;              
                                         
    // Create a message queue to receive power notifications
    HANDLE hPowerMsgQ = CreateMsgQueue(NULL, &mqo);
    if (NULL == hPowerMsgQ) 
    {
        RETAILMSG(1, (L"CreateMsgQueue failed: %x\n", GetLastError()));
        goto Error;
    }

    // Request power notifications 
    HANDLE hPowerNotifications = RequestPowerNotifications(hPowerMsgQ,
                                                           PBT_TRANSITION | 
                                                           PBT_RESUME | 
                                                           PBT_POWERINFOCHANGE);
    if (NULL == hPowerNotifications) 
    {
        RETAILMSG(1, (L"RequestPowerNotifications failed: %x\n", GetLastError()));
        goto Error;
    }

    HANDLE rgHandles[2] = {0};
    rgHandles[0] = hPowerMsgQ;
    rgHandles[1] = g_hEventShutDown;

    // Wait for a power notification or for the app to exit
    while(WaitForMultipleObjects(2, rgHandles, FALSE, INFINITE) == WAIT_OBJECT_0)
    {
        DWORD cbRead;
        DWORD dwFlags;
        POWER_BROADCAST *ppb = (POWER_BROADCAST*) new BYTE[cbPowerMsgSize];
            
        // loop through in case there is more than 1 msg 
        while(ReadMsgQueue(hPowerMsgQ, ppb, cbPowerMsgSize, &cbRead, 
                           0, &dwFlags))
        {
            switch (ppb->Message)
            {
                case PBT_TRANSITION:
                    RETAILMSG(1,(L"Power Notification Message: PBT_TRANSITION\n"));
                    RETAILMSG(1,(L"Flags: %lx", ppb->Flags));
                    RETAILMSG(1,(L"Length: %d", ppb->Length));
                    if (ppb->Length)
                    {
                        RETAILMSG(1,(L"SystemPowerState: %s\n", ppb->SystemPowerState));
                    }
                    break;

                case PBT_RESUME:
                    RETAILMSG(1,(L"Power Notification Message: PBT_RESUME\n"));
                    break;

                case PBT_POWERINFOCHANGE:
                {
                    RETAILMSG(1,(L"Power Notification Message: PBT_POWERINFOCHANGE\n"));

                    // PBT_POWERINFOCHANGE message embeds a 
                    // POWER_BROADCAST_POWER_INFO structure into the 
                    // SystemPowerState field
                    PPOWER_BROADCAST_POWER_INFO ppbpi =
                        (PPOWER_BROADCAST_POWER_INFO) ppb->SystemPowerState;
                    if (ppbpi) 
                    {
                        RETAILMSG(1,(L"Length: %d", ppb->Length));
                        RETAILMSG(1,(L"BatteryLifeTime = %d\n",ppbpi->dwBatteryLifeTime));
                        RETAILMSG(1,(L"BatterFullLifeTime = %d\n",
                                     ppbpi->dwBatteryFullLifeTime));
                        RETAILMSG(1,(L"BackupBatteryLifeTime = %d\n",
                                     ppbpi->dwBackupBatteryLifeTime));
                        RETAILMSG(1,(L"BackupBatteryFullLifeTime = %d\n",
                                     ppbpi->dwBackupBatteryFullLifeTime));
                        RETAILMSG(1,(L"ACLineStatus = %d\n",ppbpi->bACLineStatus));
                        RETAILMSG(1,(L"BatteryFlag = %d\n",ppbpi->bBatteryFlag));
                        RETAILMSG(1,(L"BatteryLifePercent = %d\n",
                                     ppbpi->bBatteryLifePercent));
                        RETAILMSG(1,(L"BackupBatteryFlag = %d\n",
                                     ppbpi->bBackupBatteryFlag));
                        RETAILMSG(1,(L"BackupBatteryLifePercent = %d\n",
                                     ppbpi->bBackupBatteryLifePercent));
                    }
                    break;
                }

                default:
                    break;
            }

            UpdatePowerState();
        }

        delete[] ppb;
    }

Error:
    if (hPowerNotifications)
        StopPowerNotifications(hPowerNotifications);

    if (hPowerMsgQ)
        CloseMsgQueue(hPowerMsgQ);

    return NULL;
}