📄 instance_linkprotocol.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.
*///==============================================================================// Instance_LinkProtocol.cpp//// //==============================================================================//#include "stdafx.h"#include "Instance_LinkProtocol.h"#include "netdev_lib.h"#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>//==============================================================================//==============================================================================// // ServerInstanceObject implementation// //==============================================================================//==============================================================================//==============================================================================DefaultLinkProtocolInstanceObject::~DefaultLinkProtocolInstanceObject(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: DefaultLinkProtocolInstanceObject::~DefaultLinkProtocolInstanceObject()") ); UnRegisterEvents();}//==============================================================================bool DefaultLinkProtocolInstanceObject::Initialize( /*in*/ const IntelMobileString& pszFullInterfaceId ){ _Log(IntelMobileText("DefaultLinkProtocolInstanceObject::Initialize(%s)"), pszFullInterfaceId.c_str()); // // TODO: change the internal key bool bRet = true; try { Lock(); m_sKey = pszFullInterfaceId; //event stuff m_hMediaThreadHandle = NULL; m_bMediaThreadActive = false; m_bMediaConnectivetyFlag = false; RegisterEvents(); Unlock(); return bRet; } catch(...) { Unlock(); THROWIMEXCEPTION("80043142"); } }//=============================================================================DWORD __stdcall DefaultLinkProtocolInstanceObject::MediaThreadProc(LPVOID pParam){ DefaultLinkProtocolInstanceObject *pThis = reinterpret_cast<DefaultLinkProtocolInstanceObject *> (pParam); if ( pThis ) pThis->MonitorMediaConnectivety(); return 0;}//=============================================================================void DefaultLinkProtocolInstanceObject::MonitorMediaConnectivety(){ IntelMobileBool ibVal1 = false; while(m_bMediaThreadActive) { ibVal1 = MediaPresent.GetValue(); if(ibVal1 != m_bMediaConnectivetyFlag) { if(ibVal1) { FireEvent(ServerEvent(ServerEvent::eMediaConnected, this)); } else { FireEvent(ServerEvent(ServerEvent::eMediaDisconnected, this)); } m_bMediaConnectivetyFlag = ibVal1; } sleep(1); }}//=============================================================================bool DefaultLinkProtocolInstanceObject::RegisterEvents(){ Lock(); if (m_bMediaThreadActive == false) { if (m_hMediaThreadHandle) { CloseHandle(m_hMediaThreadHandle); m_hMediaThreadHandle = NULL; } DWORD dwThreadId = 0; m_bMediaThreadActive = true; m_hMediaThreadHandle = CreateThread(NULL, 0, MediaThreadProc, this, NULL, &dwThreadId); if (!m_hMediaThreadHandle) m_bMediaThreadActive = false; } Unlock(); return m_bMediaThreadActive;}//=============================================================================bool DefaultLinkProtocolInstanceObject::UnRegisterEvents(){ Lock(); if (m_hMediaThreadHandle) { m_bMediaThreadActive = false; ::WaitForSingleObject(m_hMediaThreadHandle, INFINITE); m_hMediaThreadHandle = NULL; } Unlock(); return true;}//============================================================================IntelMobileString DefaultLinkProtocolInstanceObject::GetDevice(){ try { //the key is same as device return m_sKey; } catch(...) { THROWIMEXCEPTION("80043146"); } }//==============================================================================//==============================================================================// Network Adapter Attributes//==============================================================================//==============================================================================//// These all return the true value. If there is an error, throw // an appropriate HRESULT. i These need to return the true value// because the override the virtual GetValue() function in the // Property base class.void LinkProtocol_DataRatesTxClass::GetValueImpl(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: LinkProtocol_DataRatesTxClass::GetValueImpl()") ); DefaultLinkProtocolInstanceObject* pThis = dynamic_cast<DefaultLinkProtocolInstanceObject*>(_pThis); if ( !pThis ) return; if ( !pThis->MaxLinkSpeed.IsNull() ) { IntelMobileUInt64 iCurrentRate = pThis->MaxLinkSpeed.GetValue(); this->InsertValueImpl( iCurrentRate ); } else this->SetNull( true ); return;}//==============================================================================void LinkProtocol_DataRatesRxClass::GetValueImpl(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: LinkProtocol_DataRatesRxClass::GetValueImpl()") ); DefaultLinkProtocolInstanceObject* pThis = dynamic_cast<DefaultLinkProtocolInstanceObject*>(_pThis); if ( !pThis ) return; if ( !pThis->MaxLinkSpeed.IsNull() ) { IntelMobileUInt64 iCurrentRate = pThis->MaxLinkSpeed.GetValue(); this->InsertValueImpl( iCurrentRate ); } else this->SetNull( true ); return;}//=============================================================================void LinkProtocol_DataRateTxClass::GetValueImpl(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: LinkProtocol_DataRateTxClass::GetValueImpl()") ); DefaultLinkProtocolInstanceObject* pThis = dynamic_cast<DefaultLinkProtocolInstanceObject*>(_pThis); if ( !pThis ) return; if ( !pThis->MaxLinkSpeed.IsNull() ) { IntelMobileUInt64 iCurrentRate = pThis->MaxLinkSpeed.GetValue(); this->SetValueImpl( iCurrentRate ); } else this->SetNull( true ); return;}//=============================================================================void LinkProtocol_DataRateRxClass::GetValueImpl(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: LinkProtocol_DataRateRxClass::GetValueImpl()") ); DefaultLinkProtocolInstanceObject* pThis = dynamic_cast<DefaultLinkProtocolInstanceObject*>(_pThis); if ( !pThis ) return; if ( !pThis->MaxLinkSpeed.IsNull() ) { IntelMobileUInt64 iCurrentRate = pThis->MaxLinkSpeed.GetValue(); this->SetValueImpl( iCurrentRate ); } else this->SetNull( true ); return;}//============================================================================void LinkProtocol_TxPowerClass::GetValueImpl(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: LinkProtocol_TxPowerClass::GetValueImpl()") ); this->SetNull(true);}//============================================================================void LinkProtocol_EnabledClass::GetValueImpl(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: LinkProtocol_EnabledClass::GetValueImpl()") ); DefaultLinkProtocolInstanceObject* pThis = reinterpret_cast<DefaultLinkProtocolInstanceObject*>(_pThis); if ( !pThis ) return; IntelMobileBool bValue = false; try{ pThis->Lock(); netdev_dev netdev; if(netdev_get_device(pThis->GetKey().c_str(), netdev) != NETDEV_SUCCESS) { pThis->Unlock(); throw; } netdev_enabled enabled; if(netdev_get_enabled(netdev, enabled) != NETDEV_SUCCESS) { this->SetNull(true); pThis->Unlock(); return; } bool bValue; if(enabled == ENABLED_UP) bValue = true; else bValue = false; this->SetValueImpl( bValue ); pThis->Unlock(); } catch(...) { pThis->Unlock(); THROWIMEXCEPTION("80043148"); }}//==================================================================void LinkProtocol_MediaPresentClass::GetValueImpl(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: LinkProtocol_MediaPresendClass::GetValueImpl()") ); DefaultLinkProtocolInstanceObject* pThis = reinterpret_cast<DefaultLinkProtocolInstanceObject*>(_pThis); if (!pThis) return; try{ pThis->Lock(); netdev_dev netdev; if(netdev_get_device(pThis->GetKey().c_str(), netdev) != NETDEV_SUCCESS) { pThis->Unlock(); throw; } netdev_running running; if(netdev_get_running(netdev, running) != NETDEV_SUCCESS) { this->SetNull(true); pThis->Unlock(); return; } bool bValue; if(running == RUNNING_RUN) bValue = true; else bValue = false; this->SetValueImpl( bValue );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -