mmserv/sts/stsserver/src/stsserver.cpp
changeset 14 80975da52420
child 16 43d09473c595
equal deleted inserted replaced
12:5a06f39ad45b 14:80975da52420
       
     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 "stsserver.h"
       
    22 
       
    23 #include <ecom/ecom.h>
       
    24 #include "stsserversession.h"
       
    25 #include "sts.h"
       
    26 
       
    27 // TODO: IMPLEMENT PLATFORM SECURITY CHECKS ON THIS API.
       
    28 
       
    29 // Total number of ranges
       
    30 const TUint KStsRangeCount = 2;
       
    31 
       
    32 // Definition of the ranges of IPC numbers
       
    33 const TInt KStsRanges[KStsRangeCount] =
       
    34     {
       
    35     0, KStsCmdLast + 1
       
    36     };
       
    37 
       
    38 // Policy to implement for each of the above ranges        
       
    39 const TUint8 KStsElementsIndex[KStsRangeCount] =
       
    40     {
       
    41     CPolicyServer::EAlwaysPass, CPolicyServer::ENotSupported
       
    42     };
       
    43 
       
    44 // Package all the above together into a policy
       
    45 const CPolicyServer::TPolicy KStsPolicy =
       
    46     {
       
    47     CPolicyServer::EAlwaysPass, // specifies all connect attempts should pass
       
    48             KStsRangeCount, // number of ranges                                   
       
    49             KStsRanges, // ranges array
       
    50             KStsElementsIndex, // elements<->ranges index
       
    51             NULL
       
    52     };
       
    53 
       
    54 // CStsServer IMPLEMENTATION
       
    55 
       
    56 CStsServer* CStsServer::NewLC()
       
    57     {
       
    58     CStsServer* self = new (ELeave) CStsServer();
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61     return self;
       
    62     }
       
    63 
       
    64 CStsServer::CStsServer() :
       
    65     CPolicyServer(0, KStsPolicy, ESharableSessions), iSts(0)
       
    66     {
       
    67     }
       
    68 
       
    69 void CStsServer::ConstructL()
       
    70     {
       
    71     StartL(KStsServerName);
       
    72     iSts = CSts::Create();
       
    73     if (iSts == 0)
       
    74         {
       
    75         User::Leave(KErrNoMemory);
       
    76         }
       
    77     }
       
    78 
       
    79 CStsServer::~CStsServer()
       
    80     {
       
    81     iSessions.ResetAndDestroy();
       
    82     CSts::Delete(iSts);
       
    83     REComSession::FinalClose();
       
    84     }
       
    85 
       
    86 CSession2* CStsServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
       
    87     {
       
    88     if (aVersion.iMajor != KStsServerMajorVersion || aVersion.iMinor
       
    89             != KStsServerMinorVersion || aVersion.iBuild != KStsServerBuild)
       
    90         {
       
    91         User::Leave(KErrNotSupported);
       
    92         } // end if
       
    93 
       
    94     CStsServer& nonConstThis = *const_cast<CStsServer*> (this);
       
    95 
       
    96     // Construct a new session, passing it a pointer to the server object.  This function
       
    97     // is const, so the const-ness must be cast away from the this pointer.
       
    98     CSession2* returnValue = new (ELeave) CStsServerSession(nonConstThis, *iSts);
       
    99 
       
   100     return returnValue;
       
   101     }
       
   102 
       
   103 void CStsServer::AddSession(CStsServerSession* aSession)
       
   104     {
       
   105     iSessions.Append(aSession);
       
   106     }
       
   107 
       
   108 void CStsServer::DropSession(CStsServerSession* aSession)
       
   109     {
       
   110     // Find the current session in the list of sessions.
       
   111     TInt index = iSessions.Find(aSession);
       
   112 
       
   113     if (index != KErrNotFound)
       
   114         {
       
   115         // Remove the session from the list of sessions.
       
   116         iSessions.Remove(index);
       
   117         } // end if
       
   118 
       
   119     if (iSessions.Count() == 0)
       
   120         {
       
   121         // No more clients. Shutdown the server.
       
   122         CActiveScheduler::Stop();
       
   123         }
       
   124     }
       
   125 
       
   126 // SERVER LAUNCHING FUNCTIONALITY
       
   127 
       
   128 EXPORT_C void CStsServer::RunServerL(bool aPerformProcessRendezvous,
       
   129         bool aPerformThreadRendezvous)
       
   130     {
       
   131     // naming the server thread after the server helps to debug panics
       
   132     User::LeaveIfError(User::RenameThread(KStsServerName));
       
   133 
       
   134     // create and install the active scheduler
       
   135     CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
       
   136     CleanupStack::PushL(scheduler);
       
   137     CActiveScheduler::Install(scheduler);
       
   138 
       
   139     // create the server (leave it on the cleanup stack)
       
   140     CStsServer* server = CStsServer::NewLC();
       
   141 
       
   142     // Initialisation complete, now signal the client, if requested.
       
   143 
       
   144     if (aPerformProcessRendezvous)
       
   145         {
       
   146         RProcess::Rendezvous(KErrNone);
       
   147         }
       
   148 
       
   149     if (aPerformThreadRendezvous)
       
   150         {
       
   151         RThread::Rendezvous(KErrNone);
       
   152         }
       
   153 
       
   154     // Ready to run
       
   155     // Start wait loop, will return when server is shutdown
       
   156     CActiveScheduler::Start();
       
   157 
       
   158     // Cleanup the server
       
   159     CleanupStack::PopAndDestroy(server);
       
   160 
       
   161     // Cleanup scheduler after shutdown
       
   162     CleanupStack::PopAndDestroy(scheduler);
       
   163     }