Lovense Integration
LovenseManager.h
1 // (CVN) - Candy Valley Network GmbH
2 
3 #pragma once
4 
5 #include <CoreMinimal.h>
6 
7 // EXTERNAL INCLUDES
8 
9 // INTERNAL INCLUDES
10 #include "LovenseEvents.h"
11 #include "LovenseTypes.h"
12 
13 
99 class LOVENSEINTEGRATION_API FLovenseManager {
100  friend class FLovenseIntegrationModule;
101 
102 public:
103  FLovenseManager();
104 
106  static FLovenseManager* Get();
107 
116  void StartLovense();
126  void StopLovense();
127 
129  void UpdateAdapters();
130 
132  void UpdateToys();
133 
138  void ClearAllCommands(class ULovenseToy* toy = nullptr);
139 
141  void ReloadLovenseConfig();
142 
144  FORCEINLINE class ULovenseEvents* GetLovenseEvents() { return this->lovenseEvents.Get(); }
149  FORCEINLINE const TArray<class ULovenseToy*>& GetToys() { return this->toys; }
151  FORCEINLINE bool IsLovenseRunning() { return this->bIsLovenseRunning; }
153  FORCEINLINE bool IsUpdatingAdapters() { return this->bIsUpdatingAdapters; }
155  FORCEINLINE bool IsUpdatingToys() { return this->bIsUpdatingToys; }
156 
158  bool IsIPStringValid(const FString& ipString, const TCHAR* delimiter = TEXT("."));
160  bool IsDomainStringValid(const FString& domainString);
162  bool IsPortStringValid(const FString& portString);
163 
165  FString ConvertIPStringToDomainString(const FString& ipString);
167  FString ConvertDomainStringToIPString(const FString& domainString);
168 
170  void StartTimer(FTimerHandle& timerHandle, float timerRate, bool bIsLooped);
172  void StartTimer(FTimerHandle& timerHandle, const FTimerDelegate& delegate, float timerRate, bool bIsLooped);
174  void StartTimer(FTimerHandle& timerHandle, const FTimerDynamicDelegate& delegate, float timerRate, bool bIsLooped);
176  void StopTimer(FTimerHandle& timerHandle);
178  bool IsTimerRunning(FTimerHandle timerHandle);
180  bool IsTimerExecuting(FTimerHandle timerHandle);
181 
198  bool SendCommand(
199  ELovenseCommand command,
200  class ULovenseToy* toy,
201  uint8 valueA = 0,
202  int32 time = 0,
203  uint8 valueB = 0,
204  uint8 valueC = 0,
205  const FString& presetName = TEXT(""),
206  FLovensePattern pattern = FLovensePattern(),
207  FOnLovenseResponse callback = FOnLovenseResponse()
208  );
209 
216  bool SendCommand_Test(class ULovenseToy* toy);
217 
222  bool SendCommand_Stop(class ULovenseToy* toy);
223 
234  bool SendCommand_Vibrate(class ULovenseToy* toy, uint8 vibrationSpeed);
235 
247  bool SendCommand_Vibrate1(class ULovenseToy* toy, uint8 vibrationSpeed);
248 
260  bool SendCommand_Vibrate2(class ULovenseToy* toy, uint8 vibrationSpeed);
261 
273  bool SendCommand_Rotate(class ULovenseToy* toy, uint8 rotationSpeed);
274 
286  bool SendCommand_RotateAntiClockwise(class ULovenseToy* toy, uint8 rotationSpeed);
287 
299  bool SendCommand_RotateClockwise(class ULovenseToy* toy, uint8 rotationSpeed);
300 
310  bool SendCommand_RotateChange(class ULovenseToy* toy);
311 
323  bool SendCommand_AirAuto(class ULovenseToy* toy, uint8 pulseSpeed);
324 
335  bool SendCommand_AirIn(class ULovenseToy* toy);
336 
347  bool SendCommand_AirOut(class ULovenseToy* toy);
348 
359  bool SendCommand_Thrust(class ULovenseToy* toy, uint8 thrustingSpeed);
360 
371  bool SendCommand_Suck(class ULovenseToy* toy, uint8 suctionSpeed);
372 
383  bool SendCommand_Finger(class ULovenseToy* toy, uint8 fingeringSpeed);
384 
396  bool SendCommand_Preset(class ULovenseToy* toy, uint8 pattern);
397 
408  bool SendCommand_Battery(class ULovenseToy* toy, FOnLovenseResponse callback);
409 
424  bool SendCommand_AVibrate(class ULovenseToy* toy, uint8 vibrationSpeed, int32 time);
425 
442  bool SendCommand_AVibrate1(class ULovenseToy* toy, uint8 vibrationSpeed, int32 time);
443 
460  bool SendCommand_AVibrate2(class ULovenseToy* toy, uint8 vibrationSpeed, int32 time);
461 
477  bool SendCommand_ARotate(class ULovenseToy* toy, uint8 rotationSpeed, int32 time);
478 
494  bool SendCommand_AAirLevel(class ULovenseToy* toy, uint8 pulseSpeed, int32 time);
495 
510  bool SendCommand_AThrust(class ULovenseToy* toy, uint8 thrustingSpeed, int32 time);
511 
526  bool SendCommand_ASuck(class ULovenseToy* toy, uint8 suctionSpeed, int32 time);
527 
542  bool SendCommand_AFinger(class ULovenseToy* toy, uint8 fingeringSpeed, int32 time);
543 
559  bool SendCommand_APreset(class ULovenseToy* toy, const FString& patternName, int32 time);
560 
580  bool SendCommand_AVibRotate(class ULovenseToy* toy, uint8 vibrationSpeed, uint8 rotationSpeed, int32 time);
581 
601  bool SendCommand_AVibAir(class ULovenseToy* toy, uint8 vibrationSpeed, uint8 pulseSpeed, int32 time);
602 
618  bool SendCommand_AVibRotateAir(class ULovenseToy* toy, uint8 vibrationSpeed, uint8 rotationSpeed, uint8 pulseSpeed, int32 time);
619 
633  bool SendCommand_AAll(class ULovenseToy* toy, uint8 speed, int32 time);
634 
646  bool SendCommand_Pattern(class ULovenseToy* toy, FLovensePattern& pattern);
647 
649  template<typename TCallback>
650  FORCEINLINE void ForEachAdapter(TCallback callback) {
651  for (TSharedPtr<class ILovenseAdapter> adapter : this->lovenseAdapters) callback(adapter);
652  }
653 
664  void OnCommandFailed();
665 
671  FORCEINLINE int32 GetToyDelay() { return this->toyDelay; }
678  FORCEINLINE void SetToyDelay(int32 value) { this->toyDelay = value; }
684  FORCEINLINE float GetToyStrengthMultiplier() { return this->toyStrengthMultiplier; }
691  FORCEINLINE void SetToyStrengthMultiplier(float value) { this->toyStrengthMultiplier = value; }
696  FORCEINLINE bool GetToyVibrationEnabled() { return this->bToyVibrationEnabled; }
703  void SetToyVibrationEnabled(bool value);
708  FORCEINLINE bool GetToyRotationEnabled() { return this->bToyRotationEnabled; }
715  void SetToyRotationEnabled(bool value);
720  FORCEINLINE bool GetToyAirEnabled() { return this->bToyAirEnabled; }
727  void SetToyAirEnabled(bool value);
732  FORCEINLINE bool GetToyThrustingEnabled() { return this->bToyThrustingEnabled; }
739  void SetToyThrustingEnabled(bool value);
744  FORCEINLINE bool GetToySuctionEnabled() { return this->bToySuctionEnabled; }
751  void SetToySuctionEnabled(bool value);
756  FORCEINLINE bool GetToyFingeringEnabled() { return this->bToyFingeringEnabled; }
763  void SetToyFingeringEnabled(bool value);
764 
766  FORCEINLINE const FLovenseCommandDelayTimers& GetCommandDelayTimers() { return this->commandDelayTimers; }
767 
768 private:
770  void Initialize();
772  void Shutdown();
773 
778  void InitializeAdapter(TSharedPtr<class ILovenseAdapter> adapter, FLovenseAdapterDescription& adapterDescription);
784  void FilterAdaptersAndAddOfflineAdapters();
790  void PruneAdapters();
795  void UpdateToys_Internal();
796 
801  void ClearData(bool bClearCurrentData);
802 
809  void OnUpdateAdaptersTimerFinished();
817  void StartUpdateAdaptersTimer();
824  void ResetUpdateAdaptersTimer();
825 
827  void OnUpdateToysTimerLoop();
829  void StartUpdateToysTimer();
830 
831 private:
833  TStrongObjectPtr<class ULovenseEvents> lovenseEvents;
835  FLovenseGetAdaptersResponseData adaptersResponseData;
837  TArray<TSharedPtr<class ILovenseAdapter>> lovenseAdapters;
839  TArray<class ULovenseToy*> toys;
840 
841  // Temporary adapter and toy information used while UpdateAdapters() or UpdateToys() is still in progress.
843  int32 numAdaptersWaitingForGetToysResponse;
845  int32 numAdaptersFailedGetToys;
850  TArray<TSharedPtr<class ILovenseAdapter>> temporaryLovenseAdapters;
855  TArray<class ULovenseToy*> temporaryToys;
856 
858  bool bIsLovenseRunning;
860  bool bIsUpdatingAdapters;
862  bool bIsUpdatingToys;
863 
865  FTimerHandle updateAdaptersTimerHandle;
870  float currentUpdateAdaptersTimerInterval;
875  FTimerHandle updateToysTimerHandle;
877  FLovenseCommandDelayTimers commandDelayTimers;
878 
885  int32 toyDelay;
892  float toyStrengthMultiplier;
898  bool bToyVibrationEnabled;
904  bool bToyRotationEnabled;
910  bool bToyAirEnabled;
916  bool bToyThrustingEnabled;
922  bool bToySuctionEnabled;
928  bool bToyFingeringEnabled;
929 };
FLovenseIntegrationModule
Lovense Integration Module class. Use FLovenseIntegrationModule::Get() to easily get the module insta...
Definition: LovenseIntegration.h:20
FLovenseManager::GetLovenseEvents
FORCEINLINE class ULovenseEvents * GetLovenseEvents()
Definition: LovenseManager.h:144
FLovenseManager::GetToyThrustingEnabled
FORCEINLINE bool GetToyThrustingEnabled()
Get the cached "ToyThrustingEnabled" config value. If false, thrusting speed values will be set to ...
Definition: LovenseManager.h:732
ULovenseEvents
Object holding global Lovense Integration delegates.
Definition: LovenseEvents.h:30
FLovenseManager::IsLovenseRunning
FORCEINLINE bool IsLovenseRunning()
Definition: LovenseManager.h:151
FLovenseCommandDelayTimers
These timers define the minimum update frequencies for the respective commands. There's a global se...
Definition: LovenseTypes.h:465
FLovenseManager::GetToyDelay
FORCEINLINE int32 GetToyDelay()
Get the cached "ToyDelay" config value. Toy delay is in milliseconds. Value range is 0-2000ms and d...
Definition: LovenseManager.h:671
FLovenseManager::SetToyStrengthMultiplier
FORCEINLINE void SetToyStrengthMultiplier(float value)
Set the cached "ToyStrengthMultiplier" config value. Value range is 0.0f-1.0f and defaults to 1....
Definition: LovenseManager.h:691
ULovenseToy
UObject representing a Lovense Toy.
Definition: LovenseToy.h:19
FLovenseManager::IsUpdatingAdapters
FORCEINLINE bool IsUpdatingAdapters()
Definition: LovenseManager.h:153
FLovenseManager::GetToyAirEnabled
FORCEINLINE bool GetToyAirEnabled()
Get the cached "ToyAirEnabled" config value. If false, air speed values will be set to 0 before com...
Definition: LovenseManager.h:720
FLovenseManager::GetToyVibrationEnabled
FORCEINLINE bool GetToyVibrationEnabled()
Get the cached "ToyVibrationEnabled" config value. If false, vibration speed values will be set to ...
Definition: LovenseManager.h:696
FLovenseIntegrationModule::Get
static FORCEINLINE FLovenseIntegrationModule & Get()
Get the instance of the module. Always valid.
Definition: LovenseIntegration.h:40
FLovenseManager::ForEachAdapter
FORCEINLINE void ForEachAdapter(TCallback callback)
Iterates over all active adapters.
Definition: LovenseManager.h:650
FLovenseManager::SetToyDelay
FORCEINLINE void SetToyDelay(int32 value)
Set the cached "ToyDelay" config value. Toy delay is in milliseconds. Value range is 0-2000ms and d...
Definition: LovenseManager.h:678
FLovensePattern
Structure holding all necessary information for a pattern command.
Definition: LovenseTypes.h:403
FLovenseManager::GetToyRotationEnabled
FORCEINLINE bool GetToyRotationEnabled()
Get the cached "ToyRotationEnabled" config value. If false, rotation speed values will be set to 0 ...
Definition: LovenseManager.h:708
FLovenseManager::IsUpdatingToys
FORCEINLINE bool IsUpdatingToys()
Definition: LovenseManager.h:155
FLovenseManager::GetToyStrengthMultiplier
FORCEINLINE float GetToyStrengthMultiplier()
Get the cached "ToyStrengthMultiplier" config value. Value range is 0.0f-1.0f and defaults to 1....
Definition: LovenseManager.h:684
FLovenseManager::GetCommandDelayTimers
const FORCEINLINE FLovenseCommandDelayTimers & GetCommandDelayTimers()
Get the global set of Command Delay Timers used when commands are broadcasted. See FLovenseCommandDel...
Definition: LovenseManager.h:766
FLovenseManager::GetToys
const FORCEINLINE TArray< class ULovenseToy * > & GetToys()
Definition: LovenseManager.h:149
FLovenseGetAdaptersResponseData
Container holding (mostly) raw HTTP request json data from ILovenseAdapter::TryGetAdapterData() respo...
Definition: LovenseTypes.h:339
FLovenseManager
This class defines the plugin interface. Use FLovenseManager::Get() to get the global manager instanc...
Definition: LovenseManager.h:99
FLovenseManager::GetToySuctionEnabled
FORCEINLINE bool GetToySuctionEnabled()
Get the cached "ToySuctionEnabled" config value. If false, suction speed values will be set to 0 be...
Definition: LovenseManager.h:744
FLovenseAdapterDescription
Container holding (mostly) raw HTTP request json data for a Lovense App instance in the local network...
Definition: LovenseTypes.h:249
FLovenseManager::GetToyFingeringEnabled
FORCEINLINE bool GetToyFingeringEnabled()
Get the cached "ToyFingeringEnabled" config value. If false, fingering speed values will be set to ...
Definition: LovenseManager.h:756