mmserv/sts/stsserver/src/stsserver.cpp
branchRCL_3
changeset 20 0ac9a5310753
parent 19 095bea5f582e
child 21 999b2818a0eb
equal deleted inserted replaced
19:095bea5f582e 20:0ac9a5310753
     1 /*
       
     2  * Copyright (c) 2010 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:
       
    15  * This file is the implementation of the Symbian STS Server.  This
       
    16  * file handles the Symbian specific server creation/deletation
       
    17  * activities, and adding/removing sessions.  The actual STS
       
    18  * functionality is handled in the STS class.
       
    19  */
       
    20 
       
    21 //  Include Files  
       
    22 #include "stsserver.h"
       
    23 #include "stsserversession.h"
       
    24 #include "sts.h"
       
    25 
       
    26 // Total number of ranges
       
    27 const TUint KStsRangeCount = 3;
       
    28 
       
    29 // Definition of the ranges of IPC numbers
       
    30 const TInt KStsRanges[KStsRangeCount] =
       
    31     {
       
    32     0, 2, KStsCmdLast + 1
       
    33     };
       
    34 
       
    35 // Policy to implement for each of the above ranges        
       
    36 const TUint8 KStsElementsIndex[KStsRangeCount] =
       
    37     {
       
    38             CPolicyServer::EAlwaysPass,
       
    39             CPolicyServer::ECustomCheck,
       
    40             CPolicyServer::ENotSupported
       
    41     };
       
    42 
       
    43 // Package all the above together into a policy
       
    44 const CPolicyServer::TPolicy KStsPolicy =
       
    45     {
       
    46     CPolicyServer::EAlwaysPass, // specifies all connect attempts should pass
       
    47             KStsRangeCount, // number of ranges                                   
       
    48             KStsRanges, // ranges array
       
    49             KStsElementsIndex, // elements<->ranges index
       
    50             NULL
       
    51     };
       
    52 
       
    53 // CStsServer IMPLEMENTATION
       
    54 
       
    55 CStsServer* CStsServer::NewLC()
       
    56     {
       
    57     CStsServer* self = new (ELeave) CStsServer();
       
    58     CleanupStack::PushL(self);
       
    59     self->ConstructL();
       
    60     return self;
       
    61     }
       
    62 
       
    63 CStsServer::CStsServer() :
       
    64     CPolicyServer(0, KStsPolicy, ESharableSessions), iSts(0)
       
    65     {
       
    66     }
       
    67 
       
    68 void CStsServer::ConstructL()
       
    69     {
       
    70     StartL(KStsServerName);
       
    71     iSts = CSts::Create();
       
    72     if (iSts == 0)
       
    73         {
       
    74         User::Leave(KErrNoMemory);
       
    75         }
       
    76     }
       
    77 
       
    78 CStsServer::~CStsServer()
       
    79     {
       
    80     iSessions.ResetAndDestroy();
       
    81     CSts::Delete(iSts);
       
    82     }
       
    83 
       
    84 // Performs security checks based on the tone or Alarm type.
       
    85 CPolicyServer::TCustomResult CStsServer::CustomSecurityCheckL(
       
    86         const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& aMissing)
       
    87     {
       
    88     CPolicyServer::TCustomResult result;
       
    89 
       
    90     switch (aMsg.Function())
       
    91         {
       
    92         case StsMsg_PlayTone:
       
    93         case StsMsg_PlayToneAlarm:
       
    94             {
       
    95             CSystemToneService::TToneType tone =
       
    96                     (CSystemToneService::TToneType) aMsg.Int0();
       
    97             result = SecurityCheckTone(tone, aMsg, aMissing);
       
    98             }
       
    99             break;
       
   100         case StsMsg_PlayAlarm:
       
   101             {
       
   102             CSystemToneService::TAlarmType alarm =
       
   103                     (CSystemToneService::TAlarmType) aMsg.Int0();
       
   104             result = SecurityCheckAlarm(alarm, aMsg, aMissing);
       
   105             }
       
   106             break;
       
   107         default:
       
   108             result = CPolicyServer::EFail;
       
   109         }
       
   110 
       
   111     return result;
       
   112     }
       
   113 
       
   114 CPolicyServer::TCustomResult CStsServer::SecurityCheckAlarm(
       
   115         CSystemToneService::TAlarmType aAlarm, const RMessage2& /*aMsg*/,
       
   116         TSecurityInfo& /*aMissing*/)
       
   117     {
       
   118     CPolicyServer::TCustomResult result;
       
   119     switch (aAlarm)
       
   120         {
       
   121         default:
       
   122             result = CPolicyServer::EPass;
       
   123         }
       
   124     return result;
       
   125     }
       
   126 
       
   127 CPolicyServer::TCustomResult CStsServer::SecurityCheckTone(
       
   128         CSystemToneService::TToneType aTone, const RMessage2& /*aMsg*/,
       
   129         TSecurityInfo& /*aMissing*/)
       
   130     {
       
   131     CPolicyServer::TCustomResult result;
       
   132     switch (aTone)
       
   133         {
       
   134         default:
       
   135             result = CPolicyServer::EPass;
       
   136         }
       
   137     return result;
       
   138     }
       
   139 
       
   140 CSession2* CStsServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
       
   141     {
       
   142     if (aVersion.iMajor != KStsServerMajorVersion || aVersion.iMinor
       
   143             != KStsServerMinorVersion || aVersion.iBuild != KStsServerBuild)
       
   144         {
       
   145         User::Leave(KErrNotSupported);
       
   146         }
       
   147     else
       
   148         {
       
   149         //TODO: Add trace here
       
   150         }// end if
       
   151 
       
   152     CStsServer& nonConstThis = *const_cast<CStsServer*> (this);
       
   153 
       
   154     // Construct a new session, passing it a pointer to the server object.  This function
       
   155     // is const, so the const-ness must be cast away from the this pointer.
       
   156     CSession2* returnValue = new (ELeave) CStsServerSession(nonConstThis,
       
   157             *iSts);
       
   158 
       
   159     return returnValue;
       
   160     }
       
   161 
       
   162 void CStsServer::AddSession(CStsServerSession* aSession)
       
   163     {
       
   164     iSessions.Append(aSession);
       
   165     }
       
   166 
       
   167 void CStsServer::DropSession(CStsServerSession* aSession)
       
   168     {
       
   169     // Find the current session in the list of sessions.
       
   170     TInt index = iSessions.Find(aSession);
       
   171 
       
   172     if (index != KErrNotFound)
       
   173         {
       
   174         // Remove the session from the list of sessions.
       
   175         iSessions.Remove(index);
       
   176         }
       
   177     else
       
   178         {
       
   179         //TODO: Add trace here
       
   180         } // end if
       
   181 
       
   182     if (iSessions.Count() == 0)
       
   183         {
       
   184         // No more clients. Shutdown the server.
       
   185         CActiveScheduler::Stop();
       
   186         }
       
   187     }
       
   188 
       
   189 // SERVER LAUNCHING FUNCTIONALITY
       
   190 
       
   191 EXPORT_C void CStsServer::RunServerL()
       
   192     {
       
   193     // naming the server thread after the server helps to debug panics
       
   194     User::LeaveIfError(User::RenameThread(KStsServerName));
       
   195 
       
   196     // create and install the active scheduler
       
   197     CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
       
   198     CleanupStack::PushL(scheduler);
       
   199     CActiveScheduler::Install(scheduler);
       
   200 
       
   201     // create the server (leave it on the cleanup stack)
       
   202     CStsServer* server = CStsServer::NewLC();
       
   203 
       
   204     // Initialisation complete, now signal the client.
       
   205     RProcess::Rendezvous(KErrNone);
       
   206 
       
   207     // Ready to run
       
   208     // Start wait loop, will return when server is shutdown
       
   209     CActiveScheduler::Start();
       
   210 
       
   211     // Cleanup the server
       
   212     CleanupStack::PopAndDestroy(server);
       
   213 
       
   214     // Cleanup scheduler after shutdown
       
   215     CleanupStack::PopAndDestroy(scheduler);
       
   216     }