NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
transform-base.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2018 Regents of the University of California.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*/
21
22
#ifndef NDN_CXX_SECURITY_TRANSFORM_BASE_HPP
23
#define NDN_CXX_SECURITY_TRANSFORM_BASE_HPP
24
25
#include "
ndn-cxx/detail/common.hpp
"
26
27
#include <vector>
28
29
namespace
ndn
{
30
namespace
security {
31
namespace
transform
{
32
48
class
Error
:
public
std::runtime_error
49
{
50
public
:
51
Error
(
size_t
index,
const
std::string& what);
52
53
size_t
54
getIndex
()
const
55
{
56
return
m_index;
57
}
58
59
private
:
60
size_t
m_index;
61
};
62
68
class
Downstream
69
{
70
public
:
71
virtual
72
~Downstream
() =
default
;
73
90
size_t
91
write
(
const
uint8_t*
buf
,
size_t
size);
92
101
void
102
end
();
103
107
bool
108
isEnd
()
const
109
{
110
return
m_isEnd;
111
}
112
116
void
117
setIndex
(
size_t
index)
118
{
119
m_index = index;
120
}
121
125
size_t
126
getIndex
()
const
127
{
128
return
m_index;
129
}
130
131
protected
:
132
Downstream
();
133
134
private
:
138
virtual
size_t
139
doWrite(
const
uint8_t*
buf
,
size_t
size) = 0;
140
144
virtual
void
145
doEnd() = 0;
146
147
private
:
148
bool
m_isEnd;
149
size_t
m_index;
150
};
151
157
class
Upstream
158
{
159
public
:
160
virtual
161
~Upstream
() =
default
;
162
163
protected
:
164
Upstream
();
165
166
protected
:
170
void
171
appendChain
(unique_ptr<Downstream> tail);
172
173
Downstream
*
174
getNext
()
175
{
176
return
m_next
.get();
177
}
178
179
protected
:
180
unique_ptr<Downstream>
m_next
;
181
};
182
186
class
Transform
:
public
Upstream
,
187
public
Downstream
,
188
noncopyable
189
{
190
protected
:
191
typedef
std::vector<uint8_t>
OBuffer
;
192
193
Transform
();
194
200
void
201
flushOutputBuffer
();
202
207
void
208
flushAllOutput
();
209
213
void
214
setOutputBuffer
(unique_ptr<OBuffer> buffer);
215
219
bool
220
isOutputBufferEmpty
()
const
;
221
222
private
:
226
size_t
227
doWrite(
const
uint8_t* data,
size_t
dataLen)
final
;
228
234
void
235
doEnd() final;
236
248
virtual
void
249
preTransform();
250
256
virtual
size_t
257
convert(const uint8_t* data,
size_t
dataLen) = 0;
258
266
virtual
void
267
finalize();
268
269
private:
270
unique_ptr<
OBuffer
> m_oBuffer;
271
size_t
m_outputOffset;
272
};
273
279
class
Sink
: public
Downstream
,
280
noncopyable
281
{
282
};
283
289
class
Source
:
public
Upstream
,
290
noncopyable
291
{
292
public
:
296
Source
&
297
operator>>
(unique_ptr<Transform>
transform
);
298
304
void
305
operator>>
(unique_ptr<Sink> sink);
306
307
protected
:
308
Source
();
309
313
void
314
pump();
315
319
size_t
320
getIndex
()
const
321
{
322
return
0;
323
}
324
325
private
:
329
virtual
void
330
doPump() = 0;
331
332
private
:
333
size_t
m_nModules;
// count of modules in the chain starting from this Source
334
};
335
336
}
// namespace transform
337
}
// namespace security
338
}
// namespace ndn
339
340
#endif // NDN_CXX_SECURITY_TRANSFORM_BASE_HPP
buf
const uint8_t * buf
Definition:
verification-helpers.cpp:47
common.hpp
Common includes and macros used throughout the library.
ndn::operator>>
std::istream & operator>>(std::istream &is, Name &name)
Parse URI from stream as Name.
Definition:
name.cpp:370
ndn::security::transform::Source::getIndex
size_t getIndex() const
Get the source module index (should always be 0).
Definition:
transform-base.hpp:320
ndn::security::transform::Downstream::isEnd
bool isEnd() const
Check if the input interface of a module is closed.
Definition:
transform-base.hpp:108
transform
ndn::security::transform::Upstream::Upstream
Upstream()
Definition:
transform-base.cpp:61
ndn::security::transform::Transform::flushAllOutput
void flushAllOutput()
Read the all the content from output buffer and write it into next module.
Definition:
transform-base.cpp:96
ndn::security::transform::Error::getIndex
size_t getIndex() const
Definition:
transform-base.hpp:54
ndn::security::transform::Transform::OBuffer
std::vector< uint8_t > OBuffer
Definition:
transform-base.hpp:191
ndn::security::transform::Transform::flushOutputBuffer
void flushOutputBuffer()
Read the content from output buffer and write it into next module.
Definition:
transform-base.cpp:85
ndn::security::transform::Upstream::getNext
Downstream * getNext()
Definition:
transform-base.hpp:174
ndn::security::transform::Upstream::~Upstream
virtual ~Upstream()=default
ndn::security::transform::Error
Base class of transformation error.
Definition:
transform-base.hpp:49
ndn::security::transform::Downstream::write
size_t write(const uint8_t *buf, size_t size)
Accept input data and perform transformation.
Definition:
transform-base.cpp:41
ndn::security::transform::Downstream
The downstream interface of a transformation module.
Definition:
transform-base.hpp:69
ndn::security::transform::Upstream::m_next
unique_ptr< Downstream > m_next
Definition:
transform-base.hpp:180
ndn::security::transform::Upstream
The upstream interface of a transformation module.
Definition:
transform-base.hpp:158
ndn::security::transform::Downstream::end
void end()
Close the input interface of a module.
Definition:
transform-base.cpp:52
ndn::security::transform::Transform::setOutputBuffer
void setOutputBuffer(unique_ptr< OBuffer > buffer)
Set output buffer to buffer.
Definition:
transform-base.cpp:104
ndn::security::transform::Upstream::appendChain
void appendChain(unique_ptr< Downstream > tail)
connect to next transformation module
Definition:
transform-base.cpp:67
ndn::security::transform::Source
Abstraction of the transformation source module.
Definition:
transform-base.hpp:291
ndn::security::transform::Transform
Abstraction of an intermediate transformation module.
Definition:
transform-base.hpp:189
ndn::security::transform::Downstream::setIndex
void setIndex(size_t index)
Set the module index.
Definition:
transform-base.hpp:117
ndn::security::transform::Downstream::Downstream
Downstream()
Definition:
transform-base.cpp:34
ndn::security::transform::Transform::isOutputBufferEmpty
bool isOutputBufferEmpty() const
Check if output buffer is empty.
Definition:
transform-base.cpp:112
ndn::security::transform::Transform::Transform
Transform()
Definition:
transform-base.cpp:78
ndn::security::transform::Downstream::getIndex
size_t getIndex() const
Get the module index.
Definition:
transform-base.hpp:126
ndn::security::transform::Downstream::~Downstream
virtual ~Downstream()=default
ndn::security::transform::Sink
Abstraction of the transformation sink module.
Definition:
transform-base.hpp:281
ndn::security::transform::Error::Error
Error(size_t index, const std::string &what)
Definition:
transform-base.cpp:28
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndnSIM
ndn-cxx
ndn-cxx
security
transform
transform-base.hpp
Generated on Mon Jun 1 2020 22:32:15 for ndnSIM by
1.8.18