Kea  1.5.0
ncr_io.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef NCR_IO_H
8 #define NCR_IO_H
9 
50 
51 #include <asiolink/io_address.h>
52 #include <asiolink/io_service.h>
53 #include <dhcp_ddns/ncr_msg.h>
54 #include <exceptions/exceptions.h>
55 
56 #include <deque>
57 
58 namespace isc {
59 namespace dhcp_ddns {
60 
68  NCR_TCP
69 };
70 
80 extern NameChangeProtocol stringToNcrProtocol(const std::string& protocol_str);
81 
88 extern std::string ncrProtocolToString(NameChangeProtocol protocol);
89 
92 public:
93  NcrListenerError(const char* file, size_t line, const char* what) :
94  isc::Exception(file, line, what) { };
95 };
96 
99 public:
100  NcrListenerOpenError(const char* file, size_t line, const char* what) :
101  isc::Exception(file, line, what) { };
102 };
103 
106 public:
107  NcrListenerReceiveError(const char* file, size_t line, const char* what) :
108  isc::Exception(file, line, what) { };
109 };
110 
111 
166 public:
167 
169  enum Result {
173  ERROR
174  };
175 
182  public:
194  virtual void operator ()(const Result result,
195  NameChangeRequestPtr& ncr) = 0;
196 
198  }
199  };
200 
205  NameChangeListener(RequestReceiveHandler& recv_handler);
206 
209  };
210 
221  void startListening(isc::asiolink::IOService& io_service);
222 
227  void stopListening();
228 
229 protected:
239  void receiveNext();
240 
266  void invokeRecvHandler(const Result result, NameChangeRequestPtr& ncr);
267 
277  virtual void open(isc::asiolink::IOService& io_service) = 0;
278 
286  virtual void close() = 0;
287 
296  virtual void doReceive() = 0;
297 
298 public:
305  bool amListening() const {
306  return (listening_);
307  }
308 
318  bool isIoPending() const {
319  return (io_pending_);
320  }
321 
322 private:
329  void setListening(bool value) {
330  listening_ = value;
331  }
332 
334  bool listening_;
335 
337  bool io_pending_;
338 
340  RequestReceiveHandler& recv_handler_;
341 };
342 
344 typedef boost::shared_ptr<NameChangeListener> NameChangeListenerPtr;
345 
346 
349 public:
350  NcrSenderError(const char* file, size_t line, const char* what) :
351  isc::Exception(file, line, what) { };
352 };
353 
356 public:
357  NcrSenderOpenError(const char* file, size_t line, const char* what) :
358  isc::Exception(file, line, what) { };
359 };
360 
363 public:
364  NcrSenderQueueFull(const char* file, size_t line, const char* what) :
365  isc::Exception(file, line, what) { };
366 };
367 
370 public:
371  NcrSenderSendError(const char* file, size_t line, const char* what) :
372  isc::Exception(file, line, what) { };
373 };
374 
375 
403 
452 
458 public:
459 
461  typedef std::deque<NameChangeRequestPtr> SendQueue;
462 
464  static const size_t MAX_QUEUE_DEFAULT = 1024;
465 
467  enum Result {
471  ERROR
472  };
473 
480  public:
492  virtual void operator ()(const Result result,
493  NameChangeRequestPtr& ncr) = 0;
494 
496  }
497  };
498 
506  NameChangeSender(RequestSendHandler& send_handler,
507  size_t send_queue_max = MAX_QUEUE_DEFAULT);
508 
510  virtual ~NameChangeSender() {
511  }
512 
522  void startSending(isc::asiolink::IOService & io_service);
523 
528  void stopSending();
529 
541 
554  void assumeQueue(NameChangeSender& source_sender);
555 
569  virtual int getSelectFd() = 0;
570 
574  virtual bool ioReady() = 0;
575 
576 protected:
583  void sendNext();
584 
611  void invokeSendHandler(const NameChangeSender::Result result);
612 
622  virtual void open(isc::asiolink::IOService& io_service) = 0;
623 
631  virtual void close() = 0;
632 
643  virtual void doSend(NameChangeRequestPtr& ncr) = 0;
644 
645 public:
657  void skipNext();
658 
665  void clearSendQueue();
666 
671  bool amSending() const {
672  return (sending_);
673  }
674 
679  bool isSendInProgress() const {
680  return ((ncr_to_send_) ? true : false);
681  }
682 
684  size_t getQueueMaxSize() const {
685  return (send_queue_max_);
686  }
687 
696  void setQueueMaxSize(const size_t new_max);
697 
699  size_t getQueueSize() const {
700  return (send_queue_.size());
701  }
702 
713  const NameChangeRequestPtr& peekAt(const size_t index) const;
714 
735  virtual void runReadyIO();
736 
737 protected:
740  return (send_queue_);
741  }
742 
743 private:
750  void setSending(bool value) {
751  sending_ = value;
752  }
753 
755  bool sending_;
756 
758  RequestSendHandler& send_handler_;
759 
761  size_t send_queue_max_;
762 
764  SendQueue send_queue_;
765 
767  NameChangeRequestPtr ncr_to_send_;
768 
773  asiolink::IOService* io_service_;
774 };
775 
777 typedef boost::shared_ptr<NameChangeSender> NameChangeSenderPtr;
778 
779 } // namespace isc::dhcp_ddns
780 } // namespace isc
781 
782 #endif
ncr_msg.h
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
isc::dhcp_ddns::NameChangeListener::close
virtual void close()=0
Abstract method which closes the IO source.
isc::dhcp_ddns::NameChangeSender::setQueueMaxSize
void setQueueMaxSize(const size_t new_max)
Sets the maximum queue size to the given value.
Definition: ncr_io.cc:337
isc::dhcp_ddns::NameChangeSender::getQueueMaxSize
size_t getQueueMaxSize() const
Returns the maximum number of entries allowed in the send queue.
Definition: ncr_io.h:684
isc::dhcp_ddns::NameChangeSender::assumeQueue
void assumeQueue(NameChangeSender &source_sender)
Move all queued requests from a given sender into the send queue.
Definition: ncr_io.cc:359
isc::dhcp_ddns::NameChangeSender
Abstract interface for sending NameChangeRequests.
Definition: ncr_io.h:457
isc::dhcp_ddns::NameChangeSender::RequestSendHandler::operator()
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR send callback.
isc::dhcp_ddns::NameChangeListener::NameChangeListener
NameChangeListener(RequestReceiveHandler &recv_handler)
Constructor.
Definition: ncr_io.cc:48
isc::dhcp_ddns::NcrSenderSendError
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:369
isc::dhcp_ddns::NameChangeListener::TIME_OUT
@ TIME_OUT
Definition: ncr_io.h:171
isc::dhcp_ddns::NameChangeSender::~NameChangeSender
virtual ~NameChangeSender()
Destructor.
Definition: ncr_io.h:510
isc::dhcp_ddns::NameChangeSender::NameChangeSender
NameChangeSender(RequestSendHandler &send_handler, size_t send_queue_max=MAX_QUEUE_DEFAULT)
Constructor.
Definition: ncr_io.cc:154
isc::dhcp_ddns::NameChangeSender::skipNext
void skipNext()
Removes the request at the front of the send queue.
Definition: ncr_io.cc:320
isc::dhcp_ddns::NameChangeSender::MAX_QUEUE_DEFAULT
static const size_t MAX_QUEUE_DEFAULT
Defines a default maximum number of entries in the send queue.
Definition: ncr_io.h:464
isc::dhcp_ddns::NameChangeSender::RequestSendHandler::~RequestSendHandler
virtual ~RequestSendHandler()
Definition: ncr_io.h:495
isc::dhcp_ddns::NameChangeListener::doReceive
virtual void doReceive()=0
Initiates an IO layer asynchronous read.
isc::dhcp_ddns::NameChangeListener::ERROR
@ ERROR
Definition: ncr_io.h:173
isc::dhcp_ddns::NameChangeSender::Result
Result
Defines the outcome of an asynchronous NCR send.
Definition: ncr_io.h:467
io_address.h
isc::dhcp_ddns::NcrSenderOpenError::NcrSenderOpenError
NcrSenderOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:357
isc::dhcp_ddns::NameChangeSender::STOPPED
@ STOPPED
Definition: ncr_io.h:470
isc::dhcp_ddns::NameChangeSender::stopSending
void stopSending()
Closes the IO sink and stops send logic.
Definition: ncr_io.cc:191
isc::dhcp_ddns::NameChangeListener::STOPPED
@ STOPPED
Definition: ncr_io.h:172
isc::dhcp_ddns::NameChangeListener
Abstract interface for receiving NameChangeRequests.
Definition: ncr_io.h:165
isc::dhcp_ddns::NameChangeListener::SUCCESS
@ SUCCESS
Definition: ncr_io.h:170
isc::dhcp_ddns::NameChangeRequestPtr
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
isc::dhcp_ddns::NameChangeSender::clearSendQueue
void clearSendQueue()
Flushes all entries in the send queue.
Definition: ncr_io.cc:328
isc::dhcp_ddns::NameChangeSender::open
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO sink for transmission.
isc::dhcp_ddns::NameChangeSender::RequestSendHandler
Abstract class for defining application layer send callbacks.
Definition: ncr_io.h:479
isc::dhcp_ddns::NcrListenerOpenError
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:98
isc::dhcp_ddns::NameChangeListener::stopListening
void stopListening()
Closes the IO source and stops listen logic.
Definition: ncr_io.cc:88
isc::dhcp_ddns::NameChangeSender::ioReady
virtual bool ioReady()=0
Returns whether or not the sender has IO ready to process.
isc::dhcp_ddns::NameChangeListener::RequestReceiveHandler
Abstract class for defining application layer receive callbacks.
Definition: ncr_io.h:181
io_service.h
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp_ddns::NameChangeSender::isSendInProgress
bool isSendInProgress() const
Returns true when a send is in progress.
Definition: ncr_io.h:679
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::dhcp_ddns::NameChangeSender::sendRequest
void sendRequest(NameChangeRequestPtr &ncr)
Queues the given request to be sent.
Definition: ncr_io.cc:223
isc::dhcp_ddns::NameChangeListener::amListening
bool amListening() const
Returns true if the listener is listening, false otherwise.
Definition: ncr_io.h:305
isc::dhcp_ddns::NameChangeSender::close
virtual void close()=0
Abstract method which closes the IO sink.
isc::dhcp_ddns::NCR_TCP
@ NCR_TCP
Definition: ncr_io.h:68
isc::dhcp_ddns::NcrSenderOpenError
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:355
isc::dhcp_ddns::NameChangeListenerPtr
boost::shared_ptr< NameChangeListener > NameChangeListenerPtr
Defines a smart pointer to an instance of a listener.
Definition: ncr_io.h:344
isc::dhcp_ddns::NcrSenderError::NcrSenderError
NcrSenderError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:350
isc::dhcp_ddns::NameChangeListener::startListening
void startListening(isc::asiolink::IOService &io_service)
Prepares the IO for reception and initiates the first receive.
Definition: ncr_io.cc:55
isc::dhcp_ddns::NameChangeSender::peekAt
const NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
Definition: ncr_io.cc:347
isc::dhcp_ddns::NameChangeSender::invokeSendHandler
void invokeSendHandler(const NameChangeSender::Result result)
Calls the NCR send completion handler registered with the sender.
Definition: ncr_io.cc:269
isc::dhcp_ddns::NameChangeListener::open
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO source for reception.
isc::dhcp_ddns::NcrListenerError::NcrListenerError
NcrListenerError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:93
isc::dhcp_ddns::NameChangeSender::doSend
virtual void doSend(NameChangeRequestPtr &ncr)=0
Initiates an IO layer asynchronous send.
isc::dhcp_ddns::NameChangeSender::sendNext
void sendNext()
Dequeues and sends the next request on the send queue.
Definition: ncr_io.cc:246
isc::dhcp_ddns::NameChangeSenderPtr
boost::shared_ptr< NameChangeSender > NameChangeSenderPtr
Defines a smart pointer to an instance of a sender.
Definition: ncr_io.h:777
isc::dhcp_ddns::NcrListenerError
Exception thrown if an NcrListenerError encounters a general error.
Definition: ncr_io.h:91
isc::dhcp_ddns::NCR_UDP
@ NCR_UDP
Definition: ncr_io.h:67
isc::dhcp_ddns::NameChangeSender::ERROR
@ ERROR
Definition: ncr_io.h:471
isc::dhcp_ddns::NameChangeSender::startSending
void startSending(isc::asiolink::IOService &io_service)
Prepares the IO for transmission.
Definition: ncr_io.cc:164
isc::dhcp_ddns::NcrSenderError
Thrown when a NameChangeSender encounters an error.
Definition: ncr_io.h:348
isc::dhcp_ddns::ncrProtocolToString
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
Definition: ncr_io.cc:30
isc::dhcp_ddns::NameChangeSender::TIME_OUT
@ TIME_OUT
Definition: ncr_io.h:469
isc::dhcp_ddns::NameChangeSender::SUCCESS
@ SUCCESS
Definition: ncr_io.h:468
exceptions.h
isc::dhcp_ddns::NcrListenerReceiveError::NcrListenerReceiveError
NcrListenerReceiveError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:107
isc::dhcp_ddns::NcrSenderQueueFull::NcrSenderQueueFull
NcrSenderQueueFull(const char *file, size_t line, const char *what)
Definition: ncr_io.h:364
isc::dhcp_ddns::NcrListenerReceiveError
Exception thrown if an error occurs initiating an IO receive.
Definition: ncr_io.h:105
isc::dhcp_ddns::NameChangeListener::RequestReceiveHandler::~RequestReceiveHandler
virtual ~RequestReceiveHandler()
Definition: ncr_io.h:197
isc::dhcp_ddns::NameChangeListener::isIoPending
bool isIoPending() const
Returns true if the listener has an IO call in progress.
Definition: ncr_io.h:318
isc::dhcp_ddns::NameChangeSender::SendQueue
std::deque< NameChangeRequestPtr > SendQueue
Defines the type used for the request send queue.
Definition: ncr_io.h:461
isc::dhcp_ddns::NameChangeSender::amSending
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
Definition: ncr_io.h:671
isc::dhcp_ddns::NameChangeListener::Result
Result
Defines the outcome of an asynchronous NCR receive.
Definition: ncr_io.h:169
isc::dhcp_ddns::NcrSenderQueueFull
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:362
isc::dhcp_ddns::NameChangeListener::invokeRecvHandler
void invokeRecvHandler(const Result result, NameChangeRequestPtr &ncr)
Calls the NCR receive handler registered with the listener.
Definition: ncr_io.cc:105
isc::dhcp_ddns::NameChangeSender::runReadyIO
virtual void runReadyIO()
Processes sender IO events.
Definition: ncr_io.cc:389
isc::dhcp_ddns::NameChangeSender::getSelectFd
virtual int getSelectFd()=0
Returns a file descriptor suitable for use with select.
Definition: ncr_io.cc:384
isc::dhcp_ddns::NameChangeSender::getQueueSize
size_t getQueueSize() const
Returns the number of entries currently in the send queue.
Definition: ncr_io.h:699
isc::dhcp_ddns::NcrListenerOpenError::NcrListenerOpenError
NcrListenerOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:100
isc::dhcp_ddns::NameChangeListener::~NameChangeListener
virtual ~NameChangeListener()
Destructor.
Definition: ncr_io.h:208
isc::dhcp_ddns::stringToNcrProtocol
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts labels to NameChangeProtocol enum values.
Definition: ncr_io.cc:17
isc::dhcp_ddns::NcrSenderSendError::NcrSenderSendError
NcrSenderSendError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:371
isc::dhcp_ddns::NameChangeSender::getSendQueue
SendQueue & getSendQueue()
Returns a reference to the send queue.
Definition: ncr_io.h:739
isc::dhcp_ddns::NameChangeListener::RequestReceiveHandler::operator()
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR receive callback.
isc::dhcp_ddns::NameChangeListener::receiveNext
void receiveNext()
Initiates an asynchronous receive.
Definition: ncr_io.cc:82
isc::dhcp_ddns::NameChangeProtocol
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:66