📄 intelmobilecontextclassprovider.cpp
字号:
if(pMyBandwidthInstance) { pMyBandwidthInstance->FireEvent(ServerEvent( ServerEvent::eBandwidthChanged, pMyBandwidthInstance )); } } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043203")); nse.SetParent( &se ); throw nse; } throw se; } } for (theIterator = g_RateVector.begin(); theIterator != g_RateVector.end();theIterator++) { // ProcotolRateInfo* temp = (ProcotolRateInfo *)theIterator; (*theIterator).IsReplaced = false; } Sleep(3000); } return CCONTEXT_SUCCESS;}unsigned int RouteMonitorThread(void *pParam){ routemonitor(); return CCONTEXT_SUCCESS;}int ContextClassProvider::EventRegister(unsigned int EventId){ _Log(IntelMobileText("ContextClassProvider::EventRegister(%d)"), EventId); try { int iRet; iRet = CCONTEXT_FAIL; DWORD dwThreadId = 0; switch ( EventId ) { case EVENT_IPADDR_CHANGE: /* if ( !g_hIPAddressChangeThread ) { g_hIPAddressChangeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE ) IPAddressChangeCB, NULL, 0, &dwThreadId); // g_hIPAddressChangeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE ) IPAddressChangeCB, NULL, 0, NULL); if ( !g_hIPAddressChangeThread ) { iRet = CCONTEXT_FAIL; goto GracefulExit; } } else goto GracefulExit; break;*/ case EVENT_ROUTE_CHANGE: if ( !g_hRouteChangeThread ) { g_hRouteChangeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE )RouteMonitorThread, NULL, 0, &dwThreadId); // g_hRouteChangeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE )RouteTableChangeCB, NULL, 0, NULL); if ( !g_hRouteChangeThread ) { iRet = CCONTEXT_FAIL; goto GracefulExit; } } /* else goto GracefulExit; */ break; case EVENT_CONNECT: /* if ( !g_hConnectThread ) { g_hConnectThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE ) ConnectCB, NULL, 0, &dwThreadId); if ( !g_hConnectThread ) { iRet = CCONTEXT_FAIL; goto GracefulExit; } } else goto GracefulExit; */ break; case EVENT_DISCONNECT: /* if ( !g_hDisconnectThread ) { g_hDisconnectThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE ) DisconnectCB, NULL, 0, &dwThreadId); if ( !g_hDisconnectThread ) { iRet = CCONTEXT_FAIL; goto GracefulExit; } } else goto GracefulExit; */ break; case EVENT_BANDWIDTHCHANGED: if ( !g_hBandwidthChangedThread ) { g_hBandwidthChangedThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE ) BandwidthChangeView, NULL, 0, &dwThreadId); if ( !g_hBandwidthChangedThread) { iRet = CCONTEXT_FAIL; goto GracefulExit; } } /* else goto GracefulExit; */ break; default: iRet = CCONTEXT_FAIL; goto GracefulExit; break; } iRet = CCONTEXT_SUCCESS; GracefulExit: return iRet; } catch(...) { THROWIMEXCEPTION("80043206"); }}void MonitorConnectState(int *pNotUsed){/* int iRet; bool PrevIsNetOn; bool IsNetOn; BOOL bRet; bool Changed; long PrevCnt; CMediaConnect cMediaConnect; try { g_hMonitorSem = CreateSemaphore(NULL, 0, 100, NULL); if ( !g_hMonitorSem ) return; g_hMediaConnectSem = CreateSemaphore(NULL, 0, 100, NULL); if ( !g_hMediaConnectSem ) return; g_hMediaDisconnectSem = CreateSemaphore(NULL, 0, 100, NULL); if ( !g_hMediaDisconnectSem ) return; } catch(...) { // THROWIMEXCEPTION(80043207); } try { Changed = false; iRet = cMediaConnect.IsNetOn(&IsNetOn); } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043208")); nse.SetParent( &se ); throw nse; } throw se; } catch(...) { // THROWIMEXCEPTION(80043208); } while ( !g_bExit ) { PrevIsNetOn = IsNetOn; iRet = cMediaConnect.IsNetOn(&IsNetOn); Changed = PrevIsNetOn ^ IsNetOn; if ( Changed ) { try { if ( IsNetOn ) { if ( g_hMediaConnectSem ) bRet = ReleaseSemaphore(g_hMediaConnectSem, 1, &PrevCnt); } else { if ( g_hMediaDisconnectSem ) bRet = ReleaseSemaphore(g_hMediaDisconnectSem, 1, &PrevCnt); } } catch(...) { // THROWIMEXCEPTION(80043209); } } try { WaitForSingleObject(g_hMonitorSem, CONNECT_CHECK_TIME); } catch(...) { // THROWIMEXCEPTION(80043202); } }*/}unsigned int ConnectStateChangeCB(void *pNotUsed){ int iRet; bool PrevIsNetOn; bool IsNetOn; BOOL bRet; static bool Changed; long PrevCnt; CMediaConnect cMediaConnect; bool init = false;/* try {//nhu: call back directly g_hMonitorSem = CreateSemaphore(NULL, 0, 100, NULL); if ( !g_hMonitorSem ) return; g_hMediaConnectSem = CreateSemaphore(NULL, 0, 100, NULL); if ( !g_hMediaConnectSem ) return; g_hMediaDisconnectSem = CreateSemaphore(NULL, 0, 100, NULL); if ( !g_hMediaDisconnectSem ) return; } catch(...) { // THROWIMEXCEPTION(80043207); }*//* if(!init) { try { Changed = false; iRet = cMediaConnect.IsNetOn(&IsNetOn); init = true; } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043208")); nse.SetParent( &se ); throw nse; } throw se; } }*/ //while ( !g_bExit ) //{ //PrevIsNetOn = IsNetOn; iRet = cMediaConnect.IsNetOn(&IsNetOn); //Changed = PrevIsNetOn ^ IsNetOn; //if ( Changed ) //{ try { if ( IsNetOn ) { //nhu: call back directly, is it good? /* if ( g_hMediaConnectSem ) bRet = ReleaseSemaphore(g_hMediaConnectSem, 1, &PrevCnt); */ //printf("Media Connect\n"); ConnectCB(NULL); } else { //nhu: call back directly, is it goold? /* if ( g_hMediaDisconnectSem ) bRet = ReleaseSemaphore(g_hMediaDisconnectSem, 1, &PrevCnt); */ //printf("Media DisConnect\n"); DisconnectCB(NULL); } } catch(...) { // THROWIMEXCEPTION(80043209); } //} /* try { //nhu: if it only sleep, then call back directly //WaitForSingleObject(g_hMonitorSem, CONNECT_CHECK_TIME); } catch(...) { // THROWIMEXCEPTION(80043202); } */ //} return 0;}PROVIDER_API IClassProvider* CreateClassProvider(/* HWND& hWnd*/ ){// LocalClassProvider.SetWindowHandle( hWnd ); return &LocalClassProvider;}//==============================================================================ContextClassProvider::~ContextClassProvider(){ Unload(); try { DeleteCriticalSection( &m_DefaultProviderCS ); } catch(...) { // THROWIMEXCEPTION(8004320A); }}bool ContextClassProvider::Load(){//#ifdef _DEBUG _Log(IntelMobileText("ContextClassProvider::Load()"));//#endif bool bRet = true; bRet = Scan(); if(bRet!=true) { return false; } try { DWORD dwThreadId = 0; //g_hMonitorConnectThread=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE ) MonitorConnectState, NULL, 0, NULL); /* if(!g_hMonitorConnectThread) { g_hMonitorConnectThread=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE ) MonitorConnectState, NULL, 0, &dwThreadId); if(g_hMonitorConnectThread==NULL) { return false; } } */ } catch(...) { // THROWIMEXCEPTION(80043206); } int iRet = CCONTEXT_FAIL; iRet = EventRegister(EVENT_CONNECT); if(iRet!=CCONTEXT_SUCCESS) { return false; } iRet = EventRegister(EVENT_DISCONNECT); if(iRet!=CCONTEXT_SUCCESS) { return false; } iRet = EventRegister(EVENT_IPADDR_CHANGE); if(iRet!=CCONTEXT_SUCCESS) { return false; } iRet = EventRegister( EVENT_ROUTE_CHANGE); if(iRet!=CCONTEXT_SUCCESS) { return false; } // other initialization, i.e. monitor and fire events... iRet = EventRegister( EVENT_BANDWIDTHCHANGED ); if(iRet!=CCONTEXT_SUCCESS) { return false; } return true;}bool ContextClassProvider::Unload(){ _Log(IntelMobileText("ContextClassProvider::Unload()")); try { g_bExit = 1; //Sleep(EXIT_DELAY); //CloseHandle( g_hMonitorConnectThread ); CloseHandle( g_hRouteChangeThread ); CloseHandle( g_hBandwidthChangedThread ); //CloseHandle( g_hIPAddressChangeThread ); //CloseHandle( g_hConnectThread ); //CloseHandle( g_hDisconnectThread ); return true; } catch(...) { THROWIMEXCEPTION("8004320B"); }}bool ContextClassProvider::Scan(){ // to detect devices and call CreateInstance(...). CreateInstance( IntelMobileText("Connectivity"), IntelMobileText("Connectivity"), IntelMobileText("Connectivity") ); CreateInstance( IntelMobileText("Power"), IntelMobileText("Power"), IntelMobileText("Power") ); CreateInstance( IntelMobileText("Bandwidth"), IntelMobileText("Bandwidth"), IntelMobileText("Bandwidth") ); CreateInstance( IntelMobileText("Storage"), IntelMobileText("Storage"), IntelMobileText("Storage") ); CreateInstance( IntelMobileText("Display"), IntelMobileText("Display"), IntelMobileText("Display") ); return true;}/*bool ContextClassProvider::WindowNotification(HWND m_hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam){ bool bRet = true; // // TODO: for CE. But.. we does not support WindowNotification on WinCE. return bRet;}*///==============================================================================ServerInstanceObject* ContextClassProvider::CreateInstance( const IntelMobileString& externalKey, const IntelMobileString& internalKey, const IntelMobileString& sType ){// _Log(IntelMobileText("ContextClassProvider::CreateInstance(%s, %s, %s)", externalKey, internalKey, sType ); try { ServerInstanceObject* pObject = GetClassObject().GetInstance( internalKey ); if ( pObject == NULL ) { IInstanceProvider* pProvider = GetLayer()->GetLayerInstanceProvider( sType, externalKey ); if ( pProvider != NULL ) { pObject = pProvider->CreateInstance( internalKey ); if ( pObject != NULL ) { ServerInstanceCollection* pCollection = GetClassObject().GetInstances(); pCollection->Add( pObject ); } } } return pObject; } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("8004320C")); nse.SetParent( &se ); throw nse; } throw se; } catch(...) { // THROWIMEXCEPTION(8004320C); }}ServerInstanceObject * ContextClassProvider::GetInstance(const IntelMobileString& internalKey){ _Log(IntelMobileText("ContextClassProvider::GetInstance(%s)"), 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 + -