From: Michal MalĂ˝ Date: Wed, 29 Jul 2015 23:51:27 +0000 (+0200) Subject: Finish modularization. Other FFB APIs can now be added X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=0a3852cb9cc3365a80af2df663567a47ab49b47d;p=FFBChecker.git Finish modularization. Other FFB APIs can now be added --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 512ee97..4cf7a25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,19 +25,20 @@ set(FFBChecker_SRCS constanteffectsettings.cpp effectsettings.cpp envelopesettings.cpp - ffbconditioneffect.cpp + linuxffbconditioneffect.cpp ffbconditioneffectparameters.cpp - ffbconstanteffect.cpp + linuxffbconstanteffect.cpp ffbconstanteffectparameters.cpp ffbdevice.cpp ffbeffect.cpp - ffbeffectfactory.cpp + linuxffbeffect.cpp + linuxffbeffectfactory.cpp ffbeffectparameters.cpp ffbenvelopeparameters.cpp ffbnulleffect.cpp - ffbperiodiceffect.cpp + linuxffbperiodiceffect.cpp ffbperiodiceffectparameters.cpp - ffbrampeffect.cpp + linuxffbrampeffect.cpp ffbrampeffectparameters.cpp ffbrumbleeffect.cpp ffbrumbleeffectparameters.cpp diff --git a/ffbdevice.cpp b/ffbdevice.cpp index a2424af..822dfe5 100644 --- a/ffbdevice.cpp +++ b/ffbdevice.cpp @@ -1,5 +1,4 @@ #include "ffbdevice.h" -#include "ffbeffectfactory.h" const std::vector& FFBDevice::availableConditionSubtypesList() const { diff --git a/ffbeffect.cpp b/ffbeffect.cpp index 21fa75a..a496094 100644 --- a/ffbeffect.cpp +++ b/ffbeffect.cpp @@ -1,60 +1,12 @@ #include "ffbeffect.h" #include "globalsettings.h" -#include FFBEffect::FFBEffect(FFBEffectTypes type) { - m_internalIdx = -1; m_status = FFBEffectStatus::NOT_LOADED; m_type = type; } -struct ff_effect* FFBEffect::createFFStruct(const std::shared_ptr params) -{ - struct ff_effect* eff = new struct ff_effect; - memset(eff, 0, sizeof(struct ff_effect)); - - eff->id = m_internalIdx; - eff->direction = params->direction; - eff->replay.delay = params->replayDelay; - eff->replay.length = params->replayLength; - - return eff; -} - -void FFBEffect::reportError(const QString& errorMsg) const -{ - QMessageBox::warning(nullptr, "FFB effect error", errorMsg); -} - -bool FFBEffect::checkGenericParameters(const std::shared_ptr params) -{ - if (!GlobalSettings::GS()->doSanityChecks) - return true; - - if (params->repeat < 1) { - reportError("Effect must be played back at least once."); - return false; - } - - if (!checkBoundsInclusive(params->direction, 0, 0xFFFF)) { - reportError("Direction out of bounds."); - return false; - } - - if (!checkBoundsInclusive(params->replayDelay, 0, 0x7FFF)) { - reportError("Replay delay out of bounds."); - return false; - } - - if (!checkBoundsInclusive(params->replayLength, 0, 0x7FFF)) { - reportError("Replay length out of bounds."); - return false; - } - - return true; -} - bool FFBEffect::operator==(const FFBEffect& other) const { return this->type() == other.type(); diff --git a/ffbeffect.h b/ffbeffect.h index 36bb5d6..aa294ae 100644 --- a/ffbeffect.h +++ b/ffbeffect.h @@ -4,18 +4,13 @@ #include "ffbeffectparameters.h" #include "globals.h" #include -#include class FFBEffect { public: enum class FFBEffectStatus { PLAYING, UPLOADED, NOT_LOADED }; explicit FFBEffect(FFBEffectTypes type); - virtual struct ff_effect* createFFStruct() = 0; - inline int internalIdx() const { return m_internalIdx; } virtual const std::shared_ptr parameters() const = 0; - void reportError(const QString& errorMsg) const; - inline void setInternalIdx(int idx) { m_internalIdx = idx; } virtual bool setParameters(const std::shared_ptr params) = 0; inline void setStatus(FFBEffectStatus status) { m_status = status; } inline FFBEffectStatus status() const { return m_status; } @@ -25,18 +20,12 @@ public: virtual bool operator!=(const FFBEffect&) const; protected: - struct ff_effect* createFFStruct(const std::shared_ptr params); - bool checkGenericParameters(const std::shared_ptr params); + virtual bool checkGenericParameters(const std::shared_ptr params) = 0; private: - int m_internalIdx; FFBEffectStatus m_status; FFBEffectTypes m_type; -signals: - -public slots: - }; #endif // FFBEFFECT_H diff --git a/ffbeffectfactory.cpp b/ffbeffectfactory.cpp deleted file mode 100644 index 41462cf..0000000 --- a/ffbeffectfactory.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "ffbeffectfactory.h" - -FFBEffectFactory::FFBEffectFactory() -{ -} - -std::shared_ptr FFBEffectFactory::createEffect(FFBEffectTypes type) -{ - switch (type) { - case FFBEffectTypes::NONE: - return std::shared_ptr(new FFBNullEffect()); - case FFBEffectTypes::CONSTANT: - return std::shared_ptr(new FFBConstantEffect()); - case FFBEffectTypes::PERIODIC: - return std::shared_ptr(new FFBPeriodicEffect()); - case FFBEffectTypes::CONDITION: - return std::shared_ptr(new FFBConditionEffect()); - case FFBEffectTypes::RAMP: - return std::shared_ptr(new FFBRampEffect()); - case FFBEffectTypes::RUMBLE: - return std::shared_ptr(new FFBRumbleEffect()); - default: - return nullptr; - } -} diff --git a/ffbeffectfactory.h b/ffbeffectfactory.h deleted file mode 100644 index a276be9..0000000 --- a/ffbeffectfactory.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FFBEFFECTFACTORY_H -#define FFBEFFECTFACTORY_H - -#include "globals.h" -#include "ffbconditioneffect.h" -#include "ffbconstanteffect.h" -#include "ffbnulleffect.h" -#include "ffbperiodiceffect.h" -#include "ffbrampeffect.h" -#include "ffbrumbleeffect.h" - -class FFBEffectFactory -{ -public: - static std::shared_ptr createEffect(FFBEffectTypes type); - -private: - FFBEffectFactory(); - -}; - -#endif // FFBEFFECTFACTORY_H diff --git a/ffbnulleffect.h b/ffbnulleffect.h index 5829574..2aa896c 100644 --- a/ffbnulleffect.h +++ b/ffbnulleffect.h @@ -7,9 +7,11 @@ class FFBNullEffect : public FFBEffect { public: explicit FFBNullEffect(); - inline struct ff_effect* createFFStruct() { return nullptr; } inline const std::shared_ptr parameters() const { return nullptr; } inline bool setParameters(const std::shared_ptr params) { (void)(params); return false; } + +protected: + bool checkGenericParameters(const std::shared_ptr params) { Q_UNUSED(params); return false; } }; #endif // FFBNULLEFFECT_H diff --git a/ffbrumbleeffect.cpp b/ffbrumbleeffect.cpp index 8a1ab82..e6f58f4 100644 --- a/ffbrumbleeffect.cpp +++ b/ffbrumbleeffect.cpp @@ -1,13 +1,13 @@ -#include "ffbrumbleeffect.h" +#include "linuxffbrumbleeffect.h" -FFBRumbleEffect::FFBRumbleEffect() : - FFBEffect(FFBEffectTypes::RUMBLE) +LinuxFFBRumbleEffect::LinuxFFBRumbleEffect() : + LinuxFFBEffect(FFBEffectTypes::RUMBLE) { } -struct ff_effect* FFBRumbleEffect::createFFStruct() +struct ff_effect* LinuxFFBRumbleEffect::createFFStruct() { - struct ff_effect* eff = FFBEffect::createFFStruct(m_params); + struct ff_effect* eff = LinuxFFBEffect::createFFStruct(m_params); eff->type = FF_RUMBLE; @@ -17,7 +17,7 @@ struct ff_effect* FFBRumbleEffect::createFFStruct() return eff; } -bool FFBRumbleEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBRumbleEffect::setParameters(const std::shared_ptr params) { try { return setParameters(std::dynamic_pointer_cast(params)); @@ -27,7 +27,7 @@ bool FFBRumbleEffect::setParameters(const std::shared_ptr p } } -bool FFBRumbleEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBRumbleEffect::setParameters(const std::shared_ptr params) { if (!checkGenericParameters(params)) return false; diff --git a/ffbconditioneffect.cpp b/linuxffbconditioneffect.cpp similarity index 87% rename from ffbconditioneffect.cpp rename to linuxffbconditioneffect.cpp index 7e6ef21..9b3d5fd 100644 --- a/ffbconditioneffect.cpp +++ b/linuxffbconditioneffect.cpp @@ -1,13 +1,13 @@ -#include "ffbconditioneffect.h" +#include "linuxffbconditioneffect.h" #include "globalsettings.h" -FFBConditionEffect::FFBConditionEffect() : - FFBEffect(FFBEffectTypes::CONDITION) +LinuxFFBConditionEffect::LinuxFFBConditionEffect() : + LinuxFFBEffect(FFBEffectTypes::CONDITION) {} -struct ff_effect* FFBConditionEffect::createFFStruct() +struct ff_effect* LinuxFFBConditionEffect::createFFStruct() { - struct ff_effect* eff = FFBEffect::createFFStruct(m_params); + struct ff_effect* eff = LinuxFFBEffect::createFFStruct(m_params); eff->u.condition[0].center = m_params->center[FFBConditionEffectParameters::Axis::X]; eff->u.condition[0].deadband = m_params->deadband[FFBConditionEffectParameters::Axis::X]; @@ -45,7 +45,7 @@ struct ff_effect* FFBConditionEffect::createFFStruct() return eff; } -bool FFBConditionEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBConditionEffect::setParameters(const std::shared_ptr params) { try { return setParameters(std::dynamic_pointer_cast(params)); @@ -56,7 +56,7 @@ bool FFBConditionEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBConditionEffect::setParameters(const std::shared_ptr params) { if (!checkGenericParameters(params)) return false; @@ -126,13 +126,13 @@ bool FFBConditionEffect::setParameters(const std::shared_ptrtype() != other.type()) return false; else { try { - const FFBConditionEffect& cother = dynamic_cast(other); + const LinuxFFBConditionEffect& cother = dynamic_cast(other); return this->m_params->subtype == cother.m_params->subtype; } catch (std::bad_cast&) { return false; diff --git a/ffbconditioneffect.h b/linuxffbconditioneffect.h similarity index 67% rename from ffbconditioneffect.h rename to linuxffbconditioneffect.h index 8bc7869..ea7adcc 100644 --- a/ffbconditioneffect.h +++ b/linuxffbconditioneffect.h @@ -1,13 +1,13 @@ -#ifndef FFBCONDITIONEFFECT_H -#define FFBCONDITIONEFFECT_H +#ifndef LINUXFFBCONDITIONEFFECT_H +#define LINUXFFBCONDITIONEFFECT_H -#include "ffbeffect.h" +#include "linuxffbeffect.h" #include "ffbconditioneffectparameters.h" -class FFBConditionEffect : public FFBEffect +class LinuxFFBConditionEffect : public LinuxFFBEffect { public: - explicit FFBConditionEffect(); + explicit LinuxFFBConditionEffect(); struct ff_effect* createFFStruct(); inline const std::shared_ptr parameters() const { return m_params; } bool setParameters(const std::shared_ptr params); @@ -18,4 +18,4 @@ private: std::shared_ptr m_params; }; -#endif // FFBCONDITIONEFFECT_H +#endif // FFBCONDITIONEFFECT_H \ No newline at end of file diff --git a/ffbconstanteffect.cpp b/linuxffbconstanteffect.cpp similarity index 75% rename from ffbconstanteffect.cpp rename to linuxffbconstanteffect.cpp index 879dd11..347d96f 100644 --- a/ffbconstanteffect.cpp +++ b/linuxffbconstanteffect.cpp @@ -1,15 +1,14 @@ -#include "ffbconstanteffect.h" +#include "linuxffbconstanteffect.h" #include "globalsettings.h" -FFBConstantEffect::FFBConstantEffect() : - FFBEffect(FFBEffectTypes::CONSTANT) -{ -} +LinuxFFBConstantEffect::LinuxFFBConstantEffect() : + LinuxFFBEffect(FFBEffectTypes::CONSTANT) +{} -struct ff_effect* FFBConstantEffect::createFFStruct() +struct ff_effect* LinuxFFBConstantEffect::createFFStruct() { /* Set up generic effect parameters */ - struct ff_effect* eff = FFBEffect::createFFStruct(m_params); + struct ff_effect* eff = LinuxFFBEffect::createFFStruct(m_params); eff->type = FF_CONSTANT; @@ -23,7 +22,7 @@ struct ff_effect* FFBConstantEffect::createFFStruct() return eff; } -bool FFBConstantEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBConstantEffect::setParameters(const std::shared_ptr params) { try { return setParameters(std::dynamic_pointer_cast(params)); @@ -33,7 +32,7 @@ bool FFBConstantEffect::setParameters(const std::shared_ptr return false; } -bool FFBConstantEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBConstantEffect::setParameters(const std::shared_ptr params) { if (!checkGenericParameters(params)) return false; diff --git a/ffbconstanteffect.h b/linuxffbconstanteffect.h similarity index 65% rename from ffbconstanteffect.h rename to linuxffbconstanteffect.h index 05a907e..4d6d0ab 100644 --- a/ffbconstanteffect.h +++ b/linuxffbconstanteffect.h @@ -1,13 +1,13 @@ -#ifndef FFBCONSTANTEFFECT_H -#define FFBCONSTANTEFFECT_H +#ifndef LINUXFFBCONSTANTEFFECT_H +#define LINUXFFBCONSTANTEFFECT_H -#include "ffbeffect.h" +#include "linuxffbeffect.h" #include "ffbconstanteffectparameters.h" -class FFBConstantEffect : public FFBEffect +class LinuxFFBConstantEffect : public LinuxFFBEffect { public: - explicit FFBConstantEffect(); + explicit LinuxFFBConstantEffect(); struct ff_effect* createFFStruct(); inline const std::shared_ptr parameters() const { return m_params; } bool setParameters(const std::shared_ptr params); @@ -17,4 +17,4 @@ private: std::shared_ptr m_params; }; -#endif // FFBCONSTANTEFFECT_H +#endif // LINUXFFBCONSTANTEFFECT_H \ No newline at end of file diff --git a/linuxffbdevice.cpp b/linuxffbdevice.cpp index c20804c..6b9187d 100644 --- a/linuxffbdevice.cpp +++ b/linuxffbdevice.cpp @@ -1,5 +1,5 @@ #include "linuxffbdevice.h" -#include "ffbeffectfactory.h" +#include "linuxffbeffectfactory.h" #include #include #include @@ -17,7 +17,7 @@ LinuxFFBDevice::LinuxFFBDevice(const int fd, const int maxEffectCount, const QSt c_path(path) { for (int i = 0; i < maxEffectCount; i++) - m_effects.push_back(FFBEffectFactory::createEffect(FFBEffectTypes::NONE)); + m_effects.push_back(LinuxFFBEffectFactory::createEffect(FFBEffectTypes::NONE)); } void LinuxFFBDevice::close() @@ -83,7 +83,7 @@ bool LinuxFFBDevice::removeAndEraseEffect(const int idx) return true; if (removeEffect(idx)) { - m_effects[idx] = FFBEffectFactory::createEffect(FFBEffectTypes::NONE); + m_effects[idx] = LinuxFFBEffectFactory::createEffect(FFBEffectTypes::NONE); if (m_effects[idx]->type() != FFBEffectTypes::NONE) { qCritical("Unable to empty the effect slot."); return false; @@ -99,10 +99,16 @@ bool LinuxFFBDevice::removeAndEraseEffect(const int idx) bool LinuxFFBDevice::removeEffect(const int idx) { + std::shared_ptr linEff; if (!stopEffect(idx)) return false; - int internalIdx = m_effects[idx]->internalIdx(); + if (m_effects[idx]->type() == FFBEffectTypes::NONE) + return true; + + linEff = std::static_pointer_cast(m_effects[idx]); + + int internalIdx = linEff->internalIdx(); int ret = ioctl(c_fd, EVIOCRMFF, internalIdx); if (ret < 0) return false; @@ -111,6 +117,7 @@ bool LinuxFFBDevice::removeEffect(const int idx) bool LinuxFFBDevice::startEffect(const int idx, const FFBEffectTypes type, std::shared_ptr parameters) { + std::shared_ptr linEff; int ret; CHECK_EFFECT_IDX(idx); @@ -122,11 +129,13 @@ bool LinuxFFBDevice::startEffect(const int idx, const FFBEffectTypes type, std:: if (m_effects[idx]->status() == FFBEffect::FFBEffectStatus::PLAYING) return true; + linEff = std::static_pointer_cast(m_effects[idx]); + /* Start playback */ struct input_event evt; evt.type = EV_FF; - evt.code = m_effects[idx]->internalIdx(); - evt.value = m_effects[idx]->parameters()->repeat; + evt.code = linEff->internalIdx(); + evt.value = linEff->parameters()->repeat; ret = write(c_fd, &evt, sizeof(struct input_event)); if (ret != sizeof(struct input_event)) { @@ -135,13 +144,15 @@ bool LinuxFFBDevice::startEffect(const int idx, const FFBEffectTypes type, std:: return false; } - m_effects[idx]->setStatus(FFBEffect::FFBEffectStatus::PLAYING); + linEff->setStatus(FFBEffect::FFBEffectStatus::PLAYING); return true; } bool LinuxFFBDevice::stopEffect(const int idx) { + std::shared_ptr linEff; + CHECK_EFFECT_IDX(idx); if (m_effects[idx] == nullptr) @@ -150,7 +161,9 @@ bool LinuxFFBDevice::stopEffect(const int idx) if (m_effects[idx]->status() != FFBEffect::FFBEffectStatus::PLAYING) return true; - int internalIdx = m_effects[idx]->internalIdx(); + linEff = std::static_pointer_cast(m_effects[idx]); + + int internalIdx = linEff->internalIdx(); struct input_event evt; evt.type = EV_FF; @@ -161,22 +174,28 @@ bool LinuxFFBDevice::stopEffect(const int idx) if (ret != sizeof(struct input_event)) return false; - m_effects[idx]->setStatus(FFBEffect::FFBEffectStatus::UPLOADED); + linEff->setStatus(FFBEffect::FFBEffectStatus::UPLOADED); return true; } bool LinuxFFBDevice::uploadEffect(const int idx, const FFBEffectTypes type, std::shared_ptr parameters) { struct ff_effect* kernelEff = nullptr; - std::shared_ptr effect = FFBEffectFactory::createEffect(type); + std::shared_ptr effect = LinuxFFBEffectFactory::createEffect(type); + std::shared_ptr linEff; + + if (type != FFBEffectTypes::NONE) + linEff = std::static_pointer_cast(effect); + else + return false; CHECK_EFFECT_IDX(idx); - if (effect == nullptr) { + if (linEff == nullptr) { qDebug() << "Unable to create effect"; return false; } - if (!effect->setParameters(parameters)) { + if (!linEff->setParameters(parameters)) { qDebug() << "Unable to set effect parameters, some values are probably invalid."; return false; } @@ -188,32 +207,31 @@ bool LinuxFFBDevice::uploadEffect(const int idx, const FFBEffectTypes type, std: /* There is no effect in the selected slot */ if (m_effects[idx]->type() == FFBEffectTypes::NONE) { - effect->setStatus(FFBEffect::FFBEffectStatus::UPLOADED); + linEff->setStatus(FFBEffect::FFBEffectStatus::UPLOADED); qDebug() << "Creating new effect"; } else { - if (*m_effects[idx] != *effect) { + + if (*m_effects[idx] != *linEff) { if (!removeEffect(idx)) { QMessageBox::critical(nullptr, "FFB Device", "Unable to remove effect"); return false; } - effect->setStatus(FFBEffect::FFBEffectStatus::UPLOADED); + linEff->setStatus(FFBEffect::FFBEffectStatus::UPLOADED); qDebug() << "Recreating effect" << idx; } else { - effect->setInternalIdx(m_effects[idx]->internalIdx()); - effect->setStatus(m_effects[idx]->status()); + linEff->setInternalIdx(std::static_pointer_cast(m_effects[idx])->internalIdx()); + linEff->setStatus(m_effects[idx]->status()); qDebug() << "Updating effect" << idx; } } - kernelEff = effect->createFFStruct(); + kernelEff = linEff->createFFStruct(); if (kernelEff == nullptr) { QMessageBox::critical(nullptr, "FFB Device", "ff_effect struct could not have been created. Effect not uploaded."); qDebug() << "struct ff_effect not created"; return false; } - qDebug() << kernelEff->u.condition[0].center << kernelEff->u.condition[0].deadband << kernelEff->u.condition[1].center << kernelEff->u.condition[1].deadband; - int ret = ioctl(c_fd, EVIOCSFF, kernelEff); if (ret < 0) { QMessageBox::critical(nullptr, "FFB Device", "Effect could not have been uploaded, error code: " + QString::number(ret)); @@ -222,9 +240,9 @@ bool LinuxFFBDevice::uploadEffect(const int idx, const FFBEffectTypes type, std: return false; } - effect->setInternalIdx(kernelEff->id); + linEff->setInternalIdx(kernelEff->id); delete kernelEff; - m_effects[idx] = effect; + m_effects[idx] = linEff; return true; } diff --git a/linuxffbeffect.cpp b/linuxffbeffect.cpp new file mode 100644 index 0000000..26e0e29 --- /dev/null +++ b/linuxffbeffect.cpp @@ -0,0 +1,55 @@ +#include "linuxffbeffect.h" +#include "globalsettings.h" +#include + +LinuxFFBEffect::LinuxFFBEffect(FFBEffectTypes type) : + FFBEffect(type) +{ + m_internalIdx = -1; +} + +struct ff_effect* LinuxFFBEffect::createFFStruct(const std::shared_ptr params) +{ + struct ff_effect* eff = new struct ff_effect; + memset(eff, 0, sizeof(struct ff_effect)); + + eff->id = m_internalIdx; + eff->direction = params->direction; + eff->replay.delay = params->replayDelay; + eff->replay.length = params->replayLength; + + return eff; +} + +void LinuxFFBEffect::reportError(const QString& errorMsg) const +{ + QMessageBox::warning(nullptr, "FFB effect error", errorMsg); +} + +bool LinuxFFBEffect::checkGenericParameters(const std::shared_ptr params) +{ + if (!GlobalSettings::GS()->doSanityChecks) + return true; + + if (params->repeat < 1) { + reportError("Effect must be played back at least once."); + return false; + } + + if (!checkBoundsInclusive(params->direction, 0, 0xFFFF)) { + reportError("Direction out of bounds."); + return false; + } + + if (!checkBoundsInclusive(params->replayDelay, 0, 0x7FFF)) { + reportError("Replay delay out of bounds."); + return false; + } + + if (!checkBoundsInclusive(params->replayLength, 0, 0x7FFF)) { + reportError("Replay length out of bounds."); + return false; + } + + return true; +} \ No newline at end of file diff --git a/linuxffbeffect.h b/linuxffbeffect.h new file mode 100644 index 0000000..3f83094 --- /dev/null +++ b/linuxffbeffect.h @@ -0,0 +1,25 @@ +#ifndef LINUXFFBEFFECT_H +#define LINUXFFBEFFECT_H + +#include "ffbeffect.h" +#include + +class LinuxFFBEffect : public FFBEffect { +public: + explicit LinuxFFBEffect(FFBEffectTypes type); + virtual struct ff_effect* createFFStruct() = 0; + inline int internalIdx() const { return m_internalIdx; } + inline void setInternalIdx(int idx) { m_internalIdx = idx; } + +protected: + struct ff_effect* createFFStruct(const std::shared_ptr params); + bool checkGenericParameters(const std::shared_ptr params); + void reportError(const QString& errorMsg) const; + +private: + + int m_internalIdx; + +}; + +#endif // LINUXFFBEFFECT_H diff --git a/linuxffbeffectfactory.cpp b/linuxffbeffectfactory.cpp new file mode 100644 index 0000000..37161be --- /dev/null +++ b/linuxffbeffectfactory.cpp @@ -0,0 +1,21 @@ +#include "linuxffbeffectfactory.h" + +std::shared_ptr LinuxFFBEffectFactory::createEffect(FFBEffectTypes type) +{ + switch (type) { + case FFBEffectTypes::NONE: + return std::shared_ptr(new FFBNullEffect()); + case FFBEffectTypes::CONSTANT: + return std::shared_ptr(new LinuxFFBConstantEffect()); + case FFBEffectTypes::PERIODIC: + return std::shared_ptr(new LinuxFFBPeriodicEffect()); + case FFBEffectTypes::CONDITION: + return std::shared_ptr(new LinuxFFBConditionEffect()); + case FFBEffectTypes::RAMP: + return std::shared_ptr(new LinuxFFBRampEffect()); + case FFBEffectTypes::RUMBLE: + return std::shared_ptr(new LinuxFFBRumbleEffect()); + default: + return nullptr; + } +} diff --git a/linuxffbeffectfactory.h b/linuxffbeffectfactory.h new file mode 100644 index 0000000..2f3d219 --- /dev/null +++ b/linuxffbeffectfactory.h @@ -0,0 +1,22 @@ +#ifndef LinuxFFBEFFECTFACTORY_H +#define FFBEFFECTFACTORY_H + +#include "globals.h" +#include "linuxffbconditioneffect.h" +#include "linuxffbconstanteffect.h" +#include "ffbnulleffect.h" +#include "linuxffbperiodiceffect.h" +#include "linuxffbrampeffect.h" +#include "linuxffbrumbleeffect.h" + +class LinuxFFBEffectFactory +{ +public: + static std::shared_ptr createEffect(FFBEffectTypes type); + +private: + LinuxFFBEffectFactory() {}; + +}; + +#endif // FFBEFFECTFACTORY_H diff --git a/ffbperiodiceffect.cpp b/linuxffbperiodiceffect.cpp similarity index 82% rename from ffbperiodiceffect.cpp rename to linuxffbperiodiceffect.cpp index 0dea0d6..4602c9f 100644 --- a/ffbperiodiceffect.cpp +++ b/linuxffbperiodiceffect.cpp @@ -1,14 +1,14 @@ -#include "ffbperiodiceffect.h" +#include "linuxffbperiodiceffect.h" #include "globalsettings.h" #include -FFBPeriodicEffect::FFBPeriodicEffect() : - FFBEffect(FFBEffectTypes::PERIODIC) +LinuxFFBPeriodicEffect::LinuxFFBPeriodicEffect() : + LinuxFFBEffect(FFBEffectTypes::PERIODIC) {} -struct ff_effect* FFBPeriodicEffect::createFFStruct() +struct ff_effect* LinuxFFBPeriodicEffect::createFFStruct() { - struct ff_effect* eff = FFBEffect::createFFStruct(m_params); + struct ff_effect* eff = LinuxFFBEffect::createFFStruct(m_params); if (eff == nullptr) return nullptr; @@ -48,7 +48,7 @@ struct ff_effect* FFBPeriodicEffect::createFFStruct() return eff; } -bool FFBPeriodicEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBPeriodicEffect::setParameters(const std::shared_ptr params) { try { return setParameters(std::dynamic_pointer_cast(params)); @@ -58,7 +58,7 @@ bool FFBPeriodicEffect::setParameters(const std::shared_ptr } } -bool FFBPeriodicEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBPeriodicEffect::setParameters(const std::shared_ptr params) { if (!checkGenericParameters(params)) return false; @@ -114,13 +114,13 @@ bool FFBPeriodicEffect::setParameters(const std::shared_ptrtype() != other.type()) return false; else { try { - const FFBPeriodicEffect& eff = dynamic_cast(other); + const LinuxFFBPeriodicEffect& eff = dynamic_cast(other); return this->m_params->waveform == eff.m_params->waveform; } catch(std::bad_cast&) { return false; @@ -128,6 +128,3 @@ bool FFBPeriodicEffect::operator==(const FFBEffect& other) const } } -FFBPeriodicEffect::~FFBPeriodicEffect() -{ -} diff --git a/ffbperiodiceffect.h b/linuxffbperiodiceffect.h similarity index 68% rename from ffbperiodiceffect.h rename to linuxffbperiodiceffect.h index 14891b0..5cea06c 100644 --- a/ffbperiodiceffect.h +++ b/linuxffbperiodiceffect.h @@ -1,14 +1,13 @@ -#ifndef FFBPERIODICEFFECT_H -#define FFBPERIODICEFFECT_H +#ifndef LINUXFFBPERIODICEFFECT_H +#define LINUXFFBPERIODICEFFECT_H -#include "ffbeffect.h" +#include "linuxffbeffect.h" #include "ffbperiodiceffectparameters.h" -class FFBPeriodicEffect : public FFBEffect +class LinuxFFBPeriodicEffect : public LinuxFFBEffect { public: - FFBPeriodicEffect(); - ~FFBPeriodicEffect(); + LinuxFFBPeriodicEffect(); struct ff_effect* createFFStruct(); inline const std::shared_ptr parameters() const { return m_params; } bool setParameters(const std::shared_ptr params); @@ -19,4 +18,4 @@ private: std::shared_ptr m_params; }; -#endif // FFBPERIODICEFFECT_H +#endif // LINUXFFBPERIODICEFFECT_H diff --git a/ffbrampeffect.cpp b/linuxffbrampeffect.cpp similarity index 80% rename from ffbrampeffect.cpp rename to linuxffbrampeffect.cpp index 3428b26..f93cd51 100644 --- a/ffbrampeffect.cpp +++ b/linuxffbrampeffect.cpp @@ -1,14 +1,14 @@ -#include "ffbrampeffect.h" +#include "linuxffbrampeffect.h" #include "globalsettings.h" -FFBRampEffect::FFBRampEffect() : - FFBEffect(FFBEffectTypes::RAMP) +LinuxFFBRampEffect::LinuxFFBRampEffect() : + LinuxFFBEffect(FFBEffectTypes::RAMP) { } -struct ff_effect* FFBRampEffect::createFFStruct() +struct ff_effect* LinuxFFBRampEffect::createFFStruct() { - struct ff_effect* eff = FFBEffect::createFFStruct(m_params); + struct ff_effect* eff = LinuxFFBEffect::createFFStruct(m_params); if (eff == nullptr) return nullptr; @@ -26,7 +26,7 @@ struct ff_effect* FFBRampEffect::createFFStruct() } -bool FFBRampEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBRampEffect::setParameters(const std::shared_ptr params) { try { return setParameters(std::dynamic_pointer_cast(params)); @@ -36,7 +36,7 @@ bool FFBRampEffect::setParameters(const std::shared_ptr par } } -bool FFBRampEffect::setParameters(const std::shared_ptr params) +bool LinuxFFBRampEffect::setParameters(const std::shared_ptr params) { if (!checkGenericParameters(params)) return false; @@ -76,7 +76,3 @@ bool FFBRampEffect::setParameters(const std::shared_ptr m_params = params; return true; } - -FFBRampEffect::~FFBRampEffect() -{ -} diff --git a/ffbrampeffect.h b/linuxffbrampeffect.h similarity index 72% rename from ffbrampeffect.h rename to linuxffbrampeffect.h index b4ab26e..79c8f44 100644 --- a/ffbrampeffect.h +++ b/linuxffbrampeffect.h @@ -1,14 +1,13 @@ -#ifndef FFBRAMPEFFECT_H -#define FFBRAMPEFFECT_H +#ifndef LINUXFFBRAMPEFFECT_H +#define LINUXFFBRAMPEFFECT_H -#include "ffbeffect.h" +#include "linuxffbeffect.h" #include "ffbrampeffectparameters.h" -class FFBRampEffect : public FFBEffect +class LinuxFFBRampEffect : public LinuxFFBEffect { public: - FFBRampEffect(); - ~FFBRampEffect(); + LinuxFFBRampEffect(); struct ff_effect* createFFStruct(); inline const std::shared_ptr parameters() const { return m_params; } bool setParameters(const std::shared_ptr params); diff --git a/ffbrumbleeffect.h b/linuxffbrumbleeffect.h similarity index 72% rename from ffbrumbleeffect.h rename to linuxffbrumbleeffect.h index e0075c3..7717157 100644 --- a/ffbrumbleeffect.h +++ b/linuxffbrumbleeffect.h @@ -1,13 +1,13 @@ -#ifndef FFBRUMBLEEFFECT_H -#define FFBRUMBLEEFFECT_H +#ifndef LINUXFFBRUMBLEEFFECT_H +#define LINUXFFBRUMBLEEFFECT_H -#include "ffbeffect.h" +#include "linuxffbeffect.h" #include "ffbrumbleeffectparameters.h" -class FFBRumbleEffect : public FFBEffect +class LinuxFFBRumbleEffect : public LinuxFFBEffect { public: - FFBRumbleEffect(); + LinuxFFBRumbleEffect(); struct ff_effect* createFFStruct(); inline const std::shared_ptr parameters() const { return m_params; } bool setParameters(const std::shared_ptr params);