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

📄 led_service.cpp

📁 LED 驱动程序模块源程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
									(BYTE *)&dwLedcount, 									&dwSize) )		{			//get the notification value			RegistryGetDWORD(					SN_NOTIFICATIONACTIVE_ROOT, 					SN_NOTIFICATIONACTIVE_PATH,					SN_NOTIFICATIONACTIVE_VALUE,					&dwNotificationState);  			if (0 == dwLedcount)			{							if (S_OK == RegistryGetString( 									SN_NOTIFICATIONACTIVE_ROOT,  									SN_NOTIFICATIONACTIVE_PATH,									SN_NOTIFICATIONACTIVE_CLSIDVALUE,									szNotificationCLSID,									MAX_SIZE))				{					//find the CLSID whether is ARAMCLSID					if (0 == wcsncmp(szNotificationCLSID, szALARMCLSID, MAX_SIZE))					{						   if( RED_BLINK != g_dwMyState )						   {							    g_uStateToBeRecovered |= 1 << g_dwMyState;						    }						Tran2State(RED_BLINK);						RegCloseKey( hkey );												return FALSE;					}				}			              				if (0 == dwNotificationState)				{					if (S_OK == RegistryGetString( 										SN_NOTIFICATIONACTIVE_ROOT,  										SN_NOTIFICATIONACTIVE_PATH,										SN_NOTIFICATIONACTIVE_CLSIDVALUE,										szNotificationCLSID,										MAX_SIZE))					{						if ( 0 ==  wcsncmp( szNotificationCLSID, szBlueToothCLSID, MAX_SIZE))						{						   if( RED_BLINK != g_dwMyState )						   {							    g_uStateToBeRecovered |= 1 << g_dwMyState;						    }							Tran2State(RED_BLINK);							RegCloseKey( hkey );													return FALSE;						}					}					else					{						Dispatch(NOTIFY_OFF_SIG);						RegCloseKey( hkey );												return FALSE;					}				}				else				{					if (g_bHaveAlarmNotify ==TRUE)					{						   if( RED_BLINK != g_dwMyState )						   {							    g_uStateToBeRecovered |= 1 << g_dwMyState;						    }						Tran2State(RED_BLINK);					}					else					{						Dispatch(NOTIFY_OFF_SIG);					}					RegCloseKey(hkey);					return FALSE;				}			}			else			{								if (0 == dwNotificationState)				{					RegCloseKey(hkey);										return FALSE;				}				else				{					if( RED_BLINK != g_dwMyState )					{						 g_uStateToBeRecovered |= 1 << g_dwMyState;					}					Tran2State(RED_BLINK);					RegCloseKey(hkey);											return FALSE;				}				} 		}		RegCloseKey( hkey );	}	return FALSE;}/******************************************************************************** 	Function 		: ChargingCase			Handle Charging Case	Param		: NULL	Return Value	: NULL*********************************************************************************/void ChargingCase(void){	DWORD dwBattState			= 0;		DWORD dwACOnline			= 0;	//  Get the new power state value.	if ((S_OK != RegistryGetDWORD(						SN_POWERBATTERYSTATE_ROOT,						SN_POWERBATTERYSTATE_PATH,						SN_POWERBATTERYSTATE_VALUE,						&dwBattState))  		|| (S_OK != RegistryGetDWORD(						SN_POWERBATTERYACLINE_ROOT, 						SN_POWERBATTERYACLINE_PATH,						SN_POWERBATTERYACLINE_VALUE,						&dwACOnline)))	     	{		goto Break;	}	dwBattState = dwBattState & BATTERY_FLAG_CHARGE;	dwACOnline =  dwACOnline & AC_LINE_ONLINE;	if ( AC_LINE_ONLINE == dwACOnline )		// online       	{		if (dwBattState)						// Charger connected while charging not  completed		{			Dispatch(CHARGING_SIG);		}		else		{			Dispatch(CHARGE_DONE_SIG);          // Charger connected while charging completed		}	}	else										// Not online 	{		Dispatch(CHARGER_UNPLUGGED_SIG);    // charger unplugged, or get dwACOnline failed	}	Break: ;}/******************************************************************************** 	Function 		: PhoneCase			Handle Phone Case	Param		: NULL	Return Value	: NULL*********************************************************************************/void PhoneCase(void){	DWORD dwNoPhoneService	= 0;	if (S_OK == RegistryGetDWORD(						SN_PHONENOSERVICE_ROOT,						SN_PHONENOSERVICE_PATH,						SN_PHONENOSERVICE_VALUE,						&dwNoPhoneService))		{			if (dwNoPhoneService & SN_PHONENOSERVICE_BITMASK || dwNoPhoneService &SN_PHONENOSIM_BITMASK)   			{				Dispatch(NETREGISTER_OFF_SIG);           //  NETREGISTER OFF                			}			else			{				Dispatch(NETREGISTER_ON_SIG);            //  NETREGISTER ON			}		}}/******************************************************************************** 	Function 		: NotificationCase			Handle Notification Case	Param		: NULL	Return Value	: NULL*********************************************************************************/void NotificationCase(void){    DWORD dwNotificationState	= 0;	    DWORD dwSMSnumber = 0;    DWORD dwOptions = 0;    TCHAR szNotificationCLSID[MAX_SIZE] = { 0 } ;    TCHAR szSMSCLSID[]					 = TEXT("{A877D65B-239C-47A7-9304-0D347F580408}");    TCHAR szMisCallCLSID[]				        = TEXT("{A877D660-239C-47A7-9304-0D347F580408}");    TCHAR szALARMCLSID[]				        = TEXT("{15F11F90-8A5F-454C-89FC-BA9B7AAB0CAD}");    TCHAR szBlueToothCLSID[]			        = TEXT("{F55615D6-D29E-4DB8-8C75-98125D1A7253}");    TCHAR szWifiCLSID[]					 = TEXT("{DDBD3B44-80B0-4B24-9DC4-839FEA6E559E}");    TCHAR szSendSMSCLSID[]				 = TEXT("{7615FF9C-B6D0-4D23-8910-E7D6D40E2A67}");    //get CLSID    if (S_OK == RegistryGetString(         SN_NOTIFICATIONACTIVE_ROOT,          SN_NOTIFICATIONACTIVE_PATH,        SN_NOTIFICATIONACTIVE_CLSIDVALUE,        szNotificationCLSID,        MAX_SIZE))    {			        //Find the SendSMS CLSID        if( 0 ==  wcsncmp( szNotificationCLSID, szSendSMSCLSID, MAX_SIZE))        {            if (S_OK == RegistryGetDWORD(                SN_CONTROLPANELNOTIFICATIONACTIVES_ROOT,                 SN_CONTROLPANELNOTIFICATIONACTIVES_SMSPATH,                SN_CONTROLPANELNOTIFICATIONACTIVES_OPTIONSVALUE,                &dwOptions))            {                if ((dwOptions & SN_CONTROLPANELNOTIFICATIONACTIVES_BITMASK)                 != SN_CONTROLPANELNOTIFICATIONACTIVES_BITMASK)                {                    if(S_OK != RegistryGetDWORD(                        SN_MESSAGINGSMSUNREAD_ROOT,                        SN_MESSAGINGSMSUNREAD_PATH,                        SN_MESSAGINGSMSUNREAD_VALUE,                        &dwSMSnumber))                    {                        if(1 == dwSMSnumber)                        {                            g_uStateToBeRecovered |= 1 << g_dwMyState;                            g_bSendSMSFlag = TRUE;                        }                    }                }            }        }                //Find the SMS CLSID		        if (0 ==  wcsncmp(szNotificationCLSID, szSMSCLSID, MAX_SIZE))        {	            //when have a SMS whether flash on	            if (OtherNotification(SN_CONTROLPANELNOTIFICATIONACTIVES_SMSPATH))            {                goto NOUseStateMachine;            }        }        //Find the MISCALL CLSID		        if (0 ==  wcsncmp(szNotificationCLSID, szMisCallCLSID, MAX_SIZE))        {            //when have a Miss Call whether flash on 	            if (OtherNotification(SN_CONTROLPANELNOTIFICATIONACTIVES_MISSCALLPATH))            {                goto NOUseStateMachine;            }        }        //Find the Alarm CLSID        if (0 ==  wcsncmp( szNotificationCLSID, szALARMCLSID, MAX_SIZE))        {	            g_bHaveAlarmNotify = TRUE;            //when have a Alarm whether flash on            if (AlarmNotification())            {                goto NOUseStateMachine;            }        }        //Find the BlueTooth CLSID        if (0 ==  wcsncmp( szNotificationCLSID, szBlueToothCLSID, MAX_SIZE))        {		            //when have a BlueTooth whether flash on            if (OtherNotification(SN_CONTROLPANELNOTIFICATIONACTIVES_BLUETOOTHPATH))            {                goto NOUseStateMachine;            }							        }        //Find the WIFI CLSID        if (0 ==  wcsncmp(szNotificationCLSID, szWifiCLSID, MAX_SIZE))        {			            //when have a BlueTooth whether flash on            if (OtherNotification(SN_CONTROLPANELNOTIFICATIONACTIVES_WIFIPATH))            {                goto NOUseStateMachine;            }				        }		        //go to state machine        Dispatch(NOTIFY_ON_SIG);	    }    else    {        g_bHaveAlarmNotify = FALSE;        Dispatch(NOTIFY_OFF_SIG);    }        NOUseStateMachine:;}/******************************************************************************** 	Function 		: RegistryNotifyCallbackFunc			Handle message	Param		: hNotify							SW handle	Param		: dwUserData						State to be changed 	Param		: pData							SW handle	Param		: cbData							SW handle	Return Value	: NULL*********************************************************************************/void RegistryNotifyCallbackFunc(HREGNOTIFY hNotify, DWORD dwUserData, const PBYTE pData, const UINT cbData){	RETAILMSG(TRUE, (L"LED_Service.dll RegistryNotifyCallbackFunc...START..g_uStateToBeRecovered = %d\r\n",g_uStateToBeRecovered));	//  Let's identify the Notification we received, 	//  based on the User Data we passed in, while registering for the notification.	switch (dwUserData)	{	case NotificationState:		NotificationCase();		break;	case LedcountState:				LedCountCase();		break;	case ChargingState:		ChargingCase();		break;	case PhoneState:		PhoneCase();		break;	default: 		break;	}	RETAILMSG(TRUE, (L"LED_Service.dll RegistryNotifyCallbackFunc...END...g_uStateToBeRecovered = %d\r\n",g_uStateToBeRecovered));}/******************************************************************************** 	Function 		: CloseAllNotifications			Close all message	Param		: NULL	Return Value	: NULL*********************************************************************************/void  CloseAllNotifications (void){    	int iCounter = 0;	RETAILMSG(TRUE, (L"LED_Service.dll +CloseAllNotifications\r\n"));	for (iCounter = 0; iCounter < MAX_NOTIF; iCounter++)	{		RegistryCloseNotification(g_hRegNotify[iCounter]);	}	RETAILMSG(TRUE, (L"LED_Service.dll -CloseAllNotifications\r\n"));}/******************************************************************************** 	Function 		: LED_Init			Initiate LED state	Param		: dwData				dwData controlled by OS	Return Value	: DWORD				received and explained by OS*********************************************************************************/DWORD LED_Init(DWORD dwData){	HRESULT hResult = NULL;	NOTIFICATIONCONDITION notifCondition;	RETAILMSG(1, (L"LED_Service.dll RegisterNotifications Entered\r\n"));	hResult = RegistryNotifyCallback(				SN_NOTIFICATIONACTIVE_ROOT,				SN_NOTIFICATIONACTIVE_PATH,				SN_NOTIFICATIONACTIVE_CLSIDVALUE,				RegistryNotifyCallbackFunc,				NotificationState,				NULL,				&g_hRegNotify[NotificationState]);	if (FAILED(hResult))	{		goto Error;	}	// Notify us of any change in the value and set the bitmask of the value to check.	notifCondition.ctComparisonType = REG_CT_ANYCHANGE;	notifCondition.dwMask           	= SN_POWERBATTERYSTATE_BITMASK;	notifCondition.TargetValue.dw   	= 0;	// Register battery state notification.	hResult = RegistryNotifyCallback(				SN_POWERBATTERYSTATE_ROOT,				SN_POWERBATTERYSTATE_PATH,				SN_POWERBATTERYSTATE_VALUE,				RegistryNotifyCallbackFunc,          // This notification uses a callback.				ChargingState,       				&notifCondition,				&g_hRegNotify [ChargingState]);	if (FAILED(hResult))	{		goto Error;	}		// Register for PhoneSearchService notifications.	notifCondition.ctComparisonType = REG_CT_ANYCHANGE;	notifCondition.dwMask           	= SN_PHONENOSERVICE_BITMASK;	notifCondition.TargetValue.dw  	 = 0;	hResult = RegistryNotifyCallback(				SN_PHONENOSERVICE_ROOT,				SN_PHONENOSERVICE_PATH,				SN_PHONENOSERVICE_VALUE,				RegistryNotifyCallbackFunc,				PhoneState,				&notifCondition,				&g_hRegNotify[PhoneState]);	if (FAILED(hResult))	{		goto Error;	}	// Register ledcount state notification.	hResult = RegistryNotifyCallback(				SN_CONTROLPANELNOTIFICATIONACTIVES_ROOT, 				SN_CONTROLPANELNOTIFICATIONACTIVES_DEFAULTPATH,				SN_CONTROLPANELNOTIFICATIONACTIVES_LEDCOUNTVALUE,				RegistryNotifyCallbackFunc,          // This notification uses a callback.				LedcountState,       				NULL,				&g_hRegNotify[LedcountState]);	if (FAILED(hResult))	{		goto Error;	}   	// get handle for NLED driver	g_hMessage = OpenEvent( EVENT_ALL_ACCESS,  FALSE,  LED_OURSTATEMACHINE ); 	if (NULL == g_hMessage )	{		RETAILMSG(TRUE, (L"LED_Service.dll Create event LED_OURSTATEMACHINE failed.\r\n"));		goto Error;	}	hVIB = CreateFile(L"VIB1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);	if (INVALID_HANDLE_VALUE == hVIB )	{		RETAILMSG(TRUE, (L"LED_Service.dll  hVIB create fail,GetLastError = 0x%08x\n", GetLastError ()));		}	RETAILMSG(TRUE, (L"LED_Service.dll RegisterNotifications exited\r\n"));       return 1;Error:	return hResult;}/******************************************************************************** 	Function 		: LED_Init			Deinitiate LED state	Param		: dwData				dwData controlled by OS	Return Value	: DWORD				received and explained by OS*********************************************************************************/DWORD LED_Deinit(DWORD dwData){	LPDWORD lpExitCode = NULL;	DWORD   dwErrorInfo = 0;	CloseAllNotifications();	LEDFlick(LED_RED, 0);	LEDFlick(LED_GREEN, 0);	CloseHandle(hVIB);	if (GetExitCodeThread(hThread,lpExitCode))	{		ExitThread(*lpExitCode);	}	else	{		dwErrorInfo = GetLastError();	}	CloseHandle(hThread);	if (g_hMessage != NULL)	{		CloseHandle(g_hMessage);	}	RETAILMSG(TRUE,(TEXT("LED_Service.dll  LED_Deinit Executed")));		return 0;}// We do not care of the following six functions and implement them as empty functionDWORD LED_Close(DWORD dwData){	RETAILMSG(TRUE,(TEXT("LED_Service.dll  LED_Close Executed")));	return 0;}DWORD LED_IOControl(DWORD dwData, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, 					PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut){	RETAILMSG(TRUE,(TEXT("LED_Service.dll  LED_IOControl Executed")));	return 1;}DWORD LED_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode){	RETAILMSG(TRUE,(TEXT("LED_Service.dll  LED_Open Executed")));	return 0;}DWORD LED_Read(DWORD dwData, LPVOID pBuf, DWORD dwLen){	RETAILMSG(TRUE,(TEXT("LED_Service.dll  LED_Read Executed")));	return 0;}DWORD LED_Seek(DWORD dwData, long pos, DWORD type){	RETAILMSG(TRUE,(TEXT("LED_Service.dll  LED_Seek Executed")));	return 0;}DWORD LED_Write(DWORD dwData, LPCVOID pInBuf, DWORD dwInLen){	RETAILMSG(TRUE,(TEXT("LED_Service.dll  LED_Write Executed")));	return 0;}/*----------------------------------------------------------------------End of LED_Service.cpp----------------------------------------------------------------------*/

⌨️ 快捷键说明

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