bluetoothengine/bthid/bthidserver/src/bthiddevice.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 "bthiddevice.h"
       
    20 #include "hiddescriptorlist.h"
       
    21 
       
    22 // A version number for this object when externalised.
       
    23 // Only for future proofing.
       
    24 const TInt KVersionNumber = 1;
       
    25 
       
    26 CBTHidDevice* CBTHidDevice::NewL()
       
    27     {
       
    28     CBTHidDevice* self = NewLC();
       
    29     CleanupStack::Pop(self);
       
    30     return self;
       
    31     }
       
    32 
       
    33 CBTHidDevice* CBTHidDevice::NewLC()
       
    34     {
       
    35     CBTHidDevice* self = new (ELeave) CBTHidDevice();
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     return self;
       
    39     }
       
    40 
       
    41 CBTHidDevice::CBTHidDevice()
       
    42     {
       
    43     }
       
    44 
       
    45 CBTHidDevice::~CBTHidDevice()
       
    46     {
       
    47     delete iDescList;
       
    48     }
       
    49 
       
    50 TInt CBTHidDevice::DiskSize() const
       
    51     {
       
    52     // Always using 10 bytes as an estimate for Series 60 Descriptor headers
       
    53 
       
    54     //4 for KVersionNumber
       
    55     //6 + 10 for the iAddress
       
    56     //4 for iDeviceReleaseNumber
       
    57     //4 for iDeviceSubClass
       
    58     //4 for iCountryCode
       
    59     //1 for iVirtuallyCabled
       
    60     //1 for iReconnectInit
       
    61     //1 for iNormallyConnectable
       
    62     //4 for iProfileVersion
       
    63     //4 for iVendorID
       
    64     //4 for iProductID
       
    65     //1 for iUseSecurity
       
    66     //256 + 10 for iDeviceName
       
    67     //4 for iDeviceClass
       
    68     TInt size = 318;
       
    69 
       
    70     // Now add the size required for the descriptor list
       
    71     size += iDescList->DiskSize();
       
    72 
       
    73     return size;
       
    74     }
       
    75 
       
    76 void CBTHidDevice::ExternalizeL(RWriteStream& aStream) const
       
    77     {
       
    78     // NOTE!! When changing this function, also check DiskSize
       
    79 
       
    80     // Write the version number
       
    81     aStream.WriteInt32L(KVersionNumber);
       
    82 
       
    83     // Write all member variables to the stream.
       
    84     // Leave if we get any error
       
    85     aStream.WriteL(iAddress.Des());
       
    86     aStream.WriteUint32L(iDeviceReleaseNumber);
       
    87     aStream.WriteUint32L(iDeviceSubClass);
       
    88     aStream.WriteUint32L(iCountryCode);
       
    89     aStream.WriteInt8L(iVirtuallyCabled ? 1 : 0);
       
    90     aStream.WriteInt8L(iReconnectInit ? 1 : 0);
       
    91     aStream.WriteInt8L(iNormallyConnectable ? 1 : 0);
       
    92     aStream.WriteUint32L(iProfileVersion);
       
    93     aStream.WriteUint32L(iVendorID);
       
    94     aStream.WriteUint32L(iProductID);
       
    95     aStream.WriteInt8L(iUseSecurity ? 1 : 0);
       
    96     aStream << iDeviceName;
       
    97     aStream << iDeviceClass;
       
    98     aStream << *iDescList;
       
    99     }
       
   100 
       
   101 void CBTHidDevice::InternalizeL(RReadStream& aStream)
       
   102     {
       
   103     // Read the version number
       
   104     // Ignored in this version.
       
   105     aStream.ReadInt32L();
       
   106 
       
   107     // Read all member variables from the stream
       
   108     // Leave if we get any error
       
   109 
       
   110     // Get a pointer to the address to fill
       
   111     TPtr8 addr = iAddress.Des();
       
   112     // Read the address in
       
   113     aStream.ReadL(addr);
       
   114 
       
   115     iDeviceReleaseNumber = aStream.ReadUint32L();
       
   116     iDeviceSubClass = aStream.ReadUint32L();
       
   117     iCountryCode = aStream.ReadUint32L();
       
   118     iVirtuallyCabled = aStream.ReadInt8L();
       
   119     iReconnectInit = aStream.ReadInt8L();
       
   120     iNormallyConnectable = aStream.ReadInt8L();
       
   121     iProfileVersion = aStream.ReadUint32L();
       
   122     iVendorID = aStream.ReadUint32L();
       
   123     iProductID = aStream.ReadUint32L();
       
   124     iUseSecurity = aStream.ReadInt8L();
       
   125     aStream >> iDeviceName;
       
   126     aStream >> iDeviceClass;
       
   127     aStream >> *iDescList;
       
   128     }
       
   129 
       
   130 void CBTHidDevice::ConstructL()
       
   131     {
       
   132     iDescList = new (ELeave) CHidDescriptorList;
       
   133     }
       
   134 
       
   135 // End of File