Skip to content

Commit ecf73ff

Browse files
doc: improve connections doc
1 parent e0a3cf9 commit ecf73ff

File tree

15 files changed

+786
-584
lines changed

15 files changed

+786
-584
lines changed

goldenmaster/Plugins/ApiGear/Source/ApiGear/Public/AbstractApiGearConnection.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#include "AbstractApiGearConnection.generated.h"
99

1010
/**
11-
* @brief Abstract base for IApiGearConnection implementation
12-
* Implements state management and handles common reconnection functionality. Exposes delegates.
11+
* Abstract base for IApiGearConnection implementation.
12+
* Handles common reconnection functionality.
13+
* Keeps the connection state updated.
14+
* Exposes delegates for getting notifications of the connection state.
1315
* Does not add the actual connection handling - it needs to be implemented by the final connection.
1416
*/
1517
UCLASS(Abstract, NotBlueprintable)
@@ -19,6 +21,7 @@ class APIGEAR_API UAbstractApiGearConnection : public UObject, public IApiGearCo
1921

2022
public:
2123
explicit UAbstractApiGearConnection(const FObjectInitializer& ObjectInitializer);
24+
2225
FApiGearConnectionIsConnectedDelegate& GetIsConnectedChangedDelegate() override;
2326
FApiGearConnectionStateChangedDelegate& GetConnectionStateChangedDelegate() override;
2427

@@ -29,6 +32,8 @@ class APIGEAR_API UAbstractApiGearConnection : public UObject, public IApiGearCo
2932
void OnDisconnected(bool bReconnect) final;
3033
void Connect() final;
3134
void Disconnect() final;
35+
36+
/* Use this function to block AutoReconnect behavior temporarily until the connection is disconnected. */
3237
void StopReconnecting() override;
3338
bool IsConnected() PURE_VIRTUAL(UAbstractApiGearConnection::IsConnected, return false;);
3439

@@ -43,19 +48,39 @@ class APIGEAR_API UAbstractApiGearConnection : public UObject, public IApiGearCo
4348
private:
4449
void SetConnectionState(EApiGearConnectionState State);
4550

51+
/**
52+
* Implement in derived class to provide actual logic specific for your connection for when network connection is established.
53+
* Should not be used directly, instead use OnConnected().
54+
*/
4655
virtual void OnConnected_Implementation() PURE_VIRTUAL(UAbstractApiGearConnection::OnConnected_Implementation, );
56+
/**
57+
* Implement in derived class to provide actual logic specific for your connection for when the network connection is over
58+
* Should not be used directly, instead use OnDisonnected().
59+
*/
4760
virtual void OnDisconnected_Implementation(bool bReconnect) PURE_VIRTUAL(UAbstractApiGearConnection::OnDisconnected_Implementation, );
61+
/**
62+
* Implement in derived class to provide actual logic specific for your connection to establish a connection
63+
* Should not be used directly, instead use Connect().
64+
*/
4865
virtual void Connect_Implementation() PURE_VIRTUAL(UAbstractApiGearConnection::Connect_Implementation, );
66+
/**
67+
* Implement in derived class to provide actual logic specific for your connection to close connection
68+
* Should not be used directly, instead use Disconnect().
69+
*/
4970
virtual void Disconnect_Implementation() PURE_VIRTUAL(UAbstractApiGearConnection::Disconnect_Implementation, );
5071

5172
FApiGearConnectionIsConnectedDelegate IsConnectedChanged;
5273
FApiGearConnectionStateChangedDelegate ConnectionStateChanged;
5374

75+
/** If set to true, the connection if not running will try to reconnect with a time interval, until succeeded */
5476
bool bIsAutoReconnectEnabled;
77+
/** Used when the bIsAutoReconnectEnabled is on but reconnection functionality needs to be temporarily stop for disconnecting. */
5578
bool bStopReconnectingRequested;
5679

80+
/** Reconnection timer*/
5781
ApiGear::FDelegateHandle RetryTickerHandle;
5882

83+
/** Reconnection timer delegate*/
5984
FTickerDelegate RetryTickerDelegate;
6085

6186
EApiGearConnectionState ConnectionState;

goldenmaster/Plugins/ApiGear/Source/ApiGear/Public/ApiGearConnection.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ enum class EApiGearConnectionState : uint8
1818
Connected UMETA(Displayname = "Connected")
1919
};
2020

