-
Notifications
You must be signed in to change notification settings - Fork 31
Rpc client u subscription #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MaximilianToe
wants to merge
6
commits into
eclipse-uprotocol:main
Choose a base branch
from
MaximilianToe:RpcClientUSubscription
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a742ad4
first implementation of usubscription
MaximilianToe 7040db4
Added test and refactored some parts of usubscription
lennartbecker-d 741e7ba
made USubscription async with InvokeProtoFuture return type
MaximilianToe 7e5f3b6
implemented cr comments
MaximilianToe f567967
rebase and use method in subscription calls
6aae8ea
renamed invokeProtoMethod
MaximilianToe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
include/up-cpp/client/usubscription/v3/RequestBuilder.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// SPDX-FileCopyrightText: 2025 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License Version 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef UP_CPP_CLIENT_USUBSCRIPTION_V3_REQUESTBUILDER_H | ||
#define UP_CPP_CLIENT_USUBSCRIPTION_V3_REQUESTBUILDER_H | ||
#include <up-cpp/utils/ProtoConverter.h> | ||
#include <uprotocol/core/usubscription/v3/usubscription.pb.h> | ||
|
||
#include <utility> | ||
|
||
namespace uprotocol::core::usubscription::v3 { | ||
|
||
/// @struct CallOptions | ||
/// @brief Additional details for uSubscription service. | ||
/// | ||
/// Each member represents an optional parameter for the uSubscription service. | ||
struct CallOptions { | ||
/// Permission level of the subscription request | ||
std::optional<uint32_t> permission_level; | ||
/// TAP token for access. | ||
std::optional<std::string> token; | ||
/// Expiration time of the subscription. | ||
std::optional<std::chrono::system_clock::time_point> when_expire; | ||
/// Sample period for the subscription messages in milliseconds. | ||
std::optional<std::chrono::milliseconds> sample_period_ms; | ||
/// Details of the subscriber. | ||
std::optional<google::protobuf::Any> subscriber_details; | ||
/// Details of the subscription. | ||
std::optional<google::protobuf::Any> subscription_details; | ||
}; | ||
|
||
/// @brief Builds different requests using specified options. | ||
/// | ||
/// This struct facilitates the construction of requests based on | ||
/// `USubscriptionOptions`, providing methods to build different requests. | ||
struct RequestBuilder { | ||
/// @brief Builds a subscription request for a given topic. | ||
/// | ||
/// @param topic The `v1::UUri` representing the topic for the subscription. | ||
/// | ||
/// @return A `SubscriptionRequest` configured for the specified topic. | ||
static SubscriptionRequest buildSubscriptionRequest( | ||
const v1::UUri& topic, const CallOptions& options = {}); | ||
|
||
/// @brief Builds an unsubscription request for a given topic. | ||
/// | ||
/// @param topic The `v1::UUri` representing the topic to unsubscribe from. | ||
/// | ||
/// @return An `UnsubscribeRequest` configured for the specified topic. | ||
static UnsubscribeRequest buildUnsubscribeRequest(const v1::UUri& topic); | ||
|
||
/// @brief Build fetch subscritions request for a given topic. | ||
/// | ||
/// @param topic The `v1::UUri` representing the topic to fetch. | ||
/// | ||
/// @return A `FetchSubscriptionsRequest` configured for the specified | ||
/// topic. | ||
static FetchSubscriptionsRequest buildFetchSubscriptionsRequest( | ||
const v1::UUri& topic); | ||
|
||
/// @brief Build fetch subscritions request for a given subscriber. | ||
/// | ||
/// @param subscriber The `SubscriberInfo` representing the subscriber to | ||
/// fetch. | ||
/// | ||
/// @return A `FetchSubscriptionsRequest` configured for the specified | ||
/// subscriber. | ||
static FetchSubscriptionsRequest buildFetchSubscriptionsRequest( | ||
const SubscriberInfo& subscriber); | ||
|
||
/// @brief Build fetch subscribers request for a given topic. | ||
/// | ||
/// @param topic The `v1::UUri` representing the topic to fetch. | ||
/// | ||
/// @return A `FetchSubscribersRequest` configured for the specified topic. | ||
static FetchSubscribersRequest buildFetchSubscribersRequest( | ||
const v1::UUri& topic); | ||
|
||
/// @brief Build a notifications request for a given topic. Subscription | ||
/// change | ||
/// notifications MUST use topic SubscriptionsChange with resource id | ||
/// 0x8000, as per the protobuf definition. | ||
/// | ||
/// @param topic The `v1::UUri` representing the topic to (un)register | ||
/// for/from. | ||
/// | ||
/// @return A `NotificationsRequest` configured for the specified topic. | ||
static NotificationsRequest buildNotificationsRequest( | ||
const v1::UUri& topic); | ||
}; | ||
|
||
} // namespace uprotocol::core::usubscription::v3 | ||
#endif // UP_CPP_CLIENT_USUBSCRIPTION_V3_REQUESTBUILDER_H |
134 changes: 134 additions & 0 deletions
134
include/up-cpp/client/usubscription/v3/RpcClientUSubscription.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// SPDX-FileCopyrightText: 2025 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License Version 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef UP_CPP_CLIENT_USUBSCRIPTION_V3_RPCCLIENTUSUBSCRIPTION_H | ||
#define UP_CPP_CLIENT_USUBSCRIPTION_V3_RPCCLIENTUSUBSCRIPTION_H | ||
|
||
#include <up-cpp/communication/NotificationSink.h> | ||
#include <up-cpp/communication/RpcClient.h> | ||
#include <up-cpp/transport/UTransport.h> | ||
#include <uprotocol/core/usubscription/v3/usubscription.pb.h> | ||
|
||
#include "up-cpp/client/usubscription/v3/USubscription.h" | ||
#include "up-cpp/client/usubscription/v3/USubscriptionUUriBuilder.h" | ||
|
||
/// The uEntity (type) identifier of the uSubscription service. | ||
constexpr uint32_t USUBSCRIPTION_TYPE_ID = 0x00000000; | ||
/// The (latest) major version of the uSubscription service. | ||
constexpr uint8_t UE_VERSION_MAJOR = 0x03; | ||
/// The resource identifier of uSubscription's _subscribe_ operation. | ||
constexpr uint16_t RESOURCE_ID_SUBSCRIBE = 0x0001; | ||
/// The resource identifier of uSubscription's _unsubscribe_ operation. | ||
constexpr uint16_t RESOURCE_ID_UNSUBSCRIBE = 0x0002; | ||
/// The resource identifier of uSubscription's _fetch subscriptions_ operation. | ||
constexpr uint16_t RESOURCE_ID_FETCH_SUBSCRIPTIONS = 0x0003; | ||
/// The resource identifier of uSubscription's _register for notifications_ | ||
/// operation. | ||
constexpr uint16_t RESOURCE_ID_REGISTER_FOR_NOTIFICATIONS = 0x0006; | ||
/// The resource identifier of uSubscription's _unregister for notifications_ | ||
/// operation. | ||
constexpr uint16_t RESOURCE_ID_UNREGISTER_FOR_NOTIFICATIONS = 0x0007; | ||
/// The resource identifier of uSubscription's _fetch subscribers_ operation. | ||
constexpr uint16_t RESOURCE_ID_FETCH_SUBSCRIBERS = 0x0008; | ||
|
||
constexpr auto USUBSCRIPTION_REQUEST_TTL = std::chrono::milliseconds(5000); | ||
|
||
namespace uprotocol::core::usubscription::v3 { | ||
using v3::SubscriptionRequest; | ||
using v3::UnsubscribeRequest; | ||
|
||
struct USubscriptionOptions { | ||
std::string authority_name; | ||
uint16_t instance_id = 0x0000; | ||
}; | ||
|
||
/// @brief Client which implements the USubscription interface | ||
struct RpcClientUSubscription : USubscription { | ||
using RpcClientUSubscriptionOrStatus = | ||
utils::Expected<std::unique_ptr<RpcClientUSubscription>, v1::UStatus>; | ||
using ListenCallback = transport::UTransport::ListenCallback; | ||
using ListenHandle = transport::UTransport::ListenHandle; | ||
|
||
/// @brief Subscribes from a given topic | ||
/// | ||
/// @param subscription_request The request object containing the topic to | ||
/// subscribe to | ||
/// @return Returns a future that reslves to a SubscriptionResponse on | ||
/// success and a UStatus else | ||
communication::RpcClient::InvokeProtoFuture<SubscriptionResponse> subscribe( | ||
const SubscriptionRequest& subscription_request) override; | ||
|
||
/// @brief Unsubscribes from a given topic | ||
/// | ||
/// @param unsubscribe_request The request object containing the topic to | ||
/// unsubscribe from | ||
/// @return Returns an UnsubscribeResponse on success and a UStatus else | ||
communication::RpcClient::InvokeProtoFuture<UnsubscribeResponse> | ||
unsubscribe(const UnsubscribeRequest& unsubscribe_request) override; | ||
|
||
/// @brief Fetches the list of topics the client is subscribed to | ||
/// | ||
/// @param fetch_subscriptions_request The request object | ||
/// @return Returns a future that reslves to a FetchSubscriptionsResponse on | ||
/// success and a UStatus else | ||
communication::RpcClient::InvokeProtoFuture<FetchSubscriptionsResponse> | ||
fetch_subscriptions( | ||
const FetchSubscriptionsRequest& fetch_subscriptions_request) override; | ||
|
||
/// @brief Fetches the list of subscribers for a given topic | ||
/// | ||
/// @param fetch_subscribers_request The request object containing the topic | ||
/// for which the subscribers are to be fetched | ||
/// @return Returns a FetchSubscribersResponse on success and a UStatus else | ||
communication::RpcClient::InvokeProtoFuture<FetchSubscribersResponse> | ||
fetch_subscribers( | ||
const FetchSubscribersRequest& fetch_subscribers_request) override; | ||
|
||
/// @brief Registers to receive notifications | ||
/// | ||
/// @param register_notifications_request The request object containing | ||
/// the details to register for notifications | ||
/// @return Returns a future that resolves to a NotificationResponse on | ||
/// success and a UStatus else | ||
communication::RpcClient::InvokeProtoFuture<NotificationsResponse> | ||
register_for_notifications( | ||
const NotificationsRequest& register_notifications_request) override; | ||
|
||
/// @brief Unregisters from receiving notifications. | ||
/// | ||
/// @param unregister_notifications_request The request object containing | ||
/// the details needed to stop receiving notifications. | ||
/// @return Returns future that resolves to a NotificationResponse on | ||
/// success and a UStatus else | ||
communication::RpcClient::InvokeProtoFuture<NotificationsResponse> | ||
unregister_for_notifications( | ||
const NotificationsRequest& unregister_notifications_request) override; | ||
|
||
/// @brief Constructor | ||
/// | ||
/// @param transport Transport used to send messages | ||
/// @param options Struct containing all options for the USubscription | ||
/// client | ||
explicit RpcClientUSubscription( | ||
std::shared_ptr<transport::UTransport> transport, | ||
const USubscriptionOptions& options); | ||
|
||
~RpcClientUSubscription() override = default; | ||
|
||
private: | ||
std::shared_ptr<transport::UTransport> transport_; | ||
std::shared_ptr<communication::RpcClient> rpc_client_; | ||
USubscriptionUUriBuilder uuri_builder_; | ||
}; | ||
|
||
} // namespace uprotocol::core::usubscription::v3 | ||
|
||
#endif // UP_CPP_CLIENT_USUBSCRIPTION_V3_RPCCLIENTUSUBSCRIPTION_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.