]> granicus.if.org Git - icinga2/blob - lib/pgsql_shim/pgsqlinterface.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / pgsql_shim / pgsqlinterface.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef PGSQLINTERFACE_H
4 #define PGSQLINTERFACE_H
5
6 #include "pgsql_shim/pgsql_shim_export.h"
7 #include <memory>
8 #include <libpq-fe.h>
9
10 namespace icinga
11 {
12
13 struct PgsqlInterface
14 {
15         PgsqlInterface(const PgsqlInterface&) = delete;
16         PgsqlInterface& operator=(PgsqlInterface&) = delete;
17
18         virtual void Destroy() = 0;
19
20         virtual void clear(PGresult *res) const = 0;
21         virtual char *cmdTuples(PGresult *res) const = 0;
22         virtual char *errorMessage(const PGconn *conn) const = 0;
23         virtual size_t escapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error) const = 0;
24         virtual PGresult *exec(PGconn *conn, const char *query) const = 0;
25         virtual void finish(PGconn *conn) const = 0;
26         virtual char *fname(const PGresult *res, int field_num) const = 0;
27         virtual int getisnull(const PGresult *res, int tup_num, int field_num) const = 0;
28         virtual char *getvalue(const PGresult *res, int tup_num, int field_num) const = 0;
29         virtual int isthreadsafe() const = 0;
30         virtual int nfields(const PGresult *res) const = 0;
31         virtual int ntuples(const PGresult *res) const = 0;
32         virtual char *resultErrorMessage(const PGresult *res) const = 0;
33         virtual ExecStatusType resultStatus(const PGresult *res) const = 0;
34         virtual int serverVersion(const PGconn *conn) const = 0;
35         virtual PGconn *setdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, const char *login, const char *pwd) const = 0;
36         virtual PGconn *connectdb(const char *conninfo) const = 0;
37         virtual ConnStatusType status(const PGconn *conn) const = 0;
38
39 protected:
40         PgsqlInterface() = default;
41         ~PgsqlInterface() = default;
42 };
43
44 struct PgsqlInterfaceDeleter
45 {
46         void operator()(PgsqlInterface *ifc) const
47         {
48                 ifc->Destroy();
49         }
50 };
51
52 }
53
54 extern "C"
55 {
56         PGSQL_SHIM_EXPORT icinga::PgsqlInterface *create_pgsql_shim();
57 }
58
59 typedef icinga::PgsqlInterface *(*create_pgsql_shim_ptr)();
60
61 #endif /* PGSQLINTERFACE_H */