nidas v1.2.3
XMLFdBinInputStream.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_XMLFDBININPUTSTREAM_H
28#define NIDAS_CORE_XMLFDBININPUTSTREAM_H
29
30#include <xercesc/util/XercesDefs.hpp>
31#include <xercesc/util/BinInputStream.hpp>
33
34#include <unistd.h>
35
36#include <iostream>
37
38namespace nidas { namespace core {
39
44class XMLFdBinInputStream: public xercesc::BinInputStream {
45public:
46
52 XMLFdBinInputStream(const std::string& n,int f) : name(n),fd(f),curpos(0),_eof(false) {}
54 {
55 // std::cerr << "~XMLFdBinInputStream" << std::endl;
56 }
57
58 XMLFilePos
59 curPos() const { return curpos; }
60
66 XMLSize_t
67 readBytes(XMLByte* const toFill,
68 const XMLSize_t maxToRead
69 )
70 {
71 if (_eof) return 0;
72 // std::cerr << "XMLFdBinInputStream reading " << maxToRead << std::endl;
73 ssize_t l = ::read(fd,toFill,maxToRead);
74 if (l < 0) throw nidas::util::IOException(name,"read",errno);
75 for (int i = 0; i < l; i++)
76 if (toFill[i] == '\x04') {
77 l = i;
78 _eof = true;
79 }
80 curpos += l;
81 // std::cerr << "XMLFdBinInputStream read " << std::string((char*)toFill,0,l < 20 ? l : 20) << std::endl;
82 // std::cerr << "XMLFdBinInputStream read " << std::string((char*)toFill,0,l) << std::endl;
83 // std::cerr << "XMLFdBinInputStream read " << l << std::endl;
84 // toFill[l] = 0;
85 // toFill[l+1] = 0;
86 return l;
87 }
88
89 const XMLCh* getContentType() const
90 {
91 return 0;
92 }
93
94protected:
95
96 std::string name;
97
98 int fd;
99 XMLFilePos curpos;
100
101 bool _eof;
102
103};
104
105}} // namespace nidas namespace core
106
107#endif
108
Implemenation of xercesc::BinInputStream, which reads from a unix file descriptor.
Definition XMLFdBinInputStream.h:44
XMLFdBinInputStream(const std::string &n, int f)
Constructor.
Definition XMLFdBinInputStream.h:52
XMLFilePos curpos
Definition XMLFdBinInputStream.h:99
~XMLFdBinInputStream()
Definition XMLFdBinInputStream.h:53
XMLFilePos curPos() const
Definition XMLFdBinInputStream.h:59
const XMLCh * getContentType() const
Definition XMLFdBinInputStream.h:89
bool _eof
Definition XMLFdBinInputStream.h:101
std::string name
Definition XMLFdBinInputStream.h:96
XMLSize_t readBytes(XMLByte *const toFill, const XMLSize_t maxToRead)
return number of bytes read, or 0 on EOF.
Definition XMLFdBinInputStream.h:67
int fd
Definition XMLFdBinInputStream.h:98
Definition IOException.h:37
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31