/usr/include/dballe/db/v7/repinfo.h is in libdballe-dev 7.21-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #ifndef DBALLE_DB_V7_REPINFO_H
#define DBALLE_DB_V7_REPINFO_H
/** @file
* @ingroup db
*
* Repinfo table management used by the db module.
*/
#include <dballe/sql/fwd.h>
#include <memory>
#include <map>
#include <string>
#include <vector>
namespace dballe {
struct Record;
namespace core {
struct Query;
}
namespace db {
namespace v7 {
namespace repinfo {
/** repinfo cache entry */
struct Cache
{
/// Report code
unsigned id;
/** Report name */
std::string memo;
/** Report description */
std::string desc;
/// Report priority
int prio;
/** Report descriptor (currently unused) */
std::string descriptor;
/// Report A table value (currently unused)
unsigned tablea;
/** New report name used when updating the repinfo table */
std::string new_memo;
/** New report description used when updating the repinfo table */
std::string new_desc;
/// New report priority used when updating the repinfo table
int new_prio;
/** New report descriptor used when updating the repinfo table */
std::string new_descriptor;
/// New report A table value used when updating the repinfo table
unsigned new_tablea;
Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea);
void make_new();
void dump(FILE* out) const;
};
/** reverse rep_memo -> rep_cod cache entry */
struct Memoidx
{
/** Report name */
std::string memo;
/** Report code */
int id;
bool operator<(const Memoidx& memo) const;
};
}
/// Fast cached access to the repinfo table
struct Repinfo
{
dballe::sql::Connection& conn;
Repinfo(dballe::sql::Connection& conn);
virtual ~Repinfo() {}
//static std::unique_ptr<Repinfo> create(Connection& conn);
/**
* Fill repinfo information in a Record based on the repinfo entry with the
* given ID
*/
void to_record(int id, Record& rec);
/// Get the rep_memo for a given ID; throws if id is not valud
const char* get_rep_memo(int id);
/// Get the ID for a given rep_memo; returns -1 if rep_memo is not valid
int get_id(const char* rep_memo);
/// Get the priority for a given ID; returns INT_MAX if id is not valid
int get_priority(int id);
/**
* Update the report type information in the database using the data from the
* given file.
*
* @param deffile
* Pathname of the file to use for the update. The NULL value is accepted
* and means to use the default configure repinfo.csv file.
* @retval added
* Number of entries that have been added during the update.
* @retval deleted
* Number of entries that have been deleted during the update.
* @retval updated
* Number of entries that have been updated during the update.
*/
void update(const char* deffile, int* added, int* deleted, int* updated);
/**
* Get a mapping between rep_memo and their priorities
*/
std::map<std::string, int> get_priorities();
/**
* Return a vector of IDs matching the priority constraints in the given record.
*/
std::vector<int> ids_by_prio(const core::Query& rec);
/**
* Get the id of a repinfo entry given its name.
*
* It creates a new entry if the memo is missing from the database.
*
* @param memo
* The name to query
* @return
* The resulting id.
*/
int obtain_id(const char* memo);
/// Dump the entire contents of the database to an output stream
virtual void dump(FILE* out) = 0;
protected:
/** Cache of table entries */
std::vector<repinfo::Cache> cache;
/** rep_memo -> rep_cod reverse index */
mutable std::vector<repinfo::Memoidx> memo_idx;
/// Get a Cache entry by database ID
const repinfo::Cache* get_by_id(unsigned id) const;
/// Get a Cache entry by report name
const repinfo::Cache* get_by_memo(const char* memo) const;
/// Lookup a cache index by database ID. Returns -1 if not found
int cache_find_by_id(unsigned id) const;
/// Lookup a cache index by report name. Returns -1 if not found
int cache_find_by_memo(const char* memo) const;
/// Append an entry to the cache
void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea);
/// Rebuild the memo_idx cache
void rebuild_memo_idx() const;
/// Read cache entries from a repinfo file on disk
std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
/// Return how many time this ID is used in the database
virtual int id_use_count(unsigned id, const char* name) = 0;
/// Delete a repinfo entry
virtual void delete_entry(unsigned id) = 0;
/// Update an entry using the new_* fields of \a entry
virtual void update_entry(const repinfo::Cache& entry) = 0;
/// Insert an entry using the new_* fields of \a entry
virtual void insert_entry(const repinfo::Cache& entry) = 0;
/// Reread the repinfo cache from the database
virtual void read_cache() = 0;
/// Create an automatic entry for a missing memo, and insert it in the database
virtual void insert_auto_entry(const char* memo) = 0;
};
}
}
}
#endif
|