Coverage Report

Created: 2025-05-16 06:24

/src/ntopng/include/StringFifoQueue.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * (C) 2014-25 - 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 _STRING_FIFO_QUEUE_H
23
#define _STRING_FIFO_QUEUE_H
24
25
#include "ntop_includes.h"
26
27
class StringFifoQueue : public FifoQueue<char *> {
28
 public:
29
8
  StringFifoQueue(u_int32_t queue_size) : FifoQueue<char *>(queue_size) {}
30
31
8
  ~StringFifoQueue() {
32
508
    while (!q.empty()) {
33
500
      char *s = q.front();
34
35
500
      q.pop();
36
500
      free(s);
37
500
    }
38
8
  }
39
40
4.18k
  bool enqueue(char *item) {
41
4.18k
    bool rv;
42
43
4.18k
    m.lock(__FILE__, __LINE__);
44
45
4.18k
    if (canEnqueue()) {
46
500
      char *d = strdup(item);
47
48
500
      if (d) {
49
500
        q.push(d);
50
500
        rv = true;
51
500
      } else {
52
0
        rv = false;
53
0
      }
54
500
    } else
55
3.68k
      rv = false;
56
57
4.18k
    if (rv)
58
500
      num_enqueued++;
59
3.68k
    else
60
3.68k
      num_not_enqueued++;
61
62
4.18k
    m.unlock(__FILE__, __LINE__);
63
64
4.18k
    return (rv);
65
4.18k
  }
66
};
67
68
#endif /* _STRING_FIFO_QUEUE_H */