reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ProtonThreadBase.hxx
Go to the documentation of this file.
1#ifndef PROTONTHREADBASE_HXX
2#define PROTONTHREADBASE_HXX
3
4#include <sstream>
5#include <string>
6
7#include "ThreadIf.hxx"
8#include "TimeLimitFifo.hxx"
9
10#include <proton/connection.hpp>
11#include <proton/function.hpp>
12#include <proton/messaging_handler.hpp>
13#include <proton/receiver.hpp>
14#include <proton/sender.hpp>
15#include <proton/transport.hpp>
16#include <proton/work_queue.hpp>
17
18#include "cajun/json/elements.h"
19
20namespace resip {
21
22class ProtonThreadBase : public resip::ThreadIf, proton::messaging_handler
23{
24public:
25
27 {
28 public:
29 ProtonReceiverBase(const std::string &u,
30 std::chrono::duration<long int> maximumAge,
31 std::chrono::duration<long int> retryDelay);
32 virtual ~ProtonReceiverBase();
33 std::chrono::duration<long int> mMaximumAge;
34 std::chrono::duration<long int> mRetryDelay;
35 std::string mUrl;
36 proton::receiver mReceiver;
37 proton::work_queue* mWorkQueue;
39 std::unique_ptr<json::Object> getBodyAsJSON(const proton::message &m);
40 protected:
42 };
43
45 {
46 public:
47 ProtonSenderBase(const std::string &u,
48 std::chrono::duration<long int> retryDelay = std::chrono::seconds(2));
49 virtual ~ProtonSenderBase();
50 std::chrono::duration<long int> mRetryDelay;
51 std::string mUrl;
52 proton::sender mSender;
53 proton::work_queue* mWorkQueue;
56
57 void sendMessage(const resip::Data& msg);
58 void doSend();
59 protected:
61 };
62
63 ProtonThreadBase(std::chrono::duration<long int> mRetryDelay = std::chrono::seconds(2));
64 virtual ~ProtonThreadBase();
65
66 void addReceiver(std::shared_ptr<ProtonReceiverBase> rx);
67 void addSender(std::shared_ptr<ProtonSenderBase> tx);
68
69 std::shared_ptr<ProtonSenderBase> getSenderForReply(const std::string& replyTo);
70
71 void on_container_start(proton::container &c) override;
72 void on_connection_open(proton::connection &conn) override;
73 void on_receiver_open(proton::receiver &) override;
74 void on_receiver_close(proton::receiver &) override;
75 void on_sender_open(proton::sender &) override;
76 void on_sender_close(proton::sender &) override;
77 void on_transport_error(proton::transport &t) override;
78 void on_message(proton::delivery &d, proton::message &m) override;
79 void on_sendable(proton::sender &s) override;
80 void on_tracker_accept(proton::tracker &t) override;
81
82 virtual void thread() override;
83 virtual void shutdown() override;
84
85
86private:
87 bool checkSenderShutdown();
88 void doShutdown();
89
90 void openReceiver(std::shared_ptr<ProtonReceiverBase> rx);
91 void openSender(std::shared_ptr<ProtonSenderBase> tx);
92
93 std::chrono::duration<long int> mRetryDelay;
94
95 std::shared_ptr<proton::container> mContainer;
96 proton::connection mConnection;
97 bool mConnected;
98
99 std::vector<std::shared_ptr<ProtonReceiverBase>> mReceivers;
100 std::vector<std::shared_ptr<ProtonSenderBase>> mSenders;
101
102 bool mStarted = false;
103};
104
105} // namespace
106
107#endif
108
109/* ====================================================================
110 *
111 * Copyright 2016-2022 Daniel Pocock https://danielpocock.com
112 * Copyright 2022 Software Freedom Institute LLC https://softwarefreedom.institute
113 *
114 * Redistribution and use in source and binary forms, with or without
115 * modification, are permitted provided that the following conditions
116 * are met:
117 *
118 * 1. Redistributions of source code must retain the above copyright
119 * notice, this list of conditions and the following disclaimer.
120 *
121 * 2. Redistributions in binary form must reproduce the above copyright
122 * notice, this list of conditions and the following disclaimer in
123 * the documentation and/or other materials provided with the
124 * distribution.
125 *
126 * 3. Neither the name of the author(s) nor the names of any contributors
127 * may be used to endorse or promote products derived from this software
128 * without specific prior written permission.
129 *
130 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
131 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
132 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
133 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
134 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
135 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
136 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
137 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
138 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
139 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
140 * SUCH DAMAGE.
141 *
142 * ====================================================================
143 *
144 *
145 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
resip::TimeLimitFifo< proton::message > mFifo
std::chrono::duration< long int > mMaximumAge
std::chrono::duration< long int > mRetryDelay
std::unique_ptr< json::Object > getBodyAsJSON(const proton::message &m)
resip::TimeLimitFifo< proton::message > & getFifo()
resip::TimeLimitFifo< Data > & getFifo()
std::chrono::duration< long int > mRetryDelay
void on_transport_error(proton::transport &t) override
void on_sender_close(proton::sender &) override
std::shared_ptr< ProtonSenderBase > getSenderForReply(const std::string &replyTo)
void on_sender_open(proton::sender &) override
void on_receiver_close(proton::receiver &) override
void on_connection_open(proton::connection &conn) override
void addReceiver(std::shared_ptr< ProtonReceiverBase > rx)
void on_tracker_accept(proton::tracker &t) override
void on_container_start(proton::container &c) override
void on_receiver_open(proton::receiver &) override
void on_sendable(proton::sender &s) override
void addSender(std::shared_ptr< ProtonSenderBase > tx)
virtual void shutdown() override
virtual void thread() override
void on_message(proton::delivery &d, proton::message &m) override
A wrapper class to create and spawn a thread.
Definition ThreadIf.hxx:54
dcm! – add UnusedChecking(_enum) below;
unsigned long long uint64_t
Definition Stun.hxx:39