IBR-DTNSuite
0.10
Main Page
Namespaces
Classes
Files
File List
File Members
IBR-DTNSuite
Namespaces
Classes
Files
File List
daemon
ibrcommon
ibrdtn
ibrdtn
api
Client.cpp
Client.h
PlainSerializer.cpp
PlainSerializer.h
data
security
streams
utils
config.h
ibrdtn.h
tools
File Members
Client.h
Go to the documentation of this file.
1
/*
2
* Client.h
3
*
4
* Copyright (C) 2011 IBR, TU Braunschweig
5
*
6
* Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*
20
*/
21
22
#ifndef CLIENT_H_
23
#define CLIENT_H_
24
25
#include "
ibrdtn/data/Number.h
"
26
#include "
ibrdtn/data/Bundle.h
"
27
#include "
ibrdtn/streams/StreamConnection.h
"
28
#include <
ibrcommon/net/socketstream.h
>
29
#include <
ibrcommon/thread/Mutex.h
>
30
#include <
ibrcommon/thread/MutexLock.h
>
31
#include <
ibrcommon/Exceptions.h
>
32
#include <
ibrcommon/thread/Queue.h
>
33
34
namespace
dtn
35
{
36
namespace
api
37
{
41
class
ConnectionException
:
public
ibrcommon::Exception
42
{
43
public
:
44
ConnectionException
(
string
what
=
"A connection error occurred."
) throw() : ibrcommon::
Exception
(
what
)
45
{
46
};
47
};
48
52
class
ConnectionTimeoutException
:
public
ConnectionException
53
{
54
public
:
55
ConnectionTimeoutException
(
string
what
=
"Timeout."
) throw() :
ConnectionException
(
what
)
56
{
57
};
58
};
59
63
class
ConnectionAbortedException
:
public
ConnectionException
64
{
65
public
:
66
ConnectionAbortedException
(
string
what
=
"Aborted."
) throw() :
ConnectionException
(
what
)
67
{
68
};
69
};
70
80
class
Client
:
public
dtn::streams::StreamConnection
,
public
dtn::streams::StreamConnection::Callback
81
{
82
private
:
90
class
AsyncReceiver :
public
ibrcommon::JoinableThread
91
{
92
public
:
98
AsyncReceiver(
Client
&client);
99
104
virtual
~AsyncReceiver();
105
106
protected
:
112
void
run()
throw
();
113
118
void
__cancellation()
throw
();
119
120
private
:
121
// member variable for the reference to the client object
122
Client
&
_client
;
123
124
bool
_running
;
125
};
126
127
public
:
131
enum
COMMUNICATION_MODE
132
{
133
MODE_BIDIRECTIONAL
= 0,
134
MODE_SENDONLY
= 1
135
};
136
148
Client
(
const
std::string &app,
ibrcommon::socketstream
&stream,
const
COMMUNICATION_MODE
mode =
MODE_BIDIRECTIONAL
);
149
Client
(
const
std::string &app,
const
dtn::data::EID
&
group
,
ibrcommon::socketstream
&stream,
const
COMMUNICATION_MODE
mode =
MODE_BIDIRECTIONAL
);
150
154
virtual
~Client
();
155
159
void
connect
();
160
165
void
close
();
166
170
void
abort
();
171
177
virtual
void
eventConnectionDown
() throw ();
178
184
virtual
void
eventBundleAck
(const dtn::data::
Length
&ack) throw ();
185
190
virtual
void
eventShutdown
(
StreamConnection
::
ConnectionShutdownCases
) throw () {};
191
196
virtual
void
eventTimeout
() throw () {};
197
202
virtual
void
eventError
() throw () {};
203
209
virtual
void
eventConnectionUp
(
const
dtn::streams::StreamContactHeader
&) throw () {};
210
215
virtual
void
eventBundleRefused
() throw () {};
216
221
virtual
void
eventBundleForwarded
() throw () {};
222
226
void
operator<<
(
const
dtn::data::Bundle
&b);
227
235
dtn::data::Bundle
getBundle
(
const
dtn::data::Timeout
timeout = 0) throw (
ConnectionException
);
236
237
// public variable
238
dtn::data::
Length
lastack
;
239
240
protected:
246
virtual
void
received
(const dtn::streams::StreamContactHeader&) {};
247
253
virtual
void
received
(
const
dtn::data::Bundle
&b);
254
255
private
:
256
// tcp stream reference to send/receive data to the daemon
257
ibrcommon::socketstream
&_stream;
258
259
// communication mode flags
260
COMMUNICATION_MODE
_mode;
261
262
// own application suffix
263
std::string _app;
264
265
// group to join
266
dtn::data::EID
_group;
267
268
// The asynchronous receiver thread which receives incoming bundles
269
Client::AsyncReceiver _receiver;
270
271
// the queue for incoming bundles, when used in synchronous mode
272
ibrcommon::Queue<dtn::data::Bundle>
_inqueue;
273
};
274
}
275
}
276
277
#endif
/* CLIENT_H_ */
ibrdtn
ibrdtn
api
Client.h
Generated on Mon Jul 22 2013 15:16:00 for IBR-DTNSuite by
1.8.3.1