Skip to content

Commit 93cfb8b

Browse files
authored
Modify documentation (olp-cpp-sdk-core/client) (#610)
Relates to: OLPEDGE-1441 Signed-off-by: Halyna Dumych <[email protected]>
1 parent d69a8d8 commit 93cfb8b

File tree

15 files changed

+600
-257
lines changed

15 files changed

+600
-257
lines changed

olp-cpp-sdk-core/include/olp/core/client/ApiError.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class CORE_API ApiError {
6262
/**
6363
* @brief Creates the `ApiError` instance with the HTTP status code.
6464
*
65-
* Represents the server status. Evaluates the HTTP status code and sets the
66-
* `error_code_` and `is_retriable_ flag` parameters . You can call this
65+
* Represents the server status. Evaluates the HTTP status code and sets
66+
* the `error_code_` and `is_retriable_ flag` parameters. You can call this
6767
* constructor using the HTTP status code and error text message.
6868
*
6969
* @param http_status_code The HTTP status code returned by the server.
@@ -76,28 +76,30 @@ class CORE_API ApiError {
7676
is_retryable_(http::HttpStatusCode::IsRetryable(http_status_code)) {}
7777

7878
/**
79-
* Gets the error code.
79+
* @brief Gets the error code.
8080
*
8181
* @return The code associated with the error.
8282
*/
8383
inline ErrorCode GetErrorCode() const { return error_code_; }
8484

8585
/**
86-
* Gets the HTTP status code.
86+
* @brief Gets the HTTP status code.
8787
*
8888
* @return The HTTP status code.
8989
*/
9090
inline int GetHttpStatusCode() const { return http_status_code_; }
9191

9292
/**
93-
* Gets the error message.
93+
* @brief Gets the error message.
9494
*
9595
* @return The error message associated with the error.
9696
*/
9797
inline const std::string& GetMessage() const { return message_; }
9898

9999
/**
100-
* Returns true if a request can be retried for this error.
100+
* @brief Checks if the request can be retried for this error.
101+
*
102+
* @return True if the request can be retried for this error; false otherwise.
101103
*/
102104
inline bool ShouldRetry() const { return is_retryable_; }
103105

olp-cpp-sdk-core/include/olp/core/client/ApiNoResult.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ namespace olp {
2323
namespace client {
2424

2525
/**
26-
* Used when an ApiResponse does not contain result data. E.g. a HTTP 200
27-
* response with no response body.
26+
* @brief Used when `ApiResponse` does not contain result data.
27+
*
28+
* Example: the HTTP 200 response with no response body.
2829
*/
2930
class ApiNoResult {};
3031

olp-cpp-sdk-core/include/olp/core/client/ApiResponse.h

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,34 @@ namespace olp {
2828
namespace client {
2929

3030
/**
31-
* Represents a request outcome.
31+
* @brief Represents a request outcome.
3232
*
3333
* Contains a successful result or failure error. Before you try to access
34-
* the result of the error, check the request outcome.
34+
* the error result, check the request outcome.
3535
*
3636
* @tparam Result The result type.
3737
* @tparam Error The error type.
3838
*/
3939
template <typename Result, typename Error>
4040
class ApiResponse {
4141
public:
42+
/**
43+
* @brief The type of result.
44+
*/
4245
using ResultType = Result;
46+
/**
47+
* @brief The type of error.
48+
*/
4349
using ErrorType = Error;
4450

4551
ApiResponse() = default;
4652

4753
/**
48-
* @brief ApiResponse Constructor for moving a successfully executed request.
54+
* @brief Creates the `ApiResponse` instance.
55+
*
56+
* Used for moving the successfully executed request.
57+
*
58+
* @param result The `ResultType` instance.
4959
*/
5060
ApiResponse(ResultType result) : result_(std::move(result)), success_(true) {}
5161

@@ -57,35 +67,39 @@ class ApiResponse {
5767
ApiResponse(const ErrorType& error) : error_(error), success_(false) {}
5868

5969
/**
60-
* @brief ApiResponse Copy constructor.
70+
* @brief Creates the `ApiResponse` instance that is a copy of the `r`
71+
* parameter.
72+
*
73+
* @param r The `ApiResponse` instance from which the response is copied.
6174
*/
6275
ApiResponse(const ApiResponse& r)
6376
: result_(r.result_), error_(r.error_), success_(r.success_) {}
6477

6578
/**
66-
* @brief IsSuccessful Gets the status of the request attempt.
67-
* @return True is request successfully completed.
79+
* @brief Checks the status of the request attempt.
80+
*
81+
* @return True if the request is successfully completed; false otherwise.
6882
*/
6983
inline bool IsSuccessful() const { return success_; }
7084

7185
/**
72-
* @brief GetResult Gets the result for a succcessfully executed request
73-
* @return A valid Result if IsSuccessful() returns true. Undefined,
74-
* otherwise.
86+
* @brief Gets the result of the successfully executed request.
87+
*
88+
* @return The result instance.
7589
*/
7690
inline const ResultType& GetResult() const { return result_; }
7791

7892
/**
79-
* @brief MoveResult Moves the result for a succcessfully executed request
80-
* @return A valid Result if IsSuccessful() returns true. Undefined,
81-
* otherwise.
93+
* @brief Moves the result of the successfully executed request.
94+
*
95+
* @return The forwarding reference to the result instance.
8296
*/
8397
inline ResultType&& MoveResult() { return std::move(result_); }
8498

8599
/**
86-
* @brief GetError Gets the error for an unsucccessful request attempt.
87-
* @return A valid Error if IsSuccessful() returns false. Undefined,
88-
* otherwise.
100+
* @brief Gets the error of the unsuccessful request attempt.
101+
*
102+
* @return The result instance.
89103
*/
90104
inline const ErrorType& GetError() const { return error_; }
91105

@@ -96,15 +110,17 @@ class ApiResponse {
96110
};
97111

98112
/**
99-
* @brief A wrapper template that you can use to cancel the request or wait for
113+
* @brief A wrapper template that you can use to cancel a request or wait for
100114
* it to finalize.
101115
*
102116
* @tparam T The result type.
103117
*/
104118
template <typename T>
105119
class CancellableFuture {
106120
public:
107-
/// The typedef for the sharable promise.
121+
/**
122+
* @brief The sharable promise type.
123+
*/
108124
using PromisePtr = std::shared_ptr<std::promise<T>>;
109125

110126
/**
@@ -118,7 +134,7 @@ class CancellableFuture {
118134
: cancel_token_(cancel_token), promise_(std::move(promise)) {}
119135

120136
/**
121-
* @brief Gets the `CancellationToken` reference used to cancell the ongoing
137+
* @brief Gets the `CancellationToken` reference used to cancel the ongoing
122138
* operation.
123139
*
124140
* @return The constant reference to the `CancellationToken` instance.

olp-cpp-sdk-core/include/olp/core/client/CancellationContext.h

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,84 @@ namespace olp {
3030
namespace client {
3131

3232
/**
33-
* @brief Wrapper which manages cancellation state for any asynchronous
34-
* operations in a thread safe way.
35-
* All public APIs are thread safe.
33+
* @brief A wrapper that manages the cancellation state of an asynchronous
34+
* operation in a thread-safe way.
35+
*
36+
* All public APIs are thread-safe.
37+
*
3638
* This class is both movable and copyable.
3739
*/
3840
class CORE_API CancellationContext {
3941
public:
42+
/**
43+
* @brief The type alias of the operation function.
44+
*/
4045
using ExecuteFuncType = std::function<CancellationToken()>;
46+
/**
47+
* @brief The type alias of the cancel function.
48+
*/
4149
using CancelFuncType = std::function<void()>;
4250

4351
CancellationContext();
4452

4553
/**
46-
* @brief Execute a given cancellable code block if the operation has not yet
47-
* been cancelled. Otherwise, execute a custom cancellation function.
48-
* @param execute_fn A function to execute if this operation is not yet
49-
* cancelled. This function should return a CancellationToken which
50-
* CancellationContext will propogate a cancel request to.
51-
* @param cancel_fn A function which will be called if this operation is
52-
* already cancelled.
53-
* @return true in case of successfull execution, false in case context was
54+
* @brief Executes the given cancellable code block if the operation is not
55+
* cancelled.
56+
*
57+
* Otherwise, executes the custom cancellation function.
58+
*
59+
* @param execute_fn The function that should be executed if this operation is
60+
* not cancelled. This function should return `CancellationToken` for which
61+
* `CancellationContext` propagates a cancel request.
62+
* @param cancel_fn The function that is called if this operation is
63+
* cancelled.
64+
*
65+
* @return True if the execution is successful; false if the context was
5466
* cancelled.
55-
* @deprecated Will be removed once TaskScheduler will be used.
67+
*
68+
* @deprecated Will be removed. Use `TaskScheduler` instead.
5669
*/
5770
bool ExecuteOrCancelled(const ExecuteFuncType& execute_fn,
5871
const CancelFuncType& cancel_fn = nullptr);
5972

6073
/**
61-
* @brief Allows the user to cancel an ongoing operation in a threadsafe way.
74+
* @brief Cancels the ongoing operation in a thread-safe way.
6275
*/
6376
void CancelOperation();
6477

6578
/**
66-
* @brief Check if this context was cancelled.
67-
* @return `true` on context cancelled, `false` otherwise.
79+
* @brief Checks whether this context is cancelled.
80+
*
81+
* @return True if the context is cancelled; false otherwise.
6882
*/
6983
bool IsCancelled() const;
7084

7185
private:
7286
/**
73-
* @brief Implementation to be able to shared a instance of
74-
* CancellationContext.
87+
* @brief An implementation used to shared the `CancellationContext` instance.
7588
*/
7689
struct CancellationContextImpl {
77-
/// Mutex lock to protect from concurrent read/write.
90+
/**
91+
* @brief The mutex lock used to protect the `CancellationContext` object
92+
* from the concurrent read and write operations.
93+
*/
7894
mutable std::recursive_mutex mutex_;
79-
/// Sub operation context return from ExecuteOrCancelled() execute_fn.
80-
/// @deprecated This will be removed once TaskScheduler is used.
95+
/**
96+
* @brief The suboperation context returned from `execute_fn` of
97+
* `ExecuteOrCancelled()`.
98+
*
99+
* @deprecated Will be removed. Use `TaskScheduler` instead.
100+
*/
81101
CancellationToken sub_operation_cancel_token_{};
82-
/// Flag that will be set to `true` on CancelOperation().
102+
/**
103+
* @brief The flag that is set to `true` for `CancelOperation()`.
104+
*/
83105
bool is_cancelled_{false};
84106
};
85107

86-
/// Shared implementation.
108+
/**
109+
* @brief The shared implementation.
110+
*/
87111
std::shared_ptr<CancellationContextImpl> impl_;
88112
};
89113

olp-cpp-sdk-core/include/olp/core/client/CancellationToken.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ namespace olp {
2828
namespace client {
2929

3030
/**
31-
* @brief Cancels service requests
31+
* @brief Cancels service requests.
3232
*/
3333
class CORE_API CancellationToken {
3434
public:
35-
/// The alias for the cancellation function.
35+
/**
36+
* @brief The alias for the cancellation function.
37+
*/
3638
using CancelFuncType = std::function<void()>;
3739

3840
CancellationToken() = default;
3941

4042
/**
4143
* @brief Creates the `CancellationToken` instance.
4244
*
43-
* @param func The operation that should be used to cancel the ongoing.
45+
* @param func The operation that should be used to cancel the ongoing
4446
* operation.
4547
*/
4648
CancellationToken(CancelFuncType func);

olp-cpp-sdk-core/include/olp/core/client/Condition.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,35 @@ namespace olp {
2929
namespace client {
3030

3131
/**
32-
* @brief The Condition helper class allows to wait until the notification is
33-
* called by a task or cancellation is performed by the user.
32+
* @brief A helper class that allows one thread to call and wait for a
33+
* notification in the other thread.
3434
*/
3535
class Condition final {
3636
public:
3737
Condition() = default;
3838

3939
/**
40-
* @brief Should be called by task's callback to notify \c Wait to unblock the
41-
* routine.
40+
* @brief Called by the task callback to notify `Wait` to unblock
41+
* the routine.
4242
*/
4343
void Notify() {
4444
std::unique_lock<std::mutex> lock(mutex_);
4545
signaled_ = true;
4646

47-
// Condition should be under the lock in order to not run into the data
48-
// race, which might occur when spurious wakeup happens in the other
49-
// thread while waiting for the condition's signal.
47+
// Condition should be under the lock not to run into the data
48+
// race that might occur when a spurious wakeup happens in the other
49+
// thread while waiting for the condition signal.
5050
condition_.notify_one();
5151
}
5252

5353
/**
54-
* @brief Waits a task for a \c Notify or \c CancellationContext to be
55-
* cancelled by the user.
56-
* @param timeout milliseconds to wait on condition
57-
* @return True on notified wake, False on timeout
54+
* @brief Waits for the `Notify` function.
55+
*
56+
* @param timeout The time (in milliseconds) during which the `Wait`
57+
* function waits for the notification.
58+
*
59+
* @return True if the notification is returned before the timeout; false
60+
* otherwise.
5861
*/
5962
bool Wait(std::chrono::milliseconds timeout = std::chrono::seconds(60)) {
6063
std::unique_lock<std::mutex> lock(mutex_);

olp-cpp-sdk-core/include/olp/core/client/ErrorCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum class ErrorCode {
4848
RequestTimeout,
4949

5050
/**
51-
* Internal server failure.
51+
* An internal server failure.
5252
*/
5353
InternalFailure,
5454

0 commit comments

Comments
 (0)