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