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

📄 base_property.h

📁 270的linux说明
💻 H
📖 第 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.

*///==============================================================================// base_Property.h//==============================================================================//#pragma once#ifndef _BASE_PROPERTY_H#define _BASE_PROPERTY_H#include "inc/framework/win2linux.h"#include <string>#include <vector>#include "inc/framework/base_EventDispatcher.h"#include "inc/framework/base_Threshold.h"#include "inc/framework/base_InstanceObject.h"#include "inc/framework/base_Object.h"#include "inc/framework/basetypes.h"#include "inc/framework/base_Enum.h"#include "inc/framework/PropertyManager.h"using namespace std;class ServerPropertyBase;class ServerInstanceObject;class PropertyMonitorThread;// this allows multiple implementations with the same property name, the implementation// figures out which class it applies to and searches the property list for a specific// implemenation of it.  Since this is all key based, it doesn't follow normal rules// for inherited values (i.e. using vtable, etc.)class ServerPropertyMap{public:	ServerPropertyMap (IntelMobileString s1, IntelMobileString s2, ServerPropertyBase* s3)		:szName(s1),		szFullName(s2),		pProperty(s3) {}    IntelMobileString            szName;         // e.g. "TxRate"    IntelMobileString            szFullName;     // e.g. "WiredTxRate"    ServerPropertyBase*     pProperty;      // e.g. &class WiredTxRateClass};//==============================================================================//==============================================================================//// ServerPropertyBase//// Description: // Need this base class so we can have a polymorphic class to store within a map for both// array and regular property types.  //// The map is needed so that an object can find its property given a name.  // Explain why important...////==============================================================================//==============================================================================class ServerPropertyBase : public ServerObject, public EventDispatcher{public:    ServerPropertyBase( ServerInstanceObject* pThis, const IntelMobileString& Name, bool IsSettable, bool IsStatic, int iMinPollRate );    virtual ~ServerPropertyBase();          public:    virtual bool                IsSettable()                        { return _Settable; }    bool                IsStatic()                          { return _Static; }    bool                IsInitialized()                     { return _Initialized; };    virtual size_t      GetSize()                           { return _Null ? 0 : 1; }               // GH to support access of array     virtual size_t      GetMaxSize()                        { return 1; }                           //    size through base class pointer    const IntelMobileString& GetName()                           { return _Name; }    virtual bool        IsNull() = 0;                                                               // Queries the device     virtual void        InitValue() = 0;//==============================================================================// These might be taken out, depends on Threshold implementation taking over// this functionality.    // essential function for automated polling, the collection can't use GetValue directly because    // it only has knowledge of the ServerPropertyBase which doesn't have any <type> knowledge and    // therefore can't use GetValue.  All this does is call GetValue...    long                GetMinPollRate() { return _iMinPollRate; }    bool                PollCheck();    	virtual HRESULT Subscribe  ( HANDLE pInterface, ServerEvent::EventType eType );    virtual HRESULT Unsubscribe( HANDLE pInterface, ServerEvent::EventType eType );//==============================================================================protected:      bool                IsCachedNull()                      { return _Null; }                       // Doesn't query device    void                SetNull( bool Null )                { _Null = Null; _Initialized = true; }  // Server only    void                SetInitialized( bool Initialized)   { _Initialized = Initialized; }         // Server only//==============================================================================// These might be taken out, depends on Threshold implementation taking over// this functionality.    void                TriggerChangedEvent();//==============================================================================protected:    // This function is for a specific property implementation to override to get specific    // information from a particular piece of hardware.  It is called appropriately from    // GetValue().    virtual void    GetValueImpl() = 0;        virtual bool    GetValueShim() = 0;	PropertyManager&  m_PropertyManager;private:    void                Init( vector<ServerPropertyMap>** pPropList, const IntelMobileString& Name );protected:    IntelMobileString                _Name;              // No setter, done statically at compile time    bool                        _Settable;          // No setter, done statically at compile time    bool                        _Static;            // No setter, done statically at compile time    long                        _iMinPollRate;    bool                        _Initialized;    bool                        _Null;               ServerInstanceObject*       _pThis;    PropertyMonitorThread*      m_pMonitorThread;   // NULL Unless a n Event or Threshold is set.    ThresholdCollection         m_Thresholds;       // Threadsafe collection.private:    vector<ServerPropertyMap>*  pPrivatePropList;};//==============================================================================//// ServerProperty//// Description: // Split out from the ServerPropertyBase so that the ServerPropertyMap could be used // abstractly.  These are aggregated in the specific instances of the derived classes for// obvious reasons////==============================================================================template <class T>class ServerProperty : public ServerPropertyBase{public:     virtual ~ServerProperty() {}    // No default value    ServerProperty( ServerInstanceObject* pThis, const IntelMobileString& Name, bool IsSettable, bool IsStatic, int iMinPollRate )        :   ServerPropertyBase( pThis, Name, IsSettable, IsStatic, iMinPollRate )       {}    // Takes default value, sets default value and initializes base    ServerProperty( ServerInstanceObject* pThis, const IntelMobileString& Name, const T Value, bool IsSettable, bool IsStatic, int iMinPollRate )        :   ServerPropertyBase( pThis, Name, IsSettable, IsStatic, iMinPollRate )    {        SetValue( Value );     }    void InitValue()    {         if ( IsInitialized() == false )        {            GetValueImpl();         }    }    bool IsNull()    {         if ( !IsInitialized() || !IsStatic() )         {              GetValue();             SetInitialized( true );        }        return _Null;    }    // This function should be called from the client only.  If you want to set the value from the server    // directly, call SetValueImpl().     // SetValueImpl() - sets the value of the property in the singleton object.  Templatized.    // SetValueImplOnDevice() - sets the value on the device itself.  This is a virtual function of    //      course that each implementor has to code.    void SetValue( T Value )    { try{         if ( !IsInitialized() || !IsStatic() )        {            SetValueImpl( Value );            SetValueImplOnDevice( Value );        }        else            throw E_FAIL;}catch( ServerException se){        throw se;}catch(...){	THROWIMEXCEPTION("8004401D");}    }    // This is necessary for functionality that needs to get the store value without querying the device    // It's ok to throw an error here, the server method that calls this should be aware that it    // should check for null first just like on the client.    // Server only function    T GetCachedValue()      {//      if ( !IsCachedNull() )            return _Value;//      else//      {//          throw E_FAIL;//      }    }    const T GetValue()    {try{        if ( !ServerProperty::IsStatic() || !ServerProperty::IsInitialized() ) // skip if static, unless first time to get ( is null = true )        {            if ( ServerProperty::IsInitialized() == true )            {                // two things:                // 1. only need to fire changed event if it has been initialized                // 2. static events can't change by definition                GetValueShim();            }            else            {                GetValueImpl();            }        }        if ( ServerProperty::IsCachedNull() )        {            //return S_FALSE to client            //on the client side, if S_FALSE, throw error            // in com server wrapper,         }        return _Value;}catch( ServerException se){        throw se;}catch(...){        THROWIMEXCEPTION("8004401E");}    }    // This is how we determine if something has changed.  It gets the current value as a side effect.    // This is called from:    //    PollCheck()    //    GetValue()    //    Server methods instead of them calling GetValueImpl() directly    virtual bool GetValueShim()    {        bool bRet = true;        Lock();        // store previous value        bool bCachedNull = IsCachedNull();        T PreviousValue = _Value;        // get real value        GetValueImpl();        // very important to check NULL status first because value can be the same when the only        // difference is the NULL value!        if ( bCachedNull != _Null )        {            TriggerChangedEvent();        }        else        {            // compare values            if ( PreviousValue != _Value )            {                // trigger changed event if necessary                TriggerChangedEvent();            }        }        Unlock();        return bRet;    }protected://    // This function is for a specific property implementation to override to get specific//    // information from a particular piece of hardware.  It is called appropriately from//    // GetValue().//    virtual void    GetValueImpl() = 0;    // This function sets the internal value within the property.  It doesn't modify the    // hardware or check to see if its able to be set.  For that, use SetValue().  This    // function is useful to call from within a GetValueImpl() implementation to set    // the property in the class.  You might think, if it's not static nothing should be    // stored and we should go to the hardware every time!  Well, that's fine and what     // happens but we need to save that value once we get it to detect changes later on.    virtual bool SetValueImpl( T Value )    {	try{        _Value = Value;             SetNull(false);        SetInitialized(true);        return true;}catch( ServerException se){        throw se;}catch(...){        THROWIMEXCEPTION("8004401D");}    }    // This function is for a specific property implementation to override to set something    // on hardware.  This is called from SetValue() if the property is Settable.  Servers can    // use this to change device settings directly.    virtual bool    SetValueImplOnDevice( T Value )    {

⌨️ 快捷键说明

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