nidas  v1.2-1520
RemoteSerialConnection.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  ** 2004, 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_REMOTESERIALCONNECTION_H
28 #define NIDAS_CORE_REMOTESERIALCONNECTION_H
29 
30 #include <nidas/util/Socket.h>
31 #include "SerialSensor.h"
32 #include "SampleClient.h"
34 
35 #include "Polled.h"
36 
37 namespace nidas { namespace core {
38 
39 class SensorHandler;
40 
42 {
43 public:
44 
46 
48 
52  void flush() throw() {}
53 
54  const std::string& getName() const { return _name; }
55 
56  void setName(const std::string& val) { _name = val; }
57 
58  void close() throw(nidas::util::IOException);
59 
60  void readSensorName() throw(nidas::util::IOException);
61 
62  int getFd() const { return _socket->getFd(); }
63 
64  const std::string& getSensorName() const { return _devname; }
65 
67 
68  DSMSensor* getDSMSensor() const { return _sensor; }
69 
74  void sensorNotFound() throw(nidas::util::IOException);
75 
79  bool receive(const Sample* s) throw();
80 
86  bool handlePollEvents(uint32_t events) throw();
87 
93  void nlTocrnl(std::string& input);
94 
106  std::string doEscCmds(const std::string& inputstr) throw(nidas::util::IOException);
107 
108 private:
109 
110  std::string _name;
111 
112  nidas::util::Socket* _socket;
113 
114  std::string _devname;
115 
117 
119 
123  std::string _input;
124 
126 
128 
133 
138 
141 
143  RemoteSerialConnection& operator=(const RemoteSerialConnection&);
144 
145 };
146 
147 }} // namespace nidas namespace core
148 
149 #endif
Definition: RemoteSerialConnection.h:41
bool _nullTerminated
Definition: RemoteSerialConnection.h:125
bool receive(const Sample *s)
Receive a sample from the DSMSensor, write data portion to socket.
Definition: RemoteSerialConnection.cc:189
void close()
Definition: RemoteSerialConnection.cc:62
SensorHandler * _handler
Definition: RemoteSerialConnection.h:127
SensorHandler implements a DSMSensor event loop.
Definition: SensorHandler.h:87
Implementation of support for a sensor which generates character output.
Definition: CharacterSensor.h:46
bool _closedWarning
Has the user been sent a &quot;sensor is closed&quot; warning.
Definition: RemoteSerialConnection.h:132
Support for a sensor that is sending packets on a TCP socket, a UDP socket, a Bluetooth RF Comm socke...
Definition: SerialSensor.h:64
Interface for objects with a file descriptor, providing a virtual method to be called when system cal...
Definition: Polled.h:109
~RemoteSerialConnection()
Definition: RemoteSerialConnection.cc:51
const std::string & getSensorName() const
Definition: RemoteSerialConnection.h:64
nidas::util::Socket * _socket
Definition: RemoteSerialConnection.h:112
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
void nlTocrnl(std::string &input)
little utility for translating newlines to carriage-return + newlines in a string.
Definition: RemoteSerialConnection.cc:209
int getFd() const
Fetch the file descriptor associate with this socket.
Definition: Socket.h:617
SerialSensor * _serSensor
Definition: RemoteSerialConnection.h:118
std::string doEscCmds(const std::string &inputstr)
Parse and execute ESC commands in user input.
Definition: RemoteSerialConnection.cc:221
int _timeoutMsecs
Sensor timeout when the RemoteSerialConnection was established.
Definition: RemoteSerialConnection.h:137
void flush()
Implementation of SampleClient::flush().
Definition: RemoteSerialConnection.h:52
DSMSensor * getDSMSensor() const
Definition: RemoteSerialConnection.h:68
Interface to a data sample.
Definition: Sample.h:189
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
bool handlePollEvents(uint32_t events)
An epoll event occurred, most likely it is time to read data from socket, write to DSMSensor...
Definition: RemoteSerialConnection.cc:361
const std::string & getName() const
Definition: RemoteSerialConnection.h:54
Definition: IOException.h:37
Implementation of an IOChannel, over a Socket.
Definition: Socket.h:45
void setSensor(CharacterSensor *val)
Definition: RemoteSerialConnection.cc:112
RemoteSerialConnection(nidas::util::Socket *sock, SensorHandler *handler)
Definition: RemoteSerialConnection.cc:42
void readSensorName()
Definition: RemoteSerialConnection.cc:85
CharacterSensor * _sensor
Definition: RemoteSerialConnection.h:116
std::string _name
Definition: RemoteSerialConnection.h:110
std::string _input
Left over input characters after previous parse for escape sequences.
Definition: RemoteSerialConnection.h:123
A stream (TCP) socket.
Definition: Socket.h:430
int getFd() const
Definition: RemoteSerialConnection.h:62
std::string _devname
Definition: RemoteSerialConnection.h:114
void sensorNotFound()
Notify this RemoteSerialConnection that a sensor matching getSensorName() was not found...
Definition: RemoteSerialConnection.cc:100
void setName(const std::string &val)
Definition: RemoteSerialConnection.h:56