Lovense Integration
ILovenseAdapter.h
1 // (CVN) - Candy Valley Network GmbH
2 
3 #pragma once
4 
5 #include <CoreMinimal.h>
6 
7 // EXTERNAL INCLUDES
8 #include <IHttpRequest.h>
9 
10 // INTERNAL INCLUDES
11 #include "LovenseTypes.h"
12 
13 
21  friend class FLovenseManager;
22 
23 public:
31  static bool TryGetAdapterData(FOnLovenseGetAdaptersResponse callback);
32 
39  const TArray<TPair<FString, FTimerHandle>> GetToyTestTimerHandles() { return this->toyTestTimerHandles; }
40 
45  virtual bool Initialize(FLovenseAdapterDescription& description);
47  virtual void Shutdown();
48 
57  virtual bool GetToys(FOnLovenseGetToysResponse callback);
58 
63  virtual bool SendCommand_Test(const FString& toyId);
69  virtual bool SendCommand_Stop(const FString& parameters, const FString& toyId);
76  virtual bool SendCommand_Vibrate(const FString& parameters, const FString& toyId, uint8 vibrationSpeed) { return false; }
83  virtual bool SendCommand_Vibrate1(const FString& parameters, const FString& toyId, uint8 vibrationSpeed) { return false; }
90  virtual bool SendCommand_Vibrate2(const FString& parameters, const FString& toyId, uint8 vibrationSpeed) { return false; }
97  virtual bool SendCommand_Rotate(const FString& parameters, const FString& toyId, uint8 rotationSpeed) { return false; }
104  virtual bool SendCommand_RotateAntiClockwise(const FString& parameters, const FString& toyId, uint8 rotationSpeed) { return false; }
111  virtual bool SendCommand_RotateClockwise(const FString& parameters, const FString& toyId, uint8 rotationSpeed) { return false; }
117  virtual bool SendCommand_RotateChange(const FString& parameters, const FString& toyId) { return false; }
124  virtual bool SendCommand_AirAuto(const FString& parameters, const FString& toyId, uint8 pulseSpeed) { return false; }
130  virtual bool SendCommand_AirIn(const FString& parameters, const FString& toyId) { return false; }
136  virtual bool SendCommand_AirOut(const FString& parameters, const FString& toyId) { return false; }
143  virtual bool SendCommand_Thrust(const FString& parameters, const FString& toyId, uint8 thrustingSpeed) { return false; }
150  virtual bool SendCommand_Suck(const FString& parameters, const FString& toyId, uint8 suctionSpeed) { return false; }
157  virtual bool SendCommand_Finger(const FString& parameters, const FString& toyId, uint8 fingeringSpeed) { return false; }
164  virtual bool SendCommand_Preset(const FString& parameters, const FString& toyId, uint8 pattern) { return false; }
170  virtual bool SendCommand_Battery(const FString& parameters, const FString& toyId, FOnLovenseResponse callback) { return false; }
178  virtual bool SendCommand_AVibrate(const FString& parameters, const FString& toyId, uint8 vibrationSpeed, int32 time) { return false; }
186  virtual bool SendCommand_AVibrate1(const FString& parameters, const FString& toyId, uint8 vibrationSpeed, int32 time) { return false; }
194  virtual bool SendCommand_AVibrate2(const FString& parameters, const FString& toyId, uint8 vibrationSpeed, int32 time) { return false; }
202  virtual bool SendCommand_ARotate(const FString& parameters, const FString& toyId, uint8 rotationSpeed, int32 time) { return false; }
210  virtual bool SendCommand_AAirLevel(const FString& parameters, const FString& toyId, uint8 pulseSpeed, int32 time) { return false; }
218  virtual bool SendCommand_AThrust(const FString& parameters, const FString& toyId, uint8 thrustingSpeed, int32 time) { return false; }
226  virtual bool SendCommand_ASuck(const FString& parameters, const FString& toyId, uint8 suctionSpeed, int32 time) { return false; }
234  virtual bool SendCommand_AFinger(const FString& parameters, const FString& toyId, uint8 fingeringSpeed, int32 time) { return false; }
242  virtual bool SendCommand_APreset(const FString& parameters, const FString& toyId, const FString& patternName, int32 time) { return false; }
251  virtual bool SendCommand_AVibRotate(const FString& parameters, const FString& toyId, uint8 vibrationSpeed, uint8 rotationSpeed, int32 time) { return false; }
260  virtual bool SendCommand_AVibAir(const FString& parameters, const FString& toyId, uint8 vibrationSpeed, uint8 pulseSpeed, int32 time) { return false; }
270  virtual bool SendCommand_AVibRotateAir(const FString& parameters, const FString& toyId, uint8 vibrationSpeed, uint8 rotationSpeed, uint8 pulseSpeed, int32 time) { return false; }
283  virtual bool SendCommand_AAll(const FString& parameters, const FString& toyId, uint8 vibrationSpeed, uint8 rotationSpeed, uint8 pulseSpeed, uint8 thrustingSpeed, uint8 fingeringSpeed, uint8 suctionSpeed, int32 time) { return false; }
290  virtual bool SendCommand_Pattern(const FString& parameters, const FString& toyId, FLovensePattern& pattern) { return false; }
291 
292 protected:
293  ILovenseAdapter();
295  virtual ~ILovenseAdapter() {}
296 
301  static TSharedPtr<class ILovenseAdapter> CreateLovenseAdapter(const FLovenseAdapterDescription& adapterDescription);
302 
307  virtual FHttpRequestPtr CreateHTTPRequest_GetToys() = 0;
313  virtual FHttpRequestPtr CreateHTTPRequest_SendCommand(const FString& parameters) = 0;
314 
316  void CreateLovenseToy(FLovenseToyDescription& toyDescription);
322  virtual void GetToysDataJsonObject(TSharedPtr<class FJsonObject> jsonObject, TSharedPtr<class FJsonObject>& outToysJsonObject);
328  virtual void ParseToyDescription(FLovenseToyDescription& outToyDescription, TSharedPtr<class FJsonObject> toyObject) = 0;
329 
337  virtual bool SendCommand(const FString& parameters, FOnLovenseResponse callback = FOnLovenseResponse());
338 
340  virtual void OnToyTestTimerFinished();
341 
342 protected:
343  TSharedPtr<class LovenseToyEventsWebSocketHandler> lovenseToyEventsWebSocketHandler;
347  FString deviceIp;
352  FString webProtocol;
356  TArray<TStrongObjectPtr<class ULovenseToy>> toyStrongPointers;
361  TArray<TPair<FString, FTimerHandle>> toyTestTimerHandles;
362 };
363 
368 protected:
369  virtual FHttpRequestPtr CreateHTTPRequest_GetToys() override { return nullptr; }
370  virtual FHttpRequestPtr CreateHTTPRequest_SendCommand(const FString& parameters) override { return nullptr; }
371  virtual void ParseToyDescription(FLovenseToyDescription& toyDescription, TSharedPtr<FJsonObject> toyObject) override {}
372 };
ILovenseAdapter::deviceIp
FString deviceIp
Device IP string (excluding port) the Lovense App instance is running on. Parsed in Initialize().
Definition: ILovenseAdapter.h:347
ILovenseAdapter::SendCommand_Pattern
virtual bool SendCommand_Pattern(const FString &parameters, const FString &toyId, FLovensePattern &pattern)
See FLovenseManager::SendCommand_Pattern() for information on this command.
Definition: ILovenseAdapter.h:290
LovenseTestAdapter::CreateHTTPRequest_SendCommand
virtual FHttpRequestPtr CreateHTTPRequest_SendCommand(const FString &parameters) override
Create HTTP request to send a command. Each API+Platform combination requires different HTTP reques...
Definition: ILovenseAdapter.h:370
ILovenseAdapter::SendCommand_AVibrate1
virtual bool SendCommand_AVibrate1(const FString &parameters, const FString &toyId, uint8 vibrationSpeed, int32 time)
See FLovenseManager::SendCommand_AVibrate1() for information on this command.
Definition: ILovenseAdapter.h:186
ILovenseAdapter::SendCommand_Finger
virtual bool SendCommand_Finger(const FString &parameters, const FString &toyId, uint8 fingeringSpeed)
See FLovenseManager::SendCommand_Vibrate() for information on this command.
Definition: ILovenseAdapter.h:157
ILovenseAdapter::SendCommand_AVibrate
virtual bool SendCommand_AVibrate(const FString &parameters, const FString &toyId, uint8 vibrationSpeed, int32 time)
See FLovenseManager::SendCommand_AVibrate() for information on this command.
Definition: ILovenseAdapter.h:178
LovenseTestAdapter::CreateHTTPRequest_GetToys
virtual FHttpRequestPtr CreateHTTPRequest_GetToys() override
Create HTTP request to poll for toy info. Each API+Platform combination requires different HTTP req...
Definition: ILovenseAdapter.h:369
ILovenseAdapter::CreateLovenseAdapter
static TSharedPtr< class ILovenseAdapter > CreateLovenseAdapter(const FLovenseAdapterDescription &adapterDescription)
Factory function for lovense adapters. Checks the adapterDescription.platform and adapterDescriptio...
Definition: ILovenseAdapter.cpp:312
LovenseTestAdapter
Dummy adapter used to check if a FLovenseAdapterDescription has valid data.
Definition: ILovenseAdapter.h:367
ILovenseAdapter::TryGetAdapterData
static bool TryGetAdapterData(FOnLovenseGetAdaptersResponse callback)
Polls "https://api.lovense-api.com/api/lan/v2/app" for toys in the local network. This is the same ...
Definition: ILovenseAdapter.cpp:37
ILovenseAdapter::SendCommand_Vibrate2
virtual bool SendCommand_Vibrate2(const FString &parameters, const FString &toyId, uint8 vibrationSpeed)
See FLovenseManager::SendCommand_Vibrate2() for information on this command.
Definition: ILovenseAdapter.h:90
ILovenseAdapter::SendCommand_AVibrate2
virtual bool SendCommand_AVibrate2(const FString &parameters, const FString &toyId, uint8 vibrationSpeed, int32 time)
See FLovenseManager::SendCommand_AVibrate2() for information on this command.
Definition: ILovenseAdapter.h:194
ILovenseAdapter::SendCommand_AThrust
virtual bool SendCommand_AThrust(const FString &parameters, const FString &toyId, uint8 thrustingSpeed, int32 time)
See FLovenseManager::SendCommand_AThrust() for information on this command.
Definition: ILovenseAdapter.h:218
ILovenseAdapter::GetToysDataJsonObject
virtual void GetToysDataJsonObject(TSharedPtr< class FJsonObject > jsonObject, TSharedPtr< class FJsonObject > &outToysJsonObject)
Retrieve a json object holding an array of toys. The json structure is different between the API's,...
Definition: ILovenseAdapter.cpp:345
ILovenseAdapter::SendCommand_RotateAntiClockwise
virtual bool SendCommand_RotateAntiClockwise(const FString &parameters, const FString &toyId, uint8 rotationSpeed)
See FLovenseManager::SendCommand_RotateAntiClockwise() for information on this command.
Definition: ILovenseAdapter.h:104
ILovenseAdapter::SendCommand_Stop
virtual bool SendCommand_Stop(const FString &parameters, const FString &toyId)
See FLovenseManager::SendCommand_Stop() for information on this command.
Definition: ILovenseAdapter.cpp:300
ILovenseAdapter::CreateLovenseToy
void CreateLovenseToy(FLovenseToyDescription &toyDescription)
Creates a toy object and adds it to the toyStrongPointers array. Also adds the toyDescription to the ...
Definition: ILovenseAdapter.cpp:330
ILovenseAdapter::SendCommand_AAirLevel
virtual bool SendCommand_AAirLevel(const FString &parameters, const FString &toyId, uint8 pulseSpeed, int32 time)
See FLovenseManager::SendCommand_AAirLevel() for information on this command.
Definition: ILovenseAdapter.h:210
ILovenseAdapter::CreateHTTPRequest_SendCommand
virtual FHttpRequestPtr CreateHTTPRequest_SendCommand(const FString &parameters)=0
Create HTTP request to send a command. Each API+Platform combination requires different HTTP reques...
ILovenseAdapter::ParseToyDescription
virtual void ParseToyDescription(FLovenseToyDescription &outToyDescription, TSharedPtr< class FJsonObject > toyObject)=0
Parses a json object holding toy data and fills a toy description. The json structure is different be...
ILovenseAdapter::toyStrongPointers
TArray< TStrongObjectPtr< class ULovenseToy > > toyStrongPointers
Array of the Lovense toy object instances. Is strong object pointer so these UObjects aren't gc'd.
Definition: ILovenseAdapter.h:356
ILovenseAdapter::SendCommand
virtual bool SendCommand(const FString &parameters, FOnLovenseResponse callback=FOnLovenseResponse())
Send a HTTP request to the respective Lovense App.
Definition: ILovenseAdapter.cpp:352
ILovenseAdapter::SendCommand_AirAuto
virtual bool SendCommand_AirAuto(const FString &parameters, const FString &toyId, uint8 pulseSpeed)
See FLovenseManager::SendCommand_AirAuto() for information on this command.
Definition: ILovenseAdapter.h:124
ILovenseAdapter::SendCommand_Rotate
virtual bool SendCommand_Rotate(const FString &parameters, const FString &toyId, uint8 rotationSpeed)
See FLovenseManager::SendCommand_Rotate() for information on this command.
Definition: ILovenseAdapter.h:97
ILovenseAdapter::SendCommand_AAll
virtual bool SendCommand_AAll(const FString &parameters, const FString &toyId, uint8 vibrationSpeed, uint8 rotationSpeed, uint8 pulseSpeed, uint8 thrustingSpeed, uint8 fingeringSpeed, uint8 suctionSpeed, int32 time)
See FLovenseManager::SendCommand_AAll() for information on this command.
Definition: ILovenseAdapter.h:283
ILovenseAdapter::SendCommand_Suck
virtual bool SendCommand_Suck(const FString &parameters, const FString &toyId, uint8 suctionSpeed)
See FLovenseManager::SendCommand_Vibrate() for information on this command.
Definition: ILovenseAdapter.h:150
ILovenseAdapter::SendCommand_Vibrate
virtual bool SendCommand_Vibrate(const FString &parameters, const FString &toyId, uint8 vibrationSpeed)
See FLovenseManager::SendCommand_Vibrate() for information on this command.
Definition: ILovenseAdapter.h:76
ILovenseAdapter::GetToyTestTimerHandles
const TArray< TPair< FString, FTimerHandle > > GetToyTestTimerHandles()
Array of toy deviceId string and test timer handle. This holds the toy deviceId so we can check if ...
Definition: ILovenseAdapter.h:39
ILovenseAdapter::webProtocol
FString webProtocol
The web protocol to use. Default is HTTPS, but will be set to HTTP if li.Request.UseDirectIP is true ...
Definition: ILovenseAdapter.h:352
ILovenseAdapter::SendCommand_AFinger
virtual bool SendCommand_AFinger(const FString &parameters, const FString &toyId, uint8 fingeringSpeed, int32 time)
See FLovenseManager::SendCommand_AFinger() for information on this command.
Definition: ILovenseAdapter.h:234
ILovenseAdapter::SendCommand_AVibAir
virtual bool SendCommand_AVibAir(const FString &parameters, const FString &toyId, uint8 vibrationSpeed, uint8 pulseSpeed, int32 time)
See FLovenseManager::SendCommand_AVibAir() for information on this command.
Definition: ILovenseAdapter.h:260
ILovenseAdapter::SendCommand_Battery
virtual bool SendCommand_Battery(const FString &parameters, const FString &toyId, FOnLovenseResponse callback)
See FLovenseManager::SendCommand_Battery() for information on this command.
Definition: ILovenseAdapter.h:170
FLovenseGetToysResponseData
Container holding (mostly) raw HTTP request json data from ILovenseAdapter::GetToys() response.
Definition: LovenseTypes.h:371
ILovenseAdapter::Initialize
virtual bool Initialize(FLovenseAdapterDescription &description)
Initializes the adapter with the passed in adapter description.
Definition: ILovenseAdapter.cpp:133
ILovenseAdapter::GetAdapterDescription
const FORCEINLINE FLovenseAdapterDescription & GetAdapterDescription()
The adapter description that was used to initialize this adapter. Holds (mostly) raw TryGetAdapterDat...
Definition: ILovenseAdapter.h:34
ILovenseAdapter::SendCommand_AirOut
virtual bool SendCommand_AirOut(const FString &parameters, const FString &toyId)
See FLovenseManager::SendCommand_AirOut() for information on this command.
Definition: ILovenseAdapter.h:136
ILovenseAdapter::SendCommand_ARotate
virtual bool SendCommand_ARotate(const FString &parameters, const FString &toyId, uint8 rotationSpeed, int32 time)
See FLovenseManager::SendCommand_ARotate() for information on this command.
Definition: ILovenseAdapter.h:202
ILovenseAdapter::SendCommand_Vibrate1
virtual bool SendCommand_Vibrate1(const FString &parameters, const FString &toyId, uint8 vibrationSpeed)
See FLovenseManager::SendCommand_Vibrate1() for information on this command.
Definition: ILovenseAdapter.h:83
ILovenseAdapter::SendCommand_RotateChange
virtual bool SendCommand_RotateChange(const FString &parameters, const FString &toyId)
See FLovenseManager::SendCommand_RotateChange() for information on this command.
Definition: ILovenseAdapter.h:117
ILovenseAdapter::GetToys
virtual bool GetToys(FOnLovenseGetToysResponse callback)
Polls the Lovense App for toys and creates toy objects for all received toys. We always directly po...
Definition: ILovenseAdapter.cpp:208
ILovenseAdapter::toyTestTimerHandles
TArray< TPair< FString, FTimerHandle > > toyTestTimerHandles
Array of toy deviceId string and test timer handle. This holds the toy deviceId so we can check if ...
Definition: ILovenseAdapter.h:361
ILovenseAdapter::SendCommand_RotateClockwise
virtual bool SendCommand_RotateClockwise(const FString &parameters, const FString &toyId, uint8 rotationSpeed)
See FLovenseManager::SendCommand_RotateClockwise() for information on this command.
Definition: ILovenseAdapter.h:111
ILovenseAdapter::SendCommand_AVibRotate
virtual bool SendCommand_AVibRotate(const FString &parameters, const FString &toyId, uint8 vibrationSpeed, uint8 rotationSpeed, int32 time)
See FLovenseManager::SendCommand_AVibRotate() for information on this command.
Definition: ILovenseAdapter.h:251
FLovensePattern
Structure holding all necessary information for a pattern command.
Definition: LovenseTypes.h:403
ILovenseAdapter::SendCommand_Thrust
virtual bool SendCommand_Thrust(const FString &parameters, const FString &toyId, uint8 thrustingSpeed)
See FLovenseManager::SendCommand_Vibrate() for information on this command.
Definition: ILovenseAdapter.h:143
ILovenseAdapter
Abstract base class for Lovense adapters. These adapters handle the communication with the Lovense ...
Definition: ILovenseAdapter.h:20
ILovenseAdapter::SendCommand_APreset
virtual bool SendCommand_APreset(const FString &parameters, const FString &toyId, const FString &patternName, int32 time)
See FLovenseManager::SendCommand_APreset() for information on this command.
Definition: ILovenseAdapter.h:242
ILovenseAdapter::adapterDescription
FLovenseAdapterDescription adapterDescription
The adapter description that was used to initialize this adapter. Holds (mostly) raw TryGetAdapterDat...
Definition: ILovenseAdapter.h:345
ILovenseAdapter::OnToyTestTimerFinished
virtual void OnToyTestTimerFinished()
Test timer finished event. Will set vibration speed of the relevant toy to 0 and remove the relevant ...
Definition: ILovenseAdapter.cpp:411
ILovenseAdapter::CreateHTTPRequest_GetToys
virtual FHttpRequestPtr CreateHTTPRequest_GetToys()=0
Create HTTP request to poll for toy info. Each API+Platform combination requires different HTTP req...
FLovenseToyDescription
Container holding (mostly) raw HTTP request json data for a Lovense Toy instance.
Definition: LovenseTypes.h:192
ILovenseAdapter::SendCommand_ASuck
virtual bool SendCommand_ASuck(const FString &parameters, const FString &toyId, uint8 suctionSpeed, int32 time)
See FLovenseManager::SendCommand_ASuck() for information on this command.
Definition: ILovenseAdapter.h:226
FLovenseManager
This class defines the plugin interface. Use FLovenseManager::Get() to get the global manager instanc...
Definition: LovenseManager.h:99
ILovenseAdapter::SendCommand_AirIn
virtual bool SendCommand_AirIn(const FString &parameters, const FString &toyId)
See FLovenseManager::SendCommand_AirIn() for information on this command.
Definition: ILovenseAdapter.h:130
ILovenseAdapter::SendCommand_Test
virtual bool SendCommand_Test(const FString &toyId)
See FLovenseManager::SendCommand_Test() for information on this command.
Definition: ILovenseAdapter.cpp:269
ILovenseAdapter::responseData
FLovenseGetToysResponseData responseData
Holds (mostly) raw GetToys() HTTP request json data.
Definition: ILovenseAdapter.h:354
FLovenseAdapterDescription
Container holding (mostly) raw HTTP request json data for a Lovense App instance in the local network...
Definition: LovenseTypes.h:249
ILovenseAdapter::SendCommand_AVibRotateAir
virtual bool SendCommand_AVibRotateAir(const FString &parameters, const FString &toyId, uint8 vibrationSpeed, uint8 rotationSpeed, uint8 pulseSpeed, int32 time)
See FLovenseManager::SendCommand_AVibRotateAir() for information on this command.
Definition: ILovenseAdapter.h:270
ILovenseAdapter::SendCommand_Preset
virtual bool SendCommand_Preset(const FString &parameters, const FString &toyId, uint8 pattern)
See FLovenseManager::SendCommand_Preset() for information on this command.
Definition: ILovenseAdapter.h:164
ILovenseAdapter::Shutdown
virtual void Shutdown()
Deinitialize the adapter. This will stop any running test timers and clear toy objects.
Definition: ILovenseAdapter.cpp:184