Line |
Branch |
Exec |
Source |
1 |
|
|
/***************************************************************************** |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2015-2016 Richard Hacker (lerichi at gmx dot net) |
4 |
|
|
* |
5 |
|
|
* This file is part of the PdCom library. |
6 |
|
|
* |
7 |
|
|
* The PdCom library is free software: you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU Lesser General Public License as published by |
9 |
|
|
* the Free Software Foundation, either version 3 of the License, or (at your |
10 |
|
|
* option) any later version. |
11 |
|
|
* |
12 |
|
|
* The PdCom library is distributed in the hope that it will be useful, but |
13 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
15 |
|
|
* License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
18 |
|
|
* along with the PdCom library. If not, see <http://www.gnu.org/licenses/>. |
19 |
|
|
* |
20 |
|
|
*****************************************************************************/ |
21 |
|
|
|
22 |
|
|
#include "SpyLayer.h" |
23 |
|
|
|
24 |
|
|
#include <iostream> |
25 |
|
|
#include <sstream> |
26 |
|
|
#include <string> |
27 |
|
|
|
28 |
|
|
using namespace PdCom::impl; |
29 |
|
|
|
30 |
|
|
/////////////////////////////////////////////////////////////////////////// |
31 |
|
✗ |
SpyLayer::SpyLayer(IOLayer *parent) : IOLayer(parent) |
32 |
|
|
{} |
33 |
|
|
|
34 |
|
|
/////////////////////////////////////////////////////////////////////////// |
35 |
|
✗ |
int SpyLayer::read(char *buf, int n) |
36 |
|
|
{ |
37 |
|
✗ |
const int rv = IOLayer::read(buf, n); |
38 |
|
|
|
39 |
|
✗ |
if (rv > 0) { |
40 |
|
✗ |
std::istringstream is(std::string(buf, rv)); |
41 |
|
✗ |
std::string line; |
42 |
|
✗ |
while (is.rdbuf()->in_avail()) { |
43 |
|
✗ |
std::getline(is, line); |
44 |
|
✗ |
std::cout << "--> " << line << std::endl; |
45 |
|
|
} |
46 |
|
|
} |
47 |
|
✗ |
else if (n and rv == 0) |
48 |
|
✗ |
std::cout << "EOF rv=" << rv << std::endl; |
49 |
|
|
|
50 |
|
✗ |
return rv; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
/////////////////////////////////////////////////////////////////////////// |
54 |
|
✗ |
void SpyLayer::write(const char *buf, size_t n) |
55 |
|
|
{ |
56 |
|
✗ |
IOLayer::write(buf, n); |
57 |
|
|
|
58 |
|
✗ |
outputBuffer.append(buf, n); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
/////////////////////////////////////////////////////////////////////////// |
62 |
|
✗ |
void SpyLayer::flush() |
63 |
|
|
{ |
64 |
|
✗ |
IOLayer::flush(); |
65 |
|
|
|
66 |
|
✗ |
std::istringstream is(outputBuffer); |
67 |
|
✗ |
std::string line; |
68 |
|
✗ |
while (is.rdbuf()->in_avail()) { |
69 |
|
✗ |
std::getline(is, line); |
70 |
|
✗ |
std::cout << "<-- " << line << std::endl; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
✗ |
outputBuffer.clear(); |
74 |
|
12 |
} |
75 |
|
|
|