📄 intelmobileplatformclassprovider.cpp
字号:
/*
Copyright (c) 2008, Intel Corporation.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*///==============================================================================// IntelMobilePlatformClassProvider.cpp//// Defines the class for the default processor provider. This module// contains the methods for the public interfaces of the inherited classes.//// //==============================================================================//#include "stdafx.h"#include "IntelMobilePlatformClassProvider.h"//#include "inc/base/InstanceProvider.h"PlatformClassProvider LocalClassProvider;//==============================================================================PROVIDER_API IClassProvider* CreateClassProvider(/* HWND& hWnd*/ ){// LocalClassProvider.SetWindowHandle( hWnd ); return &LocalClassProvider;}//==============================================================================PlatformClassProvider::~PlatformClassProvider(){ Unload(); DeleteCriticalSection( &m_DefaultProviderCS );}bool PlatformClassProvider::Load(){ bool bRet = true; //register self to receive the windows messages for WM_WTSSESSEION_CHANGE /*BOOL bVal = WTSRegisterSessionNotification(m_hWnd, NOTIFY_FOR_ALL_SESSIONS); if ( FALSE == bVal ) { //CAN NOT REGISTER SESSION NOTIFICATION THROWIMEXCEPTION (80043200); }*/ bRet = Scan(); return bRet;}bool PlatformClassProvider::Unload(){ //unregister the WM_WTSSESSION_CHANGE /*BOOL bVal = WTSUnRegisterSessionNotification(m_hWnd); if (FALSE == bVal) { //CAN NOT UNREGISTER SESSION NOTIFICATION //THROWIMEXCEPTION (80043202); }*/ return true;}/*bool PlatformClassProvider::GetPlatformInternalKey(IntelMobileString& internalKey){ //define the OS version variable; OSVERSIONINFOEX osVersionInfo; ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFOEX)); osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); //get the OS version information BOOL bVal = GetVersionEx((OSVERSIONINFO *)&osVersionInfo); if (!bVal) { osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx((OSVERSIONINFO *)&osVersionInfo)) { //ERROR return false; } } switch (osVersionInfo.dwPlatformId) { //Test each version to retrieve internalKey case VER_PLATFORM_WIN32_NT: if (osVersionInfo.dwMajorVersion == 5 && osVersionInfo.dwMinorVersion == 2) internalKey = L"Microsoft Windows Server 2003 Family "; if (osVersionInfo.dwMajorVersion == 5 && osVersionInfo.dwMinorVersion == 1) internalKey = L"Microsoft Windows XP "; if (osVersionInfo.dwMajorVersion == 5 && osVersionInfo.dwMinorVersion == 0) internalKey = L"Microsoft Windows 2000 "; if (osVersionInfo.dwMajorVersion <= 4) internalKey = L"Microsoft Windows NT "; // Test for specific product on Windows NT 4.0 SP6 and later. if( bVal ) { // Test for the workstation type. if ( osVersionInfo.wProductType == VER_NT_WORKSTATION ) { if( osVersionInfo.dwMajorVersion == 4 ) internalKey += L"Workstation 4.0 "; else if( osVersionInfo.wSuiteMask & VER_SUITE_PERSONAL ) internalKey += L"Home Edition "; else internalKey += L"Professional "; } // Test for the server type. else if ( osVersionInfo.wProductType == VER_NT_SERVER ) { if( osVersionInfo.dwMajorVersion == 5 && osVersionInfo.dwMinorVersion == 2 ) { if( osVersionInfo.wSuiteMask & VER_SUITE_DATACENTER ) internalKey += L"Datacenter Edition "; else if ( osVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE ) internalKey += L"Enterprise Edition "; else if ( osVersionInfo.wSuiteMask == VER_SUITE_BLADE ) internalKey += L"Web Edition "; else internalKey += L"Standard Edition "; } else if( osVersionInfo.dwMajorVersion == 5 && osVersionInfo.dwMinorVersion == 0 ) { if( osVersionInfo.wSuiteMask & VER_SUITE_DATACENTER ) internalKey += L"Datacenter Server "; else if ( osVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE ) internalKey += L"Advanced Server "; else internalKey += L"Server "; } // Windows NT 4.0 else { if( osVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE ) internalKey += L"Server 4.0, Enterprise Edition " ; else internalKey += L"Server 4.0 "; } } } // Test for specific product on Windows NT 4.0 SP5 and earlier else { HKEY hKey; char szProductType[80]; DWORD dwBufLen=80; LONG lRet; lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, (LPCTSTR)"SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey ); if( lRet == ERROR_SUCCESS ) { lRet = RegQueryValueEx( hKey, (LPCTSTR)"ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen); if (!( (lRet != ERROR_SUCCESS) || (dwBufLen > 80) )) { RegCloseKey( hKey ); if ( lstrcmpi( (LPCTSTR)"WINNT", (LPCTSTR)szProductType) == 0 ) internalKey += L"Workstation " ; if ( lstrcmpi( (LPCTSTR) "LANMANNT", (LPCTSTR)szProductType) == 0 ) internalKey += L"Server "; if ( lstrcmpi( (LPCTSTR)"SERVERNT", (LPCTSTR)szProductType) == 0 ) internalKey += L"Advanced Server " ; TCHAR tempTStr[80]; wsprintf(tempTStr, L"%d.%d ", osVersionInfo.dwMajorVersion, osVersionInfo.dwMinorVersion); internalKey += tempTStr; } } } // Display service pack (if any) and build number. if( osVersionInfo.dwMajorVersion == 4 && lstrcmpi( osVersionInfo.szCSDVersion, (LPCTSTR)"Service Pack 6" ) == 0 ) { HKEY hKey; LONG lRet; // Test for SP6 versus SP6a. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, (LPCTSTR)"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009", 0, KEY_QUERY_VALUE, &hKey ); if( lRet == ERROR_SUCCESS ) { TCHAR tempTStr[80]; wsprintf(tempTStr, L"Service Pack 6a (Build %d) ", osVersionInfo.dwBuildNumber & 0xFFFF); internalKey += tempTStr; } else // Windows NT 4.0 prior to SP6a { TCHAR tempTStr[80]; wsprintf(tempTStr, L"%s (Build %d) ", osVersionInfo.szCSDVersion, osVersionInfo.dwBuildNumber & 0xFFFF); internalKey += tempTStr; } RegCloseKey( hKey ); } else // Windows NT 3.51 and earlier or Windows 2000 and later { TCHAR tempTStr[80]; wsprintf(tempTStr, L"%s (Build %d) ", osVersionInfo.szCSDVersion, osVersionInfo.dwBuildNumber & 0xFFFF); internalKey += tempTStr; } break; case VER_PLATFORM_WIN32_WINDOWS: if (osVersionInfo.dwMajorVersion == 4 && osVersionInfo.dwMinorVersion == 0) { internalKey = L"Microsoft Windows 95 "; if ( osVersionInfo.szCSDVersion[1] == 'C' || osVersionInfo.szCSDVersion[1] == 'B' ) internalKey += L"OSR2 " ; } if (osVersionInfo.dwMajorVersion == 4 && osVersionInfo.dwMinorVersion == 10) { internalKey = L"Microsoft Windows 98 "; if ( osVersionInfo.szCSDVersion[1] == 'A' ) internalKey += L"SE " ; } if (osVersionInfo.dwMajorVersion == 4 && osVersionInfo.dwMinorVersion == 90) { internalKey = L"Microsoft Windows Millennium Edition"; } break; case VER_PLATFORM_WIN32s: internalKey = L"Microsoft Win32s"; break; default: //OTHERS internalKey = L"Unknown"; } for ( unsigned int x=0; x<internalKey.length() ; x++ )#ifdef _UNICODE internalKey[x] = towlower( internalKey[x] );#else internalKey[x] = tolower( internalKey[x] );#endif return true;}*/bool PlatformClassProvider::Scan(){// _Log( L"Initializing Platform" ); try { Lock(); IntelMobileString internalKey = IntelMobileText("Platform"), externalKey = IntelMobileText("Platform"); /*if (false == GetPlatformInternalKey(internalKey)) return false;*/ // CreateInstance(externalKey, internalKey); CreateInstance(externalKey, internalKey,internalKey); Unlock(); } catch ( ServerException se) { Unlock(); if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("800432C0")); nse.SetParent( &se ); throw nse; } throw se; } catch ( ... ) { Unlock(); THROWIMEXCEPTION( "800432C0" ); }// _Log( IntelMobileText("Platform init complete." ); return true;}/*bool PlatformClassProvider::WindowNotification(HWND m_hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam){ bool bRet = true; //get the instance object IntelMobileString internalKey = IntelMobileText("platform";*/ /*if (false == GetPlatformInternalKey(internalKey)) { bRet = false; return bRet; }*//* ServerPlatformInstanceObject *pObject = NULL; //trigger the event switch (iMsg) { case WM_QUERYENDSESSION: pObject = dynamic_cast<ServerPlatformInstanceObject *> (GetInstance(internalKey)); if (NULL == pObject) return false; if (lParam & ENDSESSION_LOGOFF) ;//pObject->FireEvent(ServerEvent(ServerEvent::eLogoffRequested, pObject)); else pObject->FireEvent(ServerEvent(ServerEvent::eShutDownRequested, pObject)); bRet = true; break; case WM_ENDSESSION: pObject = dynamic_cast<ServerPlatformInstanceObject *> (GetInstance(internalKey)); if (NULL == pObject) return false; if (lParam & ENDSESSION_LOGOFF) ;//pObject->FireEvent(ServerEvent(ServerEvent::eLoggingOff, pObject)); else pObject->FireEvent(ServerEvent(ServerEvent::eShuttingDown, pObject)); bRet = true; break; case WM_POWERBROADCAST: pObject = dynamic_cast<ServerPlatformInstanceObject *> (GetInstance(internalKey)); if (NULL == pObject) return false; switch (wParam) { case PBT_APMQUERYSUSPEND: pObject->FireEvent(ServerEvent(ServerEvent::eSuspendRequested, pObject)); break; case PBT_APMQUERYSUSPENDFAILED: //pObject->FireEvent(ServerEvent(ServerEvent::eSuspendDenied, pObject)); break; case PBT_APMSUSPEND: pObject->FireEvent(ServerEvent(ServerEvent::eSuspending, pObject)); break; case PBT_APMRESUMEAUTOMATIC: break; case PBT_APMRESUMECRITICAL: pObject->FireEvent(ServerEvent(ServerEvent::eCriticalResume, pObject)); break; case PBT_APMRESUMESUSPEND: pObject->FireEvent(ServerEvent(ServerEvent::eNormalResume, pObject)); break; } bRet = true; break;*/ /*case WM_WTSSESSION_CHANGE: pObject = dynamic_cast<ServerPlatformInstanceObject *> (GetInstance(internalKey)) ; if (NULL == pObject) return false; switch (wParam) { case WTS_CONSOLE_CONNECT: break; case WTS_CONSOLE_DISCONNECT: break; case WTS_SESSION_LOCK: break; case WTS_SESSION_UNLOCK: break; case WTS_SESSION_LOGOFF: break; case WTS_SESSION_LOGON: pObject->FireEvent(ServerEvent(ServerEvent::eLoggingIn, pObject)); break; default: break; } bRet = true; break;*//* } return bRet;}*///==============================================================================ServerInstanceObject* PlatformClassProvider::CreateInstance( const IntelMobileString& externalKey, const IntelMobileString& internalKey, /*in*/ const IntelMobileString& sType ){ ServerInstanceObject* pObject = GetClassObject().GetInstance( internalKey ); try { if ( pObject == NULL ) { // IInstanceProvider* pProvider = GetLayer()->GetLayerInstanceProvider(sType, externalKey ); IInstanceProvider* pProvider = GetLayer()->GetLayerInstanceProvider(IntelMobileText("Platform"), externalKey ); if ( pProvider != NULL ) { pObject = pProvider->CreateInstance( internalKey ); if ( pObject != NULL ) { // ServerInstanceCollection* pCollection = GetClassObject().GetInstances(); ServerClassObject &p=GetClassObject(); ServerInstanceCollection* pCollection = p.GetInstances(); if(pCollection!=NULL) pCollection->Add( pObject ); } } } return pObject; } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("800432C1")); nse.SetParent( &se ); throw nse; } throw se; } catch(...) { THROWIMEXCEPTION("800432C1"); } return pObject;}ServerInstanceObject * PlatformClassProvider::GetInstance(const IntelMobileString& internalKey){ ServerInstanceObject *pObject = NULL; pObject = GetClassObject().GetInstance(internalKey); if (pObject == NULL) { Scan(); pObject = GetClassObject().GetInstance(internalKey); } return pObject;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -