qthighway/xqserviceipc/xqserviceipcserver/xqserviceipcserver_symbianserver.cpp
branchRCL_3
changeset 9 5d007b20cfd0
equal deleted inserted replaced
8:885c2596c964 9:5d007b20cfd0
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:  Symbian implementation for IPC server
       
    19 *
       
    20 */
       
    21 
       
    22 #include "xqservicelog.h"
       
    23 
       
    24 #include "xqserviceipcserver_symbianserver.h"
       
    25 #include "xqserviceipcserver_symbiansession.h"
       
    26 
       
    27 namespace QtService
       
    28 {
       
    29 // Server Security Policy
       
    30 const TUint KServerRangeCount = 2;
       
    31 const TInt KServerRanges[KServerRangeCount] = { 
       
    32                 0, //range is [0-2)
       
    33                 3 //range is [3-KMaxTInt] 
       
    34                 };
       
    35 const TUint8 KSeverElementsIndex[KServerRangeCount] = { 
       
    36                 0,
       
    37                 CPolicyServer::ENotSupported };
       
    38 
       
    39 const CPolicyServer::TPolicyElement KServerPolicyElements[] = { {
       
    40                 _INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData),
       
    41                 CPolicyServer::EFailClient } };
       
    42 
       
    43 const CPolicyServer::TPolicy KServerPolicy = {
       
    44                 CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
       
    45                 KServerRangeCount, KServerRanges, KSeverElementsIndex,
       
    46                 KServerPolicyElements };
       
    47 
       
    48 enum
       
    49 {
       
    50     EServerPriority = CActive::EPriorityStandard
       
    51 };
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 
       
    55 /*!
       
    56     \class CServiceSymbianServer
       
    57     \brief Symbian client server implementation
       
    58 */
       
    59 
       
    60 /*!
       
    61     Constructor.
       
    62 */
       
    63 CServiceSymbianServer::CServiceSymbianServer() :
       
    64     CPolicyServer(EServerPriority, KServerPolicy)
       
    65 {
       
    66     XQSERVICE_DEBUG_PRINT("CServiceSymbianServer::CServiceSymbianServer");
       
    67 }
       
    68 
       
    69 /*!
       
    70     2nd phased constructor.
       
    71 */
       
    72 void CServiceSymbianServer::ConstructL()
       
    73 {
       
    74 }
       
    75 
       
    76 /*!
       
    77     Two phased constructor.
       
    78 */
       
    79 CServiceSymbianServer* CServiceSymbianServer::NewL()
       
    80 {
       
    81     XQSERVICE_DEBUG_PRINT("CServiceSymbianServer::NewL");
       
    82     CServiceSymbianServer* self = new (ELeave) CServiceSymbianServer;
       
    83     CleanupStack::PushL(self);
       
    84     self->ConstructL();
       
    85     CleanupStack::Pop(self);
       
    86     return self;
       
    87 }
       
    88 
       
    89 /*!
       
    90     Destructor.
       
    91 */
       
    92 CServiceSymbianServer::~CServiceSymbianServer()
       
    93 {
       
    94     XQSERVICE_DEBUG_PRINT("CServiceSymbianServer::~CServiceSymbianServer");
       
    95 }
       
    96 
       
    97 /*!
       
    98     Start listening for new service requests.
       
    99     \param aServerName Name of the server.
       
   100     \return true if successful.
       
   101 */
       
   102 bool CServiceSymbianServer::listen(const QString& aServerName)
       
   103 {
       
   104     XQSERVICE_DEBUG_PRINT("CServiceSymbianServer::listen");
       
   105     XQSERVICE_DEBUG_PRINT("aServerName: %s", qPrintable(aServerName));
       
   106     bool listening(true);
       
   107 
       
   108     // Needs to be here becuase Q_Ptr isonly set after constructor of public
       
   109     iObserver = Observer();
       
   110     TPtrC serverName(reinterpret_cast<const TUint16*> (aServerName.utf16()));
       
   111     TInt err=0;
       
   112     TRAP( err, StartL(serverName) );
       
   113     XQSERVICE_DEBUG_PRINT("listen status=%d", err);
       
   114     if (err != KErrNone) {
       
   115         listening = false;
       
   116     }
       
   117     // Complete the server rendezvous that th client started
       
   118     XQSERVICE_DEBUG_PRINT("CServiceSymbianServer::Rendezvouz");
       
   119     RProcess::Rendezvous(KErrNone);
       
   120     XQSERVICE_DEBUG_PRINT("listening: %d", listening);
       
   121     return listening;
       
   122 }
       
   123 
       
   124 /*!
       
   125     Shutdown the server and stop serving clients.
       
   126 */
       
   127 void CServiceSymbianServer::disconnect()
       
   128 {
       
   129     XQSERVICE_DEBUG_PRINT("CServiceSymbianServer::disconnect");
       
   130     // Symbian Servers do not have disconnect, 
       
   131     // the process has to exit
       
   132 }
       
   133 
       
   134 /*!
       
   135     Create a new session, derived from CPolicyServer.
       
   136     \param aVersion Version of the server.
       
   137     \param aMessage Message object.
       
   138 */
       
   139 CSession2* CServiceSymbianServer::NewSessionL(const TVersion& aVersion,
       
   140                                               const RMessage2& aMessage) const
       
   141 {
       
   142     XQSERVICE_DEBUG_PRINT("CServiceSymbianServer::NewSessionL");
       
   143     TVersion v(1, 0, 0);
       
   144     if (!User::QueryVersionSupported(v, aVersion)) {
       
   145         XQSERVICE_DEBUG_PRINT("Not supported version");
       
   146         User::Leave(KErrNotSupported);
       
   147     }
       
   148 
       
   149     // Create a new Symbian Session for the client
       
   150     return CServiceSymbianSession::NewL(iObserver);
       
   151 }
       
   152 }
       
   153 
       
   154 // END OF FILE