utilities/serviceipcserver/platform/s60/serviceipcserversymbianserver.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 "serviceipcserversymbianserver_p.h"
       
    19 #include "serviceipcserversymbiansession.h"
       
    20 #include <clientinfo.h>
       
    21 
       
    22 namespace WRT
       
    23 {
       
    24 // Server Security Policy
       
    25 const TUint KServerRangeCount = 2;
       
    26 const TInt KServerRanges[KServerRangeCount] = { 
       
    27                 0, //range is [0-1)
       
    28                 2 //range is [2-KMaxTInt] 
       
    29                 };
       
    30 const TUint8 KSeverElementsIndex[KServerRangeCount] = { 
       
    31                 0,
       
    32                 CPolicyServer::ENotSupported };
       
    33 
       
    34 const CPolicyServer::TPolicyElement KServerPolicyElements[] = { {
       
    35                 _INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData),
       
    36                 CPolicyServer::EFailClient } };
       
    37 
       
    38 const CPolicyServer::TPolicy KServerPolicy = {
       
    39                 CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
       
    40                 KServerRangeCount, KServerRanges, KSeverElementsIndex,
       
    41                 KServerPolicyElements };
       
    42 
       
    43 enum
       
    44 {
       
    45     EServerPriority = CActive::EPriorityStandard
       
    46 };
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 /*!
       
    51  \class CServiceSymbianServer
       
    52  Symbian client server implementation
       
    53  */
       
    54 
       
    55 /*!
       
    56  Constructor
       
    57  */
       
    58 CServiceSymbianServer::CServiceSymbianServer() :
       
    59     CPolicyServer(EServerPriority, KServerPolicy), m_keepServer(false)
       
    60 {
       
    61     m_sessionIdTable = new SessionIdTable();
       
    62 }
       
    63 
       
    64 /*!
       
    65  2nd phased constructor
       
    66  */
       
    67 void CServiceSymbianServer::ConstructL()
       
    68 {
       
    69 }
       
    70 
       
    71 /*!
       
    72  Two phased constructor
       
    73  */
       
    74 CServiceSymbianServer* CServiceSymbianServer::NewL()
       
    75 {
       
    76     CServiceSymbianServer* self = new (ELeave) CServiceSymbianServer;
       
    77     CleanupStack::PushL(self);
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop(self);
       
    80     return self;
       
    81 }
       
    82 
       
    83 /*!
       
    84  Destructor
       
    85  */
       
    86 CServiceSymbianServer::~CServiceSymbianServer()
       
    87 {
       
    88     delete m_sessionIdTable;
       
    89 }
       
    90 
       
    91 
       
    92 /*!
       
    93  A new session is being created \n
       
    94  Cancel the shutdown timer if it was running
       
    95 */
       
    96 void CServiceSymbianServer::addSession()
       
    97 
       
    98 {
       
    99     ++m_sessionCount;
       
   100     stopExitTimer();
       
   101 }
       
   102 
       
   103 /*!
       
   104  A session is being destroyed \n
       
   105  Start the shutdown timer if it is the last session.
       
   106 */
       
   107 void CServiceSymbianServer::closeSession()
       
   108 {
       
   109     if ((--m_sessionCount==0) && (!m_keepServer))
       
   110     {
       
   111         startExitTimer();
       
   112     }
       
   113 }
       
   114 
       
   115 /*!
       
   116  Start listening for new service requests
       
   117  @param aServerName name of the server
       
   118  */
       
   119 bool CServiceSymbianServer::listen(const QString& aServerName)
       
   120 {
       
   121     bool listening(true);
       
   122 
       
   123     // Needs to be here because Q_Ptr isonly set after constructor of public
       
   124     m_observer = Observer();
       
   125     TPtrC serverName(reinterpret_cast<const TUint16*> (aServerName.utf16()));
       
   126     TRAPD( err, StartL(serverName) );
       
   127     if (err != KErrNone) {
       
   128         listening = false;
       
   129     }
       
   130     // Complete the server rendezvous that th client started
       
   131     RProcess::Rendezvous(KErrNone);
       
   132     return listening;
       
   133 }
       
   134 
       
   135 /*!
       
   136  Shutdown the server and stop serving clients 
       
   137  */
       
   138 void CServiceSymbianServer::disconnect()
       
   139 {
       
   140     // Symbian Servers do not have disconnect, 
       
   141     // the process has to exit
       
   142 }
       
   143 
       
   144 /*!
       
   145  A session is being destroyed \n
       
   146  Start the shutdown timer if it is the last session and aKeepServer is trues.
       
   147  @param aKeepLife to keep or disconnect IPC server when all clients are shutdown. 
       
   148 */
       
   149 void CServiceSymbianServer::configIpcServerLifetime(bool aKeepServer)
       
   150 {
       
   151     if ((m_keepServer) && (m_sessionCount==0) && (!aKeepServer))
       
   152     {
       
   153         startExitTimer();
       
   154     }
       
   155     m_keepServer = aKeepServer;
       
   156 }
       
   157 
       
   158 /*!
       
   159  Create a new session, derived from CPolicyServer
       
   160  @param aVersion version of the server
       
   161  @param aMessage message object
       
   162  */
       
   163 CSession2* CServiceSymbianServer::NewSessionL(const TVersion& aVersion,
       
   164                                               const RMessage2& aMessage) const
       
   165 {
       
   166     TVersion v(1, 0, 0);
       
   167     if (!User::QueryVersionSupported(v, aVersion)) {
       
   168         User::Leave(KErrNotSupported);
       
   169     }
       
   170 
       
   171     ClientInfo *client = new ClientInfo();
       
   172     TSecureId sid(aMessage.Identity());
       
   173     client->setProcessId(sid.iId);
       
   174     client->setVendorId(aMessage.VendorId().iId);
       
   175     RThread clientThread;
       
   176     aMessage.ClientL(clientThread);
       
   177     RProcess clientProc;
       
   178     clientThread.Process(clientProc);
       
   179     client->setName(QString::fromUtf16(clientProc.Name().Ptr(), 
       
   180                                        clientProc.Name().Length()));
       
   181     client->setSessionId(m_sessionIdTable->allocate());
       
   182     // Create a new Symbian Session for the client
       
   183     CServiceSymbianSession * session = CServiceSymbianSession::NewL(m_observer);
       
   184     session->setClientInfo(client);
       
   185     return session;
       
   186 }
       
   187 }
       
   188 
       
   189 // END OF FILE