⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdd_timerapi.c

📁 gif to bmp conversion
💻 C
字号:
#define MODULE_NAME						"jdd"
#define FILE_NAME						"jdd_timerapi.c"
/***************************************************************************
 * $Id: jdd_timerapi.c,v 1.10 2007/09/11 14:38:35 kumardevhtmlbrow Exp $
 * $Revision: 1.10 $
 * $DateTime: $
 * 
 * IMPORTANT NOTICE
 *
 * Please note that any and all title and/or intellectual property rights 
 * in and to this Software or any part of this (including without limitation 
 * any images, photographs, animations, video, audio, music, text and/or 
 * "applets," incorporated into the Software), herein mentioned to as 
 * "Software", the accompanying printed materials, and any copies of the 
 * Software, are owned by Jataayu Software (P) Ltd., Bangalore ("Jataayu") 
 * or Jataayu's suppliers as the case may be. The Software is protected by 
 * copyright, including without limitation by applicable copyright laws, 
 * international treaty provisions, other intellectual property laws and 
 * applicable laws in the country in which the Software is being used. 
 * You shall not modify, adapt or translate the Software, without prior 
 * express written consent from Jataayu. You shall not reverse engineer, 
 * decompile, disassemble or otherwise alter the Software, except and 
 * only to the extent that such activity is expressly permitted by 
 * applicable law notwithstanding this limitation. Unauthorized reproduction 
 * or redistribution of this program or any portion of it may result in severe 
 * civil and criminal penalties and will be prosecuted to the maximum extent 
 * possible under the law. Jataayu reserves all rights not expressly granted. 
 * 
 * THIS SOFTWARE IS PROVIDED TO YOU "AS IS" WITHOUT WARRANTY OF ANY 
 * KIND AND ANY AND ALL REPRESENTATION AND WARRANTIES, EITHER EXPRESS 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY ACCURACY OF INFORMATIONAL CONTENT, AND/OR FITNESS 
 * FOR A PARTICULAR PURPOSE OR USE, TITLE OR INFRINGEMENT ARE EXPRESSLY 
 * DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. YOU ASSUME THE 
 * ENTIRE RISK AS TO THE ACCURACY AND THE USE OF THIS SOFTWARE. JATAAYU 
 * SHALL NOT BE LIABLE FOR ANY CONSEQUENTIAL, INCIDENTAL, INDIRECT, 
 * EXEMPLARY, SPECIAL OR PUNITIVE DAMAGES INCLUDING WITHOUT LIMITATION 
 * ANY LOSS OF DATA, OR; LOSS OF PROFIT, SAVINGS BUSINESS OR GOODWILL 
 * OR OTHER SIMILAR LOSS RESULTING FROM OR OUT OF THE USE OR INABILITY 
 * TO USE THIS SOFTWARE, EVEN IF JATAAYU HAS BEEN ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE, OR FOR ANY CLAIM BY ANY THIRD PARTY.
 *
 ***************************************************************************
 *
 * Revision Details
 * ----------------
 * $Log: jdd_timerapi.c,v $
 * Revision 1.10  2007/09/11 14:38:35  kumardevhtmlbrow
 * Visual Studio 2005 change update
 *
 * Revision 1.9  2007/06/15 10:49:21  sriramdevhtmlbrow
 * Updated copyright information
 *
 *  
 ***************************************************************************/


/***************************************************************************
* System Include Files
**************************************************************************/



/***************************************************************************
* User Include Files
**************************************************************************/
# include <time.h>
# include <ddl.h>

#ifdef JDD_LOG_ENABLED
#define __MODULE_ID__					TIMER_MODULE
#else
#define __MODULE_ID__					0
#endif

# include <jcal.h>

//#include <mmicontrolstructures.h>


/***************************************************************************
* Type Definitions
**************************************************************************/

#define	TimerClass			TEXT ("TimerDDL")

/***************************************************************************
* Macros
**************************************************************************/


/***************************************************************************
* Global Variable declarations and definitions
**************************************************************************/

HWND hDummyWnd ;

/***************************************************************************
* Local Function Prototypes
**************************************************************************/
LRESULT CALLBACK TimerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

typedef struct _win32_timer
{
	JC_TIMER_CALLBACK	timerCallback ;
	JC_UINT32			uiCallbackArg ;
	JC_BOOLEAN			bIsSuspended ;
} JC_WIN32_TIMER ;


/***************************************************************************
* All Local Function Definitions
**************************************************************************/

