crypto/weakcryptospi/test/kms/private_include/product/kmsserver.h
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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: 
       
    15 * Values and data types used by KMS server-side implementation.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @internalComponent
       
    24  @file
       
    25 */
       
    26 
       
    27 #ifndef KMSSERVER_H
       
    28 #define KMSSERVER_H
       
    29 
       
    30 #include <e32base.h>
       
    31 
       
    32 #include "kmsservercommon.h"
       
    33 
       
    34 
       
    35 // forward declaration so can contain pointer in server object
       
    36 class CKmsShutdown;
       
    37 class CKeyMgmtServer : public CServer2
       
    38 /**
       
    39 	Symbian OS server object creates sessions for KMS clients.
       
    40  */
       
    41 	{
       
    42 public:
       
    43 	static CKeyMgmtServer* NewLC();
       
    44 	virtual ~CKeyMgmtServer();
       
    45 	
       
    46 	// implement CServer2
       
    47 	virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
       
    48 	
       
    49 	void IncrementSessionCount();
       
    50 	void DecrementSessionCount();
       
    51 	
       
    52 private:
       
    53 	CKeyMgmtServer();
       
    54 	void ConstructL();
       
    55 
       
    56 private:
       
    57 	/**
       
    58 		If there have been no open sessions for this period of time,
       
    59 		then the server is stopped.
       
    60 	 */
       
    61 	static const TInt KShutdownPeriodUs = 2 * 1000 * 1000;
       
    62 	TBool iLoadedLdd;		///< Whether the ldd was successfully loaded.
       
    63 	
       
    64 	/**
       
    65 		The number of currently open sessions.  When the last open session
       
    66 		is closed then the shutdown timer is started.
       
    67 	 */
       
    68 	TInt iSessionCount;
       
    69 	
       
    70 	/**
       
    71 		Shuts down the server after an inactivity period when no sessions
       
    72 		have been open.
       
    73 	 */
       
    74 	CKmsShutdown* iShutdown;
       
    75 	};
       
    76 
       
    77 class CKeyMgmtSession : public CSession2
       
    78 /**
       
    79 	Symbian OS server session object handles requests from KMS clients
       
    80 	which are sent through the RKmsSession class.
       
    81  */
       
    82 	{
       
    83 public:
       
    84 	static CKeyMgmtSession* NewL();
       
    85 	virtual ~CKeyMgmtSession();
       
    86 	
       
    87 	// implement CSession2
       
    88 	virtual void ServiceL(const RMessage2& aMessage);
       
    89 	// override CSession2
       
    90 	virtual void ServiceError(const RMessage2& aMessage, TInt aError);
       
    91 
       
    92 private:
       
    93 	void ConstructL();
       
    94 	
       
    95 	void GenerateKeyL(const RMessage2& aMessage, RProcess aClientProc);
       
    96 	void StoreKeyL(const RMessage2& aMessage, RProcess aClientProc);
       
    97 	void WriteHandleToClientL(const RMessage2& aMessage, RProcess aClientProc, TKeyHandle aHandle);
       
    98 	
       
    99 	void DeleteKeyL(const RMessage2& aMessage, RProcess aClientProc);
       
   100 
       
   101 	void AddUsageL(const RMessage2& aMessage, RProcess aClientProc);
       
   102 	void DeleteUsageL(const RMessage2& aMessage, RProcess aClientProc);
       
   103 	
       
   104 private:
       
   105 	/**
       
   106 		This channel provides access to the hardware key store via a device driver.
       
   107 		It is opened when the session is created, and closed when the session is
       
   108 		destroyed.
       
   109 	 */
       
   110 	RKmsChannel iChannel;
       
   111 	};
       
   112 
       
   113 class CKmsShutdown : public CTimer
       
   114 /**
       
   115 	Stops the server after no sessions have been connected for
       
   116 	a specified period.
       
   117  */
       
   118 	{
       
   119 public:
       
   120 	static CKmsShutdown* NewL(TInt iDelayUs);
       
   121 	
       
   122 	void Restart();
       
   123 	
       
   124 private:
       
   125 	CKmsShutdown(TInt aPeriodUs);
       
   126 	
       
   127 	// implement CTimer
       
   128 	virtual void RunL();
       
   129 	
       
   130 private:
       
   131 	/** Timer delay in microseconds. */
       
   132 	TInt iDelayUs;
       
   133 	};
       
   134 
       
   135 #endif	// #ifndef KMSSERVER_H
       
   136 
       
   137