serviceproviders/sapi_sysinfo/sysinfoservice/src/activestore.cpp
changeset 5 989d2f495d90
child 43 1790c2f1027c
equal deleted inserted replaced
1:a36b1e19a461 5:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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:  class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "activerequests.h"
       
    19 #include "entitykeys.h"
       
    20 #include "sysnetworkrequest.h"
       
    21 #include "sysaccessoryrequest.h"
       
    22 #include "sysconnectionrequest.h"
       
    23 #include "sysuseractivity.h"
       
    24 #include "sysrequest.h"
       
    25 
       
    26 using namespace SysInfo;
       
    27 
       
    28 const TInt KGranularity(2);
       
    29 
       
    30 RPointerArray<CActiveRequest> ActiveStore::iHandlers(KGranularity);
       
    31 
       
    32 // --------------------------------------------------------------------
       
    33 // CActiveRequest::CActiveRequest()
       
    34 // C++ default constructor.
       
    35 // --------------------------------------------------------------------
       
    36 //
       
    37 CActiveRequest::CActiveRequest(TSysRequest::TRequestType aReqType, 
       
    38                                 TInt32 aTransID,
       
    39                                 ISystemObserver* aObsrvr)
       
    40                                 :CActive(EPriorityNormal),
       
    41                                 iTransactionID(aTransID),
       
    42                                 iRequestType(aReqType),
       
    43                                 iObserver(aObsrvr)
       
    44 								 
       
    45     {
       
    46     CActiveScheduler::Add(this);
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------
       
    50 // CActiveRequest::~CActiveRequest()
       
    51 // destructor
       
    52 // --------------------------------------------------------------------
       
    53 //
       
    54 CActiveRequest::~CActiveRequest()
       
    55     {
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------
       
    59 // CActiveRequest::CreateActiveRequestL()
       
    60 // static factory method to create asynchronous requests.
       
    61 // --------------------------------------------------------------------
       
    62 //
       
    63 void CActiveRequest::CreateActiveRequestL(const TSysRequest& aSysRequest,
       
    64                                             CActiveRequest*& aActiveObj)
       
    65     {
       
    66     const TPtrC Entity = aSysRequest.Entity();
       
    67     const TPtrC Key =	aSysRequest.Key();
       
    68 
       
    69     aActiveObj = NULL;
       
    70 
       
    71     if ( !Entity.CompareF(KNetwork) )
       
    72         CreateNetworkRequestL(aSysRequest,aActiveObj);
       
    73 
       
    74     else if( !Entity.CompareF(KGeneral) )
       
    75         CreateGeneralRequestL(aSysRequest,aActiveObj);
       
    76 
       
    77     else if( !Entity.CompareF(KBattery) )
       
    78         {
       
    79         // Battery Entity Keys.
       
    80         if( !Key.CompareF(KChargingStatus) )
       
    81             aActiveObj = CPubSubNotifier::NewL(aSysRequest,
       
    82                                             CPubSubNotifier::EChargingStatus);
       
    83 
       
    84         else if( !Key.CompareF(KBatteryStrength) )
       
    85             aActiveObj = CNetwork::NewL(aSysRequest,
       
    86                                                 CNetwork::EBatteryStrength);
       
    87 
       
    88         else
       
    89             User::Leave(KErrNotFound);
       
    90         }
       
    91 
       
    92     else if( !Entity.CompareF(KConnectivity) )
       
    93         {
       
    94         // Connectivity Entity Keys.
       
    95         if( !Key.CompareF(KBlueTooth))
       
    96             aActiveObj = CCenrepNotifier::NewL(aSysRequest,
       
    97                                                 CCenrepNotifier::EBlueTooth);
       
    98 
       
    99         else if( !Key.CompareF(KInfraRed) )
       
   100             aActiveObj = CPubSubNotifier::NewL(aSysRequest,
       
   101                                                 CPubSubNotifier::EInfraRed);
       
   102 
       
   103         else if( (!Key.CompareF(SysInfo::KConnectionStatus)) 
       
   104                         || (!Key.CompareF(SysInfo::KActiveConnections)))
       
   105             aActiveObj = CConnection::NewL(aSysRequest);
       
   106 
       
   107         else
       
   108             User::Leave(KErrNotFound);
       
   109         }
       
   110     else if( !Entity.CompareF(KDisplay))
       
   111         {
       
   112         // Display keys.
       
   113         if ( !Key.CompareF(KUserInactivity) )
       
   114             aActiveObj = CUserActivity::NewL(aSysRequest);
       
   115 
       
   116         else if( !Key.CompareF(KAutoLockStatus) )
       
   117             aActiveObj = CCenrepNotifier::NewL(aSysRequest,
       
   118                                                 CCenrepNotifier::EKeyLock);
       
   119 
       
   120         else
       
   121             User::Leave(KErrNotFound);
       
   122         }
       
   123     else if( !Entity.CompareF(KMemory))
       
   124         {
       
   125         if ( !Key.CompareF(KCriticalMemory) )
       
   126             aActiveObj = CCriticalMemNotifier::NewL(aSysRequest);
       
   127 
       
   128         else if( !Key.CompareF(KMemoryCard) )
       
   129             aActiveObj = CPubSubNotifier::NewL(aSysRequest,
       
   130                                             CPubSubNotifier::EMemoryCard);
       
   131 
       
   132         else
       
   133             User::Leave(KErrNotFound);
       
   134         }
       
   135     //Ensure we don't return NULL handle.
       
   136     if(!aActiveObj)
       
   137         User::Leave(KErrNotFound);
       
   138     }
       
   139 
       
   140 // --------------------------------------------------------------------
       
   141 // CActiveRequest::CreateActiveRequestL()
       
   142 // creates active objs related to Network entity.
       
   143 // --------------------------------------------------------------------
       
   144 //
       
   145 void CActiveRequest::CreateNetworkRequestL(const TSysRequest& aSysRequest,
       
   146                                             CActiveRequest*& aActiveObj)
       
   147     {
       
   148     TPtrC Key = aSysRequest.Key();
       
   149     // parse network entity keys.
       
   150     if ( !Key.CompareF(SysInfo::KSignalStrength) )
       
   151         aActiveObj = CNetwork::NewL(aSysRequest,CNetwork::ESignalStrength);
       
   152 
       
   153     else if ( !Key.CompareF(KRegistrationStatus) )
       
   154         aActiveObj = CPubSubNotifier::NewL(aSysRequest,
       
   155                                     CPubSubNotifier::ERegistrationStatus);
       
   156 
       
   157     else if ( !Key.CompareF(SysInfo::KNetworkMode) )
       
   158         aActiveObj = CPubSubNotifier::NewL(aSysRequest,
       
   159                                             CPubSubNotifier::ENetworkMode);
       
   160 
       
   161     else if ( !Key.CompareF(KHomeNetwork) )
       
   162         aActiveObj = CNetwork::NewL(aSysRequest,CNetwork::EHomeNetworkInfo);
       
   163 
       
   164     else if ( !Key.CompareF(KCurrentNetwork) )
       
   165         aActiveObj = CNetwork::NewL(aSysRequest,CNetwork::ECurrentNetworkInfo);
       
   166 
       
   167     else if ( !Key.CompareF(KLocationArea) )
       
   168         aActiveObj = CNetwork::NewL(aSysRequest,CNetwork::ELocationAreaCode);
       
   169 
       
   170     else if ( !Key.CompareF(KCellID) )
       
   171         aActiveObj = CNetwork::NewL(aSysRequest,CNetwork::ECellId);
       
   172 
       
   173     else
       
   174         User::Leave(KErrNotFound);
       
   175     }
       
   176 
       
   177 // --------------------------------------------------------------------
       
   178 // CActiveRequest::CreateGeneralRequestL()
       
   179 // creates active objs related general entity.
       
   180 // --------------------------------------------------------------------
       
   181 //
       
   182 void CActiveRequest::CreateGeneralRequestL(const TSysRequest& aSysRequest,
       
   183                                                 CActiveRequest*& aActiveObj)
       
   184     {
       
   185     TPtrC Key = aSysRequest.Key();
       
   186     //parse general entity keys.
       
   187     if ( !Key.CompareF(KAccessoryStatus) )
       
   188         aActiveObj = CAccessory::NewL(aSysRequest);
       
   189 
       
   190     else if( !Key.CompareF(KInputLanguage) )
       
   191         aActiveObj = CCenrepNotifier::NewL(aSysRequest,
       
   192                                             CCenrepNotifier::EInputLanguage);
       
   193 
       
   194     else if( !Key.CompareF(KPridictiveText) )
       
   195         aActiveObj = CCenrepNotifier::NewL(aSysRequest,
       
   196                                             CCenrepNotifier::EPridictiveText);
       
   197 
       
   198     else if( !Key.CompareF(KVibraActive) )
       
   199         aActiveObj = CCenrepNotifier::NewL(aSysRequest,CCenrepNotifier::EVibra);
       
   200 
       
   201     else if( !Key.CompareF(KFlipStatus) )
       
   202         aActiveObj = CPubSubNotifier::NewL(aSysRequest,
       
   203                                                 CPubSubNotifier::EFlipStatus);
       
   204 
       
   205     else if( !Key.CompareF(KGripStatus) )
       
   206         aActiveObj = CPubSubNotifier::NewL(aSysRequest,
       
   207                                                 CPubSubNotifier::EGripStatus);
       
   208 
       
   209     else
       
   210         User::Leave(KErrNotFound);
       
   211     }
       
   212 
       
   213 // --------------------------------------------------------------------
       
   214 // ActiveStore::AddRequestL()
       
   215 // appends an active request to the active obj store.
       
   216 // --------------------------------------------------------------------
       
   217 //
       
   218 void ActiveStore::AddRequestL(const CActiveRequest* aActiveReq )
       
   219     {
       
   220     TInt ActiveReqCnt = iHandlers.Count();
       
   221     // add active obj to store only if this transaction id 
       
   222     // doesn't exists before.
       
   223 	for(TInt i=0; i<ActiveReqCnt; i++)
       
   224         {
       
   225         if(iHandlers[i]->TransactionID() == aActiveReq->TransactionID())
       
   226             User::Leave(KErrAlreadyExists);
       
   227         }
       
   228     //append the request.
       
   229     iHandlers.AppendL(aActiveReq);
       
   230     }
       
   231 
       
   232 // --------------------------------------------------------------------
       
   233 // ActiveStore::RemoveRequest()
       
   234 // removes an active request from active obj store or performs cancel
       
   235 // operation on the active object.
       
   236 // --------------------------------------------------------------------
       
   237 //
       
   238 TInt ActiveStore::RemoveRequest(TInt32 aTransID)
       
   239     {
       
   240     TInt ActiveReqCnt = iHandlers.Count();
       
   241     for(TInt i=0; i<ActiveReqCnt; i++)
       
   242         {
       
   243         // Identify object associated with this transaction ID.
       
   244         if(iHandlers[i]->TransactionID() == aTransID)
       
   245             {
       
   246             CActiveRequest* ActiveObject = iHandlers[i];
       
   247             //delete active request. 
       
   248             delete ActiveObject;
       
   249             //Removes this request from RPointerArray.
       
   250             iHandlers.Remove(i);
       
   251             return KErrNone;
       
   252             }
       
   253         }
       
   254     //specified transaction id doesn't exists in store.
       
   255     return KErrNotFound;
       
   256     }
       
   257 
       
   258 // --------------------------------------------------------------------
       
   259 // ActiveStore::ReleaseResourcesL()
       
   260 // removes all active requests in active obj store and release all
       
   261 // memory associated with this static class.
       
   262 // --------------------------------------------------------------------
       
   263 //
       
   264 void ActiveStore::ReleaseResources()
       
   265     {
       
   266     TInt count = iHandlers.Count();
       
   267 
       
   268     if(count>0)
       
   269         {
       
   270         for(TInt i=0; i<count; i++)
       
   271             {
       
   272             CActiveRequest* activeObject = iHandlers[i];
       
   273             //delete active request.
       
   274             delete activeObject;
       
   275             }
       
   276         //de-allocate all the pointer memory allocated.
       
   277         iHandlers.Reset();
       
   278         }
       
   279     //Close the pointer array to free all the memory allocated to it.
       
   280     iHandlers.Close();
       
   281     }