void CALLBACK timerProc (HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
	JC_WIN32_TIMER *pTimer ;

	PARAM_INTENTIONALLY_NOT_USED (dwTime) ;
	PARAM_INTENTIONALLY_NOT_USED (uMsg) ;
	PARAM_INTENTIONALLY_NOT_USED (hwnd) ;
	pTimer = (JC_WIN32_TIMER *) idEvent ;
	if (NULL != pTimer && E_FALSE == pTimer->bIsSuspended)
	{
		JC_TIMER_CALLBACK timerCallback = pTimer->timerCallback ;
		timerCallback (pTimer->uiCallbackArg, (JC_UINT32) pTimer) ;
	}
	return ;
}

LRESULT CALLBACK TimerWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    return DefWindowProc(hWnd, message, wParam, lParam) ;
}

JC_RETCODE jdd_TimerInitialize (void)
{
	WNDCLASS wc;

	wc.style			= 0 ;
	wc.lpfnWndProc		= (WNDPROC)TimerWndProc;
	wc.cbClsExtra		= 0;
	wc.cbWndExtra		= 0;
	wc.hInstance		= NULL;
	wc.hIcon			= NULL;
	wc.hCursor			= NULL;
	wc.hbrBackground	= (HBRUSH)(COLOR_WINDOW + 1);
	wc.lpszMenuName		= NULL;
	wc.lpszClassName	= TimerClass ;

	RegisterClass (&wc) ;
	
	hDummyWnd = CreateWindow(TimerClass, TEXT("jTimerDDL"), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
	return JC_OK ;
}

// This function creates a timer and sets the expiry time. 
JC_RETCODE jdd_TimerCreate (JC_UINT32 uiTimerValueMilliSec, 
							JC_TIMER_CALLBACK timerCallback, 
							JC_UINT32 uiCallbackArg,
							JC_INT8 *psTimerName,
							JC_UINT32 *puiTimerID)
{
	JC_UINT64 ulTimer = 0 ;
	JC_WIN32_TIMER *pTimer ;

	PARAM_INTENTIONALLY_NOT_USED (psTimerName) ;

	pTimer = (JC_WIN32_TIMER *) jdd_MemAlloc (1, sizeof (JC_WIN32_TIMER)) ;
	if (pTimer == NULL)
	{
		return JC_ERR_MEMORY_ALLOCATION ;
	}

	pTimer->timerCallback = timerCallback ;
	pTimer->uiCallbackArg = uiCallbackArg ;
	pTimer->bIsSuspended = E_FALSE ;
	ulTimer = SetTimer ( hDummyWnd, (JC_UINT32)pTimer, uiTimerValueMilliSec, timerProc) ;
	if (0 == ulTimer)
	{
		return JC_ERR_TIMER_CREATE ;
	}
	
	*puiTimerID = (JC_UINT32)pTimer ;
	
	return JC_OK ;
}

// This function destroys the created timer and frees any resource associated with the timer.

JC_RETCODE jdd_TimerDestroy (JC_UINT32 uiTimerID) 
{

	JC_INT32 bDelTimer = 0 ;

	bDelTimer = KillTimer (hDummyWnd, uiTimerID) ;
	if (0 == bDelTimer)
	{
		return JC_ERR_TIMER_DESTROY ;
	}
	jdd_MemFree ((void *)uiTimerID) ;
	return JC_OK ;
}

// This function resets a created timer to new values. 

JC_RETCODE jdd_TimerReset (JC_UINT32 uiTimerID,
						   JC_UINT32 uiTimerValueMilliSec, 
							JC_TIMER_CALLBACK timerCallback, 
							JC_UINT32 uiCallbackArg)
{
	PARAM_INTENTIONALLY_NOT_USED (uiTimerID) ;
	PARAM_INTENTIONALLY_NOT_USED (uiTimerValueMilliSec) ;
	PARAM_INTENTIONALLY_NOT_USED (timerCallback) ;
	PARAM_INTENTIONALLY_NOT_USED (uiCallbackArg) ;
	return JC_ERR_NOT_IMPLEMENTED ;
}

// This function stops the ticking timer. But the timer is not destroyed. 
// To use the timer after stop is done, the timer has to be reset.
JC_RETCODE jdd_TimerStop (JC_UINT32 uiTimerID) 
{
	PARAM_INTENTIONALLY_NOT_USED (uiTimerID) ;
	return JC_ERR_NOT_IMPLEMENTED ;
}

// This function suspends the created timer. 

JC_RETCODE jdd_TimerSuspend (JC_UINT32 uiTimerID)
{
	JC_WIN32_TIMER *pTimer ;
	
	pTimer = (JC_WIN32_TIMER *) uiTimerID ;
	if (NULL != pTimer)
	{
		pTimer->bIsSuspended = E_TRUE ;
	}
	return JC_OK ;
}

// This function resumes a suspended timer.
JC_RETCODE jdd_TimerResume (JC_UINT32 uiTimerID)
{
	JC_WIN32_TIMER *pTimer ;
	
	pTimer = (JC_WIN32_TIMER *) uiTimerID ;
	if (NULL != pTimer)
	{
		pTimer->bIsSuspended = E_FALSE ;
	}
	return JC_OK ;
}

// This function causes the currently executing thread to sleep for the specified number of milliseconds.
void jdd_TimerSystemSleep (JC_UINT32 value) 
{
	Sleep (value) ;
}

// This function returns the current time of the system.
JC_INT64 jdd_TimerGetCurrentTime (void)
{
	time_t timeval = 0 ;
	return time (&timeval) ;
}


// This function returns the number of milliseconds that have elapsed since the system was started.
JC_UINT32 jdd_TimerSystemGetTickCount (void) 
{
	return GetTickCount () ;
}	


void jdd_TimerGetGMTime ( const JC_INT64 *plTime, 
											ST_TIME *pstTime ) 
{
	struct tm *pTmStruct ;
	pTmStruct = gmtime( ( const time_t *) plTime ) ;
	if ((JC_NULL != pstTime) && (JC_NULL != pTmStruct))
	{
		/* memcpy could have solved, but not used with a fear that ST_TIME structure may get changed in future*/
		pstTime->iSec					= pTmStruct->tm_sec ;
		pstTime->iMin					= pTmStruct->tm_min ;
		pstTime->iHour					= pTmStruct->tm_hour ;
		pstTime->iDayOfMonth			= pTmStruct->tm_mday ;
		pstTime->iMonth					= pTmStruct->tm_mon ;
		pstTime->iYear					= pTmStruct->tm_year ;
		pstTime->iDayOfTheWeek			= pTmStruct->tm_wday ;
		pstTime->iDayInTheYear			= pTmStruct->tm_yday ;
		pstTime->iDayLightSavingTime	= pTmStruct->tm_isdst ;
	}
}

JC_INT64 jdd_TimerGetMKTime( ST_TIME *pstTime )
{
	struct tm tmStruct ;

	/* memcpy could have solved, but not used with a fear that ST_TIME structure may get changed in future*/
	tmStruct.tm_sec		= pstTime->iSec ;
	tmStruct.tm_min		= pstTime->iMin ;
	tmStruct.tm_hour	= pstTime->iHour ;  
	tmStruct.tm_mday	= pstTime->iDayOfMonth ;
	tmStruct.tm_mon		= pstTime->iMonth	;
	tmStruct.tm_year	= pstTime->iYear	;
	tmStruct.tm_wday	= pstTime->iDayOfTheWeek	;
	tmStruct.tm_yday	= pstTime->iDayInTheYear ;
	tmStruct.tm_isdst	= pstTime->iDayLightSavingTime ;
	
	return ( JC_INT64) mktime( &tmStruct) ;

}

void jdd_TimerGetCurrentLocalTime( const JC_INT64 *plTime, 
									  ST_TIME *pstTime ) 
{
	struct tm *pTmStruct ;
	pTmStruct = localtime( ( const time_t *) plTime ) ;
	if ((JC_NULL != pstTime ) && (JC_NULL != pTmStruct))
	{
		/* memcpy could have solved, but not used with a fear that ST_TIME structure may get changed in future*/
		pstTime->iSec					= pTmStruct->tm_sec ;
		pstTime->iMin					= pTmStruct->tm_min ;
		pstTime->iHour					= pTmStruct->tm_hour ;
		pstTime->iDayOfMonth			= pTmStruct->tm_mday ;
		pstTime->iMonth					= pTmStruct->tm_mon ;
		pstTime->iYear					= pTmStruct->tm_year ;
		pstTime->iDayOfTheWeek			= pTmStruct->tm_wday ;
		pstTime->iDayInTheYear			= pTmStruct->tm_yday ;
		pstTime->iDayLightSavingTime	= pTmStruct->tm_isdst ;
	}
}

JC_INT64  jdd_TimerGetGMTLocalTimeDiff(void)
{
	return _timezone ;
}

/* END OF FILE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -