reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
UserAgent.hxx
Go to the documentation of this file.
1#if !defined(UserAgent_hxx)
2#define UserAgent_hxx
3
7#include "HandleTypes.hxx"
8
17#include <rutil/Log.hxx>
18#include <rutil/Mutex.hxx>
19
20#include <memory>
21
22namespace recon
23{
24
25class UserAgentShutdownCmd;
27class UserAgentClientSubscription;
28class UserAgentClientPublication;
29class UserAgentRegistration;
30
55 public resip::Postable
56{
57public:
58
80 virtual ~UserAgent();
81
90 void startup();
91
99 virtual void process(int timeoutMs); // call this in a loop
100
108 void shutdown();
109
114 void logDnsCache();
115
119 void clearDnsCache();
120
127
128 // Utility Methods ////////////////////////////////////////////////////////////
144
156
165 ConversationProfileHandle addConversationProfile(std::shared_ptr<ConversationProfile> conversationProfile, bool defaultOutgoing=true); // thread safe
166
174
185
200 virtual void startApplicationTimer(unsigned int timerId, std::chrono::duration<double> duration, unsigned int seqNumber);
201
217 SubscriptionHandle createSubscription(const resip::Data& eventType, const resip::NameAddr& target, unsigned int subscriptionTime, const resip::Mime& mimeType); // thread safe
218
226
229
231 // UserAgent Handlers //////////////////////////////////////////////
233
246 virtual void onApplicationTimer(unsigned int timerId, std::chrono::duration<double> duration, unsigned int seqNumber);
247
259
270 virtual void onSubscriptionTerminated(SubscriptionHandle handle, unsigned int statusCode);
271
275 const char* sendMessage(const resip::NameAddr& destination, const resip::Data& msg, const resip::Mime& mimeType);
276
277 std::shared_ptr<UserAgentMasterProfile> getUserAgentMasterProfile() const noexcept;
278
280 resip::SipStack& getSipStack() { return mStack; };
282
283 // Shutdown Handler ////////////////////////////////////////////////////////////
284 void onDumCanBeDeleted();
285
286 // Postable for Connection Terminated event
287 virtual void post(resip::Message* msg);
288
289 // Registration Handler ////////////////////////////////////////////////////////
294
295 // ClientSubscriptionHandler ///////////////////////////////////////////////////
296 virtual void onUpdatePending(resip::ClientSubscriptionHandle h, const resip::SipMessage& notify, bool outOfOrder);
297 virtual void onUpdateActive(resip::ClientSubscriptionHandle h, const resip::SipMessage& notify, bool outOfOrder);
298 virtual void onUpdateExtension(resip::ClientSubscriptionHandle, const resip::SipMessage& notify, bool outOfOrder);
302
303 // ClientPublicationHandler ///////////////////////////////////////////////////
304 virtual void onSuccess(resip::ClientPublicationHandle h, const resip::SipMessage& status);
305 virtual void onRemove(resip::ClientPublicationHandle h, const resip::SipMessage& status);
307 virtual void onFailure(resip::ClientPublicationHandle h, const resip::SipMessage& status);
308
309 // UserProfile selection for incoming and outgoing calls, override to customize
310 std::shared_ptr<ConversationProfile> getDefaultOutgoingConversationProfile();
311 // Returns the ConversationProfile for a specific media address
312 std::shared_ptr<ConversationProfile> getConversationProfileByMediaAddress(const resip::Data& mediaAddress);
313 virtual std::shared_ptr<ConversationProfile> getIncomingConversationProfile(const resip::SipMessage& msg); // returns the most appropriate conversation profile for the message
314
326
327 // Note: In general the following fns are not thread safe and must be called from dum process
328 // loop only
330 friend class RemoteParticipant;
334 friend class DefaultDialogSet;
338
339 void addTransports();
340 void post(resip::ApplicationMessage& message, std::chrono::duration<double> duration);
341 void shutdownImpl();
342 void addConversationProfileImpl(ConversationProfileHandle handle, std::shared_ptr<ConversationProfile> conversationProfile, bool defaultOutgoing=true);
347 void createPublicationImpl(PublicationHandle handle, const resip::Data& status, const resip::Data& eventType, const resip::NameAddr& target, unsigned int publicationTime, const resip::Mime& mimeType);
349
350 // Subscription storage
352 typedef std::map<SubscriptionHandle, UserAgentClientSubscription *> SubscriptionMap;
359
360 // Publication storage
362 typedef std::map<PublicationHandle, UserAgentClientPublication *> PublicationMap;
369
370 // Conversation Profile Storage
371 typedef std::map<ConversationProfileHandle, std::shared_ptr<ConversationProfile> > ConversationProfileMap;
377
379 typedef std::map<ConversationProfileHandle, UserAgentRegistration*> RegistrationMap;
383
385 std::shared_ptr<UserAgentMasterProfile> mProfile;
392 volatile bool mDumShutdown;
393 volatile bool mUserAgentShutdown;
394};
395
396}
397
398#endif
399
400
401/* ====================================================================
402
403 Copyright (c) 2021, Daniel Pocock https://danielpocock.com
404 Copyright (c) 2016-2022, SIP Spectrum, Inc. http://www.sipspectrum.com
405 Copyright (c) 2007-2008, Plantronics, Inc.
406
407 All rights reserved.
408
409 Redistribution and use in source and binary forms, with or without
410 modification, are permitted provided that the following conditions are
411 met:
412
413 1. Redistributions of source code must retain the above copyright
414 notice, this list of conditions and the following disclaimer.
415
416 2. Redistributions in binary form must reproduce the above copyright
417 notice, this list of conditions and the following disclaimer in the
418 documentation and/or other materials provided with the distribution.
419
420 3. Neither the name of Plantronics nor the names of its contributors
421 may be used to endorse or promote products derived from this
422 software without specific prior written permission.
423
424 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
425 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
426 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
427 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
428 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
429 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
430 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
431 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
432 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
433 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
434 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
435
436 ==================================================================== */
This class is one of two main classes of concern to an application using the UserAgent library.
This class is used by non-Invite DialogSets.
This class represents a media resource participant.
This class represent an Instant Message remote participant.
This class is used by Invite DialogSets used for IM Sessions only (m=message SDP).
This class represents an IM Session remote participant.
This class is used by Invite DialogSets.
This class represent a remote participant.
This class is one of two main classes of concern to an application using the UserAgent library.
This class is used by Invite DialogSets.
This class represent a remote participant.
This class is used to manage active client publications.
This class is used to manage active client subscriptions.
This class is used to manage active SIP registrations.
This class is used to provide server digest authentication capabilities.
The classes defined here are used to pass commands from the application thread to the UserAgent threa...
This class is one of two main classes of concern to an application using the UserAgent library.
Definition UserAgent.hxx:56
virtual void onSubscriptionNotify(SubscriptionHandle handle, const resip::Data &notifyData)
Callback used when a subscription has received an event notification from the server.
void unregisterSubscription(UserAgentClientSubscription *)
volatile bool mDumShutdown
std::shared_ptr< UserAgentMasterProfile > mProfile
std::map< ConversationProfileHandle, UserAgentRegistration * > RegistrationMap
std::map< SubscriptionHandle, UserAgentClientSubscription * > SubscriptionMap
virtual void onApplicationTimer(unsigned int timerId, std::chrono::duration< double > duration, unsigned int seqNumber)
Callback used when an application timer expires.
std::shared_ptr< ConversationProfile > getDefaultOutgoingConversationProfile()
virtual void process(int timeoutMs)
This should be called in a loop to give process cycles to the UserAgent.
const char * sendMessage(const resip::NameAddr &destination, const resip::Data &msg, const resip::Mime &mimeType)
Used to send a MESSAGE SIP message.
void shutdown()
Used to initiate a shutdown of the useragent.
virtual void onUpdateExtension(resip::ClientSubscriptionHandle, const resip::SipMessage &notify, bool outOfOrder)
resip::DialogUsageManager & getDialogUsageManager()
virtual std::shared_ptr< ConversationProfile > getIncomingConversationProfile(const resip::SipMessage &msg)
void setDefaultOutgoingConversationProfile(ConversationProfileHandle handle)
Sets an existing Conversation Profile to the default profile to use for outbound calls.
static void setLogLevel(resip::Log::Level level, LoggingSubsystem subsystem=SubsystemAll)
Static method that sets the logging level for a particular subsystem, or all subsystems.
resip::Mutex mSubscriptionHandleMutex
std::shared_ptr< UserAgentMasterProfile > getUserAgentMasterProfile() const noexcept
ConversationManager * mConversationManager
SubscriptionMap mSubscriptions
void destroyPublication(PublicationHandle handle)
resip::EventStackThread mStackThread
resip::SipStack mStack
void registerRegistration(UserAgentRegistration *)
void startup()
Starts the SIP stack thread.
resip::Mutex mPublicationHandleMutex
virtual void onSuccess(resip::ClientRegistrationHandle h, const resip::SipMessage &response)
Called when registration succeeds or each time it is successfully refreshed (manual refreshes only).
void destroyConversationProfile(ConversationProfileHandle handle)
Destroys an existing Conversation Profile.
void logDnsCache()
Used to initiate a snapshot of the existing DNS entries in the cache to the logging subsystem.
RegistrationMap mRegistrations
PublicationHandle mCurrentPublicationHandle
ConversationProfileHandle addConversationProfile(std::shared_ptr< ConversationProfile > conversationProfile, bool defaultOutgoing=true)
Adds a Conversation Profile to be managed, by the user agent.
std::map< PublicationHandle, UserAgentClientPublication * > PublicationMap
resip::EventThreadInterruptor * mEventInterruptor
void destroySubscription(SubscriptionHandle handle)
Destroys an existing subscriptions.
resip::Mutex mConversationProfileHandleMutex
PublicationHandle createPublication(const resip::Data &eventType, const resip::NameAddr &target, const resip::Data &status, unsigned int publicationTime, const resip::Mime &mimeType)
void unregisterPublication(UserAgentClientPublication *)
virtual void onUpdatePending(resip::ClientSubscriptionHandle h, const resip::SipMessage &notify, bool outOfOrder)
ConversationProfileHandle getNewConversationProfileHandle()
void registerSubscription(UserAgentClientSubscription *)
SubscriptionHandle createSubscription(const resip::Data &eventType, const resip::NameAddr &target, unsigned int subscriptionTime, const resip::Mime &mimeType)
Requests that the user agent create and manage an event subscription.
void unregisterRegistration(UserAgentRegistration *)
resip::SipStack & getSipStack()
resip::DialogUsageManager mDum
virtual void onNewSubscription(resip::ClientSubscriptionHandle h, const resip::SipMessage &notify)
ConversationProfileMap mConversationProfiles
virtual ~UserAgent()
void clearDnsCache()
Used to clear the existing DNS entries in the cache.
void addConversationProfileImpl(ConversationProfileHandle handle, std::shared_ptr< ConversationProfile > conversationProfile, bool defaultOutgoing=true)
std::shared_ptr< ConversationProfile > getConversationProfileByMediaAddress(const resip::Data &mediaAddress)
virtual void post(resip::Message *msg)
volatile bool mUserAgentShutdown
ConversationManager * getConversationManager()
Retrieves the ConversationManager passed in the constructor.
virtual void startApplicationTimer(unsigned int timerId, std::chrono::duration< double > duration, unsigned int seqNumber)
Used by an application to start a timer that is managed by the useragent.
PublicationMap mPublications
virtual void onRemove(resip::ClientPublicationHandle h, const resip::SipMessage &status)
PublicationHandle getNewPublicationHandle()
void destroySubscriptionImpl(SubscriptionHandle handle)
virtual void onTerminated(resip::ClientSubscriptionHandle h, const resip::SipMessage *notify)
SubscriptionHandle mCurrentSubscriptionHandle
ConversationProfileHandle mCurrentConversationProfileHandle
std::map< ConversationProfileHandle, std::shared_ptr< ConversationProfile > > ConversationProfileMap
SubscriptionHandle getNewSubscriptionHandle()
void setDefaultOutgoingConversationProfileImpl(ConversationProfileHandle handle)
void registerPublication(UserAgentClientPublication *)
void createPublicationImpl(PublicationHandle handle, const resip::Data &status, const resip::Data &eventType, const resip::NameAddr &target, unsigned int publicationTime, const resip::Mime &mimeType)
resip::Security * mSecurity
resip::FdPollGrp * mPollGrp
ConversationProfileHandle mDefaultOutgoingConversationProfileHandle
void onDumCanBeDeleted()
virtual int onRequestRetry(resip::ClientRegistrationHandle h, int retryMinimum, const resip::SipMessage &msg)
call on Retry-After failure.
virtual void onRemoved(resip::ClientRegistrationHandle h, const resip::SipMessage &response)
virtual void onUpdateActive(resip::ClientSubscriptionHandle h, const resip::SipMessage &notify, bool outOfOrder)
virtual void onSubscriptionTerminated(SubscriptionHandle handle, unsigned int statusCode)
Callback used when a subscription is terminated.
void destroyPublicationImpl(PublicationHandle handle)
void createSubscriptionImpl(SubscriptionHandle handle, const resip::Data &eventType, const resip::NameAddr &target, unsigned int subscriptionTime, const resip::Mime &mimeType)
virtual void onFailure(resip::ClientRegistrationHandle h, const resip::SipMessage &response)
Called if registration fails, usage will be destroyed (unless a Registration retry interval is enable...
void destroyConversationProfileImpl(ConversationProfileHandle handle)
A base-class for messages used by applications.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
This class creates a thread in which to run one or more SipStacks.
The base-class used for message-passing.
Definition Message.hxx:21
Represents the "media-type" element in the RFC 3261 grammar.
Definition Mime.hxx:20
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
Represents a SIP message.
This is the primary point of interaction between the app-layer and the stack.
Definition SipStack.hxx:160
unsigned int ConversationProfileHandle
unsigned int SubscriptionHandle
unsigned int PublicationHandle
dcm! – add UnusedChecking(_enum) below;
void(* AfterSocketCreationFuncPtr)(Socket s, int transportType, const char *file, int line)
Definition Socket.hxx:107
std::mutex Mutex
A semaphore that can be locked by only one thread at a time.
Definition Mutex.hxx:37
void list()
Definition userAdmin.cxx:66