Coverage Report

Created: 2024-02-29 06:05

/src/strongswan/src/libstrongswan/processing/jobs/callback_job.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2009-2012 Tobias Brunner
3
 * Copyright (C) 2007-2011 Martin Willi
4
 *
5
 * Copyright (C) secunet Security Networks AG
6
 *
7
 * This program is free software; you can redistribute it and/or modify it
8
 * under the terms of the GNU General Public License as published by the
9
 * Free Software Foundation; either version 2 of the License, or (at your
10
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
11
 *
12
 * This program is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
 * for more details.
16
 */
17
18
#include "callback_job.h"
19
20
#include <threading/thread.h>
21
#include <threading/condvar.h>
22
#include <threading/semaphore.h>
23
#include <threading/mutex.h>
24
#include <collections/linked_list.h>
25
26
typedef struct private_callback_job_t private_callback_job_t;
27
28
/**
29
 * Private data of an callback_job_t Object.
30
 */
31
struct private_callback_job_t {
32
33
  /**
34
   * Public callback_job_t interface.
35
   */
36
  callback_job_t public;
37
38
  /**
39
   * Callback to call on execution
40
   */
41
  callback_job_cb_t callback;
42
43
  /**
44
   * parameter to supply to callback
45
   */
46
  void *data;
47
48
  /**
49
   * cleanup function for data
50
   */
51
  callback_job_cleanup_t cleanup;
52
53
  /**
54
   * cancel function
55
   */
56
  callback_job_cancel_t cancel;
57
58
  /**
59
   * Priority of this job
60
   */
61
  job_priority_t prio;
62
};
63
64
METHOD(job_t, destroy, void,
65
  private_callback_job_t *this)
66
3.92k
{
67
3.92k
  if (this->cleanup)
68
0
  {
69
0
    this->cleanup(this->data);
70
0
  }
71
3.92k
  free(this);
72
3.92k
}
73
74
METHOD(job_t, execute, job_requeue_t,
75
  private_callback_job_t *this)
76
0
{
77
0
  return this->callback(this->data);
78
0
}
79
80
METHOD(job_t, cancel, bool,
81
  private_callback_job_t *this)
82
0
{
83
0
  return this->cancel(this->data);
84
0
}
85
86
METHOD(job_t, get_priority, job_priority_t,
87
  private_callback_job_t *this)
88
3.92k
{
89
3.92k
  return this->prio;
90
3.92k
}
91
92
/*
93
 * Described in header.
94
 */
95
callback_job_t *callback_job_create_with_prio(callback_job_cb_t cb, void *data,
96
        callback_job_cleanup_t cleanup, callback_job_cancel_t cancel,
97
        job_priority_t prio)
98
3.92k
{
99
3.92k
  private_callback_job_t *this;
100
101
3.92k
  INIT(this,
102
3.92k
    .public = {
103
3.92k
      .job = {
104
3.92k
        .execute = _execute,
105
3.92k
        .get_priority = _get_priority,
106
3.92k
        .destroy = _destroy,
107
3.92k
      },
108
3.92k
    },
109
3.92k
    .callback = cb,
110
3.92k
    .data = data,
111
3.92k
    .cleanup = cleanup,
112
3.92k
    .cancel = cancel,
113
3.92k
    .prio = prio,
114
3.92k
  );
115
116
3.92k
  if (cancel)
117
3.92k
  {
118
3.92k
    this->public.job.cancel = _cancel;
119
3.92k
  }
120
121
3.92k
  return &this->public;
122
3.92k
}
123
124
/*
125
 * Described in header.
126
 */
127
callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
128
                  callback_job_cleanup_t cleanup,
129
                  callback_job_cancel_t cancel)
130
0
{
131
0
  return callback_job_create_with_prio(cb, data, cleanup, cancel,
132
0
                     JOB_PRIO_MEDIUM);
133
0
}