Coverage Report

Created: 2026-04-01 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/base/gsnotify.c
Line
Count
Source
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* Notification machinery implementation */
18
#include "gx.h"
19
#include "gserrors.h"
20
#include "gsstruct.h"
21
#include "gsnotify.h"
22
23
/* GC descriptors */
24
private_st_gs_notify_registration();
25
public_st_gs_notify_list();
26
27
/* Initialize a notification list. */
28
void
29
gs_notify_init(gs_notify_list_t *nlist, gs_memory_t *mem)
30
2.65M
{
31
2.65M
    nlist->first = 0;
32
2.65M
    nlist->memory = mem;
33
2.65M
}
34
35
/* Register a client. */
36
int
37
gs_notify_register(gs_notify_list_t *nlist, gs_notify_proc_t proc,
38
                   void *proc_data)
39
2.95M
{
40
2.95M
    gs_notify_registration_t *nreg =
41
2.95M
        gs_alloc_struct(nlist->memory, gs_notify_registration_t,
42
2.95M
                        &st_gs_notify_registration, "gs_notify_register");
43
44
2.95M
    if (nreg == 0)
45
0
        return_error(gs_error_VMerror);
46
2.95M
    nreg->proc = proc;
47
2.95M
    nreg->proc_data = proc_data;
48
2.95M
    nreg->next = nlist->first;
49
2.95M
    nlist->first = nreg;
50
2.95M
    return 0;
51
2.95M
}
52
53
/*
54
 * Unregister a client.  Return 1 if the client was registered, 0 if not.
55
 * If proc_data is 0, unregister all registrations of that proc; otherwise,
56
 * unregister only the registration of that procedure with that proc_data.
57
 */
58
static void
59
no_unreg_proc(void *pdata)
60
1.12M
{
61
1.12M
}
62
int
63
gs_notify_unregister_calling(gs_notify_list_t *nlist, gs_notify_proc_t proc,
64
                             void *proc_data,
65
                             void (*unreg_proc)(void *pdata))
66
1.12M
{
67
1.12M
    gs_notify_registration_t **prev = &nlist->first;
68
1.12M
    gs_notify_registration_t *cur;
69
1.12M
    bool found = 0;
70
71
3.37M
    while ((cur = *prev) != 0)
72
2.24M
        if (cur->proc == proc &&
73
1.12M
            (proc_data == 0 || cur->proc_data == proc_data)
74
2.24M
            ) {
75
1.12M
            *prev = cur->next;
76
1.12M
            unreg_proc(cur->proc_data);
77
1.12M
            gs_free_object(nlist->memory, cur, "gs_notify_unregister");
78
1.12M
            found = 1;
79
1.12M
        } else
80
1.12M
            prev = &cur->next;
81
1.12M
    return found;
82
1.12M
}
83
int
84
gs_notify_unregister(gs_notify_list_t *nlist, gs_notify_proc_t proc,
85
                     void *proc_data)
86
1.12M
{
87
1.12M
    return gs_notify_unregister_calling(nlist, proc, proc_data, no_unreg_proc);
88
1.12M
}
89
90
/*
91
 * Notify the clients on a list.  If an error occurs, return the first
92
 * error code, but notify all clients regardless.
93
 */
94
int
95
gs_notify_all(gs_notify_list_t *nlist, void *event_data)
96
2.15M
{
97
2.15M
    gs_notify_registration_t *cur;
98
2.15M
    gs_notify_registration_t *next;
99
2.15M
    int ecode = 0;
100
101
5.10M
    for (next = nlist->first; (cur = next) != 0;) {
102
2.95M
        int code;
103
104
2.95M
        next = cur->next;
105
2.95M
        code = cur->proc(cur->proc_data, event_data);
106
2.95M
        if (code < 0 && ecode == 0)
107
0
            ecode = code;
108
2.95M
    }
109
2.15M
    return ecode;
110
2.15M
}
111
112
/* Release a notification list. */
113
void
114
gs_notify_release(gs_notify_list_t *nlist)
115
2.15M
{
116
2.15M
    gs_memory_t *mem = nlist->memory;
117
118
3.98M
    while (nlist->first) {
119
1.83M
        gs_notify_registration_t *next = nlist->first->next;
120
121
        gs_free_object(mem, nlist->first, "gs_notify_release");
122
1.83M
        nlist->first = next;
123
1.83M
    }
124
2.15M
}