nidas  v1.2-1520
McSocket.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  ** 2005, 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_MCSOCKET_H
28 #define NIDAS_CORE_MCSOCKET_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 
43 class McSocket: public IOChannel
44 {
45 public:
46 
50  McSocket();
51 
53  }
54 
55  McSocket* clone() const;
56 
59  }
60 
63  }
64 
69  bool isRequester() const { return _amRequester; }
70 
71  void setRequester(bool val) { _amRequester = val; }
72 
73  void setName(const std::string& val) { _name = val; }
74 
75  const std::string& getName() const { return _name; }
76 
79 
80  IOChannel* connect() throw(nidas::util::IOException);
81 
82  virtual void connected(nidas::util::Socket* sock,const nidas::util::Inet4PacketInfoX& pktinfo);
83 
84  virtual bool isNewInput() const { return _newInput; }
85 
86  // nidas::util::Inet4Address getRemoteInet4Address();
87 
89  {
90  _keepAliveIdleSecs = val;
91  }
92 
93  int getKeepAliveIdleSecs() const throw (nidas::util::IOException)
94  {
95  return _keepAliveIdleSecs;
96  }
97 
102  {
103  _nonBlocking = val;
104  }
105 
109  bool isNonBlocking() const throw (nidas::util::IOException)
110  {
111  return _nonBlocking;
112  }
113 
119  size_t read(void*, size_t) throw (nidas::util::IOException)
120  {
121  assert(false);
122  return 0;
123  }
124 
130  size_t write(const void*, size_t) throw (nidas::util::IOException)
131  {
132  assert(false);
133  return 0;
134  }
135 
141  size_t write(const struct iovec*, int) throw (nidas::util::IOException)
142  {
143  assert(false);
144  return 0;
145  }
146 
147  void close() throw (nidas::util::IOException);
148 
149  int getFd() const;
150 
151  void fromDOMElement(const xercesc::DOMElement*)
152  throw(nidas::util::InvalidParameterException);
153 
154  class MyMcSocket: public nidas::util::McSocket<nidas::util::Socket>
155  {
156  public:
159  {
160  _outer->connected(sock,pktinfo);
161  }
162  private:
164  MyMcSocket(const MyMcSocket&);
166  };
167 
169  {
171  }
172 
174  {
176  }
177 
178 protected:
179 
184  McSocket(const McSocket&);
185 
187 
189 
190 private:
191 
192  std::string _name;
193 
195 
197 
198  bool _newInput;
199 
201 
203 
207  McSocket& operator=(const McSocket&);
208 };
209 
210 
211 }} // namespace nidas namespace core
212 
213 #endif
int getKeepAliveIdleSecs() const
Definition: McSocket.h:93
McSocket & operator=(const McSocket &)
No assignment.
size_t write(const struct iovec *, int)
A McSocket shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: McSocket.h:141
McSocket()
Constructor.
Definition: McSocket.cc:41
virtual void connected(nidas::util::Socket *sock, const nidas::util::Inet4PacketInfoX &pktinfo)
Definition: McSocket.cc:95
McSocketRequest
Definition: Datagrams.h:34
IOChannelRequester * _iochanRequester
Definition: McSocket.h:186
std::string _name
Definition: McSocket.h:192
void setNonBlocking(bool val)
Do setNonBlocking(val) on underlying socket.
Definition: McSocket.h:101
void setRequestType(enum McSocketRequest val)
Definition: McSocket.h:57
MyMcSocket _mcsocket
Definition: McSocket.h:188
bool isRequester() const
Does this McSocket request connections, or does it listen for incoming connections.
Definition: McSocket.h:69
A IP version 4 socket address, containing a host address, and a port number.
Definition: Inet4SocketAddress.h:41
const nidas::util::Inet4SocketAddress & getInet4McastSocketAddress() const
Definition: McSocket.h:173
const std::string & getName() const
Definition: McSocket.h:75
bool _nonBlocking
Definition: McSocket.h:202
const Inet4SocketAddress & getInet4McastSocketAddress() const
Get the multicast address for listening to requests.
Definition: McSocket.h:323
bool _firstRead
Definition: McSocket.h:196
Definition: Inet4PacketInfo.h:92
void connected(nidas::util::Socket *sock, const nidas::util::Inet4PacketInfoX &pktinfo)
Virtual method that is called when a socket connection is established.
Definition: McSocket.h:158
McSocket * clone() const
Derived classes must provide clone.
Definition: McSocket.cc:60
A channel for Input or Output of data.
Definition: IOChannel.h:64
virtual bool isNewInput() const
Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from t...
Definition: McSocket.h:84
nidas::core::McSocket * _outer
Definition: McSocket.h:163
int _keepAliveIdleSecs
Definition: McSocket.h:200
void requestConnection(IOChannelRequester *service)
After the IOChannel is configured, a user of IOChannel calls requestConnection to get things started...
Definition: McSocket.cc:87
~McSocket()
Definition: McSocket.h:52
bool isNonBlocking() const
Return isNonBlocking() of underlying socket.
Definition: McSocket.h:109
size_t read(void *, size_t)
A McSocket shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: McSocket.h:119
int getFd() const
Definition: McSocket.cc:119
void setInet4McastSocketAddress(const nidas::util::Inet4SocketAddress &val)
Definition: McSocket.h:168
bool _amRequester
Definition: McSocket.h:194
Definition: IOException.h:37
Implementation of an IOChannel, over a Socket.
Definition: Socket.h:45
void setRequester(bool val)
Definition: McSocket.h:71
enum McSocketRequest getRequestType() const
Definition: McSocket.h:61
A stream (TCP) socket.
Definition: Socket.h:430
void fromDOMElement(const xercesc::DOMElement *)
Initialize myself from a xercesc::DOMElement.
Definition: McSocket.cc:124
bool _newInput
Definition: McSocket.h:198
Definition: McSocket.h:154
void close()
Definition: McSocket.cc:113
IOChannel * connect()
Establish a connection.
Definition: McSocket.cc:65
Implementation of an IOChannel, using nidas::util::McSocket&lt;nidas::util::Socket&gt; to establish a TCP c...
Definition: McSocket.h:43
size_t write(const void *, size_t)
A McSocket shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: McSocket.h:130
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
Interface for an object that requests connections to Inputs or Outputs.
Definition: IOChannel.h:54
MyMcSocket(nidas::core::McSocket *s)
Definition: McSocket.h:157
void setName(const std::string &val)
Definition: McSocket.h:73
void setKeepAliveIdleSecs(int val)
Definition: McSocket.h:88