📄 intelmobilecontextclassprovider.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.
*///==============================================================================// IntelMobileContextClassProvider.cpp//// Defines the class for the Context class provider. This module// contains the methods for the public interfaces of the inherited classes.// Implement the event for the connectivity//// //==============================================================================/*#include "stdafx.h"#include <windows.h>#include <iphlpapi.h>#include <iptypes.h>*/#include <string>using namespace std;#include "IntelMobileContextClassProvider.h"#include "mediaconnect.h"#include "inc/common/EnumBase.h"#include "inc/framework/base_Exception.h"#include "routemonitor.h"typedef struct{ IntelMobileString key; unsigned __int64 TxRate; unsigned __int64 RxRate; IntelMobileBool IsReplaced;} ProcotolRateInfo;typedef vector <ProcotolRateInfo> RATEVECTOR;RATEVECTOR g_RateVector;bool g_isInitialized = false;ContextClassProvider LocalClassProvider;HANDLE g_hRouteChangeThread = NULL; // callback for route changeHANDLE g_hIPAddressChangeThread = NULL; // callback for ip address changeHANDLE g_hConnectThread = NULL; // callback for connect changeHANDLE g_hDisconnectThread = NULL; // callback for disconnect changeHANDLE g_hMonitorConnectThread = NULL; // monitor threadHANDLE g_hMonitorSem = NULL; // monitoring semaphore (sleep sub)HANDLE g_hMediaConnectSem = NULL; // connect cb semaphoreHANDLE g_hMediaDisconnectSem = NULL; // disconnect cb semaphoreHANDLE g_hBandwidthChangedThread = NULL; // callback for bandwidth changeint g_bExit = 0; // dll exit flag//==============================================================================unsigned int ConnectCB(void *pParam){ int iRet; iRet = CCONTEXT_SUCCESS; //while ( !g_bExit ) //{ /* try { WaitForSingleObject(g_hMediaConnectSem, INFINITE); } catch(...) { // THROWIMEXCEPTION(80043202); } */ // if ( g_hMediaConnectSem ) // { ServerInstanceObject* pMyConnectivityInstance=NULL; try { pMyConnectivityInstance = GetLayer()->GetLayerClassObject(IntelMobileText("Context")).GetInstance(IntelMobileText("Connectivity")); } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043201")); nse.SetParent( &se ); throw nse; } throw se; } try { if(pMyConnectivityInstance) { pMyConnectivityInstance->FireEvent(ServerEvent( ServerEvent::eConnected, pMyConnectivityInstance )); } } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043203")); nse.SetParent( &se ); throw nse; } throw se; } // } //} return CCONTEXT_SUCCESS;}/* ______________________________________________________________ DisconnectCB______________________________________________________________ */unsigned int DisconnectCB(void *pParam){ int iRet; iRet = CCONTEXT_SUCCESS; //while ( !g_bExit ) //{ /* try { WaitForSingleObject(g_hMediaDisconnectSem, INFINITE); } catch(...) { // THROWIMEXCEPTION(80043202); } */ // if ( g_hMediaDisconnectSem ) // { ServerInstanceObject* pMyConnectivityInstance = NULL; try { pMyConnectivityInstance=GetLayer()->GetLayerClassObject(IntelMobileText("Context")).GetInstance(IntelMobileText("Connectivity")); } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043201")); nse.SetParent( &se ); throw nse; } throw se; } try { if(pMyConnectivityInstance) { pMyConnectivityInstance->FireEvent(ServerEvent( ServerEvent::eDisconnected, pMyConnectivityInstance )); } } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043203")); nse.SetParent( &se ); throw nse; } throw se; } // } //} return CCONTEXT_SUCCESS;}/* ______________________________________________________________ RouteTableChangeCB______________________________________________________________ */unsigned int RouteTableChangeCB(void *pParam){ int iRet; BOOL bWait; HANDLE hRouteChange; HRESULT hResult;// unsigned long NumberOfBytesTransferred; unsigned int Status; bWait = FALSE; hRouteChange = NULL; iRet = CCONTEXT_SUCCESS;/* try { memset(&Overlapped, 0, sizeof(OVERLAPPED)); } catch(...) { THROWIMEXCEPTION(80043204); }*/ try { // Status = NotifyRouteChange(&hRouteChange, NULL); // if ( Status == NO_ERROR ) { // // TODO: for CE //hResult = GetOverlappedResult(hRouteChange, &Overlapped, &NumberOfBytesTransferred, bWait); //nhu: monitor thread call back directly //hResult=WaitForSingleObject(hRouteChange,INFINITE); } /* else { iRet = CCONTEXT_FAIL; break; } */ } catch(...) { // THROWIMEXCEPTION(80043205); } ServerInstanceObject* pMyConnectivityInstance = NULL; try { pMyConnectivityInstance=GetLayer()->GetLayerClassObject(IntelMobileText("Context")).GetInstance(IntelMobileText("Connectivity")); } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043201")); nse.SetParent( &se ); throw nse; } throw se; } try { if(pMyConnectivityInstance) { pMyConnectivityInstance->FireEvent(ServerEvent( ServerEvent::eRouteTableChanged, pMyConnectivityInstance )); } } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043203")); nse.SetParent( &se ); throw nse; } throw se; } return CCONTEXT_SUCCESS;}/* ______________________________________________________________ IPAddressChangeCB______________________________________________________________ */unsigned int IPAddressChangeCB(void *pParam){ int iRet; HANDLE hRouteChange; HRESULT hResult;// OVERLAPPED Overlapped;// unsigned long NumberOfBytesTransferred; unsigned int Status; BOOL bWait; bWait = FALSE; iRet = CCONTEXT_SUCCESS; hRouteChange = NULL;/* try { memset(&Overlapped, 0, sizeof(OVERLAPPED)); } catch(...) { THROWIMEXCEPTION(80043204); }*/ try { // Status = NotifyAddrChange(&hRouteChange, NULL); // if ( Status == NO_ERROR ) { // // TODO: for CE// hResult = GetOverlappedResult(hRouteChange, &Overlapped, &NumberOfBytesTransferred, bWait); //nhu: monitor thread call back directly //hResult=WaitForSingleObject(hRouteChange,INFINITE); } /* else { iRet = CCONTEXT_FAIL; break; } */ } catch(...) { // THROWIMEXCEPTION(80043205); } ServerInstanceObject* pMyConnectivityInstance = NULL; try { pMyConnectivityInstance=GetLayer()->GetLayerClassObject(IntelMobileText("Context")).GetInstance(IntelMobileText("Connectivity")); } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043201")); nse.SetParent( &se ); throw nse; } throw se; } try { if(pMyConnectivityInstance) { pMyConnectivityInstance->FireEvent(ServerEvent( ServerEvent::eIpAddressChanged, pMyConnectivityInstance )); } } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043203")); nse.SetParent( &se ); throw nse; } throw se; } return CCONTEXT_SUCCESS;}unsigned int BandwidthChangeView(void *pParam){ int iRet; //BOOL bWait; //RATEVECTOR RateVector; //whether or not this is the first time to run the program if (g_RateVector.empty()) { g_isInitialized = false;// g_RateVector.clear(); } else g_isInitialized = true; //bWait = FALSE; iRet = CCONTEXT_SUCCESS; while ( !g_bExit ) { ServerLinkProtocolInstanceObject *pLinkProtocolInstance; long iChangedIndex = 0; // to act like client int iEnumIndex = 0; bool isFiredEvent = false; ServerInstanceObject* pMyBandwidthInstance = NULL; try { pMyBandwidthInstance = GetLayer()->GetLayerClassObject(IntelMobileText("Context")).GetInstance(IntelMobileText("Bandwidth")); } catch(ServerException se) { if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043201")); nse.SetParent( &se ); throw nse; } throw se; } ServerInstanceCollection* pLinkProtocolInstanceCollection = NULL; ProcotolRateInfo tempProtocolRateInfo; //IntelMobileString tempKey = NULL; //unsigned __int64 tempTx = 0; //unsigned __int64 tempRx = 0; RATEVECTOR::iterator theIterator; unsigned __int32 size = 0; if (pLinkProtocolInstanceCollection = ((ServerLinkProtocolClassObject&)(GetLayer()->GetLayerClassObject(IntelMobileText("LinkProtocol")))).GetInstances()) { pLinkProtocolInstanceCollection->Reset(&iChangedIndex); bool bHasNext; if ( bHasNext = pLinkProtocolInstanceCollection->HasNext(iEnumIndex, iChangedIndex )) { size = pLinkProtocolInstanceCollection->GetCount(); while ( bHasNext )//&& !isFiredEvent ) { if ( !pLinkProtocolInstanceCollection->Next( (ServerInstanceObject**)&pLinkProtocolInstance, &iEnumIndex, iChangedIndex ) ) break; else { BOOL isMatched = false; if (g_isInitialized == false) { //initialize the global Rate vector tempProtocolRateInfo.key = pLinkProtocolInstance->GetKey(); tempProtocolRateInfo.TxRate = pLinkProtocolInstance->DataRateTx.GetValue(); tempProtocolRateInfo.RxRate = pLinkProtocolInstance->DataRateRx.GetValue(); tempProtocolRateInfo.IsReplaced = true; g_RateVector.push_back(tempProtocolRateInfo); } else { //initialize the RateVector for the next check tempProtocolRateInfo.key = pLinkProtocolInstance->GetKey(); tempProtocolRateInfo.TxRate = pLinkProtocolInstance->DataRateTx.GetValue(); tempProtocolRateInfo.RxRate = pLinkProtocolInstance->DataRateRx.GetValue(); tempProtocolRateInfo.IsReplaced = true; //RateVector.push_back(tempProtocolRateInfo); //if (size < RateVector.size()) //{ // //firedevent �����Ƿ�Ҫ������ʧ��instance��tx ����rxΪ0 // isFiredEvent = true; //} //tempKey = pLinkProtocolInstance->GetKey(); //tempTx = pLinkProtocolInstance->CurrentTxDataRate.GetValue(); //tempRx = pLinkProtocolInstance->CurrentRxDataRate.GetValue(); for (theIterator = g_RateVector.begin(); theIterator != g_RateVector.end();theIterator++) { // ProcotolRateInfo* temp = (ProcotolRateInfo *)theIterator; if ((*theIterator).key == pLinkProtocolInstance->GetKey()) { if(tempProtocolRateInfo.TxRate != (*theIterator).TxRate || tempProtocolRateInfo.RxRate !=(*theIterator).RxRate) { isFiredEvent = true; ((*theIterator)).TxRate = tempProtocolRateInfo.TxRate; ((*theIterator)).RxRate = tempProtocolRateInfo.RxRate; } ((*theIterator)).IsReplaced = true; isMatched = true; break; } } if (isMatched == false)//that means there is new linkprotocol instance { g_RateVector.push_back(tempProtocolRateInfo); if (!(tempProtocolRateInfo.TxRate == 0 && tempProtocolRateInfo.RxRate ==0)) { isFiredEvent = true; //û�з������instance����ǰ��instance��vector�У�˵���½�������һ��protocol instance,��Ҫ�����¼����instance��tx rx�Ƿ�Ϊ�� } } } } if (!(bHasNext = pLinkProtocolInstanceCollection->HasNext( iEnumIndex, iChangedIndex ))) break; } g_isInitialized = true; } } for (theIterator = g_RateVector.begin(); theIterator < g_RateVector.end(); theIterator++) { // ProcotolRateInfo* temp = (ProcotolRateInfo *)theIterator; if ((*theIterator).IsReplaced == false)//that meas there is a linkprotocol instance which has been removed { if (!((*theIterator).TxRate == 0 && (*theIterator).RxRate == 0)) { isFiredEvent = true; } theIterator = g_RateVector.erase(theIterator); } } if (isFiredEvent) { try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -