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 
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 {
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 {
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
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
Definition: ncr_io.h:671
Exception thrown if an error occurs initiating an IO receive.
Definition: ncr_io.h:105
NcrSenderSendError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:371
bool amListening() const
Returns true if the listener is listening, false otherwise.
Definition: ncr_io.h:305
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:369
NcrSenderOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:357
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts labels to NameChangeProtocol enum values.
Definition: ncr_io.cc:17
virtual void close()=0
Abstract method which closes the IO source.
virtual bool ioReady()=0
Returns whether or not the sender has IO ready to process.
virtual int getSelectFd()=0
Returns a file descriptor suitable for use with select.
Definition: ncr_io.cc:384
NcrListenerOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:100
NcrListenerError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:93
void assumeQueue(NameChangeSender &source_sender)
Move all queued requests from a given sender into the send queue.
Definition: ncr_io.cc:359
Result
Defines the outcome of an asynchronous NCR send.
Definition: ncr_io.h:467
boost::shared_ptr< NameChangeListener > NameChangeListenerPtr
Defines a smart pointer to an instance of a listener.
Definition: ncr_io.h:344
void skipNext()
Removes the request at the front of the send queue.
Definition: ncr_io.cc:320
size_t getQueueSize() const
Returns the number of entries currently in the send queue.
Definition: ncr_io.h:699
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Thrown when a NameChangeSender encounters an error.
Definition: ncr_io.h:348
Exception thrown if an NcrListenerError encounters a general error.
Definition: ncr_io.h:91
SendQueue & getSendQueue()
Returns a reference to the send queue.
Definition: ncr_io.h:739
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
Definition: ncr_io.cc:30
void clearSendQueue()
Flushes all entries in the send queue.
Definition: ncr_io.cc:328
NameChangeListener(RequestReceiveHandler &recv_handler)
Constructor.
Definition: ncr_io.cc:48
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:355
const NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
Definition: ncr_io.cc:347
NcrListenerReceiveError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:107
NameChangeSender(RequestSendHandler &send_handler, size_t send_queue_max=MAX_QUEUE_DEFAULT)
Constructor.
Definition: ncr_io.cc:154
boost::shared_ptr< NameChangeSender > NameChangeSenderPtr
Defines a smart pointer to an instance of a sender.
Definition: ncr_io.h:777
Abstract class for defining application layer send callbacks.
Definition: ncr_io.h:479
void startListening(isc::asiolink::IOService &io_service)
Prepares the IO for reception and initiates the first receive.
Definition: ncr_io.cc:55
size_t getQueueMaxSize() const
Returns the maximum number of entries allowed in the send queue.
Definition: ncr_io.h:684
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO sink for transmission.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void receiveNext()
Initiates an asynchronous receive.
Definition: ncr_io.cc:82
NcrSenderQueueFull(const char *file, size_t line, const char *what)
Definition: ncr_io.h:364
virtual void doSend(NameChangeRequestPtr &ncr)=0
Initiates an IO layer asynchronous send.
virtual void runReadyIO()
Processes sender IO events.
Definition: ncr_io.cc:389
void stopSending()
Closes the IO sink and stops send logic.
Definition: ncr_io.cc:191
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO source for reception.
void startSending(isc::asiolink::IOService &io_service)
Prepares the IO for transmission.
Definition: ncr_io.cc:164
NcrSenderError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:350
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR send callback.
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:362
bool isSendInProgress() const
Returns true when a send is in progress.
Definition: ncr_io.h:679
void sendNext()
Dequeues and sends the next request on the send queue.
Definition: ncr_io.cc:246
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:66
void setQueueMaxSize(const size_t new_max)
Sets the maximum queue size to the given value.
Definition: ncr_io.cc:337
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR receive callback.
virtual ~NameChangeListener()
Destructor.
Definition: ncr_io.h:208
std::deque< NameChangeRequestPtr > SendQueue
Defines the type used for the request send queue.
Definition: ncr_io.h:461
bool isIoPending() const
Returns true if the listener has an IO call in progress.
Definition: ncr_io.h:318
Abstract interface for sending NameChangeRequests.
Definition: ncr_io.h:457
void invokeRecvHandler(const Result result, NameChangeRequestPtr &ncr)
Calls the NCR receive handler registered with the listener.
Definition: ncr_io.cc:105
void sendRequest(NameChangeRequestPtr &ncr)
Queues the given request to be sent.
Definition: ncr_io.cc:223
void stopListening()
Closes the IO source and stops listen logic.
Definition: ncr_io.cc:88
virtual ~NameChangeSender()
Destructor.
Definition: ncr_io.h:510
void invokeSendHandler(const NameChangeSender::Result result)
Calls the NCR send completion handler registered with the sender.
Definition: ncr_io.cc:269
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
virtual void close()=0
Abstract method which closes the IO sink.
Abstract interface for receiving NameChangeRequests.
Definition: ncr_io.h:165
Abstract class for defining application layer receive callbacks.
Definition: ncr_io.h:181
virtual void doReceive()=0
Initiates an IO layer asynchronous read.
static const size_t MAX_QUEUE_DEFAULT
Defines a default maximum number of entries in the send queue.
Definition: ncr_io.h:464
Result
Defines the outcome of an asynchronous NCR receive.
Definition: ncr_io.h:169
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:98