1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* Copyright (C) 2016 Tobias Brunner
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "mock_sender.h"
#include <collections/linked_list.h>
typedef struct private_mock_sender_t private_mock_sender_t;
/**
* Private data
*/
struct private_mock_sender_t {
/**
* Public interface
*/
mock_sender_t public;
/**
* Packet queue, as message_t*
*/
linked_list_t *queue;
};
METHOD(sender_t, send_, void,
private_mock_sender_t *this, packet_t *packet)
{
message_t *message;
message = message_create_from_packet(packet);
message->parse_header(message);
this->queue->insert_last(this->queue, message);
}
METHOD(mock_sender_t, dequeue, message_t*,
private_mock_sender_t *this)
{
message_t *message = NULL;
this->queue->remove_first(this->queue, (void**)&message);
return message;
}
METHOD(sender_t, destroy, void,
private_mock_sender_t *this)
{
this->queue->destroy_offset(this->queue, offsetof(message_t, destroy));
free(this);
}
/*
* Described in header
*/
mock_sender_t *mock_sender_create()
{
private_mock_sender_t *this;
INIT(this,
.public = {
.interface = {
.send = _send_,
.send_no_marker = (void*)nop,
.flush = (void*)nop,
.destroy = _destroy,
},
.dequeue = _dequeue,
},
.queue = linked_list_create(),
);
return &this->public;
}
|