nidas  v1.2-1520
McSocketUDP.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2009, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_CORE_MCSOCKETUDP_H
28 #define NIDAS_CORE_MCSOCKETUDP_H
29 
30 #include "IOChannel.h"
31 #include "DOMable.h"
32 #include <nidas/util/McSocket.h>
33 
34 #include <string>
35 #include <iostream>
36 
37 namespace nidas { namespace core {
38 
46 class McSocketUDP: public IOChannel {
47 
48 public:
49 
53  McSocketUDP();
54 
59  McSocketUDP(const McSocketUDP&);
60 
62 
63  McSocketUDP* clone() const;
64 
67  }
68 
71  }
72 
77  bool isRequester() const { return _amRequester; }
78 
79  void setRequester(bool val) { _amRequester = val; }
80 
81  void setName(const std::string& val) { _name = val; }
82 
83  const std::string& getName() const { return _name; }
84 
87 
88  IOChannel* connect() throw(nidas::util::IOException);
89 
90  virtual bool isNewInput() const { return _newInput; }
91 
92  virtual void connected(nidas::util::DatagramSocket* sock,
93  const nidas::util::Inet4PacketInfoX& pktinfo);
94 
99  {
100  _nonBlocking = val;
101  }
102 
106  bool isNonBlocking() const throw (nidas::util::IOException)
107  {
108  return _nonBlocking;
109  }
110 
116  size_t read(void*, size_t) throw (nidas::util::IOException)
117  {
118  assert(false);
119  return 0;
120  }
121 
127  size_t write(const void*, size_t) throw (nidas::util::IOException)
128  {
129  assert(false);
130  return 0;
131  }
132 
138  size_t write(const struct iovec*, int) throw (nidas::util::IOException)
139  {
140  assert(false);
141  return 0;
142  }
143 
144  void close() throw (nidas::util::IOException);
145 
146  int getFd() const;
147 
148  void fromDOMElement(const xercesc::DOMElement*)
149  throw(nidas::util::InvalidParameterException);
150 
151  class MyMcSocket: public nidas::util::McSocket<nidas::util::DatagramSocket>
152  {
153  public:
156  const nidas::util::Inet4PacketInfoX& pktinfo)
157  {
158  _outer->connected(sock,pktinfo);
159  }
160  private:
162 
164  MyMcSocket(const MyMcSocket&);
166  };
167 
169  {
171  }
172 
174  {
176  }
177 
178 protected:
179 
181 
183 
184 private:
185 
186  std::string _name;
187 
189 
191 
192  bool _newInput;
193 
195 
198 
199 };
200 
201 }} // namespace nidas namespace core
202 
203 #endif
Implementation of an IOChannel, using nidas::util::McSocket&lt;nidas::util::DatagramSocket&gt; to establish...
Definition: McSocketUDP.h:46
IOChannelRequester * _iochanRequester
Definition: McSocketUDP.h:180
virtual bool isNewInput() const
Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from t...
Definition: McSocketUDP.h:90
void setRequester(bool val)
Definition: McSocketUDP.h:79
enum McSocketRequest getRequestType() const
Definition: McSocketUDP.h:69
bool _nonBlocking
Definition: McSocketUDP.h:194
const nidas::util::Inet4SocketAddress & getInet4McastSocketAddress() const
Definition: McSocketUDP.h:173
A socket for sending or receiving datagrams, either unicast, broadcast or multicast.
Definition: Socket.h:912
std::string _name
Definition: McSocketUDP.h:186
McSocketRequest
Definition: Datagrams.h:34
size_t write(const struct iovec *, int)
A McSocketUDP shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: McSocketUDP.h:138
A IP version 4 socket address, containing a host address, and a port number.
Definition: Inet4SocketAddress.h:41
void setInet4McastSocketAddress(const nidas::util::Inet4SocketAddress &val)
Definition: McSocketUDP.h:168
virtual void connected(nidas::util::DatagramSocket *sock, const nidas::util::Inet4PacketInfoX &pktinfo)
Definition: McSocketUDP.cc:86
void close()
Definition: McSocketUDP.cc:100
int getFd() const
Definition: McSocketUDP.cc:106
Definition: McSocketUDP.h:151
void setNonBlocking(bool val)
Do setNonBlocking(val) on underlying socket.
Definition: McSocketUDP.h:98
const Inet4SocketAddress & getInet4McastSocketAddress() const
Get the multicast address for listening to requests.
Definition: McSocket.h:323
Definition: Inet4PacketInfo.h:92
void setName(const std::string &val)
Definition: McSocketUDP.h:81
MyMcSocket _mcsocket
Definition: McSocketUDP.h:182
A channel for Input or Output of data.
Definition: IOChannel.h:64
void fromDOMElement(const xercesc::DOMElement *)
Initialize myself from a xercesc::DOMElement.
Definition: McSocketUDP.cc:111
~McSocketUDP()
Definition: McSocketUDP.h:61
McSocketUDP()
Constructor.
Definition: McSocketUDP.cc:37
Implementation of an IOChannel, over a DatagramSocket.
Definition: DatagramSocket.h:44
nidas::core::McSocketUDP * _outer
Definition: McSocketUDP.h:161
bool isNonBlocking() const
Return isNonBlocking() of underlying socket.
Definition: McSocketUDP.h:106
void setRequestType(enum McSocketRequest val)
Definition: McSocketUDP.h:65
const std::string & getName() const
Definition: McSocketUDP.h:83
void requestConnection(IOChannelRequester *service)
After the IOChannel is configured, a user of IOChannel calls requestConnection to get things started...
Definition: McSocketUDP.cc:78
McSocketUDP * clone() const
Derived classes must provide clone.
Definition: McSocketUDP.cc:55
Definition: IOException.h:37
bool isRequester() const
Does this McSocket request connections, or does it listen for incoming connections.
Definition: McSocketUDP.h:77
bool _newInput
Definition: McSocketUDP.h:192
void connected(nidas::util::DatagramSocket *sock, const nidas::util::Inet4PacketInfoX &pktinfo)
Virtual method that is called when a socket connection is established.
Definition: McSocketUDP.h:155
McSocketUDP & operator=(const McSocketUDP &)
No assignment.
size_t write(const void *, size_t)
A McSocketUDP shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: McSocketUDP.h:127
bool _amRequester
Definition: McSocketUDP.h:188
Implementation of an IOChannel, using nidas::util::McSocket&lt;nidas::util::Socket&gt; to establish a TCP c...
Definition: McSocket.h:43
void setRequestType(int val)
Set the request type value.
Definition: McSocket.h:340
int getRequestType() const
Get the request type number.
Definition: McSocket.h:345
void setInet4McastSocketAddress(const Inet4SocketAddress &val)
Set the multicast address for listening to requests.
Definition: McSocket.h:332
MyMcSocket(nidas::core::McSocketUDP *s)
Definition: McSocketUDP.h:154
Interface for an object that requests connections to Inputs or Outputs.
Definition: IOChannel.h:54
IOChannel * connect()
Establish a connection.
Definition: McSocketUDP.cc:60
size_t read(void *, size_t)
A McSocketUDP shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: McSocketUDP.h:116
bool _firstRead
Definition: McSocketUDP.h:190