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