Multiple simultaneous request support to Communication
[qtmeetings] / src / IO / Communication / CommunicationManager.h
1 #ifndef COMMUNICATIONMANAGER_H_
2 #define COMMUNICATIONMANAGER_H_
3
4 #include <QObject>
5 #include <QList>
6 #include <QDateTime>
7 #include "Communication.h"
8 #include "Room.h"
9 #include "MessagingUtils.h"
10
11 class ConnectionSettings;
12 class Meeting;
13
14 //! Responsible for Exchange server communication and request encoding and response parsing.
15 /*!
16  *  CommunicationManager holds two connections to the Exchange server:
17  *  Fetching and modifying connection. Fetching connetion is read only connection
18  *  which has static authentication information defined in the application configuration.
19  *  The modifying connection's authentication information varies, according to the user interface.
20  * 
21  *  NOTE! Currently Modifying connection is NOT implemented.
22  */
23 class CommunicationManager : public QObject
24 {
25         Q_OBJECT
26
27 public:
28         enum CommunicationType
29         {
30                 FetchingCommunication,
31                 ModifyingCommunication
32         };
33
34 public:
35         //! Constructor.
36         /*! 
37          *  \param aConnection Reference to the fetching ConnectionSettings.
38         */
39         CommunicationManager( const ConnectionSettings &aConnection );
40         virtual ~CommunicationManager();
41         //! Starts fetching meetings. Meetings are returned by the meetingsFetched signal.
42         /*! 
43          *  Calls the MS Exchange GetUserAvailability WebService method. 
44          *  \param aFrom QDateTime to start searching from.
45          *  \param aUntil QDateTime to search meetings until.
46          *  \param aIn Meeting room meetings are searched.
47         */
48         void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room &aIn );
49         //! Starts fetching a meeting details. Details are returned by the meetingDetailsFetched signal.
50         /*! 
51          *  \param aMeeting A meeting the detailed information is wanted.
52         */
53         void fetchMeetingDetails( Meeting &aMeeting );
54 /* Not supported member functions which are using the modifying communication
55         void setModifyCredentials( const QString &aUsername, const QString &aPassword ) {};
56         void createMeeting( const Meeting &aMeeting ) {};
57         void updateMeeting( const Meeting &aMeeting ) {};
58         void deleteMeeting( const Meeting &aMeeting ) {};
59 */
60
61 signals:
62         //! Emitted when an error happens. Error could be QHttp or SOAP related.
63         /*! 
64         *   \param aCode An error code defined by CommunicationManager.
65         *   \param aType FetchingCommunication or ModifyingCommunication.
66         */
67         void error( int aCode, CommunicationManager::CommunicationType aType );
68         //! Emitted when a http request is ongoing. Reports the bytes read from the server.
69         /*! 
70         *   \param aDone Bytes read from the server.
71         *   \param aTotal Bytes total of the response.
72         *   \param aType FetchingCommunication or ModifyingCommunication.
73         */
74         void readProgress( int aDone, int aTotal, CommunicationManager::CommunicationType aType );
75         //! Emitted when meetings are fetched.
76         /*! 
77         *   \param aMeetings Meetings found according to the search criteria.
78         */
79         void meetingsFetched( const QList<Meeting*> &aMeetings );
80         //! Emitted when meeting details are fetched.
81         /*! 
82         *   \param aDetailedMeeting Meeting which contains detailed information.
83         */
84         void meetingDetailsFetched( Meeting &aDetailedMeeting );
85
86 protected slots:
87         //! Connected to Communication::requestFinished.
88         void requestFinished( int aRequestId, int aError );
89         //! Connected to Communication::readProgress.
90         void readProgress( int aRequestId, int aDone, int aTotal );
91         
92 protected:
93         //! Gets the secondary id number of a meeting.
94         /*! 
95          *  Calls the MS Exchange ConvertId WebService method. Converts primary id
96          *  number to secondary id number.
97          *  \param aMeeting A meeting which contains primaryId number.
98         */
99         void getSecondaryIdForMeeting( Meeting &aMeeting );
100         //! Gets the details of a meeting.
101         /*! 
102          *  Calls the MS Exchange GetCalendarItem WebService method.
103          *  \param aMeeting A meeting the detailed information is wanted.
104         */
105         void getMeetingDetails( Meeting &aMeeting );
106         
107         /*! 
108          *  Lists the WebService methods known by the CommunicationManager.
109         */
110         enum RequestType
111         {
112                 GetUserAvailability = 1,
113                 ConvertId,
114                 GetCalendarItem
115         };
116         //! Internal data structure which contains data about requests made to Exchange server.
117         class RequestData
118         {
119         public:
120                 RequestData( RequestType aType, int aRequestId ) : 
121                         type( aType ), requestId( aRequestId ), room( NULL ), meeting( NULL ) {};
122                 ~RequestData()
123                 {
124                         if( type == GetUserAvailability )
125                                 delete room;
126                 };
127                 //! Holds one of the enum RequestType value
128                 RequestType type;
129                 //! Request ID number returned by the Communication::request
130                 int requestId;
131                 //! Pointer to a Room related to this request. NULL by default. Owned.
132                 Room* room;
133                 //! Pointer to a Meeting related to this request. Not owned.
134                 Meeting* meeting;
135         };
136         //! Adds a request to the iRequestInfos list.
137         /*! 
138          *  \param aType One of the enum RequestType value.
139          *  \param aRequestId Request ID number returned by the Communication::request
140         */
141         void addRequest( RequestType aType, int aRequestId );
142         //! Takes RequestData off from the iRequestInfos list.
143         /*! 
144          *  Returns a pointer to RequestData data structure. Removes RequestData from
145          *  the iRequestInfos list.
146          *  \param aRequestId Request ID number returned by the Communication::request
147         */
148         RequestData* takeRequest( int aRequestId );
149         //! Finds a RequestData from the iRequestInfos list.
150         /*! 
151          *  Returns a pointer to RequestData, NULL if not found.
152          *  \param aRequestType Request type
153         */
154         const RequestData* findRequest( RequestType aRequestType ) const;
155         
156 private:
157         //! Instance of Connection settings of the fetching communication
158         ConnectionSettings *iConnectionSettings;
159         //! Instance of the fetching communication
160         Communication* iFetchingCommunication;
161         //! Instance of the modifying communication
162         Communication* iModifyingCommunication;
163         //! Temporary list which holds the lastest meetings fetched
164         QList<Meeting*> iMeetings;
165         //! Additional information about requests made to the Exchange server
166         QList<RequestData*> iRequestInfos;
167 };
168
169 #endif /*COMMUNICATIONMANAGER_H_*/