/** * Exercises Handler - Handle all information which is needed for AVS to create the proper AV-Streams for a specific context * $Id$ * $HeadURL$ * $Author$ * Created by Christian Ehrlicher, SLSE, 2016-10-20 */ #pragma once #include #include #include #include #include #include #include "av_control.h" #include "fm_control.h" #include "exercise_context.h" #include "logger.h" #include namespace AudioVideoManagement { class MainHandler; class ExercisesHandler; /** * The ExerciseHandler observes the Exercise's state changes and translates * our states into states known to AVS. * The wanted AVS state is communicated to AVS via RCP/AVE (see AVControl). * * The ExerciseHandler also ensures that there exist two device_config entries -- * one for the playback and one for the record session. * * Furthermore the ExerciseHandler observes the lifetime of the Exercise. * Once the Exercise is terminated, AVS is requested to delete all data * related to that Exercise. Once that is done, the device_config entries are * removed and removeMeImFinished() is signalled. */ class ExerciseHandler : public QObject { Q_OBJECT public: ExerciseHandler(MainHandler *mainHandler, int exerciseId); static QString avTypeRecordSession() { return QStringLiteral("RECORD_SESSION"); } static QString avTypePlaybackSession() { return QStringLiteral("PLAYBACK_SESSION"); } const ExerciseContext &context() const { return m_exContext; } QString contextString() const { return m_exContext.toString(); } /** * Called by ExercisesHandler whenever the exercise state changed. */ void setNewExerciseState(ExerciseManagement::ExerciseState newState); /** * Public as the ExercisesHandler adds the Record- and ReplaySession * after instantiation in case they already exist when the application starts. */ void addDeviceConfig(const Database::AvmDeviceConfig &config); /** * Called once directly after instantiation if upon startup of the service * there exists an entry in exercise_last_seen for this exercise. */ void setLastSeen(const Database::AvmExerciseLastSeen &lastSeen); signals: /** * @name Signals that notify a state change regarding the notion of whether the * context is active or not. * A context is considered active when the corresponding excercise has one of the * following states: Started, Paused, Resumed. * The state can only change from activated to deactivated but not back. */ ///@{ void contextActivated(); void contextDeactivated(); ///@} /** Signalled after the exercise has been removed from AVS. */ void removeMeImFinished(int exerciseId); /** Signalled after device_config modifications. */ void avDbReloadNeeded(); private slots: void onUpdateTimerTimeout(); void onLastSeenTimerTimeout(); void onOperatingModeChanged(const ExerciseContext &context, AVControl::Component comp, AVControl::OperatingMode om); void onContextFilesDeleted(const ExerciseContext &context); void onAvSuccessfullyLoggedIn(); private: // methods void checkForRecordPlaybackSession(); static AVControl::OperatingMode avModeFromExerciseState(ExerciseManagement::ExerciseState state); bool isTerminating() const; AVControl *avControl() const; FMControl *fmControl() const; DatabaseInterface *db() const; ExerciseManagement::Interface::Dtc *exmDtc() const; private: // attributes Database::AvmDeviceConfig m_recordSession; Database::AvmDeviceConfig m_replaySession; ExerciseContext m_exContext; ExerciseManagement::ExerciseState m_curExerciseState; Database::AvmExerciseLastSeen m_lastSeen; AVControl::OperatingMode m_curAVOperatingMode; MainHandler *m_mainHandler; QTimer *m_updateTimer; QTimer *m_lastSeenTimer; bool m_bWarnedOnce; LOGGER_T m_logger; }; } // namespace AudioVideoManagement