21-
/// Used when Network Layer Connection changes its state to connected(true) or any other connection state (false).
21+
/** Used when Network Layer Connection changes its state to connected(true) or any other connection state(false). */
2222
DECLARE_MULTICAST_DELEGATE_OneParam(FApiGearConnectionIsConnectedDelegate, bool);
23-
/// Used when Network Layer Connection changes its state.
23+
/** Used when Network Layer Connection changes its state. */
2424
DECLARE_MULTICAST_DELEGATE_OneParam(FApiGearConnectionStateChangedDelegate, EApiGearConnectionState);
2525
/**
26-
* @brief Used when the interface client changes its subscription status:
26+
* Used when the interface client changes its subscription status:
2727
* either is plugged in the network and ready to use with protocol of your choice (true)
2828
* or it won't be able to properly communicate with server side (false).
2929
* An established network connection (ConnectionIsConnectedDelegate with true parameter) is often necessary, but not sufficient (depending on your setup and used protocol)
@@ -32,11 +32,12 @@ DECLARE_MULTICAST_DELEGATE_OneParam(FApiGearConnectionStateChangedDelegate, EApi
3232
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FApiGearRemoteApiSubscriptionStatusChangedDelegate, bool, IsSubscribed);
3333

3434
/**
35-
* @brief An interface for all connections meant to be used by ApiGear
35+
* An interface for all connections meant to be used by ApiGear
3636
* ensures all connections have:
3737
* - settings for reconnection
3838
* - current state
3939
* - general state and settings accessors
40+
* @see AbstractApiGearConnection for implementation of common functionality.
4041
*/
4142
UINTERFACE(MinimalAPI, meta = (CannotImplementInterfaceInBlueprint))
4243
class UApiGearConnection : public UInterface
@@ -49,34 +50,51 @@ class APIGEAR_API IApiGearConnection
4950
GENERATED_BODY()
5051

5152
public:
53+
54+
/** Returns a delegate for notifications informing whether connection is ready to use
55+
* @see ApiGearConnectionIsConnectedDelegate
56+
*/
5257
virtual FApiGearConnectionIsConnectedDelegate& GetIsConnectedChangedDelegate() = 0;
58+
/** Returns a delegate for notifications informing about the connection state.
59+
* @see FApiGearConnectionStateChangedDelegate
60+
*/
5361
virtual FApiGearConnectionStateChangedDelegate& GetConnectionStateChangedDelegate() = 0;
5462

5563
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
5664
virtual void Configure(FString InServerURL, bool bInAutoReconnectEnabled) = 0;
5765

5866
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
67+
/** Call this function to request connection to be established */
5968
virtual void Connect() = 0;
6069
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
70+
/** A callback for when the network connection is established,
71+
* Use to finalize connect related actions in the implemented connection,
72+
* For notifications on when connection is disconnected use GetIsConnectedChangedDelegate or ApiGearConnectionStateChangedDelegate.
73+
*/
6174
virtual void OnConnected() = 0;
6275
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
76+
/** Call this function to request closing connection. */
6377
virtual void Disconnect() = 0;
6478
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
79+
/** A callback for when the network connection has closed,
80+
* use to finalize disconnect-related actions in the implemented connection.
81+
* For notifications on when connection is disconnected use GetIsConnectedChangedDelegate or ApiGearConnectionStateChangedDelegate.
82+
*/
6583
virtual void OnDisconnected(bool bReconnect) = 0;
6684
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
6785
virtual bool IsConnected() = 0;
6886
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
6987
virtual void StopReconnecting() = 0;
7088

71-
/** Returns the endpoint identifier for this connection, e.g. simulation or phone_service */
89+
/** Returns the endpoint identifier for this connection, e.g. simulation or phone_service*/
7290
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
7391
virtual FString GetUniqueEndpointIdentifier() const = 0;
7492

7593
/** Returns the server URL */
7694
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
7795
virtual FString GetServerURL() const = 0;
7896

79-
/** Returns the type identifier for this connection, e.g. olink */
97+
/** Returns the identifier of protocol used for this connection, e.g. olink */
8098
UFUNCTION(BlueprintCallable, Category = "ApiGear|Connection")
8199
virtual FString GetConnectionProtocolIdentifier() const = 0;
82100

