sensorservices/sensorserver/inc/server/sensrvtransaction.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Sensor server transaction base class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SENSRVTRANSACTION_H
       
    20 #define SENSRVTRANSACTION_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "sensrvmessage.h"
       
    24 
       
    25 class CSensrvSession;
       
    26 class CSensrvProxyManager;
       
    27 class CSensrvPluginProxy;
       
    28 class CSensrvChannel;
       
    29 
       
    30 /**
       
    31  *  Base class for Sensor Server transactions
       
    32  *
       
    33  *  @since S60 5.0
       
    34  */
       
    35 class CSensrvTransaction : public CBase
       
    36     {
       
    37     public:
       
    38         
       
    39         /** 
       
    40         * Transaction types
       
    41         *
       
    42         * Mediator transactions are never owned by transaction queues and are reused, 
       
    43         * even if the regular transactions are not. They are used for passing events 
       
    44         * internally between SSY and Server main thread.
       
    45         */
       
    46         enum TSensrvTransactionType
       
    47             {
       
    48             ETransTypeNone,                      ///< Uninitialized type.
       
    49             ETransTypeLoadSsy = 1,               ///< Loads SSY.
       
    50             ETransTypeDelayedInitialize,         ///< Reloads plugin after unloading is complete
       
    51             ETransTypeDelayedOpenChannel,        ///< Reattempts Open channel after loading is complete
       
    52             ETransTypeClientQueryChannels,       ///< Waiting transaction for channel info queries
       
    53             ETransTypeOpenChannel,               ///< Opens channel
       
    54             ETransTypeCloseChannel,              ///< Closes channel
       
    55             ETransTypeStartListening,            ///< Starts listening to a channel
       
    56             ETransTypeStopListening,             ///< Stops listening to a channel
       
    57             ETransTypeGetProperty,               ///< Gets single property of a channel
       
    58             ETransTypeGetAllProperties,          ///< Gets all properties of a channel  
       
    59             ETransTypeSetProperty,               ///< Sets single property of a channel
       
    60             ETransTypeStartConditionListening,   ///< Starts condition listening
       
    61             ETransTypeStopConditionListening,    ///< Stops condition listening
       
    62             ETransTypeMediatorFirst = 10000,     ///< Just here to indicate first internal transaction.  
       
    63             ETransTypeMediatorNewDataAvailable,  ///< SSY mediator notifies channel about new data with this transaction.
       
    64             ETransTypeMediatorForceBufferFilled, ///< Channel listener notifies SSY that buffer fill needs to be forced.
       
    65             ETransTypeMediatorForceChannelClose, ///< SSY mediator notifies channel that it needs to be closed because of error situation.
       
    66             ETransTypeMediatorPropertyChanged,    ///< SSY mediator notifies channels about changed property.
       
    67             ETransTypeMediatorChannelsChanged    ///< SSY mediator notifies proxy about channel registration
       
    68             };
       
    69             
       
    70          /**
       
    71          * Transactino states
       
    72          */
       
    73          enum TSensrvTransactionState
       
    74             {
       
    75             ETransStateUninitialized,      ///< Initial state of transaction
       
    76             ETransStateQueued,             ///< Transaction has been queued
       
    77             ETransStateExecuting,          ///< Transaction is executing
       
    78             ETransStateHandledAtSsy,       ///< Transaction has been handled at SSY.
       
    79             ETransStateNotifyFailed,       ///< Transaction notifying to a mediator failed
       
    80             ETransStateCompleted           ///< Transaction has been completed and will be deleted shortly.
       
    81             };
       
    82             
       
    83          /**
       
    84          * Channel open message data
       
    85          */
       
    86         class TChannelOpenMessageData
       
    87             {
       
    88         public:
       
    89             inline TChannelOpenMessageData( TInt aMaxBufferingCount, TInt aDataItemSize ) : 
       
    90                 iMaxBufferingCount(aMaxBufferingCount), iDataItemSize(aDataItemSize) {}
       
    91 
       
    92             TInt iMaxBufferingCount;
       
    93             TInt iDataItemSize;
       
    94             };
       
    95         
       
    96         /**
       
    97         * Two phase constructor
       
    98         *
       
    99         * @since S60 5.0
       
   100         * @param aMessage The message related to this transaction. 
       
   101         *         Can be NULL if transaction has no client.
       
   102         *         Ownership of the message passes to this transaction.
       
   103         * @param aProxy The plugin proxy related to this transaction. 
       
   104         *         Can be NULL if transaction is not related to a single proxy.
       
   105         * @param aChannel The channel related to this transaction.
       
   106         *         Can be NULL if transaction is not related to a channel.
       
   107         * @param aType The transaction type.
       
   108         * @return New CSensrvTransaction instance
       
   109         * @exception KErrNoMemory Out of memory
       
   110         */
       
   111         static CSensrvTransaction* NewL(CSensrvMessage* aMessage, 
       
   112                                         CSensrvPluginProxy* aProxy, 
       
   113                                         CSensrvChannel* aChannel,
       
   114                                         TSensrvTransactionType aType);
       
   115 
       
   116         /**
       
   117         * Two phase constructor, leaves newly created object to cleanupstack.
       
   118         *
       
   119         * @since S60 5.0
       
   120         * @param aMessage The message related to this transaction. 
       
   121         *         Can be NULL if transaction has no client.
       
   122         *         Ownership of the message passes to this transaction.
       
   123         * @param aProxy The plugin proxy related to this transaction. 
       
   124         *         Can be NULL if transaction is not related to a single proxy.
       
   125         * @param aChannel The channel related to this transaction.
       
   126         *         Can be NULL if transaction is not related to a channel.
       
   127         * @param aType The transaction type.
       
   128         * @return New CSensrvTransaction instance
       
   129         * @exception KErrNoMemory Out of memory
       
   130         */
       
   131         static CSensrvTransaction* NewLC(CSensrvMessage* aMessage, 
       
   132                                         CSensrvPluginProxy* aProxy, 
       
   133                                         CSensrvChannel* aChannel,
       
   134                                         TSensrvTransactionType aType);
       
   135 
       
   136         /**
       
   137         * Destructor.
       
   138         */
       
   139         virtual ~CSensrvTransaction();
       
   140 
       
   141         /**
       
   142         * Completes the transaction and related message, if any. 
       
   143         *
       
   144         * @since S60 5.0
       
   145         */
       
   146         void Complete();
       
   147 
       
   148         /**
       
   149         * Gets session related to this transaction.
       
   150         *
       
   151         * @since S60 5.0
       
   152         * @return Session pointer. NULL if transaction has no client.
       
   153         */
       
   154         inline CSensrvSession* Session() const { return iMessage ? iMessage->Session() : NULL; };
       
   155 
       
   156         /**
       
   157         * Gets message related to this transaction.
       
   158         * 
       
   159         * @since S60 5.0
       
   160         * @return Message pointer. NULL if transaction has no client.
       
   161         */
       
   162         inline CSensrvMessage* Message() const { return iMessage; };
       
   163 
       
   164         /**
       
   165         * Gets the plugin proxy related to transaction.
       
   166         *
       
   167         * @since S60 5.0
       
   168         * @return Related proxy. NULL if transaction is not related to a single proxy.
       
   169         */
       
   170         inline CSensrvPluginProxy* Proxy() const { return iProxy; };
       
   171 
       
   172         /**
       
   173         * Gets related channel pointer.
       
   174         *
       
   175         * @since S60 5.0
       
   176         * @return Pointer to related channel. NULL if transaction is not related to a channel.
       
   177         */
       
   178         inline CSensrvChannel* Channel() const { return iChannel; };
       
   179 
       
   180         /**
       
   181         * Gets the transaction type.
       
   182         *
       
   183         * @since S60 5.0
       
   184         * @return Transaction type.
       
   185         */
       
   186         inline TSensrvTransactionType Type() const { return iType; };
       
   187 
       
   188         /**
       
   189         * Checks if transaction is a mediator transaction.
       
   190         *
       
   191         * @since S60 5.0
       
   192         * @return ETrue if transaction is a mediator transaction
       
   193         */
       
   194         inline TBool IsMediatorType() const { return iType > ETransTypeMediatorFirst ? ETrue : EFalse; };
       
   195 
       
   196         /**
       
   197         * Gets transaction timestamp.
       
   198         *
       
   199         * @since S60 5.0
       
   200         * @return TTime Transaction creation timestamp
       
   201         */
       
   202         inline const TTime& TimeStamp() const { return iTimeStamp; };
       
   203 
       
   204         /**
       
   205         * Resets transaction timestamp to current time.
       
   206         *
       
   207         * @since S60 5.0
       
   208         * @return TTime New transaction timestamp
       
   209         */
       
   210         inline const TTime& ResetTimeStamp() { iTimeStamp.HomeTime(); return iTimeStamp; };
       
   211         
       
   212         /**
       
   213         * Gets transaction error.
       
   214         *
       
   215         * @since S60 5.0
       
   216         * @return Error code.
       
   217         */
       
   218         inline TInt ErrorCode() const { return iErrorCode; };
       
   219 
       
   220         /**
       
   221         * Gets transaction state.
       
   222         *
       
   223         * @since S60 5.0
       
   224         * @return Transaction state.
       
   225         */
       
   226         inline TInt State() const { return iState; };
       
   227 
       
   228         /**
       
   229         * Sets transaction state.
       
   230         *
       
   231         * @since S60 5.0
       
   232         * @param aState The new state for transaction. 
       
   233         */
       
   234         void SetState(TSensrvTransactionState aState);
       
   235 
       
   236         /**
       
   237         * Sets data to message to be returned to client.
       
   238         * 
       
   239         * @since S60 5.0
       
   240         * @param aData Data to set to the message. 
       
   241         *              How TAny pointer is interpreted depends on transaction type:
       
   242         *              ETransTypeClientQueryChannels - RSensrvChannelInfoList*,
       
   243         *              ETransTypeOpenChannel - TChannelOpenMessageData*
       
   244         * @return KErrBadHandle Message is NULL.
       
   245         *         KErrBadDescriptor Message parameters are not descriptor type.
       
   246         *         KErrOverflow Message descriptor too small.
       
   247         */
       
   248         TInt SetMessageData(TAny* aData);
       
   249 
       
   250         /**
       
   251         * Sets transaction error.
       
   252         *
       
   253         * @since S60 5.0
       
   254         * @param aErrorCode Error code
       
   255         */
       
   256         void SetErrorCode(TInt aErrorCode);
       
   257 
       
   258         /**
       
   259         * Extracts message from transaction. 
       
   260         * Message completion responsibility transfers to caller.
       
   261         *
       
   262         * @since S60 5.0
       
   263         * @return The message previously owned by transaction.
       
   264         */
       
   265         CSensrvMessage* ExtractMessage();
       
   266 
       
   267     private:
       
   268 
       
   269         /**
       
   270          * C++ constructor
       
   271          *
       
   272          * @since S60 5.0
       
   273          * @param aMessage The message related to this transaction. 
       
   274          *         Can be NULL if transaction has no client.
       
   275          * @param aProxy The plugin proxy related to this transaction. 
       
   276          *         Can be NULL if transaction is not related to a single proxy.
       
   277          * @param aChannel The channel related to this transaction.
       
   278          *         Can be NULL if transaction is not related to a channel.
       
   279          * @param aType The transaction type.
       
   280          */
       
   281         CSensrvTransaction(CSensrvMessage* aMessage, 
       
   282                            CSensrvPluginProxy* aProxy, 
       
   283                            CSensrvChannel* aChannel,
       
   284                            TSensrvTransactionType aType);
       
   285 
       
   286     private:
       
   287 
       
   288         /**
       
   289         * Message related to transaction.
       
   290         * Can be NULL for clientless internal transactions.
       
   291         * Not own, but is responsible for completion. 
       
   292         * All messages are owned by session objects.
       
   293         */
       
   294         CSensrvMessage* iMessage;
       
   295 
       
   296         /**
       
   297         * Plugin proxy related to transaction.
       
   298         * Can be NULL for transactions not related to a single proxy.
       
   299         * Not Own.
       
   300         */
       
   301         CSensrvPluginProxy* iProxy;
       
   302 
       
   303         /**
       
   304         * Channel related to transaction.
       
   305         * Can be NULL for transactions not related to a channel.
       
   306         * Not Own.
       
   307         */
       
   308         CSensrvChannel* iChannel;
       
   309 
       
   310         /**
       
   311         * Transaction type.
       
   312         */
       
   313         TSensrvTransactionType iType;
       
   314 
       
   315         /**
       
   316         * Transaction state.
       
   317         */
       
   318         TSensrvTransactionState iState;
       
   319 
       
   320         /**
       
   321         * Transaction creation time. 
       
   322         */
       
   323         TTime iTimeStamp;
       
   324 
       
   325         /**
       
   326         * Error related to transaction.
       
   327         */
       
   328         TInt iErrorCode;
       
   329     };
       
   330 
       
   331 
       
   332 
       
   333 #endif // SENSRVTRANSACTION_H