1 #ifndef COMMUNICATIONMANAGER_H_
2 #define COMMUNICATIONMANAGER_H_
7 #include "Communication.h"
9 #include "MessagingUtils.h"
11 class ConnectionSettings;
14 //! Responsible for Exchange server communication and request encoding and response parsing.
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.
21 * NOTE! Currently Modifying connection is NOT implemented.
23 class CommunicationManager : public QObject
28 enum CommunicationType
30 FetchingCommunication,
31 ModifyingCommunication
37 * \param aConnection Reference to the fetching ConnectionSettings.
39 CommunicationManager( const ConnectionSettings &aConnection );
40 virtual ~CommunicationManager();
41 //! Starts fetching meetings. Meetings are returned by the meetingsFetched signal.
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.
48 void fetchMeetings( /*const QDateTime &aFrom, const QDateTime &aUntil*/const int aWeek, const int aYear, const Room &aIn );
49 //! Starts fetching a meeting details. Details are returned by the meetingDetailsFetched signal.
51 * \param aMeeting A meeting the detailed information is wanted.
53 void fetchMeetingDetails( Meeting &aMeeting );
54 //! Cancels all meeting detail requests.
55 void cancelFetchMeetingDetails();
56 /* Not supported member functions which are using the modifying communication
57 void setModifyCredentials( const QString &aUsername, const QString &aPassword ) {};
58 void createMeeting( const Meeting &aMeeting ) {};
59 void updateMeeting( const Meeting &aMeeting ) {};
60 void deleteMeeting( const Meeting &aMeeting ) {};
64 //! Emitted when an error happens. Error could be QHttp or SOAP related.
66 * \param aCode An error code defined by CommunicationManager.
67 * \param aType FetchingCommunication or ModifyingCommunication.
69 void error( int aCode, CommunicationManager::CommunicationType aType );
70 //! Emitted when a http request is ongoing. Reports the bytes read from the server.
72 * \param aDone Bytes read from the server.
73 * \param aTotal Bytes total of the response.
74 * \param aType FetchingCommunication or ModifyingCommunication.
76 void readProgress( int aDone, int aTotal, CommunicationManager::CommunicationType aType );
77 //! Emitted when meetings are fetched.
79 * \param aMeetings Meetings found according to the search criteria.
81 void meetingsFetched( const QList<Meeting*> &aMeetings );
82 //! Emitted when meeting details are fetched.
84 * \param aDetailedMeeting Meeting which contains detailed information.
86 void meetingDetailsFetched( Meeting &aDetailedMeeting );
89 //! Connected to Communication::requestFinished.
90 void requestFinished( int aRequestId, int aError );
91 //! Connected to Communication::readProgress.
92 void readProgress( int aRequestId, int aDone, int aTotal );
95 //! Gets the secondary id number of a meeting.
97 * Calls the MS Exchange ConvertId WebService method. Converts primary id
98 * number to secondary id number.
99 * \param aMeeting A meeting which contains primaryId number.
101 void getSecondaryIdForMeeting( Meeting &aMeeting );
102 //! Gets the details of a meeting.
104 * Calls the MS Exchange GetCalendarItem WebService method.
105 * \param aMeeting A meeting the detailed information is wanted.
107 void getMeetingDetails( Meeting &aMeeting );
110 * Lists the WebService methods known by the CommunicationManager.
114 GetUserAvailability = 1,
118 //! Internal data structure which contains data about requests made to Exchange server.
122 RequestData( RequestType aType, int aRequestId ) :
123 type( aType ), requestId( aRequestId ), room( NULL ), meeting( NULL ) {};
126 if( type == GetUserAvailability )
129 //! Holds one of the enum RequestType value
131 //! Request ID number returned by the Communication::request
133 //! Pointer to a Room related to this request. NULL by default. Owned.
135 //! Pointer to a Meeting related to this request. Not owned.
138 //! Adds a request to the iRequestInfos list.
140 * \param aType One of the enum RequestType value.
141 * \param aRequestId Request ID number returned by the Communication::request
143 void addRequest( RequestType aType, int aRequestId );
144 //! Takes RequestData off from the iRequestInfos list.
146 * Returns a pointer to RequestData data structure. Removes RequestData from
147 * the iRequestInfos list.
148 * \param aRequestId Request ID number returned by the Communication::request
150 RequestData* takeRequest( int aRequestId );
151 //! Finds a RequestData from the iRequestInfos list.
153 * Returns a pointer to RequestData, NULL if not found.
154 * \param aRequestType Request type
156 const RequestData* findRequest( RequestType aRequestType ) const;
159 //! Instance of Connection settings of the fetching communication
160 ConnectionSettings *iConnectionSettings;
161 //! Instance of the fetching communication
162 Communication* iFetchingCommunication;
163 //! Instance of the modifying communication
164 Communication* iModifyingCommunication;
165 //! Temporary list which holds the lastest meetings fetched
166 QList<Meeting*> iMeetings;
167 //! Additional information about requests made to the Exchange server
168 QList<RequestData*> iRequestInfos;
169 //! A flag that all meeting detail requests has been cancelled
170 QList<int> iCancelledRequests;
173 #endif /*COMMUNICATIONMANAGER_H_*/