bluetoothengine/bthid/manager/src/session.cpp
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This is the implementation of application class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32svr.h>
       
    20 
       
    21 #include "layoutmgr.h"
       
    22 #include "server.h"
       
    23 #include "session.h"
       
    24 #include "decode.h"
       
    25 #include "library.h"
       
    26 #include "client.h"
       
    27 #include "debug.h"
       
    28 
       
    29 // ----------------------------------------------------------------------
       
    30 
       
    31 CLayoutSession::CLayoutSession()
       
    32     {
       
    33     // nothing else to do
       
    34     }
       
    35 
       
    36 CLayoutSession* CLayoutSession::NewL()
       
    37     {
       
    38     CLayoutSession* self = CLayoutSession::NewLC();
       
    39     CleanupStack::Pop(self);
       
    40     return self;
       
    41     }
       
    42 
       
    43 CLayoutSession* CLayoutSession::NewLC()
       
    44     {
       
    45     CLayoutSession* self = new (ELeave) CLayoutSession;
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     return self;
       
    49     }
       
    50 
       
    51 void CLayoutSession::ConstructL()
       
    52     {
       
    53     iDecoder = CKeyboardDecoder::NewL();
       
    54     }
       
    55 
       
    56 CLayoutSession::~CLayoutSession()
       
    57     {
       
    58     Server()->SessionClosed();
       
    59 
       
    60     delete iDecoder;
       
    61     iLayoutLibrary = 0; // no ownership
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------
       
    65 
       
    66 void CLayoutSession::ServiceL(const RMESSAGE& aMessage)
       
    67     {
       
    68     TRAPD(err, DispatchMessageL(aMessage));
       
    69     aMessage.Complete(err);
       
    70     }
       
    71 
       
    72 void CLayoutSession::DispatchMessageL(const RMESSAGE& aMessage)
       
    73     {
       
    74     TRACE_INFO( (_L("[HID]\tCLayoutSession::DispatchMessageL(%d)\r\n"),
       
    75                  aMessage.Function()));
       
    76 
       
    77     // Extract the service code from the message
       
    78     TLayoutManagerService service =
       
    79         static_cast<TLayoutManagerService>(aMessage.Function());
       
    80 
       
    81     switch (service)
       
    82         {
       
    83         case EKeyEvent:
       
    84             {
       
    85             TPckgBuf<TKeyEventInfo> eventPkg;
       
    86             aMessage.ReadL(0, eventPkg);
       
    87             TRACE_INFO( (
       
    88                             _L("[HID]\tKey event message: 0x%04x, 0x%02x, %d, %d"),
       
    89                             eventPkg().iHidKey, eventPkg().iModifiers.Value(),
       
    90                             eventPkg().iLockKeys.iCapsLock,
       
    91                             eventPkg().iLockKeys.iNumLock));
       
    92 
       
    93             TPckgBuf<TDecodedKeyInfo> keyPkg;
       
    94             iDecoder->Event(eventPkg(), keyPkg());
       
    95             aMessage.WriteL(1, keyPkg);
       
    96             }
       
    97             break;
       
    98 
       
    99         case ESetInitialLayout:
       
   100             {
       
   101             TRACE_INFO( (_L("[HID]\tSet initial layout message\r\n")));
       
   102             Server()->SetInitialLayoutL(aMessage.Int0(),
       
   103                                         aMessage.Int1(), aMessage.Int2());
       
   104             }
       
   105             break;
       
   106 
       
   107         case ESetLayout:
       
   108             {
       
   109             TRACE_INFO( (_L("[HID]\tSet layout ALL message\r\n")));
       
   110             User::LeaveIfError(Server()->SetLayout(aMessage.Int0()));
       
   111             }
       
   112             break;
       
   113 
       
   114         case EGetInitialLayout:
       
   115             {
       
   116             TRACE_INFO( (_L("[HID]\tGet initial layout message\r\n")));
       
   117             TPckgBuf<TInt> idPkg(Server()->InitialLayout());
       
   118             aMessage.WriteL(0, idPkg);
       
   119             }
       
   120             break;
       
   121 
       
   122         case EGetLayout:
       
   123             {
       
   124             TRACE_INFO( (_L("[HID]\tGet layout message\r\n")));
       
   125             TInt layout = Server()->Layout();
       
   126             TRACE_INFO( (_L("  Layout library ID is %d\r\n"), layout));
       
   127             TPckgBuf<TInt> idPkg(layout);
       
   128             aMessage.WriteL(0, idPkg);
       
   129             }
       
   130             break;
       
   131 
       
   132         case EResetDecoder:
       
   133             {
       
   134             TRACE_INFO( (_L("[HID]\tReset decoder message\r\n")));
       
   135             iDecoder->Reset();
       
   136             }
       
   137             break;
       
   138 
       
   139         case EGetDeviceInfo:
       
   140             {
       
   141             TRACE_INFO( (_L("[HID]\tGet device info message\r\n")));
       
   142             TPckgBuf<TBool> isNokiaSu8Pkg(Server()->IsNokiaSu8());
       
   143             aMessage.WriteL(0, isNokiaSu8Pkg);
       
   144             TPckgBuf<TBool> foundLayoutPkg(Server()->FoundLayout());
       
   145             aMessage.WriteL(1, foundLayoutPkg);
       
   146             }
       
   147             break;
       
   148 
       
   149         default:
       
   150             {
       
   151             TRACE_INFO( (_L("[HID]\tUnknown service request %d\r\n"), service));
       
   152             CLayoutServer::PanicClient(aMessage, EBadRequest);
       
   153             break;
       
   154             }
       
   155         }
       
   156     }
       
   157 
       
   158 // ----------------------------------------------------------------------
       
   159 
       
   160 void CLayoutSession::SetLayout(CLayoutLibrary* aLayoutLibrary)
       
   161     {
       
   162     TRACE_INFO( (_L("[HID]\tCLayoutSession::SetLayout(0x%08x)\n"),
       
   163                  aLayoutLibrary));
       
   164     TRACE_INFO( (_L("[HID]\t  Layout ID is %d (0x%x)\n"),
       
   165                  aLayoutLibrary->Id()));
       
   166 
       
   167     iLayoutLibrary = aLayoutLibrary;
       
   168     iDecoder->SetLayout(iLayoutLibrary->Layout());
       
   169     }
       
   170 
       
   171 // ----------------------------------------------------------------------
       
   172 
       
   173 CLayoutServer* CLayoutSession::Server()
       
   174     {
       
   175     return const_cast<CLayoutServer*>(static_cast<const CLayoutServer*>
       
   176                                       (CSession2::Server()));
       
   177     }
       
   178 
       
   179 // ----------------------------------------------------------------------