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

📄 intelmobilenetworkclassprovider.cpp

📁 270的linux说明
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*

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.

*///==============================================================================// IntelMobileNetworkClassProvider.cpp//// Defines the class for the default network provider for IntelMobile.  This module// contains the methods for the public interfaces of the inherited classes.//// //==============================================================================//#include "stdafx.h"#include "IntelMobileNetworkClassProvider.h"#include "adaptermonitor.h"#include "netdev_lib.h"#include <assert.h>#include "NetworkHelp.h"#include <stdio.h>NetworkClassProvider LocalClassProvider;bool g_bActive = false;extern "C" unsigned AdapterChangeCB(unsigned int IsAdd){	/*//	MYDEV detail;    DWORD flags;    DWORD size, i, j;        IntelMobileChar szAddDevMsg[500], szRemoveDevMsg[500];    IntelMobileString szAddDevString = "Finding a new Network Device: ";        IntelMobileString szRemoveDevString = "Removed a  Network Device: ";		IntelMobileChar szInstanceName[MAX_ADAPTER_NAME_LENGTH + 4];        IntelMobileChar sDevicePool[10][MAX_ADAPTER_NAME_LENGTH + 4];    SetLastError(0);	int ifcount = 0;    //while (ReadMsgQueue(h, &detail, sizeof(detail), &size, 1, &flags) == TRUE)    {                for(i = 0; i < 500; i ++)                {					szAddDevMsg[i] = '\0';                        szRemoveDevMsg[i] = '\0';                }                i = 0;                j = 0;                if (IsAdd)  //DEVICEARRIVAL                {			GetInterfaceCount(&ifcount);			if(ifcount > g_iDevNum)                        	LocalClassProvider.Scan();  //if add a device, re-scan		}else if(IsAdd == 0) //DEVICEREMOVECOMPLETE                {                       //init variables                        for(j = 0; j < MAX_ADAPTER_NAME_LENGTH + 4; j ++)                        {							szInstanceName[j] = '\0';                        }                        for(i = 0; i < 10; i ++)                        {                                for(j = 0; j < MAX_ADAPTER_NAME_LENGTH + 4; j ++)                                {                                        sDevicePool[i][j] = '\0';								}                       }//re-scan network device to sDevicePool                        DWORD err;                        ULONG size = 0;                        //IP_ADAPTER_INFO *info = NULL;                        IntelMobileInt iDevNum;                        //Re-Scan since OS find remove device message                        //GetAdaptersInfo(info, &size);                        // Allocate space for the list.                        //info = (IP_ADAPTER_INFO*) new char[size];                        try{                                iDevNum = 0;				IntelMobileChar desc[256];				GetInterfaceCount(&ifcount);        			while(ifcount>0)        			{						GetInterfaceName(ifcount, desc, 256);					strncpy(sDevicePool[iDevNum], desc, 256);                                        iDevNum ++;					ifcount --;                                }                                if(iDevNum >= g_iDevNum )				{                                        //throw "return";					//printf("iDevNum(%d) >= g_iDevNum(%d)", iDevNum, g_iDevNum);					return;				}                                //compare with these DevicePools to find which device is removed                                for(i = 0; i < g_iDevNum; i ++)                                {                                        j = 0;                                        while(j < iDevNum)                                        {                                                if ( strcmp( (char *)(IntelMobileChar *)sDevicePool[j], (char *)(IntelMobileChar *)g_sDeviceIDPool[i] ) != 0 )                                                {                                                        j ++;                                                }                                                else                                                {                                                        break;                                                }                                        }                                        if(j >= iDevNum)                                        {                                                memcpy((char *)(IntelMobileChar *)szInstanceName, (char *)(IntelMobileChar *)g_sDeviceIDPool[i], strlen(g_sDeviceIDPool[i]) * sizeof(IntelMobileChar));                                                break;                                        }				}                                //not remove Network                                if(i >= g_iDevNum)                                {                                        //::MessageBox(NULL, IntelMobile("Not Remove Network", IntelMobile("Remove", MB_OK);                                        //throw "return";					//printf("i(%d) >= g_iDevNum(%d)", i, g_iDevNum);					return;								}                                //re-set global Device Pool                                for(i = 0; i < 10; i ++)								{                                        memcpy(g_sDeviceIDPool[i], sDevicePool[i], strlen(sDevicePool[i]) * sizeof(IntelMobileChar));                                }                                g_iDevNum = iDevNum;                                //::MessageBox(NULL, (IntelMobileChar *)szInstanceName, IntelMobile("szInstanceName", MB_OK);                                // Find adapter                                //DefaultNetworkAdapterInstanceObject* pInstanceObject = (DefaultNetworkAdapterInstanceObject*)GetClassObject( IntelMobile("NetworkAdapter" ).GetInstance( pDevBroadcastInterface->dbcc_name );                                DefaultNetworkAdapterInstanceObject* pInstanceObject = (DefaultNetworkAdapterInstanceObject*)LocalClassProvider.GetClassObject( IntelMobileText("NetworkAdapter") ).GetInstance( (IntelMobileChar *)szInstanceName );  //(IntelMobileChar *)detail.d.szName);  //(IntelMobileChar *)szInstanceName );                                if ( pInstanceObject != NULL )                                {                                       // Remove corresponding protocols from their collection                                        size_t iReportedProtocols = pInstanceObject->Protocols.GetSize();                                        size_t iDiscoveredProtocols = 0;                                        IntelMobileChar szTemp[10];                                        for(i = 0; i < 10; i ++)                                        {                                                szTemp[i] = '\0';                                        }                                        sprintf( &szTemp[0], "0x%x", *(IntelMobileChar *)&iReportedProtocols );                                       //::MessageBox(NULL, szTemp, IntelMobile("iReportedProtocols = ", MB_OK | MB_ICONSTOP);                                       while ( pInstanceObject->Protocols.GetSize() > 0 )                                        {											IntelMobileString sProtocol = pInstanceObject->Protocols.GetValue( 0 );                                                assert( sProtocol[0] != NULL );                                                if ( sProtocol[0] != NULL )                                                {                                                        // Removes protocol from the Protocol ArrayString member                                                        // and physically deletes the memory allocation for the														// Protocol InstanceObject                                                        //DefaultLinkProtocolInstanceObject* pLinkObject = (DefaultLinkProtocolInstanceObject*)GetClassObject( IntelMobile("LinkProtocol" ).GetInstance( sProtocol );                                                        DefaultLinkProtocolInstanceObject* pLinkObject = (DefaultLinkProtocolInstanceObject*)LocalClassProvider.GetClassObject( IntelMobileText("LinkProtocol") ).GetInstance( sProtocol );                                                        if ( pLinkObject != NULL )                                                        {                                                                pInstanceObject->RemoveProtocol( pLinkObject, sProtocol );                                                        }                                                }                                                iDiscoveredProtocols++;					}                                        assert( iDiscoveredProtocols == iReportedProtocols );                                        // Remove adapter from its collection										pInstanceObject->RemoveInstance();                                }  //if ( pInstanceObject != NULL )                        }                        catch(char * p)                        {                                if(!strcmp(p, "return"))                                {                                       //Do some clean up work before return.                                        //delete[] (char *)info;									return;                                }                                throw p;                       }                        //delete[] (char *)info;                }  //else        }  //while    //printf("Leaving Enumerate, error = %d\n", GetLastError());*/}/******************************************************************************///MonitorProc( LPVOID pParam )//  Purpose: Monitor whether PnP device message popup or not//  Input: pParam -- OS Message parameter//  Output: /******************************************************************************/DWORD MonitorProc( LPVOID pParam ){	//TODO: Need Implement   adaptermonitor();   return 0;} //  MonitorProc()//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------PROVIDER_API IClassProvider* CreateClassProvider(/* HWND& hWnd*/ ){	return &LocalClassProvider;}//==============================================================================NetworkClassProvider::~NetworkClassProvider(){	Unload();	//DeleteCriticalSection( &m_DefaultProviderCS );}//==============================================================================bool NetworkClassProvider::Load(){	printf("NetworkClassProvider::Load()");	bool bRet = true;	DWORD dwThreadId = 0, dwMediaStatusThreadId = 0;	HANDLE hHandle = NULL;	try	{		bRet = Scan();		if(bRet)		{			if(g_bActive == false)			{				hHandle  = ::CreateThread( NULL, 0, MonitorProc, this, NULL, &dwThreadId );				if(hHandle)				{					g_bActive = true;				}			}		}		return bRet;	}	catch(...)	{		THROWIMEXCEPTION("80043081");	}	}//==============================================================================bool NetworkClassProvider::Unload(){	//	// Unregister for the device change	g_bActive = false;	adaptermonitor_fini();	return true;}//=============================================================================bool NetworkClassProvider::Scan(){	bool bRet = true;	IntelMobileString externalKey = IntelMobileText("");	IntelMobileString internalKey = IntelMobileText("");	Lock();	vector<netdev_dev> netdev_list;	if(netdev_get_devices(netdev_list) == NETDEV_SUCCESS)	{		//get the network devices list, then enumerate them		vector<netdev_dev>::iterator itr = netdev_list.begin();

⌨️ 快捷键说明

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