Coverage Report

Created: 2024-02-25 06:37

/src/ntopng/include/FifoSerializerQueue.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * (C) 2014-24 - ntop.org
4
 *
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 *
20
 */
21
22
#ifndef _FIFO_SERIALIZER_QUEUE_H
23
#define _FIFO_SERIALIZER_QUEUE_H
24
25
#include "ntop_includes.h"
26
27
class FifoSerializerQueue : public FifoQueue<ndpi_serializer*> {
28
 public:
29
  FifoSerializerQueue(u_int32_t queue_size)
30
2
      : FifoQueue<ndpi_serializer*>(queue_size) {}
31
32
2
  ~FifoSerializerQueue() {
33
2
    while (!q.empty()) {
34
0
      ndpi_serializer* s = q.front();
35
36
0
      q.pop();
37
0
      ndpi_term_serializer(s);
38
0
      free(s);
39
0
    }
40
2
  }
41
42
0
  bool enqueue(ndpi_serializer* item) {
43
0
    bool rv;
44
45
0
    m.lock(__FILE__, __LINE__);
46
47
0
    if (canEnqueue()) {
48
0
      q.push(item);
49
0
      rv = true;
50
0
    } else {
51
0
      rv = false;
52
0
    }
53
54
0
    if (rv)
55
0
      num_enqueued++;
56
0
    else
57
0
      num_not_enqueued++;
58
59
0
    m.unlock(__FILE__, __LINE__);
60
61
0
    return (rv);
62
0
  }
63
};
64
65
#endif /* _FIFO_SERIALIZER_QUEUE_H */