sensorservices/sensorserver/inc/server/senserverchannel.h
changeset 0 4e1aa6a622a0
child 9 b0e374890c7b
child 59 0f7422b6b602
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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 channel implemetation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SENSERVERCHANNEL_H
       
    20 #define SENSERVERCHANNEL_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "sensrvtypes.h"
       
    24 #include "sensrvchannelinfo.h"
       
    25 #include "sensrvresourcechannelinfo.h"
       
    26 #include "sensrvmessage.h"
       
    27 #include "ssypropertyprovider.h"
       
    28 #include "ssychanneldataprovider.h"
       
    29 #include "sensrvgeneralproperties.h"
       
    30 
       
    31 class CSensrvTransaction;
       
    32 class CSensrvPluginProxy;
       
    33 class CSensrvTransactionQueue;
       
    34 class CSensrvPropertyQueue;
       
    35 class CSensrvChannelListener;
       
    36 class CSensrvChannelBuffer;
       
    37 class CSensrvConditionEvaluator;
       
    38 
       
    39 /**
       
    40 * Implements channel related handling.
       
    41 *
       
    42 * @since S60 5.0
       
    43 */
       
    44 class CSensrvChannel : public CBase
       
    45     {
       
    46     public:
       
    47 
       
    48         /**
       
    49         * Channel state.
       
    50         */
       
    51         enum TSensrvChannelState
       
    52             {
       
    53             EChannelStateClosed,             ///< Channel is closed
       
    54             EChannelStateOpen,               ///< Channel is open to at least one client
       
    55             EChannelStateListening           ///< Channel is listening for data
       
    56             };
       
    57 
       
    58         /**
       
    59         * Two phase constructor
       
    60         *
       
    61         * @since S60 5.0
       
    62         * @param aInfo Channel info.
       
    63         * @param aProxy Callback proxy.
       
    64         * @return New CSensrvChannel instance
       
    65         * @exception KErrNoMemory Out of memory
       
    66         */
       
    67 		static CSensrvChannel* NewL( const TSensrvResourceChannelInfo& aInfo,
       
    68 									 CSensrvPluginProxy& aProxy );
       
    69 
       
    70         /**
       
    71         * Destructor.
       
    72         */
       
    73         virtual ~CSensrvChannel();
       
    74 
       
    75         /**
       
    76         * Returns the channel id
       
    77         *
       
    78         * @since S60 5.0
       
    79         * @return Channel id.
       
    80         */
       
    81         inline TSensrvChannelId Id() { return iId; };
       
    82 
       
    83         /**
       
    84         * Gets channel state.
       
    85         * Called from both threads.
       
    86         *
       
    87         * @since S60 5.0
       
    88         * @return Current channel state
       
    89         */
       
    90         inline TSensrvChannelState State() const { return iState; };
       
    91 
       
    92         /**
       
    93         * Gets parent proxy reference.
       
    94         * Called from both threads.
       
    95         *
       
    96         * @since S60 5.0
       
    97         * @return Current channel state
       
    98         */
       
    99         inline CSensrvPluginProxy& Proxy() { return iProxy; };
       
   100 
       
   101         /**
       
   102         * Gets data provider pointer.
       
   103         * Called from SSY thread.
       
   104         *
       
   105         * @since S60 5.0
       
   106         * @return Current data provider pointer. Can be NULL.
       
   107         */
       
   108         inline MSsyChannelDataProvider* DataProvider() { return iDataProvider; };
       
   109 
       
   110         /**
       
   111         * Gets property provider pointer.
       
   112         * Called from SSY thread.
       
   113         *
       
   114         * @since S60 5.0
       
   115         * @return Current property provider pointer. Can be NULL.
       
   116         */
       
   117         inline MSsyPropertyProvider* PropertyProvider() { return iPropertyProvider; };
       
   118 
       
   119         /**
       
   120         * Gets data buffer pointer.
       
   121         * Called from SSY thread.
       
   122         *
       
   123         * @since S60 5.0
       
   124         * @return Data buffer pointer. Can be NULL.
       
   125         */
       
   126         inline CSensrvChannelBuffer* Buffer() { return iChannelBuffer; };
       
   127 
       
   128         /**
       
   129         * Gets maximum allowed buffering count.
       
   130         * Called from server thread.
       
   131         *
       
   132         * @since S60 5.0
       
   133         * @return Maximum allowed buffering count
       
   134         */
       
   135         inline TInt MaxBufferingCount() { return iMaxBufferingCount; };
       
   136 
       
   137         /**
       
   138         * Gets the persistent ETransTypeMediatorNewDataAvailable transaction.
       
   139         * Called from SSY thread.
       
   140         *
       
   141         * @since S60 5.0
       
   142         * @return ETransTypeMediatorNewDataAvailable transaction
       
   143         */
       
   144         inline CSensrvTransaction* DataAvailableTransaction() const { return iDataAvailableTransaction; };
       
   145 
       
   146        /**
       
   147         * Gets the persistent ETransTypeMediatorPropertyChanged transaction.
       
   148         * Called from SSY thread.
       
   149         *
       
   150         * @since S60 5.0
       
   151         * @return ETransTypeMediatorPropertyChanged transaction.
       
   152         */
       
   153         inline CSensrvTransaction* PropertyChangedTransaction() const { return iPropertyChangedTransaction; };
       
   154 
       
   155         /**
       
   156         * Gets the persistent ETransTypeMediatorForceBufferFilled transaction.
       
   157         * Called from server thread.
       
   158         *
       
   159         * @since S60 5.0
       
   160         * @return ETransTypeMediatorForceBufferFilled transaction
       
   161         */
       
   162         inline CSensrvTransaction* ForceBufferFilledTransaction() const { return iForceBufferFilledTransaction; };
       
   163 
       
   164         /**
       
   165         * Gets the persistent ETransTypeMediatorForceChannelClose transaction.
       
   166         * Called from SSY thread.
       
   167         *
       
   168         * @since S60 5.0
       
   169         * @return ETransTypeMediatorForceChannelClose transaction
       
   170         */
       
   171         inline CSensrvTransaction*  ForceChannelCloseTransaction() const { return iForceChannelCloseTransaction; };
       
   172 
       
   173         /**
       
   174         * Gets the listener count.
       
   175         * Called from server thread.
       
   176         *
       
   177         * @since S60 5.0
       
   178         * @return Listener count.
       
   179         */
       
   180         inline TInt ListenerCount() const { return iListenerList.Count(); };
       
   181 
       
   182         /**
       
   183         * Gets the data item size
       
   184         * Called from server thread.
       
   185         *
       
   186         * @since S60 5.0
       
   187         * @return Data item size
       
   188         */
       
   189         inline TInt DataItemSize() const { return iChannelInfo.iDataItemSize; };
       
   190 
       
   191         /**
       
   192         * Handles client message.
       
   193         * Message completion responsibility transfers.
       
   194         * Called only within server thread.
       
   195         *
       
   196         * @since S60 5.0
       
   197         * @param aMessage The message containing the client request.
       
   198         */
       
   199         void DispatchMessage( CSensrvMessage& aMessage );
       
   200 
       
   201         /**
       
   202         * Indicates channel has been opened by SSY
       
   203         * Called from SSY thread only.
       
   204         *
       
   205         * @since S60 5.0
       
   206         * @param aErrorCode Indicates any error that occurred during channel opening.
       
   207         * @param aDataProvider Pointer to channel data provider instance
       
   208         * @param aSensorPropertyProvider Pointer to sensor property provider instance
       
   209         */
       
   210         void ChannelOpened( TInt aErrorCode,
       
   211                             MSsyChannelDataProvider* aDataProvider,
       
   212                             MSsyPropertyProvider* aSensorPropertyProvider );
       
   213 
       
   214         /**
       
   215         * Indicates channel has been closed by SSY
       
   216         * Called from SSY thread only.
       
   217         *
       
   218         * @since S60 5.0
       
   219         */
       
   220         void ChannelClosed();
       
   221 
       
   222         /**
       
   223         * Store a changed property provided by SSY.
       
   224         * Called from SSY thread only.
       
   225         *
       
   226         * @since S60 5.0
       
   227         * @param aProperty Property that has changed
       
   228         * @param aIgnoreSession Do not store change for this session. Can be NULL.
       
   229         * @return ETrue if property was stored to any listener.
       
   230         */
       
   231         TBool StoreChangedProperty( const TSensrvProperty& aProperty,
       
   232                                     const CSensrvSession* aIgnoreSession );
       
   233 
       
   234         /**
       
   235         * Completes transaction after it has been handled by SSY.
       
   236         * Only called from server thread.
       
   237         *
       
   238         * @since S60 5.0
       
   239         * @param aTransaction The transaction to complete
       
   240         */
       
   241         void CompleteTransaction( CSensrvTransaction* aTransaction );
       
   242 
       
   243         /**
       
   244         * Cleans up session related data.
       
   245         *
       
   246         * @since S60 5.0
       
   247         * @param aSession The session that was deleted
       
   248         */
       
   249         void SessionTerminated( CSensrvSession* aSession );
       
   250 
       
   251         /**
       
   252         * Handles notify failure at SSY
       
   253         *
       
   254         * @since S60 5.0
       
   255         */
       
   256         void HandleSsyNotifyFailure();
       
   257 
       
   258         /**
       
   259         * Forces buffer filled at SSY
       
   260         *
       
   261         * @since S60 5.0
       
   262         */
       
   263         void ForceBufferFilled();
       
   264 
       
   265         /**
       
   266         * Recalculates buffering count, if there is more than one
       
   267         * client.
       
   268         *
       
   269         * @since S60 5.0
       
   270         * @return The new buffering count. If returned value is zero,
       
   271         *         it means there are no listeners in channel.
       
   272         */
       
   273         TInt RecalculateBufferingCount();
       
   274 
       
   275         /**
       
   276         * Creates a new condition evaluator or returns an existing one.
       
   277         *
       
   278         * @since S60 5.0
       
   279         * @return The condition evaluator reference.
       
   280         */
       
   281         CSensrvConditionEvaluator* ConditionEvaluatorL();
       
   282 
       
   283         /**
       
   284         * Get clients of this channel. The client identified by aCallerSecureId
       
   285         * is not added to the affected clients list.
       
   286         *
       
   287         * @since S60 5.0
       
   288         * @param[in,out] aAffectedClients On return contains client
       
   289         *                 processes priorities for this channel.
       
   290         * @param[in]     aCallerSecureId Identifies the listener which is filtered away.
       
   291         */
       
   292         void GetAffectedClients( RArray<TInt>& aAffectedClients,
       
   293                                  TSecureId aCallerSecureId );
       
   294 
       
   295         /**
       
   296         * Gets listener for session.
       
   297         *
       
   298         * @since S60 5.0
       
   299         * @param aSession Session for which the listener is needed.
       
   300         * @return Listener pointer or NULL if not found.
       
   301         */
       
   302         CSensrvChannelListener* GetListener(CSensrvSession* aSession);
       
   303 
       
   304         /**
       
   305         * Takes the property set control.
       
   306         * Required priority checks must be done by client before using this method.
       
   307         *
       
   308         * @since S60 5.0
       
   309         * @param[in] aListener The listener that takes control or NULL if control is freed.
       
   310         */
       
   311         void TakePropertySetControl( CSensrvChannelListener* aListener );
       
   312 
       
   313         /**
       
   314         * Gets the listener that has taken the property set control.
       
   315         *
       
   316         * @since S60 5.0
       
   317         * @return The listener that has taken the property set control or NULL if control has not been taken.
       
   318         */
       
   319         inline CSensrvChannelListener* TakenPropertySetControl() const { return iCurrentSetPropertyControl; };
       
   320 
       
   321         /**
       
   322         * Gets the highest priority listener and its multiples from this channel.
       
   323         *
       
   324         * @since S60 5.0
       
   325         * @param[out] aHighestPriority Stores the highest priority.
       
   326         * @return Multiples of highest listener priority
       
   327         */
       
   328         TInt GetHighestListenerPriority( TInt& aHighestPriority );
       
   329 
       
   330         /**
       
   331         * Gets channel group
       
   332         * Called from server thread.
       
   333         *
       
   334         * @since S60 5.0
       
   335         * @return Channel group.
       
   336         */
       
   337         TSensrvResourceChannelInfo::TSensrvChannelGroup ChannelGroup();
       
   338 
       
   339     private:
       
   340 
       
   341         /**
       
   342         * C++ constructor
       
   343         *
       
   344         * @since S60 5.0
       
   345         * @param aInfo Channel info.
       
   346         * @param aProxy Callback proxy.
       
   347         */
       
   348         CSensrvChannel(const TSensrvChannelInfo& aInfo,
       
   349                        CSensrvPluginProxy& aProxy);
       
   350 
       
   351         /**
       
   352         * 2nd phase of construction
       
   353         *
       
   354         * @since S60 5.0
       
   355         */
       
   356         void ConstructL();
       
   357 
       
   358         /**
       
   359         * Handles next transaction in queue.
       
   360         * If first transaction is still executing
       
   361         * or the queue is empty, does nothing.
       
   362         *
       
   363         * @since S60 5.0
       
   364         */
       
   365         void HandleNextTransaction();
       
   366 
       
   367         /**
       
   368         * Deletes a listener.
       
   369         *
       
   370         * @since S60 5.0
       
   371         * @param aSession Session for which the listener is deleted.
       
   372         */
       
   373         void DeleteListener(CSensrvSession* aSession);
       
   374 
       
   375         /**
       
   376         * Finds a listener by session.
       
   377         *
       
   378         * @since S60 5.0
       
   379         * @param aSession Session for which the listener is found.
       
   380         */
       
   381 		CSensrvChannelListener* FindListener( CSensrvSession* aSession );
       
   382 
       
   383         /**
       
   384         * Closes the channel to SSY if there are no listeners.
       
   385         *
       
   386         * @since S60 5.0
       
   387         */
       
   388         void CloseIfNeeded();
       
   389 
       
   390         /**
       
   391         * Handles start data and condition listening transactions
       
   392         *
       
   393         * @since S60 5.0
       
   394         * @param aTransaction Reference to the transaction.
       
   395         * @return Error code
       
   396         */
       
   397         TInt HandleStartListeningTransaction(CSensrvTransaction& aTransaction);
       
   398 
       
   399         /**
       
   400         * Handles stop data and condition listening transactions
       
   401         *
       
   402         * @since S60 5.0
       
   403         * @param aTransaction Reference to the transaction.
       
   404         * @param[out] aSsyTransactionNeeded Returns ETrue if SSY transaction is needed.
       
   405         * @return Error code
       
   406         */
       
   407         TInt HandleStopListeningTransaction(CSensrvTransaction& aTransaction,
       
   408                                             TBool& aSsyTransactionNeeded);
       
   409 
       
   410         /**
       
   411         * Gets the highest priority listener and its multiples from all affected channels.
       
   412         *
       
   413         * @since S60 5.0
       
   414         * @param[out] aHighestPriority Stores the highest priority.
       
   415         * @return Multiples of highest listener priority
       
   416         */
       
   417         TInt GetHighestListenerPriorityOfAffectedChannels( TInt& aHighestPriority );
       
   418 
       
   419         /**
       
   420         * Updated set property success indication to channel listeners
       
   421         *
       
   422         * @since S60 5.0
       
   423         * @param[in] aChannel Channel to update
       
   424         * @param aHighestOfAffectedChannels Highest priority of affected channels
       
   425         * @param aMultiplesOnAffectedChannels Multiples of highest priority listeners
       
   426         */
       
   427         static void UpdateSetPropertySuccessIndToChannelListeners(
       
   428             CSensrvChannel& aChannel, TInt aHighestOfAffectedChannels, TInt aMultiplesOnAffectedChannels );
       
   429 
       
   430         /**
       
   431         * Handles set property success indications on property change
       
   432         *
       
   433         * @since S60 5.0
       
   434         */
       
   435         void HandleSetPropertySuccessIndOnPropertyChange();
       
   436 
       
   437         /**
       
   438         * Handles set property success indications on listener creation or deletion
       
   439         *
       
   440         * @since S60 5.0
       
   441         */
       
   442         void HandleSetPropertySuccessIndOnCreateOrDelete();
       
   443 
       
   444 
       
   445         /**
       
   446         * Handles dependent channels on channel open
       
   447         *
       
   448         * @since S60 5.0
       
   449         */
       
   450 		void HandleDependencyOnOpen();
       
   451 
       
   452         /**
       
   453         * Handles dependent channels on channel close
       
   454         *
       
   455         * @since S60 5.0
       
   456         */
       
   457 		void HandleDependencyOnClose( const TInt& aPriority );
       
   458 
       
   459         /**
       
   460         * Sets dependent channel availability
       
   461         *
       
   462         * @since S60 5.0
       
   463         */
       
   464 		TInt SetAvailability( TSensrvChannelId aChannelId, TSensrvProperty& aProperty, TSensrvAvailability aValue, const TSecurityInfo& aSecurityInfo );
       
   465 
       
   466         /**
       
   467         * Sets dependent channel availability
       
   468         *
       
   469         * @since S60 5.0
       
   470         */
       
   471 		TInt SetChannelAvailability( TSensrvChannelId aChannelIdToEnable, TSensrvChannelId aChannelIdToDisable, TSensrvProperty& aProperty );
       
   472 
       
   473         /**
       
   474         * Sets dependent channel availability
       
   475         *
       
   476         * @since S60 5.0
       
   477         */
       
   478 		TInt SetChannelAvailability( TSensrvChannelId aChannelId, TSensrvProperty& aProperty, TSensrvAvailability aValue );
       
   479 
       
   480         /**
       
   481         * Get channel from affected channels list with the lowest priority
       
   482         *
       
   483         * @since S60 5.0
       
   484         */
       
   485 		TInt GetLowestChannelPriority( const RSensrvChannelList* aAffectedChannelsList, TSensrvChannelId& aChannelId );
       
   486 
       
   487 
       
   488         /**
       
   489         * Get channel from affected channels list with the highest priority
       
   490         *
       
   491         * @since S60 5.0
       
   492         */
       
   493 		TInt GetHighestChannelPriority( const RSensrvChannelList* aAffectedChannelsList, TSensrvChannelId& aChannelId );
       
   494 
       
   495         /**
       
   496         * Gets the affected channel list from SSY
       
   497         *
       
   498         * @since S60 5.0
       
   499         * @return Affected channel list or NULL
       
   500         */
       
   501         RSensrvChannelList* GetAffectedChannels() const;
       
   502 
       
   503         /**
       
   504         * Gets the affected channel list from SSY
       
   505         *
       
   506         * @since S60 5.0
       
   507         * @return Affected channel list or NULL
       
   508         */
       
   509         RSensrvChannelList* GetAvailabilityAffectedChannels( TSensrvAvailability aValue ) const;
       
   510 
       
   511         /**
       
   512         * Reads channel group
       
   513         *
       
   514         * @since S60 5.0
       
   515         * @return Channel group.
       
   516         */
       
   517         TSensrvResourceChannelInfo::TSensrvChannelGroup ReadChannelGroup();
       
   518 
       
   519         /**
       
   520         * Handles channel availability property change
       
   521         *
       
   522         * @since S60 5.0
       
   523         */
       
   524         void HandleAvailabilityChange( const TSensrvProperty& aProperty );
       
   525 
       
   526         /**
       
   527         * Handles channel availability property change
       
   528         *
       
   529         * @since S60 5.0
       
   530         */
       
   531 		void HandleAvailabilityChange( const TSensrvAvailability& value );
       
   532 
       
   533         /**
       
   534         * Handles channel availability property change to unavailabe
       
   535         *
       
   536         * @since S60 5.0
       
   537         */
       
   538 		void CSensrvChannel::SetChannelUnavailable( );
       
   539 
       
   540         /**
       
   541         * Handles channel availability property change to availabe
       
   542         *
       
   543         * @since S60 5.0
       
   544         */
       
   545 		void CSensrvChannel::SetChannelAvailable( );
       
   546 
       
   547     private: // Member variables
       
   548 
       
   549         /**
       
   550         * Channel identifier of this channel.
       
   551         */
       
   552         TSensrvChannelId iId;
       
   553 
       
   554         /**
       
   555         * Transaction queue for transactions targeting this channel.
       
   556         * Own. iChannelQueue owns the queued transactions.
       
   557         */
       
   558         CSensrvTransactionQueue* iChannelQueue;
       
   559 
       
   560         /**
       
   561         * Current channel state
       
   562         */
       
   563         TSensrvChannelState iState;
       
   564 
       
   565         /**
       
   566         * Callback proxy
       
   567         */
       
   568         CSensrvPluginProxy& iProxy;
       
   569 
       
   570         /**
       
   571         * Channel listener array for open clients
       
   572         * Listed listeners are owned.
       
   573         */
       
   574         RPointerArray<CSensrvChannelListener> iListenerList;
       
   575 
       
   576         /**
       
   577         * Channel buffer.
       
   578         * Own.
       
   579         */
       
   580         CSensrvChannelBuffer* iChannelBuffer;
       
   581 
       
   582         /**
       
   583         * Data provider residing in SSY thread heap.
       
   584         * Can safely be accessed only from SSY thread.
       
   585         * Not Own, owned by SSY.
       
   586         */
       
   587         MSsyChannelDataProvider* iDataProvider;
       
   588 
       
   589         /**
       
   590         * Sensor property provider residing in SSY thread heap.
       
   591         * Can safely be accessed only from SSY thread.
       
   592         * Not Own, owned by SSY.
       
   593         */
       
   594         MSsyPropertyProvider* iPropertyProvider;
       
   595 
       
   596         /**
       
   597         * Transaction for notifying new data from SSY to Server.
       
   598         * It is stored and reused to both avoid repeatedly
       
   599         * constructing and deleting it and to ensure it always
       
   600         * exists, as the transaction is initiated by SSY.
       
   601         * Own.
       
   602         */
       
   603         CSensrvTransaction* iDataAvailableTransaction;
       
   604 
       
   605         /**
       
   606         * Transaction for notifying buffer filled must be forced.
       
   607         * It is stored and reused to avoid repeatedly
       
   608         * constructing and deleting it.
       
   609         * Own.
       
   610         */
       
   611         CSensrvTransaction* iForceBufferFilledTransaction;
       
   612 
       
   613         /**
       
   614         * Transaction for notifying channel close must be forced.
       
   615         * It is stored and reused to  ensure it always
       
   616         * exists, as the transaction is initiated by SSY.
       
   617         * Own.
       
   618         */
       
   619         CSensrvTransaction* iForceChannelCloseTransaction;
       
   620 
       
   621         /**
       
   622         * Indicates outstanding explicit buffer fill request.
       
   623         */
       
   624         TBool iForcingBufferFilled;
       
   625 
       
   626         /**
       
   627         * Indicates maximum buffering count.
       
   628         */
       
   629         TInt iMaxBufferingCount;
       
   630 
       
   631         /**
       
   632         * Transaction for notifying property change from SSY to Server
       
   633         * Own.
       
   634         */
       
   635         CSensrvTransaction* iPropertyChangedTransaction;
       
   636 
       
   637         /**
       
   638         * Condition evaluator plugin.
       
   639         * Own.
       
   640         */
       
   641         CSensrvConditionEvaluator* iConditionEvaluator;
       
   642 
       
   643         /**
       
   644         * Channel info of this channel.
       
   645         */
       
   646         TSensrvResourceChannelInfo iChannelInfo;
       
   647 
       
   648         /**
       
   649         * The channel listener that has taken the property set control.
       
   650         * Not own.
       
   651         */
       
   652         CSensrvChannelListener* iCurrentSetPropertyControl;
       
   653 
       
   654         /**
       
   655         * Highest listener priority of the channel.
       
   656         */
       
   657         TInt iHighestListenerPriority;
       
   658 
       
   659         /**
       
   660         * Multiples of highest listener priority.
       
   661         * If there are no listeners on this channel, value is zero.
       
   662         * If there is single listener with the highest priority, value is one, etc.
       
   663         */
       
   664         TInt iHighestListenerPriorityMultiples;
       
   665 
       
   666     };
       
   667 
       
   668 
       
   669 
       
   670 #endif // SENSERVERCHANNEL_H