nancy.liao
2025-05-29 8d405b265285c368df2e9cf1c14acee7532e0ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * EventRegistry.h
 *
 *  Created on: Mar 30, 2014
 *
 */
 
#ifndef EVENTREGISTRY_H_
#define EVENTREGISTRY_H_
 
#include <licensecc/datatypes.h>
 
#include <vector>
#include <map>
#include <set>
#include <string>
 
namespace license {
 
/**
 * Tracks the events relative to a license and provide explanation regarding
 * failures to verify licenses.
 */
class EventRegistry {
private:
    friend EventRegistry &operator<<(EventRegistry &, AuditEvent &);
    friend EventRegistry &operator<<(EventRegistry &, EventRegistry &);
    friend std::ostream &operator<<(std::ostream &out, const EventRegistry &er);
 
    std::vector<AuditEvent> logs;
    /**
     * For every license keep track of the events who progressed most
     * in the validation process
     */
    std::map<std::string, size_t> mostAdvancedLogIdx_by_LicenseId;
    int current_validation_step;
 
public:
    EventRegistry();
    // operator <<
    void append(const EventRegistry &eventRegistry);
    /**
     * Turn the event warning for the license with the most advanced status
     * into an error.
     */
    bool turnWarningsIntoErrors();
    bool turnErrorsIntoWarnings();
    bool isGood() const;
    /**
     * Return the last failure (event with warn or error status)
     * for the license with the most advanced status.
     * @return NULL if no failures are found.
     */
    const AuditEvent *getLastFailure() const;
    void addEvent(LCC_EVENT_TYPE event, const std::string &licenseLocationId);
    void addEvent(LCC_EVENT_TYPE event, const char *licenseLocationId = nullptr, const char *info = nullptr);
    void exportLastEvents(AuditEvent *auditEvents, int nlogs);
    std::string to_string() const;
};
}  // namespace license
#endif /* EVENTREGISTRY_H_ */