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>
55
56#include <deque>
57
58namespace isc {
59namespace dhcp_ddns {
60
69};
70
80extern NameChangeProtocol stringToNcrProtocol(const std::string& protocol_str);
81
88extern std::string ncrProtocolToString(NameChangeProtocol protocol);
89
92public:
93 NcrListenerError(const char* file, size_t line, const char* what) :
94 isc::Exception(file, line, what) { };
95};
96
99public:
100 NcrListenerOpenError(const char* file, size_t line, const char* what) :
101 isc::Exception(file, line, what) { };
102};
103
106public:
107 NcrListenerReceiveError(const char* file, size_t line, const char* what) :
108 isc::Exception(file, line, what) { };
109};
110
111
166public:
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
222
227 void stopListening();
228
229protected:
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
298public:
305 bool amListening() const {
306 return (listening_);
307 }
308
318 bool isIoPending() const {
319 return (io_pending_);
320 }
321
322private:
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
344typedef boost::shared_ptr<NameChangeListener> NameChangeListenerPtr;
345
346
349public:
350 NcrSenderError(const char* file, size_t line, const char* what) :
351 isc::Exception(file, line, what) { };
352};
353
356public:
357 NcrSenderOpenError(const char* file, size_t line, const char* what) :
358 isc::Exception(file, line, what) { };
359};
360
363public:
364 NcrSenderQueueFull(const char* file, size_t line, const char* what) :
365 isc::Exception(file, line, what) { };
366};
367
370public:
371 NcrSenderSendError(const char* file, size_t line, const char* what) :
372 isc::Exception(file, line, what) { };
373};
374
375
403
452
458public:
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
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
576protected:
583 void sendNext();
584
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
645public:
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
737protected:
740 return (send_queue_);
741 }
742
743private:
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
777typedef boost::shared_ptr<NameChangeSender> NameChangeSenderPtr;
778
779} // namespace isc::dhcp_ddns
780} // namespace isc
781
782#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Abstract class for defining application layer receive callbacks.
Definition: ncr_io.h:181
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR receive callback.
Abstract interface for receiving NameChangeRequests.
Definition: ncr_io.h:165
void stopListening()
Closes the IO source and stops listen logic.
Definition: ncr_io.cc:88
virtual void close()=0
Abstract method which closes the IO source.
bool isIoPending() const
Returns true if the listener has an IO call in progress.
Definition: ncr_io.h:318
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO source for reception.
void startListening(isc::asiolink::IOService &io_service)
Prepares the IO for reception and initiates the first receive.
Definition: ncr_io.cc:55
virtual void doReceive()=0
Initiates an IO layer asynchronous read.
void invokeRecvHandler(const Result result, NameChangeRequestPtr &ncr)
Calls the NCR receive handler registered with the listener.
Definition: ncr_io.cc:105
virtual ~NameChangeListener()
Destructor.
Definition: ncr_io.h:208
bool amListening() const
Returns true if the listener is listening, false otherwise.
Definition: ncr_io.h:305
Result
Defines the outcome of an asynchronous NCR receive.
Definition: ncr_io.h:169
void receiveNext()
Initiates an asynchronous receive.
Definition: ncr_io.cc:82
Abstract class for defining application layer send callbacks.
Definition: ncr_io.h:479
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR send callback.
Abstract interface for sending NameChangeRequests.
Definition: ncr_io.h:457
void stopSending()
Closes the IO sink and stops send logic.
Definition: ncr_io.cc:191
virtual int getSelectFd()=0
Returns a file descriptor suitable for use with select.
Definition: ncr_io.cc:384
void assumeQueue(NameChangeSender &source_sender)
Move all queued requests from a given sender into the send queue.
Definition: ncr_io.cc:359
size_t getQueueMaxSize() const
Returns the maximum number of entries allowed in the send queue.
Definition: ncr_io.h:684
size_t getQueueSize() const
Returns the number of entries currently in the send queue.
Definition: ncr_io.h:699
const NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
Definition: ncr_io.cc:347
virtual bool ioReady()=0
Returns whether or not the sender has IO ready to process.
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO sink for transmission.
void skipNext()
Removes the request at the front of the send queue.
Definition: ncr_io.cc:320
std::deque< NameChangeRequestPtr > SendQueue
Defines the type used for the request send queue.
Definition: ncr_io.h:461
void clearSendQueue()
Flushes all entries in the send queue.
Definition: ncr_io.cc:328
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
Definition: ncr_io.h:671
virtual void doSend(NameChangeRequestPtr &ncr)=0
Initiates an IO layer asynchronous send.
void setQueueMaxSize(const size_t new_max)
Sets the maximum queue size to the given value.
Definition: ncr_io.cc:337
static const size_t MAX_QUEUE_DEFAULT
Defines a default maximum number of entries in the send queue.
Definition: ncr_io.h:464
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
virtual void close()=0
Abstract method which closes the IO sink.
void sendRequest(NameChangeRequestPtr &ncr)
Queues the given request to be sent.
Definition: ncr_io.cc:223
virtual void runReadyIO()
Processes sender IO events.
Definition: ncr_io.cc:389
SendQueue & getSendQueue()
Returns a reference to the send queue.
Definition: ncr_io.h:739
bool isSendInProgress() const
Returns true when a send is in progress.
Definition: ncr_io.h:679
Result
Defines the outcome of an asynchronous NCR send.
Definition: ncr_io.h:467
void sendNext()
Dequeues and sends the next request on the send queue.
Definition: ncr_io.cc:246
void startSending(isc::asiolink::IOService &io_service)
Prepares the IO for transmission.
Definition: ncr_io.cc:164
Exception thrown if an NcrListenerError encounters a general error.
Definition: ncr_io.h:91
NcrListenerError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:93
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:98
NcrListenerOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:100
Exception thrown if an error occurs initiating an IO receive.
Definition: ncr_io.h:105
NcrListenerReceiveError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:107
Thrown when a NameChangeSender encounters an error.
Definition: ncr_io.h:348
NcrSenderError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:350
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:355
NcrSenderOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:357
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:362
NcrSenderQueueFull(const char *file, size_t line, const char *what)
Definition: ncr_io.h:364
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:369
NcrSenderSendError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:371
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts labels to NameChangeProtocol enum values.
Definition: ncr_io.cc:17
boost::shared_ptr< NameChangeListener > NameChangeListenerPtr
Defines a smart pointer to an instance of a listener.
Definition: ncr_io.h:344
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:66
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
Definition: ncr_io.cc:30
boost::shared_ptr< NameChangeSender > NameChangeSenderPtr
Defines a smart pointer to an instance of a sender.
Definition: ncr_io.h:777
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:214
Defines the logger used by the top-level component of kea-dhcp-ddns.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...