Capturing keys in background

<!-- /* Font Definitions */ @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:宋体; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@SimSun"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:SimSun;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

 

Capturing keys in background

From Forum Nokia Wiki

The CKeyCapturer implementation illustrates how to capture key events in a background process. Note that you need to define the key to be captured when using the CaptureKey() function (example is capturing the EKeyDevice0 key).

Also note that if the key should also be usable for the focused application, you need to manually forward it. This is already handled by the example as shown in the RunL() method. The callback interface function will return EFalse if the key is supposed to be forwarded to the focus application and ETrue if the key was consumed.

This example code should work with all platforms, but when used with S60 3rd Edition devices you need to have the SwEvent capability.

If you want to capture basic application keys in a foreground application you can use the standard OfferKeyEventL() method implemented in your CCoeControl derived class. If your application does not implement the standard application framework, you could also try using CKeyCapturer2 implementation.

Header required:

#include <w32std.h>
#include <apgwgnam.h> //CApaWindowGroupName

Library Required:

LIBRARY   ws32.lib
LIBRARY   apgrfx.lib //CApaWindowGroupName

Capability Required:

capability    SwEvent

CapturingKeys.cpp

CKeyCapturer* CKeyCapturer:: NewL ( MKeyCallBack& aObserver)
        {
        CKeyCapturer* self = CKeyCapturer:: NewLC ( aObserver) ;
        CleanupStack:: Pop ( self) ;
        return self;
        }
 
CKeyCapturer* CKeyCapturer:: NewLC ( MKeyCallBack& aObserver)
        {
        CKeyCapturer* self = new ( ELeave) CKeyCapturer( aObserver) ;
        CleanupStack:: PushL ( self) ;
        self- > ConstructL() ;
        return self;
        }
 
CKeyCapturer:: CKeyCapturer ( MKeyCallBack& aObserver)
: CActive( EPriorityStandard) ,iObserver( aObserver) ,iHandle( - 1)
{
}
 
CKeyCapturer:: ~CKeyCapturer()
{
        if ( iHandle > - 1)
        {
               iWg.CancelCaptureKey ( iHandle) ;
        }
 
        iHandle = - 1 ;
 
        Cancel() ;
 
        iWg.Close () ;
        iWsSession.Close () ;    
}
 
void CKeyCapturer:: ConstructL ()
{
        CActiveScheduler:: Add ( this ) ;
 
        User:: LeaveIfError ( iWsSession.Connect ()) ;
 
        iWg= RWindowGroup( iWsSession) ;
        User:: LeaveIfError ( iWg.Construct (( TUint32) & iWg, EFalse)) ;
        iWg.SetOrdinalPosition ( - 1) ;
        iWg.EnableReceiptOfFocus ( EFalse) ;
 
        CApaWindowGroupName* wn= CApaWindowGroupName:: NewLC ( iWsSession) ;
        wn- > SetHidden( ETrue) ;
        wn- > SetWindowGroupName( iWg) ;
        CleanupStack:: PopAndDestroy () ;
 
        iHandle = iWg.CaptureKey ( EKeyDevice0, 0,0) ;
        Listen() ;
}
 
void CKeyCapturer:: RunL ()
{
        if ( iStatus == KErrNone)
        {
               TWsEvent e;
               iWsSession.GetEvent ( e) ;
 
               if ( iObserver.KeyCapturedL ( e))
               {       
                       TInt wgId = iWsSession.GetFocusWindowGroup () ;
                       iWsSession.SendEventToWindowGroup ( wgId, e) ;
               }
        }
 
        if ( iStatus ! = KErrCancel)
        {
               Listen() ;
        }
}
 
void CKeyCapturer:: DoCancel ()
{
        iWsSession.EventReadyCancel () ;
}
 
void CKeyCapturer:: Listen ()
{
        iWsSession.EventReady ( & iStatus) ;
        SetActive() ;
}

CapturingKeys.h