goldenmaster/Plugins/ApiGear/Source/ApiGear/Public/ApiGearConnectionsStore.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
APIGEAR_API DECLARE_LOG_CATEGORY_EXTERN(LogApiGearConnectionsStore, Log, All);
1414

1515
/**
16-
* Implements the connections store for the ApiGear plugin.
16+
* Creates and stores connections based on configured connections in settings.
17+
* @see ApiGearSettings
1718
*
18-
* Can handle all connections which inherit from the IApiGearConnection interface.
19-
* To register your own protocol, you need to call RegisterConnectionFactory
20-
* before this class/module is initialized. The ApiGearOLink module is an example
21-
* how this can be done.
19+
* Handles all connections which inherit from the IApiGearConnection interface.
20+
* @warning For custom protocols make sure you've registered your own protocol factory with a RegisterConnectionFactory.
21+
* before this class/module is initialized.
22+
* You may use implemented ApiGearOLink module as an example.
2223
*/
2324
UCLASS(BlueprintType)
2425
class APIGEAR_API UApiGearConnectionsStore : public UEngineSubsystem
@@ -30,7 +31,11 @@ class APIGEAR_API UApiGearConnectionsStore : public UEngineSubsystem
3031
/** A type of function for creating connections*/
3132
using FConnectionFactoryFunction = TFunction<TScriptInterface<IApiGearConnection>(UObject*, FString)>;
3233

33-
/** register factories for different types of connections */
34+
/**
35+
* Register custom factories of connections.
36+
* This function must be called before this class or module are initialized.
37+
* @see ApiGearOLink.
38+
*/
3439
static bool RegisterConnectionFactory(FString ConnectionTypeIdentifier, FConnectionFactoryFunction FactoryFunction);
3540

3641
// USubssystem functions
@@ -62,6 +67,7 @@ class APIGEAR_API UApiGearConnectionsStore : public UEngineSubsystem
6267
UFUNCTION(BlueprintCallable, Category = "ApiGear|ConnectionsStore")
6368
TArray<FString> GetAvailableProtocols() const;
6469

70+
/** Replaces ApiGear plugin settings configured for the project with all currently added connections. */
6571
UFUNCTION(BlueprintCallable, Category = "ApiGear|ConnectionsStore")
6672
void OverwriteAndSaveConnectionsToSettings() const;
6773

goldenmaster/Plugins/ApiGear/Source/ApiGear/Public/ApiGearSettings.h

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "Engine/EngineTypes.h"
88
#include "ApiGearSettings.generated.h"
99

10-
/** Settings per connection for ApiGear plugins */
10+
/** Settings for a connection in ApiGear plugins */
1111
USTRUCT()
1212
struct FApiGearConnectionSetting
1313
{
@@ -19,23 +19,36 @@ struct FApiGearConnectionSetting
1919
*/
2020
FString ProtocolIdentifier{"olink"};
2121

22-
/** Choose the server to connect to */
22+
/**
23+
* Choose the server to connect to
24+
* this is a full address with a port
25+
* It will be used "as is", so if you need any pre or post fixes like
26+
* "ws://" make sure the field contains it.
27+
*/
2328
UPROPERTY(EditAnywhere, config, Category = ApiGearConnectionSetting)
2429
FString URL{TEXT("ws://127.0.0.1:8000/ws")};
2530

26-
/** Choose whether to automatically reconnect */
31+
/** Enable reconnect functionality for connection, also automatically starts the connection for the first time */
2732
UPROPERTY(EditAnywhere, config, Category = ApiGearConnectionSetting)
2833
bool AutoReconnectEnabled{false};
2934
};
3035

