vpnengine/eventmediator/inc/eventmediator.h
branchRCL_3
changeset 44 735de8341ce4
parent 0 33413c0669b9
child 49 5960d2d03390
equal deleted inserted replaced
41:e06095241a65 44:735de8341ce4
    49 /**
    49 /**
    50 * Defines the event mediator server. 
    50 * Defines the event mediator server. 
    51 */
    51 */
    52 class CEventMediatorServer : public CPolicyServer, public MSitDeathListener
    52 class CEventMediatorServer : public CPolicyServer, public MSitDeathListener
    53     {
    53     {
    54     friend class CEventMediatorSession; // Friend class
       
    55 
       
    56     public: //Methods
    54     public: //Methods
    57 
    55 
    58     // Constructors and destructor
    56     // Constructors and destructor
    59 
    57 
    60         /**
    58         /**
    75         /**
    73         /**
    76         * Creates a new session.
    74         * Creates a new session.
    77         */
    75         */
    78         CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
    76         CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
    79 
    77 
       
    78         /**
       
    79          * Notifies the server that a session has been deleted.
       
    80          */
       
    81         void SessionDeleted(TBool aIsSitSession);
    80     // Other methods
    82     // Other methods
    81         
    83         
    82         /**
    84         /**
    83          * Reports new envent to the eventmediator server.
    85          * Reports new envent to the eventmediator server.
    84          * @param aType: type of the event.
    86          * @param aType: type of the event.
    96 
    98 
    97         /**
    99         /**
    98          * Finds out whether the specified client thread is a SIT
   100          * Finds out whether the specified client thread is a SIT
    99          * thread or not
   101          * thread or not
   100          */
   102          */
   101         TBool IsClientTheSitL(const RMessage2& aMessage);
   103         TBool IsClientTheSitL(const RMessage2& aMessage) const;
   102 
   104 
   103         /**
   105         /**
   104          * Starts the SIT thread if it is not running
   106          * Starts the SIT thread if it is not running
   105          */
   107          */
   106         void MakeSureSitIsRunningL();
   108         void MakeSureSitIsRunningL();
   206          */
   208          */
   207         TInt NewEventSpecId();
   209         TInt NewEventSpecId();
   208 
   210 
   209         TPtrC EventLogFileName(void);
   211         TPtrC EventLogFileName(void);
   210         
   212         
       
   213         /**
       
   214          * Copies data describing an event to the client.
       
   215          * @param aMessge: a message from client side sent by RConnection::FetchData
       
   216          * @return error code, KErrNone if successfull
       
   217          */
       
   218         TInt CopyEventDataL(const RMessage2& aMessage);    
       
   219         
       
   220         
   211    public: // From MSitDeathListener
   221    public: // From MSitDeathListener
   212         void SitDied();
   222         void SitDied();
   213 
   223 
   214    protected:
   224    protected:
   215         /**
   225         /**
   229         CEventMediatorServer(void);
   239         CEventMediatorServer(void);
   230 
   240 
   231         /**
   241         /**
   232          * Perform the second phase construction of a CVpnManagerServer
   242          * Perform the second phase construction of a CVpnManagerServer
   233          * object.
   243          * object.
   234          * @param aServer Pointer to the server itself.
   244          */
   235          */
   245         void ConstructL();
   236         void ConstructL(CEventMediatorServer* aServer);
       
   237 
   246 
   238     // Other methods
   247     // Other methods
   239 
   248 
   240         /**
       
   241          * Stops the server if the session count is zero.
       
   242          */
       
   243         void StopEventMediator(void);
       
   244 
       
   245         /**
       
   246          * Copies data describing an event to the client.
       
   247          * @param aMessge: a message from client side sent by RConnection::FetchData
       
   248          * @return error code, KErrNone if successfull
       
   249          */
       
   250         TInt CopyEventDataL(const RMessage2& aMessage);    
       
   251 
   249 
   252         /**
   250         /**
   253          * Reduces listener count of a stored event by one and destroys it if count becomes zero.
   251          * Reduces listener count of a stored event by one and destroys it if count becomes zero.
   254          * @param aIndex: the index of the stored event in the list.
   252          * @param aIndex: the index of the stored event in the list.
   255          */
   253          */
   256         void MarkStoredEventListened(TInt aIndex);
   254         void MarkStoredEventListened(TInt aIndex);
   257 
       
   258         /**
       
   259          * Sets the iShuttingDown flag.
       
   260          */
       
   261         void SetShuttingDown(TBool aShuttingDown);
       
   262 
   255 
   263     private: //Data
   256     private: //Data
   264         // List of Events that have been reported but not handled by all listeners.
   257         // List of Events that have been reported but not handled by all listeners.
   265         CArrayFixFlat<TEventContainer*> iStoredEvents;
   258         CArrayFixFlat<TEventContainer*> iStoredEvents;
   266         // Number of currently existing sessions.
   259         // Number of currently existing sessions.
   267         TInt iSessionCount;
   260         mutable TInt iSessionCount;
   268         // Log writer
   261         // Log writer
   269         CEventLogger* iLogger;
   262         CEventLogger* iLogger;
   270         // The next event specification ID
   263         // The next event specification ID
   271         // (used with SIT event listening requests)
   264         // (used with SIT event listening requests)
   272         TInt iNextEventSpecId;
   265         TInt iNextEventSpecId;
   288         static const CPolicyServer::TPolicyElement iElements[];
   281         static const CPolicyServer::TPolicyElement iElements[];
   289         static const CPolicyServer::TPolicy iPolicy;
   282         static const CPolicyServer::TPolicy iPolicy;
   290 
   283 
   291     };
   284     };
   292 
   285 
   293 // CLASS DECLARATION
       
   294 
       
   295 /**
       
   296 * Defines the session to the VPN manager server. 
       
   297 */
       
   298 class CEventMediatorSession : public CSession2
       
   299     {
       
   300     public: //Message types
       
   301         enum
       
   302             {
       
   303             KEventMediatorListen,
       
   304             KEventMediatorListenWithSpec,
       
   305             KEventMediatorCancel,
       
   306             KEventMediatorCancelWithSpec,
       
   307             KEventMediatorCancelAll,
       
   308             KEventMediatorReportEvent,
       
   309             KEventMediatorReportEventWithSpec,
       
   310             KEventMediatorFetchData,
       
   311             KEventMediatorReportLogEvent,
       
   312             KEventMediatorNewEventSpecId,
       
   313             KEventMediatorDeletePrivateFiles,
       
   314             KEventMediatorGetEventLogSize,
       
   315             KEventMediatorGetEventLogHeader,
       
   316             KEventMediatorGetEventLogData,
       
   317             KEventMediatorClearEventLog
       
   318             };
       
   319     
       
   320     public: // Methods
       
   321 
       
   322     // Constructors and destructor
       
   323 
       
   324         /**
       
   325         * Static constructor
       
   326         */
       
   327         static CEventMediatorSession* NewL(CEventMediatorServer* aServer, const RMessage2& aMessage);
       
   328         
       
   329         /**
       
   330         * Default destructor
       
   331         */
       
   332         ~CEventMediatorSession(void);
       
   333 
       
   334         /**
       
   335         * Wrapper function which Dispatches and executes the client's service calls
       
   336         * (See Message type definition).
       
   337         */
       
   338         void ServiceL(const RMessage2& aMessage);
       
   339 
       
   340         /**
       
   341          * Checks if client is listening events of the given type and completes message 
       
   342          * sent by clients ListenToEvent function. The length of the event data and
       
   343          * the pointer to that data are written to the message.
       
   344          * @param aType: type of the event.
       
   345          * @param aSpec: additional info on event.
       
   346          * @param aData: event data.
       
   347          * @return number of listeners for the event was listened.
       
   348          */
       
   349         TInt CheckEventL(const TEventType aType, const TDesC8* aSpec, const TDesC8* aData, TInt aStatus);
       
   350 
       
   351         /**
       
   352          * Tries to find a task request that is not being fulfilled
       
   353          * already
       
   354          */
       
   355         CListenerContainer* FindWaitingTaskRequest();
       
   356 
       
   357         /**
       
   358          * Retrieves the event listener object, if any, that is using
       
   359          * the SIT that is fulfilling the specified event.
       
   360          */
       
   361         CListenerContainer* FindListener(TEventType aEventType, TInt aEventSpecId);
       
   362         
       
   363         /**
       
   364          * Retrieves the event listener object, if any, that is using
       
   365          * the SIT that is fulfilling the specified event.
       
   366          */
       
   367         CListenerContainer* FindListener(TEventType aEventType, const TDesC8* aEventSpec);
       
   368 
       
   369         /**
       
   370          * Completes the specified listener if it is owned by the
       
   371          * session. Returns ETrue is the listener was found and
       
   372          * completed, EFalse otherwise.
       
   373          */
       
   374         void CompleteListener(TEventType aEventType, const TDesC8* aEventSpec, TInt aStatus);
       
   375 
       
   376         void CompleteTaskRequests(TInt aStatus);
       
   377 
       
   378         TBool IsASitSession();
       
   379         
       
   380     private: //Methods
       
   381     // Constructors and destructor
       
   382 
       
   383         /**
       
   384         * Constructor
       
   385         */
       
   386         CEventMediatorSession(CEventMediatorServer* aServer);
       
   387 
       
   388         /**
       
   389          * Starts listening events of requesteed type by coping the message to iListenedEvents.
       
   390          * @param aMessage: aMessage sent by clients ListenToEvent function.
       
   391          * @return: error code, KErrNone if successfull.
       
   392          */
       
   393         TInt ListenToEventWithSpecL(const RMessage2& aMessage);
       
   394 
       
   395         /**
       
   396          * Starts listening events of requesteed type by coping the message to iListenedEvents.
       
   397          * @param aMessage: aMessage sent by clients ListenToEvent function.
       
   398          * @return: error code, KErrNone if successfull.
       
   399          */
       
   400         TInt ListenToEventL(const RMessage2& aMessage);
       
   401 
       
   402         /**
       
   403          * Reports the event contained in the message to the event mediator server.
       
   404          * @param aMessage: aMessage sent by clients ReportEvent function.
       
   405          * @return: error code, KErrNone if successfull.
       
   406          */
       
   407         void ReportEventL(const RMessage2& aMessage);
       
   408 
       
   409         /**
       
   410          * Reports a log event contained in the message to the event mediator server.
       
   411          * @param aMessage: aMessage sent by clients ReportLogEvent function.
       
   412          * @return: error code, KErrNone if successfull.
       
   413          */
       
   414         void ReportLogEventL(const RMessage2& aMessage);
       
   415 
       
   416         /**
       
   417          * Reports the event contained in the message to the event mediator server.
       
   418          * @param aMessage: aMessage sent by clients ReportEvent function.
       
   419          * @return: error code, KErrNone if successfull.
       
   420          */
       
   421         void ReportEventWithSpecL(const RMessage2& aMessage);
       
   422 
       
   423         /**
       
   424          * Cancels listning of one event type.
       
   425          * @param aMessage: aMessage sent by clients CancelListenToEvent function.
       
   426          */
       
   427         void CancelListening(const RMessage2& aMessage);
       
   428 
       
   429         /**
       
   430          * Cancels listning of one event type.
       
   431          * @param aMessage: aMessage sent by clients CancelListenToEvent function.
       
   432          */
       
   433         void CancelListeningWithSpecL(const RMessage2& aMessage);
       
   434 
       
   435         /**
       
   436          * Cancels all listening.
       
   437          * @param aMessage: aMessage sent by clients CancelAllListening function.
       
   438          */
       
   439         void CancelAll();
       
   440 
       
   441         /**
       
   442          * Copies event data from the server to the client.
       
   443          * @param aMessage: aMessage sent by clients FetchData function.
       
   444          * @return: error code, KErrNone if successfull.
       
   445          */
       
   446         TInt FetchDataL(const RMessage2& aMessage);
       
   447 
       
   448         /**
       
   449          * Looks up a message from iListenedEvents.
       
   450          * @param aType: type of the event the message is listening to.
       
   451          * @param aIndex: the position of the message in iListenedEvents.
       
   452          * @return ETrue if message exists, EFalse if not.
       
   453          */
       
   454         TBool FindListenerMsg(const TEventType aType,TInt& index);
       
   455 
       
   456         /**
       
   457          * Looks up a message from iListenedEvents.
       
   458          * @param aType: type of the event the message is listening to.
       
   459          * @param aIndex: the position of the message in iListenedEvents.
       
   460          * @return ETrue if message exists, EFalse if not.
       
   461          */
       
   462         TBool FindListenerMsg(const TEventType aType,const TDesC8* aSpec,TInt& index);
       
   463 
       
   464         /**
       
   465          * Searches for a task request type event listening request
       
   466          */
       
   467         TBool FindTaskRequestListenerMsg(TInt& index);
       
   468         
       
   469         /**
       
   470          * Reads data that was reported with the event from client. Allocates a buffer
       
   471          * for data and gives ownership of that buffer to caller.
       
   472          * @param aMessage: aMessage sent by clients ReportEvent function.
       
   473          * @return pointer to the newly created buffer containig data.
       
   474          */
       
   475         HBufC8* ReadEventDataFromClientL(const RMessage2& aMessage);
       
   476 
       
   477         /**
       
   478          * Reads specification describing the event from client. Allocates a buffer
       
   479          * for secification and gives ownership of that buffer to caller.
       
   480          * @param aMessage: aMessage sent with event specification.
       
   481          * @return pointer to the newly created buffer containig data.
       
   482          */
       
   483         HBufC8* ReadSpecificationFromClientL(const RMessage2& aMessage);
       
   484 
       
   485         /**
       
   486          * Completes the specified listener and deletes it from the
       
   487          * listener list
       
   488          */
       
   489         void CompleteListener(TInt aIndex, TInt aStatus);
       
   490 
       
   491         /**
       
   492          * Returns to the client a new event specification ID
       
   493          */
       
   494         void NewEventSpecIdL(const RMessage2& aMessage);
       
   495 
       
   496         TInt DeletePrivateFiles();
       
   497         void DeletePrivateFilesL();
       
   498         
       
   499         TInt GetEventLogSize(const RMessage2& aMessage);
       
   500         TInt GetEventLogHeader(const RMessage2& aMessage);
       
   501         TInt GetEventLogData(const RMessage2& aMessage);
       
   502         TInt ClearEventLog();
       
   503         
       
   504     private: //Data
       
   505         // List of messages listening to events
       
   506         CArrayFixFlat<CListenerContainer*> iListenedEvents;
       
   507         // Event mediator server
       
   508         CEventMediatorServer* iServer;
       
   509 
       
   510         RFs     iFs;
       
   511         RFile   iEventLogFile;
       
   512         TBool   iEventLogFileOpen;
       
   513         // Is this session from a SIT or not
       
   514 
       
   515     public:        
       
   516         TBool iIsSitSession;
       
   517     };
       
   518 
   286 
   519 // CLASS DECLARATION
   287 // CLASS DECLARATION
   520 
   288 
   521 /**
   289 /**
   522 * Container for one reported event from witch it can be read by all listening sessions. 
   290 * Container for one reported event from witch it can be read by all listening sessions. 
   547 class CListenerContainer : public CBase
   315 class CListenerContainer : public CBase
   548     {
   316     {
   549     public: //Methods
   317     public: //Methods
   550     // Constructors and destructor
   318     // Constructors and destructor
   551         CListenerContainer(const RMessage2& aMessage, TDesC8* aSpec,
   319         CListenerContainer(const RMessage2& aMessage, TDesC8* aSpec,
   552                            CEventMediatorServer* aServer);
   320                            CEventMediatorServer& aServer);
   553         ~CListenerContainer();
   321         ~CListenerContainer();
   554 
   322 
   555         inline TEventType Type() {return (TEventType) iMessage.Int0();}
   323         inline TEventType Type() {return (TEventType) iMessage.Int0();}
   556         inline RMessage2& Message() {return iMessage;}
   324         inline RMessage2& Message() {return iMessage;}
   557         inline TDesC8* Specification() {return iSpec;}
   325         inline TDesC8* Specification() {return iSpec;}
   568         // Data descriptor reported with the event.
   336         // Data descriptor reported with the event.
   569         TDesC8*     iSpec;
   337         TDesC8*     iSpec;
   570         RMessage2   iMessage;
   338         RMessage2   iMessage;
   571         TEventType  iEventType;
   339         TEventType  iEventType;
   572         // Pointer to the event mediator server
   340         // Pointer to the event mediator server
   573         CEventMediatorServer* iServer;
   341         CEventMediatorServer& iServer;
   574         // A flag that tells whether the request
   342         // A flag that tells whether the request
   575         // is being fulfilled by the SIT or not
   343         // is being fulfilled by the SIT or not
   576         TBool iBeingFulfilledBySit;
   344         TBool iBeingFulfilledBySit;
   577     };
   345     };
   578 
   346