GCC Code Coverage Report


Directory: src/gate/
File: src/gate/system/platform/linux_dbus_api.h
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 27 0.0%
Functions: 0 3 0.0%
Branches: 0 32 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #ifndef GATE_SYSTEM_PLATFORM_LINUX_DBUS_API_H_INCLUDED
30 #define GATE_SYSTEM_PLATFORM_LINUX_DBUS_API_H_INCLUDED
31
32 #include <dbus/dbus.h>
33 #include "gate/libraries.h"
34 #include "gate/results.h"
35
36 typedef struct gate_libdbus_class
37 {
38 void (*error_init)(DBusError* ptr_error);
39 void (*error_free)(DBusError* ptr_error);
40
41 DBusConnection* (*bus_get)(DBusBusType type, DBusError* ptr_error);
42
43 DBusConnection* (*connection_open)(const char* address, DBusError* error);
44 DBusConnection* (*connection_ref)(DBusConnection* connection);
45 void (*connection_unref)(DBusConnection* connection);
46 void (*connection_close)(DBusConnection* connection);
47 DBusMessage* (*connection_send_with_reply_and_block)(DBusConnection* connection, DBusMessage* message, int timeout_milliseconds, DBusError* error);
48
49 DBusMessage* (*message_ref)(DBusMessage* message);
50 void (*message_unref)(DBusMessage* message);
51 DBusMessage* (*message_copy)(const DBusMessage* message);
52 DBusMessage* (*message_new_method_call)(const char* bus_name, const char* path, const char* iface, const char* method);
53 dbus_bool_t (*message_append_args)(DBusMessage* message, int first_arg_type, ...);
54
55 } gate_libdbus_t;
56
57
58 #if defined(GATE_SYSTEM_LIBDBUS_STATIC)
59
60 static gate_result_t load_libdbus_lib()
61 {
62 return GATE_RESULT_OK;
63 }
64
65 # define LOAD_DBUS_FUNC(funcptr, funcname) do { funcptr = funcname; } while(0)
66
67 #else
68
69 static gate_library_t global_libdbus_lib = NULL;
70
71 static gate_result_t load_libdbus_lib()
72 {
73 static gate_string_t const libdbus_libname = GATE_STRING_INIT_STATIC("libdbus-1.so");
74 gate_result_t ret;
75
76 if (global_libdbus_lib == NULL)
77 {
78 ret = gate_library_open(&libdbus_libname, &global_libdbus_lib, 0);
79 if (GATE_FAILED(ret))
80 {
81 global_libdbus_lib = NULL;
82 }
83 }
84 else
85 {
86 ret = GATE_RESULT_OK;
87 }
88 return ret;
89 }
90
91 static gate_result_t load_libdbus_function(void* ptr_funcptr, char const* funcname)
92 {
93 return gate_library_get_function_name(global_libdbus_lib, funcname, ptr_funcptr);
94 }
95
96 # define LOAD_DBUS_FUNC(funcptr, funcname) do { \
97 gate_result_t result = load_libdbus_function(&funcptr, #funcname); \
98 if(GATE_FAILED(result)) { return result; } \
99 } while(0)
100
101 #endif
102
103
104 static gate_result_t load_libdbus(gate_libdbus_t* dbus)
105 {
106 gate_result_t result = load_libdbus_lib();
107 if (GATE_FAILED(result))
108 {
109 return result;
110 }
111
112 LOAD_DBUS_FUNC(dbus->error_init, dbus_error_init);
113 LOAD_DBUS_FUNC(dbus->error_free, dbus_error_free);
114
115 LOAD_DBUS_FUNC(dbus->bus_get, dbus_bus_get);
116
117 LOAD_DBUS_FUNC(dbus->connection_open, dbus_connection_open);
118 LOAD_DBUS_FUNC(dbus->connection_ref, dbus_connection_ref);
119 LOAD_DBUS_FUNC(dbus->connection_unref, dbus_connection_unref);
120 LOAD_DBUS_FUNC(dbus->connection_close, dbus_connection_close);
121 LOAD_DBUS_FUNC(dbus->connection_send_with_reply_and_block, dbus_connection_send_with_reply_and_block);
122
123 LOAD_DBUS_FUNC(dbus->message_ref, dbus_message_ref);
124 LOAD_DBUS_FUNC(dbus->message_unref, dbus_message_unref);
125 LOAD_DBUS_FUNC(dbus->message_copy, dbus_message_copy);
126 LOAD_DBUS_FUNC(dbus->message_new_method_call, dbus_message_new_method_call);
127 LOAD_DBUS_FUNC(dbus->message_append_args, dbus_message_append_args);
128
129 return GATE_RESULT_OK;
130 }
131
132
133 #endif
134