Skip to content

Commit fb81873

Browse files
lennartbecker-dMaximilianToe
authored andcommitted
Added test and refactored some parts of usubscription
1 parent 67e12d4 commit fb81873

File tree

15 files changed

+1487
-301
lines changed

15 files changed

+1487
-301
lines changed

include/up-cpp/client/usubscription/v3/RequestBuilder.h

Lines changed: 56 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
1+
// SPDX-FileCopyrightText: 2025 Contributors to the Eclipse Foundation
22
//
33
// See the NOTICE file(s) distributed with this work for additional
44
// information regarding copyright ownership.
@@ -18,12 +18,10 @@
1818

1919
namespace uprotocol::core::usubscription::v3 {
2020

21-
/**
22-
* @struct USubscriptionOptions
23-
* @brief Additional details for uSubscription service.
24-
*
25-
* Each member represents an optional parameter for the uSubscription service.
26-
*/
21+
/// @struct USubscriptionOptions
22+
/// @brief Additional details for uSubscription service.
23+
///
24+
/// Each member represents an optional parameter for the uSubscription service.
2725
struct USubscriptionOptions {
2826
/// Permission level of the subscription request
2927
std::optional<uint32_t> permission_level;
@@ -39,80 +37,64 @@ struct USubscriptionOptions {
3937
std::optional<google::protobuf::Any> subscription_details;
4038
};
4139

42-
/**
43-
* @brief Builds different requests using specified options.
44-
*
45-
* This struct facilitates the construction of requests based on
46-
* `USubscriptionOptions`, providing methods to build different requests.
47-
*/
40+
/// @brief Builds different requests using specified options.
41+
///
42+
/// This struct facilitates the construction of requests based on
43+
/// `USubscriptionOptions`, providing methods to build different requests.
4844
struct RequestBuilder {
49-
/**
50-
* @brief Constructs a RequestBuilder with the given subscription options.
51-
*
52-
* @param options Subscription options to configure the requests. Defaults
53-
* to empty options.
54-
*/
55-
explicit RequestBuilder(USubscriptionOptions options = {})
56-
: options_(std::move(options)) {}
45+
/// @brief Builds a subscription request for a given topic.
46+
///
47+
/// @param topic The `v1::UUri` representing the topic for the subscription.
48+
///
49+
/// @return A `SubscriptionRequest` configured for the specified topic.
50+
static SubscriptionRequest buildSubscriptionRequest(
51+
const v1::UUri& topic, const USubscriptionOptions& options = {});
5752

58-
/**
59-
* @brief Builds a subscription request for a given topic.
60-
*
61-
* @param topic The `v1::UUri` representing the topic for the subscription.
62-
*
63-
* @return A `SubscriptionRequest` configured for the specified topic.
64-
*/
65-
SubscriptionRequest buildSubscriptionRequest(const v1::UUri& topic) const;
66-
67-
/**
68-
* @brief Builds an unsubscription request for a given topic.
69-
*
70-
* @param topic The `v1::UUri` representing the topic to unsubscribe from.
71-
*
72-
* @return An `UnsubscribeRequest` configured for the specified topic.
73-
*/
53+
/// @brief Builds an unsubscription request for a given topic.
54+
///
55+
/// @param topic The `v1::UUri` representing the topic to unsubscribe from.
56+
///
57+
/// @return An `UnsubscribeRequest` configured for the specified topic.
7458
static UnsubscribeRequest buildUnsubscribeRequest(const v1::UUri& topic);
7559

76-
/**
77-
* @brief Build fetch subscritions request for a given topic.
78-
*
79-
* @param topic The `v1::UUri` representing the topic to fetch.
80-
*
81-
* @return An `FetchSubscriptionsRequest` configured for the specified topic.
82-
*/
83-
static FetchSubscriptionsRequest buildFetchSubscriptionsRequest(const v1::UUri& topic);
84-
85-
/**
86-
* @brief Build fetch subscritions request for a given subscriber.
87-
*
88-
* @param subscriber The `SubscriberInfo` representing the subscriber to fetch.
89-
*
90-
* @return An `FetchSubscriptionsRequest` configured for the specified subscriber.
91-
*/
92-
static FetchSubscriptionsRequest buildFetchSubscriptionsRequest(const SubscriberInfo& subscriber);
60+
/// @brief Build fetch subscritions request for a given topic.
61+
///
62+
/// @param topic The `v1::UUri` representing the topic to fetch.
63+
///
64+
/// @return A `FetchSubscriptionsRequest` configured for the specified
65+
/// topic.
66+
static FetchSubscriptionsRequest buildFetchSubscriptionsRequest(
67+
const v1::UUri& topic);
9368

94-
/**
95-
* @brief Build fetch subscribers request for a given topic.
96-
*
97-
* @param topic The `v1::UUri` representing the topic to fetch.
98-
*
99-
* @return An `FetchSubscribersRequest` configured for the specified topic.
100-
*/
101-
static FetchSubscribersRequest buildFetchSubscribersRequest(const v1::UUri& topic);
69+
/// @brief Build fetch subscritions request for a given subscriber.
70+
///
71+
/// @param subscriber The `SubscriberInfo` representing the subscriber to
72+
/// fetch.
73+
///
74+
/// @return A `FetchSubscriptionsRequest` configured for the specified
75+
/// subscriber.
76+
static FetchSubscriptionsRequest buildFetchSubscriptionsRequest(
77+
const SubscriberInfo& subscriber);
10278

103-
/**
104-
* @brief Build notification request for a given topic. Subscription change notifications
105-
* MUST use topic SubscriptionChange with resource id 0x8000, as per the protobuf definition.
106-
*
107-
* @param topic The `v1::UUri` representing the topic to (un)register for/from.
108-
*
109-
* @return An `NotificationsRequest` configured for the specified topic.
110-
*/
111-
static NotificationsRequest buildNotificationRequest(const v1::UUri& topic);
112-
79+
/// @brief Build fetch subscribers request for a given topic.
80+
///
81+
/// @param topic The `v1::UUri` representing the topic to fetch.
82+
///
83+
/// @return A `FetchSubscribersRequest` configured for the specified topic.
84+
static FetchSubscribersRequest buildFetchSubscribersRequest(
85+
const v1::UUri& topic);
11386

114-
private:
115-
USubscriptionOptions options_; ///< Options used to configure the requests.
87+
/// @brief Build a notifications request for a given topic. Subscription
88+
/// change
89+
/// notifications MUST use topic SubscriptionsChange with resource id
90+
/// 0x8000, as per the protobuf definition.
91+
///
92+
/// @param topic The `v1::UUri` representing the topic to (un)register
93+
/// for/from.
94+
///
95+
/// @return A `NotificationsRequest` configured for the specified topic.
96+
static NotificationsRequest buildNotificationsRequest(
97+
const v1::UUri& topic);
11698
};
11799

118100
} // namespace uprotocol::core::usubscription::v3
Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
1+
// SPDX-FileCopyrightText: 2025 Contributors to the Eclipse Foundation
22
//
33
// See the NOTICE file(s) distributed with this work for additional
44
// information regarding copyright ownership.
@@ -23,31 +23,29 @@
2323
/// The uEntity (type) identifier of the uSubscription service.
2424
constexpr uint32_t USUBSCRIPTION_TYPE_ID = 0x00000000;
2525
/// The (latest) major version of the uSubscription service.
26-
constexpr uint8_t USUBSCRIPTION_VERSION_MAJOR = 0x03;
26+
constexpr uint8_t UE_VERSION_MAJOR = 0x03;
2727
/// The resource identifier of uSubscription's _subscribe_ operation.
2828
constexpr uint16_t RESOURCE_ID_SUBSCRIBE = 0x0001;
2929
/// The resource identifier of uSubscription's _unsubscribe_ operation.
3030
constexpr uint16_t RESOURCE_ID_UNSUBSCRIBE = 0x0002;
3131
/// The resource identifier of uSubscription's _fetch subscriptions_ operation.
3232
constexpr uint16_t RESOURCE_ID_FETCH_SUBSCRIPTIONS = 0x0003;
33-
/// The resource identifier of uSubscription's _register for notifications_ operation.
33+
/// The resource identifier of uSubscription's _register for notifications_
34+
/// operation.
3435
constexpr uint16_t RESOURCE_ID_REGISTER_FOR_NOTIFICATIONS = 0x0006;
35-
/// The resource identifier of uSubscription's _unregister for notifications_ operation.
36+
/// The resource identifier of uSubscription's _unregister for notifications_
37+
/// operation.
3638
constexpr uint16_t RESOURCE_ID_UNREGISTER_FOR_NOTIFICATIONS = 0x0007;
3739
/// The resource identifier of uSubscription's _fetch subscribers_ operation.
3840
constexpr uint16_t RESOURCE_ID_FETCH_SUBSCRIBERS = 0x0008;
39-
// TODO(lennart) see default_call_options() for the request in Rust
40-
constexpr auto USUBSCRIPTION_REQUEST_TTL =
41-
std::chrono::milliseconds(0x0800); // TODO(lennart) change time
41+
42+
constexpr auto USUBSCRIPTION_REQUEST_TTL = std::chrono::milliseconds(5000);
4243

4344
namespace uprotocol::core::usubscription::v3 {
4445
using v3::SubscriptionRequest;
4546
using v3::UnsubscribeRequest;
4647

47-
/// @brief Interface for uEntities to create subscriptions.
48-
///
49-
/// Like all L3 client APIs, the RpcClientUSubscription is a wrapper on top of
50-
/// the L2 Communication APIs and USubscription service.
48+
/// @brief Client which implements the USubscription interface
5149
struct RpcClientUSubscription : USubscription {
5250
using RpcClientUSubscriptionOrStatus =
5351
utils::Expected<std::unique_ptr<RpcClientUSubscription>, v1::UStatus>;
@@ -57,54 +55,72 @@ struct RpcClientUSubscription : USubscription {
5755
template <typename Response>
5856
Response invokeResponse(communication::RpcClient rpc_client);
5957

60-
/// @brief Subscribe to the topic
58+
/// @brief Subscribes from a given topic
6159
///
60+
/// @param subscription_request The request object containing the topic to
61+
/// subscribe to
62+
/// @return Returns a SubscriptionResponse on success and a UStatus else
6263
utils::Expected<SubscriptionResponse, v1::UStatus> subscribe(
6364
const SubscriptionRequest& subscription_request) override;
6465

65-
/// @brief Unsubscribe from the topic
66+
/// @brief Unsubscribes from a given topic
6667
///
68+
/// @param unsubscribe_request The request object containing the topic to
69+
/// unsubscribe from
70+
/// @return Returns an UnsubscribeResponse on success and a UStatus else
6771
utils::Expected<UnsubscribeResponse, v1::UStatus> unsubscribe(
6872
const UnsubscribeRequest& unsubscribe_request) override;
69-
70-
/// @brief Fetch all subscriptions either by topic or subscriber
71-
///
72-
utils::Expected<FetchSubscriptionsResponse, v1::UStatus> fetch_subscriptions(
73-
const FetchSubscriptionsRequest& fetch_subscribers) override;
7473

75-
/// @brief Fetch all subscribers
74+
/// @brief Fetches the list of topics the client is subscribed to
7675
///
76+
/// @param fetch_subscriptions_request The request object
77+
/// @return Returns a FetchSubscriptionsResponse on success and a UStatus
78+
/// else
79+
utils::Expected<FetchSubscriptionsResponse, v1::UStatus>
80+
fetch_subscriptions(
81+
const FetchSubscriptionsRequest& fetch_subscriptions_request) override;
82+
83+
/// @brief Fetches the list of subscribers for a given topic
84+
///
85+
/// @param fetch_subscribers_request The request object containing the topic
86+
/// for which the subscribers are to be fetched
87+
/// @return Returns a FetchSubscribersResponse on success and a UStatus else
7788
utils::Expected<FetchSubscribersResponse, v1::UStatus> fetch_subscribers(
78-
const FetchSubscribersRequest& fetch_subscribers) override;
89+
const FetchSubscribersRequest& fetch_subscribers_request) override;
7990

80-
/// @brief Register for notifications
91+
/// @brief Registers to receive notifications
8192
///
82-
utils::Expected<NotificationsResponse, v1::UStatus> register_for_notifications(const
83-
NotificationsRequest& register_notifications_request) override ;
84-
85-
/// @brief Unregister for notifications
93+
/// @param register_notifications_request The request object containing
94+
/// the details to register for notifications
95+
/// @return Returns a NotificationResponse on success and a UStatus else
96+
utils::Expected<NotificationsResponse, v1::UStatus>
97+
register_for_notifications(
98+
const NotificationsRequest& register_notifications_request) override;
99+
100+
/// @brief Unregisters from receiving notifications.
86101
///
87-
utils::Expected<NotificationsResponse, v1::UStatus> unregister_for_notifications(const
88-
NotificationsRequest& unregister_notifications_request) override ;
102+
/// @param unregister_notifications_request The request object containing
103+
/// the details needed to stop receiving notifications.
104+
/// @return Returns a NotificationResponse on success and a UStatus else
105+
utils::Expected<NotificationsResponse, v1::UStatus>
106+
unregister_for_notifications(
107+
const NotificationsRequest& unregister_notifications_request) override;
89108

90109
/// @brief Constructor
91110
///
92-
/// @param transport Transport to register with.
111+
/// @param transport Transport used to send messages
93112
explicit RpcClientUSubscription(
94113
std::shared_ptr<transport::UTransport> transport)
95114
: transport_(std::move(transport)) {}
96115

97-
/// @brief Destructor
98116
~RpcClientUSubscription() override = default;
99117

100118
private:
101-
// Transport
102119
std::shared_ptr<transport::UTransport> transport_;
103120

104-
// URI info about the uSubscription service
105121
USubscriptionUUriBuilder uuri_builder_;
106122
};
107123

108124
} // namespace uprotocol::core::usubscription::v3
109125

110-
#endif // UP_CPP_CLIENT_USUBSCRIPTION_V3_RPCCLIENTUSUBSCRIPTION_H
126+
#endif // UP_CPP_CLIENT_USUBSCRIPTION_V3_RPCCLIENTUSUBSCRIPTION_H

include/up-cpp/client/usubscription/v3/USubscription.h

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
1+
// SPDX-FileCopyrightText: 2025 Contributors to the Eclipse Foundation
22
//
33
// See the NOTICE file(s) distributed with this work for additional
44
// information regarding copyright ownership.
@@ -19,29 +19,61 @@
1919

2020
namespace uprotocol::core::usubscription::v3 {
2121

22+
/// @brief Interface for uEntities to create subscriptions.
23+
///
24+
/// Like all L3 client APIs, the RpcClientUSubscription is a wrapper on top of
25+
/// the L2 Communication APIs and USubscription service.
2226
struct USubscription {
2327
template <typename R>
2428
using ResponseOrStatus = utils::Expected<R, v1::UStatus>;
2529

2630
virtual ~USubscription() = default;
2731

32+
/// @brief sends a subscription request to a USubscription backend and a
33+
/// response on success or else a status code
34+
///
35+
/// @param subscription_request containing a topic to subscribe to
36+
/// @return SubscriptionReponse on success and UStatus else
2837
virtual ResponseOrStatus<SubscriptionResponse> subscribe(
2938
const SubscriptionRequest& subscription_request) = 0;
3039

40+
/// @brief sends an unsubscribe request to a USubscription backend and a
41+
/// response on success or else a status code
42+
///
43+
/// @param unsubscribe_request containing a topic to unsubscribe
44+
/// @return UnsubscribeResponse on success and UStatus else
3145
virtual ResponseOrStatus<UnsubscribeResponse> unsubscribe(
3246
const UnsubscribeRequest& unsubscribe_request) = 0;
3347

34-
virtual ResponseOrStatus<FetchSubscriptionsResponse> fetch_subscriptions(const
35-
FetchSubscriptionsRequest& fetch_subscribers_request) = 0;
48+
/// @brief fetches all topics the client is subscribed to from the backend
49+
///
50+
/// @param fetch_subscriptions_request
51+
/// @return FetchSubscriptionsResponse on success and UStatus else
52+
virtual ResponseOrStatus<FetchSubscriptionsResponse> fetch_subscriptions(
53+
const FetchSubscriptionsRequest& fetch_subscriptions_request) = 0;
3654

37-
virtual ResponseOrStatus<NotificationsResponse> register_for_notifications(const
38-
NotificationsRequest& register_notifications_request) =0 ;
55+
/// @brief registers for notifications to a USubscription backend
56+
///
57+
/// @param register_notifications_request
58+
/// @return NotificationResponse on success and UStatus else
59+
virtual ResponseOrStatus<NotificationsResponse> register_for_notifications(
60+
const NotificationsRequest& register_notifications_request) = 0;
3961

40-
virtual ResponseOrStatus<NotificationsResponse> unregister_for_notifications(const
41-
NotificationsRequest& unregister_notifications_request) = 0;
62+
/// @brief unregisters for notifications to a USubscription backend
63+
///
64+
/// @param unregister_notifications_request
65+
/// @return NotificationResponse on success and UStatus else
66+
virtual ResponseOrStatus<NotificationsResponse>
67+
unregister_for_notifications(
68+
const NotificationsRequest& unregister_notifications_request) = 0;
4269

43-
virtual ResponseOrStatus<FetchSubscribersResponse> fetch_subscribers(const
44-
FetchSubscribersRequest& fetch_subscribers_request) = 0;
70+
/// @brief fetches all subscribers for a given topic from the backend
71+
///
72+
/// @param fetch_subscriptions_request containing the topic for which the
73+
/// subscribers are fetched
74+
/// @return FetchSubscriptionsResponse on success and UStatus else
75+
virtual ResponseOrStatus<FetchSubscribersResponse> fetch_subscribers(
76+
const FetchSubscribersRequest& fetch_subscribers_request) = 0;
4577
};
4678

4779
} // namespace uprotocol::core::usubscription::v3

include/up-cpp/client/usubscription/v3/USubscriptionUUriBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
1+
// SPDX-FileCopyrightText: 2025 Contributors to the Eclipse Foundation
22
//
33
// See the NOTICE file(s) distributed with this work for additional
44
// information regarding copyright ownership.

0 commit comments

Comments
 (0)