The TimetableManager class is the main access point to the API functionality.
This class manages all the state used by the API. API functions that require
only global state are methods of this class. API functions that require
per-session state are methods of UserSession
or CourseLoad
.
UserSession
objects are created by calling TimetableManager::StartSession()
(course loads, in turn, are created by
calling UserSession::NewCourseLoad()
or UserSession::OpenCourseLoad()
).
A program using the API should have a single instance of TimetableManager,
created using the static method TimetableManager::Create()
. API functions are then called on this
instance.
Here is an outline of the TimetableManager class:
class TimetableManager { public: // Creates the single TimetableManager instance. static TimetableManager& Create(const string& data_files_path = ""); // API functions that use global state vector<string> GetCourseDataFileNames() const; void UpdateTimetableData(ProgressIndicator progress_indicator); void LoadTimetableData(ITimetableDataSource& source, ProgressIndicator progress_indicator); void ReloadData(); // API functions for managing sessions UserSession StartSession() const; };
static TimetableManager& TimetableManager::Create(const string& data_files_path = "");
Creates the singleton instance of TimetableManager
.
const string& data_files_path = ""
The filesystem path where the data files used by the API are stored. If left blank (the default), the API will look for the data files in the directory where the executable that is using the API is located (on Windows), or the current working directory of the process using the API (on Linux).
vector<string> GetCourseDataFileNames() const;
Returns a list of the filenames of all course timetable data files,
including the prefix specified in TimetableManager
::Create()
.
void TimetableManager::UpdateTimetableData(ProgressIndicator progress_indicator);
Updates the course timetable data files managed by the API by downloading and parsing the latest data from the relevant university websites.
This function may be called while user sessions are active. Course loads opened from user sessions created before this call will use the course timetable data prior to the update, and those opened from user sessions created after this call will use the updated data.
ProgressIndicator progress_indicator
Used to report the progress of the downloading. This is useful for some clients as the downloading can take a user-noticeably long time.
void TimetableManager::LoadTimetableData(ITimetableDataSource& source, ProgressIndicator progress_indicator);
Replace the API's internal course timetable data files with timetable
data from the specified ITimetableDataSource
.
This function will call source
's
get_reader()
method for each course timetable data file, read the data from the
returned istream
, and
replace its internal copy of the data file with the read data.
This function may be called while user sessions are active. Course loads opened from user sessions created before this call will use the course timetable data prior to the update, and those opened from user sessions created after this call will use the updated data.
ProgressIndicator progress_indicator
Used to report the progress of the loading. This is useful in cases
where get_reader()
does something time-consuming, such as download the course timetable
data file from a website.
Related: GetCourseDataFileNames()
returns the names of all course timetable
data files.
void TimetableManager::ReloadData();
Reload all data from internal data files. This includes timetable data, data from sessions.txt and data from altwkexcept.txt (for more information, see Data Files Used by the API). This should be called when sessions.txt or altwkexcept.txt changes.
This function may be called while user sessions are active. Course loads opened from user sessions created before this call will use the course timetable data prior to the update, and those opened from user sessions created after this call will use the updated data.
UserSession TimetableManager::StartSession() const;
Creates a new user session. The user session can be used to create
course loads via NewCourseLoad()
or OpenCourseLoad()
. The resources used by the user session
and the course loads will be freed when the respective objects go out
of scope.