Kea  2.1.7-git
ncr_io.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 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 
49 
50 #include <asiolink/io_address.h>
51 #include <asiolink/io_service.h>
52 #include <dhcp_ddns/ncr_msg.h>
53 #include <exceptions/exceptions.h>
54 
55 #include <boost/scoped_ptr.hpp>
56 
57 #include <deque>
58 #include <mutex>
59 
60 namespace isc {
61 namespace dhcp_ddns {
62 
71 };
72 
82 extern NameChangeProtocol stringToNcrProtocol(const std::string& protocol_str);
83 
90 extern std::string ncrProtocolToString(NameChangeProtocol protocol);
91 
94 public:
95  NcrListenerError(const char* file, size_t line, const char* what) :
96  isc::Exception(file, line, what) { };
97 };
98 
101 public:
102  NcrListenerOpenError(const char* file, size_t line, const char* what) :
103  isc::Exception(file, line, what) { };
104 };
105 
108 public:
109  NcrListenerReceiveError(const char* file, size_t line, const char* what) :
110  isc::Exception(file, line, what) { };
111 };
112 
113 
168 public:
169 
171  enum Result {
176  };
177 
184  public:
185 
198  virtual void operator ()(const Result result,
199  NameChangeRequestPtr& ncr) = 0;
200 
202  }
203  };
204 
210 
213  };
214 
225  void startListening(isc::asiolink::IOService& io_service);
226 
231  void stopListening();
232 
233 protected:
243  void receiveNext();
244 
270  void invokeRecvHandler(const Result result, NameChangeRequestPtr& ncr);
271 
281  virtual void open(isc::asiolink::IOService& io_service) = 0;
282 
290  virtual void close() = 0;
291 
300  virtual void doReceive() = 0;
301 
302 public:
303 
312  bool amListening() const {
313  return (listening_);
314  }
315 
327  bool isIoPending() const {
328  return (io_pending_);
329  }
330 
331 private:
338  void setListening(bool value) {
339  listening_ = value;
340  }
341 
343  bool listening_;
344 
346  bool io_pending_;
347 
349  RequestReceiveHandler& recv_handler_;
350 };
351 
353 typedef boost::shared_ptr<NameChangeListener> NameChangeListenerPtr;
354 
355 
358 public:
359  NcrSenderError(const char* file, size_t line, const char* what) :
360  isc::Exception(file, line, what) { };
361 };
362 
365 public:
366  NcrSenderOpenError(const char* file, size_t line, const char* what) :
367  isc::Exception(file, line, what) { };
368 };
369 
372 public:
373  NcrSenderQueueFull(const char* file, size_t line, const char* what) :
374  isc::Exception(file, line, what) { };
375 };
376 
379 public:
380  NcrSenderSendError(const char* file, size_t line, const char* what) :
381  isc::Exception(file, line, what) { };
382 };
383 
384 
412 
461 
467 public:
468 
470  typedef std::deque<NameChangeRequestPtr> SendQueue;
471 
473  static const size_t MAX_QUEUE_DEFAULT = 1024;
474 
476  enum Result {
481  };
482 
489  public:
490 
502  virtual void operator ()(const Result result,
503  NameChangeRequestPtr& ncr) = 0;
504 
506  }
507  };
508 
516  NameChangeSender(RequestSendHandler& send_handler,
517  size_t send_queue_max = MAX_QUEUE_DEFAULT);
518 
520  virtual ~NameChangeSender() {
521  }
522 
532  void startSending(isc::asiolink::IOService & io_service);
533 
538  void stopSending();
539 
550  void sendRequest(NameChangeRequestPtr& ncr);
551 
564  void assumeQueue(NameChangeSender& source_sender);
565 
579  virtual int getSelectFd() = 0;
580 
584  virtual bool ioReady() = 0;
585 
586 private:
587 
591  void startSendingInternal(isc::asiolink::IOService & io_service);
592 
598  void sendRequestInternal(NameChangeRequestPtr& ncr);
599 
606  void assumeQueueInternal(NameChangeSender& source_sender);
607 
612  void invokeSendHandlerInternal(const NameChangeSender::Result result);
613 
616  void skipNextInternal();
617 
622  size_t getQueueSizeInternal() const;
623 
631  const NameChangeRequestPtr& peekAtInternal(const size_t index) const;
632 
633 protected:
634 
641  void sendNext();
642 
669  void invokeSendHandler(const NameChangeSender::Result result);
670 
680  virtual void open(isc::asiolink::IOService& io_service) = 0;
681 
689  virtual void close() = 0;
690 
701  virtual void doSend(NameChangeRequestPtr& ncr) = 0;
702 
703 public:
704 
716  void skipNext();
717 
725  void clearSendQueue();
726 
733  bool amSending() const {
734  return (sending_);
735  }
736 
743  bool isSendInProgress() const;
744 
748  size_t getQueueMaxSize() const {
749  return (send_queue_max_);
750  }
751 
760  void setQueueMaxSize(const size_t new_max);
761 
765  size_t getQueueSize() const;
766 
778  const NameChangeRequestPtr& peekAt(const size_t index) const;
779 
799  virtual void runReadyIO();
800 
801 protected:
802 
806  SendQueue& getSendQueue() {
807  return (send_queue_);
808  }
809 
810 private:
811 
818  void setSending(bool value) {
819  sending_ = value;
820  }
821 
823  bool sending_;
824 
826  RequestSendHandler& send_handler_;
827 
829  size_t send_queue_max_;
830 
832  SendQueue send_queue_;
833 
835  NameChangeRequestPtr ncr_to_send_;
836 
841  asiolink::IOService* io_service_;
842 
844  const boost::scoped_ptr<std::mutex> mutex_;
845 };
846 
848 typedef boost::shared_ptr<NameChangeSender> NameChangeSenderPtr;
849 
850 } // namespace dhcp_ddns
851 } // namespace isc
852 
853 #endif
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
Definition: ncr_io.h:733
Exception thrown if an error occurs initiating an IO receive.
Definition: ncr_io.h:107
NcrSenderSendError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:380
bool amListening() const
Returns true if the listener is listening, false otherwise.
Definition: ncr_io.h:312
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:378
NcrSenderOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:366
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts text labels to NameChangeProtocol enums.
Definition: ncr_io.cc:23
NcrListenerOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:102
NcrListenerError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:95
Result
Defines the outcome of an asynchronous NCR send.
Definition: ncr_io.h:476
boost::shared_ptr< NameChangeListener > NameChangeListenerPtr
Defines a smart pointer to an instance of a listener.
Definition: ncr_io.h:353
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:357
Exception thrown if an NcrListenerError encounters a general error.
Definition: ncr_io.h:93
SendQueue & getSendQueue()
Returns a reference to the send queue.
Definition: ncr_io.h:806
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
Definition: ncr_io.cc:36
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:364
NcrListenerReceiveError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:109
boost::shared_ptr< NameChangeSender > NameChangeSenderPtr
Defines a smart pointer to an instance of a sender.
Definition: ncr_io.h:848
Abstract class for defining application layer send callbacks.
Definition: ncr_io.h:488
size_t getQueueMaxSize() const
Returns the maximum number of entries allowed in the send queue.
Definition: ncr_io.h:748
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
NcrSenderQueueFull(const char *file, size_t line, const char *what)
Definition: ncr_io.h:373
NcrSenderError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:359
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:371
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:68
virtual ~NameChangeListener()
Destructor.
Definition: ncr_io.h:212
std::deque< NameChangeRequestPtr > SendQueue
Defines the type used for the request send queue.
Definition: ncr_io.h:470
bool isIoPending() const
Returns true if the listener has an IO call in progress.
Definition: ncr_io.h:327
Abstract interface for sending NameChangeRequests.
Definition: ncr_io.h:466
virtual ~NameChangeSender()
Destructor.
Definition: ncr_io.h:520
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
Abstract interface for receiving NameChangeRequests.
Definition: ncr_io.h:167
Abstract class for defining application layer receive callbacks.
Definition: ncr_io.h:183
Result
Defines the outcome of an asynchronous NCR receive.
Definition: ncr_io.h:171
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:100