Creating and Deleting a Session: Tutorial

This tutorial shows you how to create and delete a session with the Comms Database.

Context

You create a session with the Comms Database before you start to read and write the data. You can also set the access attributes for the session.

Prerequisites

Before you start, you must understand:

  • the general concept of the Comms Database

  • the specific concept of Comms Database Sessions

  • how to write and build application code to run on Symbian platform

Steps

  1. Include the header files, define namespaces, and declare constants.

    TheCommsDatTypesV1_1.h header file defines the classes and API items that the tool or application requires. This header file includes all other required header files. Define the CommsDat namesapce. Define a [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]TVersion set with the version information. The location of this code depends on the structure of the tool or application.
    #include <CommsDatTypesV1_1.h> 
    
    // Add a declaration like this for each specific version you need.
    // In this example, the major version number, the minor version number
    // and the build number are all 1.
    #define KCDVersion1_1 TVersion(1,1,1) 
    
    using namespace CommsDat;
    
    ...
  2. Create the session.

    You select the version of the interface when you create the session.
    ...
    // for the version 1.1.1 defined in step 1
    CMDBSession* iDb = CMDBSession::NewL(KCDVersion1_1); 
    ...
  3. Set the access attributes for the session.

    This is an optional step. The following code allows the tool or application to see the elements that are marked as hidden in the Comms Database. The ECHidden symbol is an enum value of the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]TCDAttributeFlags enum. You can also set the other access attributes, but the hidden attribute is the most common use case.
    ...
    iDb->SetAttributeMask(ECDHidden); 
    ...
  4. Delete the session object after the tool or application has finished its use of the Comms Database

    ...
    delete iDb;

Related concepts