utilities/serviceipcserver/sessionidtable.cpp
changeset 16 3c88a81ff781
equal deleted inserted replaced
14:6aeb7a756187 16:3c88a81ff781
       
     1 /**
       
     2    This file is part of CWRT package **
       
     3 
       
     4    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). **
       
     5 
       
     6    This program is free software: you can redistribute it and/or modify
       
     7    it under the terms of the GNU (Lesser) General Public License as
       
     8    published by the Free Software Foundation, version 2.1 of the License.
       
     9    This program is distributed in the hope that it will be useful, but
       
    10    WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
       
    12    (Lesser) General Public License for more details. You should have
       
    13    received a copy of the GNU (Lesser) General Public License along
       
    14    with this program. If not, see <http://www.gnu.org/licenses/>.
       
    15 */
       
    16 
       
    17 
       
    18 #include "sessionidtable.h"
       
    19 #include <QDebug>
       
    20 
       
    21 /*!
       
    22  \class SessionIdTable
       
    23  Assign unique session id for each client session
       
    24  */
       
    25  
       
    26 namespace WRT
       
    27 {
       
    28 const int KSessionIdNotDefined = -1;
       
    29 /*!
       
    30  Default constructor
       
    31  */
       
    32 SessionIdTable::SessionIdTable()
       
    33 {
       
    34     for ( int i = 0; i < SessionIdTableSize; i++ ) {
       
    35         m_data[i]  = false;
       
    36     }
       
    37 }
       
    38 
       
    39 /*!
       
    40  Reserve a session id.
       
    41  @return int unique session id.
       
    42  */
       
    43 int SessionIdTable::allocate()
       
    44 {
       
    45     int sessionId = KSessionIdNotDefined;
       
    46 
       
    47     // Search the table for free index
       
    48     for ( int i = 0; i < SessionIdTableSize; ++i ) {
       
    49         if ( !m_data[i] ) {
       
    50             m_data[i]  = true;
       
    51             sessionId = i;
       
    52             break;
       
    53         }
       
    54     }
       
    55 
       
    56     if( sessionId == KSessionIdNotDefined ){
       
    57         //all session id being used??
       
    58     }
       
    59 
       
    60     return sessionId;
       
    61 }
       
    62 
       
    63 /*!
       
    64  Release a session id.
       
    65  @param aSessionId session id.
       
    66  */ 
       
    67 void SessionIdTable::release( int aSessionId ) {
       
    68     if( !m_data[aSessionId] ) {
       
    69         qDebug() << "release sessionid " << aSessionId; 
       
    70     } 
       
    71     m_data[aSessionId] = false;
       
    72 }
       
    73 }
       
    74 
       
    75 // End of file