Skip to content

Commit 2a0ff4e

Browse files
Rename "subscriber" to "subscription" (#204)
Signed-off-by: Christophe Bedard <[email protected]>
1 parent 153c2ce commit 2a0ff4e

16 files changed

+80
-80
lines changed

email/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ set(SOURCES
5656
src/service_handler.cpp
5757
src/service_info.cpp
5858
src/service_server.cpp
59-
src/subscriber.cpp
59+
src/subscription.cpp
6060
src/subscription_handler.cpp
6161
src/timestamp.cpp
6262
src/utils.cpp

email/include/email/subscriber.hpp renamed to email/include/email/subscription.hpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef EMAIL__SUBSCRIBER_HPP_
16-
#define EMAIL__SUBSCRIBER_HPP_
15+
#ifndef EMAIL__SUBSCRIPTION_HPP_
16+
#define EMAIL__SUBSCRIPTION_HPP_
1717

1818
#include <chrono>
1919
#include <memory>
@@ -33,25 +33,25 @@
3333
namespace email
3434
{
3535

36-
/// Message subscriber.
36+
/// Message subscription.
3737
/**
3838
* Uses emails, with the topic name as the email subject and the data as the email body.
3939
* TODO(christophebedard) add take to get a vector of all available messages?
4040
*/
41-
class Subscriber : public PubSubObject
41+
class Subscription : public PubSubObject
4242
{
4343
public:
4444
/// Constructor.
4545
/**
4646
* \param topic_name the topic name to subscribe to
4747
*/
4848
EMAIL_PUBLIC
49-
explicit Subscriber(const std::string & topic_name);
49+
explicit Subscription(const std::string & topic_name);
5050

5151
EMAIL_PUBLIC
52-
virtual ~Subscriber();
52+
virtual ~Subscription();
5353

54-
/// Check if the subscriber has a message.
54+
/// Check if the subscription has a message.
5555
/**
5656
* \return true if there is a message, false otherwise
5757
*/
@@ -80,12 +80,12 @@ class Subscriber : public PubSubObject
8080
get_message_with_info();
8181

8282
private:
83-
EMAIL_DISABLE_COPY(Subscriber)
83+
EMAIL_DISABLE_COPY(Subscription)
8484

8585
std::shared_ptr<Logger> logger_;
86-
SubscriptionHandler::SubscriberQueue::SharedPtr messages_;
86+
SubscriptionHandler::SubscriptionQueue::SharedPtr messages_;
8787
};
8888

8989
} // namespace email
9090

91-
#endif // EMAIL__SUBSCRIBER_HPP_
91+
#endif // EMAIL__SUBSCRIPTION_HPP_

email/include/email/subscription_handler.hpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,35 @@ namespace email
3333

3434
/// Email handler for subscriptions.
3535
/**
36-
* Distributes new messages to the right subscriber(s).
36+
* Distributes new messages to the right subscription(s).
3737
*/
3838
class SubscriptionHandler
3939
{
4040
public:
41-
using SubscriberQueue = SafeQueue<std::pair<std::string, MessageInfo>>;
41+
using SubscriptionQueue = SafeQueue<std::pair<std::string, MessageInfo>>;
4242

4343
/// Constructor.
4444
SubscriptionHandler();
4545

4646
~SubscriptionHandler();
4747

48-
/// Register a subscriber with the handler.
48+
/// Register a subscription with the handler.
4949
/**
50-
* New messages will be added to the subscriber's queue if the topic name matches.
50+
* New messages will be added to the subscription's queue if the topic name matches.
5151
*
5252
* \param topic_name the topic name
53-
* \param message_queue the subscriber's message queue to push the new message to
53+
* \param message_queue the subscription's message queue to push the new message to
5454
*/
5555
void
56-
register_subscriber(
56+
register_subscription(
5757
const std::string & topic_name,
58-
SubscriberQueue::SharedPtr message_queue);
58+
SubscriptionQueue::SharedPtr message_queue);
5959

6060
/// Handle new email.
6161
/**
6262
* To be called by the `PollingManager`.
6363
*
64-
* Adds the message to the queues of subscribers with topic names that match the new message.
64+
* Adds the message to the queues of subscriptions with topic names that match the new message.
6565
*
6666
* \param data the new email data
6767
*/
@@ -72,8 +72,8 @@ class SubscriptionHandler
7272
EMAIL_DISABLE_COPY(SubscriptionHandler)
7373

7474
std::shared_ptr<Logger> logger_;
75-
std::mutex subscribers_mutex_;
76-
std::multimap<std::string, SubscriberQueue::SharedPtr> subscribers_;
75+
std::mutex subscriptions_mutex_;
76+
std::multimap<std::string, SubscriptionQueue::SharedPtr> subscriptions_;
7777
};
7878

7979
} // namespace email

email/include/email/wait.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "email/service_client.hpp"
2525
#include "email/service_request.hpp"
2626
#include "email/service_server.hpp"
27-
#include "email/subscriber.hpp"
27+
#include "email/subscription.hpp"
2828
#include "email/visibility_control.hpp"
2929

3030
namespace email
@@ -42,17 +42,17 @@ namespace email
4242
EMAIL_PUBLIC
4343
std::pair<std::string, MessageInfo>
4444
wait_for_message_with_info(
45-
Subscriber * subscription,
45+
Subscription * subscription,
4646
const std::chrono::milliseconds timeout = std::chrono::milliseconds(-1));
4747

4848
/// Get a message with info from a subscription, waiting until one is available.
4949
/**
50-
* \see wait_for_message(std::shared_ptr<Subscriber>, const std::chrono::milliseconds)
50+
* \see wait_for_message(std::shared_ptr<Subscription>, const std::chrono::milliseconds)
5151
*/
5252
EMAIL_PUBLIC
5353
std::pair<std::string, MessageInfo>
5454
wait_for_message_with_info(
55-
std::shared_ptr<Subscriber> subscription,
55+
std::shared_ptr<Subscription> subscription,
5656
const std::chrono::milliseconds timeout = std::chrono::milliseconds(-1));
5757

5858
/// Get a message from a subscription, waiting until one is available.
@@ -67,17 +67,17 @@ wait_for_message_with_info(
6767
EMAIL_PUBLIC
6868
std::string
6969
wait_for_message(
70-
Subscriber * subscription,
70+
Subscription * subscription,
7171
const std::chrono::milliseconds timeout = std::chrono::milliseconds(-1));
7272

7373
/// Get a message from a subscription, waiting until one is available.
7474
/**
75-
* \see wait_for_message(std::shared_ptr<Subscriber>, const std::chrono::milliseconds)
75+
* \see wait_for_message(std::shared_ptr<Subscription>, const std::chrono::milliseconds)
7676
*/
7777
EMAIL_PUBLIC
7878
std::string
7979
wait_for_message(
80-
std::shared_ptr<Subscriber> subscription,
80+
std::shared_ptr<Subscription> subscription,
8181
const std::chrono::milliseconds timeout = std::chrono::milliseconds(-1));
8282

8383
/// Get a service reponse with info, waiting until it is available.

email/include/email/wait_set.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "email/guard_condition.hpp"
2424
#include "email/service_client.hpp"
2525
#include "email/service_server.hpp"
26-
#include "email/subscriber.hpp"
26+
#include "email/subscription.hpp"
2727
#include "email/macros.hpp"
2828
#include "email/visibility_control.hpp"
2929

@@ -41,14 +41,14 @@ class WaitSet
4141
/// Constructor.
4242
EMAIL_PUBLIC
4343
WaitSet(
44-
std::vector<Subscriber *> subscriptions = {},
44+
std::vector<Subscription *> subscriptions = {},
4545
std::vector<ServiceClient *> clients = {},
4646
std::vector<ServiceServer *> servers = {},
4747
std::vector<GuardCondition *> guard_conditions = {});
4848

4949
/// Constructor.
5050
EMAIL_PUBLIC
51-
explicit WaitSet(Subscriber * subscription);
51+
explicit WaitSet(Subscription * subscription);
5252

5353
EMAIL_PUBLIC
5454
~WaitSet();
@@ -78,7 +78,7 @@ class WaitSet
7878
/// Add a subscription.
7979
EMAIL_PUBLIC
8080
void
81-
add_subscription(Subscriber * subscription);
81+
add_subscription(Subscription * subscription);
8282

8383
/// Add a client.
8484
EMAIL_PUBLIC
@@ -97,7 +97,7 @@ class WaitSet
9797

9898
/// Get the subscriptions.
9999
EMAIL_PUBLIC
100-
const std::vector<Subscriber *> &
100+
const std::vector<Subscription *> &
101101
get_subscriptions() const;
102102

103103
/// Get the clients.
@@ -156,7 +156,7 @@ class WaitSet
156156
std::chrono::steady_clock::time_point start);
157157

158158
std::shared_ptr<Logger> logger_;
159-
std::vector<Subscriber *> subscriptions_;
159+
std::vector<Subscription *> subscriptions_;
160160
std::vector<ServiceClient *> clients_;
161161
std::vector<ServiceServer *> servers_;
162162
std::vector<GuardCondition *> guard_conditions_;

email/src/subscriber.cpp renamed to email/src/subscription.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,37 @@
2424
#include "email/message_info.hpp"
2525
#include "email/pub_sub.hpp"
2626
#include "email/safe_queue.hpp"
27-
#include "email/subscriber.hpp"
27+
#include "email/subscription.hpp"
2828
#include "email/subscription_handler.hpp"
2929

3030
namespace email
3131
{
3232

33-
Subscriber::Subscriber(const std::string & topic_name)
33+
Subscription::Subscription(const std::string & topic_name)
3434
: PubSubObject(topic_name),
35-
logger_(log::get_or_create("Subscriber::" + topic_name)),
36-
messages_(std::make_shared<SubscriptionHandler::SubscriberQueue>())
35+
logger_(log::get_or_create("Subscription::" + topic_name)),
36+
messages_(std::make_shared<SubscriptionHandler::SubscriptionQueue>())
3737
{
3838
logger_->debug("created with GID: {}", get_gid());
3939
// Register with handler
40-
get_global_context()->get_subscription_handler()->register_subscriber(
40+
get_global_context()->get_subscription_handler()->register_subscription(
4141
get_topic_name(),
4242
messages_);
4343
}
4444

45-
Subscriber::~Subscriber()
45+
Subscription::~Subscription()
4646
{
4747
logger_->debug("destroying");
4848
}
4949

5050
bool
51-
Subscriber::has_message() const
51+
Subscription::has_message() const
5252
{
5353
return !messages_->empty();
5454
}
5555

5656
std::optional<std::string>
57-
Subscriber::get_message()
57+
Subscription::get_message()
5858
{
5959
if (!has_message()) {
6060
return std::nullopt;
@@ -63,7 +63,7 @@ Subscriber::get_message()
6363
}
6464

6565
std::optional<std::pair<std::string, MessageInfo>>
66-
Subscriber::get_message_with_info()
66+
Subscription::get_message_with_info()
6767
{
6868
if (!has_message()) {
6969
return std::nullopt;

email/src/subscription_handler.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace email
3131

3232
SubscriptionHandler::SubscriptionHandler()
3333
: logger_(log::create("SubscriptionHandler")),
34-
subscribers_mutex_(),
35-
subscribers_()
34+
subscriptions_mutex_(),
35+
subscriptions_()
3636
{
3737
// Register handler with the polling manager
3838
get_global_context()->get_polling_manager()->register_handler(
@@ -49,13 +49,13 @@ SubscriptionHandler::~SubscriptionHandler()
4949
}
5050

5151
void
52-
SubscriptionHandler::register_subscriber(
52+
SubscriptionHandler::register_subscription(
5353
const std::string & topic_name,
54-
SubscriberQueue::SharedPtr message_queue)
54+
SubscriptionQueue::SharedPtr message_queue)
5555
{
5656
{
57-
std::scoped_lock<std::mutex> lock(subscribers_mutex_);
58-
subscribers_.insert({topic_name, message_queue});
57+
std::scoped_lock<std::mutex> lock(subscriptions_mutex_);
58+
subscriptions_.insert({topic_name, message_queue});
5959
}
6060
logger_->debug("subscription registered with topic name: {}", topic_name);
6161
}
@@ -75,8 +75,8 @@ SubscriptionHandler::handle(const struct EmailData & data)
7575

7676
// Push it to the right queue
7777
{
78-
std::scoped_lock<std::mutex> lock(subscribers_mutex_);
79-
auto range = subscribers_.equal_range(topic);
78+
std::scoped_lock<std::mutex> lock(subscriptions_mutex_);
79+
auto range = subscriptions_.equal_range(topic);
8080
for (auto it = range.first; it != range.second; ++it) {
8181
// Push message content to the queue
8282
logger_->debug("adding message to subscription queue with topic: {}", topic);

email/src/wait.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
#include "email/service_info.hpp"
2424
#include "email/service_request.hpp"
2525
#include "email/service_server.hpp"
26-
#include "email/subscriber.hpp"
26+
#include "email/subscription.hpp"
2727
#include "email/wait_set.hpp"
2828

2929
namespace email
3030
{
3131

3232
std::pair<std::string, MessageInfo>
3333
wait_for_message_with_info(
34-
Subscriber * subscription,
34+
Subscription * subscription,
3535
const std::chrono::milliseconds timeout)
3636
{
3737
email::WaitSet waitset({subscription});
@@ -43,23 +43,23 @@ wait_for_message_with_info(
4343

4444
std::pair<std::string, MessageInfo>
4545
wait_for_message_with_info(
46-
std::shared_ptr<Subscriber> subscription,
46+
std::shared_ptr<Subscription> subscription,
4747
const std::chrono::milliseconds timeout)
4848
{
4949
return wait_for_message_with_info(subscription.get(), timeout);
5050
}
5151

5252
std::string
5353
wait_for_message(
54-
Subscriber * subscription,
54+
Subscription * subscription,
5555
const std::chrono::milliseconds timeout)
5656
{
5757
return wait_for_message_with_info(subscription, timeout).first;
5858
}
5959

6060
std::string
6161
wait_for_message(
62-
std::shared_ptr<Subscriber> subscription,
62+
std::shared_ptr<Subscription> subscription,
6363
const std::chrono::milliseconds timeout)
6464
{
6565
return wait_for_message(subscription.get(), timeout);

0 commit comments

Comments
 (0)