3136
/**
32-
* Implements the settings for the ApiGear plugin.
37+
* Stores settings for each connection and other network related settings for ApiGear plugin.
38+
* For each connection settings a connections is created by ApiGearConnectionsStore on startup,
39+
* For other custom protocols make sure that a factory for it is added to ApiGearConnectionsStore.
40+
* @see ApiGearConnectionsStore
3341
*/
3442
UCLASS(Config = Engine, DefaultConfig)
3543
class APIGEAR_API UApiGearSettings : public UObject
3644
{
3745
GENERATED_UCLASS_BODY()
38-
/** Choose the server to connect to */
46+
/**
47+
* Url of tracer server to connect to.
48+
* This is a full address with a port
49+
* It will be used "as is", so if you need any pre or post fixes like
50+
* "ws://" make sure the field contains it.
51+
*/
3952
UPROPERTY(EditAnywhere, config, Category = TracerSetup, meta = (ConfigRestartRequired = true))
4053
FString Tracer_URL;
4154

@@ -47,15 +60,20 @@ class APIGEAR_API UApiGearSettings : public UObject
4760
UPROPERTY(EditAnywhere, config, Category = TracerSetup, meta = (ConfigRestartRequired = true))
4861
bool Tracer_EnableDebugLog;
4962

50-
/** Save and overwrite runtime modifications to the connections on exit */
63+
/**
64+
* Save and overwrite runtime modifications to the connections on exit.
65+
* The property is checked on exit.
66+
* If set to false, all the changes (compared with the startup) will be lost, even if it was set to true during application lifetime.
67+
* You still can save current settings state during editing regardless of this property with a ApiGearConnectionsStore::OverwriteAndSaveConnectionsToSettings function.
68+
*/
5169
UPROPERTY(EditAnywhere, config, Category = ConnectionSetup, meta = (ConfigRestartRequired = true, Display = "Use runtime changes instead of settings"))
5270
bool bSaveRuntimeEdit;
5371

54-
// Automatically start
72+
/** Automatically starts the Hosted OLink Server. */
5573
UPROPERTY(EditAnywhere, config, Category = OLinkHostSetup)
5674
bool OLINK_AutoStart;
5775

58-
// On which Port to listen
76+
/** Port on which Hosted OLink Server is listening.*/
5977
UPROPERTY(EditAnywhere, config, Category = OLinkHostSetup)
6078
uint32 OLINK_Port;
6179

goldenmaster/Plugins/ApiGear/Source/ApiGear/Public/ApiGearTicker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "Runtime/Launch/Resources/Version.h"
55
#include "Containers/Ticker.h"
66

7+
8+
/** This is a a helper file to provide version independent ticker functionality */
79
namespace ApiGear
810
{
911
#if (ENGINE_MAJOR_VERSION >= 5)

goldenmaster/Plugins/ApiGear/Source/ApiGear/Public/apigear.json.adapter.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,40 @@
88
#define JSON_NOEXCEPTION 1
99
#include <nlohmann/json.hpp>
1010

11+
/**
12+
* Converts json formated data into FString.
13+
* The functions signature must follow the nlohmann from_jason function rules.
14+
* It is automatically called in usage j.get<FString>();
15+
* @param j an input json formated data
16+
* @param p FString that will be filled with data from j.
17+
* In case data is malformed or not convertible to FString the function will throw.
18+
*/
1119
static void from_json(const nlohmann::json& j, FString& p)
1220
{
1321
p = FString(UTF8_TO_TCHAR(j.get<std::string>().c_str()));
1422
}
1523

24+
/**
25+
* Converts FString into json formated data.
26+
* The functions signature must follow the nlohmann to_json function rules.
27+
* It is automatically called in usage j = p;
28+
* @param j a json type data that will be filled with data from p
29+
* @param p an input from which json data will be filled.
30+
*/
1631
static void to_json(nlohmann::json& j, const FString& value)
1732
{
1833
j = TCHAR_TO_UTF8(*value);
1934
}
2035

36+
/**
37+
* Converts json formated data into TArray of T type elements.
38+
* The T type needs to be either std type or have its from_json function.
39+
* The functions signature must follow the nlohmann from_jason function rules.
40+
* It is automatically called in usage j.get<TArray<T>>();
41+
* @param j an input json formated data
42+
* @param p FString that will be filled with data from j.
43+
* In case data is malformed or not convertible to FString the function will throw.
44+
*/
2145
template <typename T>
2246
void from_json(const nlohmann::json& j, TArray<T>& p)
2347
{
@@ -29,6 +53,14 @@ void from_json(const nlohmann::json& j, TArray<T>& p)
2953
}
3054
}
3155

56+
/**
57+
* Converts TArray of T type elements into json formated data.
58+
* The T type needs to be either std type or have its to_json function.
59+
* The functions signature must follow the nlohmann to_json function rules.
60+
* It is automatically called in usage j = p;
61+
* @param j a json type data that will be filled with data from p
62+
* @param p an input from which json data will be filled.
63+
*/
3264
template <typename T>
3365
void to_json(nlohmann::json& j, const TArray<T>& p)
3466
{

0 commit comments

Comments
 (0)