class MKeyCallBack
{
public :
        virtual TBool KeyCapturedL( TWsEvent aEvent) = 0 ;
} ;
 
class CKeyCapturer : public CActive
{
public :
        static CKeyCapturer* NewL( MKeyCallBack& aObserver) ;
        static CKeyCapturer* NewLC( MKeyCallBack& aObserver) ;
        virtual ~CKeyCapturer() ;
private :
        CKeyCapturer( MKeyCallBack& aObserver) ;
        void ConstructL() ;
        void RunL() ;
        void DoCancel() ;
        void Listen() ;
private :
        MKeyCallBack& iObserver;
        RWsSession     iWsSession;
        RWindowGroup    iWg;
        TInt                   iHandle;
} ;

If you need to capture keys that are intended for applications like Google Maps or Nokia Maps, where a key held down makes multiple events you might better use this code in the RunL function:

void CKeyCapturer::RunL()
{
        if (iStatus == KErrNone)
        {
               TWsEvent e;
               iWsSession.GetEvent(e);              
 
               //Only if iRepeats is 0 we should forward the event
               if(e.Key()->iRepeats == 0 && iObserver.KeyCapturedL(e))
               {
                       TInt wgId = iWsSession.GetFocusWindowGroup();
                       iWsSession.SendEventToWindowGroup(wgId, e);                 
               }             
        }
 
        if (iStatus != KErrCancel)
        {
               Listen();
        }
}

 

 

数据中心机房是现代信息技术的核心设施,它承载着企业的重要数据和服务,因此,其基础设计与规划至关重要。在制定这样的方案时,需要考虑的因素繁多,包括但不限于以下几点: 1. **容量规划**:必须根据业务需求预测未来几年的数据处理和存储需求,合理规划机房的规模和设备容量。这涉及到服务器的数量、存储设备的容量以及网络带宽的需求等。 2. **电力供应**:数据中心是能源消耗大户,因此电力供应设计是关键。要考虑不间断电源(UPS)、备用发电机的容量,以及高效节能的电力分配系统,确保电力的稳定供应并降低能耗。 3. **冷却系统**:由于设备密集运行,散热问题不容忽视。合理的空调布局和冷却系统设计可以有效控制机房温度,避免设备过热引发故障。 4. **物理安全**:包括防火、防盗、防震、防潮等措施。需要设计防火分区、安装烟雾探测和自动灭火系统,设置访问控制系统,确保只有授权人员能进入。 5. **网络架构**:规划高速、稳定、冗余的网络架构,考虑使用光纤、以太网等技术,构建层次化网络,保证数据传输的高效性和安全性。 6. **运维管理**:设计易于管理和维护的IT基础设施,例如模块化设计便于扩展,集中监控系统可以实时查看设备状态,及时发现并解决问题。 7. **绿色数据中心**:随着环保意识的提升,绿色数据中心成为趋势。采用节能设备,利用自然冷源,以及优化能源管理策略,实现低能耗和低碳排放。 8. **灾难恢复**:考虑备份和恢复策略,建立异地灾备中心,确保在主数据中心发生故障时,业务能够快速恢复。 9. **法规遵从**:需遵循国家和地区的相关法律法规,如信息安全、数据保护和环境保护等,确保数据中心的合法运营。 10. **扩展性**:设计时应考虑到未来的业务发展和技术进步,保证机房有充足的扩展空间和升级能力。 技术创新在数据中心机房基础设计及规划方案中扮演了重要角色。例如,采用虚拟化技术可以提高硬件资源利用率,软件定义网络(SDN)提供更灵活的网络管理,人工智能和机器学习则有助于优化能源管理和故障预测。 总结来说,一个完整且高效的数据中心机房设计及规划方案,不仅需要满足当前的技术需求和业务目标,还需要具备前瞻性和可持续性,以适应快速变化的IT环境和未来可能的技术革新。同时,也要注重经济效益,平衡投资成本与长期运营成本,实现数据中心的高效、安全和绿色运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值